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)
  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 (isset($sql_object)) {
  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($login20_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 ($result != 0return _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->DBInsert ($q1);
  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::deleteAvatar()
  378.    * creation aleatoire d'un passkey
  379.    *
  380.    * @access public
  381.    * @param string $user_id 
  382.    * @param object $sql_object 
  383.    * @return string $password
  384.    */
  385.   function deleteAvatar($id$sql_object)
  386.   {
  387.       
  388.       // Notify the end of the current method
  389.       $this->dispatcher->notify(new sfEvent($this'user.delete_avatar'array('id' => $id)));
  390.       
  391.       $q "SELECT profile_avatar FROM " T_PROFILE " WHERE profile_id='" $id "';";
  392.  
  393.       $data $sql_object->DBSelect($q);
  394.       if(count($data!= && $data[0]!=0{
  395.           return false;
  396.       else {
  397.           @unlink('../'.$r[0]['profile_avatar']);
  398.           $q "UPDATE " T_PROFILE " SET profile_avatar='' WHERE profile_id='" $id "';";
  399.           $r $sql_object->DBQuery($q);
  400.  
  401.           return $r;
  402.       }
  403.  
  404.   }
  405.  
  406.   /**
  407.    * user::ModifyWorkshops()
  408.    * Update workgroups for a given user
  409.    *
  410.    * @access public
  411.    * @param int $user_id identifiant du workshop
  412.    * @param array $workgroups workgroups to add
  413.    * @param string $user_right droit confié a l'utilisateur sur le workshop
  414.    * @param object $sql_object 
  415.    * @return integer $r
  416.    */
  417.   function ModifyWorkshops($user_id$workgroups$user_right $sql_object)
  418.   {
  419.       // Notify the end of the current method
  420.       $this->dispatcher->notify(new sfEvent($this'user.modify_workshops'array('id' => $user_id'workgroups' => $workgroups'user_rights' => $user_right)));
  421.        
  422.     if (is_numeric($user_id)) {
  423.       $this->ID = $user_id;
  424.     else return false;
  425.  
  426.     if($this->DeleteWorkshops($this->ID$user_right$sql_object)) {
  427.       $r $this->AddWorkshops($this->ID$workgroups$user_right$sql_object);
  428.     }
  429.  
  430.     return $r;
  431.   }
  432.  
  433.   /**
  434.    * user::generateNewPasskey()
  435.    * creation aleatoire d'un passkey
  436.    *
  437.    * @access public
  438.    * @param string $user_id 
  439.    * @param object $sql_object 
  440.    * @return string $password
  441.    */
  442.   function generateNewPasskey($user_id$sql_object)
  443.   {
  444.       // Notify the end of the current method
  445.       $this->dispatcher->notify(new sfEvent($this'user.generate_passkey'array('id' => $user_id)));
  446.       
  447.     $this->PASSKEY $this->GetNewPassword(30);
  448.     $q "UPDATE " $this->TDB_USER . " SET user_forget_passkey='" $this->PASSKEY "' WHERE user_id='" $user_id "';";
  449.  
  450.     $r $sql_object->DBQuery ($q);
  451.     if($rreturn $this->PASSKEY;
  452.     else return false;
  453.   }
  454.  
  455.   /**
  456.    * user::resetPasskey()
  457.    * creation aleatoire d'un passkey
  458.    *
  459.    * @access public
  460.    * @param string $user_id 
  461.    * @param object $sql_object 
  462.    * @return string $password
  463.    */
  464.   function resetPasskey($user_id$sql_object)
  465.   {
  466.       // Notify the end of the current method
  467.       $this->dispatcher->notify(new sfEvent($this'user.reset_passkey'array('id' => $user_id)));
  468.       
  469.     $q "UPDATE " $this->TDB_USER . " SET user_forget_passkey='' WHERE user_id='" $user_id "';";
  470.  
  471.     $r $sql_object->DBQuery ($q);
  472.     return $r;
  473.   }
  474.  
  475.   /**
  476.    * user::GetNewPassword()
  477.    * creation aleatoire d'un password
  478.    *
  479.    * @access public
  480.    * @param int $length taille du password
  481.    * @return string $password
  482.    */
  483.   function GetNewPassword($length PASSWD_MINLENGTH)
  484.   {
  485.       // Notify the end of the current method
  486.       $this->dispatcher->notify(new sfEvent($this'user.get_new_password'array('length' => $length)));
  487.       
  488.     $str 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  489.     $password '';
  490.     for ($i 0$i $length$i++{
  491.       $password .= substr($strrand(0strlen($str1)1);
  492.     }
  493.     return $password;
  494.   }
  495.  
  496.   /**
  497.    * user::InitUserRight()
  498.    * formatage du tableau de droit suivant profil prédeterminé
  499.    *
  500.    * @access public
  501.    * @param string $type niveau utilisateur : SIMPLE_USER ou ADMIN_USER
  502.    * @return array $table_right : tableau des droits de l'utilisateur
  503.    */
  504.   function InitUserRight($type 'SIMPLE_USER')
  505.   {
  506.  
  507.     $table_user array ("dashboard" => 'U'"workshop" => 'U'"publication" => 'U'"project" => 'U',
  508.             "news" => 'U'"yellowpages" => 'U'"theme" => 'U',
  509.             "scale" => 'U'"level" => 'U'"category_user" => 'U');
  510.  
  511.     switch ($type{
  512.       case 'SIMPLE_USER':
  513.         $table_right $table_user;
  514.         break;
  515.       case 'ADMIN_USER':
  516.         $table_right array ("dashboard" => 'A'"workshop" => 'A'"publication" => 'A',
  517.                     "project" => 'A'"news" => 'A'"yellowpages" => 'A',
  518.                     "theme" => 'A'"scale" => 'A'"level" => 'A',
  519.                     "category_user" => 'A');
  520.         break;
  521.       default:
  522.         $table_right $table_user;
  523.         break;
  524.     }
  525.     
  526.     // Filter data event + return value
  527.     $r $this->dispatcher->filter(new sfEvent($this'user.init_user_right'array('data' => $table_right))$table_right);
  528.     $table_right $r->getReturnValue();
  529.  
  530.     return $table_right;
  531.   }
  532.  
  533.  
  534.   /**
  535.    * user::UpdateUserPassword()
  536.    * changement de password (mise à jour) dans la bdd
  537.    *
  538.    * @access public
  539.    * @param int $ID identifiant utilisateur
  540.    * @param string $pass nouveau password non crypté
  541.    * @param object $sql_object 
  542.    * @return bool $result
  543.    */
  544.   function UpdateUserPassword($ID$pass$sql_object)
  545.   {
  546.       // Notify the end of the current method
  547.       $this->dispatcher->notify(new sfEvent($this'user.update_password'array('id' => $ID'password' => $pass)));
  548.       
  549.     if (is_numeric($ID)) {
  550.       $this->ID = $ID;
  551.     else exit($ID);
  552.     $this->PASSWORD = crypt($passSALT_CRYPT);
  553.     $q "UPDATE " $this->TDB_USER . " SET user_password='" $this->PASSWORD . "' WHERE user_id='" $this->ID . "';";
  554.     $result $sql_object->DBQuery ($q);
  555.  
  556.     return $result;
  557.   }
  558.  
  559.   /**
  560.    * user::AddUser()
  561.    * Ajout d'un utilisateur
  562.    *
  563.    * @access public
  564.    * @param array $table_user contient les composants de l'utilisateur
  565.    * @param array $table_right contient les droits attribués au nouvel utilisateur
  566.    * @param object $sql_object 
  567.    * @return integer $last_id
  568.    *  renvoie un message d'erreur ou un numerique id de l'insertion
  569.    */
  570.   function AddUser($table_user$table_right$sql_object)
  571.   {
  572.       // Filter data event + return value
  573.       $r $this->dispatcher->filter(new sfEvent($this'user.before_add'array('data' => $table_user'user_rights' => $table_right))$table_user);
  574.       $table_user $r->getReturnValue();
  575.       
  576.     $table_user=$sql_object->DBescape($table_user);
  577.  
  578.     $this->LOGIN = strip_input(trim($table_user[0]));
  579.     $this->P_EMAIL = strtolower($table_user[1]);
  580.     $this->P_EMAIL_DISPLAY = $table_user[2];
  581.     $this->P_FIRSTNAME = strip_input(trim($table_user[3]));
  582.     $this->P_LASTNAME = strip_input(trim($table_user[4]));
  583.     $this->PASSWORD = crypt($table_user[5]SALT_CRYPT);
  584.     $this->_SetUserCategory($table_right);
  585.     
  586.     $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());";
  587.  
  588.     $this->ID = $sql_object->DBInsert ($q1);
  589.     
  590.     $this->_AddProfile($this->ID$sql_object);
  591.     $this->_AddRight($this->ID$table_right$sql_object);
  592.  
  593.     $q "UPDATE " $this->TDB_USER . " SET user_rights=".$this->ID.", user_profile=".$this->ID." WHERE user_id=".$this->ID.";";
  594.  
  595.     $res $sql_object->DBQuery($q);
  596.     
  597.     if($res && (defined('NEWSLETTER_AUTO_SUB'&& NEWSLETTER_AUTO_SUB == 1)) {
  598.       include_once('../class/class.newsletter.php');
  599.       $newsletter new newsletter;
  600.       $newsletter->AddEmail($this->P_EMAIL$sql_object);
  601.     }
  602.  
  603.     // Notify the end of the current method
  604.     $this->dispatcher->notify(new sfEvent($this'user.after_add'array('data' => $table_user'user_rights' => $table_right'id' => $this->ID)));
  605.     
  606.     return $this->ID;
  607.   }
  608.  
  609.   /**
  610.    * user::DeleteUser()
  611.    * suppression d'un utilisateur
  612.    *
  613.    * @access public
  614.    * @param int $ID identifiant de l'utilisateur
  615.    * @param object $sql_object 
  616.    * @return bool $result
  617.    */
  618.   function DeleteUser($ID$sql_object)
  619.   {
  620.       // Notify the beginning of the current method
  621.       $this->dispatcher->notify(new sfEvent($this'user.delete'array('id' => $ID)));
  622.       
  623.     if (is_numeric($ID)) {
  624.       $this->ID = $ID;
  625.     else return false;
  626.     $q "UPDATE " $this->TDB_USER . " SET user_validity='N' WHERE user_id=" $this->ID . ";";
  627.     $result $sql_object->DBQuery ($q);
  628.     $q "DELETE FROM " J_WORK_USERS " WHERE jwu_user_id=" $this->ID . ";";
  629.     $res $sql_object->DBQuery ($q);
  630.  
  631.     return $res;
  632.   }
  633.  
  634.   /**
  635.    * user::ModifyProfile()
  636.    * modification d'un profil utilisateur
  637.    *
  638.    * @access public
  639.    * @param int $id identifiant d'un profil
  640.    * @param object $sql_object 
  641.    * @param array $table_profile contient les composants d'un profil
  642.    * @return bool $result
  643.    */
  644.   function ModifyProfile($ID$table_profile$sql_object)
  645.   {
  646.       // Filter data event + return value
  647.       $r $this->dispatcher->filter(new sfEvent($this'user.before_modify_profile'array('data' => $table_profile'id' => $ID))$table_profile);
  648.       $table_profile $r->getReturnValue();
  649.       
  650.     $table_profile=$sql_object->DBescape($table_profile);
  651.  
  652.     if (is_numeric($ID)) {
  653.       $this->ID = $ID;
  654.     else return false;
  655.  
  656.     $this->P_EMAIL = strtolower($table_profile[0]);
  657.  
  658.     $q "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  659.     $result $sql_object->DBSelect ($q);
  660.  
  661.     $q "SELECT user_profile FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "' LIMIT 1;";
  662.     $data $sql_object->DBSelect ($q'OBJECT');
  663.     if ($data!=&& count($data== 1{
  664.       $this->P_ID = $data[0]->user_profile;
  665.     else return false;
  666.     $this->P_EMAIL_DISPLAY = strtoupper($table_profile[1]);
  667.     $this->P_CITY = strip_input(ucfirst(trim($table_profile[2])));
  668.     $this->P_BIRTHDATE = ($table_profile[3]=='--''0001-01-01' formatDate($table_profile[3]true);
  669.     $this->P_LEISURES = strip_input(trim($table_profile[4]));
  670.     $this->P_JOB = strip_input(trim($table_profile[5]));
  671.     $this->P_QUOTATION = strip_input(trim($table_profile[6]));
  672.     $this->P_SIGNATURE = strip_input(trim($table_profile[7]));
  673.     $this->P_FIRSTNAME = strip_input(trim($table_profile[8]));
  674.     $this->P_LASTNAME = strip_input(trim($table_profile[9]));
  675.     $this->P_AVATAR = strip_input($table_profile[10]);
  676.  
  677.     $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 . "';";
  678.  
  679.     $result $sql_object->DBQuery ($q);
  680.     
  681.     // Notify the end of the current method
  682.     $this->dispatcher->notify(new sfEvent($this'user.after_modify_profile'array('data' => $table_profile'id' => $ID)));
  683.     
  684.  
  685.     return $result;
  686.   }
  687.  
  688.   /**
  689.    * user::ModifyRight()
  690.    * modification des droits d'un utilisateur
  691.    *
  692.    * @access public
  693.    * @param int $ID identifiant de l'utilisateur
  694.    * @param object $sql_object 
  695.    * @param array $table_right contient un tableau associatif de droit
  696.    * @return bool $result
  697.    */
  698.   function ModifyRight($ID$table_right$sql_object)
  699.   {
  700.       // Filter data event + return value
  701.       $r $this->dispatcher->filter(new sfEvent($this'user.before_modify_right'array('data' => $table_right'id' => $ID))$table_right);
  702.       $table_right $r->getReturnValue();
  703.       
  704.     if (is_numeric($ID)) {
  705.       $this->ID = $ID;
  706.     else return false;
  707.  
  708.     $update '';
  709.     $sep ', ';
  710.     if (isset($table_right['dashboard'])) {
  711.       $this->R_DASHBOARD = $table_right['dashboard'];
  712.       $update .= "rights_dashboard='" $this->R_DASHBOARD . "'";
  713.     }
  714.     if (isset($table_right['project'])) {
  715.       $this->R_PROJECT = $table_right['project'];
  716.       $update .= $sep "rights_project='" $this->R_PROJECT . "'";
  717.     }
  718.     if (isset($table_right['publication'])) {
  719.       $this->R_PUBLICATION = $table_right['publication'];
  720.       $update .= $sep "rights_publication='" $this->R_PUBLICATION . "'";
  721.     }
  722.     if (isset($table_right['workshop'])) {
  723.       $this->R_WORKSHOP = $table_right['workshop'];
  724.       $update .= $sep "rights_workshop='" $this->R_WORKSHOP . "'";
  725.     }
  726.     if (isset($table_right['news'])) {
  727.       $this->R_NEWS = $table_right['news'];
  728.       $update .= $sep "rights_news='" $this->R_NEWS . "'";
  729.     }
  730.     if (isset($table_right['yellowpages'])) {
  731.       $this->R_YELLOWPAGES = $table_right['yellowpages'];
  732.       $update .= $sep "rights_yellowpages='" $this->R_YELLOWPAGES . "'";
  733.     }
  734.     if (isset($table_right['theme'])) {
  735.       $this->R_THEME = $table_right['theme'];
  736.       $update .= $sep "rights_theme='" $this->R_THEME . "'";
  737.     }
  738.     if (isset($table_right['scale'])) {
  739.       $this->R_SCALE = $table_right['scale'];
  740.       $update .= $sep "rights_scale='" $this->R_SCALE . "'";
  741.     }
  742.     if (isset($table_right['level'])) {
  743.       $this->R_LEVEL = $table_right['level'];
  744.       $update .= $sep "rights_level='" $this->R_LEVEL . "'";
  745.     }
  746.     if (isset($table_right['category_user'])) {
  747.       $this->R_CATEGORY_USER = $table_right['category_user'];
  748.       $update .= $sep "rights_category_user='" $this->R_CATEGORY_USER . "'";
  749.     }
  750.  
  751.     $q "UPDATE " $this->TDB_USER . " SET user_last_modify=NOW() WHERE user_id='" $this->ID . "';";
  752.     $result $sql_object->DBSelect ($q);
  753.     $q "SELECT user_rights FROM " $this->TDB_USER . " WHERE user_id='" $this->ID . "';";
  754.     $result $sql_object->DBSelect ($q);
  755.  
  756.     if ($result == 0return false;
  757.     if (count($result== 1{
  758.       $this->R_ID = $result[0]['user_rights'];
  759.     else return false;
  760.     $q "UPDATE " T_RIGHT " SET " $update " WHERE rights_id='" $this->R_ID . "';";
  761.     $result $sql_object->DBQuery ($q);
  762.  
  763.     if ($result{
  764.       $this->_SetUserCategory($table_right);
  765.       $q "UPDATE " $this->TDB_USER . " SET user_category='" $this->CATEGORY . "' WHERE user_id='" $this->ID . "';";
  766.  
  767.       $result $sql_object->DBQuery ($q);
  768.     }
  769.     
  770.     // Notify the end of the current method
  771.     $this->dispatcher->notify(new sfEvent($this'user.after_modify_right'array('data' => $table_right'id' => $ID)));
  772.     return $result;
  773.   }
  774.  
  775.  
  776. }
  777.  
  778. ?>

Documentation generated on Mon, 08 Apr 2013 18:13:20 +0200 by phpDocumentor 1.4.1