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