<?php
/*
UWAGA: wszystkie zapytanie sql sformatować odpowiednio dla adodb
*/
require_once("../core/adodb/adodb.inc.php");
class TUser {
private $user_id=-1;
private $nick ="";
private $name= "";
private $group_id=0;
private $password="";
private $password_crypt="";
private $email="";
private $gg="";
private $photo="";
private $description="";
private $phone="";
private $last_error="";
private $is_error=0; //0 - no error, 1 - error
################################## need to update all validation functions #####
##############################
/********************************************************************************
*****
VALIDATE FUNCTIONS
********************************************************************************
*****/
public function validateName($name) {
// validate if name is correct, name have 2 words which begin with uppercase and s
pace beetween of them
if (ereg("^[A-z](a-zA-Z/-)*( A-Za-z/-)*",$name)) { $this->unsetError();
return true;
}
else {
$this->last_error = "NO_VALID_NAME";
$this->setError();
return false;
}
}
public function validateEmail() {
//validate if email is correct
if (eregi("^([a-z0-9_-.]{1,25})@([a-z0-9_-.]){1,25}$",$this->$email)){ $this->unsetError();
return true;
}
else {
$this->last_error = "NO_VALID_EMAIL";
$this->setError();
return false;
}
}
public function validatePassword($pass) {
//6-25 signs, one big letter and one number
if (ereg("[A-Za-z0-9]")) { $this->setError();
return true;
}
else {
$this->last_error = "NO_VALID_PASSWORD";
$this->setError();
return false;
}
}
/********************************************************************************
*****
COMPARE FUNCTIONS
********************************************************************************
*****/
public function comparePassword($value="") {
if ($this->password == $value) {
$this->unsetError();
return true;
}
else {
$this->last_error = "PASSWORD_NOT_SAME";
$this->unsetError();
return false;
}
}
/********************************************************************************
*****
GET FUNCTIONS
********************************************************************************
*****/
public function getUserInfo(){
return $this;
}
/********************************************************************************
*****
SET FUNCTIONS
********************************************************************************
*****/
public function setError(){
$this->is_error = 1;
}
public function unsetError(){
$this->is_error = 0;
}
public function setUserID($value="") {
$this->user_id = $value;
}
public function setNick($value="") {
$this->nick = $value;
}
public function setName($value="") {
$this->name = $value;
}
public function setGroupID($value="") {
$this->group_id = $value;
}
public function setPassword($value="") {
$this->password = $value;
}
public function setEmail($value="") {
$this->email = $value;
}
public function setGG($value="") {
$this->gg = $value;
}
public function setPhoto($value="") {
$this->phone = $value;
}
public function setDescription($value="") {
$this->description = $value;
}
public function setPhone($value="") {
$this->phone = $value;
}
public function setUserFromSQL($table){
//set user data using result form SQL query
$this->user_id = $table["id_user"];
$this->nick = $table["nick"];
$this->name = $table["name"];
$this->group_id = $table["name"];
$this->password = $table["password"];
$this->password_crypt = md5($table["password"]); $this->email = $table["email"];
$this->gg = $table["gg"];
$this->photo = $table["photo"];
$this->description = $table["description"];
$this->phone = $table["phone"];
$this->last_error = "";
$this->is_error = "0"; //no error
}
public function __construct() {
$this->user_id = "-1";
$this->nick = "";
$this->name = "";
$this->group_id = "0";
$this->password = "";
$this->password_crypt = "";
$this->email = "";
$this->gg = "";
$this->photo = "";
$this->description = "";
$this->phone = "";
$this->last_error = "";
$this->is_error = "0"; //no error
}
public function clearrData() {
$this->__construct();
}
/********************************************************************************
*****
SET FUNCTIONS
********************************************************************************
*****/
public function findAllGroupsSQL(&$groups) {
//fing all groups where belong user
//if user is set
if ($this->user_id != "-1") {
/*
$sql = " SELECT user_id, group_id, id_groups, name, moderator_id"
." FROM rbx_group_users LEFT JOIN rbx_groups"
." ON rbx_group_users.group_id = rbx_groups.id_groups"
." WHERE user_id = 3";
*/
}
else {
$this->lastError="NO_USER";
$this->setError();
return false;
}
}
public function userExistsSQL() {
//connectToADO($db);
$sql = "select email from rbx_username where email='".$this->email."'";
//$result = $db->Execute($sql);
if (!$result->FieldCount())
return true;
else return false;
}
public function createUserSQL() {
//gdy uzytkownik nie istnieje
if (!$this->userExists()) {
//connectToADO($db);
$sql = "insert into 'rbx_user' ( 'id_user' , 'name' , 'pass' , 'email' , 'gg' , 'photo' , 'description' , 'phone' )".
" values ('', '".$this->name."', '".$this->password_crypt."', '".$this->email."', '".$this->gg."', '".$this->photo."', '".$this->description."', '".$this->phone."')";
//$result = $db->Execute($sql);
$this->is_error = false;
}
else {
$this->is_error = true;
$this->last_error = "USER_ALREADY_EXIST";
}
}
public function updateUserSQL() {
//connectToADO($db);
$sql = "update 'rbx_user'"
." set 'name'=".$this->name.","
." 'pass'=".$this->password_crypt.","
." 'email'=".$this->email.","
." 'gg'=".$this->gg.","
." 'photo'=".$this->photo.","
." 'description'=".$this->description.","
." 'phone'=".$this->phone.","
." 'pass'=".$this->password_crypt
." WHERE 'id_user'=".$this->user_id;
//$result = $db->Execute($sql);
$this->is_error = false;
}
public function deleteCurrentUserSQL() {
//connectToADO($db);
$sql = "delete from 'rbx_user'"
."WHERE user_id=".$this->user_id;
//result = $db->Execute($sql);
$this->is_error = false;
}
public function deleteUserSQL($db) {
//connectToADO($db);
$sql = "delete from 'rbx_user'"
."WHERE user_id=".$db->user_id;
//result = $db->Execute($sql);
$this->is_error = false;
}
}
?>