<?php
/* ============================================================
* user.php
* -------------------
* Date : 21 june 2006
* E-mail : hide@address.com
*
* Version : 1.0 (21/06/2006 - 13:35)
*
* This a free software
* licensed under GPL (General public license)
*
============================================================ */
/**
* The user object: contains all info for users (and the updating, inserting and deleting)
*
* @version 1.0.0
* @package userclass
*/
/**
* userclass
*/
class User {
var $userID,
$userName,
$userPassword,
$active;
/**
* user constructor
*/
function User() {}
/**
* To insert a user in the database
*/
function setUser() {
// Get data
$i = new iter("select * from tm_users where userName = '$this->userName'");
$user = $i->fetch();
if(!($user)) {
$q = new query("INSERT INTO `tm_users` ( `user_id` , `userName` , `userPassword`, `userEmail` , `securitylevel` , `active` , `datecreated` , `datemodified` )
VALUES (NULL, '$this->userName', '$this->userPassword', '$this->userEmail','0', '1', NOW() , NOW());");
// Get the new user ID
$this->user_id = $q->insertId;; // Get the user_id from the database
// Assign the values to the data members
$this->userName = $userName;
$this->userPassword = $userPassword;
} else { die('user exists'); }
}
/**
* To update a user in the database
*
* @param integer $id the id of the user you want to update
*/
function updateUser($id) {
$q = new query("UPDATE `tm_users` SET
`userName` = '$this->userName',
`userPassword` = '$this->userPassword',
`userEmail` = '$this->userEmail',
`datemodified` = NOW( )
WHERE `user_id` = '$id' LIMIT 1 ;");
}
/**
* To delete a user in the database
*
* @param integer $id the id of the user you want to update
*/
function delete($id) {
$q = new query("DELETE FROM `tm_users` WHERE `user_id` = '$id'");
}
/**
* To get userdata: search on username
*
* @param string $username username of the user you want to get info from
*/
function getUser($userName) {
// Get data
$i = new iter("select * from tm_users where userName = '$userName'");
$user = $i->fetch();
foreach (get_object_vars($user) as $key=>$val)
$this->$key = $val;
}
/**
* To get userdata: search on userid
*
* @param integer $id the id of the user you want to update
*/
function getUserbyid($user_id) {
// Get data
$i = new iter("select * from tm_users where user_id = '$user_id'");
$user = $i->fetch();
foreach (get_object_vars($user) as $key=>$val)
$this->$key = $val;
}
/**
* Quickcheck for the password only (die's if password is incorrect)
*/
function verifyPassword() {
// Get data
$i = new iter("select * from tm_users where userName = '$this->userName'");
$user = $i->fetch();
$actualPassword = $user->userPassword; // Get the password from the database
$givenPassword = $this->userPassword; // Get the password given by the user
// Verify that they match
if(!($actualPassword == $givenPassword)) {setcookie("user", false, time()+60*60*24*30);
setcookie("secret", false, time()+60*60*24*30);
die("Incorrect Username of Password");}
// Verify if user is active
if(!($user->active == '1')) {setcookie("user", false, time()+60*60*24*30);
setcookie("secret", false, time()+60*60*24*30);
die("Inactive User");}
$this->user_id = $user->user_id; // Get the user_id from the database
}
/**
* Quickway to update a password for a user
*
* @param string $newPassword New password you want to set for this user
*/
function changePassword($newPassword) {
// Update data
$q = new query("update tm_users set userPassword = '$newPassword' where user_id = '$this->user_id'");
// update the password stored in the object
$this->userPassword = $newPassword;
}
/**
* Just to display some basic userinfo (mostly used in testing)
*/
function displayUserInfo() {
echo '<b>ID: </b>' . $this->user_id . '<br>';
echo '<b>Name: </b>' . $this->userName . '<br>';
echo '<b>Password: </b>' . $this->userPassword . '<br>';
}
}
?>