<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOOPS_ROOT_PATH."/class/XCube_ActionForm.class.php";

/**
 * This class is generated by makeActionForm tool.
 * @auchor makeActionForm
 */
class EditUserForm extends XCube_ActionForm 
{
	function getTokenName()
	{
		return "Module.User.EditUserForm.Token." . $this->get('uid');
	}
	
	function prepare()
	{
		// set properties
		$this->mFormProperties['uid']=new XCube_IntProperty('uid');
		$this->mFormProperties['name']=new XCube_StringProperty('name');
		$this->mFormProperties['email']=new XCube_StringProperty('email');
		$this->mFormProperties['user_viewemail']=new XCube_IntProperty('user_viewemail');
		$this->mFormProperties['url']=new XCube_StringProperty('url');
		$this->mFormProperties['user_icq']=new XCube_StringProperty('user_icq');
		$this->mFormProperties['user_aim']=new XCube_StringProperty('user_aim');
		$this->mFormProperties['user_yim']=new XCube_StringProperty('user_yim');
		$this->mFormProperties['user_msnm']=new XCube_StringProperty('user_msnm');
		$this->mFormProperties['user_from']=new XCube_StringProperty('user_from');
		$this->mFormProperties['user_occ']=new XCube_StringProperty('user_occ');
		$this->mFormProperties['user_intrest']=new XCube_StringProperty('user_intrest');
		$this->mFormProperties['user_sig']=new XCube_TextProperty('user_sig');
		$this->mFormProperties['attachsig']=new XCube_IntProperty('attachsig');
		$this->mFormProperties['bio']=new XCube_TextProperty('bio');
		$this->mFormProperties['pass']=new XCube_StringProperty('pass');
		$this->mFormProperties['vpass']=new XCube_StringProperty('vpass');
		$this->mFormProperties['user_mailok']=new XCube_IntProperty('user_mailok');

		// set fields
		$this->mFieldProperties['name']=new XCube_FieldProperty($this);
		$this->mFieldProperties['name']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['name']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_REALNAME,"60");
		$this->mFieldProperties['name']->addVar("maxlength",60);

		$this->mFieldProperties['email']=new XCube_FieldProperty($this);
		$this->mFieldProperties['email']->setDependsByArray(array('required','maxlength'));
		$this->mFieldProperties['email']->addMessage("required",_MD_USER_ERROR_REQUIRED,_US_EMAIL,"60");
		$this->mFieldProperties['email']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_EMAIL,"60");
		$this->mFieldProperties['email']->addVar("maxlength",60);

		$this->mFieldProperties['user_viewemail']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_viewemail']->setDependsByArray(array('intRange'));
		$this->mFieldProperties['user_viewemail']->addMessage("intRange",_MD_USER_ERROR_INTRANGE,"user_viewemail");
		$this->mFieldProperties['user_viewemail']->addVar("min",0);
		$this->mFieldProperties['user_viewemail']->addVar("max",1);

		$this->mFieldProperties['url']=new XCube_FieldProperty($this);
		$this->mFieldProperties['url']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['url']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_WEBSITE,"100");
		$this->mFieldProperties['url']->addVar("maxlength",100);

		$this->mFieldProperties['user_icq']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_icq']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['user_icq']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_ICQ,"15");
		$this->mFieldProperties['user_icq']->addVar("maxlength",15);

		$this->mFieldProperties['user_from']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_from']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['user_from']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_LOCATION,"100");
		$this->mFieldProperties['user_from']->addVar("maxlength",100);

		$this->mFieldProperties['user_aim']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_aim']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['user_aim']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_AIM,"18");
		$this->mFieldProperties['user_aim']->addVar("maxlength",18);

		$this->mFieldProperties['user_msnm']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_msnm']->setDependsByArray(array('maxlength'));
		$this->mFieldProperties['user_msnm']->addMessage("maxlength",_MD_USER_ERROR_MAXLENGTH,_US_MSNM,"100");
		$this->mFieldProperties['user_msnm']->addVar("maxlength",100);

		$this->mFieldProperties['attachsig']=new XCube_FieldProperty($this);
		$this->mFieldProperties['attachsig']->setDependsByArray(array('intRange'));
		$this->mFieldProperties['attachsig']->addMessage("intRange",_MD_USER_ERROR_INTRANGE,"attachsig");
		$this->mFieldProperties['attachsig']->addVar("min",0);
		$this->mFieldProperties['attachsig']->addVar("max",1);

		$this->mFieldProperties['user_mailok']=new XCube_FieldProperty($this);
		$this->mFieldProperties['user_mailok']->setDependsByArray(array('intRange'));
		$this->mFieldProperties['user_mailok']->addMessage("intRange",_MD_USER_ERROR_INTRANGE,"user_mailok");
		$this->mFieldProperties['user_mailok']->addVar("min",0);
		$this->mFieldProperties['user_mailok']->addVar("max",1);
	}
	
	function validatePass()
	{
		if(strlen($this->getVar('pass'))>0||strlen($this->getVar('vpass'))>0)
			if($this->getVar('pass')!=$this->getVar('vpass')) {
				$this->addErrorMessage(_MD_USER_ERROR_PASSWORD);
				$this->set('pass',null);	// reset
				$this->set('vpass',null);
			}
	}
	
	function load(&$user)
	{
		//Corner-cutting
		$vars=$user->getProperties();
		foreach($vars as $key=>$val) {
			$this->set($key,$val);
		}

		$this->set('pass',null);
		$this->set('vpass',null);
	}
	
	function update(&$user)
	{
		$user->set('name',$this->getVar('name'));
		$user->set('email',$this->getVar('email'));
		$user->set('user_viewemail',$this->getVar('user_viewemail'));
		$user->set('url',$this->getVar('url'));
		$user->set('user_icq',$this->getVar('user_icq'));
		$user->set('user_aim',$this->getVar('user_aim'));
		$user->set('user_yim',$this->getVar('user_yim'));
		$user->set('user_msnm',$this->getVar('user_msnm'));
		$user->set('user_from',$this->getVar('user_from'));
		$user->set('user_occ',$this->getVar('user_occ'));
		$user->set('user_intrest',$this->getVar('user_intrest'));
		$user->set('user_sig',$this->getVar('user_sig'));
		$user->set('attachsig',$this->getVar('attachsig'));
		$user->set('user_sig',$this->getVar('user_sig'));
		$user->set('bio',$this->getVar('bio'));
		$user->set('user_mailok',$this->getVar('user_mailok'));
		
		if($this->getVar('pass'))
			$user->set('pass',md5($this->getVar('pass')));
	}
}

?>
