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