<?php

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

File:         list_pages.php
Description:  Administrative overview of all pages

*/

    include "../modules/class_page.php";
    include "../modules/class_pagelist.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;
    }

    // Create new page?
    if (isset ($_POST['pagel_CreatePage']))
    {
        header ('Location: ' . $ADMIN_EDIT_PAGES_SITE . '?action=new');
        return;
    }
    // Edit page?
    if (isset ($_POST['pagel_EditPage']))
    {
        header ('Location: ' . $ADMIN_EDIT_PAGES_SITE . '?id=' . $_POST['pagel_PageId'] . '&action=edit');
        return;
    }
    // Delete page?
    if (isset ($_POST['pagel_DeletePage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGES_SITE . '?id=' . $_POST['pagel_PageId'] . '&action=delete');
        return;
    }
    // Lock page?
    if (isset ($_POST['pagel_LockPage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGES_SITE . '?id=' . $_POST['pagel_PageId'] . '&action=lock');
        return;
    }
    // Unlock page?
    if (isset ($_POST['pagel_UnlockPage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGES_SITE . '?id=' . $_POST['pagel_PageId'] . '&action=unlock');
        return;
    }

    // Display
    print_admin_header(get_translation('admin_pagel_head'), true, get_translation('admin_login_logout'), $ADMIN_HELP_FILE . '#n1-2', true, get_translation('admin_backtomain'));
    $page = new cPage;
    $pageList = new cPageList;
    $pageFilter = 0;
    if (isset ($_GET['filter']) && $_GET['filter'] != "")
        $pageFilter = $_GET['filter'];
    else if (isset ($_POST['pagel_filter']) && $_POST['pagel_filter'] != "")
        $pageFilter = $_POST['pagel_filter'];

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

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

    echo_r ('<form method="post" action="">');
    echo_r ('<table border="0" width="100%">');
    echo_r ('<tr>');
    echo_r ('  <td width="20%"><input type="submit" class="bottom_btn" value="' . get_translation('admin_pagel_createnew') . '" name="pagel_CreatePage"></td>');
    echo_r ('  <td width="10%">' . get_translation('admin_filter') . '</td>');
    echo_r ('  <td>');
    echo_r ('  <select name="pagel_filter" onChange="submit();">');
    echo   ('  <option value="' . $FILTER_ALL . '"');
    if ($pageFilter == $FILTER_ALL)
        echo (' selected');
    echo_r ('>' . get_translation('admin_all') . '</option>');
    echo   ('  <option value="' . $FILTER_UNLOCKED . '"');
    if ($pageFilter == $FILTER_UNLOCKED)
        echo (' selected');
    echo_r ('>' . get_translation('admin_unlocked') . '</option>');
    echo   ('  <option value="' . $FILTER_LOCKED . '"');
    if ($pageFilter == $FILTER_LOCKED)
        echo (' selected');
    echo_r ('>' . get_translation('admin_locked') . '</option>');
    echo_r ('  </select>');
    echo_r ('  </td>');
    echo_r ('</tr>');
    echo_r ('</table>');
    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);

        echo_r('<hr>');
        echo_r('<table width="100%" border="0">');
        echo_r('  <tr>');
        echo_r('    <td width="14%">');
        echo  ('      <a href="' . $ADMIN_EDIT_PAGES_SITE . '?id=' . $page->GetId() . '&amp;action=edit">');
        if ($page->GetType() == PAGETYPE_LINK)
            echo_r('<img src="' . $PAGE_LINK_IMAGE . '" title="' . get_translation('admin_edit') . '" alt=""></a>');
        else 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->IsLocked() == true)
            echo_r('       <img src="' . $LOCKED_IMAGE . '" title="' . get_translation('admin_locked') . '" alt="">');
        echo_r('    </td>');
        echo_r('    <td width="28%">');
        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>');
        if ($page->ShowInNavigation() == true)
            echo_r('       ' . get_translation('admin_page_navpositionlevel') . ': ' . $page->GetNavigationLevel() . ' [' . $page->GetNavigationPosition() . ']<br>');
        else
            echo_r('       <i>' . get_translation('admin_page_notinnavigation') . '</i><br>');
        echo_r('    </td>');
        echo_r('    <td width="28%">');
        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('    <td width="30%">');
        echo_r('    <form method="post" action="">');
        echo_r('    <input type="hidden" value="' . $page->GetId() . '" name="pagel_PageId">  ');
        if (user_is_reporter() == false)
        {
            echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_edit') . '" name="pagel_EditPage">  ');
            if ($page->IsLocked() == true)
            {
                echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_unlock') . '" name="pagel_UnlockPage">  ');
            }
            else
            {
                echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_lock') . '" name="pagel_LockPage">  ');
            }
        }
        if ($page->IsDeleteProtected() == false)
            echo_r('    <input type="submit"  class="side_btn" value="' . get_translation('admin_delete') . '" name="pagel_DeletePage">  ');
        echo_r('    </form>');
        echo_r('    </td>');
        echo_r('  </tr>');
        echo_r('  <tr>');
        echo_r('    <td></td>');
        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>');
    }
    print_bottom_links("pagel_Cancel", get_translation('admin_ok'));

    print_admin_footer();
?>