From 55159317292935c7235bf85a3449f34630fb63e6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Jul 2009 16:17:56 +0000 Subject: [PATCH] Fix: Some change to fix pb of editing password of a user by linking a member to it. --- htdocs/adherents/adherent.class.php | 65 +++++++++++++++++ htdocs/adherents/fiche.php | 105 ++++++++++++++++++++++------ htdocs/html.form.class.php | 49 ++++++++++++- 3 files changed, 193 insertions(+), 26 deletions(-) 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 ''.$langs->trans("LinkedToDolibarrThirdParty").''; - print $html->select_societes($adh->fk_soc,'socid','',1); + print ''.$langs->trans("LinkedToDolibarrThirdParty").''; + if ($adh->fk_soc) + { + $company=new Societe($db); + $result=$company->fetch($adh->fk_soc); + print $company->getNomUrl(1); + } + else + { + print $langs->trans("NoThirdPartyAssociatedToMember"); + } print ''; } // Login Dolibarr print ''.$langs->trans("LinkedToDolibarrUser").''; - print $html->select_users($adh->user_id,'userid',1); + if ($adh->user_id) + { + print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'none'); + } + else print $langs->trans("NoDolibarrAccess"); print ''; print ''; @@ -988,7 +1016,6 @@ if ($rowid && $action != 'edit') $rowspan=14+sizeof($adho->attribute_label); if ($conf->societe->enabled) $rowspan++; - print '
'; print ''; print ''; @@ -1070,34 +1097,66 @@ if ($rowid && $action != 'edit') // Third party Dolibarr if ($conf->societe->enabled) { - print ''; } // Login Dolibarr - print ''; print "
'.$langs->trans("LinkedToDolibarrThirdParty").''; - if ($adh->fk_soc) - { - $company=new Societe($db); - $result=$company->fetch($adh->fk_soc); - print $company->getNomUrl(1); - } - else - { - print $langs->trans("NoThirdPartyAssociatedToMember"); - } + print '
'; + print ''; + if ($_GET['action'] != 'editthirdparty' && $user->rights->adherent->creer) print ''; + print '
'; + print $langs->trans("LinkedToDolibarrThirdParty"); + print 'id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'
'; + print '
'; + if ($_GET['action'] == 'editthirdparty') + { + $page=$_SERVER['PHP_SELF'].'?rowid='.$adh->id; + $htmlname='socid'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $html->select_societes($adh->fk_soc,'socid','',1); + print '
'; + } + else + { + if ($adh->fk_soc) + { + $company=new Societe($db); + $result=$company->fetch($adh->fk_soc); + print $company->getNomUrl(1); + } + else + { + print $langs->trans("NoThirdPartyAssociatedToMember"); + } + } print '
'.$langs->trans("LinkedToDolibarrUser").''; - if ($adh->user_id) + print '
'; + print ''; + if ($_GET['action'] != 'editlogin' && $user->rights->adherent->creer) print ''; + print '
'; + print $langs->trans("LinkedToDolibarrUser"); + print 'id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'
'; + print '
'; + if ($_GET['action'] == 'editlogin') { - $dolibarr_user=new User($db); - $dolibarr_user->id=$adh->user_id; - $result=$dolibarr_user->fetch(); - print $dolibarr_user->getLoginUrl(1); + print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'userid'); + } + else + { + if ($adh->user_id) + { + print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'none'); + } + else print $langs->trans("NoDolibarrAccess"); } - else print $langs->trans("NoDolibarrAccess"); print '
\n"; - print ''; print "\n"; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 53fdfa25e0c..ba3f08661d3 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -681,7 +681,7 @@ class Form if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // On recherche les utilisateurs - $sql = "SELECT u.rowid, u.name, u.firstname FROM"; + $sql = "SELECT u.rowid, u.name, u.firstname, u.login FROM"; $sql.= " ".MAIN_DB_PREFIX ."user as u"; $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')"; @@ -702,12 +702,15 @@ class Form if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid)) { - print ''; + print ''; + print ''; $i++; } } @@ -1784,6 +1787,46 @@ class Form } + /** + * \brief Affiche formulaire de selection d'un utilisateur + * \param page Page + * \param selected Id of user preselected + * \param htmlname Name of input html field + */ + function form_users($page, $selected='', $htmlname='userid') + { + global $langs; + + if ($htmlname != "none") + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $this->select_users($selected,$htmlname,1,0,0); + print '
'; + } + else + { + if ($selected) + { + require_once(DOL_DOCUMENT_ROOT ."/user.class.php"); + //$this->load_cache_contacts(); + //print $this->cache_contacts[$selected]; + $theuser=new User($this->db); + $theuser->id=$selected; + $theuser->fetch(); + print $theuser->getNomUrl(1); + } else { + print " "; + } + } + } + + /** * \brief Affiche formulaire de selection des modes de reglement * \param page Page