dolibarr  17.0.4
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
7  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
10  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
11  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
13  * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
36 // Load Dolibarr environment
37 require '../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51 
52 // Load translation files required by the page
53 $langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
54 
55 $mesg = ''; $error = 0; $errors = array();
56 
57 // Get parameters
58 $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
59 $confirm = GETPOST('confirm', 'alpha');
60 $backtopage = GETPOST('backtopage', 'alpha');
61 $cancel = GETPOST('cancel', 'alpha');
62 $id = GETPOST('id', 'int');
63 $socid = GETPOST('socid', 'int');
64 
65 // Initialize technical object
66 $object = new Contact($db);
67 $extrafields = new ExtraFields($db);
68 
69 // fetch optionals attributes and labels
70 $extrafields->fetch_name_optionals_label($object->table_element);
71 
72 $socialnetworks = getArrayOfSocialNetworks();
73 
74 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
75 $object->getCanvas($id);
76 $objcanvas = null;
77 $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
78 if (!empty($canvas)) {
79  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
80  $objcanvas = new Canvas($db, $action);
81  $objcanvas->getCanvas('contact', 'contactcard', $canvas);
82 }
83 
84 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
85 $hookmanager->initHooks(array('contactcard', 'globalcard'));
86 
87 if ($id > 0) {
88  $object->fetch($id);
89  $object->info($id);
90 }
91 
92 if (!($object->id > 0) && $action == 'view') {
93  $langs->load("errors");
94  print($langs->trans('ErrorRecordNotFound'));
95  exit;
96 }
97 
98 $triggermodname = 'CONTACT_MODIFY';
99 $permissiontoadd = $user->rights->societe->contact->creer;
100 
101 // Security check
102 if ($user->socid) {
103  $socid = $user->socid;
104 }
105 if ($object->priv && $object->user_creation->id != $user->id) {
106  accessforbidden();
107 }
108 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
109 
110 
111 /*
112  * Actions
113  */
114 
115 $parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
116 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117 if ($reshook < 0) {
118  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119 }
120 
121 if (empty($reshook)) {
122  $backurlforlist = DOL_URL_ROOT.'/contact/list.php';
123 
124  if (empty($backtopage) || ($cancel && empty($id))) {
125  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
126  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
127  $backtopage = $backurlforlist;
128  } else {
129  $backtopage = DOL_URL_ROOT.'/contact/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
130  }
131  }
132  }
133 
134  if ($cancel) {
135  if (!empty($backtopageforcancel)) {
136  header("Location: ".$backtopageforcancel);
137  exit;
138  } elseif (!empty($backtopage)) {
139  header("Location: ".$backtopage);
140  exit;
141  }
142  $action = '';
143  }
144 
145  // Creation utilisateur depuis contact
146  if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
147  // Recuperation contact actuel
148  $result = $object->fetch($id);
149 
150  if ($result > 0) {
151  $db->begin();
152 
153  // Creation user
154  $nuser = new User($db);
155  $result = $nuser->create_from_contact($object, GETPOST("login")); // Do not use GETPOST(alpha)
156 
157  if ($result > 0) {
158  $result2 = $nuser->setPassword($user, GETPOST("password"), 0, 0, 1); // Do not use GETPOST(alpha)
159  if ($result2) {
160  $db->commit();
161  } else {
162  $error = $nuser->error; $errors = $nuser->errors;
163  $db->rollback();
164  }
165  } else {
166  $error = $nuser->error; $errors = $nuser->errors;
167  $db->rollback();
168  }
169  } else {
170  $error = $object->error; $errors = $object->errors;
171  }
172  }
173 
174 
175  // Confirmation desactivation
176  if ($action == 'disable' && !empty($permissiontoadd)) {
177  $object->fetch($id);
178  if ($object->setstatus(0) < 0) {
179  setEventMessages($object->error, $object->errors, 'errors');
180  } else {
181  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
182  exit;
183  }
184  }
185 
186  // Confirmation activation
187  if ($action == 'enable' && !empty($permissiontoadd)) {
188  $object->fetch($id);
189  if ($object->setstatus(1) < 0) {
190  setEventMessages($object->error, $object->errors, 'errors');
191  } else {
192  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
193  exit;
194  }
195  }
196 
197  // Add contact
198  if ($action == 'add' && !empty($permissiontoadd)) {
199  $db->begin();
200 
201  if ($canvas) {
202  $object->canvas = $canvas;
203  }
204 
205  $object->entity = (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
206  $object->socid = GETPOST("socid", 'int');
207  $object->lastname = (string) GETPOST("lastname", 'alpha');
208  $object->firstname = (string) GETPOST("firstname", 'alpha');
209  $object->civility_code = (string) GETPOST("civility_code", 'alpha');
210  $object->poste = (string) GETPOST("poste", 'alpha');
211  $object->address = (string) GETPOST("address", 'alpha');
212  $object->zip = (string) GETPOST("zipcode", 'alpha');
213  $object->town = (string) GETPOST("town", 'alpha');
214  $object->country_id = (int) GETPOST("country_id", 'int');
215  $object->state_id = (int) GETPOST("state_id", 'int');
216  //$object->jabberid = GETPOST("jabberid", 'alpha');
217  //$object->skype = GETPOST("skype", 'alpha');
218  //$object->twitter = GETPOST("twitter", 'alpha');
219  //$object->facebook = GETPOST("facebook", 'alpha');
220  //$object->linkedin = GETPOST("linkedin", 'alpha');
221  $object->socialnetworks = array();
222  if (isModEnabled('socialnetworks')) {
223  foreach ($socialnetworks as $key => $value) {
224  if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
225  $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
226  }
227  }
228  }
229  $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
230  $object->no_email = GETPOST("no_email", "int");
231  $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
232  $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
233  $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
234  $object->fax = (string) GETPOST("fax", 'alpha');
235  $object->priv = GETPOST("priv", 'int');
236  $object->note_public = (string) GETPOST("note_public", 'restricthtml');
237  $object->note_private = (string) GETPOST("note_private", 'restricthtml');
238  $object->roles = GETPOST("roles", 'array');
239 
240  $object->statut = 1; //Default status to Actif
241 
242  // Note: Correct date should be completed with location to have exact GM time of birth.
243  $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth", 'int'), GETPOST("birthdayday", 'int'), GETPOST("birthdayyear", 'int'));
244  $object->birthday_alert = GETPOST("birthday_alert", 'alpha');
245 
246  //Default language
247  $object->default_lang = GETPOST('default_lang');
248 
249  // Fill array 'array_options' with data from add form
250  $ret = $extrafields->setOptionalsFromPost(null, $object);
251  if ($ret < 0) {
252  $error++;
253  $action = 'create';
254  }
255 
256  if (isModEnabled('mailing') && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && $object->no_email == -1 && !empty($object->email)) {
257  $error++;
258  $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
259  $action = 'create';
260  }
261 
262  if (!empty($object->email) && !isValidEMail($object->email)) {
263  $langs->load("errors");
264  $error++;
265  $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
266  $action = 'create';
267  }
268 
269  if (empty($object->lastname)) {
270  $error++;
271  $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
272  $action = 'create';
273  }
274 
275  if (empty($error)) {
276  $id = $object->create($user);
277  if ($id <= 0) {
278  $error++;
279  $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
280  $action = 'create';
281  }
282  }
283 
284  if (empty($error)) {
285  // Categories association
286  $contcats = GETPOST('contcats', 'array');
287  if (count($contcats) > 0) {
288  $result = $object->setCategories($contcats);
289  if ($result <= 0) {
290  $error++;
291  $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
292  $action = 'create';
293  }
294  }
295  }
296 
297  if (empty($error) && isModEnabled('mailing') && !empty($object->email)) {
298  // Add mass emailing flag into table mailing_unsubscribe
299  $result = $object->setNoEmail($object->no_email);
300  if ($result < 0) {
301  $error++;
302  $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
303  $action = 'create';
304  }
305  }
306 
307  if (empty($error) && $id > 0) {
308  $db->commit();
309  if (!empty($backtopage)) {
310  $url = str_replace('__ID__', $id, $backtopage);
311  } else {
312  $url = 'card.php?id='.$id;
313  }
314  header("Location: ".$url);
315  exit;
316  } else {
317  $db->rollback();
318  }
319  }
320 
321  if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer) {
322  $result = $object->fetch($id);
323  $object->oldcopy = clone $object;
324 
325  $object->old_lastname = (string) GETPOST("old_lastname", 'alpha');
326  $object->old_firstname = (string) GETPOST("old_firstname", 'alpha');
327 
328  $result = $object->delete(); // TODO Add $user as first param
329  if ($result > 0) {
330  setEventMessages("RecordDeleted", null, 'mesgs');
331  if ($backurlforlist) {
332  header("Location: ".$backurlforlist);
333  exit;
334  } else {
335  header("Location: ".DOL_URL_ROOT.'/contact/list.php');
336  exit;
337  }
338  } else {
339  setEventMessages($object->error, $object->errors, 'errors');
340  }
341  }
342 
343  if ($action == 'update' && empty($cancel) && !empty($permissiontoadd)) {
344  if (!GETPOST("lastname", 'alpha')) {
345  $error++; $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
346  $action = 'edit';
347  }
348 
349  if (isModEnabled('mailing') && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST("no_email", "int") == -1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
350  $error++;
351  $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
352  $action = 'edit';
353  }
354 
355  if (!empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)) && !isValidEMail(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
356  $langs->load("errors");
357  $error++;
358  $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
359  $action = 'edit';
360  }
361 
362  if (!$error) {
363  $contactid = GETPOST("contactid", 'int');
364  $object->fetch($contactid);
365  $object->fetchRoles();
366 
367  // Photo save
368  $dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
369  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
370  if (GETPOST('deletephoto') && $object->photo) {
371  $fileimg = $dir.'/'.$object->photo;
372  $dirthumbs = $dir.'/thumbs';
373  dol_delete_file($fileimg);
374  dol_delete_dir_recursive($dirthumbs);
375  $object->photo = '';
376  }
377  if ($file_OK) {
378  if (image_format_supported($_FILES['photo']['name']) > 0) {
379  dol_mkdir($dir);
380 
381  if (@is_dir($dir)) {
382  $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
383  $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
384 
385  if (!($result > 0)) {
386  $errors[] = "ErrorFailedToSaveFile";
387  } else {
388  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
389 
390  // Create thumbs
391  $object->addThumbs($newfile);
392  }
393  }
394  } else {
395  $errors[] = "ErrorBadImageFormat";
396  }
397  } else {
398  switch ($_FILES['photo']['error']) {
399  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
400  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
401  $errors[] = "ErrorFileSizeTooLarge";
402  break;
403  case 3: //uploaded file was only partially uploaded
404  $errors[] = "ErrorFilePartiallyUploaded";
405  break;
406  }
407  }
408 
409  $object->oldcopy = clone $object;
410 
411  $object->old_lastname = (string) GETPOST("old_lastname", 'alpha');
412  $object->old_firstname = (string) GETPOST("old_firstname", 'alpha');
413 
414  $object->socid = GETPOST("socid", 'int');
415  $object->lastname = (string) GETPOST("lastname", 'alpha');
416  $object->firstname = (string) GETPOST("firstname", 'alpha');
417  $object->civility_code = (string) GETPOST("civility_code", 'alpha');
418  $object->poste = (string) GETPOST("poste", 'alpha');
419 
420  $object->address = (string) GETPOST("address", 'alpha');
421  $object->zip = (string) GETPOST("zipcode", 'alpha');
422  $object->town = (string) GETPOST("town", 'alpha');
423  $object->state_id = GETPOST("state_id", 'int');
424  $object->country_id = GETPOST("country_id", 'int');
425 
426  $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
427  $object->no_email = GETPOST("no_email", "int");
428  //$object->jabberid = GETPOST("jabberid", 'alpha');
429  //$object->skype = GETPOST("skype", 'alpha');
430  //$object->twitter = GETPOST("twitter", 'alpha');
431  //$object->facebook = GETPOST("facebook", 'alpha');
432  //$object->linkedin = GETPOST("linkedin", 'alpha');
433  $object->socialnetworks = array();
434  if (isModEnabled('socialnetworks')) {
435  foreach ($socialnetworks as $key => $value) {
436  if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
437  $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
438  }
439  }
440  }
441  $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
442  $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
443  $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
444  $object->fax = (string) GETPOST("fax", 'alpha');
445  $object->priv = (string) GETPOST("priv", 'int');
446  $object->note_public = (string) GETPOST("note_public", 'restricthtml');
447  $object->note_private = (string) GETPOST("note_private", 'restricthtml');
448 
449  $object->roles = GETPOST("roles", 'array'); // Note GETPOSTISSET("role") is null when combo is empty
450 
451  //Default language
452  $object->default_lang = GETPOST('default_lang');
453 
454  // Fill array 'array_options' with data from add form
455  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
456  if ($ret < 0) {
457  $error++;
458  }
459 
460  if (!$error) {
461  $result = $object->update($contactid, $user);
462 
463  if ($result > 0) {
464  // Categories association
465  $categories = GETPOST('contcats', 'array');
466  $object->setCategories($categories);
467 
468  // Update mass emailing flag into table mailing_unsubscribe
469  if (GETPOSTISSET('no_email') && $object->email) {
470  $no_email = GETPOST('no_email', 'int');
471  $result = $object->setNoEmail($no_email);
472  if ($result < 0) {
473  setEventMessages($object->error, $object->errors, 'errors');
474  $action = 'edit';
475  }
476  }
477 
478  $action = 'view';
479  } else {
480  setEventMessages($object->error, $object->errors, 'errors');
481  $action = 'edit';
482  }
483  }
484  }
485 
486  if (!$error && empty($errors)) {
487  if (!empty($backtopage)) {
488  header("Location: ".$backtopage);
489  exit;
490  }
491  }
492  }
493 
494  if ($action == 'setprospectcontactlevel' && !empty($permissiontoadd)) {
495  $object->fetch($id);
496  $object->fk_prospectlevel = GETPOST('prospect_contact_level_id', 'alpha');
497  $result = $object->update($object->id, $user);
498  if ($result < 0) {
499  setEventMessages($object->error, $object->errors, 'errors');
500  }
501  }
502 
503  // set communication status
504  if ($action == 'setstcomm' && !empty($permissiontoadd)) {
505  $object->fetch($id);
506  $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
507  $result = $object->update($object->id, $user);
508  if ($result < 0) {
509  setEventMessages($object->error, $object->errors, 'errors');
510  }
511  }
512 
513  // Update extrafields
514  if ($action == "update_extras" && !empty($permissiontoadd)) {
515  $object->fetch(GETPOST('id', 'int'));
516 
517  $attributekey = GETPOST('attribute', 'alpha');
518  $attributekeylong = 'options_'.$attributekey;
519 
520  if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
521  // This is properties of a date
522  $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
523  //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
524  } else {
525  $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
526  }
527 
528  $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
529  if ($result > 0) {
530  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
531  $action = 'view';
532  } else {
533  setEventMessages($object->error, $object->errors, 'errors');
534  $action = 'edit_extras';
535  }
536  }
537 
538  // Update extrafields
539  if ($action == 'update_extras' && !empty($user->rights->societe->contact->creer)) {
540  $object->oldcopy = dol_clone($object);
541 
542  // Fill array 'array_options' with data from update form
543  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
544  if ($ret < 0) {
545  $error++;
546  }
547 
548  if (!$error) {
549  $result = $object->insertExtraFields('CONTACT_MODIFY');
550  if ($result < 0) {
551  setEventMessages($object->error, $object->errors, 'errors');
552  $error++;
553  }
554  }
555 
556  if ($error) {
557  $action = 'edit_extras';
558  }
559  }
560 
561  // Actions to send emails
562  $triggersendname = 'CONTACT_SENTBYMAIL';
563  $paramname = 'id';
564  $mode = 'emailfromcontact';
565  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
566 }
567 
568 
569 /*
570  * View
571  */
572 
573 $form = new Form($db);
574 $formadmin = new FormAdmin($db);
575 $formcompany = new FormCompany($db);
576 
577 $objsoc = new Societe($db);
578 if ($socid > 0) {
579  $objsoc->fetch($socid);
580 }
581 
582 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
583 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
584  $title = $object->lastname;
585 }
586 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
587 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
588 
589 llxHeader('', $title, $help_url);
590 
591 $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
592 
593 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
594  // -----------------------------------------
595  // When used with CANVAS
596  // -----------------------------------------
597  if (empty($object->error) && $id) {
598  $object = new Contact($db);
599  $result = $object->fetch($id);
600  if ($result <= 0) {
601  dol_print_error('', $object->error);
602  }
603  }
604  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
605  $objcanvas->display_canvas($action); // Show template
606 } else {
607  // -----------------------------------------
608  // When used in standard mode
609  // -----------------------------------------
610 
611  // Confirm deleting contact
612  if ($user->rights->societe->contact->supprimer) {
613  if ($action == 'delete') {
614  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
615  }
616  }
617 
618  /*
619  * Onglets
620  */
621  $head = array();
622  if ($id > 0) {
623  // Si edition contact deja existant
624  $object = new Contact($db);
625  $res = $object->fetch($id, $user);
626  if ($res < 0) {
627  setEventMessages($object->error, $object->errors, 'errors');
628  }
629 
630  $object->fetchRoles();
631 
632  // Show tabs
633  $head = contact_prepare_head($object);
634  }
635 
636  if ($user->rights->societe->contact->creer) {
637  if ($action == 'create') {
638  /*
639  * Fiche en mode creation
640  */
641  $object->canvas = $canvas;
642 
643  $object->state_id = GETPOST("state_id", "int");
644 
645  // We set country_id, country_code and label for the selected country
646  $object->country_id = GETPOST("country_id") ? GETPOST("country_id", "int") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
647  if ($object->country_id) {
648  $tmparray = getCountry($object->country_id, 'all');
649  $object->country_code = $tmparray['code'];
650  $object->country = $tmparray['label'];
651  }
652 
653  $linkback = '';
654 
655  print load_fiche_titre($title, $linkback, 'address');
656 
657  // Show errors
658  dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
659 
660  if ($conf->use_javascript_ajax) {
661  print "\n".'<script type="text/javascript">'."\n";
662  print 'jQuery(document).ready(function () {
663  jQuery("#selectcountry_id").change(function() {
664  document.formsoc.action.value="create";
665  document.formsoc.submit();
666  });
667 
668  $("#copyaddressfromsoc").click(function() {
669  $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
670  $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
671  $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
672  console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
673  $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
674  /* set country at end because it will trigger page refresh */
675  console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
676  $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
677  });
678  })'."\n";
679  print '</script>'."\n";
680  }
681 
682  print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
683  print '<input type="hidden" name="token" value="'.newToken().'">';
684  print '<input type="hidden" name="action" value="add">';
685  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
686  if (!empty($objsoc)) {
687  print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
688  }
689 
690  print dol_get_fiche_head($head, 'card', '', 0, '');
691 
692  print '<table class="border centpercent">';
693 
694  // Name
695  print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
696  print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname", 'alpha') ?GETPOST("lastname", 'alpha') : $object->lastname).'" autofocus="autofocus"></td>';
697  print '</tr>';
698 
699  print '<tr>';
700  print '<td><label for="firstname">';
701  print $form->textwithpicto($langs->trans("Firstname"), $langs->trans("KeepEmptyIfGenericAddress")).'</label></td>';
702  print '<td colspan="3"><input name="firstname" id="firstname"type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname", 'alpha') ?GETPOST("firstname", 'alpha') : $object->firstname).'"></td>';
703  print '</tr>';
704 
705  // Company
706  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
707  if ($socid > 0) {
708  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
709  print '<td colspan="3" class="maxwidthonsmartphone">';
710  print $objsoc->getNomUrl(1, 'contact');
711  print '</td>';
712  print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
713  print '</td></tr>';
714  } else {
715  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
716  print img_picto('', 'company').$form->select_company($socid, 'socid', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
717  print '</td></tr>';
718  }
719  }
720 
721  // Civility
722  print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
723  print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
724  print '</td></tr>';
725 
726  // Job position
727  print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
728  print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ?GETPOST("poste", 'alphanohtml') : $object->poste).'"></td>';
729 
730  $colspan = 3;
731  if ($conf->use_javascript_ajax && $socid > 0) {
732  $colspan = 2;
733  }
734 
735  // Address
736  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->address)) == 0) {
737  $object->address = $objsoc->address; // Predefined with third party
738  }
739  print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
740  print '<td colspan="'.$colspan.'"><textarea class="flat quatrevingtpercent" name="address" id="address" rows="'.ROWS_2.'">'.(GETPOST("address", 'alpha') ?GETPOST("address", 'alpha') : $object->address).'</textarea></td>';
741 
742  if ($conf->use_javascript_ajax && $socid > 0) {
743  $rowspan = 3;
744  if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
745  $rowspan++;
746  }
747 
748  print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
749  print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
750  print '</td>';
751  }
752  print '</tr>';
753 
754  // Zip / Town
755  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->zip)) == 0) {
756  $object->zip = $objsoc->zip; // Predefined with third party
757  }
758  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->town)) == 0) {
759  $object->town = $objsoc->town; // Predefined with third party
760  }
761  print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
762  print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
763  print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
764  print '</td></tr>';
765 
766  // Country
767  print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
768  print img_picto('', 'globe-americas', 'class="paddingrightonly"');
769  print $form->select_country((GETPOST("country_id", 'alpha') ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
770  if ($user->admin) {
771  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
772  }
773  print '</td></tr>';
774 
775  // State
776  if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
777  if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
778  print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
779  } else {
780  print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
781  }
782 
783  if ($object->country_id) {
784  print img_picto('', 'state', 'class="pictofixedwidth"');
785  print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
786  } else {
787  print $countrynotdefined;
788  }
789  print '</td></tr>';
790  }
791 
792  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->phone_pro)) == 0) {
793  $object->phone_pro = $objsoc->phone; // Predefined with third party
794  }
795  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->fax)) == 0) {
796  $object->fax = $objsoc->fax; // Predefined with third party
797  }
798 
799  // Phone / Fax
800  print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
801  print '<td>';
802  print img_picto('', 'object_phoning');
803  print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" value="'.(GETPOSTISSET('phone_pro') ? GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
804  if ($conf->browser->layout == 'phone') {
805  print '</tr><tr>';
806  }
807  print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
808  print '<td>';
809  print img_picto('', 'object_phoning');
810  print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
811 
812  print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
813  print '<td>';
814  print img_picto('', 'object_phoning_mobile');
815  print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
816  if ($conf->browser->layout == 'phone') {
817  print '</tr><tr>';
818  }
819  print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
820  print '<td>';
821  print img_picto('', 'object_phoning_fax');
822  print '<input type="text" name="fax" id="fax" class="maxwidth200" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
823  print '</tr>';
824 
825  if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->email)) == 0) {
826  $object->email = $objsoc->email; // Predefined with third party
827  }
828 
829  // Email
830  print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
831  print '<td>';
832  print img_picto('', 'object_email');
833  print '<input type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
834  print '</tr>';
835 
836  // Unsubscribe
837  if (isModEnabled('mailing')) {
838  if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
839  print "\n".'<script type="text/javascript">'."\n";
840  print '$(document).ready(function () {
841  $("#email").keyup(function() {
842  if ($(this).val()!="") {
843  $(".noemail").addClass("fieldrequired");
844  } else {
845  $(".noemail").removeClass("fieldrequired");
846  }
847  });
848  })'."\n";
849  print '</script>'."\n";
850  }
851  if (!GETPOSTISSET("no_email") && !empty($object->email)) {
852  $result = $object->getNoEmail();
853  if ($result < 0) {
854  setEventMessages($object->error, $object->errors, 'errors');
855  }
856  }
857  print '<tr>';
858  print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
859  print '<td>';
860  print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
861  print '</td>';
862  print '</tr>';
863  }
864 
865 
866  if (isModEnabled('socialnetworks')) {
867  foreach ($socialnetworks as $key => $value) {
868  if ($value['active']) {
869  print '<tr>';
870  print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
871  print '<td colspan="3">';
872  if (!empty($value['icon'])) {
873  print '<span class="fa '.$value['icon'].'"></span>';
874  }
875  print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ?GETPOST($key, 'alphanohtml') : (!empty($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : "")).'">';
876  print '</td>';
877  print '</tr>';
878  } elseif (!empty($object->socialnetworks[$key])) {
879  print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
880  }
881  }
882  }
883 
884  // Visibility
885  print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
886  $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
887  print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ?GETPOST("priv", 'alpha') : $object->priv), 0);
888  print '</td></tr>';
889 
890  //Default language
891  if (getDolGlobalInt('MAIN_MULTILANGS')) {
892  print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
893  print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
894  print '</td>';
895  print '</tr>';
896  }
897 
898  // Categories
899  if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
900  print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
901  $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
902  print img_picto('', 'category').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, null, null, '90%');
903  print "</td></tr>";
904  }
905 
906  // Contact by default
907  if (!empty($socid)) {
908  print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
909  print '<td colspan="3">';
910  $contactType = $object->listeTypeContacts('external', '', 1);
911  print $form->multiselectarray('roles', $contactType, array(), 0, 0, 'minwidth500');
912  print '</td></tr>';
913  }
914 
915  // Other attributes
916  $parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
917  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
918 
919  print "</table><br>";
920 
921  print '<hr style="margin-bottom: 20px">';
922 
923  // Add personnal information
924  print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
925 
926  print '<table class="border centpercent">';
927 
928  // Date To Birth
929  print '<tr><td><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td>';
930  $form = new Form($db);
931  if ($object->birthday) {
932  print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
933  } else {
934  print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
935  }
936  print '</td>';
937 
938  print '<td><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
939  if (!empty($object->birthday_alert)) {
940  print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
941  } else {
942  print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
943  }
944  print '</td>';
945  print '</tr>';
946 
947  print "</table>";
948 
949  print dol_get_fiche_end();
950 
951  print $form->buttonsSaveCancel("Add");
952 
953  print "</form>";
954  } elseif ($action == 'edit' && !empty($id)) {
955  /*
956  * Fiche en mode edition
957  */
958 
959  // We set country_id, and country_code label of the chosen country
960  if (GETPOSTISSET("country_id") || $object->country_id) {
961  $tmparray = getCountry($object->country_id, 'all');
962  $object->country_code = $tmparray['code'];
963  $object->country = $tmparray['label'];
964  }
965 
966  $objsoc = new Societe($db);
967  $objsoc->fetch($object->socid);
968 
969  // Show errors
970  dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
971 
972  if ($conf->use_javascript_ajax) {
973  print "\n".'<script type="text/javascript">'."\n";
974  print 'jQuery(document).ready(function () {
975  jQuery("#selectcountry_id").change(function() {
976  document.formsoc.action.value="edit";
977  document.formsoc.submit();
978  });
979 
980  $("#copyaddressfromsoc").click(function() {
981  $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
982  $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
983  $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
984  console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
985  $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
986  /* set country at end because it will trigger page refresh */
987  console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
988  $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
989  });
990  })'."\n";
991  print '</script>'."\n";
992  }
993 
994  print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
995  print '<input type="hidden" name="token" value="'.newToken().'">';
996  print '<input type="hidden" name="id" value="'.$id.'">';
997  print '<input type="hidden" name="action" value="update">';
998  print '<input type="hidden" name="contactid" value="'.$object->id.'">';
999  print '<input type="hidden" name="old_lastname" value="'.$object->lastname.'">';
1000  print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
1001  if (!empty($backtopage)) {
1002  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1003  }
1004 
1005  print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
1006 
1007  print '<table class="border centpercent">';
1008 
1009  // Ref/ID
1010  if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
1011  print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
1012  print $object->ref;
1013  print '</td></tr>';
1014  }
1015 
1016  // Lastname
1017  print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
1018  print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("lastname") ? GETPOST("lastname") : $object->lastname).'" autofocus="autofocus"></td>';
1019  print '</tr>';
1020  print '<tr>';
1021  // Firstname
1022  print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
1023  print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
1024  print '</tr>';
1025 
1026  // Company
1027  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
1028  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
1029  print '<td colspan="3" class="maxwidthonsmartphone">';
1030  print img_picto('', 'company').$form->select_company(GETPOST('socid', 'int') ?GETPOST('socid', 'int') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
1031  print '</td>';
1032  print '</tr>';
1033  }
1034 
1035  // Civility
1036  print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
1037  print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
1038  print '</td></tr>';
1039 
1040  // Job position
1041  print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
1042  print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ? GETPOST("poste", 'alphanohtml') : $object->poste).'"></td></tr>';
1043 
1044  // Address
1045  print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
1046  print '<td colspan="3">';
1047  print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
1048  print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
1049  print '</div><div class="paddingrightonly valignmiddle inline-block">';
1050  if ($conf->use_javascript_ajax) {
1051  print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
1052  }
1053  print '</div>';
1054  print '</td>';
1055 
1056  // Zip / Town
1057  print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1058  print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
1059  print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1060  print '</td></tr>';
1061 
1062  // Country
1063  print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1064  print img_picto('', 'globe-americas', 'class="paddingrightonly"');
1065  print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
1066  if ($user->admin) {
1067  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1068  }
1069  print '</td></tr>';
1070 
1071  // State
1072  if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
1073  if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
1074  print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1075  } else {
1076  print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1077  }
1078 
1079  print img_picto('', 'state', 'class="pictofixedwidth"');
1080  print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
1081  print '</td></tr>';
1082  }
1083 
1084  // Phone
1085  print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
1086  print '<td>';
1087  print img_picto('', 'object_phoning');
1088  print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_pro') ?GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
1089  print '<td>'.$form->editfieldkey('PhonePerso', 'fax', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
1090  print '<td>';
1091  print img_picto('', 'object_phoning');
1092  print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_perso') ?GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
1093 
1094  print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
1095  print '<td>';
1096  print img_picto('', 'object_phoning_mobile');
1097  print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_mobile') ?GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
1098  print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
1099  print '<td>';
1100  print img_picto('', 'object_phoning_fax');
1101  print '<input type="text" name="fax" id="fax" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_fax') ?GETPOST('phone_fax', 'alpha') : $object->fax).'"></td></tr>';
1102 
1103  // EMail
1104  print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1105  print '<td>';
1106  print img_picto('', 'object_email');
1107  print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'"></td>';
1108  if (isModEnabled('mailing')) {
1109  $langs->load("mails");
1110  print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
1111  print '<td>'.$object->getNbOfEMailings().'</td>';
1112  } else {
1113  print '<td colspan="2"></td>';
1114  }
1115  print '</tr>';
1116 
1117  // Unsubscribe
1118  if (isModEnabled('mailing')) {
1119  if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
1120  print "\n".'<script type="text/javascript">'."\n";
1121 
1122  print '
1123  jQuery(document).ready(function () {
1124  function init_check_no_email(input) {
1125  if (input.val()!="") {
1126  $(".noemail").addClass("fieldrequired");
1127  } else {
1128  $(".noemail").removeClass("fieldrequired");
1129  }
1130  }
1131  $("#email").keyup(function() {
1132  init_check_no_email($(this));
1133  });
1134  init_check_no_email($("#email"));
1135  })'."\n";
1136  print '</script>'."\n";
1137  }
1138  if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1139  $result = $object->getNoEmail();
1140  if ($result < 0) {
1141  setEventMessages($object->error, $object->errors, 'errors');
1142  }
1143  }
1144  print '<tr>';
1145  print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1146  print '<td>';
1147  $useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
1148  print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
1149  print '</td>';
1150  print '</tr>';
1151  }
1152 
1153  if (isModEnabled('socialnetworks')) {
1154  foreach ($socialnetworks as $key => $value) {
1155  if ($value['active']) {
1156  print '<tr>';
1157  print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
1158  print '<td colspan="3">';
1159  if (!empty($value['icon'])) {
1160  print '<span class="fa '.$value['icon'].'"></span>';
1161  }
1162  print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ?GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
1163  print '</td>';
1164  print '</tr>';
1165  } elseif (!empty($object->socialnetworks[$key])) {
1166  print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
1167  }
1168  }
1169  }
1170 
1171  // Visibility
1172  print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
1173  $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
1174  print $form->selectarray('priv', $selectarray, $object->priv, 0);
1175  print '</td></tr>';
1176 
1177  //Default language
1178  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1179  print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1180  print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
1181  print '</td>';
1182  print '</tr>';
1183  }
1184 
1185  // Note Public
1186  print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
1187  $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
1188  print $doleditor->Create(1);
1189  print '</td></tr>';
1190 
1191  // Note Private
1192  print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
1193  $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
1194  print $doleditor->Create(1);
1195  print '</td></tr>';
1196 
1197  // Status
1198  print '<tr><td>'.$langs->trans("Status").'</td>';
1199  print '<td colspan="3">';
1200  print $object->getLibStatut(4);
1201  print '</td></tr>';
1202 
1203  // Categories
1204  if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
1205  $arrayselected = array();
1206  print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
1207  print '<td colspan="3">';
1208  $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, null, null, null, 1);
1209  $c = new Categorie($db);
1210  $cats = $c->containing($object->id, 'contact');
1211  foreach ($cats as $cat) {
1212  $arrayselected[] = $cat->id;
1213  }
1214  print img_picto('', 'category').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
1215  print "</td></tr>";
1216  }
1217 
1218  // Contact by default
1219  if (!empty($object->socid)) {
1220  print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
1221  print '<td colspan="3">';
1222  print $formcompany->showRoles("roles", $object, 'edit', $object->roles);
1223  print '</td></tr>';
1224  }
1225 
1226  // Other attributes
1227  $parameters = array('colspan' => ' colspan="3"', 'cols'=> '3', 'colspanvalue'=> '3');
1228  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1229 
1230  $object->load_ref_elements();
1231 
1232  if (isModEnabled('commande')) {
1233  print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
1234  print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
1235  print '</td></tr>';
1236  }
1237 
1238  if (isModEnabled("propal")) {
1239  print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1240  print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
1241  print '</td></tr>';
1242  }
1243 
1244  if (isModEnabled('contrat')) {
1245  print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1246  print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
1247  print '</td></tr>';
1248  }
1249 
1250  if (isModEnabled('facture')) {
1251  print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1252  print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
1253  print '</td></tr>';
1254  }
1255 
1256  // Login Dolibarr
1257  print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1258  if ($object->user_id) {
1259  $dolibarr_user = new User($db);
1260  $result = $dolibarr_user->fetch($object->user_id);
1261  print $dolibarr_user->getLoginUrl(1);
1262  } else {
1263  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1264  }
1265  print '</td></tr>';
1266 
1267  // Photo
1268  print '<tr>';
1269  print '<td>'.$langs->trans("PhotoFile").'</td>';
1270  print '<td colspan="3">';
1271  if ($object->photo) {
1272  print $form->showphoto('contact', $object);
1273  print "<br>\n";
1274  }
1275  print '<table class="nobordernopadding">';
1276  if ($object->photo) {
1277  print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1278  }
1279  //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1280  print '<tr><td>';
1281  $maxfilesizearray = getMaxFileSizeArray();
1282  $maxmin = $maxfilesizearray['maxmin'];
1283  if ($maxmin > 0) {
1284  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1285  }
1286  print '<input type="file" class="flat" name="photo" id="photoinput">';
1287  print '</td></tr>';
1288  print '</table>';
1289 
1290  print '</td>';
1291  print '</tr>';
1292 
1293  print '</table>';
1294 
1295  print dol_get_fiche_end();
1296 
1297  print $form->buttonsSaveCancel();
1298 
1299  print "</form>";
1300  }
1301  }
1302 
1303  // Select mail models is same action as presend
1304  if (GETPOST('modelselected', 'alpha')) {
1305  $action = 'presend';
1306  }
1307 
1308  // View mode
1309  if (!empty($id) && $action != 'edit' && $action != 'create') {
1310  $objsoc = new Societe($db);
1311 
1312  // Show errors
1313  dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
1314 
1315  print dol_get_fiche_head($head, 'card', $title, -1, 'contact');
1316 
1317  if ($action == 'create_user') {
1318  // Full firstname and lastname separated with a dot : firstname.lastname
1319  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1320  $login = dol_buildlogin($object->lastname, $object->firstname);
1321 
1322  $generated_password = '';
1323  if (empty($ldap_sid)) { // TODO ldap_sid ?
1324  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1325  $generated_password = getRandomPassword(false);
1326  }
1327  $password = $generated_password;
1328 
1329  // Create a form array
1330  $formquestion = array(
1331  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
1332  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
1333  //array('label' => $form->textwithpicto($langs->trans("Type"),$langs->trans("InternalExternalDesc")), 'type' => 'select', 'name' => 'intern', 'default' => 1, 'values' => array(0=>$langs->trans('Internal'),1=>$langs->trans('External')))
1334  );
1335  $text = $langs->trans("ConfirmCreateContact").'<br>';
1336  if (isModEnabled("societe")) {
1337  if ($object->socid > 0) {
1338  $text .= $langs->trans("UserWillBeExternalUser");
1339  } else {
1340  $text .= $langs->trans("UserWillBeInternalUser");
1341  }
1342  }
1343  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1344  }
1345 
1346  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1347 
1348  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
1349  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1350  $morehtmlref .= '</a>';
1351 
1352  $morehtmlref .= '<div class="refidno">';
1353  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
1354  $objsoc->fetch($object->socid);
1355  // Thirdparty
1356  $morehtmlref .= $langs->trans('ThirdParty').' : ';
1357  if ($objsoc->id > 0) {
1358  $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
1359  } else {
1360  $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
1361  }
1362  }
1363  $morehtmlref .= '</div>';
1364 
1365  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1366 
1367 
1368  print '<div class="fichecenter">';
1369  print '<div class="fichehalfleft">';
1370 
1371  print '<div class="underbanner clearboth"></div>';
1372  print '<table class="border tableforfield" width="100%">';
1373 
1374  // Civility
1375  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
1376  print $object->getCivilityLabel();
1377  print '</td></tr>';
1378 
1379  // Job / position
1380  print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
1381 
1382  // Email
1383  if (isModEnabled('mailing')) {
1384  $langs->load("mails");
1385  print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
1386  print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
1387  }
1388 
1389  // Unsubscribe opt-out
1390  if (isModEnabled('mailing')) {
1391  $result = $object->getNoEmail();
1392  if ($result < 0) {
1393  setEventMessages($object->error, $object->errors, 'errors');
1394  }
1395  print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
1396  if ($object->email) {
1397  print yn($object->no_email);
1398  } else {
1399  print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
1400  }
1401  print '</td></tr>';
1402  }
1403 
1404  // Default language
1405  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1406  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1407  print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1408  //$s=picto_from_langcode($object->default_lang);
1409  //print ($s?$s.' ':'');
1410  $langs->load("languages");
1411  $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1412  print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1413  print $labellang;
1414  print '</td></tr>';
1415  }
1416 
1417  print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
1418  print $object->LibPubPriv($object->priv);
1419  print '</td></tr>';
1420 
1421  print '</table>';
1422  print '</div>';
1423 
1424  $object->fetch_thirdparty();
1425 
1426 
1427  print '<div class="fichehalfright">';
1428 
1429  print '<div class="underbanner clearboth"></div>';
1430  print '<table class="border tableforfield centpercent">';
1431 
1432 
1433  if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
1434  if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
1435  // Level of prospect
1436  print '<tr><td class="titlefield">';
1437  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1438  print $langs->trans('ProspectLevel');
1439  print '<td>';
1440  if ($action != 'editlevel' && $user->rights->societe->contact->creer) {
1441  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
1442  }
1443  print '</tr></table>';
1444  print '</td><td>';
1445  if ($action == 'editlevel') {
1446  $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
1447  } else {
1448  print $object->getLibProspLevel();
1449  }
1450  print "</td>";
1451  print '</tr>';
1452 
1453  // Status of prospection
1454  $object->loadCacheOfProspStatus();
1455  print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
1456  print ' &nbsp; &nbsp; ';
1457  print '<div class="floatright">';
1458  foreach ($object->cacheprospectstatus as $key => $val) {
1459  $titlealt = 'default';
1460  if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1461  $titlealt = $val['label'];
1462  }
1463  if ($object->stcomm_id != $val['id']) {
1464  print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&stcomm='.urlencode($val['code']).'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
1465  }
1466  }
1467  print '</div></td></tr>';
1468  }
1469  }
1470 
1471  // Categories
1472  if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
1473  print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td>';
1474  print '<td>';
1475  print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
1476  print '</td></tr>';
1477  }
1478 
1479  if (!empty($object->socid)) {
1480  print '<tr><td class="titlefield">'.$langs->trans("ContactByDefaultFor").'</td>';
1481  print '<td>';
1482  print $formcompany->showRoles("roles", $object, 'view', $object->roles);
1483  print '</td></tr>';
1484  }
1485 
1486  // Other attributes
1487  $parameters = array('socid'=>$socid);
1488  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1489 
1490  $object->load_ref_elements();
1491 
1492  if (isModEnabled("propal")) {
1493  print '<tr><td class="titlefield tdoverflow">'.$langs->trans("ContactForProposals").'</td><td>';
1494  print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
1495  print '</td></tr>';
1496  }
1497 
1498  if (isModEnabled('commande') || isModEnabled("expedition")) {
1499  print '<tr><td class="titlefield tdoverflow">';
1500  if (isModEnabled("expedition")) {
1501  print $langs->trans("ContactForOrdersOrShipments");
1502  } else {
1503  print $langs->trans("ContactForOrders");
1504  }
1505  print '</td><td>';
1506  $none = $langs->trans("NoContactForAnyOrder");
1507  if (isModEnabled("expedition")) {
1508  $none = $langs->trans("NoContactForAnyOrderOrShipments");
1509  }
1510  print $object->ref_commande ? $object->ref_commande : $none;
1511  print '</td></tr>';
1512  }
1513 
1514  if (isModEnabled('contrat')) {
1515  print '<tr><td class="tdoverflow">'.$langs->trans("ContactForContracts").'</td><td>';
1516  print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
1517  print '</td></tr>';
1518  }
1519 
1520  if (isModEnabled('facture')) {
1521  print '<tr><td class="tdoverflow">'.$langs->trans("ContactForInvoices").'</td><td>';
1522  print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
1523  print '</td></tr>';
1524  }
1525 
1526  print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td>';
1527  if ($object->user_id) {
1528  $dolibarr_user = new User($db);
1529  $result = $dolibarr_user->fetch($object->user_id);
1530  print $dolibarr_user->getLoginUrl(-1);
1531  } else {
1532  //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1533  if (!$object->user_id && $user->rights->user->user->creer) {
1534  print '<a class="aaa" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user&token='.newToken().'">'.img_picto($langs->trans("CreateDolibarrLogin"), 'add', 'class="pictofixedwidth"').$langs->trans("CreateDolibarrLogin").'</a>';
1535  }
1536  }
1537  print '</td></tr>';
1538 
1539  print "</table>";
1540 
1541  print '</div></div>';
1542  print '<div style="clear:both"></div>';
1543 
1544  print dol_get_fiche_end();
1545 
1546  /*
1547  * Action bar
1548  */
1549  print '<div class="tabsAction">';
1550 
1551  $parameters = array();
1552  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1553  if (empty($reshook) && $action != 'presend') {
1554  if (empty($user->socid)) {
1555  if (!empty($object->email)) {
1556  $langs->load("mails");
1557  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>';
1558  } else {
1559  $langs->load("mails");
1560  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
1561  }
1562  }
1563 
1564  if ($user->rights->societe->contact->creer) {
1565  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
1566  }
1567 
1568  // Activer
1569  if ($object->statut == 0 && $user->rights->societe->contact->creer) {
1570  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
1571  }
1572  // Desactiver
1573  if ($object->statut == 1 && $user->rights->societe->contact->creer) {
1574  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
1575  }
1576 
1577  // Delete
1578  if ($user->rights->societe->contact->supprimer) {
1579  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().($backtopage ? '&backtopage='.urlencode($backtopage) : ''), 'delete', $user->rights->societe->contact->supprimer);
1580  }
1581  }
1582 
1583  print "</div>";
1584 
1585  //Select mail models is same action as presend
1586  if (GETPOST('modelselected')) {
1587  $action = 'presend';
1588  }
1589 
1590  if ($action != 'presend') {
1591  print '<div class="fichecenter"><div class="fichehalfleft">';
1592 
1593  print '</div><div class="fichehalfright">';
1594 
1595  $MAXEVENT = 10;
1596 
1597  $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
1598 
1599  // List of actions on element
1600  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1601  $formactions = new FormActions($db);
1602  $somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
1603 
1604  print '</div></div>';
1605  }
1606 
1607  // Presend form
1608  $modelmail = 'contact';
1609  $defaulttopic = 'Information';
1610  $diroutput = $conf->societe->dir_output.'/contact/';
1611  $trackid = 'ctc'.$object->id;
1612 
1613  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1614  }
1615 }
1616 
1617 
1618 llxFooter();
1619 
1620 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage canvas.
Class to manage categories.
Class to manage contact/addresses.
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:47
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
$parameters
Actions.
Definition: card.php:79
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1402
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1251
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1112
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
img_action($titlealt, $numaction, $picto='')
Show logo action.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:80
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.