<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * easy-CMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * @package Scripts
 */

// define the path context
chdir('..');
define('EASY_GUI_APP_DIR', '../');


include_once('config.inc.php');
include_once('classes/core/Site.class.php');

include_once('classes/system/Dir.class.php');
include_once('classes/system/File.class.php');

include_once('interface/egScript.class.php');
include_once('interface/egManager.class.php');
include_once('interface/egContainer.class.php');
include_once('interface/egMenuItem.class.php');
include_once('interface/egFrame.class.php');
include_once('interface/egToolTip.class.php');
include_once('interface/egRichText.class.php');
include_once('interface/egLink.class.php');
include_once('interface/egStatic.class.php');
include_once('interface/egEdit.class.php');
include_once('interface/egCheckBox.class.php');
include_once('interface/egRadioButton.class.php');
include_once('interface/egPressButton.class.php');
include_once('interface/egDropDownListBox.class.php');
include_once('interface/egPropertyList.class.php');
include_once('interface/egPropertySheet.class.php');
include_once('interface/egPropertyPage.class.php');
include_once('interface/egTreeNode.class.php');
include_once('interface/egTreeList.class.php');
include_once('interface/egSubWindow.class.php');


$site = &Site::getInstance(); // constructor checks the $_GET, $_POST and $_SESSION arrays

//security check : user must be identified to restore items
$user = $site->getCurrentUser();
if(ENABLE_ADMIN_AREA == 0 || is_null($user) || $user->getUserId() != USER_ID_ROOT) {
	die("You do not have permissions to create types: access denied.");
	exit();
}


$mode = $site->getSubmittedVar('mode', ASK_SHOW_DELETED_CONTENTS);


$manager = &egManager::getInstance();
$main = &new egContainer("main_ctn", 0, 0, 0, 0);

$treeListWidth = 450;
$treeListTop = 10;

$listContainer = &new egContainer("list_ctn", 12, $treeListTop+2, $treeListWidth-1, 476, true);
$frame = &new egFrame("fra_1", "", 10, $treeListTop, $treeListWidth, 480);

$vPos = 2;
$i = 0;

switch($mode) {
  case ASK_SHOW_DELETED_CONTENTS:
    $contentsManager = &$site->getContentsManager();
    $contentTypesFieldsArray = &$contentsManager->getContentTypesFields();

    $array_protected_types = array('gallery_photo', 'mailing_list', 'mailing_subscriber', 'mailing_message');
  
    foreach($contentTypesFieldsArray as $contentType => $fieldsArray) {

      if(!in_array($contentType, $array_protected_types)) {
        $typesManager = &$site->getTypesManager();
        $dbManipulator = &$site->getDBManipulator();
        $lang_id = $site->getDefaultLangId();
        
        if(($typeObj = &$typesManager->getType($contentType)) != null) {

          $result_array = $dbManipulator->getRecord($typeObj->getTableName(), -1, "`deleted`= 1 and `lang_id` = '$lang_id'");
          while($row = $dbManipulator->fetchArray($result_array)) {
            $action = "setSelectedContent(\'".$row['id']."\',\'".$contentType."\');";
            $link = &new egLink('content_type_'.$i, $contentType.' ('.$row['id'].')', 10, $vPos, 200, 18, $action, "interface/icons/icon_template.png");
            $listContainer->addObject($link);
          	$vPos += 20;
            ++$i;
          }
        }
      }
    }


    $contentStatic = &new egStatic("content_static", LANG_CONTENT_MENU_SELECTED." : ", 10, 500, 120, 0, true);
    $contentValue  = &new egStatic("content_value", "", 140, 500, 350, 0, false);

    $viewLink = &new egLink("lnk_view", LANG_CONTENT_VIEW, 470, 15, 200, 18, "launchContentViewWindow();", "interface/icons/page.png");
    $restoreLink = &new egLink("lnk_restore", LANG_CONTENT_RESTORE, 470, 35, 200, 18, "launchContentRestoreWindow();", "interface/icons/icon_trash.png");


    $main->addObject($contentStatic);
    $main->addObject($contentValue);

    $main->addObject($viewLink);
    $main->addObject($restoreLink);

    $scripts = new egScript();
    $line = "
    var selectedContentType = '';
    var selectedContentId = '';
    function launchContentViewWindow() {
    var vars = 'content_id=' + selectedContentId + '&type_name=' + selectedContentType + '&deleted=true';
    openWindow('../index.php?display=edit_content&mode=ask_modif_content&'+vars,540, 600, 0, 0);
    }
    function launchContentRestoreWindow() {
    var vars = 'content_id=' + selectedContentId + '&type_name=' + selectedContentType;
    openWindow('restore_item.php?'+'mode=ask_restore_content&'+vars,330, 150, 0, 0);
    }
    function setSelectedContent(id, type) {
    selectedContentType = type;
    selectedContentId = id;
    document.getElementById('content_value').innerHTML = selectedContentType + ', ' + selectedContentId;
    }
    ";

    $scripts->addLine($line);
    $manager->addScripts($scripts);
    break;
  case ASK_SHOW_DELETED_CONTAINERS:

    break;
}


$main->addObject($frame);
$main->addContainer($listContainer);
$manager->addContainer($main);
print($manager->getHTML());
?>