Location: PHPKode > projects > COWeb (Common Objects for Web) > coweb-0.4.1/include/users.inc.php
<?

// Module de gestion des utilisateurs
// Ecrit par Sébastien DIAZ
// Distribue sous license GPL

include "coweb.inc.php";

if (! defined("USERS"))
{
	define("USERS",1);

	class users
	{
		var $id;			// id du user
		var $firstname;		// nom de l'utilisateur
		var $lastname;		// prenom de l'utilisateur
		var $description;	// description de l'utilisateur
		var $table;			// table ou se trouve les utilistaeurs
		var $flag;			// flag d'activation
		var $login;			// login de l'utilisateur
		var $password;		// password de l'utilisateur
		var $email;			// email de l'utilisateur

	function users($id, $table)	// Constructeur
	{
		if (isset($id))
		{
			$dbl=new db(server, port, database, login, password, type);
			$dbl->Connect();
			$dbl->query("	SELECT id, firstname, lastname, description, flag, login, password, email
							FROM $table
							WHERE id=$id"
						);
			$dbl->fetch();
			$this->id=stripslashes($dbl->row["id"]);
			$this->firstname=stripslashes($dbl->row["firstname"]);
			$this->lastname=stripslashes($dbl->row["lastname"]);
			$this->description=stripslashes($dbl->row["description"]);
			$this->flag=stripslashes($dbl->row["flag"]);
			$this->login=stripslashes($dbl->row["login"]);
			$this->password=stripslashes($dbl->row["password"]);
			$this->email=stripslashes($dbl->row["email"]);
		}
		else
		{
			$this->id="";
			$this->firstname="";
			$this->lastname="";
			$this->description="";
			$this->login="";
			$this->password="";
			$this->flag="1";
			$this->email="";
		}
		$this->table=$table;
	}

	function Show($template)
	// Affichage
	{
		echo $this->Parse($template);
	}

	function Parse($template)
	// Parse mais n'affiche pas
	{
		eval(parse($template));
		return $template;
	}

	function Generate()
	// Creation d'une table de users
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$sql="	CREATE TABLE $this->table
				(
					id int(11) NOT NULL auto_increment,
					firstname varchar(32) default NULL,
					lastname varchar(32) default NULL,
					description tinytext,
					flag char(1) NOT NULL default '1',
					login varchar(32) default NULL,
					password varchar(32) default NULL,
					email varchar(64) default NULL,
					UNIQUE KEY id (id)
				)";
		$dbl->Query($sql);
	}

	function Ungenerate()
	// Suppression d'une table de users
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$dbl->query("	DROP TABLE IF EXISTS $this->table
			");
		$dbl->fetch();
	}

	function Add()
	// Insertion d'un nouvel user
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$this->firstname=addslashes($this->firstname);
		$this->lastname=addslashes($this->lastname);
		$this->description=addslashes($this->description);
		$this->login=addslashes($this->login);
		$this->password=addslashes($this->password);
		$this->email=addslashes($this->email);
		$dbl->Query("	INSERT $this->table
						VALUES ('', '$this->firstname', '$this->lastname', '$this->description', '1', '$this->login', '$this->password', '$this->email')
			");
		$this->id=mysql_insert_id($dbl->id);
	}

	function Delete()
	// Supression d'un user
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$dbl->Query("	DELETE FROM $this->table
						WHERE id=$this->id
				");
		$dbl->fetch();
	}

	function Update()
	// Modification d'un user
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$this->label=addslashes($this->label);
		$this->url=addslashes($this->url);
		$this->description=addslashes($this->description);
		$dbl->Query("	UPDATE $this->table
						SET firstname='$this->firstname',
						lastname='$this->lastname',
						description='$this->description',
						flag='$this->flag',
						login='$this->login',
						password='$this->password',
						email='$this->email'
						WHERE id=$this->id
					");
		$dbl->Fetch();
	}

	}
}

?>
Return current item: COWeb (Common Objects for Web)