diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php
index b3a159046b3..d1787ad7ae7 100644
--- a/htdocs/adherents/card_subscriptions.php
+++ b/htdocs/adherents/card_subscriptions.php
@@ -39,6 +39,17 @@ $langs->load("members");
$langs->load("users");
$langs->load("mails");
+// If socid provided by ajax company selector
+if (! empty($_REQUEST['socid_id']))
+{
+ $_GET['socid'] = $_GET['socid_id'];
+ $_POST['socid'] = $_POST['socid_id'];
+ $_REQUEST['socid'] = $_REQUEST['socid_id'];
+}
+
+// Security check
+if (! $user->rights->adherent->cotisation->lire) accessforbidden();
+
$adh = new Adherent($db);
$adho = new AdherentOptions($db);
$adht = new AdherentType($db);
@@ -51,14 +62,103 @@ $action=GETPOST('action');
$rowid=GETPOST('rowid');
$typeid=GETPOST('typeid');
-if (! $user->rights->adherent->cotisation->lire)
-accessforbidden();
+if ($rowid)
+{
+ // Load member
+ $result = $adh->fetch($rowid);
+
+ // Define variables to know what current user can do on users
+ $canadduser=($user->admin || $user->rights->user->user->creer);
+ // Define variables to know what current user can do on properties of user linked to edited member
+ if ($adh->user_id)
+ {
+ // $user est le user qui edite, $adh->user_id est l'id de l'utilisateur lies au membre edite
+ $caneditfielduser=( (($user->id == $adh->user_id) && $user->rights->user->self->creer)
+ || (($user->id != $adh->user_id) && $user->rights->user->user->creer) );
+ $caneditpassworduser=( (($user->id == $adh->user_id) && $user->rights->user->self->password)
+ || (($user->id != $adh->user_id) && $user->rights->user->user->password) );
+ }
+}
+
+// Define variables to know what current user can do on members
+$canaddmember=$user->rights->adherent->creer;
+// Define variables to know what current user can do on properties of a member
+if ($rowid)
+{
+ $caneditfieldmember=$user->rights->adherent->creer;
+}
+
+// Define size of logo small and mini (might be set into other pages)
+$maxwidthsmall=270;$maxheightsmall=150;
+$maxwidthmini=128;$maxheightmini=72;
+$quality = 80;
+
/*
* Actions
*/
+
+if ($_POST['action'] == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
+{
+ $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='