dolibarr  9.0.0
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-2015 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.dolibarr@gmail.com>
9  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
10  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
11  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
34 require '../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
50 
51 $mesg=''; $error=0; $errors=array();
52 
53 $action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
54 $confirm = GETPOST('confirm','alpha');
55 $backtopage = GETPOST('backtopage','alpha');
56 $id = GETPOST('id','int');
57 $socid = GETPOST('socid','int');
58 
59 $object = new Contact($db);
60 $extrafields = new ExtraFields($db);
61 
62 // fetch optionals attributes and labels
63 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
64 
65 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
66 $object->getCanvas($id);
67 $objcanvas=null;
68 $canvas = (! empty($object->canvas)?$object->canvas:GETPOST("canvas"));
69 if (! empty($canvas))
70 {
71  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
72  $objcanvas = new Canvas($db, $action);
73  $objcanvas->getCanvas('contact', 'contactcard', $canvas);
74 }
75 
76 // Security check
77 if ($user->societe_id) $socid=$user->societe_id;
78 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission
79 
80 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
81 $hookmanager->initHooks(array('contactcard','globalcard'));
82 
83 
84 /*
85  * Actions
86  */
87 
88 $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
89 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
90 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 
92 if (empty($reshook))
93 {
94  // Cancel
95  if (GETPOST('cancel','alpha') && ! empty($backtopage))
96  {
97  header("Location: ".$backtopage);
98  exit;
99  }
100 
101  // Creation utilisateur depuis contact
102  if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
103  {
104  // Recuperation contact actuel
105  $result = $object->fetch($id);
106 
107  if ($result > 0)
108  {
109  $db->begin();
110 
111  // Creation user
112  $nuser = new User($db);
113  $result=$nuser->create_from_contact($object,GETPOST("login")); // Do not use GETPOST(alpha)
114 
115  if ($result > 0)
116  {
117  $result2=$nuser->setPassword($user,GETPOST("password"),0,0,1); // Do not use GETPOST(alpha)
118  if ($result2)
119  {
120  $db->commit();
121  }
122  else
123  {
124  $error=$nuser->error; $errors=$nuser->errors;
125  $db->rollback();
126  }
127  }
128  else
129  {
130  $error=$nuser->error; $errors=$nuser->errors;
131  $db->rollback();
132  }
133  }
134  else
135  {
136  $error=$object->error; $errors=$object->errors;
137  }
138  }
139 
140 
141  // Confirmation desactivation
142  if ($action == 'disable')
143  {
144  $object->fetch($id);
145  if ($object->setstatus(0)<0)
146  {
147  setEventMessages($object->error, $object->errors, 'errors');
148  }
149  else
150  {
151  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
152  exit;
153  }
154  }
155 
156  // Confirmation activation
157  if ($action == 'enable')
158  {
159  $object->fetch($id);
160  if ($object->setstatus(1)<0)
161  {
162  setEventMessages($object->error, $object->errors, 'errors');
163  }
164  else
165  {
166  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
167  exit;
168  }
169  }
170 
171  // Add contact
172  if ($action == 'add' && $user->rights->societe->contact->creer)
173  {
174  $db->begin();
175 
176  if ($canvas) $object->canvas=$canvas;
177 
178  $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
179  $object->socid = GETPOST("socid",'int');
180  $object->lastname = GETPOST("lastname",'alpha');
181  $object->firstname = GETPOST("firstname",'alpha');
182  $object->civility_id = GETPOST("civility_id",'alpha');
183  $object->poste = GETPOST("poste",'alpha');
184  $object->address = GETPOST("address",'alpha');
185  $object->zip = GETPOST("zipcode",'alpha');
186  $object->town = GETPOST("town",'alpha');
187  $object->country_id = GETPOST("country_id",'int');
188  $object->state_id = GETPOST("state_id",'int');
189  $object->skype = GETPOST("skype",'alpha');
190  $object->twitter = GETPOST("twitter",'alpha');
191  $object->facebook = GETPOST("facebook",'alpha');
192  $object->email = GETPOST("email",'alpha');
193  $object->phone_pro = GETPOST("phone_pro",'alpha');
194  $object->phone_perso = GETPOST("phone_perso",'alpha');
195  $object->phone_mobile = GETPOST("phone_mobile",'alpha');
196  $object->fax = GETPOST("fax",'alpha');
197  $object->jabberid = GETPOST("jabberid",'alpha');
198  $object->no_email = GETPOST("no_email",'int');
199  $object->priv = GETPOST("priv",'int');
200  $object->note_public = GETPOST("note_public",'none');
201  $object->note_private = GETPOST("note_private",'none');
202  $object->statut = 1; //Defult status to Actif
203 
204  // Note: Correct date should be completed with location to have exact GM time of birth.
205  $object->birthday = dol_mktime(0,0,0,GETPOST("birthdaymonth",'int'),GETPOST("birthdayday",'int'),GETPOST("birthdayyear",'int'));
206  $object->birthday_alert = GETPOST("birthday_alert",'alpha');
207 
208  // Fill array 'array_options' with data from add form
209  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
210  if ($ret < 0)
211  {
212  $error++;
213  $action = 'create';
214  }
215 
216  if (! GETPOST("lastname"))
217  {
218  $error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
219  $action = 'create';
220  }
221 
222  if (! $error)
223  {
224  $id = $object->create($user);
225  if ($id <= 0)
226  {
227  $error++; $errors=array_merge($errors,($object->error?array($object->error):$object->errors));
228  $action = 'create';
229  } else {
230  // Categories association
231  $contcats = GETPOST( 'contcats', 'array');
232  $object->setCategories($contcats);
233  }
234  }
235 
236  if (! $error && $id > 0)
237  {
238  $db->commit();
239  if (! empty($backtopage)) $url=$backtopage;
240  else $url='card.php?id='.$id;
241  header("Location: ".$url);
242  exit;
243  }
244  else
245  {
246  $db->rollback();
247  }
248  }
249 
250  if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer)
251  {
252  $result=$object->fetch($id);
253 
254  $object->old_lastname = GETPOST("old_lastname");
255  $object->old_firstname = GETPOST("old_firstname");
256 
257  $result = $object->delete();
258  if ($result > 0)
259  {
260  if ($backtopage)
261  {
262  header("Location: ".$backtopage);
263  exit;
264  }
265  else
266  {
267  header("Location: ".DOL_URL_ROOT.'/contact/list.php');
268  exit;
269  }
270  }
271  else
272  {
273  setEventMessages($object->error,$object->errors,'errors');
274  }
275  }
276 
277  if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
278  {
279  if (empty($_POST["lastname"]))
280  {
281  $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
282  $action = 'edit';
283  }
284 
285  if (! $error)
286  {
287  $contactid=GETPOST("contactid",'int');
288  $object->fetch($contactid);
289 
290  // Photo save
291  $dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
292  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
293  if (GETPOST('deletephoto') && $object->photo)
294  {
295  $fileimg=$dir.'/'.$object->photo;
296  $dirthumbs=$dir.'/thumbs';
297  dol_delete_file($fileimg);
298  dol_delete_dir_recursive($dirthumbs);
299  $object->photo = '';
300  }
301  if ($file_OK)
302  {
303  if (image_format_supported($_FILES['photo']['name']) > 0)
304  {
305  dol_mkdir($dir);
306 
307  if (@is_dir($dir))
308  {
309  $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
310  $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
311 
312  if (! $result > 0)
313  {
314  $errors[] = "ErrorFailedToSaveFile";
315  }
316  else
317  {
318  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
319 
320  // Create thumbs
321  $object->addThumbs($newfile);
322  }
323  }
324  }
325  else
326  {
327  $errors[] = "ErrorBadImageFormat";
328  }
329  }
330  else
331  {
332  switch($_FILES['photo']['error'])
333  {
334  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
335  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
336  $errors[] = "ErrorFileSizeTooLarge";
337  break;
338  case 3: //uploaded file was only partially uploaded
339  $errors[] = "ErrorFilePartiallyUploaded";
340  break;
341  }
342  }
343 
344  $object->oldcopy = clone $object;
345 
346  $object->old_lastname = GETPOST("old_lastname",'alpha');
347  $object->old_firstname = GETPOST("old_firstname",'alpha');
348 
349  $object->socid = GETPOST("socid",'int');
350  $object->lastname = GETPOST("lastname",'alpha');
351  $object->firstname = GETPOST("firstname",'alpha');
352  $object->civility_id = GETPOST("civility_id",'alpha');
353  $object->poste = GETPOST("poste",'alpha');
354 
355  $object->address = GETPOST("address",'alpha');
356  $object->zip = GETPOST("zipcode",'alpha');
357  $object->town = GETPOST("town",'alpha');
358  $object->state_id = GETPOST("state_id",'int');
359  $object->fk_departement = GETPOST("state_id",'int'); // For backward compatibility
360  $object->country_id = GETPOST("country_id",'int');
361 
362  $object->email = GETPOST("email",'alpha');
363  $object->skype = GETPOST("skype",'alpha');
364  $object->twitter = GETPOST("twitter",'alpha');
365  $object->facebook = GETPOST("facebook",'alpha');
366  $object->phone_pro = GETPOST("phone_pro",'alpha');
367  $object->phone_perso = GETPOST("phone_perso",'alpha');
368  $object->phone_mobile = GETPOST("phone_mobile",'alpha');
369  $object->fax = GETPOST("fax",'alpha');
370  $object->jabberid = GETPOST("jabberid",'alpha');
371  $object->no_email = GETPOST("no_email",'int');
372  $object->priv = GETPOST("priv",'int');
373  $object->note_public = GETPOST("note_public",'none');
374  $object->note_private = GETPOST("note_private",'none');
375 
376  // Fill array 'array_options' with data from add form
377  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
378  if ($ret < 0) $error++;
379 
380  $result = $object->update($contactid, $user);
381 
382  if ($result > 0) {
383  // Categories association
384  $categories = GETPOST('contcats', 'array');
385  $object->setCategories($categories);
386 
387  $object->old_lastname='';
388  $object->old_firstname='';
389  $action = 'view';
390  }
391  else
392  {
393  setEventMessages($object->error, $object->errors, 'errors');
394  $action = 'edit';
395  }
396  }
397 
398  if (! $error && empty($errors))
399  {
400  if (! empty($backtopage))
401  {
402  header("Location: ".$backtopage);
403  exit;
404  }
405  }
406  }
407 }
408 
409 
410 /*
411  * View
412  */
413 
414 
415 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
416 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
417 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
418 llxHeader('', $title, $help_url);
419 
420 $form = new Form($db);
421 $formcompany = new FormCompany($db);
422 
423 $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
424 
425 if ($socid > 0)
426 {
427  $objsoc = new Societe($db);
428  $objsoc->fetch($socid);
429 }
430 
431 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
432 {
433  // -----------------------------------------
434  // When used with CANVAS
435  // -----------------------------------------
436  if (empty($object->error) && $id)
437  {
438  $object = new Contact($db);
439  $result=$object->fetch($id);
440  if ($result <= 0) dol_print_error('',$object->error);
441  }
442  $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
443  $objcanvas->display_canvas($action); // Show template
444 }
445 else
446 {
447  // -----------------------------------------
448  // When used in standard mode
449  // -----------------------------------------
450 
451  // Confirm deleting contact
452  if ($user->rights->societe->contact->supprimer)
453  {
454  if ($action == 'delete')
455  {
456  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
457  }
458  }
459 
460  /*
461  * Onglets
462  */
463  $head=array();
464  if ($id > 0)
465  {
466  // Si edition contact deja existant
467  $object = new Contact($db);
468  $res=$object->fetch($id, $user);
469  if ($res < 0) { dol_print_error($db,$object->error); exit; }
470  $res=$object->fetch_optionals();
471  if ($res < 0) { dol_print_error($db,$object->error); exit; }
472 
473  // Show tabs
474  $head = contact_prepare_head($object);
475 
476  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
477  }
478 
479  if ($user->rights->societe->contact->creer)
480  {
481  if ($action == 'create')
482  {
483  /*
484  * Fiche en mode creation
485  */
486  $object->canvas=$canvas;
487 
488  $object->state_id = GETPOST("state_id");
489 
490  // We set country_id, country_code and label for the selected country
491  $object->country_id=$_POST["country_id"]?GETPOST("country_id"):(empty($objsoc->country_id)?$mysoc->country_id:$objsoc->country_id);
492  if ($object->country_id)
493  {
494  $tmparray=getCountry($object->country_id,'all');
495  $object->country_code = $tmparray['code'];
496  $object->country = $tmparray['label'];
497  }
498 
499  $title = $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
500  $linkback='';
501  print load_fiche_titre($title,$linkback,'title_companies.png');
502 
503  // Affiche les erreurs
504  dol_htmloutput_errors(is_numeric($error)?'':$error,$errors);
505 
506  if ($conf->use_javascript_ajax)
507  {
508  print "\n".'<script type="text/javascript" language="javascript">'."\n";
509  print 'jQuery(document).ready(function () {
510  jQuery("#selectcountry_id").change(function() {
511  document.formsoc.action.value="create";
512  document.formsoc.submit();
513  });
514 
515  $("#copyaddressfromsoc").click(function() {
516  $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
517  $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
518  $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
519  console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
520  $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
521  /* set country at end because it will trigger page refresh */
522  console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
523  $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
524  });
525  })'."\n";
526  print '</script>'."\n";
527  }
528 
529  print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
530  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
531  print '<input type="hidden" name="action" value="add">';
532  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
533  if (! empty($objsoc)) {
534  print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
535  }
536 
537  dol_fiche_head($head, 'card', '', 0, '');
538 
539  print '<table class="border" width="100%">';
540 
541  // Name
542  print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
543  print '<td><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>';
544  print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
545  print '<td><input name="firstname" id="firstname"type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname",'alpha')?GETPOST("firstname",'alpha'):$object->firstname).'"></td></tr>';
546 
547  // Company
548  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
549  {
550  if ($socid > 0)
551  {
552  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
553  print '<td colspan="3" class="maxwidthonsmartphone">';
554  print $objsoc->getNomUrl(1, 'contact');
555  print '</td>';
556  print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
557  print '</td></tr>';
558  }
559  else {
560  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
561  print $form->select_company($socid,'socid','','SelectThirdParty');
562  print '</td></tr>';
563  }
564  }
565 
566  // Civility
567  print '<tr><td><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
568  print $formcompany->select_civility(GETPOST("civility_id",'alpha')?GETPOST("civility_id",'alpha'):$object->civility_id);
569  print '</td></tr>';
570 
571  print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
572  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>';
573 
574  $colspan=3;
575  if ($conf->use_javascript_ajax && $socid > 0) $colspan=2;
576 
577  // Address
578  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
579  print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
580  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>';
581 
582  if ($conf->use_javascript_ajax && $socid > 0)
583  {
584  $rowspan=3;
585  if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++;
586 
587  print '<td valign="middle" align="center" rowspan="'.$rowspan.'">';
588  print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
589  print '</td>';
590  }
591  print '</tr>';
592 
593  // Zip / Town
594  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
595  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
596  print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
597  print $formcompany->select_ziptown((GETPOST("zipcode",'alpha')?GETPOST("zipcode",'alpha'):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
598  print $formcompany->select_ziptown((GETPOST("town",'alpha')?GETPOST("town",'alpha'):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
599  print '</td></tr>';
600 
601  // Country
602  print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
603  print $form->select_country((GETPOST("country_id",'alpha')?GETPOST("country_id",'alpha'):$object->country_id),'country_id');
604  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
605  print '</td></tr>';
606 
607  // State
608  if (empty($conf->global->SOCIETE_DISABLE_STATE))
609  {
610  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))
611  {
612  print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
613  }
614  else
615  {
616  print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
617  }
618 
619  if ($object->country_id)
620  {
621  print $formcompany->select_state(GETPOST("state_id",'alpha')?GETPOST("state_id",'alpha'):$object->state_id,$object->country_code,'state_id');
622  }
623  else
624  {
625  print $countrynotdefined;
626  }
627  print '</td></tr>';
628  }
629 
630  // Phone / Fax
631  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
632  print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
633  print '<td><input name="phone_pro" id="phone_pro" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_pro")?GETPOST("phone_pro"):$object->phone_pro).'"></td>';
634  print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
635  print '<td><input name="phone_perso" id="phone_perso" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_perso")?GETPOST("phone_perso"):$object->phone_perso).'"></td></tr>';
636 
637  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
638  print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
639  print '<td><input name="phone_mobile" id="phone_mobile" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_mobile")?GETPOST("phone_mobile"):$object->phone_mobile).'"></td>';
640  print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
641  print '<td><input name="fax" id="fax" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("fax",'alpha')?GETPOST("fax",'alpha'):$object->fax).'"></td></tr>';
642 
643  // EMail
644  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
645  print '<tr><td><label for="email">'.$langs->trans("Email").'</label></td>';
646  print '<td><input name="email" id="email" type="text" class="maxwidth100onsmartphone" value="'.dol_escape_htmltag(GETPOST("email",'alpha')?GETPOST("email",'alpha'):$object->email).'"></td>';
647  if (! empty($conf->mailing->enabled))
648  {
649  print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
650  print '<td>'.$form->selectyesno('no_email',(GETPOST("no_email",'alpha')?GETPOST("no_email",'alpha'):$object->no_email), 1).'</td>';
651  }
652  else
653  {
654  print '<td colspan="2">&nbsp;</td>';
655  }
656  print '</tr>';
657 
658  // Instant message and no email
659  print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
660  print '<td colspan="3"><input name="jabberid" id="jabberid" type="text" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("jabberid")?GETPOST("jabberid",'alpha'):$object->jabberid).'"></td></tr>';
661 
662  if (! empty($conf->socialnetworks->enabled))
663  {
664  // Skype
665  if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
666  {
667  print '<tr><td><label for="skype">'.fieldLabel('Skype','skype').'</label></td>';
668  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>';
669  }
670  // Twitter
671  if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
672  {
673  print '<tr><td><label for="twitter">'.fieldLabel('Twitter','twitter').'</label></td>';
674  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>';
675  }
676  // Facebook
677  if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
678  {
679  print '<tr><td><label for="facebook">'.fieldLabel('Facebook','facebook').'</label></td>';
680  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>';
681  }
682  }
683 
684  // Visibility
685  print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
686  $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
687  print $form->selectarray('priv',$selectarray,(GETPOST("priv",'alpha')?GETPOST("priv",'alpha'):$object->priv),0);
688  print '</td></tr>';
689 
690  // Categories
691  if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
692  print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td><td colspan="3">';
693  $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, 'parent', null, null, 1 );
694  print $form->multiselectarray( 'contcats', $cate_arbo, GETPOST( 'contcats', 'array' ), null, null, null,
695  null, '90%' );
696  print "</td></tr>";
697  }
698 
699  // Other attributes
700  $parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
701  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
702  print $hookmanager->resPrint;
703  if (empty($reshook))
704  {
705  print $object->showOptionals($extrafields,'edit');
706  }
707 
708  print "</table><br>";
709 
710  print '<hr style="margin-bottom: 20px">';
711 
712  // Add personnal information
713  print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>','','');
714 
715  print '<table class="border" width="100%">';
716 
717  // Date To Birth
718  print '<tr><td width="20%"><label for="birthday">'.$langs->trans("DateToBirth").'</label></td><td width="30%">';
719  $form=new Form($db);
720  if ($object->birthday)
721  {
722  print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
723  }
724  else
725  {
726  print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
727  }
728  print '</td>';
729 
730  print '<td colspan="2"><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
731  if ($object->birthday_alert)
732  {
733  print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked></td>';
734  }
735  else
736  {
737  print '<input type="checkbox" name="birthday_alert" id="birthday_alert"></td>';
738  }
739  print '</tr>';
740 
741  print "</table>";
742 
743  print dol_fiche_end();
744 
745  print '<div class="center">';
746  print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
747  if (! empty($backtopage))
748  {
749  print ' &nbsp; &nbsp; ';
750  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
751  }
752  else
753  {
754  print ' &nbsp; &nbsp; ';
755  print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
756  }
757  print '</div>';
758 
759  print "</form>";
760  }
761  elseif ($action == 'edit' && ! empty($id))
762  {
763  /*
764  * Fiche en mode edition
765  */
766 
767  // We set country_id, and country_code label of the chosen country
768  if (isset($_POST["country_id"]) || $object->country_id)
769  {
770  $tmparray=getCountry($object->country_id,'all');
771  $object->country_code = $tmparray['code'];
772  $object->country = $tmparray['label'];
773  }
774 
775  $objsoc = new Societe($db);
776  $objsoc->fetch($object->socid);
777 
778  // Affiche les erreurs
779  dol_htmloutput_errors($error,$errors);
780 
781  if ($conf->use_javascript_ajax)
782  {
783  print "\n".'<script type="text/javascript" language="javascript">'."\n";
784  print 'jQuery(document).ready(function () {
785  jQuery("#selectcountry_id").change(function() {
786  document.formsoc.action.value="edit";
787  document.formsoc.submit();
788  });
789 
790  $("#copyaddressfromsoc").click(function() {
791  $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
792  $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
793  $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
794  console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
795  $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
796  /* set country at end because it will trigger page refresh */
797  console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
798  $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
799  });
800  })'."\n";
801  print '</script>'."\n";
802  }
803 
804  print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
805  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
806  print '<input type="hidden" name="id" value="'.$id.'">';
807  print '<input type="hidden" name="action" value="update">';
808  print '<input type="hidden" name="contactid" value="'.$object->id.'">';
809  print '<input type="hidden" name="old_lastname" value="'.$object->lastname.'">';
810  print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
811  if (! empty($backtopage)) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
812 
813  dol_fiche_head($head, 'card', $title, 0, 'contact');
814 
815  print '<table class="border" width="100%">';
816 
817  // Ref/ID
818  if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
819  {
820  print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
821  print $object->ref;
822  print '</td></tr>';
823  }
824 
825  // Lastname
826  print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
827  print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.(isset($_POST["lastname"])?GETPOST("lastname"):$object->lastname).'" autofocus="autofocus"></td>';
828  print '</tr>';
829  print '<tr>';
830  // Firstname
831  print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
832  print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(isset($_POST["firstname"])?GETPOST("firstname"):$object->firstname).'"></td>';
833  print '</tr>';
834 
835  // Company
836  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
837  {
838  print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
839  print '<td colspan="3" class="maxwidthonsmartphone">';
840  print $form->select_company(GETPOST('socid','int')?GETPOST('socid','int'):($object->socid?$object->socid:-1), 'socid', '', $langs->trans("SelectThirdParty"));
841  print '</td>';
842  print '</tr>';
843  }
844 
845  // Civility
846  print '<tr><td><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
847  print $formcompany->select_civility(isset($_POST["civility_id"])?GETPOST("civility_id"):$object->civility_id);
848  print '</td></tr>';
849 
850  print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
851  print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="80" value="'.(isset($_POST["poste"])?GETPOST("poste"):$object->poste).'"></td></tr>';
852 
853  // Address
854  print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
855  print '<td colspan="3">';
856  print '<div class="paddingrightonly valignmiddle inline-block">';
857  print '<textarea class="flat minwidth200" name="address" id="address">'.(isset($_POST["address"])?GETPOST("address"):$object->address).'</textarea>';
858  print '</div><div class="paddingrightonly valignmiddle inline-block">';
859  if ($conf->use_javascript_ajax) print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
860  print '</div>';
861  print '</td>';
862 
863  // Zip / Town
864  print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
865  print $formcompany->select_ziptown((isset($_POST["zipcode"])?GETPOST("zipcode"):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
866  print $formcompany->select_ziptown((isset($_POST["town"])?GETPOST("town"):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
867  print '</td></tr>';
868 
869  // Country
870  print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
871  print $form->select_country(isset($_POST["country_id"])?GETPOST("country_id"):$object->country_id,'country_id');
872  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
873  print '</td></tr>';
874 
875  // State
876  if (empty($conf->global->SOCIETE_DISABLE_STATE))
877  {
878  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))
879  {
880  print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
881  }
882  else
883  {
884  print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
885  }
886 
887  print $formcompany->select_state($object->state_id,isset($_POST["country_id"])?GETPOST("country_id"):$object->country_id,'state_id');
888  print '</td></tr>';
889  }
890 
891  // Phone
892  print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
893  print '<td><input name="phone_pro" id="phone_pro" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["phone_pro"])?GETPOST("phone_pro"):$object->phone_pro).'"></td>';
894  print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
895  print '<td><input name="phone_perso" id="phone_perso" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["phone_perso"])?GETPOST("phone_perso"):$object->phone_perso).'"></td></tr>';
896 
897  print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
898  print '<td><input name="phone_mobile" id="phone_mobile" class="flat maxwidthonsmartphone" type="text" maxlength="80" value="'.(isset($_POST["phone_mobile"])?GETPOST("phone_mobile"):$object->phone_mobile).'"></td>';
899  print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
900  print '<td><input name="fax" id="fax" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["fax"])?GETPOST("fax"):$object->fax).'"></td></tr>';
901 
902  // EMail
903  print '<tr><td><label for="email">'.$langs->trans("EMail").'</label></td>';
904  print '<td><input name="email" id="email" type="text" class="flat maxwidthonsmartphone" value="'.(isset($_POST["email"])?GETPOST("email"):$object->email).'"></td>';
905  if (! empty($conf->mailing->enabled))
906  {
907  $langs->load("mails");
908  print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
909  print '<td>'.$object->getNbOfEMailings().'</td>';
910  }
911  else
912  {
913  print '<td colspan="2">&nbsp;</td>';
914  }
915  print '</tr>';
916 
917  // Jabberid
918  print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
919  print '<td><input name="jabberid" id="jabberid" type="text" class="minwidth100" maxlength="80" value="'.(isset($_POST["jabberid"])?$_POST["jabberid"]:$object->jabberid).'"></td>';
920  if (! empty($conf->mailing->enabled))
921  {
922  print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
923  print '<td>'.$form->selectyesno('no_email',(isset($_POST["no_email"])?$_POST["no_email"]:$object->no_email), 1).'</td>';
924  }
925  else
926  {
927  print '<td colspan="2">&nbsp;</td>';
928  }
929  print '</tr>';
930 
931  if (! empty($conf->socialnetworks->enabled))
932  {
933  // Skype
934  if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
935  {
936  print '<tr><td><label for="skype">'.fieldLabel('Skype','skype').'</label></td>';
937  print '<td><input type="text" name="skype" id="skype" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'"></td></tr>';
938  }
939  // Twitter
940  if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
941  {
942  print '<tr><td><label for="twitter">'.fieldLabel('Twitter','twitter').'</label></td>';
943  print '<td><input type="text" name="twitter" id="twitter" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'"></td></tr>';
944  }
945  // Facebook
946  if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
947  {
948  print '<tr><td><label for="facebook">'.fieldLabel('Facebook','facebook').'</label></td>';
949  print '<td><input type="text" name="facebook" id="facebook" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOST("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'"></td></tr>';
950  }
951  }
952 
953  // Visibility
954  print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
955  $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
956  print $form->selectarray('priv',$selectarray,$object->priv,0);
957  print '</td></tr>';
958 
959  // Note Public
960  print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
961  $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
962  print $doleditor->Create(1);
963  print '</td></tr>';
964 
965  // Note Private
966  print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
967  $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
968  print $doleditor->Create(1);
969  print '</td></tr>';
970 
971  // Status
972  print '<tr><td>'.$langs->trans("Status").'</td>';
973  print '<td colspan="3">';
974  print $object->getLibStatut(4);
975  print '</td></tr>';
976 
977  // Categories
978  if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) {
979  print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td>';
980  print '<td colspan="3">';
981  $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 );
982  $c = new Categorie( $db );
983  $cats = $c->containing( $object->id, 'contact' );
984  foreach ($cats as $cat) {
985  $arrayselected[] = $cat->id;
986  }
987  print $form->multiselectarray( 'contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' );
988  print "</td></tr>";
989  }
990 
991  // Other attributes
992  $parameters=array('colspan' => ' colspan="3"', 'cols'=>3);
993  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
994  print $hookmanager->resPrint;
995  if (empty($reshook))
996  {
997  print $object->showOptionals($extrafields,'edit');
998  }
999 
1000  $object->load_ref_elements();
1001 
1002  if (! empty($conf->commande->enabled))
1003  {
1004  print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
1005  print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
1006  print '</td></tr>';
1007  }
1008 
1009  if (! empty($conf->propal->enabled))
1010  {
1011  print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1012  print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
1013  print '</td></tr>';
1014  }
1015 
1016  if (! empty($conf->contrat->enabled))
1017  {
1018  print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1019  print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
1020  print '</td></tr>';
1021  }
1022 
1023  if (! empty($conf->facture->enabled))
1024  {
1025  print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1026  print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
1027  print '</td></tr>';
1028  }
1029 
1030  // Login Dolibarr
1031  print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1032  if ($object->user_id)
1033  {
1034  $dolibarr_user=new User($db);
1035  $result=$dolibarr_user->fetch($object->user_id);
1036  print $dolibarr_user->getLoginUrl(1);
1037  }
1038  else print $langs->trans("NoDolibarrAccess");
1039  print '</td></tr>';
1040 
1041  // Photo
1042  print '<tr>';
1043  print '<td>'.$langs->trans("PhotoFile").'</td>';
1044  print '<td colspan="3">';
1045  if ($object->photo) {
1046  print $form->showphoto('contact',$object);
1047  print "<br>\n";
1048  }
1049  print '<table class="nobordernopadding">';
1050  if ($object->photo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1051  //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1052  print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
1053  print '</table>';
1054 
1055  print '</td>';
1056  print '</tr>';
1057 
1058  print '</table>';
1059 
1060  print dol_fiche_end();
1061 
1062  print '<div class="center">';
1063  print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
1064  print ' &nbsp; &nbsp; ';
1065  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
1066  print '</div>';
1067 
1068  print "</form>";
1069  }
1070  }
1071 
1072  if (! empty($id) && $action != 'edit' && $action != 'create')
1073  {
1074  $objsoc = new Societe($db);
1075 
1076  /*
1077  * Fiche en mode visualisation
1078  */
1079 
1080  dol_htmloutput_errors($error,$errors);
1081 
1082  dol_fiche_head($head, 'card', $title, -1, 'contact');
1083 
1084  if ($action == 'create_user')
1085  {
1086  // Full firstname and lastname separated with a dot : firstname.lastname
1087  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1088  $login=dol_buildlogin($object->lastname,$object->firstname);
1089 
1090  $generated_password='';
1091  if (! $ldap_sid) // TODO ldap_sid ?
1092  {
1093  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1094  $generated_password=getRandomPassword(false);
1095  }
1096  $password=$generated_password;
1097 
1098  // Create a form array
1099  $formquestion=array(
1100  array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
1101  array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
1102  //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')))
1103  );
1104  $text=$langs->trans("ConfirmCreateContact").'<br>';
1105  if (! empty($conf->societe->enabled))
1106  {
1107  if ($object->socid > 0) $text.=$langs->trans("UserWillBeExternalUser");
1108  else $text.=$langs->trans("UserWillBeInternalUser");
1109  }
1110  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes');
1111  }
1112 
1113  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1114 
1115  $morehtmlref='<div class="refidno">';
1116  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
1117  {
1118  $objsoc->fetch($object->socid);
1119  // Thirdparty
1120  $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
1121  if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1, 'contact');
1122  else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
1123  }
1124  $morehtmlref.='</div>';
1125 
1126  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1127 
1128 
1129  print '<div class="fichecenter">';
1130  print '<div class="fichehalfleft">';
1131 
1132  print '<div class="underbanner clearboth"></div>';
1133  print '<table class="border tableforfield" width="100%">';
1134 
1135  // Civility
1136  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
1137  print $object->getCivilityLabel();
1138  print '</td></tr>';
1139 
1140  // Role
1141  print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
1142 
1143  // Email
1144  if (! empty($conf->mailing->enabled))
1145  {
1146  $langs->load("mails");
1147  print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
1148  print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
1149  }
1150 
1151  // Instant message and no email
1152  print '<tr><td>'.$langs->trans("IM").'</td><td>'.$object->jabberid.'</td></tr>';
1153  if (!empty($conf->mailing->enabled))
1154  {
1155  print '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td></tr>';
1156  }
1157 
1158  print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
1159  print $object->LibPubPriv($object->priv);
1160  print '</td></tr>';
1161 
1162  print '</table>';
1163 
1164  print '</div>';
1165  print '<div class="fichehalfright"><div class="ficheaddleft">';
1166 
1167  print '<div class="underbanner clearboth"></div>';
1168  print '<table class="border tableforfield" width="100%">';
1169 
1170  // Categories
1171  if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
1172  print '<tr><td class="titlefield">' . $langs->trans("Categories") . '</td>';
1173  print '<td colspan="3">';
1174  print $form->showCategories( $object->id, 'contact', 1 );
1175  print '</td></tr>';
1176  }
1177 
1178  // Other attributes
1179  $cols = 3;
1180  $parameyers=array('socid'=>$socid);
1181  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1182 
1183  $object->load_ref_elements();
1184 
1185  if (! empty($conf->propal->enabled))
1186  {
1187  print '<tr><td class="titlefield">'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1188  print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
1189  print '</td></tr>';
1190  }
1191 
1192  if (! empty($conf->commande->enabled) || ! empty($conf->expedition->enabled))
1193  {
1194  print '<tr><td>';
1195  if (! empty($conf->expedition->enabled)) { print $langs->trans("ContactForOrdersOrShipments"); }
1196  else print $langs->trans("ContactForOrders");
1197  print '</td><td colspan="3">';
1198  $none=$langs->trans("NoContactForAnyOrder");
1199  if (! empty($conf->expedition->enabled)) { $none=$langs->trans("NoContactForAnyOrderOrShipments"); }
1200  print $object->ref_commande?$object->ref_commande:$none;
1201  print '</td></tr>';
1202  }
1203 
1204  if (! empty($conf->contrat->enabled))
1205  {
1206  print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1207  print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
1208  print '</td></tr>';
1209  }
1210 
1211  if (! empty($conf->facture->enabled))
1212  {
1213  print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1214  print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
1215  print '</td></tr>';
1216  }
1217 
1218  print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1219  if ($object->user_id)
1220  {
1221  $dolibarr_user=new User($db);
1222  $result=$dolibarr_user->fetch($object->user_id);
1223  print $dolibarr_user->getLoginUrl(1);
1224  }
1225  else print $langs->trans("NoDolibarrAccess");
1226  print '</td></tr>';
1227 
1228  print '<tr><td>';
1229  print $langs->trans("VCard").'</td><td colspan="3">';
1230  print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'">';
1231  print img_picto($langs->trans("Download"),'vcard.png').' ';
1232  print $langs->trans("Download");
1233  print '</a>';
1234  print '</td></tr>';
1235 
1236  print "</table>";
1237 
1238  print '</div></div></div>';
1239  print '<div style="clear:both"></div>';
1240 
1241  print dol_fiche_end();
1242 
1243  // Barre d'actions
1244  print '<div class="tabsAction">';
1245 
1246  $parameters=array();
1247  $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
1248  if (empty($reshook))
1249  {
1250  if ($user->rights->societe->contact->creer)
1251  {
1252  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit">'.$langs->trans('Modify').'</a>';
1253  }
1254 
1255  if (! $object->user_id && $user->rights->user->user->creer)
1256  {
1257  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a>';
1258  }
1259 
1260  // Activer
1261  if ($object->statut == 0 && $user->rights->societe->contact->creer)
1262  {
1263  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable">'.$langs->trans("Reactivate").'</a>';
1264  }
1265  // Desactiver
1266  if ($object->statut == 1 && $user->rights->societe->contact->creer)
1267  {
1268  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'">'.$langs->trans("DisableUser").'</a>';
1269  }
1270 
1271  // Delete
1272  if ($user->rights->societe->contact->supprimer)
1273  {
1274  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete'.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.$langs->trans('Delete').'</a>';
1275  }
1276  }
1277 
1278  print "</div>";
1279  }
1280 }
1281 
1282 
1283 llxFooter();
1284 
1285 $db->close();
image_format_supported($file)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:38
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:996
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
Class to manage canvas.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage contact/addresses.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
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:1273
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1139
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
getRandomPassword($generic=false)
Return a generated password using default module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage a WYSIWYG editor.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114