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