uid = $uid; if ($user->getId()==$uid) { $this->uid = $user->getId(); $this->org = $user->isOrg(); $this->setUname($user->getUsername()); $this->setFirstname($user->getDetails()->getFirstname()); $this->setLastname($user->getDetails()->getLastname()); $this->setOrganization($user->getDetails()->getOrganization()); $this->setEmail($user->getDetails()->getEmail()); } $this->error = array(); } public function getId() { return $this->uid; } public function getUname() { return $this->uname; } function setUname($val) { if ($val!="") { $this->uname = $val; } else { $this->raiseError("uname"); } } public function getFirstname() { return $this->firstname; } function setFirstname($val) { if ($val!="") { $this->firstname = $val; } else { $this->raiseError("fname"); } } public function getLastname() { return $this->lastname; } function setLastname($val) { if ($val!="") { $this->lastname = $val; } else { $this->raiseError("lname"); } } public function getFullname() { return $this->getFristname()." ".$this->getLastname(); } public function getEmail() { return $this->email; } public function checkError($err) { if ( in_array($err, $this->error) ) { return true; } return false; } function setEmail($val) { if ($val!="") { $this->email = $val; } else { $this->raiseError("email"); } } public function getOrganization() { return $this->organization; } function setOrganization($val) { if ($val!="") { $this->organization = $val; } } function setPassword($pwd1, $pwd2) { if ($pwd1=="") { $this->raiseError("salasona"); } if ($pwd2=="") { $this->raiseError("sonasala"); } else if ($pwd1!=$pwd2){ // not match } else { $this->pwd = $pwd1; } } private function getPassword() { return $this->pwd; } private function raiseError($err) { $this->error []= $err; } public function isOrg() { return $this->org; } function save() { if (!$this->error) { global $kdb; //print $this->getId(); if ($this->getId()==-1) { $organ = 0; if ( $this->getOrganization()!="" ){ $organ = 1; } $kdb->query("INSERT INTO users (uname, pwd, org, registred) values ('".$this->getUname()."', '".$this->getPassword()."',".$organ.", 1)"); $lid = mysql_insert_id(); $kdb->query("INSERT INTO userinfo (userid, language, firstname, lastname, organization, email) values (".$lid.", '".DEFAULT_LANGUAGE."', '".$this->getFirstname()."', '".$this->getLastname()."', '".$this->getOrganization()."', '".$this->getEmail()."')"); $_SESSION['userid'] = $lid; header("Location:index.php"); } else { $kdb->query("UPDATE users set uname='".$this->getUname()."', pwd='".$this->getPassword()."', registred=1 WHERE id=".$this->getId()); $kdb->query("UPDATE userinfo set firstname='".$this->getFirstname()."', lastname='".$this->getLastname()."', organization='".$this->getOrganization()."', email='".$this->getEmail()."' WHERE id=".$this->getId()); } if ( isset($_SESSION['last_page']) ) { $_SESSION['page'] = $_SESSION['last_page']; } else { $_SESSION['page'] = "index"; } header("Location:index.php"); } } public function getCategory() { return 1; } } $register = new Register(-1); if ( isset($_SESSION['userid']) ) { $register = new Register($_SESSION['userid']); } if ( isset($_POST['actionSave']) && $_SESSION['page']=="register") { $register->setUname($_POST['uname']); $register->setFirstname($_POST['fname']); $register->setLastname($_POST['lname']); if ($register->isOrg()) { $register->setOrganization($_POST['org']); } $register->setEmail($_POST['email']); $register->setPassword($_POST['salasona'],$_POST['sonasala']); $register->save(); } else if ( isset($_POST['actionCancel']) ) { if ( isset($_SESSION['last_page']) ) { $_SESSION['page'] = $_SESSION['last_page']; } else { $_SESSION['page'] = 'index'; } header("Location:index.php"); } $kesa->setTemplate("register.html"); $kesa->setPage($register); ?>