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