<?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/types/Date.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/egDropDownPropertyList.class.php');
include_once('interface/egPropertyList.class.php');
include_once('interface/egPropertySheet.class.php');
include_once('interface/egPropertyPage.class.php');


$site = &Site::getInstance();

//security check : user must be ROOT 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 restore items: access denied.");
	exit();
}

$mode 		  = $site->getSubmittedVar('mode');
$content_id = $site->getSubmittedVar('content_id');
$type_name	= $site->getSubmittedVar('type_name');

$typesManager = &$site->getTypesManager();

$manager = &egManager::getInstance();
$main = &new egContainer("main_ctn", 0, 0, 0, 0);
$manager->addContainer($main);
	
switch($mode) {
  case ASK_RESTORE_CONTENT:
  case RESTORE_CONTENT:

    $contentsManager = &$site->getContentsManager();
    $contentsManager->restoreContent($content_id, $type_name);

		$scripts = &new egScript();
	  $line = "window.opener.location.reload();window.close();";
		$scripts->addLine($line);
		$manager->addScripts($scripts);
    break;
}
print($manager->getHTML());
?>