db = $db_object; } function insertUser(){ if ($this->verifyUsernameIsUnique()) { $this->password = $this->generatePassword(); $sql = "insert into users (username, password, type) values ('$this->username','$this->password','$this->type')"; $this->db->BeginTrans(); if ($this->db->Execute($sql)) { //a fost inserat utilizatorul, trebuie sa trimitem email $this->sendPasswordEmail(); include_once ("student.class.php"); $student = new student ($this->db); $student->id_user = $this->db->Insert_ID(); $student->id_faculty = $this->id_faculty; $student->name = $this->name; $student->surname = $this->surname; $student->promotion = $this->promotion; $student->email1 = $this->email; if ($student->insertStudent() == 0) { $this->db->CommitTrans(); return 0; } else { $this->db->RollbackTrans(); return 1; } } else return 1; } else { return 2; } } function getUser(){ if ($this->id_user == "") return 1; // $sql = "select u.username, u.password, u.type, s.email1, s.id_faculty, s.id_series, s.promotion from users u, students s where u.id_user = s.id_user and u.id_user = " .$this->id_user; $sql = "select u.username, u.password, u.type from users u where u.id_user = " .$this->id_user; $res = $this->db->Execute($sql); $row = $res->FetchRow(); $this->username = $row["username"]; $this->password = $row["password"]; $this->type = $row["type"]; //$this->email = $row["email1"]; //$this->promotion = $row["promotion"]; //$this->id_faculty = $row["id_faculty"]; //$this->id_series = $row["id_series"]; } function updateUser(){ if ($this->id_user == "") return 1; $sql = "update users set password='$this->password' where id_user = $this->id_user"; if ($this->db->Execute($sql)) return 0; else return 1; } function verifyUsernameIsUnique(){ $sql = "select username from users where username = '$this->username'"; $res = $this->db->Execute($sql); if ($res->RecordCount() == 0) return true; else return false; } function generatePassword(){ $totalChar = 7; // number of chars in the password $salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; srand((double)microtime()*1000000); $password=""; for ($i=0;$i<$totalChar;$i++) $password = $password . substr ($salt, rand() % strlen($salt), 1); return $password; } function sendPasswordEmail(){ require_once ("utils.class.php"); $utils = new utils ($this->db); $subject = "Cont nou la www.utcb.ro/absolventi"; $body = "Va multumim ca doriti sa va inscrieti in Baza de date absolventi, care speram sa cuprinda toti absolventii universitatii noastre. Cu ajutorul contului si a parolei primite veti putea sa inscrieti in sistem datele personale solicitate. Acestea vor putea crea o imagine completa a evolutiei profesionale a absolventilor UTCB." ."

"; $body .= "Nume utilizator: " . $this->username ."
"; $body .= "Parola: " . $this->password . "

"; $body .= "Va multumim !"; $utils->sendMail($this->email,$this->send_mail_from, $subject, $body); } function logIn(){ $sql = "select u.type, u.id_user from users u where u.username='$this->username' and u.password='$this->password'"; $res = $this->db->Execute($sql); if ($res->RecordCount() == 0) return false; else { $row = $res->FetchRow(); $_SESSION["id_user"] = $row["id_user"]; $_SESSION["type"] = $row["type"]; if ($row["type"] == "student"){ $sql = "select id_student from students where id_user =" .$row["id_user"]; $res = $this->db->Execute($sql); $row = $res->FetchRow(); $_SESSION["id_student"] = $row["id_student"]; } else { $_SESSION["id_student"] = 0; } $sql = "update users set last_login_date = now() where id_user=" .$_SESSION["id_user"]; $res = $this->db->Execute($sql); return true; } } function recoverAccoutByUsername(){ if ($this->username == "") return 1; else { $sql = "select s.email1, u.password from users u, students s where s.id_user = u.id_user and u.username='$this->username'"; $res = $this->db->Execute($sql); if (!$res) return 1; else { if ($res->RecordCount() > 0) { $row = $res->FetchRow(); require_once ("utils.class.php"); $utils = new utils ($this->db); $subject = "Recuperare parola la baza de date absolventi UTCB"; $body = "Nume utilizator: " . $this->username ."
"; $body .= "Parola: " . $row["password"] . "
"; $body .= "Va multumim !"; $utils->sendMail($row["email1"],$this->send_mail_from, $subject, $body); } else { return 1; } } } } function recoverAccoutByEmail(){ if ($this->email == "") return 1; else { $sql = "select u.username, u.password from users u, students s where s.id_user = u.id_user and s.email1='$this->email'"; $res = $this->db->Execute($sql); if (!$res) return 1; else { if ($res->RecordCount() > 0) { $row = $res->FetchRow(); require_once ("utils.class.php"); $utils = new utils ($this->db); $subject = "Recuperare parola la baza de date absolventi UTCB"; $body = "Nume utilizator: " . $row["username"] ."
"; $body .= "Parola: " . $row["password"] . "
"; $body .= "Va multumim !"; $utils->sendMail($this->email,$this->send_mail_from, $subject, $body); } else { return 1; } } } } function isLoggedIn(){ if (isset($_SESSION["id_user"]) && $_SESSION["id_user"] != "" && isset($_SESSION["type"] ) && $_SESSION["type"] !="" ) return true; else return false; } function logOut(){ unset($_SESSION["id_user"]); /* session_unregister('id_user'); */ unset($_SESSION["type"]); /* session_unregister('type'); */ unset($_SESSION["id_student"]); /* session_unregister('id_student'); */ } function getUsersList(){ $sql = "select id_user, username, password, type, last_login_date from users where type in ('utcb', 'lugera')"; $res = $this->db->Execute($sql); return $res->GetArray($res->RecordCount()); } function insertUserFromAdmin(){ if ($this->verifyUsernameIsUnique()) { $sql = "insert into users (username, password, type) values ('$this->username','$this->password','$this->type')"; if ($this->db->Execute($sql)) return 0; else return 1; } else { return 2; } } function getUserFromAdmin(){ if ($this->id_user == "") return 1; $sql = "select u.username, u.password, u.type from users u where u.id_user = " .$this->id_user; $res = $this->db->Execute($sql); $row = $res->FetchRow(); $this->username = $row["username"]; $this->password = $row["password"]; $this->type = $row["type"]; } function deleteUsers(){ if ($this->ids_list == "") return; $err = false; $this->db->BeginTrans(); $sql = "delete from users where id_user in ($this->ids_list)"; if (!$this->db->Execute($sql)) $err = true; $sql = "delete from students where id_user in ($this->ids_list)"; if (!$this->db->Execute($sql)) $err = true; if ($err) { $this->db->RollbackTrans(); return 1; } else { $this->db->CommitTrans(); return 0; } } } ?>