<?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('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 upload some file
$user = $site->getCurrentUser();
if(!$user || $user->getUserId() == USER_ID_ANONYMOUS) {
	die("access denied");
	exit();
}

$parentControlName	= $site->getSubmittedVar('parent_control_name');
$parentControlName2	= $site->getSubmittedVar('parent_control_name2');
$mode 							= $site->getSubmittedVar('mode');

$treeListWidth = 356;
$treeListTop = 30;

if($mode == 'admin') {
  $treeListWidth = 660;
	$treeListTop = 10;
}

	$usersManager = &$site->getUsersManager();

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

	$listContainer = &new egContainer("list_ctn", 10, $treeListTop+2, $treeListWidth-1, 250, true);
	$frame = &new egFrame("fra_1", "", 10, $treeListTop, $treeListWidth, 255);
	$main->addObject($frame);
	$main->addContainer($listContainer);

	$usersArray = $usersManager->getUsersArrayForDisplay();

if($mode != 'admin') {
	$txtTitle = &new egStatic("sta_1", LANG_USER_CHOOSE_STATIC, 10, 10, 250, 0, true);
	$main->addObject($txtTitle);
}

	$vPos = 2;

	foreach ($usersArray as $userId => $userLogin) {
    $link = &new egLink("user_link_".$userId, $userLogin, 10, $vPos, 200, 18, "selectUser($userId, \'$userLogin\')", 'interface/icons/icon_user.png');
    $listContainer->addObject($link);
		$vPos += 20;
	}

	$userNameStatic = &new egStatic("user_name_static", LANG_USER_MENU_SELECTED." : ", 10, 290, 150, 0, true);
	$userNameValue  = &new egStatic("user_name_value", "", 160, 290, 350, 0, false);

if($mode != 'admin') {
	$okButton = &new egPressbutton("btn_ok", "Ok", 210, 320, 80, null, "clickOKButton();");
	$cancelButton = &new egPressbutton("btn_cancel", "Cancel", 295, 320, 80, null, "clickCancelButton();");
	$main->addObject($okButton);
	$main->addObject($cancelButton);
}

if($mode == 'admin') {
	$linkAdd	 		= &new egLink("lnk_add", LANG_USER_MENU_ADD, 160, 320, 250, 18, "launchUserCreationWindow()", "interface/icons/icon_add_user.png");
	$linkRemove		= &new egLink("lnk_remove", LANG_USER_MENU_REMOVE, 160, 340, 250, 18, "launchUserDeletionWindow()", "interface/icons/remove.png");
	$linkEdit 		= &new egLink("lnk_edit", LANG_USER_MENU_EDIT, 160, 360, 200, 18, "launchUserEditionWindow()", "interface/icons/edit.png");

	$main->addObject($linkAdd);
	$main->addObject($linkRemove);
	$main->addObject($linkEdit);
}


	$main->addObject($userNameStatic);
	$main->addObject($userNameValue);


	$scripts = new egScript();
	$line = "
var userid = 0;
var username = '';
function selectUser(id, name) {
	userid = id;
	username = name;
	document.getElementById('user_name_value').innerHTML = name;
}
function clickOKButton() {
	sendResponse();
}
function clickCancelButton() {
	window.close();
}
function sendResponse() {
	window.opener.document.getElementById('".$parentControlName."').value = userid;
	window.opener.document.getElementById('".$parentControlName2."').value = username;
	window.close();
}
function launchUserCreationWindow() {
  openWindow('../index.php?display=edit_user&mode=ask_modif_user&user_id=0',540, 600, 0, 0);
}
function launchUserDeletionWindow() {
  openWindow('../index.php?display=edit_user&mode=ask_delete_user&user_id='+userid,380, 280, 0, 0);
}
function launchUserEditionWindow() {
  openWindow('../index.php?display=edit_user&mode=ask_modif_user&user_id='+userid,540, 600, 0, 0);
}
";

	$scripts->addLine($line);
	$manager->addScripts($scripts);

	$manager->addContainer($main);
	echo $manager->getHTML();

?>