linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file class.user.php

Documentation is available at class.user.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage user
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  User Management
  10.  */
  11.  
  12. class user {
  13.   /* @param
  14.    * */
  15.   var $TDB_USER = T_USER// nom de la table.
  16.   var $URI_INPUT = "user/avatar/"// dossier racine de stockage des photos
  17.   var $NB_USERS = 30// affichage par défaut du nombre d'utilisateurs
  18.   var $UPLOAD_MAX_MO = 10240// taille maximale d'upload des avatars en octets
  19.   var $ID;
  20.   var $LOGIN;
  21.   var $PASSWORD;
  22.   var $COMMUNITY = USER_COMMUNITY;
  23.   var $CATEGORY;
  24.   var $RIGHT;
  25.   var $PROFILE;
  26.   var $DATE_CREA;
  27.   var $VALIDITY;
  28.   var $LAST_MODIFY;
  29.  
  30.   var $R_ID;
  31.   var $R_DASHBOARD;
  32.   var $R_WORKSHOP;
  33.   var $R_PROJECT;
  34.   var $R_PUBLICATION;
  35.   var $R_NEWS;
  36.   var $R_YELLOWPAGES;
  37.   var $R_THEME;
  38.   var $R_SCALE;
  39.   var $R_LEVEL;
  40.  
  41.   var $P_ID;
  42.   var $P_EMAIL;
  43.  
  44.   var $P_CITY;
  45.   var $P_BIRTHDATE;
  46.   var $P_LEISURES;
  47.   var $P_JOB;
  48.   var $P_AVATAR;
  49.   var $P_QUOTATION;
  50.   var $P_SIGNATURE;
  51.  
  52.   /**
  53.    * user::CheckDataIntegrity()
  54.    * Vérification intégrité des données
  55.    *
  56.    * @access public
  57.    * @param array $table : contient les composants d'un user
  58.    * @param object $sql_object 
  59.    * @return boolean si vrai renvoie true sinon message d'erreurs (string)
  60.    */
  61.   function CheckDataIntegrity($table$sql_object null)
  62.   {
  63.     if (isset($sql_object)) {
  64.       $result $this->_checkLoginValidity($table[0]$sql_object);
  65.       if (is_string($result)) return $result;
  66.     }
  67.     $result $this->_checkEmailValidity($table[1]);
  68.     if (is_string($result)) return $result;
  69.     return true;
  70.   }
  71.  
  72.   /**
  73.    * user::_checkLoginValidity()
  74.    * validation d'un login
  75.    *
  76.    * @access private
  77.    * @param string $login : login rentré par l'utilisateur
  78.    * @param object $sql_object 
  79.    * @return bool $result
  80.    *  si valide true sinon message d'erreur (string)
  81.    */
  82.   function _checkLoginValidity($login$sql_object)
  83.   {
  84.     $login trim($login);
  85.     if (!preg_match('|^[a-zA-Z0-9]+$|'$login)) return _t('user','login_prohibited');
  86.     if (strlen($login5return _t('user','login_tooshort');
  87.     if (strlen($login20_t('user','login_toolong');
  88.     $requete "SELECT user_id FROM " $this->TDB_USER . " WHERE lower(user_login)= '" strtolower($login"' AND user_validity='Y';";
  89.  
  90.     $result $sql_object->DBSelect($requete);
  91.  
  92.     if ($result != 0return _t('user','login_used');
  93.  
  94.     return true;
  95.   }
  96.  
  97.   /**
  98.    * user::checkPasswordValidity()
  99.    * validation d'un password
  100.    *
  101.    * @access publi
  102.    * @param string $password password rentre par l'utilisateur
  103.    * @param string $pass2 (option)
  104.    * @return bool si valide true sinon message d'erreur (string)
  105.    */
  106.   function checkPasswordValidity($password$pass2 = -1)
  107.   {
  108.     if (strlen($password5return _t('user','pass_tooshort');
  109.     if (strlen($password15return _t('user','pass_toolong');
  110.     if ($pass2 != -&& $password != $pass2return _t('user','pass_not_same');
  111.  
  112.     return true;
  113.   }
  114.  
  115.   /**
  116.    * user::_checkEmailValidity()
  117.    * validation d'un email
  118.    *
  119.    * @access private
  120.    * @param string $email email rentre par l'utilisateur
  121.    * @return string $result
  122.    *  return 1 si valide sinon message d'erreur (string)
  123.    */
  124.   function _checkEmailValidity($email)
  125.   {
  126.     $email strtolower($email);
  127.     $emailinvalide _t('user','invalid_mail'" :'" $email "'";
  128.     if (strlen($email|| !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)) {
  129.       return $emailinvalide;
  130.     }
  131.     list($compte$domainesplit("@"$email2);
  132.     if (function_exists('checkdnsrr')) {
  133.       if (!checkdnsrr($domaine"MX")) return $emailinvalide;
  134.     }
  135.     return 1;
  136.   }
  137.  
  138.   /**
  139.    * user::_setUserCategory()
  140.    * determine automatique la categorie d'un utilisateur en fonction de ses droits
  141.    * et renseigne l'objet
  142.    *
  143.    * @access private
  144.    * @param array $table_right tableau des droits de l'utilisateur
  145.    * @return bool $result
  146.    */
  147.   function _setUserCategory($table_right)
  148.   {
  149.     if (isset($table_right['category_user']&& $table_right['category_user'== 'A'$this->CATEGORY = 1;
  150.     else {
  151.       if ($table_right['dashboard'== 'O' || $table_right['publication'== 'O' || $table_right['news'== 'O' || $table_right['workshop'== 'O'$this->CATEGORY = 2;
  152.       else $this->CATEGORY = 3;
  153.     }
  154.  
  155.     return true;
  156.   }
  157.  
  158.   /**
  159.    * user::_AddProfile()
  160.    * Ajout d'un profil
  161.    *
  162.    * @access private
  163.    * @param object $sql_object 
  164.    * @return integer $last_id
  165.    */
  166.   function _AddProfile($sql_object)
  167.   {
  168.     $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());";
  169.     $last_id $sql_object->DBInsert ($requete1);
  170.     return $last_id;
  171.   }
  172.  
  173.   /**
  174.    * user::_AddRight()
  175.    * stockage des droits d' un utilisateur BDD
  176.    *
  177.    * @access private
  178.    * @param array $table_right contient les droits
  179.    * @param object $sql_object 
  180.    * @return integer $last_id
  181.    */
  182.   function _AddRight($table_right$sql_object)
  183.   {
  184.     $this->R_DASHBOARD = $table_right['dashboard'];
  185.     $this->R_WORKSHOP = $table_right['workshop'];
  186.     $this->R_PROJECT = $table_right['project'];
  187.     $this->R_PUBLICATION = $table_right['publication'];
  188.     $this->R_NEWS = $table_right['news'];
  189.     $this->R_YELLOWPAGES = $table_right['yellowpages'];
  190.     $this->R_THEME = $table_right['theme'];
  191.     $this->R_SCALE = $table_right['scale'];
  192.     $this->R_LEVEL = $table_right['level'];
  193.     $this->R_CATEGORY_USER = $table_right['category_user'];
  194.     $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());";
  195.     $last_id $sql_object->DBInsert ($requete1);
  196.     return $last_id;
  197.   }
  198.  
  199.   /**
  200.    * user::GetNewPassword()
  201.    * creation aleatoire d'un password
  202.    *
  203.    * @access public
  204.    * @param int $length taille du password
  205.    * @return string $password
  206.    */
  207.   function GetNewPassword($length PASSWD_LENGTH)
  208.   {
  209.     $str 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  210.     $password '';
  211.     for ($i 0$i $length$i++{
  212.       $password .= substr($strrand(0strlen($str1)1);
  213.     }
  214.     return $password;
  215.   }
  216.  
  217.   /**
  218.    * user::InitUserRight()
  219.    * formatage du tableau de droit suivant profil prédeterminé
  220.    *
  221.    * @access public
  222.    * @param string $type niveau utilisateur : SIMPLE_USER ou ADMIN_USER
  223.    * @return array $table_right : tableau des droits de l'utilisateur
  224.    */
  225.   function InitUserRight($type 'SIMPLE_USER')
  226.   {
  227.     $table_user array ("dashboard" => 'U'"workshop" => 'U'"publication" => 'U'"project" => 'U',
  228.             "news" => 'U'"yellowpages" => 'U'"theme" => 'U',
  229.             "scale" => 'U'"level" => 'U'"category_user" => 'U');
  230.  
  231.     switch ($type{
  232.       case 'SIMPLE_USER':
  233.         $table_right $table_user;
  234.         break;
  235.       case 'ADMIN_USER':
  236.         $table_right array ("dashboard" => 'A'"workshop" => 'A'"publication" => 'A',
  237.                     "project" => 'A'"news" => 'A'"yellowpages" => 'A',
  238.                     "theme" => 'A'"scale" => 'A'"level" => 'A',
  239.                     "category_user" => 'A');
  240.         break;
  241.       default:
  242.         $table_right $table_user;
  243.         break;
  244.     }
  245.  
  246.     return $table_right;
  247.   }
  248.  
  249.  
  250.   /**
  251.    * user::UpdateUserPassword()
  252.    * changement de password (mise à jour) dans la bdd
  253.    *
  254.    * @access public
  255.    * @param int $ID identifiant utilisateur
  256.    * @param string $pass nouveau password non crypté
  257.    * @param object $sql_object 
  258.    * @return bool $result
  259.    */
  260.   function UpdateUserPassword($ID$pass$sql_object)
  261.   {
  262.     if (is_numeric($ID)) {
  263.       $this->ID = $ID;
  264.     else exit;
  265.     $this->PASSWORD = crypt($passSALT_CRYPT);
  266.     $requete "UPDATE " $this->TDB_USER . " SET user_password='" $this->PASSWORD . "' WHERE user_id='" $this->ID . "';";
  267.     $result $sql_object->DBQuery ($requete);
  268.  
  269.     return $result;
  270.   }
  271.  
  272.   /**
  273.    * user::AddUser()
  274.    * Ajout d'un utilisateur
  275.    *
  276.    * @access public
  277.    * @param array $table_user contient les composants de l'utilisateur
  278.    * @param array $table_right contient les droits attribués au nouvel utilisateur
  279.    * @param object $sql_object 
  280.    * @return integer $last_id
  281.    *  renvoie un message d'erreur ou un numerique id de l'insertion
  282.    */
  283.   function AddUser($table_user$table_right$sql_object)
  284.   {
  285.     $table_user=$sql_object->DBescape($table_user);
  286.  
  287.     $this->LOGIN = strip_input(trim($table_user[0]));
  288.     $this->P_EMAIL = strtolower($table_user[1]);
  289.     $this->P_EMAIL_DISPLAY = $table_user[2];
  290.     $this->PASSWORD = crypt($table_user[3]SALT_CRYPT);
  291.     $this->_SetUserCategory($table_right);
  292.     $this->PROFILE = $this->_AddProfile($sql_object);
  293.     $this->RIGHT = $this->_AddRight($table_right$sql_object);
  294.     $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());";
  295.  
  296.     $result $sql_object->DBInsert ($requete1);
  297.     return $result;
  298.   }
  299.  
  300.   /**
  301.    * user::DeleteUser()
  302.    * suppression d'un utilisateur
  303.    *
  304.    * @access public
  305.    * @param int $ID identifiant de l'utilisateur
  306.    * @param object $sql_object 
  307.    * @return bool $result
  308.    */
  309.   function DeleteUser($ID$sql_object)
  310.   {
  311.     if (is_numeric($ID)) {
  312.       $this->ID = $ID;
  313.     else return false;
  314.     $requete "UPDATE " $this->TDB_USER . " SET user_validity='N' WHERE user_id=" $this->ID . ";";
  315.     $result $sql_object->DBQuery ($requete);
  316.     $requete "DELETE FROM " J_WORK_USERS " WHERE jwu_user_id=" $this->ID . ";";
  317.     $result $sql_object->DBQuery ($requete);
  318.     return $result;
  319.   }
  320.  
  321.   /**
  322.    * user::ModifyProfile()
  323.    * modification d'un profil utilisateur
  324.    *
  325.    * @access public
  326.    * @param int $id identifiant d'un profil
  327.    * @param object $sql_object 
  328.    * @param array $table_profile contient les composants d'un profil
  329.    * @return bool $result
  330.    */
  331.   function ModifyProfile($ID$table_profile$sql_object)
  332.   {
  333.     $table_profile=$sql_object->DBescape($table_profile);
  334.  
  335.     if (is_numeric($ID)) {
  336.       $this->ID = $ID;
  337.     else return false;
  338.  
  339.     $this->P_EMAIL = strtolower($table_profile[0]);
  340.  
  341.     $requete "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  342.     $result $sql_object->DBSelect ($requete);
  343.  
  344.     $requete "SELECT user_profile FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "' LIMIT 1;";
  345.     $data $sql_object->DBSelect ($requete'OBJECT');
  346.     if ($data!=&& count($data== 1{
  347.       $this->P_ID = $data[0]->user_profile;
  348.     else return false;
  349.     $this->P_EMAIL_DISPLAY = strtoupper($table_profile[1]);
  350.     $this->P_CITY = strip_input(ucfirst(trim($table_profile[2])));
  351.     $this->P_BIRTHDATE = ($table_profile[3]=='--''0001-01-01' formatDate($table_profile[3]true);
  352.     $this->P_LEISURES = strip_input(trim($table_profile[4]));
  353.     $this->P_JOB = strip_input(trim($table_profile[5]));
  354.     $this->P_QUOTATION = strip_input(trim($table_profile[6]));
  355.     $this->P_SIGNATURE = strip_input(trim($table_profile[7]));
  356.     $this->P_AVATAR = strip_input($table_profile[8]);
  357.  
  358.     $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 . "';";
  359.  
  360.     $result $sql_object->DBQuery ($requete);
  361.  
  362.     return $result;
  363.   }
  364.  
  365.   /**
  366.    * user::ModifyRight()
  367.    * modification des droits d'un utilisateur
  368.    *
  369.    * @access public
  370.    * @param int $ID identifiant de l'utilisateur
  371.    * @param object $sql_object 
  372.    * @param array $table_right contient un tableau associatif de droit
  373.    * @return bool $result
  374.    */
  375.   function ModifyRight($ID$table_right$sql_object)
  376.   {
  377.     if (is_numeric($ID)) {
  378.       $this->ID = $ID;
  379.     else return false;
  380.  
  381.     $update '';
  382.     $sep ', ';
  383.     if (isset($table_right['dashboard'])) {
  384.       $this->R_DASHBOARD = $table_right['dashboard'];
  385.       $update .= "rights_dashboard='" $this->R_DASHBOARD . "'";
  386.     }
  387.     if (isset($table_right['project'])) {
  388.       $this->R_PROJECT = $table_right['project'];
  389.       $update .= $sep "rights_project='" $this->R_PROJECT . "'";
  390.     }
  391.     if (isset($table_right['publication'])) {
  392.       $this->R_PUBLICATION = $table_right['publication'];
  393.       $update .= $sep "rights_publication='" $this->R_PUBLICATION . "'";
  394.     }
  395.     if (isset($table_right['workshop'])) {
  396.       $this->R_WORKSHOP = $table_right['workshop'];
  397.       $update .= $sep "rights_workshop='" $this->R_WORKSHOP . "'";
  398.     }
  399.     if (isset($table_right['news'])) {
  400.       $this->R_NEWS = $table_right['news'];
  401.       $update .= $sep "rights_news='" $this->R_NEWS . "'";
  402.     }
  403.     if (isset($table_right['yellowpages'])) {
  404.       $this->R_YELLOWPAGES = $table_right['yellowpages'];
  405.       $update .= $sep "rights_yellowpages='" $this->R_YELLOWPAGES . "'";
  406.     }
  407.     if (isset($table_right['theme'])) {
  408.       $this->R_THEME = $table_right['theme'];
  409.       $update .= $sep "rights_theme='" $this->R_THEME . "'";
  410.     }
  411.     if (isset($table_right['scale'])) {
  412.       $this->R_SCALE = $table_right['scale'];
  413.       $update .= $sep "rights_scale='" $this->R_SCALE . "'";
  414.     }
  415.     if (isset($table_right['level'])) {
  416.       $this->R_LEVEL = $table_right['level'];
  417.       $update .= $sep "rights_level='" $this->R_LEVEL . "'";
  418.     }
  419.     if (isset($table_right['category_user'])) {
  420.       $this->R_CATEGORY_USER = $table_right['category_user'];
  421.       $update .= $sep "rights_category_user='" $this->R_CATEGORY_USER . "'";
  422.     }
  423.  
  424.     $requete "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  425.     $result $sql_object->DBSelect ($requete);
  426.     $requete "SELECT user_rights FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "';";
  427.     $result $sql_object->DBSelect ($requete);
  428.  
  429.     if ($result == 0return false;
  430.     if (count($result== 1{
  431.       $this->R_ID = $result[0]['user_rights'];
  432.     else return false;
  433.     $requete "UPDATE " T_RIGHT " SET " $update " WHERE rights_id='" $this->R_ID . "';";
  434.     $result $sql_object->DBQuery ($requete);
  435.     
  436.     if ($result{
  437.       $this->_SetUserCategory($table_right);
  438.       $requete "UPDATE " $this->TDB_USER . " SET user_category='" $this->CATEGORY . "' WHERE user_id='" $this->ID . "';";
  439.       
  440.       $result $sql_object->DBQuery ($requete);
  441.     }
  442.     return $result;
  443.   }
  444.  
  445.  
  446. }
  447.  
  448. ?>

Documentation generated on Fri, 16 Oct 2009 09:30:35 +0200 by phpDocumentor 1.4.1