diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 19c322df75d..90eef95c322 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -448,26 +448,39 @@ class Contrat // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($this->db); - $interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf); + $result=$interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf); + if ($result < 0) $error++; // Fin appel triggers - $this->db->commit(); - - return $this->id; + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$interface->error; + dolibarr_syslog("Contrat::create - 30 - ".$this->error); + + $this->db->rollback(); + return -3; + } } else { - $this->db->rollback(); + $this->error="Failed to add contact"; + dolibarr_syslog("Contrat::create - 20 - ".$this->error); - return -1; + $this->db->rollback(); + return -2; } } else { - $this->db->rollback(); - - dolibarr_syslog("Contrat::create - 10"); $this->error=$lang->trans("UnknownError: ".$this->db->error()." - sql=".$sql); + dolibarr_syslog("Contrat::create - 10 - ".$this->error); + + $this->db->rollback(); return -1; } } diff --git a/htdocs/includes/boxes/box_bookmarks.php b/htdocs/includes/boxes/box_bookmarks.php index 76b8d27e25d..b903f6ff900 100644 --- a/htdocs/includes/boxes/box_bookmarks.php +++ b/htdocs/includes/boxes/box_bookmarks.php @@ -98,7 +98,7 @@ class box_bookmarks extends ModeleBoxes { { if ($num==0 && $i==$num) { - $this->info_box_contents[$i][0] = array('align' => 'center','text'=>$langs->trans("NoRecordedBookmarks")); + $this->info_box_contents[$i][0] = array('align' => 'center','text'=>$langs->trans("NoRecordedBookmarks",DOL_URL_ROOT.'/bookmarks/liste.php')); $this->info_box_contents[$i][1] = array('text'=>' '); } else { $this->info_box_contents[$i][0] = array('text'=>' '); diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php index 4df63f8e1d1..62da20f2fce 100644 --- a/htdocs/includes/menus/barre_left/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php @@ -40,7 +40,7 @@ class MenuLeft { - var $require_top=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier + var $require_top=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier /** diff --git a/htdocs/includes/menus/barre_left/eldy_frontoffice.php b/htdocs/includes/menus/barre_left/eldy_frontoffice.php index 4df63f8e1d1..a4c7b0a368b 100644 --- a/htdocs/includes/menus/barre_left/eldy_frontoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_frontoffice.php @@ -40,7 +40,7 @@ class MenuLeft { - var $require_top=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier + var $require_top=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier /** @@ -107,7 +107,10 @@ class MenuLeft { /* * Menu HOME */ - if ($mainmenu == 'home') { + if ($mainmenu == 'home') + { + $newmenu->add(DOL_URL_ROOT.'/user/fiche.php?id='.$user->id.'&leftmenu=home', $langs->trans("MyAccount")); + if($user->admin) { $langs->load("admin"); @@ -137,12 +140,6 @@ class MenuLeft { if ($leftmenu=="system") $newmenu->add_submenu(DOL_URL_ROOT."/admin/system/database-tables-contraintes.php", $langs->trans("Constraints"),2); } - $langs->load("users"); - $newmenu->add(DOL_URL_ROOT."/user/home.php?leftmenu=users", $langs->trans("MenuUsersAndGroups")); - if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/index.php", $langs->trans("Users")); - if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/fiche.php?action=create", $langs->trans("NewUser"),2); - if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/group/index.php", $langs->trans("Groups")); - if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/group/fiche.php?action=create", $langs->trans("NewGroup"),2); } /* diff --git a/htdocs/includes/menus/barre_top/eldy_backoffice.php b/htdocs/includes/menus/barre_top/eldy_backoffice.php index c00447c34b8..1931adfcea0 100644 --- a/htdocs/includes/menus/barre_top/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_backoffice.php @@ -40,8 +40,8 @@ class MenuTop { - var $require_left=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier - var $atarget=""; // Valeur du target a utiliser dans les liens + var $require_left=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier + var $atarget=""; // Valeur du target a utiliser dans les liens /** diff --git a/htdocs/includes/menus/barre_top/eldy_frontoffice.php b/htdocs/includes/menus/barre_top/eldy_frontoffice.php index c00447c34b8..cdf88e0d22e 100644 --- a/htdocs/includes/menus/barre_top/eldy_frontoffice.php +++ b/htdocs/includes/menus/barre_top/eldy_frontoffice.php @@ -40,8 +40,8 @@ class MenuTop { - var $require_left=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier - var $atarget=""; // Valeur du target a utiliser dans les liens + var $require_left=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier + var $atarget=""; // Valeur du target a utiliser dans les liens /** diff --git a/htdocs/includes/triggers/interface_demo.class.php b/htdocs/includes/triggers/interface_demo.class.php index c59078da664..34c347a1a6f 100644 --- a/htdocs/includes/triggers/interface_demo.class.php +++ b/htdocs/includes/triggers/interface_demo.class.php @@ -17,7 +17,6 @@ * * $Id$ * $Source$ - * */ /** @@ -102,8 +101,21 @@ class InterfaceDemo // Mettre ici le code à exécuter en réaction de l'action // Les données de l'action sont stockées dans $object + // Users + if ($action == 'USER_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + } + elseif ($action == 'USER_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + } + elseif ($action == 'USER_DISABLE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + } // Companies - if ($action == 'COMPANY_CREATE') + elseif ($action == 'COMPANY_CREATE') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); } diff --git a/htdocs/langs/fr_FR/mails.lang b/htdocs/langs/fr_FR/mails.lang index a4039493467..73e303579ca 100644 --- a/htdocs/langs/fr_FR/mails.lang +++ b/htdocs/langs/fr_FR/mails.lang @@ -70,5 +70,5 @@ MailingNeedCommand=Pour des raisons de s TargetsReset=Vider liste ToClearAllRecipientsClickHere=Pour effacer la liste des destinataires de ce mailing, cliquer ici ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les listes ci-dessous -NbOfEMailingsReceived=Nb de mailings de masse reçus +NbOfEMailingsReceived=Mailings de masse reçus  IdRecord=ID enregistrement \ No newline at end of file diff --git a/htdocs/user.class.php b/htdocs/user.class.php index adb2b794876..1fea5f8b0f2 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -483,24 +483,44 @@ class User } - /** - * \brief Désactive un utilisateur - */ - + /** + * \brief Désactive un utilisateur + * \return int <0 si ko, >0 si ok + */ function disable() { + $error=0; + // Désactive utilisateur $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET login = NULL"; $sql.= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); + + if ($result) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_DISABLE',$this,$user,$lang,$conf); + if ($result < 0) $error++; + // Fin appel triggers + } + + if ($error) + { + return -$error; + } + else + { + return 1; + } } - /** - * \brief Supprime complètement un utilisateur - */ - + /** + * \brief Supprime complètement un utilisateur + */ function delete() { // Supprime droits @@ -526,22 +546,23 @@ class User } - /** - * \brief Crée un utilisateur en base - * \return si erreur <0, si ok renvoie id compte créé - */ - - function create() + /** + * \brief Crée un utilisateur en base + * \return int si erreur <0, si ok renvoie id compte créé + */ + function create() { global $langs; - + + $this->db->begin(); + $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';"; - $result=$this->db->query($sql); - if ($result) + $resql=$this->db->query($sql); + if ($resql) { - $num = $this->db->num_rows($result); - $this->db->free($result); - + $num = $this->db->num_rows($resql); + $this->db->free($resql); + if ($num) { $this->error = $langs->trans("ErrorLoginAlreadyExists"); @@ -549,94 +570,139 @@ class User } else { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,email) VALUES(now(),'$this->login','$this->email');"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login) VALUES(now(),'$this->login');"; $result=$this->db->query($sql); - + if ($result) { $table = "".MAIN_DB_PREFIX."user"; $this->id = $this->db->last_insert_id($table); - - if ($this->set_default_rights() < 0) return -4; - - if ($this->update() < 0) return -3; - - return $this->id; + + // Set default rights + if ($this->set_default_rights() < 0) + { + $this->db->rollback(); + + $this->error=$this->db->error(); + return -4; + } + + // Update minor fields + if ($this->update() < 0) + { + $this->db->rollback(); + + $this->error=$this->db->error(); + return -5; + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_CREATE',$this,$user,$lang,$conf); + if ($result < 0) $error++; + // Fin appel triggers + + if (! $error) + { + $this->db->commit(); + + return $this->id; + } + else + { + $this->db->rollback(); + + $this->error=$interface->error; + return -3; + } } else { - dolibarr_print_error($this->db); + $this->db->rollback(); + $this->error=$this->db->error(); return -2; } } } else { - dolibarr_print_error($this->db); + $this->db->rollback(); + $this->error=$this->db->error(); return -1; } } - /** - * \brief Créé en base un utilisateur depuis l'objetc contact - * \param contact Objet du contact source - * - */ - - function create_from_contact($contact) + + /** + * \brief Créé en base un utilisateur depuis l'objet contact + * \param contact Objet du contact source + * \return int si erreur <0, si ok renvoie id compte créé + */ + function create_from_contact($contact) { global $langs; + + // Positionne paramètres + $this->nom = $contact->nom; + $this->prenom = $contact->prenom; + + $this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3)); + $this->admin = 0; + + $this->email = $contact->email; + + $this->db->begin(); + + // Crée et positionne $this->id + $result=$this->create(); - $this->nom = $contact->nom; - $this->prenom = $contact->prenom; - $this->email = $contact->email; + if ($result > 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; + $sql.= " SET fk_socpeople=".$contact->id.", fk_societe=".$contact->societeid; + $sql.= " WHERE rowid=".$this->id; + $resql=$this->db->query($sql); - $this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3)); + if ($resql) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople"; + $sql.= " SET fk_user = ".$this->id; + $sql.= " WHERE idp = ".$contact->id; + $resql=$this->db->query($sql); + + if ($resql) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error()." - $sql"; + dolibarr_syslog("User::create_from_contact - 20 - ".$this->error); - $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'"; + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error()." - $sql"; + dolibarr_syslog("User::create_from_contact - 10 - ".$this->error); - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $this->db->free(); + $this->db->rollback(); + return -1; + } + } + else + { + // $this->error deja positionné + dolibarr_syslog("User::create_from_contact - 0"); - if ($num) - { - $this->error = $langs->trans("ErrorLoginAlreadyExists"); - return 0; - } - else - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec, login, fk_socpeople, fk_societe)"; - $sql .= " VALUES (now(),'$this->login',$contact->id, $contact->societeid);"; - if ($this->db->query($sql)) - { - if ($this->db->affected_rows()) - { - $table = "".MAIN_DB_PREFIX."user"; - $this->id = $this->db->last_insert_id($table); - $this->admin = 0; - $this->update(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = $this->id WHERE idp = $contact->id"; - $this->db->query($sql); - - $this->set_default_rights(); - - return $this->id; - } - } - else - { - dolibarr_print_error($this->db); - } - } - } - else - { - dolibarr_print_error($this->db); - } - + $this->db->rollback(); + return $result; + } + } /** @@ -679,12 +745,15 @@ class User /** * \brief Mise à jour en base d'un utilisateur - * \return <0 si echec, >=0 si ok + * \param create 1 si update durant le create, 0 sinon + * \return int <0 si echec, >=0 si ok */ - function update() + function update($create=0) { global $langs; + $error=0; + if (!strlen($this->code)) $this->code = $this->login; $sql = "UPDATE ".MAIN_DB_PREFIX."user SET "; @@ -707,6 +776,16 @@ class User { if ($this->db->affected_rows()) { + if (! $create) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_MODIFY',$this,$user,$lang,$conf); + if ($result < 0) $error++; + // Fin appel triggers + } + return 1; } return 0;