<?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
 */

// 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();

//security check : user must be identified to browse repositories
$user = $site->getCurrentUser();
if(ENABLE_ADMIN_AREA == 0 || is_null($user) || $user->getUserId() == USER_ID_ANONYMOUS || !$user->checkGroupMembership(GROUP_ID_ADMINS)) {
	die("You do not have permissions to access the administation area: access denied.");
	exit();
}

$containersManager = &$site->getContainersManager();
$langs_array = $containersManager->getLangsArray();
$currLangId = $site->getCurrentLangId();

$manager = &egManager::getInstance("Administration panel");
$main = &new egContainer("main_ctn", 0, 0, 0, 0);
$manager->addContainer($main);

$homeLink   = &new egLink("home_lnk", LANG_ADMIN_MANAGER_HOME_TITLE, 10, 10, 180, 18, "window.location=\'../index.php\'", "interface/icons/icon_home.png");
$adminLink = &new egLink("config_lnk", LANG_ADMIN_MANAGER_CONFIG_TITLE, 190, 10, 200, 18, "window.location=\'./config.php\'", "interface/icons/icon_config.png");
$vPos = 60;


$langList = &new egDropDownPropertyList("ddl_lang_1", "Language", 470, 10, 80);
$txtLang = &new egStatic("sta_1", LANG_LANGUAGE_LISTBOX.' :', 400, 10, 80, 0, true);
$main->addObject($langList);
$main->addObject($txtLang);

$i = 0;
foreach($langs_array as $lid => $lang_name) {
  $editionContainer = &new egContainer('edt_ctn_'.$lid, 550, 10, 500, 50, false);
  $main->addContainer($editionContainer);
  $langList->addListItem(new egPropertyPage('lti_'.$lid, ucfirst($lang_name), $editionContainer->getContainerName()));
  $langLink = &new egLink("lang_lnk_$i", "go", 0, 0, 70, 18, "window.location=\'?lid=$lid\';", "");
  $editionContainer->addObject($langLink);
  if($lid == $currLangId) {
    $langList->setSelectedItemByLabel(ucfirst($lang_name));
  }
  ++$i;
}

/*
 *
 * left pane
 *
 */

// file manager
$fileManagerStatic = &new egStatic("file_man_static", "&bull;&nbsp;".LANG_ADMIN_MANAGER_FILES_TITLE, 10, $vPos, 350, 0, true);
$vPos += 20;
// images repository
$imgLink = &new egLink("img_man_lnk", LANG_ADMIN_MANAGER_IMAGES_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_file.php?mode=admin&repository_type=".IMAGES_FOLDER."\'", "interface/icons/icon_folder_images.png");
$vPos += 20;
// documents repository
$docLink = &new egLink("doc_man_lnk", LANG_ADMIN_MANAGER_DOCS_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_file.php?mode=admin&repository_type=".DOCUMENTS_FOLDER."\'", "interface/icons/icon_folder_documents.png");
$vPos += 20;


$vPos += 20;

// contents manager
$contentsManagerStatic = &new egStatic("content_man_static", "&bull;&nbsp;".LANG_ADMIN_MANAGER_CONTENTS_TITLE, 10, $vPos, 350, 0, true);
$vPos += 20;
// page repository
$pageLink = &new egLink("page_man_lnk", LANG_ADMIN_MANAGER_PAGES_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_page.php?mode=admin\'", "interface/icons/icon_web_page.png");
$vPos += 20;


$vPos += 20;

// groups & users manager
$usersAndGroupsManagerStatic = &new egStatic("groups_and_users_man_static", "&bull;&nbsp;".LANG_ADMIN_MANAGER_GROUPS_AND_USERS_TITLE, 10, $vPos, 350, 0, true);
$vPos += 20;
// groups
$groupsLink = &new egLink("groups_man_lnk", LANG_ADMIN_MANAGER_GROUPS_TITLE, 30, $vPos, 350, 18, "document.getElementById(\'sbw_1\').src=\'select_group_user.php?mode=admin\'", "interface/icons/icon_group.png");
$vPos += 20;
// users
$usersLink = &new egLink("users_man_lnk", LANG_ADMIN_MANAGER_USERS_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_user.php?mode=admin\'", "interface/icons/icon_user.png");
$vPos += 20;


$vPos += 20;

if(ENABLE_NEWSLETTER == 1) {
	// mailingList manager
	$mailingListsManagerStatic = &new egStatic("mailing_man_static", "&bull;&nbsp;".LANG_MAILING_LIST_MANAGER_TITLE, 10, $vPos, 350, 0, true);
	$vPos += 20;
	// mailing lists
	$mailingListsLink = &new egLink("ml_lnk", LANG_MAILING_LIST_MANAGER_ML_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_ml.php?mode=admin\'", "interface/icons/icon_ml.png");
	$vPos += 20;
	// subscribers
	$subscribersLink = &new egLink("ml_subscribers_lnk", LANG_MAILING_LIST_MANAGER_SUBSCRIBERS_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_subscriber.php?mode=admin\'", "interface/icons/icon_user.png");
	$vPos += 20;
	// newsletters
	$newslettersLink = &new egLink("ml_newsletters_lnk", LANG_MAILING_LIST_MANAGER_NEWSLETTERS_TITLE, 30, $vPos, 300, 18, "document.getElementById(\'sbw_1\').src=\'select_newsletter.php?mode=admin\'", "interface/icons/icon_newsletter.png");
	$vPos += 20;

	$vPos += 20;
}


// storage manager
$websiteStatusStatic = &new egStatic("website_status_static", "&bull;&nbsp;".LANG_ADMIN_MANAGER_DISK_TITLE, 10, $vPos, 350, 0, true);
$vPos += 20;
// usage
$diskUsageLink = &new egLink("du_man_lnk", LANG_ADMIN_MANAGER_DISK_USAGE, 30, $vPos, 350, 18, "document.getElementById(\'sbw_1\').src=\'show_disk_usage.php\'", "interface/icons/disk_use.png");
$vPos += 20;


$vPos += 20;



/*
 *
 * right pane
 *
 */

$fameTop    = 60;
$fameLeft   = 230;
$fameWidth  = 680;
$fameHeight = 550;

$frame = &new egFrame("fra_1", "frame 1", $fameLeft, $fameTop, $fameWidth, $fameHeight);
$subWindow = &new egSubWindow("sbw_1", "look_at_left.php", $fameLeft+1, $fameTop+1, $fameWidth-2, $fameHeight-2);


$main->addObject($homeLink);
if($user->getUserId() == USER_ID_ROOT) {
  $main->addObject($adminLink);
}


$main->addObject($fileManagerStatic);
$main->addObject($imgLink);
$main->addObject($docLink);
$main->addObject($contentsManagerStatic);
$main->addObject($pageLink);

$main->addObject($usersAndGroupsManagerStatic);
$main->addObject($groupsLink);
$main->addObject($usersLink);

$main->addObject($mailingListsManagerStatic);
$main->addObject($mailingListsLink);
$main->addObject($subscribersLink);
$main->addObject($newslettersLink);


$main->addObject($websiteStatusStatic);
$main->addObject($diskUsageLink);


$main->addObject($frame);
$main->addObject($subWindow);

$scripts = new egScript();
$line = "
function refreshFrame() {
	var temp = document.getElementById('sbw_1').src;
	document.getElementById('sbw_1').src = '';
	document.getElementById('sbw_1').src = temp;
}
";
$scripts->addLine($line);

$manager->addScripts($scripts);


echo $manager->getHTML();

?>