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