diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index 4717fecb88f..68829482589 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -803,6 +803,71 @@ class Adherent extends CommonObject } + /** + * \brief Set link to a user + * \param userid Id of user to link to + * \return int 1=OK, -1=KO + */ + function setUserId($userid) + { + global $conf, $langs; + + $this->db->begin(); + + // If user is linked to this member, remove old link to this member + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->id; + dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -1; } + + // Set link to user + if ($userid > 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id; + $sql.= " WHERE rowid = ".$userid; + dol_syslog("Adherent::setUserId sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -2; } + } + + $this->db->commit(); + + return 1; + } + + + /** + * \brief Set link to a third party + * \param userid Id of user to link to + * \return int 1=OK, -1=KO + */ + function setThirdPartyId($thirdpartyid) + { + global $conf, $langs; + + $this->db->begin(); + + // Update link to third party + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid>0 ? $thirdpartyid : 'null'); + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("Adherent::setThirdPartyId sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Adherent::setThirdPartyId ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + + /** * \brief Fonction qui recupere l'adherent depuis son login * \param login login de l'adherent diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 817f5a1d45b..c20ba40330c 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -92,6 +92,21 @@ if ($rowid) * Actions */ +if ($_POST['action'] == 'setuserid') +{ + $result=$adh->setUserId($_POST["userid"]); + if ($result < 0) dol_print_error($adh->db,$adh->error); + $_POST['action']=''; + $action=''; +} +if ($_POST['action'] == 'setsocid') +{ + $result=$adh->setThirdPartyId($_POST["socid"]); + if ($result < 0) dol_print_error($adh->db,$adh->error); + $_POST['action']=''; + $action=''; +} + // Create user from a member if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) { @@ -712,14 +727,27 @@ if ($action == 'edit') // Third party Dolibarr if ($conf->societe->enabled) { - print '
| '; + print $this->select_users($selected,$htmlname,1,0,0); + print ' | '; + print ''; + print ' |