dolibarr  16.0.5
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2012-2020 Philippe Grand <philippe.grand@atoo-net.com>
8  * Copyright (C) 2015-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
10  * Copyright (C) 2021 Waël Almoman <info@almoman.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45 
46 // Load translation files required by the page
47 $langs->loadLangs(array("companies", "bills", "members", "users", "other", "paypal"));
48 
49 $action = GETPOST('action', 'aZ09');
50 $cancel = GETPOST('cancel', 'alpha');
51 $backtopage = GETPOST('backtopage', 'alpha');
52 $confirm = GETPOST('confirm', 'alpha');
53 $rowid = GETPOST('rowid', 'int');
54 $id = GETPOST('id') ?GETPOST('id', 'int') : $rowid;
55 $typeid = GETPOST('typeid', 'int');
56 $userid = GETPOST('userid', 'int');
57 $socid = GETPOST('socid', 'int');
58 $ref = GETPOST('ref', 'alpha');
59 
60 if (!empty($conf->mailmanspip->enabled)) {
61  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
62 
63  $langs->load('mailmanspip');
64 
65  $mailmanspip = new MailmanSpip($db);
66 }
67 
68 $object = new Adherent($db);
69 $extrafields = new ExtraFields($db);
70 
71 // fetch optionals attributes and labels
72 $extrafields->fetch_name_optionals_label($object->table_element);
73 
74 $socialnetworks = getArrayOfSocialNetworks();
75 
76 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
77 $object->getCanvas($id);
78 $canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
79 $objcanvas = null;
80 if (!empty($canvas)) {
81  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
82  $objcanvas = new Canvas($db, $action);
83  $objcanvas->getCanvas('adherent', 'membercard', $canvas);
84 }
85 
86 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87 $hookmanager->initHooks(array('membercard', 'globalcard'));
88 
89 // Fetch object
90 if ($id > 0 || !empty($ref)) {
91  // Load member
92  $result = $object->fetch($id, $ref);
93 
94  // Define variables to know what current user can do on users
95  $canadduser = ($user->admin || $user->rights->user->user->creer);
96  // Define variables to know what current user can do on properties of user linked to edited member
97  if ($object->user_id) {
98  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
99  $caneditfielduser = ((($user->id == $object->user_id) && $user->rights->user->self->creer)
100  || (($user->id != $object->user_id) && $user->rights->user->user->creer));
101  $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
102  || (($user->id != $object->user_id) && $user->rights->user->user->password));
103  }
104 }
105 
106 // Define variables to determine what the current user can do on the members
107 $canaddmember = $user->rights->adherent->creer;
108 // Define variables to determine what the current user can do on the properties of a member
109 if ($id) {
110  $caneditfieldmember = $user->rights->adherent->creer;
111 }
112 
113 // Security check
114 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
115 
116 
117 /*
118  * Actions
119  */
120 
121 $parameters = array('id'=>$id, 'rowid'=>$id, 'objcanvas'=>$objcanvas, 'confirm'=>$confirm);
122 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
123 if ($reshook < 0) {
124  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
125 }
126 
127 if (empty($reshook)) {
128  $backurlforlist = DOL_URL_ROOT.'/adherents/list.php';
129 
130  if (empty($backtopage) || ($cancel && empty($id))) {
131  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
132  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
133  $backtopage = $backurlforlist;
134  } else {
135  $backtopage = DOL_URL_ROOT.'/adherents/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
136  }
137  }
138  }
139 
140  if ($cancel) {
141  if (!empty($backtopageforcancel)) {
142  header("Location: ".$backtopageforcancel);
143  exit;
144  } elseif (!empty($backtopage)) {
145  header("Location: ".$backtopage);
146  exit;
147  }
148  $action = '';
149  }
150 
151  if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) {
152  $error = 0;
153  if (empty($user->rights->user->user->creer)) { // If can edit only itself user, we can link to itself only
154  if ($userid != $user->id && $userid != $object->user_id) {
155  $error++;
156  setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
157  }
158  }
159 
160  if (!$error) {
161  if ($userid != $object->user_id) { // If link differs from currently in database
162  $result = $object->setUserId($userid);
163  if ($result < 0) {
164  dol_print_error($object->db, $object->error);
165  }
166  $action = '';
167  }
168  }
169  }
170 
171  if ($action == 'setsocid') {
172  $error = 0;
173  if (!$error) {
174  if ($socid != $object->socid) { // If link differs from currently in database
175  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
176  $sql .= " WHERE socid = ".((int) $socid);
177  $sql .= " AND entity = ".$conf->entity;
178  $resql = $db->query($sql);
179  if ($resql) {
180  $obj = $db->fetch_object($resql);
181  if ($obj && $obj->rowid > 0) {
182  $othermember = new Adherent($db);
183  $othermember->fetch($obj->rowid);
184  $thirdparty = new Societe($db);
185  $thirdparty->fetch($socid);
186  $error++;
187  setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
188  }
189  }
190 
191  if (!$error) {
192  $result = $object->setThirdPartyId($socid);
193  if ($result < 0) {
194  dol_print_error($object->db, $object->error);
195  }
196  $action = '';
197  }
198  }
199  }
200  }
201 
202  // Create user from a member
203  if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
204  if ($result > 0) {
205  // Creation user
206  $nuser = new User($db);
207  $tmpuser = dol_clone($object);
208  if (GETPOST('internalorexternal', 'aZ09') == 'internal') {
209  $tmpuser->fk_soc = 0;
210  }
211 
212  $result = $nuser->create_from_member($tmpuser, GETPOST('login', 'alphanohtml'));
213 
214  if ($result < 0) {
215  $langs->load("errors");
216  setEventMessages($langs->trans($nuser->error), null, 'errors');
217  } else {
218  setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs');
219  $action = '';
220  }
221  } else {
222  setEventMessages($object->error, $object->errors, 'errors');
223  }
224  }
225 
226  // Create third party from a member
227  if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) {
228  if ($result > 0) {
229  // User creation
230  $company = new Societe($db);
231  $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'));
232 
233  if ($result < 0) {
234  $langs->load("errors");
235  setEventMessages($langs->trans($company->error), null, 'errors');
236  setEventMessages($company->error, $company->errors, 'errors');
237  }
238  } else {
239  setEventMessages($object->error, $object->errors, 'errors');
240  }
241  }
242 
243  if ($action == 'update' && !$cancel && $user->rights->adherent->creer) {
244  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
245 
246  $birthdate = '';
247  if (GETPOST("birthday", 'int') && GETPOST("birthmonth", 'int') && GETPOST("birthyear", 'int')) {
248  $birthdate = dol_mktime(12, 0, 0, GETPOST("birthmonth", 'int'), GETPOST("birthday", 'int'), GETPOST("birthyear", 'int'));
249  }
250  $lastname = GETPOST("lastname", 'alphanohtml');
251  $firstname = GETPOST("firstname", 'alphanohtml');
252  $gender = GETPOST("gender", 'alphanohtml');
253  $societe = GETPOST("societe", 'alphanohtml');
254  $morphy = GETPOST("morphy", 'alphanohtml');
255  $login = GETPOST("login", 'alphanohtml');
256  if ($morphy != 'mor' && empty($lastname)) {
257  $error++;
258  $langs->load("errors");
259  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
260  }
261  if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
262  $error++;
263  $langs->load("errors");
264  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
265  }
266  if ($morphy == 'mor' && empty($societe)) {
267  $error++;
268  $langs->load("errors");
269  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors');
270  }
271  // Check if the login already exists
272  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
273  if (empty($login)) {
274  $error++;
275  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors');
276  }
277  }
278  // Create new object
279  if ($result > 0 && !$error) {
280  $object->oldcopy = clone $object;
281 
282  // Change values
283  $object->civility_id = trim(GETPOST("civility_id", 'alphanohtml'));
284  $object->firstname = trim(GETPOST("firstname", 'alphanohtml'));
285  $object->lastname = trim(GETPOST("lastname", 'alphanohtml'));
286  $object->gender = trim(GETPOST("gender", 'alphanohtml'));
287  $object->login = trim(GETPOST("login", 'alphanohtml'));
288  $object->pass = trim(GETPOST("pass", 'none')); // For password, we must use 'none'
289 
290  $object->societe = trim(GETPOST("societe", 'alphanohtml')); // deprecated
291  $object->company = trim(GETPOST("societe", 'alphanohtml'));
292 
293  $object->address = trim(GETPOST("address", 'alphanohtml'));
294  $object->zip = trim(GETPOST("zipcode", 'alphanohtml'));
295  $object->town = trim(GETPOST("town", 'alphanohtml'));
296  $object->state_id = GETPOST("state_id", 'int');
297  $object->country_id = GETPOST("country_id", 'int');
298 
299  $object->phone = trim(GETPOST("phone", 'alpha'));
300  $object->phone_perso = trim(GETPOST("phone_perso", 'alpha'));
301  $object->phone_mobile = trim(GETPOST("phone_mobile", 'alpha'));
302  $object->email = preg_replace('/\s+/', '', GETPOST("member_email", 'alpha'));
303  $object->url = trim(GETPOST('member_url', 'custom', 0, FILTER_SANITIZE_URL));
304  $object->socialnetworks = array();
305  foreach ($socialnetworks as $key => $value) {
306  if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
307  $object->socialnetworks[$key] = trim(GETPOST($key, 'alphanohtml'));
308  }
309  }
310  //$object->skype = trim(GETPOST("skype", 'alpha'));
311  //$object->twitter = trim(GETPOST("twitter", 'alpha'));
312  //$object->facebook = trim(GETPOST("facebook", 'alpha'));
313  //$object->linkedin = trim(GETPOST("linkedin", 'alpha'));
314  $object->birth = $birthdate;
315 
316  $object->typeid = GETPOST("typeid", 'int');
317  //$object->note = trim(GETPOST("comment","alpha"));
318  $object->morphy = GETPOST("morphy", 'alpha');
319 
320  if (GETPOST('deletephoto', 'alpha')) {
321  $object->photo = '';
322  } elseif (!empty($_FILES['photo']['name'])) {
323  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
324  }
325 
326  // Get status and public property
327  $object->statut = GETPOST("statut", 'alpha');
328  $object->public = GETPOST("public", 'alpha');
329 
330  // Fill array 'array_options' with data from add form
331  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
332  if ($ret < 0) {
333  $error++;
334  }
335 
336  // Check if we need to also synchronize user information
337  $nosyncuser = 0;
338  if ($object->user_id) { // If linked to a user
339  if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) {
340  $nosyncuser = 1; // Disable synchronizing
341  }
342  }
343 
344  // Check if we need to also synchronize password information
345  $nosyncuserpass = 0;
346  if ($object->user_id) { // If linked to a user
347  if ($user->id != $object->user_id && empty($user->rights->user->user->password)) {
348  $nosyncuserpass = 1; // Disable synchronizing
349  }
350  }
351 
352  if (!$error) {
353  $result = $object->update($user, 0, $nosyncuser, $nosyncuserpass);
354 
355  if ($result >= 0 && !count($object->errors)) {
356  $categories = GETPOST('memcats', 'array');
357  $object->setCategories($categories);
358 
359  // Logo/Photo save
360  $dir = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos';
361  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
362  if ($file_OK) {
363  if (GETPOST('deletephoto')) {
364  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
365  $fileimg = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/'.$object->photo;
366  $dirthumbs = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member').'/photos/thumbs';
367  dol_delete_file($fileimg);
368  dol_delete_dir_recursive($dirthumbs);
369  }
370 
371  if (image_format_supported($_FILES['photo']['name']) > 0) {
372  dol_mkdir($dir);
373 
374  if (@is_dir($dir)) {
375  $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
376  if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
377  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
378  } else {
379  // Create thumbs
380  $object->addThumbs($newfile);
381  }
382  }
383  } else {
384  setEventMessages("ErrorBadImageFormat", null, 'errors');
385  }
386  } else {
387  switch ($_FILES['photo']['error']) {
388  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
389  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
390  $errors[] = "ErrorFileSizeTooLarge";
391  break;
392  case 3: //uploaded file was only partially uploaded
393  $errors[] = "ErrorFilePartiallyUploaded";
394  break;
395  }
396  }
397 
398  $rowid = $object->id;
399  $id = $object->id;
400  $action = '';
401 
402  if (!empty($backtopage)) {
403  header("Location: ".$backtopage);
404  exit;
405  }
406  } else {
407  setEventMessages($object->error, $object->errors, 'errors');
408  $action = '';
409  }
410  } else {
411  $action = 'edit';
412  }
413  } else {
414  $action = 'edit';
415  }
416  }
417 
418  if ($action == 'add' && $user->rights->adherent->creer) {
419  if ($canvas) {
420  $object->canvas = $canvas;
421  }
422  $birthdate = '';
423  if (GETPOSTISSET("birthday") && GETPOST("birthday") && GETPOSTISSET("birthmonth") && GETPOST("birthmonth") && GETPOSTISSET("birthyear") && GETPOST("birthyear")) {
424  $birthdate = dol_mktime(12, 0, 0, GETPOST("birthmonth", 'int'), GETPOST("birthday", 'int'), GETPOST("birthyear", 'int'));
425  }
426  $datesubscription = '';
427  if (GETPOSTISSET("reday") && GETPOSTISSET("remonth") && GETPOSTISSET("reyear")) {
428  $datesubscription = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", "int"), GETPOST("reyear", "int"));
429  }
430 
431  $typeid = GETPOST("typeid", 'int');
432  $civility_id = GETPOST("civility_id", 'alphanohtml');
433  $lastname = GETPOST("lastname", 'alphanohtml');
434  $firstname = GETPOST("firstname", 'alphanohtml');
435  $gender = GETPOST("gender", 'alphanohtml');
436  $societe = GETPOST("societe", 'alphanohtml');
437  $address = GETPOST("address", 'alphanohtml');
438  $zip = GETPOST("zipcode", 'alphanohtml');
439  $town = GETPOST("town", 'alphanohtml');
440  $state_id = GETPOST("state_id", 'int');
441  $country_id = GETPOST("country_id", 'int');
442 
443  $phone = GETPOST("phone", 'alpha');
444  $phone_perso = GETPOST("phone_perso", 'alpha');
445  $phone_mobile = GETPOST("phone_mobile", 'alpha');
446  // $skype=GETPOST("member_skype", 'alpha');
447  // $twitter=GETPOST("member_twitter", 'alpha');
448  // $facebook=GETPOST("member_facebook", 'alpha');
449  // $linkedin=GETPOST("member_linkedin", 'alpha');
450  $email = preg_replace('/\s+/', '', GETPOST("member_email", 'alpha'));
451  $url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
452  $login = GETPOST("member_login", 'alphanohtml');
453  $pass = GETPOST("password", 'none'); // For password, we use 'none'
454  $photo = GETPOST("photo", 'alphanohtml');
455  $morphy = GETPOST("morphy", 'alphanohtml');
456  $public = GETPOST("public", 'alphanohtml');
457 
458  $userid = GETPOST("userid", 'int');
459  $socid = GETPOST("socid", 'int');
460 
461  $object->civility_id = $civility_id;
462  $object->firstname = $firstname;
463  $object->lastname = $lastname;
464  $object->gender = $gender;
465  $object->societe = $societe; // deprecated
466  $object->company = $societe;
467  $object->address = $address;
468  $object->zip = $zip;
469  $object->town = $town;
470  $object->state_id = $state_id;
471  $object->country_id = $country_id;
472  $object->phone = $phone;
473  $object->phone_perso = $phone_perso;
474  $object->phone_mobile = $phone_mobile;
475  $object->socialnetworks = array();
476  if (!empty($conf->socialnetworks->enabled)) {
477  foreach ($socialnetworks as $key => $value) {
478  if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
479  $object->socialnetworks[$key] = GETPOST("member_".$key, 'alphanohtml');
480  }
481  }
482  }
483 
484  // $object->skype = $skype;
485  // $object->twitter = $twitter;
486  // $object->facebook = $facebook;
487  // $object->linkedin = $linkedin;
488 
489  $object->email = $email;
490  $object->url = $url;
491  $object->login = $login;
492  $object->pass = $pass;
493  $object->birth = $birthdate;
494  $object->photo = $photo;
495  $object->typeid = $typeid;
496  //$object->note = $comment;
497  $object->morphy = $morphy;
498  $object->user_id = $userid;
499  $object->socid = $socid;
500  $object->public = $public;
501 
502  // Fill array 'array_options' with data from add form
503  $ret = $extrafields->setOptionalsFromPost(null, $object);
504  if ($ret < 0) {
505  $error++;
506  }
507 
508  // Check parameters
509  if (empty($morphy) || $morphy == "-1") {
510  $error++;
511  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MemberNature")), null, 'errors');
512  }
513  // Tests if the login already exists
514  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
515  if (empty($login)) {
516  $error++;
517  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")), null, 'errors');
518  } else {
519  $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'";
520  $result = $db->query($sql);
521  if ($result) {
522  $num = $db->num_rows($result);
523  }
524  if ($num) {
525  $error++;
526  $langs->load("errors");
527  setEventMessages($langs->trans("ErrorLoginAlreadyExists", $login), null, 'errors');
528  }
529  }
530  if (empty($pass)) {
531  $error++;
532  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Password")), null, 'errors');
533  }
534  }
535  if ($morphy == 'mor' && empty($societe)) {
536  $error++;
537  $langs->load("errors");
538  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors');
539  }
540  if ($morphy != 'mor' && empty($lastname)) {
541  $error++;
542  $langs->load("errors");
543  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
544  }
545  if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
546  $error++;
547  $langs->load("errors");
548  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
549  }
550  if (!($typeid > 0)) { // Keep () before !
551  $error++;
552  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
553  }
554  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($email)) {
555  $error++;
556  $langs->load("errors");
557  setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
558  }
559  if (!empty($object->url) && !isValidUrl($object->url)) {
560  $langs->load("errors");
561  setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors');
562  }
563  $public = 0;
564  if (isset($public)) {
565  $public = 1;
566  }
567 
568  if (!$error) {
569  $db->begin();
570 
571  // Email about right and login does not exist
572  $result = $object->create($user);
573  if ($result > 0) {
574  // Foundation categories
575  $memcats = GETPOST('memcats', 'array');
576  $object->setCategories($memcats);
577 
578  $db->commit();
579  $rowid = $object->id;
580  $id = $object->id;
581  } else {
582  $db->rollback();
583 
584  if ($object->error) {
585  setEventMessages($object->error, $object->errors, 'errors');
586  } else {
587  setEventMessages($object->error, $object->errors, 'errors');
588  }
589  }
590  // Auto-create thirdparty on member creation
591  if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) {
592  if ($result > 0) {
593  // User creation
594  $company = new Societe($db);
595 
596  $companyalias = '';
597  $fullname = $object->getFullName($langs);
598 
599  if ($object->morphy == 'mor') {
600  $companyname = $object->company;
601  if (!empty($fullname)) {
602  $companyalias = $fullname;
603  }
604  } else {
605  $companyname = $fullname;
606  if (!empty($object->company)) {
607  $companyalias = $object->company;
608  }
609  }
610 
611  $result = $company->create_from_member($object, $companyname, $companyalias);
612 
613  if ($result < 0) {
614  $langs->load("errors");
615  setEventMessages($langs->trans($company->error), null, 'errors');
616  setEventMessages($company->error, $company->errors, 'errors');
617  }
618  } else {
619  setEventMessages($object->error, $object->errors, 'errors');
620  }
621  }
622  }
623  $action = ($result < 0 || !$error) ? '' : 'create';
624  }
625 
626  if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') {
627  $result = $object->delete($id, $user);
628  if ($result > 0) {
629  if (!empty($backtopage)) {
630  header("Location: ".$backtopage);
631  exit;
632  } else {
633  header("Location: list.php");
634  exit;
635  }
636  } else {
637  setEventMessages($object->error, null, 'errors');
638  }
639  }
640 
641  if ($user->rights->adherent->creer && $action == 'confirm_valid' && $confirm == 'yes') {
642  $error = 0;
643 
644  $db->begin();
645 
646  $adht = new AdherentType($db);
647  $adht->fetch($object->typeid);
648 
649  $result = $object->validate($user);
650 
651  if ($result >= 0 && !count($object->errors)) {
652  // Send confirmation email (according to parameters of member type. Otherwise generic)
653  if ($object->email && GETPOST("send_mail")) {
654  $subject = '';
655  $msg = '';
656 
657  // Send subscription email
658  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
659  $formmail = new FormMail($db);
660  // Set output language
661  $outputlangs = new Translate('', $conf);
662  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
663  // Load traductions files required by page
664  $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
665  // Get email content from template
666  $arraydefaultmessage = null;
667  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION;
668 
669  if (!empty($labeltouse)) {
670  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
671  }
672 
673  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
674  $subject = $arraydefaultmessage->topic;
675  $msg = $arraydefaultmessage->content;
676  }
677 
678  if (empty($labeltouse) || (int) $labeltouse === -1) {
679  //fallback on the old configuration.
680  setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
681  $error++;
682  } else {
683  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
684  complete_substitutions_array($substitutionarray, $outputlangs, $object);
685  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
686  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
687 
688  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
689 
690  $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
691  if ($result < 0) {
692  $error++;
693  setEventMessages($object->error, $object->errors, 'errors');
694  }
695  }
696  }
697  } else {
698  $error++;
699  if ($object->error) {
700  setEventMessages($object->error, $object->errors, 'errors');
701  } else {
702  setEventMessages($object->error, $object->errors, 'errors');
703  }
704  }
705 
706  if (!$error) {
707  $db->commit();
708  } else {
709  $db->rollback();
710  }
711  $action = '';
712  }
713 
714  if ($user->rights->adherent->supprimer && $action == 'confirm_resiliate') {
715  $error = 0;
716 
717  if ($confirm == 'yes') {
718  $adht = new AdherentType($db);
719  $adht->fetch($object->typeid);
720 
721  $result = $object->resiliate($user);
722 
723  if ($result >= 0 && !count($object->errors)) {
724  if ($object->email && GETPOST("send_mail")) {
725  $subject = '';
726  $msg = '';
727 
728  // Send subscription email
729  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
730  $formmail = new FormMail($db);
731  // Set output language
732  $outputlangs = new Translate('', $conf);
733  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
734  // Load traductions files required by page
735  $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
736  // Get email content from template
737  $arraydefaultmessage = null;
738  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_CANCELATION;
739 
740  if (!empty($labeltouse)) {
741  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
742  }
743 
744  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
745  $subject = $arraydefaultmessage->topic;
746  $msg = $arraydefaultmessage->content;
747  }
748 
749  if (empty($labeltouse) || (int) $labeltouse === -1) {
750  //fallback on the old configuration.
751  setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
752  $error++;
753  } else {
754  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
755  complete_substitutions_array($substitutionarray, $outputlangs, $object);
756  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
757  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
758 
759  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
760 
761  $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
762  if ($result < 0) {
763  $error++;
764  setEventMessages($object->error, $object->errors, 'errors');
765  }
766  }
767  }
768  } else {
769  $error++;
770 
771  if ($object->error) {
772  setEventMessages($object->error, $object->errors, 'errors');
773  } else {
774  setEventMessages($object->error, $object->errors, 'errors');
775  }
776  $action = '';
777  }
778  }
779  if (!empty($backtopage) && !$error) {
780  header("Location: ".$backtopage);
781  exit;
782  }
783  }
784 
785  if ($user->rights->adherent->supprimer && $action == 'confirm_exclude') {
786  $error = 0;
787 
788  if ($confirm == 'yes') {
789  $adht = new AdherentType($db);
790  $adht->fetch($object->typeid);
791 
792  $result = $object->exclude($user);
793 
794  if ($result >= 0 && !count($object->errors)) {
795  if ($object->email && GETPOST("send_mail")) {
796  $subject = '';
797  $msg = '';
798 
799  // Send subscription email
800  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
801  $formmail = new FormMail($db);
802  // Set output language
803  $outputlangs = new Translate('', $conf);
804  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
805  // Load traductions files required by page
806  $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
807  // Get email content from template
808  $arraydefaultmessage = null;
809  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_EXCLUSION;
810 
811  if (!empty($labeltouse)) {
812  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
813  }
814 
815  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
816  $subject = $arraydefaultmessage->topic;
817  $msg = $arraydefaultmessage->content;
818  }
819 
820  if (empty($labeltouse) || (int) $labeltouse === -1) {
821  //fallback on the old configuration.
822  setEventMessages('WarningMandatorySetupNotComplete', null, 'errors');
823  $error++;
824  } else {
825  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
826  complete_substitutions_array($substitutionarray, $outputlangs, $object);
827  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
828  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
829 
830  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
831 
832  $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
833  if ($result < 0) {
834  $error++;
835  setEventMessages($object->error, $object->errors, 'errors');
836  }
837  }
838  }
839  } else {
840  $error++;
841 
842  if ($object->error) {
843  setEventMessages($object->error, $object->errors, 'errors');
844  } else {
845  setEventMessages($object->error, $object->errors, 'errors');
846  }
847  $action = '';
848  }
849  }
850  if (!empty($backtopage) && !$error) {
851  header("Location: ".$backtopage);
852  exit;
853  }
854  }
855 
856  // SPIP Management
857  if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $confirm == 'yes') {
858  if (!count($object->errors)) {
859  if (!$mailmanspip->del_to_spip($object)) {
860  setEventMessages($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, null, 'errors');
861  }
862  }
863  }
864 
865  if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm == 'yes') {
866  if (!count($object->errors)) {
867  if (!$mailmanspip->add_to_spip($object)) {
868  setEventMessages($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, null, 'errors');
869  }
870  }
871  }
872 
873  // Actions when printing a doc from card
874  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
875 
876  // Actions to build doc
877  $upload_dir = $conf->adherent->dir_output;
878  $permissiontoadd = $user->rights->adherent->creer;
879  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
880 
881  // Actions to send emails
882  $triggersendname = 'MEMBER_SENTBYMAIL';
883  $paramname = 'id';
884  $mode = 'emailfrommember';
885  $trackid = 'mem'.$object->id;
886  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
887 }
888 
889 
890 /*
891  * View
892  */
893 
894 $form = new Form($db);
895 $formfile = new FormFile($db);
896 $formcompany = new FormCompany($db);
897 
898 $title = $langs->trans("Member")." - ".$langs->trans("Card");
899 $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
900 llxHeader('', $title, $help_url);
901 
902 $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
903 
904 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
905  // -----------------------------------------
906  // When used with CANVAS
907  // -----------------------------------------
908  if (empty($object->error) && $id) {
909  $object = new Adherent($db);
910  $result = $object->fetch($id);
911  if ($result <= 0) {
912  dol_print_error('', $object->error);
913  }
914  }
915  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
916  $objcanvas->display_canvas($action); // Show template
917 } else {
918  // -----------------------------------------
919  // When used in standard mode
920  // -----------------------------------------
921 
922  // Create mode
923  if ($action == 'create') {
924  $object->canvas = $canvas;
925  $object->state_id = GETPOST('state_id', 'int');
926 
927  // We set country_id, country_code and country for the selected country
928  $object->country_id = GETPOST('country_id', 'int') ? GETPOST('country_id', 'int') : $mysoc->country_id;
929  if ($object->country_id) {
930  $tmparray = getCountry($object->country_id, 'all');
931  $object->country_code = $tmparray['code'];
932  $object->country = $tmparray['label'];
933  }
934 
935  $soc = new Societe($db);
936  if (!empty($socid)) {
937  if ($socid > 0) {
938  $soc->fetch($socid);
939  }
940 
941  if (!($soc->id > 0)) {
942  $langs->load("errors");
943  print($langs->trans('ErrorRecordNotFound'));
944  exit;
945  }
946  }
947 
948  $adht = new AdherentType($db);
949 
950  print load_fiche_titre($langs->trans("NewMember"), '', $object->picto);
951 
952  if ($conf->use_javascript_ajax) {
953  print "\n".'<script type="text/javascript">'."\n";
954  print 'jQuery(document).ready(function () {
955  jQuery("#selectcountry_id").change(function() {
956  document.formsoc.action.value="create";
957  document.formsoc.submit();
958  });
959  function initfieldrequired() {
960  jQuery("#tdcompany").removeClass("fieldrequired");
961  jQuery("#tdlastname").removeClass("fieldrequired");
962  jQuery("#tdfirstname").removeClass("fieldrequired");
963  if (jQuery("#morphy").val() == \'mor\') {
964  jQuery("#tdcompany").addClass("fieldrequired");
965  }
966  if (jQuery("#morphy").val() == \'phy\') {
967  jQuery("#tdlastname").addClass("fieldrequired");
968  jQuery("#tdfirstname").addClass("fieldrequired");
969  }
970  }
971  jQuery("#morphy").change(function() {
972  initfieldrequired();
973  });
974  initfieldrequired();
975  })';
976  print '</script>'."\n";
977  }
978 
979  print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
980  print '<input type="hidden" name="token" value="'.newToken().'">';
981  print '<input type="hidden" name="action" value="add">';
982  print '<input type="hidden" name="socid" value="'.$socid.'">';
983  if ($backtopage) {
984  print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
985  }
986 
987  print dol_get_fiche_head('');
988 
989  print '<table class="border centpercent">';
990  print '<tbody>';
991 
992  // Login
993  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
994  print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="member_login" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("member_login") ? GETPOST("member_login", 'alphanohtml', 2) : $object->login).'" autofocus="autofocus"></td></tr>';
995  }
996 
997  // Password
998  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
999  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1000  $generated_password = getRandomPassword(false);
1001  print '<tr><td><span class="fieldrequired">'.$langs->trans("Password").'</span></td><td>';
1002  print '<input type="text" class="minwidth300" maxlength="50" name="password" value="'.dol_escape_htmltag($generated_password).'">';
1003  print '</td></tr>';
1004  }
1005 
1006  // Type
1007  print '<tr><td class="fieldrequired">'.$langs->trans("MemberType").'</td><td>';
1008  $listetype = $adht->liste_array(1);
1009  if (count($listetype)) {
1010  print $form->selectarray("typeid", $listetype, (GETPOST('typeid', 'int') ? GETPOST('typeid', 'int') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0, '', 0, 0, 0, '', '', 1);
1011  } else {
1012  print '<span class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</span>';
1013  }
1014  print "</td>\n";
1015 
1016  // Morphy
1017  $morphys["phy"] = $langs->trans("Physical");
1018  $morphys["mor"] = $langs->trans("Moral");
1019  print '<tr><td class="fieldrequired">'.$langs->trans("MemberNature")."</td><td>\n";
1020  print $form->selectarray("morphy", $morphys, (GETPOST('morphy', 'alpha') ?GETPOST('morphy', 'alpha') : $object->morphy), 1, 0, 0, '', 0, 0, 0, '', '', 1);
1021  print "</td>\n";
1022 
1023  // Company
1024  print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="minwidth300" maxlength="128" value="'.(GETPOSTISSET('societe') ? GETPOST('societe', 'alphanohtml') : $soc->name).'"></td></tr>';
1025 
1026  // Civility
1027  print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1028  print $formcompany->select_civility(GETPOST('civility_id', 'int') ? GETPOST('civility_id', 'int') : $object->civility_id, 'civility_id', 'maxwidth150', 1).'</td>';
1029  print '</tr>';
1030 
1031  // Lastname
1032  print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET('lastname') ? GETPOST('lastname', 'alphanohtml') : $object->lastname).'"></td>';
1033  print '</tr>';
1034 
1035  // Firstname
1036  print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET('firstname') ? GETPOST('firstname', 'alphanohtml') : $object->firstname).'"></td>';
1037  print '</tr>';
1038 
1039  // Gender
1040  print '<tr><td>'.$langs->trans("Gender").'</td>';
1041  print '<td>';
1042  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
1043  print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', '', 1);
1044  print '</td></tr>';
1045 
1046  // EMail
1047  print '<tr><td>'.(!empty($conf->global->ADHERENT_MAIL_REQUIRED) ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(!empty($conf->global->ADHERENT_MAIL_REQUIRED) ? '</span>' : '').'</td>';
1048  print '<td>'.img_picto('', 'object_email').' <input type="text" name="member_email" class="minwidth300" maxlength="255" value="'.(GETPOSTISSET('member_email') ? GETPOST('member_email', 'alpha') : $soc->email).'"></td></tr>';
1049 
1050  // Website
1051  print '<tr><td>'.$form->editfieldkey('Web', 'member_url', '', $object, 0).'</td>';
1052  print '<td>'.img_picto('', 'globe').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="member_url" id="member_url" value="'.$object->url.'"></td></tr>';
1053 
1054  // Address
1055  print '<tr><td class="tdtop">'.$langs->trans("Address").'</td><td>';
1056  print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="2">'.(GETPOSTISSET('address') ?GETPOST('address', 'alphanohtml') : $soc->address).'</textarea>';
1057  print '</td></tr>';
1058 
1059  // Zip / Town
1060  print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1061  print $formcompany->select_ziptown((GETPOSTISSET('zipcode') ? GETPOST('zipcode', 'alphanohtml') : $soc->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1062  print ' ';
1063  print $formcompany->select_ziptown((GETPOSTISSET('town') ? GETPOST('town', 'alphanohtml') : $soc->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1064  print '</td></tr>';
1065 
1066  // Country
1067  if (empty($soc->country_id)) {
1068  $soc->country_id = $mysoc->country_id;
1069  $soc->country_code = $mysoc->country_code;
1070  $soc->state_id = $mysoc->state_id;
1071  }
1072  print '<tr><td>'.$langs->trans('Country').'</td><td>';
1073  print img_picto('', 'country', 'class="pictofixedwidth"');
1074  print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'alpha') : $soc->country_id, 'country_id');
1075  if ($user->admin) {
1076  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1077  }
1078  print '</td></tr>';
1079 
1080  // State
1081  if (empty($conf->global->MEMBER_DISABLE_STATE)) {
1082  print '<tr><td>'.$langs->trans('State').'</td><td>';
1083  if ($soc->country_id) {
1084  print img_picto('', 'state', 'class="pictofixedwidth"');
1085  print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'int') : $soc->state_id, $soc->country_code);
1086  } else {
1087  print $countrynotdefined;
1088  }
1089  print '</td></tr>';
1090  }
1091 
1092  // Pro phone
1093  print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1094  print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" size="20" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $soc->phone).'"></td></tr>';
1095 
1096  // Personal phone
1097  print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1098  print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone_perso" size="20" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
1099 
1100  // Mobile phone
1101  print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1102  print '<td>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" size="20" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td></tr>';
1103 
1104  if (!empty($conf->socialnetworks->enabled)) {
1105  foreach ($socialnetworks as $key => $value) {
1106  if (!$value['active']) {
1107  break;
1108  }
1109  $val = (GETPOSTISSET('member_'.$key) ? GETPOST('member_'.$key, 'alpha') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]));
1110  print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="member_'.$key.'" size="40" value="'.$val.'"></td></tr>';
1111  }
1112  }
1113 
1114  // Birth Date
1115  print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1116  print $form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc');
1117  print "</td></tr>\n";
1118 
1119  // Public profil
1120  print "<tr><td>".$langs->trans("Public")."</td><td>\n";
1121  print $form->selectyesno("public", $object->public, 1);
1122  print "</td></tr>\n";
1123 
1124  // Categories
1125  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
1126  print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td><td>';
1127  $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, null, 'parent', null, null, 1);
1128  print img_picto('', 'category').$form->multiselectarray('memcats', $cate_arbo, GETPOST('memcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
1129  print "</td></tr>";
1130  }
1131 
1132  // Other attributes
1133  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1134 
1135  print '<tbody>';
1136  print "</table>\n";
1137 
1138  print dol_get_fiche_end();
1139 
1140  print $form->buttonsSaveCancel("AddMember");
1141 
1142  print "</form>\n";
1143  }
1144 
1145  // Edit mode
1146  if ($action == 'edit') {
1147  $res = $object->fetch($id);
1148  if ($res < 0) {
1149  dol_print_error($db, $object->error); exit;
1150  }
1151  $res = $object->fetch_optionals();
1152  if ($res < 0) {
1153  dol_print_error($db); exit;
1154  }
1155 
1156  $adht = new AdherentType($db);
1157  $adht->fetch($object->typeid);
1158 
1159  // We set country_id, and country_code, country of the chosen country
1160  $country = GETPOST('country', 'int');
1161  if (!empty($country) || $object->country_id) {
1162  $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country where rowid = ".(!empty($country) ? $country : $object->country_id);
1163  $resql = $db->query($sql);
1164  if ($resql) {
1165  $obj = $db->fetch_object($resql);
1166  } else {
1167  dol_print_error($db);
1168  }
1169  $object->country_id = $obj->rowid;
1170  $object->country_code = $obj->code;
1171  $object->country = $langs->trans("Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label;
1172  }
1173 
1174  $head = member_prepare_head($object);
1175 
1176 
1177  if ($conf->use_javascript_ajax) {
1178  print "\n".'<script type="text/javascript">';
1179  print 'jQuery(document).ready(function () {
1180  jQuery("#selectcountry_id").change(function() {
1181  document.formsoc.action.value="edit";
1182  document.formsoc.submit();
1183  });
1184  function initfieldrequired() {
1185  jQuery("#tdcompany").removeClass("fieldrequired");
1186  jQuery("#tdlastname").removeClass("fieldrequired");
1187  jQuery("#tdfirstname").removeClass("fieldrequired");
1188  if (jQuery("#morphy").val() == \'mor\') {
1189  jQuery("#tdcompany").addClass("fieldrequired");
1190  }
1191  if (jQuery("#morphy").val() == \'phy\') {
1192  jQuery("#tdlastname").addClass("fieldrequired");
1193  jQuery("#tdfirstname").addClass("fieldrequired");
1194  }
1195  }
1196  jQuery("#morphy").change(function() {
1197  initfieldrequired();
1198  });
1199  initfieldrequired();
1200  })';
1201  print '</script>'."\n";
1202  }
1203 
1204  print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
1205  print '<input type="hidden" name="token" value="'.newToken().'" />';
1206  print '<input type="hidden" name="action" value="update" />';
1207  print '<input type="hidden" name="rowid" value="'.$id.'" />';
1208  print '<input type="hidden" name="statut" value="'.$object->statut.'" />';
1209  if ($backtopage) {
1210  print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1211  }
1212 
1213  print dol_get_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user');
1214 
1215  print '<table class="border centpercent">';
1216 
1217  // Ref
1218  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td class="valeur">'.$object->ref.'</td></tr>';
1219 
1220  // Login
1221  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
1222  print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").' / '.$langs->trans("Id").'</span></td><td><input type="text" name="login" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("login") ? GETPOST("login", 'alphanohtml', 2) : $object->login).'"></td></tr>';
1223  }
1224 
1225  // Password
1226  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
1227  print '<tr><td class="fieldrequired">'.$langs->trans("Password").'</td><td><input type="password" name="pass" class="minwidth300" maxlength="50" value="'.dol_escape_htmltag(GETPOSTISSET("pass") ? GETPOST("pass", 'none', 2) : $object->pass).'"></td></tr>';
1228  }
1229 
1230  // Type
1231  print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
1232  if ($user->rights->adherent->creer) {
1233  print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $object->typeid), 0, 0, 0, '', 0, 0, 0, '', '', 1);
1234  } else {
1235  print $adht->getNomUrl(1);
1236  print '<input type="hidden" name="typeid" value="'.$object->typeid.'">';
1237  }
1238  print "</td></tr>";
1239 
1240  // Morphy
1241  $morphys["phy"] = $langs->trans("Physical");
1242  $morphys["mor"] = $langs->trans("Moral");
1243  print '<tr><td><span class="fieldrequired">'.$langs->trans("MemberNature").'</span></td><td>';
1244  print $form->selectarray("morphy", $morphys, (GETPOSTISSET("morphy") ? GETPOST("morphy", 'alpha') : $object->morphy), 0, 0, 0, '', 0, 0, 0, '', '', 1);
1245  print "</td></tr>";
1246 
1247  // Company
1248  print '<tr><td id="tdcompany">'.$langs->trans("Company").'</td><td><input type="text" name="societe" class="minwidth300" maxlength="128" value="'.(GETPOSTISSET("societe") ? GETPOST("societe", 'alphanohtml', 2) : $object->company).'"></td></tr>';
1249 
1250  // Civility
1251  print '<tr><td>'.$langs->trans("UserTitle").'</td><td>';
1252  print $formcompany->select_civility(GETPOSTISSET("civility_id") ? GETPOST("civility_id", 'alpha') : $object->civility_id, 'civility_id', 'maxwidth150', 1);
1253  print '</td>';
1254  print '</tr>';
1255 
1256  // Lastname
1257  print '<tr><td id="tdlastname">'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("lastname") ? GETPOST("lastname", 'alphanohtml', 2) : $object->lastname).'"></td>';
1258  print '</tr>';
1259 
1260  // Firstname
1261  print '<tr><td id="tdfirstname">'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" class="minwidth300" maxlength="50" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname", 'alphanohtml', 3) : $object->firstname).'"></td>';
1262  print '</tr>';
1263 
1264  // Gender
1265  print '<tr><td>'.$langs->trans("Gender").'</td>';
1266  print '<td>';
1267  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
1268  print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ? GETPOST('gender', 'alphanohtml') : $object->gender, 1, 0, 0, '', 0, 0, 0, '', '', 1);
1269  print '</td></tr>';
1270 
1271  // Photo
1272  print '<tr><td>'.$langs->trans("Photo").'</td>';
1273  print '<td class="hideonsmartphone" valign="middle">';
1274  print $form->showphoto('memberphoto', $object)."\n";
1275  if ($caneditfieldmember) {
1276  if ($object->photo) {
1277  print "<br>\n";
1278  }
1279  print '<table class="nobordernopadding">';
1280  if ($object->photo) {
1281  print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1282  }
1283  print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1284  print '<tr><td>';
1285  $maxfilesizearray = getMaxFileSizeArray();
1286  $maxmin = $maxfilesizearray['maxmin'];
1287  if ($maxmin > 0) {
1288  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1289  }
1290  print '<input type="file" class="flat" name="photo" id="photoinput">';
1291  print '</td></tr>';
1292  print '</table>';
1293  }
1294  print '</td></tr>';
1295 
1296  // EMail
1297  print '<tr><td>'.(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? '</span>' : '').'</td>';
1298  print '<td>'.img_picto('', 'object_email', 'class="pictofixedwidth"').'<input type="text" name="member_email" class="minwidth300" maxlength="255" value="'.(GETPOSTISSET("member_email") ? GETPOST("member_email", '', 2) : $object->email).'"></td></tr>';
1299 
1300  // Website
1301  print '<tr><td>'.$form->editfieldkey('Web', 'member_url', GETPOST('member_url', 'alpha'), $object, 0).'</td>';
1302  print '<td>'.img_picto('', 'globe', 'class="pictofixedwidth"').'<input type="text" name="member_url" id="member_url" class="maxwidth200onsmartphone maxwidth500 widthcentpercentminusx " value="'.(GETPOSTISSET('member_url') ?GETPOST('member_url', 'alpha') : $object->url).'"></td></tr>';
1303 
1304  // Address
1305  print '<tr><td>'.$langs->trans("Address").'</td><td>';
1306  print '<textarea name="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml', 2) : $object->address).'</textarea>';
1307  print '</td></tr>';
1308 
1309  // Zip / Town
1310  print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
1311  print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode", 'alphanohtml', 2) : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1312  print ' ';
1313  print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town", 'alphanohtml', 2) : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1314  print '</td></tr>';
1315 
1316  // Country
1317  //$object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; // In edit mode we don't force to company country if not defined
1318  print '<tr><td>'.$langs->trans('Country').'</td><td>';
1319  print img_picto('', 'country', 'class="pictofixedwidth"');
1320  print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id, 'country_id');
1321  if ($user->admin) {
1322  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1323  }
1324  print '</td></tr>';
1325 
1326  // State
1327  if (empty($conf->global->MEMBER_DISABLE_STATE)) {
1328  print '<tr><td>'.$langs->trans('State').'</td><td>';
1329  print img_picto('', 'state', 'class="pictofixedwidth"');
1330  print $formcompany->select_state($object->state_id, GETPOSTISSET("country_id") ? GETPOST("country_id", "alpha") : $object->country_id);
1331  print '</td></tr>';
1332  }
1333 
1334  // Pro phone
1335  print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1336  print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" value="'.(GETPOSTISSET("phone") ? GETPOST("phone") : $object->phone).'"></td></tr>';
1337 
1338  // Personal phone
1339  print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
1340  print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone_perso" value="'.(GETPOSTISSET("phone_perso") ? GETPOST("phone_perso") : $object->phone_perso).'"></td></tr>';
1341 
1342  // Mobile phone
1343  print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1344  print '<td>'.img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"').'<input type="text" name="phone_mobile" value="'.(GETPOSTISSET("phone_mobile") ? GETPOST("phone_mobile") : $object->phone_mobile).'"></td></tr>';
1345 
1346  if (!empty($conf->socialnetworks->enabled)) {
1347  foreach ($socialnetworks as $key => $value) {
1348  if (!$value['active']) {
1349  break;
1350  }
1351  print '<tr><td>'.$langs->trans($value['label']).'</td><td><input type="text" name="'.$key.'" class="minwidth100" value="'.(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : $object->socialnetworks[$key]).'"></td></tr>';
1352  }
1353  }
1354 
1355  // Birth Date
1356  print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
1357  print $form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc');
1358  print "</td></tr>\n";
1359 
1360  // Public profil
1361  print "<tr><td>".$langs->trans("Public")."</td><td>\n";
1362  print $form->selectyesno("public", (GETPOSTISSET("public") ? GETPOST("public", 'alphanohtml', 2) : $object->public), 1);
1363  print "</td></tr>\n";
1364 
1365  // Categories
1366  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
1367  print '<tr><td>'.$form->editfieldkey("Categories", 'memcats', '', $object, 0).'</td>';
1368  print '<td>';
1369  $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, null, null, null, null, 1);
1370  $c = new Categorie($db);
1371  $cats = $c->containing($object->id, Categorie::TYPE_MEMBER);
1372  $arrayselected = array();
1373  if (is_array($cats)) {
1374  foreach ($cats as $cat) {
1375  $arrayselected[] = $cat->id;
1376  }
1377  }
1378  print $form->multiselectarray('memcats', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
1379  print "</td></tr>";
1380  }
1381 
1382  // Third party Dolibarr
1383  if (!empty($conf->societe->enabled)) {
1384  print '<tr><td>'.$langs->trans("LinkedToDolibarrThirdParty").'</td><td colspan="2" class="valeur">';
1385  if ($object->socid) {
1386  $company = new Societe($db);
1387  $result = $company->fetch($object->socid);
1388  print $company->getNomUrl(1);
1389  } else {
1390  print $langs->trans("NoThirdPartyAssociatedToMember");
1391  }
1392  print '</td></tr>';
1393  }
1394 
1395  // Login Dolibarr
1396  print '<tr><td>'.$langs->trans("LinkedToDolibarrUser").'</td><td colspan="2" class="valeur">';
1397  if ($object->user_id) {
1398  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none');
1399  } else {
1400  print $langs->trans("NoDolibarrAccess");
1401  }
1402  print '</td></tr>';
1403 
1404  // Other attributes. Fields from hook formObjectOptions and Extrafields.
1405  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1406 
1407  print '</table>';
1408  print dol_get_fiche_end();
1409 
1410  print $form->buttonsSaveCancel("Save", '');
1411 
1412  print '</form>';
1413  }
1414 
1415  // View
1416  if ($id > 0 && $action != 'edit') {
1417  $res = $object->fetch($id);
1418  if ($res < 0) {
1419  dol_print_error($db, $object->error); exit;
1420  }
1421  $res = $object->fetch_optionals();
1422  if ($res < 0) {
1423  dol_print_error($db); exit;
1424  }
1425 
1426  $adht = new AdherentType($db);
1427  $res = $adht->fetch($object->typeid);
1428  if ($res < 0) {
1429  dol_print_error($db); exit;
1430  }
1431 
1432 
1433  /*
1434  * Show tabs
1435  */
1436  $head = member_prepare_head($object);
1437 
1438  print dol_get_fiche_head($head, 'general', $langs->trans("Member"), -1, 'user');
1439 
1440  // Confirm create user
1441  if ($action == 'create_user') {
1442  $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login);
1443  if (empty($login)) {
1444  // Full firstname and name separated with a dot : firstname.name
1445  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1446  $login = dol_buildlogin($object->lastname, $object->firstname);
1447  }
1448  if (empty($login)) {
1449  $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4));
1450  }
1451 
1452  // Create a form array
1453  $formquestion = array(
1454  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)
1455  );
1456  if (!empty($conf->societe->enabled) && $object->socid > 0) {
1457  $object->fetch_thirdparty();
1458  $formquestion[] = array('label' => $langs->trans("UserWillBe"), 'type' => 'radio', 'name' => 'internalorexternal', 'default'=>'external', 'values' => array('external'=>$langs->trans("External").' - '.$langs->trans("LinkedToDolibarrThirdParty").' '.$object->thirdparty->getNomUrl(1, '', 0, 1), 'internal'=>$langs->trans("Internal")));
1459  }
1460  $text = '';
1461  if (!empty($conf->societe->enabled) && $object->socid <= 0) {
1462  $text .= $langs->trans("UserWillBeInternalUser").'<br>';
1463  }
1464  $text .= $langs->trans("ConfirmCreateLogin");
1465  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1466  }
1467 
1468  // Confirm create third party
1469  if ($action == 'create_thirdparty') {
1470  $companyalias = '';
1471  $fullname = $object->getFullName($langs);
1472 
1473  if ($object->morphy == 'mor') {
1474  $companyname = $object->company;
1475  if (!empty($fullname)) {
1476  $companyalias = $fullname;
1477  }
1478  } else {
1479  $companyname = $fullname;
1480  if (!empty($object->company)) {
1481  $companyalias = $object->company;
1482  }
1483  }
1484 
1485  // Create a form array
1486  $formquestion = array(
1487  array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
1488  array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
1489  );
1490 
1491  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 'yes');
1492  }
1493 
1494  // Confirm validate member
1495  if ($action == 'valid') {
1496  $langs->load("mails");
1497 
1498  $adht = new AdherentType($db);
1499  $adht->fetch($object->typeid);
1500 
1501  $subject = '';
1502  $msg = '';
1503 
1504  // Send subscription email
1505  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1506  $formmail = new FormMail($db);
1507  // Set output language
1508  $outputlangs = new Translate('', $conf);
1509  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1510  // Load traductions files required by page
1511  $outputlangs->loadLangs(array("main", "members", "companies", "install", "other"));
1512  // Get email content from template
1513  $arraydefaultmessage = null;
1514  $labeltouse = getDolGlobalString("ADHERENT_EMAIL_TEMPLATE_MEMBER_VALIDATION");
1515 
1516  if (!empty($labeltouse)) {
1517  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1518  }
1519 
1520  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1521  $subject = $arraydefaultmessage->topic;
1522  $msg = $arraydefaultmessage->content;
1523  }
1524 
1525  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1526  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1527  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1528  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
1529 
1530  $tmp = $langs->trans("SendingAnEMailToMember");
1531  $tmp .= '<br>'.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
1532  $tmp .= '<br>'.$langs->trans("MailRecipient").': <b>'.$object->email.'</b>';
1533  $helpcontent = '';
1534  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
1535  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1536  $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1537  $helpcontent .= $subjecttosend."\n";
1538  $helpcontent .= "<br>";
1539  $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1540  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1541  $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1542 
1543  // Create form popup
1544  $formquestion = array();
1545  if ($object->email) {
1546  $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (getDolGlobalString('ADHERENT_DEFAULT_SENDINFOBYMAIL') ? true : false));
1547  }
1548  if (!empty($conf->mailman->enabled) && !empty($conf->global->ADHERENT_USE_MAILMAN)) {
1549  $formquestion[] = array('type'=>'other', 'label'=>$langs->transnoentitiesnoconv("SynchroMailManEnabled"), 'value'=>'');
1550  }
1551  if (!empty($conf->mailman->enabled) && !empty($conf->global->ADHERENT_USE_SPIP)) {
1552  $formquestion[] = array('type'=>'other', 'label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"), 'value'=>'');
1553  }
1554  print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ValidateMember"), $langs->trans("ConfirmValidateMember"), "confirm_valid", $formquestion, 'yes', 1, 220);
1555  }
1556 
1557  // Confirm resiliate
1558  if ($action == 'resiliate') {
1559  $langs->load("mails");
1560 
1561  $adht = new AdherentType($db);
1562  $adht->fetch($object->typeid);
1563 
1564  $subject = '';
1565  $msg = '';
1566 
1567  // Send subscription email
1568  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1569  $formmail = new FormMail($db);
1570  // Set output language
1571  $outputlangs = new Translate('', $conf);
1572  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1573  // Load traductions files required by page
1574  $outputlangs->loadLangs(array("main", "members"));
1575  // Get email content from template
1576  $arraydefaultmessage = null;
1577  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_CANCELATION');
1578 
1579  if (!empty($labeltouse)) {
1580  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1581  }
1582 
1583  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1584  $subject = $arraydefaultmessage->topic;
1585  $msg = $arraydefaultmessage->content;
1586  }
1587 
1588  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1589  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1590  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1591  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnResiliate()), $substitutionarray, $outputlangs);
1592 
1593  $tmp = $langs->trans("SendingAnEMailToMember");
1594  $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
1595  $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1596  $helpcontent = '';
1597  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
1598  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1599  $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1600  $helpcontent .= $subjecttosend."\n";
1601  $helpcontent .= "<br>";
1602  $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1603  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1604  $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1605 
1606  // Create an array
1607  $formquestion = array();
1608  if ($object->email) {
1609  $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? 'true' : 'false'));
1610  }
1611  if ($backtopage) {
1612  $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1613  }
1614  print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ResiliateMember"), $langs->trans("ConfirmResiliateMember"), "confirm_resiliate", $formquestion, 'no', 1, 240);
1615  }
1616 
1617  // Confirm exclude
1618  if ($action == 'exclude') {
1619  $langs->load("mails");
1620 
1621  $adht = new AdherentType($db);
1622  $adht->fetch($object->typeid);
1623 
1624  $subject = '';
1625  $msg = '';
1626 
1627  // Send subscription email
1628  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1629  $formmail = new FormMail($db);
1630  // Set output language
1631  $outputlangs = new Translate('', $conf);
1632  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1633  // Load traductions files required by page
1634  $outputlangs->loadLangs(array("main", "members"));
1635  // Get email content from template
1636  $arraydefaultmessage = null;
1637  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_EXCLUSION;
1638 
1639  if (!empty($labeltouse)) {
1640  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1641  }
1642 
1643  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1644  $subject = $arraydefaultmessage->topic;
1645  $msg = $arraydefaultmessage->content;
1646  }
1647 
1648  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1649  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1650  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1651  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnExclude()), $substitutionarray, $outputlangs);
1652 
1653  $tmp = $langs->trans("SendingAnEMailToMember");
1654  $tmp .= '<br>('.$langs->trans("MailFrom").': <b>'.$conf->global->ADHERENT_MAIL_FROM.'</b>, ';
1655  $tmp .= $langs->trans("MailRecipient").': <b>'.$object->email.'</b>)';
1656  $helpcontent = '';
1657  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
1658  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1659  $helpcontent .= '<b>'.$langs->trans("Subject").'</b>:<br>'."\n";
1660  $helpcontent .= $subjecttosend."\n";
1661  $helpcontent .= "<br>";
1662  $helpcontent .= '<b>'.$langs->trans("Content").'</b>:<br>';
1663  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1664  $label = $form->textwithpicto($tmp, $helpcontent, 1, 'help');
1665 
1666  // Create an array
1667  $formquestion = array();
1668  if ($object->email) {
1669  $formquestion[] = array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? 'true' : 'false'));
1670  }
1671  if ($backtopage) {
1672  $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1673  }
1674  print $form->formconfirm("card.php?rowid=".$id, $langs->trans("ExcludeMember"), $langs->trans("ConfirmExcludeMember"), "confirm_exclude", $formquestion, 'no', 1, 240);
1675  }
1676 
1677  // Confirm remove member
1678  if ($action == 'delete') {
1679  $formquestion = array();
1680  if ($backtopage) {
1681  $formquestion[] = array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]));
1682  }
1683  print $form->formconfirm("card.php?rowid=".$id, $langs->trans("DeleteMember"), $langs->trans("ConfirmDeleteMember"), "confirm_delete", $formquestion, 'no', 1);
1684  }
1685 
1686  // Confirm add in spip
1687  if ($action == 'add_spip') {
1688  print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
1689  }
1690  // Confirm removed from spip
1691  if ($action == 'del_spip') {
1692  print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
1693  }
1694 
1695  $rowspan = 17;
1696  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
1697  $rowspan++;
1698  }
1699  if (!empty($conf->societe->enabled)) {
1700  $rowspan++;
1701  }
1702 
1703  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1704 
1705  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
1706  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1707  $morehtmlref .= '</a>';
1708 
1709 
1710  dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1711 
1712  print '<div class="fichecenter">';
1713  print '<div class="fichehalfleft">';
1714 
1715  print '<div class="underbanner clearboth"></div>';
1716  print '<table class="border tableforfield centpercent">';
1717 
1718  // Login
1719  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
1720  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
1721  }
1722 
1723  // Type
1724  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
1725 
1726  // Morphy
1727  print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
1728  print '</tr>';
1729 
1730  // Company
1731  print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
1732 
1733  // Civility
1734  print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
1735  print '</tr>';
1736 
1737  // Password
1738  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
1739  print '<tr><td>'.$langs->trans("Password").'</td><td>';
1740  if ($object->pass) {
1741  print preg_replace('/./i', '*', $object->pass);
1742  } else {
1743  if ($user->admin) {
1744  print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
1745  }
1746  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1747  }
1748  if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
1749  $langs->load("errors");
1750  $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
1751  print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
1752  }
1753  print '</td></tr>';
1754  }
1755 
1756  // Date end subscription
1757  print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
1758  if ($object->datefin) {
1759  print dol_print_date($object->datefin, 'day');
1760  if ($object->hasDelay()) {
1761  print " ".img_warning($langs->trans("Late"));
1762  }
1763  } else {
1764  if ($object->need_subscription == 0) {
1765  print $langs->trans("SubscriptionNotNeeded");
1766  } elseif (!$adht->subscription) {
1767  print $langs->trans("SubscriptionNotRecorded");
1768  if (Adherent::STATUS_VALIDATED == $object->statut) {
1769  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1770  }
1771  } else {
1772  print $langs->trans("SubscriptionNotReceived");
1773  if (Adherent::STATUS_VALIDATED == $object->statut) {
1774  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
1775  }
1776  }
1777  }
1778  print '</td></tr>';
1779 
1780  print '</table>';
1781 
1782  print '</div>';
1783 
1784  print '<div class="fichehalfright">';
1785  print '<div class="underbanner clearboth"></div>';
1786 
1787  print '<table class="border tableforfield centpercent">';
1788 
1789  // Tags / Categories
1790  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
1791  print '<tr><td>'.$langs->trans("Categories").'</td>';
1792  print '<td colspan="2">';
1793  print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
1794  print '</td></tr>';
1795  }
1796 
1797  // Birth Date
1798  print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
1799 
1800  // Public
1801  print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
1802 
1803  // Other attributes
1804  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1805 
1806  // Third party Dolibarr
1807  if (!empty($conf->societe->enabled)) {
1808  print '<tr><td>';
1809  $editenable = $user->rights->adherent->creer;
1810  print $form->editfieldkey('LinkedToDolibarrThirdParty', 'thirdparty', '', $object, $editenable);
1811  print '</td><td colspan="2" class="valeur">';
1812  if ($action == 'editthirdparty') {
1813  $htmlname = 'socid';
1814  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
1815  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
1816  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
1817  print '<input type="hidden" name="token" value="'.newToken().'">';
1818  print '<table class="nobordernopadding">';
1819  print '<tr><td>';
1820  print $form->select_company($object->socid, 'socid', '', 1);
1821  print '</td>';
1822  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
1823  print '</tr></table></form>';
1824  } else {
1825  if ($object->socid) {
1826  $company = new Societe($db);
1827  $result = $company->fetch($object->socid);
1828  print $company->getNomUrl(1);
1829 
1830  // Show link to invoices
1831  $tmparray = $company->getOutstandingBills('customer');
1832  if (!empty($tmparray['refs'])) {
1833  print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->socid.'">'.$langs->trans("Invoices").' ('.count($tmparray['refs']).')';
1834  // TODO Add alert if warning on at least one invoice late
1835  print '</a>';
1836  }
1837  } else {
1838  print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
1839  }
1840  }
1841  print '</td></tr>';
1842  }
1843 
1844  // Login Dolibarr - Link to user
1845  print '<tr><td>';
1846  $editenable = $user->rights->adherent->creer && $user->rights->user->user->creer;
1847  print $form->editfieldkey('LinkedToDolibarrUser', 'login', '', $object, $editenable);
1848  print '</td><td colspan="2" class="valeur">';
1849  if ($action == 'editlogin') {
1850  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
1851  } else {
1852  if ($object->user_id) {
1853  $linkeduser = new User($db);
1854  $linkeduser->fetch($object->user_id);
1855  print $linkeduser->getNomUrl(-1);
1856  } else {
1857  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1858  }
1859  }
1860  print '</td></tr>';
1861 
1862  print "</table>\n";
1863 
1864  print "</div></div>\n";
1865  print '<div style="clear:both"></div>';
1866 
1867  print dol_get_fiche_end();
1868 
1869 
1870  /*
1871  * Action bar
1872  */
1873 
1874  print '<div class="tabsAction">';
1875  $isinspip = 0;
1876  $parameters = array();
1877  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1878  if (empty($reshook)) {
1879  if ($action != 'editlogin' && $action != 'editthirdparty') {
1880  // Send
1881  if (empty($user->socid)) {
1882  if (Adherent::STATUS_VALIDATED == $object->statut) {
1883  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
1884  }
1885  }
1886 
1887  // Send card by email
1888  // TODO Remove this to replace with a template
1889  /*
1890  if ($user->rights->adherent->creer) {
1891  if (Adherent::STATUS_VALIDATED == $object->statut) {
1892  if ($object->email) print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=sendinfo">'.$langs->trans("SendCardByMail")."</a>\n";
1893  else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendCardByMail")."</a>\n";
1894  } else {
1895  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("SendCardByMail")."</span>";
1896  }
1897  } else {
1898  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendCardByMail")."</span>";
1899  }*/
1900 
1901  // Modify
1902  if (!empty($user->rights->adherent->creer)) {
1903  print '<a class="butAction" href="card.php?rowid='.$id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
1904  } else {
1905  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Modify").'</span>'."\n";
1906  }
1907 
1908  // Validate
1909  if (Adherent::STATUS_DRAFT == $object->statut) {
1910  if ($user->rights->adherent->creer) {
1911  print '<a class="butAction" href="card.php?rowid='.$id.'&action=valid">'.$langs->trans("Validate").'</a>'."\n";
1912  } else {
1913  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span>'."\n";
1914  }
1915  }
1916 
1917  // Reactivate
1918  if (Adherent::STATUS_RESILIATED == $object->statut || Adherent::STATUS_EXCLUDED == $object->statut) {
1919  if ($user->rights->adherent->creer) {
1920  print '<a class="butAction" href="card.php?rowid='.$id.'&action=valid">'.$langs->trans("Reenable")."</a>\n";
1921  } else {
1922  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Reenable").'</span>'."\n";
1923  }
1924  }
1925 
1926  // Resiliate
1927  if (Adherent::STATUS_VALIDATED == $object->statut) {
1928  if ($user->rights->adherent->supprimer) {
1929  print '<a class="butAction" href="card.php?rowid='.$id.'&action=resiliate">'.$langs->trans("Resiliate")."</a></span>\n";
1930  } else {
1931  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Resiliate").'</span>'."\n";
1932  }
1933  }
1934 
1935  // Exclude
1936  if (Adherent::STATUS_VALIDATED == $object->statut) {
1937  if ($user->rights->adherent->supprimer) {
1938  print '<a class="butAction" href="card.php?rowid='.$id.'&action=exclude">'.$langs->trans("Exclude")."</a></span>\n";
1939  } else {
1940  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Exclude").'</span>'."\n";
1941  }
1942  }
1943 
1944  // Create third party
1945  if (!empty($conf->societe->enabled) && !$object->socid) {
1946  if ($user->rights->societe->creer) {
1947  if (Adherent::STATUS_DRAFT != $object->statut) {
1948  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty" title="'.dol_escape_htmltag($langs->trans("CreateDolibarrThirdPartyDesc")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
1949  } else {
1950  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrThirdParty").'</a>'."\n";
1951  }
1952  } else {
1953  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrThirdParty").'</span>'."\n";
1954  }
1955  }
1956 
1957  // Create user
1958  if (!$user->socid && !$object->user_id) {
1959  if ($user->rights->user->user->creer) {
1960  if (Adherent::STATUS_DRAFT != $object->statut) {
1961  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_user" title="'.dol_escape_htmltag($langs->trans("CreateDolibarrLoginDesc")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
1962  } else {
1963  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("CreateDolibarrLogin").'</a>'."\n";
1964  }
1965  } else {
1966  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin").'</span>'."\n";
1967  }
1968  }
1969 
1970  // Action SPIP
1971  if (!empty($conf->mailmanspip->enabled) && !empty($conf->global->ADHERENT_USE_SPIP)) {
1972  $isinspip = $mailmanspip->is_in_spip($object);
1973 
1974  if ($isinspip == 1) {
1975  print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=del_spip&token='.newToken().'">'.$langs->trans("DeleteIntoSpip").'</a>'."\n";
1976  }
1977  if ($isinspip == 0) {
1978  print '<a class="butAction" href="card.php?rowid='.$object->id.'&action=add_spip&token='.newToken().'">'.$langs->trans("AddIntoSpip").'</a>'."\n";
1979  }
1980  }
1981 
1982  // Delete
1983  if ($user->rights->adherent->supprimer) {
1984  print '<a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
1985  } else {
1986  print '<span class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</span>'."\n";
1987  }
1988  }
1989  }
1990  print '</div>';
1991 
1992  if ($isinspip == -1) {
1993  print '<br><br><span class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</span>';
1994  }
1995 
1996 
1997  // Select mail models is same action as presend
1998  if (GETPOST('modelselected')) {
1999  $action = 'presend';
2000  }
2001 
2002  if ($action != 'presend') {
2003  print '<div class="fichecenter"><div class="fichehalfleft">';
2004  print '<a name="builddoc"></a>'; // ancre
2005 
2006  // Generated documents
2007  $filename = dol_sanitizeFileName($object->ref);
2008  $filedir = $conf->adherent->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'member');
2009  $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
2010  $genallowed = $user->rights->adherent->lire;
2011  $delallowed = $user->rights->adherent->creer;
2012 
2013  print $formfile->showdocuments('member', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', (empty($object->default_lang) ? '' : $object->default_lang), '', $object);
2014  $somethingshown = $formfile->numoffiles;
2015 
2016  // Show links to link elements
2017  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
2018  //$somethingshown = $form->showLinkedObjectBlock($object, '');
2019 
2020  // Show links to link elements
2021  /*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
2022  if ($linktoelem) {
2023  print ($somethingshown?'':'<br>').$linktoelem;
2024  }
2025  */
2026 
2027  // Show online payment link
2028  $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
2029 
2030  if ($useonlinepayment) {
2031  print '<br>';
2032 
2033  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
2034  print showOnlinePaymentUrl('membersubscription', $object->ref);
2035  }
2036 
2037  print '</div><div class="fichehalfright">';
2038 
2039  $MAX = 10;
2040 
2041  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/adherents/agenda.php?id='.$object->id);
2042 
2043  // List of actions on element
2044  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2045  $formactions = new FormActions($db);
2046  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAX, '', $morehtmlcenter);
2047 
2048  print '</div></div>';
2049  }
2050 
2051  // Presend form
2052  $modelmail = 'member';
2053  $defaulttopic = 'CardContent';
2054  $diroutput = $conf->adherent->dir_output;
2055  $trackid = 'mem'.$object->id;
2056 
2057  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2058  }
2059 }
2060 
2061 // End of page
2062 llxFooter();
2063 $db->close();
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
Adherent\STATUS_RESILIATED
const STATUS_RESILIATED
Resiliated.
Definition: adherent.class.php:357
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dol_delete_dir_recursive
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1383
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
Translate
Class to manage translations.
Definition: translate.class.php:30
MailmanSpip
Class to manage mailman and spip.
Definition: mailmanspip.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
image_format_supported
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:80
member_prepare_head
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
name
$conf db name
Definition: repair.php:122
Categorie
Class to manage categories.
Definition: categorie.class.php:47
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1158
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3026
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
getRandomPassword
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
Definition: security2.lib.php:454
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7248
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_delete_file
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1231
getMaxFileSizeArray
getMaxFileSizeArray()
Return the max allowed for file upload.
Definition: security.lib.php:993
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:178
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
dol_move_uploaded_file
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1092
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
Adherent\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: adherent.class.php:353
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
Canvas
Class to manage canvas.
Definition: canvas.class.php:29
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
isValidUrl
isValidUrl($url, $http=0, $pass=0, $port=0, $path=0, $query=0, $anchor=0)
Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor].
Definition: functions2.lib.php:748
Adherent\STATUS_EXCLUDED
const STATUS_EXCLUDED
Excluded.
Definition: adherent.class.php:361
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Adherent\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: adherent.class.php:349
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:6991
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:489
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
dol_buildlogin
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
Definition: functions2.lib.php:2039
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
complete_substitutions_array
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
Definition: functions.lib.php:7961