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 = "library/userfiles/users/avatars/"// dossier racine de stockage des photos
  17.   var $NB_USERS = 30// affichage par défaut du nombre d'utilisateurs
  18.   var $UPLOAD_MAX_MO = 30720// 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_FIRSTNAME;
  45.   var $P_LASTNAME;
  46.   var $P_CITY;
  47.   var $P_BIRTHDATE;
  48.   var $P_LEISURES;
  49.   var $P_JOB;
  50.   var $P_AVATAR;
  51.   var $P_QUOTATION;
  52.   var $P_SIGNATURE;
  53.  
  54.   protected $dispatcher = null;
  55.  
  56.   public function __construct()
  57.   {
  58.     $this->dispatcher = $GLOBALS['dispatcher'];
  59.   }
  60.  
  61.   public function __call($method$arguments)
  62.   {
  63.     $event $this->dispatcher->notifyUntil(new sfEvent($this'user.extensible_function'array(
  64.       'method'    => $method,
  65.       'arguments' => $arguments
  66.     )));
  67.     if (!$event->isProcessed())
  68.     {
  69.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  70.     }
  71.  
  72.     return $event->getReturnValue();
  73.   }
  74.  
  75.   /**
  76.    * user::CheckDataIntegrity()
  77.    * Vérification intégrité des données
  78.    *
  79.    * @access public
  80.    * @param array $table : contient les composants d'un user
  81.    * @param object $sql_object 
  82.    * @return boolean si vrai renvoie true sinon message d'erreurs (string)
  83.    */
  84.   function CheckDataIntegrity($table$sql_object null$logincheck true)
  85.   {
  86.       // Filter data event + return value
  87.       $r $this->dispatcher->filter(new sfEvent($this'user.before_datacheck'array('data' => $table))$table);
  88.       $table $r->getReturnValue();
  89.       
  90.     if ($logincheck{
  91.       $result $this->_checkLoginValidity($table[0]$sql_object);
  92.       if (is_string($result)) return $result;
  93.     }
  94.     $result $this->_checkEmailValidity($table[1]);
  95.     if (is_string($result)) return $result;
  96.     
  97.     // Notify the beginning of the current method
  98.     $this->dispatcher->notify(new sfEvent($this'user.after_datacheck'array('data' => $table)));
  99.     
  100.     return true;
  101.   }
  102.  
  103.   /**
  104.    * user::_checkLoginValidity()
  105.    * validation d'un login
  106.    *
  107.    * @access private
  108.    * @param string $login : login rentré par l'utilisateur
  109.    * @param object $sql_object 
  110.    * @return bool $result
  111.    *  si valide true sinon message d'erreur (string)
  112.    */
  113.   function _checkLoginValidity($login$sql_object)
  114.   {
  115.       // Notify the beginning of the current method
  116.       $this->dispatcher->notify(new sfEvent($this'user.check_login_validity'array('login' => $login)));
  117.       
  118.     $login trim($login);
  119.     if (!preg_match('|^[a-zA-Z0-9_\.\-]+$|'$login)) return _t('user','login_prohibited');
  120.     if (strlen($login5return _t('user','login_tooshort');
  121.     if (strlen($login50_t('user','login_toolong');
  122.     $q "SELECT user_id FROM " $this->TDB_USER . " WHERE lower(user_login)= '" strtolower($login"' AND user_validity='Y';";
  123.  
  124.     $result $sql_object->DBSelect($q);
  125.  
  126.     if (isset($result[0]['user_id'])) return _t('user','login_used');
  127.  
  128.     return true;
  129.   }
  130.  
  131.   /**
  132.    * user::checkPasswordValidity()
  133.    * validation d'un password
  134.    *
  135.    * @access publi
  136.    * @param string $password password rentre par l'utilisateur
  137.    * @param string $pass2 (option)
  138.    * @return bool si valide true sinon message d'erreur (string)
  139.    */
  140.   function checkPasswordValidity($password$pass2 = -1)
  141.   {
  142.       // Notify the beginning of the current method
  143.       $this->dispatcher->notify(new sfEvent($this'user.check_password_validity'array('password' => $password'password2' => $pass2)));
  144.       
  145.     if (strlen($passwordPASSWD_MINLENGTHreturn sprintf(_t('user','pass_tooshort')PASSWD_MINLENGTH);
  146.     if (strlen($password15return _t('user','pass_toolong');
  147.     if ($pass2 != -&& $password != $pass2return _t('user','pass_not_same');
  148.  
  149.     return true;
  150.   }
  151.  
  152.   /**
  153.    * user::_checkEmailValidity()
  154.    * validation d'un email
  155.    *
  156.    * @access private
  157.    * @param string $email email rentre par l'utilisateur
  158.    * @return string $result
  159.    *  return 1 si valide sinon message d'erreur (string)
  160.    */
  161.   function _checkEmailValidity($email)
  162.   {
  163.  
  164.       // Notify the beginning of the current method
  165.       $this->dispatcher->notify(new sfEvent($this'user.check_email_validity'array('email' => $email)));
  166.       
  167.     $is_valid validEmail($email);
  168.  
  169.     if(!$is_valid{
  170.       return _t('user','invalid_mail'" :'" $email "'";
  171.     else {
  172.       return true;
  173.     }
  174.  
  175.   }
  176.  
  177.   /**
  178.    * user::_setUserCategory()
  179.    * determine automatique la categorie d'un utilisateur en fonction de ses droits
  180.    * et renseigne l'objet
  181.    *
  182.    * @access private
  183.    * @param array $table_right tableau des droits de l'utilisateur
  184.    * @return bool $result
  185.    */
  186.   function _setUserCategory($table_right)
  187.   {
  188.       // Notify the beginning of the current method
  189.       $this->dispatcher->notify(new sfEvent($this'user.set_usercategory'array('data' => $table_right)));
  190.       
  191.     if (isset($table_right['category_user']&& $table_right['category_user'== 'A'$this->CATEGORY = 1;
  192.     else {
  193.       if(in_array('A'array_values($table_right))) $this->CATEGORY = 1;
  194.       elseif ($table_right['dashboard'== 'O' || $table_right['publication'== 'O' || $table_right['news'== 'O' || $table_right['workshop'== 'O'$this->CATEGORY = 2;
  195.       else $this->CATEGORY = 3;
  196.     }
  197.  
  198.     return true;
  199.   }
  200.  
  201.   /**
  202.    * user::_AddProfile()
  203.    * Ajout d'un profil
  204.    *
  205.    * @access private
  206.    * @param integer id
  207.    * @param object $sql_object 
  208.    * @return integer $last_id
  209.    */
  210.   function _AddProfile($id$sql_object)
  211.   {
  212.       // Notify the beginning of the current method
  213.       $this->dispatcher->notify(new sfEvent($this'user.add_profile'array('id' => $id)));
  214.       
  215.     $q "INSERT INTO " T_PROFILE " (profile_id, 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 (".$id.", '" $this->P_FIRSTNAME . "', '" $this->P_LASTNAME . "', '" $this->P_EMAIL . "', '" $this->P_EMAIL_DISPLAY . "','', '0001-01-01', '', '', '', '', '', NOW());";
  216.     $r $sql_object->DBInsert ($q);
  217.     
  218.     return $r;
  219.   }
  220.  
  221.   /**
  222.    * user::_AddRight()
  223.    * stockage des droits d' un utilisateur BDD
  224.    *
  225.    * @access private
  226.    * @param integer id
  227.    * @param array $table_right contient les droits
  228.    * @param object $sql_object 
  229.    * @return integer $last_id
  230.    */
  231.   function _AddRight($id$table_right$sql_object)
  232.   {
  233.  
  234.       // Filter data event + return value
  235.       $r $this->dispatcher->filter(new sfEvent($this'user.before_add_right'array('data' => $table_right,'id' => $id))$table_right);
  236.       $table_right $r->getReturnValue();
  237.       
  238.     $this->R_DASHBOARD = $table_right['dashboard'];
  239.     $this->R_WORKSHOP = $table_right['workshop'];
  240.     $this->R_PROJECT = $table_right['project'];
  241.     $this->R_PUBLICATION = $table_right['publication'];
  242.     $this->R_NEWS = $table_right['news'];
  243.     $this->R_YELLOWPAGES = $table_right['yellowpages'];
  244.     $this->R_THEME = $table_right['theme'];
  245.     $this->R_SCALE = $table_right['scale'];
  246.     $this->R_LEVEL = $table_right['level'];
  247.     $this->R_CATEGORY_USER = $table_right['category_user'];
  248.     $q "INSERT INTO " T_RIGHT " (rights_id, 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 (".$id.", '" $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());";
  249.     $r $sql_object->DBInsert ($q);
  250.     
  251.     // Notify the end of the current method
  252.     $this->dispatcher->notify(new sfEvent($this'user.after_add_right'array('data' => $table_right'id' => $id)));
  253.     
  254.     return $r;
  255.   }
  256.  
  257.   /**
  258.    * user::GetUserWorkshops()
  259.    * Ajout d'un utilisateur à un ou plusieurs workshops
  260.    *
  261.    * @access public
  262.    * @param int $user_id identifiant du workshop
  263.    * @param array $workgroups workgroups ID
  264.    * @param string $user_right droit confié a l'utilisateur sur le workshop
  265.    * @param object $sql_object 
  266.    * @return integer $last_id
  267.    */
  268.   function GetUserWorkshops($user_id$sql_object)
  269.   {
  270.       // Notify the end of the current method
  271.       $this->dispatcher->notify(new sfEvent($this'user.get_user_workshops'array('id' => $user_id)));
  272.       
  273.     if (is_numeric($user_id)) {
  274.       $this->ID = $user_id;
  275.     else return false;
  276.  
  277.     $q "SELECT jwu_workshop_id, workshop_denomination, jwu_user_right FROM ".J_WORK_USERS."
  278.               LEFT OUTER JOIN " T_WORK " ON jwu_workshop_id=workshop_id
  279.               WHERE jwu_user_id=".$this->ID." AND jwu_user_right='U';";
  280.     $r $sql_object->DBSelect ($q);
  281.  
  282.     return $r;
  283.   }
  284.   
  285.   /**
  286.   * user::changeWorkshopsNotification()
  287.   * Change workshops notification for a given user
  288.   *
  289.   * @access public
  290.   * @param object $sql_object 
  291.   * @return integer $last_id
  292.   */
  293.   function changeWorkshopsNotification($user_id$exceptions$sql_object)
  294.   {
  295.       // Notify the end of the current method
  296.       $this->dispatcher->notify(new sfEvent($this'user.change_workshops_notification'array('id' => $id'data' => $exceptions)));
  297.   
  298.       $q "DELETE FROM " T_WORK_NOTIFY " WHERE user_id=" $user_id";";
  299.       $r $sql_object->DBQuery ($q);
  300.       
  301.       foreach($exceptions as $el{
  302.         list($type$workgroup)explode('-'$el);
  303.         $q "INSERT INTO " T_WORK_NOTIFY " (user_id, workshop_id, type) VALUES(".$user_id.", ".$workgroup.", '".$type."');";
  304.         $r $sql_object->DBInsert ($q);
  305.       }
  306.   
  307.       return $r;
  308.   }
  309.  
  310.   /**
  311.    * user::DeleteWorkshops()
  312.    * Remove all workshops for a given user
  313.    *
  314.    * @access public
  315.    * @param object $sql_object 
  316.    * @return integer $last_id
  317.    */
  318.   function DeleteWorkshops($user_id$user_right$sql_object)
  319.   {
  320.       // Notify the end of the current method
  321.       $this->dispatcher->notify(new sfEvent($this'user.delete_workshops'array('id' => $user_id'user_rights' => $user_right)));
  322.       
  323.     if (is_numeric($user_id)) {
  324.       $this->ID = $user_id;
  325.     else return false;
  326.  
  327.     $q "DELETE FROM " J_WORK_USERS " WHERE jwu_user_id=" $this->ID . " AND jwu_user_right='".$user_right."';";
  328.     $r $sql_object->DBQuery ($q);
  329.  
  330.     return $r;
  331.   }
  332.  
  333.   /**
  334.    * user::AddWorkshops()
  335.    * Ajout d'un utilisateur à un ou plusieurs workshops
  336.    *
  337.    * @access public
  338.    * @param int $user_id identifiant du workshop
  339.    * @param array $workgroups workgroups ID
  340.    * @param string $user_right droit confié a l'utilisateur sur le workshop
  341.    * @param object $sql_object 
  342.    * @return integer $last_id
  343.    */
  344.   function AddWorkshops($user_id$workgroups$user_right $sql_object)
  345.   {
  346.       // Notify the end of the current method
  347.       $this->dispatcher->notify(new sfEvent($this'user.add_workshops'array('id' => $user_id'workgroups' => $workgroups'user_rights' => $user_right)));
  348.       
  349.     if (is_numeric($user_id)) {
  350.       $this->ID = $user_id;
  351.     else return false;
  352.  
  353.     if(count($workgroups)==0return true;
  354.  
  355.     for ($i 0;$i count($workgroups);$i++{
  356.  
  357.       // check if user already belong to the group
  358.       $q "SELECT COUNT(jwu_id) AS nb FROM " J_WORK_USERS " WHERE jwu_user_id=" $this->ID . " AND jwu_workshop_id=" $workgroups[$i";";
  359.       $data $sql_object->DBSelect($q'OBJECT');
  360.  
  361.       // in case it is a pending user already in database
  362.       if ($data[0]->nb == 1{
  363.           $q "UPDATE " J_WORK_USERS " SET jwu_user_right='" $user_right "' WHERE jwu_workshop_id=" $workgroups[$i" AND jwu_user_id =" $this->ID . ";";
  364.           $last_id $sql_object->DBQuery ($q);
  365.       }
  366.       if ($data[0]->nb != 1{
  367.         $q "INSERT INTO " J_WORK_USERS " (jwu_workshop_id, jwu_user_id, jwu_user_right) VALUES(" $workgroups[$i", " $this->ID . ",'" $user_right "');";
  368.         $last_id $sql_object->DBInsert ($q1);
  369.       }
  370.       
  371.     }
  372.  
  373.     return true;
  374.   }
  375.   
  376.   /**
  377.    * user::changeLogin()
  378.    * Modifie le login d'un utilisateur
  379.    *
  380.    * @access public
  381.    * @param string $id 
  382.    * @param string $login 
  383.    * @param string $old_login 
  384.    * @param object $sql_object 
  385.    * @return string $password
  386.    */
  387.   function changeLogin($id$login$old_login$sql_object)
  388.   {
  389.        $sep ',';
  390.        
  391.       // Notify the end of the current method
  392.       $this->dispatcher->notify(new sfEvent($this'user.change_login'array('id' => $id'login' => $login)));
  393.        
  394.       $q "UPDATE " T_USER " SET user_login = '".$login."', user_old_logins = CONCAT(user_old_logins,'"$sep $old_login ."') WHERE user_id='" $id "';";
  395.   
  396.       $data $sql_object->DBQuery($q);
  397.  
  398.       return true;
  399.   
  400.   }
  401.   
  402.   /**
  403.    * user::deleteAvatar()
  404.    * creation aleatoire d'un passkey
  405.    *
  406.    * @access public
  407.    * @param string $user_id 
  408.    * @param object $sql_object 
  409.    * @return string $password
  410.    */
  411.   function deleteAvatar($id$sql_object)
  412.   {
  413.       
  414.       // Notify the end of the current method
  415.       $this->dispatcher->notify(new sfEvent($this'user.delete_avatar'array('id' => $id)));
  416.       
  417.       $q "SELECT profile_avatar FROM " T_PROFILE " WHERE profile_id='" $id "';";
  418.  
  419.       $data $sql_object->DBSelect($q);
  420.       if(count($data!= && $data[0]!=0{
  421.           return false;
  422.       else {
  423.           @unlink('../'.$r[0]['profile_avatar']);
  424.           $q "UPDATE " T_PROFILE " SET profile_avatar='' WHERE profile_id='" $id "';";
  425.           $r $sql_object->DBQuery($q);
  426.  
  427.           return $r;
  428.       }
  429.  
  430.   }
  431.  
  432.   /**
  433.    * user::ModifyWorkshops()
  434.    * Update workgroups for a given user
  435.    *
  436.    * @access public
  437.    * @param int $user_id identifiant du workshop
  438.    * @param array $workgroups workgroups to add
  439.    * @param string $user_right droit confié a l'utilisateur sur le workshop
  440.    * @param object $sql_object 
  441.    * @return integer $r
  442.    */
  443.   function ModifyWorkshops($user_id$workgroups$user_right $sql_object)
  444.   {
  445.       // Notify the end of the current method
  446.       $this->dispatcher->notify(new sfEvent($this'user.modify_workshops'array('id' => $user_id'workgroups' => $workgroups'user_rights' => $user_right)));
  447.        
  448.     if (is_numeric($user_id)) {
  449.       $this->ID = $user_id;
  450.     else return false;
  451.  
  452.     if($this->DeleteWorkshops($this->ID$user_right$sql_object)) {
  453.       $r $this->AddWorkshops($this->ID$workgroups$user_right$sql_object);
  454.     }
  455.  
  456.     return $r;
  457.   }
  458.  
  459.   /**
  460.    * user::generateNewPasskey()
  461.    * creation aleatoire d'un passkey
  462.    *
  463.    * @access public
  464.    * @param string $user_id 
  465.    * @param object $sql_object 
  466.    * @return string $password
  467.    */
  468.   function generateNewPasskey($user_id$sql_object)
  469.   {
  470.       // Notify the end of the current method
  471.       $this->dispatcher->notify(new sfEvent($this'user.generate_passkey'array('id' => $user_id)));
  472.       
  473.     $this->PASSKEY $this->GetNewPassword(30);
  474.     $q "UPDATE " $this->TDB_USER . " SET user_forget_passkey='" $this->PASSKEY "' WHERE user_id='" $user_id "';";
  475.  
  476.     $r $sql_object->DBQuery ($q);
  477.     if($rreturn $this->PASSKEY;
  478.     else return false;
  479.   }
  480.  
  481.   /**
  482.    * user::resetPasskey()
  483.    * creation aleatoire d'un passkey
  484.    *
  485.    * @access public
  486.    * @param string $user_id 
  487.    * @param object $sql_object 
  488.    * @return string $password
  489.    */
  490.   function resetPasskey($user_id$sql_object)
  491.   {
  492.       // Notify the end of the current method
  493.       $this->dispatcher->notify(new sfEvent($this'user.reset_passkey'array('id' => $user_id)));
  494.       
  495.     $q "UPDATE " $this->TDB_USER . " SET user_forget_passkey='' WHERE user_id='" $user_id "';";
  496.  
  497.     $r $sql_object->DBQuery ($q);
  498.     return $r;
  499.   }
  500.  
  501.   /**
  502.    * user::GetNewPassword()
  503.    * creation aleatoire d'un password
  504.    *
  505.    * @access public
  506.    * @param int $length taille du password
  507.    * @return string $password
  508.    */
  509.   function GetNewPassword($length PASSWD_MINLENGTH)
  510.   {
  511.       // Notify the end of the current method
  512.       $this->dispatcher->notify(new sfEvent($this'user.get_new_password'array('length' => $length)));
  513.       
  514.     $str 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  515.     $password '';
  516.     for ($i 0$i $length$i++{
  517.       $password .= substr($strrand(0strlen($str1)1);
  518.     }
  519.     return $password;
  520.   }
  521.  
  522.   /**
  523.    * user::InitUserRight()
  524.    * formatage du tableau de droit suivant profil prédeterminé
  525.    *
  526.    * @access public
  527.    * @param string $type niveau utilisateur : SIMPLE_USER ou ADMIN_USER
  528.    * @return array $table_right : tableau des droits de l'utilisateur
  529.    */
  530.   function InitUserRight($type 'SIMPLE_USER')
  531.   {
  532.  
  533.     $table_user array ("dashboard" => 'U'"workshop" => 'U'"publication" => 'U'"project" => 'U',
  534.             "news" => 'U'"yellowpages" => 'U'"theme" => 'U',
  535.             "scale" => 'U'"level" => 'U'"category_user" => 'U');
  536.  
  537.     switch ($type{
  538.       case 'SIMPLE_USER':
  539.         $table_right $table_user;
  540.         break;
  541.       case 'ADMIN_USER':
  542.         $table_right array ("dashboard" => 'A'"workshop" => 'A'"publication" => 'A',
  543.                     "project" => 'A'"news" => 'A'"yellowpages" => 'A',
  544.                     "theme" => 'A'"scale" => 'A'"level" => 'A',
  545.                     "category_user" => 'A');
  546.         break;
  547.       default:
  548.         $table_right $table_user;
  549.         break;
  550.     }
  551.     
  552.     // Filter data event + return value
  553.     $r $this->dispatcher->filter(new sfEvent($this'user.init_user_right'array('data' => $table_right))$table_right);
  554.     $table_right $r->getReturnValue();
  555.  
  556.     return $table_right;
  557.   }
  558.  
  559.  
  560.   /**
  561.    * user::UpdateUserPassword()
  562.    * changement de password (mise à jour) dans la bdd
  563.    *
  564.    * @access public
  565.    * @param int $ID identifiant utilisateur
  566.    * @param string $pass nouveau password non crypté
  567.    * @param object $sql_object 
  568.    * @return bool $result
  569.    */
  570.   function UpdateUserPassword($ID$pass$sql_object)
  571.   {
  572.       // Notify the end of the current method
  573.       $this->dispatcher->notify(new sfEvent($this'user.update_password'array('id' => $ID'password' => $pass)));
  574.       
  575.     if (is_numeric($ID)) {
  576.       $this->ID = $ID;
  577.     else exit($ID);
  578.     $this->PASSWORD = crypt($passSALT_CRYPT);
  579.     $q "UPDATE " $this->TDB_USER . " SET user_password='" $this->PASSWORD . "' WHERE user_id='" $this->ID . "';";
  580.     $result $sql_object->DBQuery ($q);
  581.  
  582.     return $result;
  583.   }
  584.  
  585.   /**
  586.    * user::AddUser()
  587.    * Ajout d'un utilisateur
  588.    *
  589.    * @access public
  590.    * @param array $table_user contient les composants de l'utilisateur
  591.    * @param array $table_right contient les droits attribués au nouvel utilisateur
  592.    * @param object $sql_object 
  593.    * @return integer $last_id
  594.    *  renvoie un message d'erreur ou un numerique id de l'insertion
  595.    */
  596.   function AddUser($table_user$table_right$sql_object$donotcrypt false)
  597.   {
  598.       // Filter data event + return value
  599.       $r $this->dispatcher->filter(new sfEvent($this'user.before_add'array('data' => $table_user'user_rights' => $table_right))$table_user);
  600.       $table_user $r->getReturnValue();
  601.       
  602.     $table_user=$sql_object->DBescape($table_user);
  603.  
  604.     $this->LOGIN = strip_input(trim($table_user[0]));
  605.     $this->P_EMAIL = strtolower($table_user[1]);
  606.     $this->P_EMAIL_DISPLAY = $table_user[2];
  607.     $this->P_FIRSTNAME = strip_input(trim($table_user[3]));
  608.     $this->P_LASTNAME = strip_input(trim($table_user[4]));
  609.     if($donotcrypt{
  610.         $this->PASSWORD = $table_user[5];
  611.     else {
  612.         $this->PASSWORD = crypt($table_user[5]SALT_CRYPT);
  613.     }
  614.     $this->_SetUserCategory($table_right);
  615.     
  616.     $q "INSERT INTO " $this->TDB_USER . " (user_login, user_password, user_community, user_category, user_date_crea) VALUES ('" $this->LOGIN . "', '" $this->PASSWORD . "', " $this->COMMUNITY . ", " $this->CATEGORY . ", NOW());";
  617.  
  618.     $this->ID = $sql_object->DBInsert ($q1);
  619.     
  620.     $this->_AddProfile($this->ID$sql_object);
  621.     $this->_AddRight($this->ID$table_right$sql_object);
  622.  
  623.     $q "UPDATE " $this->TDB_USER . " SET user_rights=".$this->ID.", user_profile=".$this->ID." WHERE user_id=".$this->ID.";";
  624.  
  625.     $res $sql_object->DBQuery($q);
  626.     
  627.     if($res && (defined('NEWSLETTER_AUTO_SUB'&& NEWSLETTER_AUTO_SUB == 1)) {
  628.       include_once('../class/class.newsletter.php');
  629.       $newsletter new newsletter;
  630.       $newsletter->AddEmail($this->P_EMAIL$sql_object);
  631.     }
  632.  
  633.     // Notify the end of the current method
  634.     $this->dispatcher->notify(new sfEvent($this'user.after_add'array('data' => $table_user'user_rights' => $table_right'id' => $this->ID)));
  635.     
  636.     return $this->ID;
  637.   }
  638.  
  639.   /**
  640.    * user::DeleteUser()
  641.    * suppression d'un utilisateur
  642.    *
  643.    * @access public
  644.    * @param int $ID identifiant de l'utilisateur
  645.    * @param object $sql_object 
  646.    * @return bool $result
  647.    */
  648.   function DeleteUser($ID$sql_object)
  649.   {
  650.       // Notify the beginning of the current method
  651.       $this->dispatcher->notify(new sfEvent($this'user.delete'array('id' => $ID)));
  652.       
  653.     if (is_numeric($ID)) {
  654.       $this->ID = $ID;
  655.     else return false;
  656.     $q "UPDATE " $this->TDB_USER . " SET user_validity='N' WHERE user_id=" $this->ID . ";";
  657.     $result $sql_object->DBQuery ($q);
  658.     $q "DELETE FROM " J_WORK_USERS " WHERE jwu_user_id=" $this->ID . ";";
  659.     $res $sql_object->DBQuery ($q);
  660.  
  661.     return $res;
  662.   }
  663.  
  664.   /**
  665.    * user::ModifyProfile()
  666.    * modification d'un profil utilisateur
  667.    *
  668.    * @access public
  669.    * @param int $id identifiant d'un profil
  670.    * @param object $sql_object 
  671.    * @param array $table_profile contient les composants d'un profil
  672.    * @return bool $result
  673.    */
  674.   function ModifyProfile($ID$table_profile$sql_object)
  675.   {
  676.       // Filter data event + return value
  677.       $r $this->dispatcher->filter(new sfEvent($this'user.before_modify_profile'array('data' => $table_profile'id' => $ID))$table_profile);
  678.       $table_profile $r->getReturnValue();
  679.       
  680.     $table_profile=$sql_object->DBescape($table_profile);
  681.  
  682.     if (is_numeric($ID)) {
  683.       $this->ID = $ID;
  684.     else return false;
  685.  
  686.     $this->P_EMAIL = strtolower($table_profile[0]);
  687.  
  688.     $q "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  689.     $result $sql_object->DBQuery($q);
  690.  
  691.     $q "SELECT user_profile FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "' LIMIT 1;";
  692.     $data $sql_object->DBSelect ($q'OBJECT');
  693.     if ($data!=&& count($data== 1{
  694.       $this->P_ID = $data[0]->user_profile;
  695.     else return false;
  696.     $this->P_EMAIL_DISPLAY = strtoupper($table_profile[1]);
  697.     $this->P_CITY = strip_input(ucfirst(trim($table_profile[2])));
  698.     $this->P_BIRTHDATE = ($table_profile[3]=='--''0001-01-01' formatDate($table_profile[3]true);
  699.     $this->P_LEISURES = strip_input(trim($table_profile[4]));
  700.     $this->P_JOB = strip_input(trim($table_profile[5]));
  701.     $this->P_QUOTATION = strip_input(trim($table_profile[6]));
  702.     $this->P_SIGNATURE = strip_input(trim($table_profile[7]));
  703.     $this->P_FIRSTNAME = strip_input(trim($table_profile[8]));
  704.     $this->P_LASTNAME = strip_input(trim($table_profile[9]));
  705.     $this->P_AVATAR = strip_input($table_profile[10]);
  706.  
  707.     $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 . "';";
  708.  
  709.     $result $sql_object->DBQuery ($q);
  710.     
  711.     // Notify the end of the current method
  712.     $this->dispatcher->notify(new sfEvent($this'user.after_modify_profile'array('data' => $table_profile'id' => $ID)));
  713.     
  714.  
  715.     return $result;
  716.   }
  717.  
  718.   /**
  719.    * user::ModifyRight()
  720.    * modification des droits d'un utilisateur
  721.    *
  722.    * @access public
  723.    * @param int $ID identifiant de l'utilisateur
  724.    * @param object $sql_object 
  725.    * @param array $table_right contient un tableau associatif de droit
  726.    * @return bool $result
  727.    */
  728.   function ModifyRight($ID$table_right$sql_object)
  729.   {
  730.       // Filter data event + return value
  731.       $r $this->dispatcher->filter(new sfEvent($this'user.before_modify_right'array('data' => $table_right'id' => $ID))$table_right);
  732.       $table_right $r->getReturnValue();
  733.       
  734.     if (is_numeric($ID)) {
  735.       $this->ID = $ID;
  736.     else return false;
  737.  
  738.     $update '';
  739.     $sep ', ';
  740.     if (isset($table_right['dashboard'])) {
  741.       $this->R_DASHBOARD = $table_right['dashboard'];
  742.       $update .= "rights_dashboard='" $this->R_DASHBOARD . "'";
  743.     }
  744.     if (isset($table_right['project'])) {
  745.       $this->R_PROJECT = $table_right['project'];
  746.       $update .= $sep "rights_project='" $this->R_PROJECT . "'";
  747.     }
  748.     if (isset($table_right['publication'])) {
  749.       $this->R_PUBLICATION = $table_right['publication'];
  750.       $update .= $sep "rights_publication='" $this->R_PUBLICATION . "'";
  751.     }
  752.     if (isset($table_right['workshop'])) {
  753.       $this->R_WORKSHOP = $table_right['workshop'];
  754.       $update .= $sep "rights_workshop='" $this->R_WORKSHOP . "'";
  755.     }
  756.     if (isset($table_right['news'])) {
  757.       $this->R_NEWS = $table_right['news'];
  758.       $update .= $sep "rights_news='" $this->R_NEWS . "'";
  759.     }
  760.     if (isset($table_right['yellowpages'])) {
  761.       $this->R_YELLOWPAGES = $table_right['yellowpages'];
  762.       $update .= $sep "rights_yellowpages='" $this->R_YELLOWPAGES . "'";
  763.     }
  764.     if (isset($table_right['theme'])) {
  765.       $this->R_THEME = $table_right['theme'];
  766.       $update .= $sep "rights_theme='" $this->R_THEME . "'";
  767.     }
  768.     if (isset($table_right['scale'])) {
  769.       $this->R_SCALE = $table_right['scale'];
  770.       $update .= $sep "rights_scale='" $this->R_SCALE . "'";
  771.     }
  772.     if (isset($table_right['level'])) {
  773.       $this->R_LEVEL = $table_right['level'];
  774.       $update .= $sep "rights_level='" $this->R_LEVEL . "'";
  775.     }
  776.     if (isset($table_right['category_user'])) {
  777.       $this->R_CATEGORY_USER = $table_right['category_user'];
  778.       $update .= $sep "rights_category_user='" $this->R_CATEGORY_USER . "'";
  779.     }
  780.  
  781.     $q "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  782.     $result $sql_object->DBSelect ($q);
  783.     $q "SELECT user_rights FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "';";
  784.     $result $sql_object->DBSelect ($q);
  785.  
  786.     if ($result == 0return false;
  787.     if (count($result== 1{
  788.       $this->R_ID = $result[0]['user_rights'];
  789.     else return false;
  790.     $q "UPDATE " T_RIGHT " SET " $update " WHERE rights_id='" $this->R_ID . "';";
  791.     $result $sql_object->DBQuery ($q);
  792.  
  793.     if ($result{
  794.       $this->_SetUserCategory($table_right);
  795.       $q "UPDATE " $this->TDB_USER . " SET user_category='" $this->CATEGORY . "' WHERE user_id='" $this->ID . "';";
  796.  
  797.       $result $sql_object->DBQuery ($q);
  798.     }
  799.     
  800.     // Notify the end of the current method
  801.     $this->dispatcher->notify(new sfEvent($this'user.after_modify_right'array('data' => $table_right'id' => $ID)));
  802.     return $result;
  803.   }
  804.  
  805.  
  806. }
  807.  
  808. ?>

Documentation generated on Thu, 20 Mar 2014 16:47:04 +0100 by phpDocumentor 1.4.1