Location: PHPKode > projects > PhpwdManager > phpwdmanager/contents/profile.php
<?php

//user profile
require_once("includes/config.inc.php");

class profile extends menu
{
	//page events
	private $sign = false;
	
	function onInit($param)
	{
		parent::onInit($param);
		
		$title = "User Profile";
		$this->title->setText($title);
	}
	
	function onLoad($param)
	{
		$this->sign = (isset($_GET['sign'])?true:false);
		
		if ($this->sign === false)
		{
			parent::onLoad($param);
		
			if (!$this->isPostBack())
			{
				//obter os dados do user
				$this->username->setText($this->User->getUsername());
			}
		}
		else
		{
			$this->setLanguage();
			$this->title->setText(ucwords($this->tr->getString("title_sign", "Signning In...User profile")));
			$this->refresh->setText(ucwords($this->tr->getString("cancel", "Cancel")));
		}
		
		/*else //new user registration
		{
			$title = "Signning In...User profile";
			$this->Form_profile->refresh->setText("Cancel");
		}*/
			
		//$this->title->setText($title);
	}
	
	//action functions
	function onSave($sender, $param)
	{
		$sql = null;
		$query = null;
		$msg = null;
		
		if ($this->isValid()) //verificar se todas as validacoes foram validadas
		{
			if ($this->sign === false)
			{
				$sql = "update users" . 
					   " set user_login = '" . strtoupper(trim($this->username->Text)) . "'" .
					   ", user_password = '" . md5(strtoupper($this->password->Text)) . "'" .
					   " where user_id = " . $this->User->getUserId() . " ;";
			}
			else
			{
				$sql = "insert into users (user_login, user_password)" .
					   " values ('" . strtoupper(trim($this->username->Text)) . "'" . 
					   ", '" . md5(strtoupper($this->password->Text)) . "') ;";
			}
			
			$query = &$this->db->query($sql);
			if (!DB::isError($query))
				$query = $this->db->commit();
			
			if (DB::isError($query))
			{
				$this->db->rollback();
				$msg = "Error updating user profile." . $query->getMessage();
				$query = -1;
				$this->onError($msg);
			}
			else if ($this->sign === false)
			{
				$this->User->setUsername($this->username->Text);
				$this->password->setText('');
				$this->confirmation->setText('');
			}
			else
			{
				$this->Application->transfer("login");
			}
		}
	}
	
	function onValidateUsername($sender, $param)
	{
		
		$sql = "select count(user_login) from users " . 
			   " where user_login = '" . trim($this->username->Text) . "'";
		
		if ($this->sign === false)
			   $sql = "$sql and user_id <> " . $this->User->getUserId();
			   
		$sql = "$sql ;";
		echo($sql);	   
		$query = $this->db->getOne($sql);
		if (DB::isError($query))
			$this->onError("Error validating the username." . $query->getMessage() . 
						   "<br><font size='1'>(syntax: $sql)</font>");
		else if ($query > 0)
			$param->isValid = false;
	}
	
	function onValidateConfirmation($sender, $param)
	{
		if ($this->password->Text !== $this->confirmation->Text)
		{
			$this->password->setText('');
			$this->confirmation->setText('');
			$param->isValid = false;
		}
	}
	
	function onRefresh($sender, $param)
	{
		if ($this->sign === false)
		{
			$this->username->setText($this->User->getUsername());
			$this->password->setText('');
			$this->confirmation->setText('');
		}
		else //in case of a new user registration, it logout and then returns to the login page
			$this->Application->transfer("logout");
	}
}

?>
Return current item: PhpwdManager