Source for file class.user.php
Documentation is available at class.user.php
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
var $URI_INPUT = "user/avatar/"; // dossier racine de stockage des photos
var $NB_USERS = 30; // affichage par défaut du nombre d'utilisateurs
var $UPLOAD_MAX_MO = 10240; // taille maximale d'upload des avatars en octets
* user::CheckDataIntegrity()
* Vérification intégrité des données
* @param array $table : contient les composants d'un user
* @param object $sql_object
* @return boolean si vrai renvoie true sinon message d'erreurs (string)
if (isset ($sql_object)) {
$result = $this->_checkLoginValidity($table[0], $sql_object);
$result = $this->_checkEmailValidity($table[1]);
* user::_checkLoginValidity()
* @param string $login : login rentré par l'utilisateur
* @param object $sql_object
* si valide true sinon message d'erreur (string)
function _checkLoginValidity($login, $sql_object)
if (!preg_match('|^[a-zA-Z0-9]+$|', $login)) return $GLOBALS['lang']['user']['login_prohibited'];
if (strlen($login) < 5) return $GLOBALS['lang']['user']['login_tooshort'];
if (strlen($login) > 20) $GLOBALS['lang']['user']['login_toolong'];
$requete = "SELECT user_id FROM " . $this->TDB_USER . " WHERE lower(user_login)= '" . strtolower($login) . "' AND user_validity='Y';";
$result = $sql_object->DBSelect($requete);
if ($result != 0) return $GLOBALS['lang']['user']['login_used'];
* user::checkPasswordValidity()
* validation d'un password
* @param string $password password rentre par l'utilisateur
* @param string $pass2 (option)
* @return bool si valide true sinon message d'erreur (string)
if (strlen($password) < 5) return $GLOBALS['lang']['user']['pass_tooshort'];
if (strlen($password) > 15) return $GLOBALS['lang']['user']['pass_toolong'];
if ($pass2 != - 1 && $password != $pass2) return $GLOBALS['lang']['user']['pass_not_same'];
* user::_checkEmailValidity()
* @param string $email email rentre par l'utilisateur
* return 1 si valide sinon message d'erreur (string)
function _checkEmailValidity($email)
$emailinvalide = $GLOBALS['lang']['user']['invalid_mail'] . " :'" . $email . "'";
if (strlen($email) < 6 || !ereg("@", $email) || preg_match_all("/([^a-zA-Z0-9_\@\.\-])/i", $email, $trouve) || !preg_match("/^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$/i", $email)) {
list ($compte, $domaine) = split("@", $email, 2);
if (!checkdnsrr($domaine, "MX")) return $emailinvalide;
* user::_setUserCategory()
* determine automatique la categorie d'un utilisateur en fonction de ses droits
* @param array $table_right tableau des droits de l'utilisateur
function _setUserCategory($table_right)
if (isset ($table_right['category_user']) && $table_right['category_user'] == 'A') $this->CATEGORY = 1;
if ($table_right['dashboard'] == 'O' || $table_right['publication'] == 'O' || $table_right['news'] == 'O' || $table_right['workshop'] == 'O') $this->CATEGORY = 2;
* @param object $sql_object
* @return integer $last_id
function _AddProfile($sql_object)
$requete = "INSERT INTO " . T_PROFILE . " (profile_email, profile_email_display, profile_city, profile_birthdate, profile_leisures, profile_job, profile_avatar, profile_quotation, profile_signature, profile_date_crea) VALUES ('" . $this->P_EMAIL . "', '" . $this->P_EMAIL_DISPLAY . "','', '0001-01-01', '', '', '', '', '', NOW());";
$last_id = $sql_object->DBInsert ($requete, 1);
* stockage des droits d' un utilisateur BDD
* @param array $table_right contient les droits
* @param object $sql_object
* @return integer $last_id
function _AddRight($table_right, $sql_object)
$this->R_NEWS = $table_right['news'];
$this->R_THEME = $table_right['theme'];
$this->R_SCALE = $table_right['scale'];
$this->R_LEVEL = $table_right['level'];
$requete = "INSERT INTO " . T_RIGHT . " (rights_dashboard, rights_workshop, rights_project, rights_publication, rights_news, rights_yellowpages, rights_theme, rights_scale, rights_level, rights_category_user, rights_date_crea)VALUES ('" . $this->R_DASHBOARD . "', '" . $this->R_WORKSHOP . "', '" . $this->R_PROJECT . "', '" . $this->R_PUBLICATION . "', '" . $this->R_NEWS . "', '" . $this->R_YELLOWPAGES . "', '" . $this->R_THEME . "', '" . $this->R_SCALE . "', '" . $this->R_LEVEL . "', '" . $this->R_CATEGORY_USER . "', NOW());";
$last_id = $sql_object->DBInsert ($requete, 1);
* creation aleatoire d'un password
* @param int $length taille du password
* @return string $password
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for ($i = 0; $i < $length; $i++ ) {
* formatage du tableau de droit suivant profil prédeterminé
* @param string $type niveau utilisateur : SIMPLE_USER ou ADMIN_USER
* @return array $table_right : tableau des droits de l'utilisateur
$table_user = array ("dashboard" => 'U', "workshop" => 'U', "publication" => 'U', "project" => 'U',
"news" => 'U', "yellowpages" => 'U', "theme" => 'U',
"scale" => 'U', "level" => 'U', "category_user" => 'U');
$table_right = $table_user;
$table_right = array ("dashboard" => 'A', "workshop" => 'A', "publication" => 'A',
"project" => 'A', "news" => 'A', "yellowpages" => 'A',
"theme" => 'A', "scale" => 'A', "level" => 'A',
$table_right = $table_user;
* user::UpdateUserPassword()
* changement de password (mise à jour) dans la bdd
* @param int $ID identifiant utilisateur
* @param string $pass nouveau password non crypté
* @param object $sql_object
$requete = "UPDATE " . $this->TDB_USER . " SET user_password='" . $this->PASSWORD . "' WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBQuery ($requete);
* @param array $table_user contient les composants de l'utilisateur
* @param array $table_right contient les droits attribués au nouvel utilisateur
* @param object $sql_object
* @return integer $last_id
* renvoie un message d'erreur ou un numerique id de l'insertion
function AddUser($table_user, $table_right, $sql_object)
$table_user= $sql_object->DBescape($table_user);
$this->_SetUserCategory($table_right);
$this->PROFILE = $this->_AddProfile($sql_object);
$this->RIGHT = $this->_AddRight($table_right, $sql_object);
$requete = "INSERT INTO " . $this->TDB_USER . " (user_login, user_password, user_community, user_category, user_rights, user_profile, user_date_crea) VALUES ('" . $this->LOGIN . "', '" . $this->PASSWORD . "', " . $this->COMMUNITY . ", " . $this->CATEGORY . ", " . $this->RIGHT . ", " . $this->PROFILE . ", NOW());";
$result = $sql_object->DBInsert ($requete, 1);
* suppression d'un utilisateur
* @param int $ID identifiant de l'utilisateur
* @param object $sql_object
$requete = "UPDATE " . $this->TDB_USER . " SET user_validity='N' WHERE user_id=" . $this->ID . ";";
$result = $sql_object->DBQuery ($requete);
$requete = "DELETE FROM " . J_WORK_USERS . " WHERE jwu_user_id=" . $this->ID . ";";
$result = $sql_object->DBQuery ($requete);
* modification d'un profil utilisateur
* @param int $id identifiant d'un profil
* @param object $sql_object
* @param array $table_profile contient les composants d'un profil
$table_profile= $sql_object->DBescape($table_profile);
$requete = "UPDATE " . $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($requete);
$requete = "SELECT user_profile FROM " . $this->TDB_USER . " WHERE user_id='" . $this->ID . "' LIMIT 1;";
$data = $sql_object->DBSelect ($requete, 'OBJECT');
if ($data!= 0 && count($data) == 1) {
$this->P_ID = $data[0]->user_profile;
$requete = "UPDATE " . T_PROFILE . " SET profile_email='" . $this->P_EMAIL . "', profile_email_display='" . $this->P_EMAIL_DISPLAY . "', profile_city='" . $this->P_CITY . "', profile_birthdate='" . $this->P_BIRTHDATE . "', profile_leisures='" . $this->P_LEISURES . "', profile_job='" . $this->P_JOB . "', profile_quotation='" . $this->P_QUOTATION . "', profile_signature='" . $this->P_SIGNATURE . "', profile_avatar='" . $this->P_AVATAR . "' WHERE profile_id='" . $this->P_ID . "';";
$result = $sql_object->DBQuery ($requete);
* modification des droits d'un utilisateur
* @param int $ID identifiant de l'utilisateur
* @param object $sql_object
* @param array $table_right contient un tableau associatif de droit
if (isset ($table_right['dashboard'])) {
$update .= "rights_dashboard='" . $this->R_DASHBOARD . "'";
if (isset ($table_right['project'])) {
$update .= $sep . "rights_project='" . $this->R_PROJECT . "'";
if (isset ($table_right['publication'])) {
$update .= $sep . "rights_publication='" . $this->R_PUBLICATION . "'";
if (isset ($table_right['workshop'])) {
$update .= $sep . "rights_workshop='" . $this->R_WORKSHOP . "'";
if (isset ($table_right['news'])) {
$this->R_NEWS = $table_right['news'];
$update .= $sep . "rights_news='" . $this->R_NEWS . "'";
if (isset ($table_right['yellowpages'])) {
$update .= $sep . "rights_yellowpages='" . $this->R_YELLOWPAGES . "'";
if (isset ($table_right['theme'])) {
$this->R_THEME = $table_right['theme'];
$update .= $sep . "rights_theme='" . $this->R_THEME . "'";
if (isset ($table_right['scale'])) {
$this->R_SCALE = $table_right['scale'];
$update .= $sep . "rights_scale='" . $this->R_SCALE . "'";
if (isset ($table_right['level'])) {
$this->R_LEVEL = $table_right['level'];
$update .= $sep . "rights_level='" . $this->R_LEVEL . "'";
if (isset ($table_right['category_user'])) {
$requete = "UPDATE " . $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($requete);
$requete = "SELECT user_rights FROM " . $this->TDB_USER . " WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($requete);
if ($result == 0) return false;
if (count($result) == 1) {
$this->R_ID = $result[0]['user_rights'];
$requete = "UPDATE " . T_RIGHT . " SET " . $update . " WHERE rights_id='" . $this->R_ID . "';";
$result = $sql_object->DBQuery ($requete);
$this->_SetUserCategory($table_right);
$requete = "UPDATE " . $this->TDB_USER . " SET user_category='" . $this->CATEGORY . "' WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBQuery ($requete);
|