<?php

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

File:         list_pageimages.php
Description:  Administrative overview of all pageimages

*/

    include "../modules/class_pageimage.php";
    include "../modules/class_pageimagelist.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['pgil_Cancel']))
    {
        header ("location: " . $ADMIN_MAIN_SITE);
        return;
    }

    // Create new pageimage?
    if (isset ($_POST['pgil_CreatePageImage']))
    {
        header ('Location: ' . $ADMIN_EDIT_PAGEIMAGES_SITE . '?action=new');
        return;
    }
    // Edit pageimage?
    if (isset ($_POST['pgil_EditPageImage']))
    {
        header ('Location: ' . $ADMIN_EDIT_PAGEIMAGES_SITE . '?id=' . $_POST['pgil_PagImgId'] . '&action=edit');
        return;
    }
    // Delete pageimage?
    if (isset ($_POST['pgil_DeletePageImage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGEIMAGES_SITE . '?id=' . $_POST['pgil_PagImgId'] . '&action=delete');
        return;
    }
    // Lock pageimage?
    if (isset ($_POST['pgil_LockPageImage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGEIMAGES_SITE . '?id=' . $_POST['pgil_PagImgId'] . '&action=lock');
        return;
    }
    // Unlock pageimage?
    if (isset ($_POST['pgil_UnlockPageImage']))
    {
        header ('Location: ' . $ADMIN_MODIFY_PAGEIMAGES_SITE . '?id=' . $_POST['pgil_PagImgId'] . '&action=unlock');
        return;
    }

    // Display
    print_admin_header(get_translation('admin_pageimgl_head'), true, get_translation('admin_login_logout'), $ADMIN_HELP_FILE . '#n1-3', true, get_translation('admin_backtomain'));
    $pgi = new cPageImage;
    $pgiList = new cPageImageList;
    $pgiFilter = 0;
    if (isset ($_GET['filter']) && $_GET['filter'] != "")
        $pgiFilter = $_GET['filter'];
    else if (isset ($_POST['pgil_filter']) && $_POST['pgil_filter'] != "")
        $pgiFilter = $_POST['pgil_filter'];

    $pgi->SetFolder($PAGEIMAGES_FOLDER);
    $pgiList->SetFolder($PAGEIMAGES_FOLDER);
    $pgiList->LoadPageImageList($pgiFilter);

    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_pageimgl_createnew') . '" name="pgil_CreatePageImage"></td>');
    echo_r ('  <td width="10%">' . get_translation('admin_filter') . '</td>');
    echo_r ('  <td>');
    echo_r ('  <select name="pgil_filter" onChange="submit();">');
    echo   ('  <option value="' . $FILTER_ALL . '"');
    if ($pgiFilter == $FILTER_ALL)
        echo (' selected');
    echo_r ('>' . get_translation('admin_all') . '</option>');
    echo   ('  <option value="' . $FILTER_UNLOCKED . '"');
    if ($pgiFilter == $FILTER_UNLOCKED)
        echo (' selected');
    echo_r ('>' . get_translation('admin_unlocked') . '</option>');
    echo   ('  <option value="' . $FILTER_LOCKED . '"');
    if ($pgiFilter == $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>');

    $pgiList->SortByTitle(true);
    $listOfPageImages = $pgiList->GetPageImageList();
    // No entries?
    if (count($listOfPageImages) < 1)
        echo_r ('<p>&nbsp;' . get_translation('admin_noentries') . '<p>');
    for ($d = 0; $d < count($listOfPageImages); $d ++)
    {
        $pgi->LoadPageImageFromId($listOfPageImages[$d]);

        echo_r('<hr>');
        echo_r('<table width="100%" border="0">');
        echo_r('  <tr>');
        echo_r('    <td width="14%">');
        echo  ('      <a href="' . $ADMIN_EDIT_PAGEIMAGES_SITE . '?id=' . $pgi->GetId() . '&amp;action=edit">');
        echo_r(get_imagezoomed($pgi->GetImageFile(), $pgi->GetWidth(), $pgi->GetHeight(), $PAGEIMAGES_THUMB_WIDTH, $PAGEIMAGES_THUMB_WIDTH, get_translation('admin_edit'), "") . '</a>');
        if ($pgi->IsLocked() == true)
            echo_r('       <img src="' . $LOCKED_IMAGE . '" title="' . get_translation('admin_locked') . '" alt="">');
        echo_r('    </td>');
        echo_r('    <td width="56%">');
        echo_r('    <table width="100%" border="0">');
        echo_r('      <tr>');
        echo_r('        <td width="50%">');
        echo_r('       <b>' . get_translation('admin_pageimg_title') . ': ' . $pgi->GetTitle() . '</b><br>');
        echo_r('       ' . get_translation('admin_pageimg_orginname') . ': ' . $pgi->GetOriginName());
        echo_r('        </td>');
        echo_r('        <td width="50%">');
        echo_r('       ' . get_translation('admin_pageimg_id') . ': ' . $pgi->GetId() . '<br>');
        echo_r('       ' . get_translation('admin_pageimg_created') . ': ' . $pgi->GetDate() . '<br>');
        echo_r('        </td>');
        echo_r('      </tr>');
        echo_r('      <tr>');
        echo_r('        <td width="100%" colspan="2">');
        echo_r('       ' . get_translation('admin_pageimg_filename') . ': <input type="text" size="60" value="' . $pgi->GetImageFile() . '" readonly><br>');
        echo_r('        </td>');
        echo_r('      </tr>');
        echo_r('    </table>');

        echo_r('    </td>');
        echo_r('    <td width="30%">');
        echo_r('    <form method="post" action="">');
        echo_r('    <input type="hidden" value="' . $pgi->GetId() . '" name="pgil_PagImgId">  ');
        if (user_is_reporter() == false)
        {
            echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_edit') . '" name="pgil_EditPageImage">  ');
            if ($pgi->IsLocked() == true)
            {
                echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_unlock') . '" name="pgil_UnlockPageImage">  ');
            }
            else
            {
                echo_r('    <input type="submit" class="side_btn" value="' . get_translation('admin_lock') . '" name="pgil_LockPageImage">  ');
            }
        }
        if (user_is_admin() == true)
            echo_r('    <input type="submit"  class="side_btn" value="' . get_translation('admin_delete') . '" name="pgil_DeletePageImage">  ');
        echo_r('    </form>');
        echo_r('    </td>');
        echo_r('  </tr>');
        echo_r('</table>');
    }
    print_bottom_links("pgil_Cancel", get_translation('admin_ok'));

    print_admin_footer();
?>