<?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    Core
 * @subpackage Forms
 */

/**
 */
include_once('config.inc.php');
include_once('classes/core/Site.class.php');
include_once('classes/core/forms/EditionForm.class.php');
include_once('classes/core/forms/UserForm.class.php');

include_once('classes/core/users/User.class.php');
include_once('classes/core/users/UsersManager.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');

/**
* PageEditionForm : edition form for Users
*
* @access   public
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	UserEditionForm.class, Sun Dec 26 16:41:28 CET 2004
* @package	Forms
*/
class UserEditionForm extends EditionForm {
	/**
	 * Class constructor.
	 *
	 * @access   public
 	 * @param    string    The mode in which the form is to be displayed.
 	 * @return   void
	 */
	function UserEditionForm(&$user, &$usersManager) {
		parent::EditionForm($user, $usersManager);
	}

	function populateUIContainer(&$guiContainer, $currLangId, $action) {
		if($action == ASK_DELETE_USER) {
			$summary = '';
      $invalid_users = array(USER_ID_ROOT, USER_ID_ADMIN, USER_ID_ANONYMOUS);
			$summary .= "<b>".LANG_USER_IDENTIFIER_STATIC." :</b> ".$this->object->getUserId();
			$summary .= "<br /><b>".LANG_USER_LOGIN_STATIC." :</b> ".$this->object->getUserLogin();
      if(in_array($this->object->getUserId(), $invalid_users)) {
        $summary .= "<br /><br /><font style=\"color: red;\"><b>".LANG_SYSTEM_OBJECT." :<br />".LANG_SYSTEM_OBJECT_DELETION_MESSAGE."</b></font>";
      }
			$txtLang = &new egStatic("sta_1", LANG_USER_DELETION_MESSAGE.LANG_COLON."<br /><br />".$summary."<br /><br />".LANG_USER_DELETION_CONFIRM, 20, 20, 300, 0);
			$guiContainer->addObject($txtLang);
		}
		else {
  		$previousTop = 40;

      $txtItemLogin = &new egStatic("txt_item_login", LANG_USER_LOGIN_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
      if($this->object->getUserId() > 0) {
        $objItemLogin = &new egStatic("obj_item_login", $this->object->getUserLogin(), 100, $previousTop, 290, 0);
      }
      else {
    		$objItemLogin = &new egEdit("obj_item_login", '', 100, $previousTop, 290, 18, 'login');
      }
  		$previousTop += 50;

      $txtItemPassword = &new egStatic("txt_item_password", LANG_USER_PASSWORD_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemPassword = &new egEdit("obj_item_password", '', 100, $previousTop, 290, 18, 'v_password', true);
  		$previousTop += 50;

      $txtItemConfirmation = &new egStatic("txt_item_confirmation", LANG_USER_CONFIRM_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemConfirmation = &new egEdit("obj_item_confirm", '', 100, $previousTop, 290, 18, 'confirm', true);
  		$previousTop += 50;

      $txtItemFirstname = &new egStatic("txt_item_firstname", LANG_USER_FIRSTNAME_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemFirstname = &new egEdit("obj_item_firstname", $this->object->getUserFirstname(), 100, $previousTop, 290, 18, 'firstname');
  		$previousTop += 50;

      $txtItemLastname = &new egStatic("txt_item_lastname", LANG_USER_LASTNAME_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemLastname = &new egEdit("obj_item_lastname", $this->object->getUserLastname(), 100, $previousTop, 290, 18, 'lastname');
  		$previousTop += 50;

      $txtItemEmail = &new egStatic("txt_item_email", LANG_USER_EMAIL_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemEmail = &new egEdit("obj_item_email", $this->object->getUserEmail(), 100, $previousTop, 290, 18, 'email');
  		$previousTop += 50;

  		$langsArray = $this->objectManager->getLangsArray();
      $txtItemLanguagesList = &new egStatic("txt_item_languages", LANG_USER_LANGUAGE_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemLanguagesList = &new egDropDownListBox("obj_item_languages", 100, $previousTop, 90, null, 'lang_id');

      foreach($langsArray as $langId => $langName) {
  			$objItemLanguagesList->addListItem(new egListItem("lti_lang_".$langId, $langName, null, $langId));
      }
      if($this->object->getUserId() > 0) {
        $objItemLanguagesList->setSelectedItemByValue($this->object->getUserLangId());
      }
      else {
        $objItemLanguagesList->setSelectedItemByValue($currLangId);
      }
  		$previousTop += 50;

      $txtItemHomepage = &new egStatic("txt_item_homepage", LANG_USER_HOMEPAGE_STATIC.LANG_COLON, 5, $previousTop, 90, 0, true);
  		$objItemHomepage = &new egEdit("obj_item_homepage", $this->object->getUserHomePageId(), 100, $previousTop, 305, 18, 'home_page_id');
  		$objItemHomepageButton = &new egPressbutton("obj_item_homepage_button", LANG_CHOOSE_BUTTON, 415, $previousTop-2, 90, null, "openWindow(\'admin/select_page.php?parent_control_name=obj_item_homepage_value\',425,450,0,0);");
  		$previousTop += 25;

  	  //var $disabled;

  		$guiContainer->addObject($txtItemLogin);
  		$guiContainer->addObject($objItemLogin);

  		$guiContainer->addObject($txtItemPassword);
  		$guiContainer->addObject($objItemPassword);

  		$guiContainer->addObject($txtItemConfirmation);
  		$guiContainer->addObject($objItemConfirmation);

  		$guiContainer->addObject($txtItemFirstname);
  		$guiContainer->addObject($objItemFirstname);

  		$guiContainer->addObject($txtItemLastname);
  		$guiContainer->addObject($objItemLastname);

  		$guiContainer->addObject($txtItemEmail);
  		$guiContainer->addObject($objItemEmail);

  		$guiContainer->addObject($txtItemLanguagesList);
  		$guiContainer->addObject($objItemLanguagesList);

  		$guiContainer->addObject($txtItemHomepage);
  		$guiContainer->addObject($objItemHomepage);
  		$guiContainer->addObject($objItemHomepageButton);

      $hiddenValuesContainer = &new egContainer("ctn_edt_ctn_hidden_values", 0, 0, 1, 1);
      $objHiddenPassword = &new egEdit("obj_hidden_control_password", '', 0, 0, 0, 0, 'password');

			$hiddenValuesContainer->addObject($objHiddenPassword);
			$guiContainer->addContainer($hiddenValuesContainer);


			$script = "
function validationFunction() {
  var inputPassword = document.getElementById('obj_item_password_value').value;
  var inputConfirm  = document.getElementById('obj_item_confirm_value').value;

  if(inputPassword != '') {
    if(inputPassword != inputConfirm) {
      window.alert('The confirmation password does not match the original password.');
      return false;
    }
    else {
      document.getElementById('obj_hidden_control_password_value').value = hex_md5(inputPassword);
      var inputPasswordItem = document.getElementById('obj_item_password_value');
      var inputConfirmItem  = document.getElementById('obj_item_confirm_value');

      for(i = 0; i < inputPassword.Length; ++i) {
        inputPasswordItem[i] = '0';
        inputConfirmItem[i] = '0';
      }
    }
  }
	return true;
}
";
      return $script;
    }
  }
}
?>