diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php
index 68829482589..19e3554d155 100644
--- a/htdocs/adherents/adherent.class.php
+++ b/htdocs/adherents/adherent.class.php
@@ -365,20 +365,21 @@ class Adherent extends CommonObject
/**
- * \brief Fonction qui met a jour l'adherent (sauf mot de passe)
+ * \brief Update a member in database (standard information and password)
* \param user User making update
- * \param notrigger 1=desactive le trigger UPDATE (quand appele par creation)
- * \param nosyncuser Do not synchronize linked user
- * \return int <0 si KO, >0 si OK
+ * \param notrigger 1=disable trigger UPDATE (when called by create)
+ * \param nosyncuser 0=Synchronize linked user (standard info), 1=Do not synchronize linked user
+ * \param nosyncuserpass 0=Synchronize linked user (password), 1=Do not synchronize linked user
+ * \return int <0 si KO, >0 si OK
*/
- function update($user,$notrigger=0,$nosyncuser=0)
+ function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0)
{
global $conf, $langs;
$nbrowsaffected=0;
$error=0;
- dol_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", email=".$this->email);
+ dol_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass.", email=".$this->email);
// Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($this->email))
@@ -415,6 +416,8 @@ class Adherent extends CommonObject
$sql.= ", fk_user_mod=".($user->id>0?$user->id:'null'); // Can be null because member can be create by a guest
$sql.= " WHERE rowid = ".$this->id;
+ dol_syslog("Adherent::update UPDATE MEMBER");
+
dol_syslog("Adherent::update sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
@@ -463,19 +466,20 @@ class Adherent extends CommonObject
}
}
- // Mise a jour mot de passe
+ // Update password
if ($this->pass)
{
+ dol_syslog("Adherent::update UPDATE PASSWORD");
if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
{
// Si mot de passe saisi et different de celui en base
- $result=$this->setPassword($user,$this->pass,0,$notrigger);
-
+ $result=$this->setPassword($user,$this->pass,0,$notrigger,$nosyncuserpass);
if (! $nbrowsaffected) $nbrowsaffected++;
}
}
// Remove link to user
+ dol_syslog("Adherent::update UPDATE LINK TO USER");
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->id;
dol_syslog("Adherent::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -495,6 +499,8 @@ class Adherent extends CommonObject
{
require_once(DOL_DOCUMENT_ROOT."/user.class.php");
+ dol_syslog("Adherent::update UPDATE LINKED USER");
+
// This member is linked with a user, so we also update users informations
// if this is an update.
$luser=new User($this->db);
@@ -517,7 +523,7 @@ class Adherent extends CommonObject
$luser->fk_member=$this->id;
- $result=$luser->update($user,0,1);
+ $result=$luser->update($user,0,1,1); // Use nosync to 1 to avoid cyclic updates
if ($result < 0)
{
$this->error=$luser->error;
@@ -699,7 +705,7 @@ class Adherent extends CommonObject
/**
- * \brief Change le mot de passe d'un utilisateur
+ * \brief Change password of a user
* \param user Object user de l'utilisateur qui fait la modification
* \param password Nouveau mot de passe (e generer si non communique)
* \param isencrypted 0 ou 1 si il faut crypter le mot de passe en base (0 par defaut)
@@ -744,7 +750,7 @@ class Adherent extends CommonObject
$result = $this->db->query($sql);
if ($result)
{
- $nbaffectedrows=$this->db->affected_rows();
+ $nbaffectedrows=$this->db->affected_rows($result);
if ($nbaffectedrows)
{
@@ -847,13 +853,21 @@ class Adherent extends CommonObject
$this->db->begin();
+ // Update link to third party
+ if ($thirdpartyid > 0)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null where fk_soc = '".$thirdpartyid."'";
+ dol_syslog("Adherent::setThirdPartyId sql=".$sql);
+ $resql = $this->db->query($sql);
+ }
+
// 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)
+ $resql = $this->db->query($sql);
+ if ($resql)
{
$this->db->commit();
return 1;
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 153e8f2e17d..0041f254719 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -77,8 +77,7 @@ $canaddmember=$user->rights->adherent->creer;
// Define variables to know what current user can do on properties of a member
if ($rowid)
{
- $caneditfieldmember=( (($user->id == $adh->user_id) && $user->rights->adherent->self->creer)
- || (($user->id != $adh->user_id) && $user->rights->adherent->creer) );
+ $caneditfieldmember=$user->rights->adherent->creer;
}
@@ -87,19 +86,62 @@ if ($rowid)
* Actions
*/
-if ($_POST['action'] == 'setuserid')
+if ($_POST['action'] == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
{
- $result=$adh->setUserId($_POST["userid"]);
- if ($result < 0) dol_print_error($adh->db,$adh->error);
- $_POST['action']='';
- $action='';
+ $error=0;
+ if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
+ {
+ if ($_POST["userid"] != $user->id && $_POST["userid"] != $adh->user_id)
+ {
+ $error++;
+ $mesg='
';
- if ($user->rights->adherent->creer) // If $user->rights->adherent->self->creer, we do not allow.
+ if ($user->rights->adherent->creer)
{
$html->select_array("typeid", $adht->liste_array(), $adh->typeid);
}
@@ -1126,7 +1171,12 @@ if ($rowid && $action != 'edit')
print '
';
if ($_GET['action'] == 'editlogin')
{
- print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'userid');
+ /*$include=array();
+ if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
+ {
+ $include=array($adh->user_id,$user->id);
+ }*/
+ print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'userid','');
}
else
{
@@ -1149,129 +1199,131 @@ if ($rowid && $action != 'edit')
*/
print '
';
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index bc566f6660e..057f2d02ab4 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -449,7 +449,7 @@ class Form
* \brief Output html form to select a third party
* \param selected Preselected type
* \param htmlname Name of field in form
- * \param filter Criteres optionnels de filtre
+ * \param filter Optionnal filters criteras
* \param showempty Add an empty field
*/
function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0)
@@ -457,7 +457,7 @@ class Form
global $conf,$user;
// On recherche les societes
- $sql = "SELECT s.rowid, s.nom";
+ $sql = "SELECT s.rowid, s.nom, s.code_client, s.code_fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.entity = ".$conf->entity;
@@ -666,39 +666,44 @@ class Form
/**
- * \brief Retourne la liste deroulante des utilisateurs
+ * \brief Return select list of users
* \param selected Id user preselected
* \param htmlname Field name in form
* \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* \param exclude List of users id to exclude
* \param disabled If select list must be disabled
+ * \param include List of users id to include
*/
- function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0)
+ function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='')
{
global $conf;
// Permettre l'exclusion d'utilisateurs
if (is_array($exclude)) $excludeUsers = implode("','",$exclude);
+ // Permettre l'inclusion d'utilisateurs
+ if (is_array($include)) $includeUsers = implode("','",$include);
// On recherche les utilisateurs
$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."')";
+ if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')";
$sql.= " ORDER BY u.name ASC";
dol_syslog("Form::select_users sql=".$sql);
- if ($this->db->query($sql))
+ $resql=$this->db->query($sql);
+ if ($resql)
{
print '