Fix: Some change to fix pb of editing password of a user by linking a member to it.
This commit is contained in:
parent
4f0806a80b
commit
5515931729
@ -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
|
||||
|
||||
@ -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 '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td class="valeur">';
|
||||
print $html->select_societes($adh->fk_soc,'socid','',1);
|
||||
print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td class="valeur">';
|
||||
if ($adh->fk_soc)
|
||||
{
|
||||
$company=new Societe($db);
|
||||
$result=$company->fetch($adh->fk_soc);
|
||||
print $company->getNomUrl(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoThirdPartyAssociatedToMember");
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Login Dolibarr
|
||||
print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td class="valeur">';
|
||||
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 '</td></tr>';
|
||||
|
||||
print '<tr><td colspan="3" align="center">';
|
||||
@ -988,7 +1016,6 @@ if ($rowid && $action != 'edit')
|
||||
$rowspan=14+sizeof($adho->attribute_label);
|
||||
if ($conf->societe->enabled) $rowspan++;
|
||||
|
||||
print '<form action="fiche.php" method="post" enctype="multipart/form-data">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
@ -1070,34 +1097,66 @@ if ($rowid && $action != 'edit')
|
||||
// Third party Dolibarr
|
||||
if ($conf->societe->enabled)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td class="valeur">';
|
||||
if ($adh->fk_soc)
|
||||
{
|
||||
$company=new Societe($db);
|
||||
$result=$company->fetch($adh->fk_soc);
|
||||
print $company->getNomUrl(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoThirdPartyAssociatedToMember");
|
||||
}
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
||||
print $langs->trans("LinkedToDolibarrThirdParty");
|
||||
print '</td>';
|
||||
if ($_GET['action'] != 'editthirdparty' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&rowid='.$adh->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'</a></td>';
|
||||
print '</tr></table>';
|
||||
print '</td><td class="valeur">';
|
||||
if ($_GET['action'] == 'editthirdparty')
|
||||
{
|
||||
$page=$_SERVER['PHP_SELF'].'?rowid='.$adh->id;
|
||||
$htmlname='socid';
|
||||
print '<form method="post" action="'.$page.'" name="form'.$htmlname.'">';
|
||||
print '<input type="hidden" name="action" value="set'.$htmlname.'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
|
||||
print '<tr><td>';
|
||||
print $html->select_societes($adh->fk_soc,'socid','',1);
|
||||
print '</td>';
|
||||
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print '</tr></table></form>';
|
||||
}
|
||||
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 '</td></tr>';
|
||||
}
|
||||
|
||||
// Login Dolibarr
|
||||
print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td class="valeur">';
|
||||
if ($adh->user_id)
|
||||
print '<tr><td>';
|
||||
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
||||
print $langs->trans("LinkedToDolibarrUser");
|
||||
print '</td>';
|
||||
if ($_GET['action'] != 'editlogin' && $user->rights->adherent->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlogin&rowid='.$adh->id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'</a></td>';
|
||||
print '</tr></table>';
|
||||
print '</td><td class="valeur">';
|
||||
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 '</td></tr>';
|
||||
|
||||
print "</table>\n";
|
||||
print '</form>';
|
||||
|
||||
print "</div>\n";
|
||||
|
||||
|
||||
@ -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 '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
print '<option value="'.$obj->rowid.'" selected="true">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
print '<option value="'.$obj->rowid.'">';
|
||||
}
|
||||
print $obj->name.($obj->name && $obj->firstname?' ':'').$obj->firstname;
|
||||
print ' ('.$obj->login.')';
|
||||
print '</option>';
|
||||
$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 '<form method="post" action="'.$page.'" name="form'.$htmlname.'">';
|
||||
print '<input type="hidden" name="action" value="set'.$htmlname.'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
|
||||
print '<tr><td>';
|
||||
print $this->select_users($selected,$htmlname,1,0,0);
|
||||
print '</td>';
|
||||
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print '</tr></table></form>';
|
||||
}
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user