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 = "library/userfiles/users/avatars/"; // dossier racine de stockage des photos
var $NB_USERS = 30; // affichage par défaut du nombre d'utilisateurs
var $UPLOAD_MAX_MO = 20480; // taille maximale d'upload des avatars en octets
public function __call($method, $arguments)
$event = $this->dispatcher->notifyUntil(new sfEvent($this, 'user.extensible_function', array(
'arguments' => $arguments
if (!$event->isProcessed())
throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
return $event->getReturnValue();
* 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 _t('user','login_prohibited');
if (strlen($login) < 5) return _t('user','login_tooshort');
if (strlen($login) > 20) _t('user','login_toolong');
$q = "SELECT user_id FROM " . $this->TDB_USER . " WHERE lower(user_login)= '" . strtolower($login) . "' AND user_validity='Y';";
$result = $sql_object->DBSelect($q);
if ($result != 0) return _t('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 _t('user','pass_tooshort');
if (strlen($password) > 15) return _t('user','pass_toolong');
if ($pass2 != - 1 && $password != $pass2) return _t('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)
return _t('user','invalid_mail') . " :'" . $email . "'";
* 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;
elseif ($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)
$q = "INSERT INTO " . T_PROFILE . " (profile_firstname, profile_lastname, 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_FIRSTNAME . "', '" . $this->P_LASTNAME . "', '" . $this->P_EMAIL . "', '" . $this->P_EMAIL_DISPLAY . "','', '0001-01-01', '', '', '', '', '', NOW());";
$last_id = $sql_object->DBInsert ($q, 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'];
$q = "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 ($q, 1);
* user::GetUserWorkshops()
* Ajout d'un utilisateur à un ou plusieurs workshops
* @param int $user_id identifiant du workshop
* @param array $workgroups workgroups ID
* @param string $user_right droit confié a l'utilisateur sur le workshop
* @param object $sql_object
* @return integer $last_id
$q = "SELECT jwu_workshop_id, workshop_denomination, jwu_user_right FROM ". J_WORK_USERS. "
LEFT OUTER JOIN " . T_WORK . " ON jwu_workshop_id=workshop_id
WHERE jwu_user_id=". $this->ID. ";";
$r = $sql_object->DBSelect ($q);
* user::changeWorkshopsNotification()
* Change workshops notification for a given user
* @param object $sql_object
* @return integer $last_id
$q = "DELETE FROM " . T_WORK_NOTIFY . " WHERE user_id=" . $user_id. ";";
$r = $sql_object->DBQuery ($q);
foreach($exceptions as $el) {
list ($type, $workgroup)= explode('-', $el);
$q = "INSERT INTO " . T_WORK_NOTIFY . " (user_id, workshop_id, type) VALUES(". $user_id. ", ". $workgroup. ", '". $type. "');";
$r = $sql_object->DBInsert ($q);
* user::DeleteWorkshops()
* Remove all workshops for a given user
* @param object $sql_object
* @return integer $last_id
$q = "DELETE FROM " . J_WORK_USERS . " WHERE jwu_user_id=" . $this->ID . " AND jwu_user_right='". $user_right. "';";
$r = $sql_object->DBQuery ($q);
* Ajout d'un utilisateur à un ou plusieurs workshops
* @param int $user_id identifiant du workshop
* @param array $workgroups workgroups ID
* @param string $user_right droit confié a l'utilisateur sur le workshop
* @param object $sql_object
* @return integer $last_id
function AddWorkshops($user_id, $workgroups, $user_right , $sql_object)
if(count($workgroups)== 0) return true;
for ($i = 0;$i < count($workgroups);$i++ ) {
// check if user already belong to the group
$q = "SELECT COUNT(jwu_id) AS nb FROM " . J_WORK_USERS . " WHERE jwu_user_id=" . $this->ID . " AND jwu_workshop_id=" . $workgroups[$i] . ";";
$data = $sql_object->DBSelect($q, 'OBJECT');
$q = "INSERT INTO " . J_WORK_USERS . " (jwu_workshop_id, jwu_user_id, jwu_user_right) VALUES(" . $workgroups[$i] . ", " . $this->ID . ",'" . $user_right . "');";
$last_id = $sql_object->DBInsert ($q, 1);
* user::ModifiyWorkshops()
* Update workgroups for a given user
* @param int $user_id identifiant du workshop
* @param array $workgroups workgroups to add
* @param string $user_right droit confié a l'utilisateur sur le workshop
* @param object $sql_object
$r = $this->AddWorkshops($this->ID, $workgroups, $user_right, $sql_object);
* user::generateNewPasskey()
* creation aleatoire d'un passkey
* @param object $sql_object
* @return string $password
$q = "UPDATE " . $this->TDB_USER . " SET user_forget_passkey='" . $this->PASSKEY . "' WHERE user_id='" . $user_id . "';";
$r = $sql_object->DBQuery ($q);
if($r) return $this->PASSKEY;
* creation aleatoire d'un passkey
* @param object $sql_object
* @return string $password
$q = "UPDATE " . $this->TDB_USER . " SET user_forget_passkey='' WHERE user_id='" . $user_id . "';";
$r = $sql_object->DBQuery ($q);
* 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
$q = "UPDATE " . $this->TDB_USER . " SET user_password='" . $this->PASSWORD . "' WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBQuery ($q);
* @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);
$q = "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());";
$res = $sql_object->DBInsert ($q, 1);
if($res && (defined('NEWSLETTER_AUTO_SUB') && NEWSLETTER_AUTO_SUB == 1)) {
include_once('../class/class.newsletter.php');
$newsletter->AddEmail($this->P_EMAIL, $sql_object);
* suppression d'un utilisateur
* @param int $ID identifiant de l'utilisateur
* @param object $sql_object
$q = "UPDATE " . $this->TDB_USER . " SET user_validity='N' WHERE user_id=" . $this->ID . ";";
$result = $sql_object->DBQuery ($q);
$q = "DELETE FROM " . J_WORK_USERS . " WHERE jwu_user_id=" . $this->ID . ";";
$res = $sql_object->DBQuery ($q);
* 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);
$q = "UPDATE " . $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($q);
$q = "SELECT user_profile FROM " . $this->TDB_USER . " WHERE user_id='" . $this->ID . "' LIMIT 1;";
$data = $sql_object->DBSelect ($q, 'OBJECT');
if ($data!= 0 && count($data) == 1) {
$this->P_ID = $data[0]->user_profile;
$q = "UPDATE " . T_PROFILE . " SET profile_firstname='" . $this->P_FIRSTNAME . "', profile_lastname='" . $this->P_LASTNAME . "', 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 ($q);
* 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'])) {
$q = "UPDATE " . $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($q);
$q = "SELECT user_rights FROM " . $this->TDB_USER . " WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBSelect ($q);
if ($result == 0) return false;
if (count($result) == 1) {
$this->R_ID = $result[0]['user_rights'];
$q = "UPDATE " . T_RIGHT . " SET " . $update . " WHERE rights_id='" . $this->R_ID . "';";
$result = $sql_object->DBQuery ($q);
$this->_SetUserCategory($table_right);
$q = "UPDATE " . $this->TDB_USER . " SET user_category='" . $this->CATEGORY . "' WHERE user_id='" . $this->ID . "';";
$result = $sql_object->DBQuery ($q);
|