<?php

/*  Alternate WebKit
(C) 2011-2014 by Alternate Tools
-----------------------------------------------------

File:         list_pagecontents.php
Description:  Administrative overview of all pagescontents

*/

    include "../modules/class_page.php";
    include "../modules/class_pagelist.php";
    include "../modules/class_textfile.php";
    include "../modules/mod_admin.php";


    // Check privileges
    check_login();
    if (user_is_customer() == true)
    {
        log_out();
        return;
    }
    if (user_is_reporter() == true || isset ($_POST['pagel_Cancel']))
    {
        header("location: " . $ADMIN_MAIN_SITE);
        return;
    }

    // Edit page?
    if (isset ($_POST['pagel_EditPage']))
    {
        header ('Location: ' . $ADMIN_EDIT_PAGECONTENTS_SITE . '?id=' . $_POST['pagel_PageId'] . '&action=edit');
        return;
    }

    // Display
    print_admin_header(get_translation('admin_pagecontl_head'), true, get_translation('admin_login_logout'), $ADMIN_HELP_FILE . '#n1-1', true, get_translation('admin_backtomain'));
    $page = new cPage;
    $pageList = new cPageList;
    $textFile = new cTextFile;

    $page->SetFolder($PAGES_FOLDER);
    $pageList->SetFolder($PAGES_FOLDER);

    $pageList->LoadPageList(1); // Unlocked
    $pageList->SortPageList(4); // Sort by position
//    $pageList->SortByPubDate(false);
    $list = $pageList->GetPageList();

    echo_r ('<form method="post" action="">');
    echo_r ('</form>');

    // No entries?
    if (count($list) < 1)
        echo_r ('<p>&nbsp;' . get_translation('admin_noentries') . '</p>');
    foreach ($list as $value)
    {
        $page->LoadPageFromId($value);
        if ($page->GetType() == PAGETYPE_LINK)
            continue;
            
        echo_r('<hr>');
        echo_r('<table width="100%" border="0">');
        echo_r('  <tr>');
        echo_r('    <td width="14%">');
        echo  ('      <a href="' . $ADMIN_EDIT_PAGECONTENTS_SITE . '?id=' . $page->GetId() . '&amp;action=edit">');
        if ($page->GetType() == PAGETYPE_CONTACT)
            echo_r('<img src="' . $PAGE_CONTACT_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_GALLERY)
            echo_r('<img src="' . $PAGE_GALLERY_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_YOUTUBEGALLERY)
            echo_r('<img src="' . $PAGE_YOUTUBEGALLERY_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_LINKS)
            echo_r('<img src="' . $PAGE_LINKLIST_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_GUESTBOOK)
            echo_r('<img src="' . $PAGE_GUESTBOOK_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_SITEMAP)
            echo_r('<img src="' . $PAGE_SITEMAP_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_NEWSLETTER)
            echo_r('<img src="' . $PAGE_NEWSLETTER_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_SEARCH)
            echo_r('<img src="' . $PAGE_SEARCH_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else if ($page->GetType() == PAGETYPE_FORM)
            echo_r('<img src="' . $PAGE_FORM_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else
            echo_r('<img src="' . $PAGE_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        if ($page->GetType() == PAGETYPE_GALLERY)
        {
            echo  ('      <a href="' . $ADMIN_EDIT_GALLERY_SITE . '?id=' . $page->GetId() . '">');
            echo_r('<img src="' . $EDITGALLERY_IMAGE . '" title="' . get_translation('admin_pagecontl_editgallery') . '" alt=""></a>');
        }
        if ($page->GetType() == PAGETYPE_YOUTUBEGALLERY)
        {
            echo  ('      <a href="' . $ADMIN_EDIT_YOUTUBEGALLERY_SITE . '?id=' . $page->GetId() . '">');
            echo_r('<img src="' . $EDITYOUTUBEGALLERY_IMAGE . '" title="' . get_translation('admin_pagecontl_edityoutubegallery') . '" alt=""></a>');
        }
        if ($page->GetType() == PAGETYPE_LINKS)
        {
            echo  ('      <a href="' . $ADMIN_EDIT_LINKLIST_SITE . '?id=' . $page->GetId() . '">');
            echo_r('<img src="' . $EDITLINKLIST_IMAGE . '" title="' . get_translation('admin_pagecontl_editlinklist') . '" alt=""></a>');
        }
        if ($page->GetType() == PAGETYPE_FORM)
        {
            echo  ('      <a href="' . $ADMIN_EDIT_FORM_SITE . '?id=' . $page->GetId() . '">');
            echo_r('<img src="' . $EDITFORM_IMAGE . '" title="' . get_translation('admin_pagecontl_editform') . '" alt=""></a>');
        }
        if ($page->GetType() == PAGETYPE_GUESTBOOK)
        {
            echo  ('      <a href="' . $ADMIN_LIST_GUESTBOOK_SITE . '?id=' . $page->GetId() . '">');
            echo_r('<img src="' . $EDITGUESTBOOK_IMAGE . '" title="' . get_translation('admin_pagecontl_editguestbook') . '" alt=""></a>');
        }
        echo_r('    </td>');
        echo_r('    <td width="56%">');
        echo_r('    <table width="100%" border="0">');
        echo_r('      <tr>');
        echo_r('        <td width="50%">');
        if ($page->IsMainPage() == true)
            echo_r('       <b><i>' . get_translation('admin_page_title') . ': ' . $page->GetTitle() . '</i></b><br>');
        else
            echo_r('       <b>' . get_translation('admin_page_title') . ': ' . $page->GetTitle() . '</b><br>');
        echo_r('       ' . get_translation('admin_page_navtitle') . ': ' . $page->GetNavigationTitle() . '<br>');
        echo_r('       ' . get_translation('admin_page_navpositionlevel') . ' ' . $page->GetNavigationLevel() . ' [' . $page->GetNavigationPosition() . ']<br>');
        echo_r('        </td>');
        echo_r('        <td width="50%">');
        echo_r('       ' . get_translation('admin_page_id') . ' ' . $page->GetId() . '<br>');
        echo_r('       ' . get_translation('admin_page_modified') . ': ' . $page->GetModified() . '<br>');
        if ($page->GetNavigationShowLevel() != "")
            echo_r('       ' . get_translation('admin_page_showsnavlevel') . ': ' . $page->GetNavigationShowLevel());
		else
            echo_r('       ' . get_translation('admin_page_showsnavlevel') . ': <b>' . get_translation('admin_all') . '</b>');
        echo_r('        </td>');
        echo_r('      </tr>');
        echo_r('      <tr>');
        echo_r('        <td width="100%" colspan="2">');
        echo_r('       ' . get_translation('admin_page_filename') . ': <input type="text" size="45" value="' . $SITE_MAIN_SITE . '?page='. $page->GetId() . '" readonly><br>');
        echo_r('        </td>');
        echo_r('      </tr>');
        echo_r('    </table>');
        echo_r('    <td width="30%">');
        echo_r('       ' . get_translation('admin_page_viewcount') . ': ' . $page->GetViewCount() . '<br>');
        if ($ADMIN_HTMLPREVIEW == true)
        {
            echo_r('       <textarea cols="30" rows="3" readonly>');
            echo_r($textFile->LoadFromFile($page->GetContentFile()));
            echo_r('       </textarea>');
        }
        echo_r('    </td>');
        echo_r('  </tr>');
        echo_r('</table>');
    }
    print_bottom_links("pagel_Cancel", get_translation('admin_ok'));

    print_admin_footer();
?>