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