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