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