dolibarr 24.0.2
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.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-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
13 * Copyright (C) 2020-2026 Open-Dsi <support@open-dsi.fr>
14 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
37// Load Dolibarr environment
38require '../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
49require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
56require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
57require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
58require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
59require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
60
61// Load translation files required by the page
62$langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
63
64$error = 0;
65$errors = array();
66
67// Get parameters
68$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
69$confirm = GETPOST('confirm', 'alpha');
70$backtopage = GETPOST('backtopage', 'alpha');
71$cancel = GETPOST('cancel', 'alpha');
72$id = GETPOSTINT('id');
73$socid = GETPOSTINT('socid');
74
75// Initialize a technical object
76$object = new Contact($db);
77
78// fetch optionals attributes and labels
79$extrafields->fetch_name_optionals_label($object->table_element);
80
81$socialnetworks = getArrayOfSocialNetworks();
82
83// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
84$object->getCanvas($id);
85$objcanvas = null;
86$canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
87if (!empty($canvas)) {
88 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
89 $objcanvas = new Canvas($db, $action);
90 $objcanvas->getCanvas('contact', 'contactcard', $canvas);
91}
92
93// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
94$hookmanager->initHooks(array('contactcard', 'globalcard'));
95
96if ($id > 0) {
97 $object->fetch($id);
98 $object->info($id);
99}
100
101if (!($object->id > 0) && $action == 'view') {
102 $langs->load("errors");
103 print($langs->trans('ErrorRecordNotFound'));
104 exit;
105}
106
107$triggermodname = 'CONTACT_MODIFY';
108$permissiontoadd = $user->hasRight('societe', 'contact', 'creer');
109$permissiontoeditextra = $permissiontoadd;
110if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
111 // For action 'update_extras', is there a specific permission set for the attribute to update
112 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
113}
114
115// Security check
116if ($user->socid) {
117 $socid = $user->socid;
118}
119if ($object->priv && $object->user_creation_id != $user->id) {
121}
122$result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
123
124
125/*
126 * Actions
127 */
128
129$parameters = array('id' => $id, 'objcanvas' => $objcanvas);
130$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
131if ($reshook < 0) {
132 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
133}
134
135if (empty($reshook)) {
136 $backurlforlist = DOL_URL_ROOT.'/contact/list.php';
137
138 if (empty($backtopage) || ($cancel && empty($id))) {
139 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
140 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
141 $backtopage = $backurlforlist;
142 } else {
143 $backtopage = DOL_URL_ROOT.'/contact/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
144 }
145 }
146 }
147
148 if ($cancel) {
149 if (!empty($backtopageforcancel)) {
150 header("Location: ".$backtopageforcancel);
151 exit;
152 } elseif (!empty($backtopage)) {
153 header("Location: ".$backtopage);
154 exit;
155 }
156 $action = '';
157 }
158
159 // Create user from contact
160 if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->hasRight('user', 'user', 'creer')) {
161 // Recuperation contact actuel
162 $result = $object->fetch($id);
163
164 if ($result > 0) {
165 $db->begin();
166
167 // Creation user
168 $nuser = new User($db);
169 $result = $nuser->create_from_contact($object, GETPOST("login")); // Do not use GETPOST(alpha)
170
171 if ($result > 0) {
172 $result2 = $nuser->setPassword($user, GETPOST("password"), 0, 0, 1); // Do not use GETPOST(alpha)
173 if (is_int($result2) && $result2 < 0) {
174 $error = $nuser->error;
175 $errors = $nuser->errors;
176 $db->rollback();
177 } else {
178 $db->commit();
179 }
180 } else {
181 $error = $nuser->error;
182 $errors = $nuser->errors;
183 $db->rollback();
184 }
185 if ($error) {
186 setEventMessage($langs->trans('ImpossibleToCreateUserFromContact').' : '.$nuser->errorsToString(), 'errors');
187 }
188 } else {
189 $error = $object->error;
190 $errors = $object->errors;
191 }
192 }
193
194
195 // Confirmation deactivation
196 if ($action == 'disable' && $permissiontoadd) {
197 $object->fetch($id);
198 if ($object->setstatus(0) < 0) {
199 setEventMessages($object->error, $object->errors, 'errors');
200 } else {
201 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
202 exit;
203 }
204 }
205
206 // Confirmation activation
207 if ($action == 'enable' && $permissiontoadd) {
208 $object->fetch($id);
209 if ($object->setstatus(1) < 0) {
210 setEventMessages($object->error, $object->errors, 'errors');
211 } else {
212 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
213 exit;
214 }
215 }
216
217 // Add contact
218 if ($action == 'add' && $permissiontoadd) {
219 $db->begin();
220
221 if ($canvas) {
222 $object->canvas = $canvas;
223 }
224
225 $object->entity = ((GETPOSTISSET('entity') && GETPOST('entity') != '') ? GETPOSTINT('entity') : $conf->entity);
226 $object->socid = $socid;
227 $object->lastname = (string) GETPOST("lastname", 'alpha');
228 $object->firstname = (string) GETPOST("firstname", 'alpha');
229 if (GETPOSTISSET("civility_code")) {
230 $object->civility_code = (string) GETPOST("civility_code", 'alpha');
231 }
232 $object->poste = (string) GETPOST("poste", 'alpha');
233 $object->address = (string) GETPOST("address", 'alpha');
234 $object->zip = (string) GETPOST("zipcode", 'alpha');
235 $object->town = (string) GETPOST("town", 'alpha');
236 $object->country_id = GETPOSTINT("country_id");
237 $object->state_id = GETPOSTINT("state_id");
238 $object->socialnetworks = array();
239 if (isModEnabled('socialnetworks')) {
240 foreach ($socialnetworks as $key => $value) {
241 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
242 $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
243 }
244 }
245 }
246 $object->email = (string) GETPOST('email', 'email');
247 $object->no_email = GETPOSTINT("no_email");
248 $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
249 $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
250 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
251 $object->fax = (string) GETPOST("fax", 'alpha');
252 $object->priv = GETPOSTINT("priv");
253 $object->note_public = (string) GETPOST("note_public", 'restricthtml');
254 $object->note_private = (string) GETPOST("note_private", 'restricthtml');
255 $object->roles = GETPOST("roles", 'array'); // Suppose this is proper array, ideally verified @phpstan-ignore assign.propertyType
256
257 $object->status = 1; //Default status to Actif
258 $object->statut = 1; //Default status to Actif
259
260 // Note: Correct date should be completed with location to have exact GM time of birth.
261 $object->birthday = dol_mktime(0, 0, 0, GETPOSTINT("birthdaymonth"), GETPOSTINT("birthdayday"), GETPOSTINT("birthdayyear"));
262 $object->birthday_alert = (GETPOST('birthday_alert', 'alpha') == "on" ? 1 : 0);
263
264 //Default language
265 $object->default_lang = GETPOST('default_lang');
266
267 // Fill array 'array_options' with data from add form
268 $ret = $extrafields->setOptionalsFromPost(null, $object);
269 if ($ret < 0) {
270 $error++;
271 $action = 'create';
272 }
273
274 if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && $object->no_email == -1 && !empty($object->email)) {
275 $error++;
276 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
277 $action = 'create';
278 }
279
280 if (!empty($object->email) && !isValidEmail($object->email)) {
281 $langs->load("errors");
282 $error++;
283 $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
284 $action = 'create';
285 }
286
287 if (empty($object->lastname)) {
288 $error++;
289 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
290 $action = 'create';
291 }
292
293 if (empty($error)) {
294 $id = $object->create($user);
295 if ($id <= 0) {
296 $error++;
297 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
298 $action = 'create';
299 }
300 }
301
302 if (empty($error)) {
303 // Categories association
304 $contcats = GETPOST('contcats', 'array');
305 if (count($contcats) > 0) {
306 $result = $object->setCategories($contcats);
307 if ($result <= 0) {
308 $error++;
309 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
310 $action = 'create';
311 }
312 }
313 }
314
315 if (empty($error) && isModEnabled('mailing') && !empty($object->email)) {
316 // Add mass emailing flag into table mailing_unsubscribe
317 $result = $object->setNoEmail($object->no_email);
318 if ($result < 0) {
319 $error++;
320 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
321 $action = 'create';
322 }
323 }
324
325 if (empty($error) && $id > 0) {
326 $db->commit();
327 if (!empty($backtopage)) {
328 $url = str_replace('__ID__', (string) $id, $backtopage);
329 } else {
330 $url = 'card.php?id='.$id;
331 }
332 header("Location: ".$url);
333 exit;
334 } else {
335 $db->rollback();
336 }
337 }
338
339 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'contact', 'supprimer')) {
340 $result = $object->fetch($id);
341 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
342
343 $result = $object->delete($user);
344 if ($result > 0) {
345 setEventMessages("RecordDeleted", null, 'mesgs');
346 if ($backurlforlist) {
347 header("Location: ".$backurlforlist);
348 exit;
349 } else {
350 header("Location: ".DOL_URL_ROOT.'/contact/list.php');
351 exit;
352 }
353 } else {
354 setEventMessages($object->error, $object->errors, 'errors');
355 }
356 }
357
358 if ($action == 'update' && empty($cancel) && $permissiontoadd) {
359 if (!GETPOST("lastname", 'alpha')) {
360 $error++;
361 $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
362 $action = 'edit';
363 }
364
365 if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && GETPOSTINT("no_email") == -1 && !empty(GETPOST('email', 'email'))) {
366 $error++;
367 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
368 $action = 'edit';
369 }
370
371 if (!empty(GETPOST('email', 'email')) && !isValidEmail(GETPOST('email', 'email'))) {
372 $langs->load("errors");
373 $error++;
374 $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
375 $action = 'edit';
376 }
377
378 if (!$error) {
379 $contactid = GETPOSTINT("contactid");
380 $object->fetch($contactid);
381 $object->fetchRoles();
382
383 // Photo save
384 $dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/contact/".$object->id."/photos";
385 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
386 if (GETPOST('deletephoto') && $object->photo) {
387 $fileimg = $dir.'/'.$object->photo;
388 $dirthumbs = $dir.'/thumbs';
389 dol_delete_file($fileimg);
390 dol_delete_dir_recursive($dirthumbs);
391 $object->photo = '';
392 }
393 if ($file_OK) {
394 if (image_format_supported($_FILES['photo']['name']) > 0) {
395 dol_mkdir($dir);
396
397 if (@is_dir($dir)) {
398 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
399 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
400
401 // Note: $result is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
402 if (!is_numeric($result) || $result <= 0) {
403 $errors[] = "ErrorFailedToSaveFile";
404 } else {
405 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
406
407 // Create thumbs
408 $object->addThumbs($newfile);
409 }
410 }
411 } else {
412 $errors[] = "ErrorBadImageFormat";
413 }
414 } else {
415 switch ($_FILES['photo']['error']) {
416 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
417 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
418 $errors[] = "ErrorFileSizeTooLarge";
419 break;
420 case 3: //uploaded file was only partially uploaded
421 $errors[] = "ErrorFilePartiallyUploaded";
422 break;
423 }
424 }
425
426 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
427
428 $object->socid = $socid;
429 $object->lastname = (string) GETPOST("lastname", 'alpha');
430 $object->firstname = (string) GETPOST("firstname", 'alpha');
431 if (GETPOSTISSET("civility_code")) {
432 $object->civility_code = (string) GETPOST("civility_code", 'alpha');
433 }
434 $object->poste = (string) GETPOST("poste", 'alpha');
435
436 $object->address = (string) GETPOST("address", 'alpha');
437 $object->zip = (string) GETPOST("zipcode", 'alpha');
438 $object->town = (string) GETPOST("town", 'alpha');
439 $object->state_id = GETPOSTINT("state_id");
440 $object->country_id = GETPOSTINT("country_id");
441
442 $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
443 $object->no_email = GETPOSTINT("no_email");
444 $object->socialnetworks = array();
445 if (isModEnabled('socialnetworks')) {
446 foreach ($socialnetworks as $key => $value) {
447 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
448 $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
449 }
450 }
451 }
452 $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
453 $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
454 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
455 $object->fax = (string) GETPOST("fax", 'alpha');
456 $object->priv = GETPOSTINT("priv");
457 $object->note_public = (string) GETPOST("note_public", 'restricthtml');
458 $object->note_private = (string) GETPOST("note_private", 'restricthtml');
459
460 // Suppose this is proper array, ideally verified @phpstan-ignore-next-line assign.propertyType
461 $object->roles = GETPOST("roles", 'array'); // Note GETPOSTISSET("role") is null when combo is empty
462
463 //Default language
464 $object->default_lang = GETPOST('default_lang');
465
466 // Fill array 'array_options' with data from add form
467 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
468 if ($ret < 0) {
469 $error++;
470 }
471
472 if (!$error) {
473 $result = $object->update($contactid, $user);
474
475 if ($result > 0) {
476 // Categories association
477 $categories = GETPOST('contcats', 'array');
478 $object->setCategories($categories);
479
480 // Update mass emailing flag into table mailing_unsubscribe
481 if (GETPOSTISSET('no_email') && $object->email) {
482 $no_email = GETPOSTINT('no_email');
483 $result = $object->setNoEmail($no_email);
484 if ($result < 0) {
485 $error++;
486 setEventMessages($object->error, $object->errors, 'errors');
487 }
488 }
489 } else {
490 $error++;
491 setEventMessages($object->error, $object->errors, 'errors');
492 }
493 }
494 }
495
496 if (!$error && empty($errors)) {
497 if (!empty($backtopage)) {
498 header("Location: ".$backtopage);
499 exit;
500 }
501 $action = 'view';
502 } else {
503 $action = 'edit';
504 }
505 }
506
507 if ($action == 'setprospectcontactlevel' && $permissiontoadd) {
508 $object->fetch($id);
509 $object->fk_prospectlevel = GETPOST('prospect_contact_level_id', 'alpha');
510 $result = $object->update($object->id, $user);
511 if ($result < 0) {
512 setEventMessages($object->error, $object->errors, 'errors');
513 }
514 }
515
516 // set communication status
517 if ($action == 'setstcomm' && $permissiontoadd) {
518 $object->fetch($id);
519 $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
520 $result = $object->update($object->id, $user);
521 if ($result < 0) {
522 setEventMessages($object->error, $object->errors, 'errors');
523 }
524 }
525
526 // Update extrafields
527 if ($action == 'update_extras' && $permissiontoeditextra) {
528 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
529
530 $attribute_name = GETPOST('attribute', 'aZ09');
531
532 // Fill array 'array_options' with data from update form
533 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
534 if ($ret < 0) {
535 $error++;
536 }
537
538 if (!$error) {
539 $result = $object->updateExtraField($attribute_name, 'CONTACT_MODIFY');
540 if ($result < 0) {
541 setEventMessages($object->error, $object->errors, 'errors');
542 $error++;
543 }
544 }
545
546 if ($error) {
547 $action = 'edit_extras';
548 }
549 }
550
551 // Actions to send emails
552 $triggersendname = 'CONTACT_SENTBYMAIL';
553 $paramname = 'id';
554 $mode = 'emailfromcontact';
555 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
556}
557
558
559/*
560 * View
561 */
562
563$form = new Form($db);
564$formadmin = new FormAdmin($db);
565$formcompany = new FormCompany($db);
566
567$objsoc = new Societe($db);
568if ($socid > 0) {
569 $objsoc->fetch($socid);
570}
571
572$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
573if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
574 $title = $object->lastname;
575}
576if (empty($object->id)) {
577 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
578}
579$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
580
581llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card');
582
583$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
584
585if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
586 // -----------------------------------------
587 // When used with CANVAS
588 // -----------------------------------------
589 if (empty($object->error) && $id) {
590 $object = new Contact($db);
591 $result = $object->fetch($id);
592 if ($result <= 0) {
593 dol_print_error(null, $object->error);
594 }
595 }
596 $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
597 $objcanvas->display_canvas($action); // Show template
598} else {
599 // -----------------------------------------
600 // When used in standard mode
601 // -----------------------------------------
602
603 // Confirm deleting contact
604 if ($user->hasRight('societe', 'contact', 'supprimer')) {
605 if ($action == 'delete') {
606 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
607 }
608 }
609
610 /*
611 * Onglets
612 */
613 $head = array();
614 if ($id > 0) {
615 // Si edition contact deja existent
616 $object = new Contact($db);
617 $res = $object->fetch($id, $user);
618 if ($res < 0) {
619 setEventMessages($object->error, $object->errors, 'errors');
620 }
621
622 $object->fetchRoles();
623
624 // Show tabs
625 $head = contact_prepare_head($object);
626 }
627
628 if ($user->hasRight('societe', 'contact', 'creer')) {
629 if ($action == 'create') {
630 /*
631 * Card in create mode
632 */
633 $object->canvas = $canvas;
634
635 $object->state_id = GETPOSTINT("state_id");
636
637 // We set country_id, country_code and label for the selected country
638 $object->country_id = GETPOST("country_id") ? GETPOSTINT("country_id") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
639 if ($object->country_id) {
640 $tmparray = getCountry($object->country_id, 'all');
641 $object->country_code = $tmparray['code'];
642 $object->country = $tmparray['label'];
643 }
644
645 $linkback = '';
646
647 print load_fiche_titre($title, $linkback, 'address');
648
649 // Show errors
650 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
651
652 if ($conf->use_javascript_ajax) {
653 print "\n".'<script type="text/javascript">'."\n";
654 print 'jQuery(document).ready(function () {
655 jQuery("#selectcountry_id").change(function() {
656 document.formsoc.action.value="create";
657 document.formsoc.submit();
658 });
659
660 $("#copyaddressfromsoc").click(function() {
661 $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
662 $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
663 $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
664 console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
665 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
666 /* set country at end because it will trigger page refresh */
667 console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
668 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
669 });
670 })'."\n";
671 print '</script>'."\n";
672 }
673
674 print '<form method="post" name="formsoc" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
675 print '<input type="hidden" name="token" value="'.newToken().'">';
676 print '<input type="hidden" name="action" value="add">';
677 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
678 if (!empty($objsoc)) {
679 print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
680 }
681
682 print dol_get_fiche_head($head, 'card', '', 0, '');
683
684 print '<table class="border centpercent">';
685
686 // Name
687 print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
688 print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname", 'alpha') ? GETPOST("lastname", 'alpha') : $object->lastname).'" autofocus="autofocus"></td>';
689 print '</tr>';
690
691 // Firstname
692 print '<tr>';
693 print '<td><label for="firstname">';
694 print $form->textwithpicto($langs->trans("Firstname"), $langs->trans("KeepEmptyIfGenericAddress")).'</label></td>';
695 print '<td colspan="3"><input name="firstname" id="firstname"type="text" class="minwidth200" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname", 'alpha') ? GETPOST("firstname", 'alpha') : $object->firstname).'"></td>';
696 print '</tr>';
697
698 // Company
699 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
700 if ($socid > 0) {
701 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
702 print '<td colspan="3" class="maxwidthonsmartphone">';
703 print $objsoc->getNomUrl(1, 'contact');
704 print '</td>';
705 print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
706 print '</td></tr>';
707 } else {
708 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
709 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($socid, 'socid', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
710 print '</td></tr>';
711 }
712 }
713
714 // Civility
715 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
716 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
717 print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
718 print '</td></tr>';
719 }
720
721 // Job position
722 print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
723 print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ? GETPOST("poste", 'alphanohtml') : $object->poste).'"></td>';
724
725 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
726 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
727
728 $colspan = 3;
729 if ($conf->use_javascript_ajax && $socid > 0) {
730 $colspan = 2;
731 }
732
733 // Address
734 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->address)) == 0) {
735 $object->address = $objsoc->address; // Predefined with third party
736 }
737 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
738 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>';
739
740 if ($conf->use_javascript_ajax && $socid > 0) {
741 $rowspan = 3;
742 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
743 $rowspan++;
744 }
745
746 print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
747 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
748 print '</td>';
749 }
750 print '</tr>';
751
752 // Zip / Town
753 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->zip)) == 0) {
754 $object->zip = $objsoc->zip; // Predefined with third party
755 }
756 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->town)) == 0) {
757 $object->town = $objsoc->town; // Predefined with third party
758 }
759 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
760 print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
761 print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
762 print '</td></tr>';
763
764 // Country
765 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
766 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
767 print $form->select_country((GETPOSTISSET("country_id") ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
768 if ($user->admin) {
769 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
770 }
771 print '</td></tr>';
772
773 // State
774 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
775 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
776 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
777 } else {
778 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
779 }
780
781 if ($object->country_id) {
782 print img_picto('', 'state', 'class="pictofixedwidth"');
783 print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
784 } else {
785 print $countrynotdefined;
786 }
787 print '</td></tr>';
788 }
789
790 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->phone_pro)) == 0) {
791 $object->phone_pro = $objsoc->phone; // Predefined with third party
792 }
793 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->fax)) == 0) {
794 $object->fax = $objsoc->fax; // Predefined with third party
795 }
796
797 // Phone / Fax
798 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
799 print '<td>';
800 print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
801 print '</td>';
802 if ($conf->browser->layout == 'phone') {
803 print '</tr><tr>';
804 }
805
806 print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
807 print '<td>';
808 print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
809 print '</td>';
810 print '</tr>';
811
812 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
813 print '<td>';
814 print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150 widthcentpercentminusx');
815 print '</td>';
816 if ($conf->browser->layout == 'phone') {
817 print '</tr><tr>';
818 }
819
820 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
821 print '<td>';
822 print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150 widthcentpercentminusx');
823 print '</td>';
824 print '</tr>';
825
826 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->email)) == 0) {
827 $object->email = $objsoc->email; // Predefined with third party
828 }
829
830 // Email
831 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
832 print '<td>';
833 print img_picto('', 'object_email', 'class="pictofixedwidth"');
834 print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
835 print '</tr>';
836
837 // Unsubscribe
838 if (isModEnabled('mailing')) {
839 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
840 print "\n".'<script type="text/javascript">'."\n";
841 print '$(document).ready(function () {
842 $("#email").keyup(function() {
843 if ($(this).val()!="") {
844 $(".noemail").addClass("fieldrequired");
845 } else {
846 $(".noemail").removeClass("fieldrequired");
847 }
848 });
849 })'."\n";
850 print '</script>'."\n";
851 }
852 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
853 $result = $object->getNoEmail();
854 if ($result < 0) {
855 setEventMessages($object->error, $object->errors, 'errors');
856 }
857 }
858 print '<tr>';
859 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
860 print '<td>';
861 // Default value is in MAILING_CONTACT_DEFAULT_BULK_STATUS that you can modify in setup of module emailing
862 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS')), 1, false, (int) (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2));
863 print '</td>';
864 print '</tr>';
865 }
866
867 // Social network
868 if (isModEnabled('socialnetworks')) {
869 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
870
871 $object->showSocialNetwork($socialnetworks, $colspan);
872
873 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
874 }
875
876 // Visibility
877 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
878 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
879 print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ? GETPOST("priv", 'alpha') : $object->priv), 0);
880 print '</td></tr>';
881
882 // Default language
883 if (getDolGlobalInt('MAIN_MULTILANGS')) {
884 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
885 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, array(), 1, 0, 0, 'maxwidth200 widthcentpercentminusx');
886 print '</td>';
887 print '</tr>';
888 }
889
890 // Categories
891 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
892 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
893 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', 'parent', 64, 0, 3);
894 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), 0, 0, '', 0, '90%');
895 print "</td></tr>";
896 }
897
898 // Contact by default
899 if ($socid > 0) {
900 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
901 print '<td colspan="3">';
902 $contactType = $object->listeTypeContacts('external', 0, 1);
903 print img_picto('', 'contact', 'class="pictofixedwidth"').$form->multiselectarray('roles', $contactType, array(), 0, 0, '', 0, '90%');
904 print '</td></tr>';
905 }
906
907 // Other attributes
908 $parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
909 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
910
911 print "</table><br>";
912
913 print '<hr style="margin-bottom: 20px">';
914
915 // Add personal information
916 print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
917
918 print '<table class="border centpercent">';
919
920 // Date To Birth
921 print '<tr><td class="titlefieldcreate"><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td colspan="3">';
922 $form = new Form($db);
923 if ($object->birthday) {
924 print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
925 } else {
926 print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
927 }
928
929 print ' &nbsp; <label for="birthday_alert">'.$langs->trans("Alert").'</label> ';
930 if (!empty($object->birthday_alert)) {
931 print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
932 } else {
933 print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
934 }
935 print '</td>';
936 print '</tr>';
937
938 print "</table>";
939
940 print dol_get_fiche_end();
941
942 print $form->buttonsSaveCancel("Add");
943
944 print "</form>";
945 } elseif ($action == 'edit' && !empty($id)) {
946 /*
947 * Card in edit mode
948 */
949
950 // We set country_id, and country_code label of the chosen country
951 if (GETPOSTISSET("country_id") || $object->country_id) {
952 $tmparray = getCountry($object->country_id, 'all');
953 $object->country_code = $tmparray['code'];
954 $object->country = $tmparray['label'];
955 }
956
957 $objsoc = new Societe($db);
958 $objsoc->fetch($object->socid);
959
960 // Show errors
961 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
962
963 if ($conf->use_javascript_ajax) {
964 print "\n".'<script type="text/javascript">'."\n";
965 print 'jQuery(document).ready(function () {
966 jQuery("#selectcountry_id").change(function() {
967 document.formsoc.action.value="edit";
968 document.formsoc.submit();
969 });
970
971 $("#copyaddressfromsoc").click(function() {
972 $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
973 $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
974 $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
975 console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
976 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
977 /* set country at end because it will trigger page refresh */
978 console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
979 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
980 });
981 })'."\n";
982 print '</script>'."\n";
983 }
984
985 print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
986 print '<input type="hidden" name="token" value="'.newToken().'">';
987 print '<input type="hidden" name="id" value="'.$id.'">';
988 print '<input type="hidden" name="action" value="update">';
989 print '<input type="hidden" name="contactid" value="'.$object->id.'">';
990 if (!empty($backtopage)) {
991 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
992 }
993
994 print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
995
996 print '<table class="border centpercent">';
997
998 // Ref/ID
999 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
1000 print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
1001 print $object->ref;
1002 print '</td></tr>';
1003 }
1004
1005 // Lastname
1006 print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
1007 print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("lastname") ? GETPOST("lastname") : $object->lastname).'" autofocus="autofocus"></td>';
1008 print '</tr>';
1009 print '<tr>';
1010 // Firstname
1011 print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
1012 print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
1013 print '</tr>';
1014
1015 // Company
1016 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1017 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
1018 print '<td colspan="3" class="maxwidthonsmartphone">';
1019 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(GETPOSTINT('socid') ? GETPOSTINT('socid') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
1020 print '</td>';
1021 print '</tr>';
1022 }
1023
1024 // Civility
1025 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
1026 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
1027 print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
1028 print '</td></tr>';
1029 }
1030
1031 // Job position
1032 print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
1033 print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ? GETPOST("poste", 'alphanohtml') : $object->poste).'"></td></tr>';
1034
1035 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1036 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1037
1038 // Address
1039 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
1040 print '<td colspan="3">';
1041 print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
1042 print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
1043 print '</div><div class="paddingrightonly valignmiddle inline-block">';
1044 if (!empty($conf->use_javascript_ajax)) {
1045 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
1046 }
1047 print '</div>';
1048 print '</td>';
1049
1050 // Zip / Town
1051 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1052 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
1053 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1054 print '</td></tr>';
1055
1056 // Country
1057 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1058 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
1059 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
1060 if ($user->admin) {
1061 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1062 }
1063 print '</td></tr>';
1064
1065 // State
1066 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1067 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1068 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1069 } else {
1070 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1071 }
1072
1073 print img_picto('', 'state', 'class="pictofixedwidth"');
1074 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
1075 print '</td></tr>';
1076 }
1077
1078 // Phone
1079 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
1080 print '<td>';
1081 print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150', 80);
1082 print '</td>';
1083 if ($conf->browser->layout == 'phone') {
1084 print '</tr><tr>';
1085 }
1086
1087 print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
1088 print '<td>';
1089 print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150', 80);
1090 print '</td></tr>';
1091
1092 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
1093 print '<td>';
1094 print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150', 80);
1095 print '</td>';
1096 if ($conf->browser->layout == 'phone') {
1097 print '</tr><tr>';
1098 }
1099
1100 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
1101 print '<td>';
1102 print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150', 80);
1103 print '</td></tr>';
1104
1105 // EMail
1106 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (int) (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';
1107 print '<td>';
1108 print img_picto('', 'object_email', 'class="pictofixedwidth"');
1109 print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
1110 if (isModEnabled('mailing')) {
1111 if ($conf->browser->layout == 'phone') {
1112 print '</tr><tr>';
1113 }
1114 $langs->load("mails");
1115 print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
1116 print '<td>'.$object->getNbOfEMailings().'</td>';
1117 } else {
1118 print '<td colspan="2"></td>';
1119 }
1120 print '</tr>';
1121
1122 // Unsubscribe
1123 if (isModEnabled('mailing')) {
1124 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1125 print "\n".'<script type="text/javascript">'."\n";
1126
1127 print '
1128 jQuery(document).ready(function () {
1129 function init_check_no_email(input) {
1130 if (input.val()!="") {
1131 $(".noemail").addClass("fieldrequired");
1132 } else {
1133 $(".noemail").removeClass("fieldrequired");
1134 }
1135 }
1136 $("#email").keyup(function() {
1137 init_check_no_email($(this));
1138 });
1139 init_check_no_email($("#email"));
1140 })'."\n";
1141 print '</script>'."\n";
1142 }
1143 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1144 $result = $object->getNoEmail();
1145 if ($result < 0) {
1146 setEventMessages($object->error, $object->errors, 'errors');
1147 }
1148 }
1149 print '<tr>';
1150 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1151 print '<td>';
1152 $useempty = (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
1153 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, false, (int) $useempty);
1154 print '</td>';
1155 print '</tr>';
1156 }
1157
1158 // Social network
1159 if (isModEnabled('socialnetworks')) {
1160 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1161
1162 $object->showSocialNetwork($socialnetworks, $colspan);
1163
1164 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1165 }
1166
1167 // Visibility
1168 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
1169 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
1170 print $form->selectarray('priv', $selectarray, $object->priv, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth150');
1171 print '</td></tr>';
1172
1173 // Default language
1174 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1175 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1176 print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, array(), 1, 0, 0, 'maxwidth200onsmartphone');
1177 print '</td>';
1178 print '</tr>';
1179 }
1180
1181 // Note Public
1182 print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
1183 $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1184 print $doleditor->Create(1);
1185 print '</td></tr>';
1186
1187 // Note Private
1188 print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
1189 $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1190 print $doleditor->Create(1);
1191 print '</td></tr>';
1192
1193 // Status
1194 print '<tr><td>'.$langs->trans("Status").'</td>';
1195 print '<td colspan="3">';
1196 print $object->getLibStatut(4);
1197 print '</td></tr>';
1198
1199 // Categories
1200 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1201 $arrayselected = array();
1202 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
1203 print '<td colspan="3">';
1204 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', '', 64, 0, 3);
1205 $c = new Categorie($db);
1206 $cats = $c->containing($object->id, 'contact');
1207 foreach ($cats as $cat) {
1208 $arrayselected[] = $cat->id;
1209 }
1210 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, 0, 0, '', 0, '90%');
1211 print "</td></tr>";
1212 }
1213
1214 // Contact by default
1215 if (!empty($object->socid)) {
1216 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
1217 print '<td colspan="3">';
1218 print img_picto('', 'category', 'class="pictofixedwidth"').$formcompany->showRoles("roles", $object, 'edit', $object->roles, '');
1219 print '</td></tr>';
1220 }
1221
1222 // Other attributes
1223 $parameters = array('colspan' => ' colspan="3"', 'cols' => '3', 'colspanvalue' => '3');
1224 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1225
1226 $object->load_ref_elements();
1227
1228 if (isModEnabled('order')) {
1229 print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
1230 print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
1231 print '</td></tr>';
1232 }
1233
1234 if (isModEnabled("propal")) {
1235 print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1236 print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
1237 print '</td></tr>';
1238 }
1239
1240 if (isModEnabled('contract')) {
1241 print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1242 print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
1243 print '</td></tr>';
1244 }
1245
1246 if (isModEnabled('invoice')) {
1247 print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1248 print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
1249 print '</td></tr>';
1250 }
1251
1252 // Login Dolibarr
1253 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1254 if ($object->user_id) {
1255 $dolibarr_user = new User($db);
1256 $result = $dolibarr_user->fetch($object->user_id);
1257 print $dolibarr_user->getLoginUrl(1);
1258 } else {
1259 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1260 }
1261 print '</td></tr>';
1262
1263 // Photo
1264 print '<tr>';
1265 print '<td>'.$langs->trans("PhotoFile").'</td>';
1266 print '<td colspan="3">';
1267 if ($object->photo) {
1268 print $form->showphoto('contact', $object);
1269 print "<br>\n";
1270 }
1271 print '<table class="nobordernopadding">';
1272 if ($object->photo) {
1273 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1274 }
1275 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1276 print '<tr><td>';
1277 $maxfilesizearray = getMaxFileSizeArray();
1278 $maxmin = $maxfilesizearray['maxmin'];
1279 if ($maxmin > 0) {
1280 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1281 }
1282 print '<input type="file" class="flat maxwidth200" name="photo" id="photoinput">';
1283 print '</td></tr>';
1284 print '</table>';
1285
1286 print '</td>';
1287 print '</tr>';
1288
1289 print '</table>';
1290
1291 print dol_get_fiche_end();
1292
1293 print $form->buttonsSaveCancel();
1294
1295 print "</form>";
1296 }
1297 }
1298
1299 // Select mail models is same action as presend
1300 if (GETPOST('modelselected', 'alpha')) {
1301 $action = 'presend';
1302 }
1303
1304 // View mode
1305 if (!empty($id) && $action != 'edit' && $action != 'create') {
1306 $objsoc = new Societe($db);
1307
1308 // Show errors
1309 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
1310
1311 print dol_get_fiche_head($head, 'card', $title, -1, 'contact');
1312
1313 if ($action == 'create_user') {
1314 // Full firstname and lastname separated with a dot : firstname.lastname
1315 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1316 $login = dol_buildlogin($object->lastname, $object->firstname);
1317
1318 $generated_password = '';
1319 if (empty($ldap_sid)) { // TODO ldap_sid ?
1320 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1321 $generated_password = getRandomPassword(false);
1322 }
1323 $password = $generated_password;
1324
1325 // Create a form array
1326 $formquestion = array(
1327 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
1328 array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
1329 //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')))
1330 );
1331 $text = $langs->trans("ConfirmCreateContact").'<br>';
1332 if (isModEnabled("societe")) {
1333 if ($object->socid > 0) {
1334 $text .= $langs->trans("UserWillBeExternalUser");
1335 } else {
1336 $text .= $langs->trans("UserWillBeInternalUser");
1337 }
1338 }
1339 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1340 }
1341
1342 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1343
1344 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
1345 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
1346 $morehtmlref .= '</a>';
1347
1348 $morehtmlref .= '<div class="refidno">';
1349 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1350 $objsoc->fetch($object->socid);
1351 // Thirdparty
1352 if ($objsoc->id > 0) {
1353 $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
1354 } else {
1355 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
1356 }
1357 }
1358 $morehtmlref .= '</div>';
1359
1360 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1361
1362
1363 print '<div class="fichecenter">';
1364 print '<div class="fichehalfleft">';
1365
1366 print '<div class="underbanner clearboth"></div>';
1367 print '<table class="border tableforfield" width="100%">';
1368
1369 // Civility
1370 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
1371 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
1372 print $object->getCivilityLabel();
1373 print '</td></tr>';
1374 }
1375
1376 // Job / position
1377 print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
1378
1379 // Email
1380 if (isModEnabled('mailing')) {
1381 $langs->load("mails");
1382 print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
1383 print '<td><a class="badge badge-info" href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
1384 }
1385
1386 // Unsubscribe opt-out
1387 if (isModEnabled('mailing')) {
1388 $result = $object->getNoEmail();
1389 if ($result < 0) {
1390 setEventMessages($object->error, $object->errors, 'errors');
1391 }
1392 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
1393 if ($object->email) {
1394 print yn($object->no_email);
1395 } else {
1396 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
1397 }
1398 print '</td></tr>';
1399 }
1400
1401 // Default language
1402 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1403 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1404 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1405 //$s=picto_from_langcode($object->default_lang);
1406 //print ($s?$s.' ':'');
1407 $langs->load("languages");
1408 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1409 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1410 print $labellang;
1411 print '</td></tr>';
1412 }
1413
1414 print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
1415 print $object->LibPubPriv($object->priv, 1);
1416 print '</td></tr>';
1417
1418 print '</table>';
1419 print '</div>';
1420
1421 $object->fetch_thirdparty();
1422
1423
1424 print '<div class="fichehalfright">';
1425
1426 print '<div class="underbanner clearboth"></div>';
1427 print '<table class="border tableforfield centpercent">';
1428
1429
1430 if (getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) {
1431 if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
1432 // Level of prospect
1433 print '<tr><td class="">';
1434 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
1435 print $langs->trans('ProspectLevel');
1436 print '<td>';
1437 if ($action != 'editlevel' && $user->hasRight('societe', 'contact', 'creer')) {
1438 print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
1439 }
1440 print '</tr></table>';
1441 print '</td><td>';
1442 if ($action == 'editlevel') {
1443 $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
1444 } else {
1445 print $object->getLibProspLevel();
1446 }
1447 print "</td>";
1448 print '</tr>';
1449
1450 // Status of prospection
1451 $object->loadCacheOfProspStatus();
1452 print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
1453 print ' &nbsp; &nbsp; ';
1454 print '<div class="floatright">';
1455 foreach ($object->cacheprospectstatus as $key => $val) {
1456 $titlealt = 'default';
1457 if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1458 $titlealt = $val['label'];
1459 }
1460 if ($object->stcomm_id != $val['id']) {
1461 print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&stcomm='.urlencode($val['code']).'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
1462 }
1463 }
1464 print '</div></td></tr>';
1465 }
1466 }
1467
1468 // Categories
1469 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1470 print '<tr><td class="">'.$langs->trans("Categories").'</td>';
1471 print '<td>';
1472 print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
1473 print '</td></tr>';
1474 }
1475
1476 // Contact by default for
1477 if (!empty($object->socid)) {
1478 print '<tr><td class="">'.$langs->trans("ContactByDefaultFor").'</td>';
1479 print '<td>';
1480 print $formcompany->showRoles("roles", $object, 'view', $object->roles, '');
1481 print '</td></tr>';
1482 }
1483
1484 // Other attributes
1485 $parameters = array('socid' => $socid);
1486 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1487
1488 $object->load_ref_elements();
1489
1490 if (isModEnabled("propal")) {
1491 print '<tr><td class="">'.$langs->trans("ContactForProposals").'</td><td>';
1492 print $object->ref_propal ? $object->ref_propal : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'<span>';
1493 print '</td></tr>';
1494 }
1495
1496 if (isModEnabled('order') || isModEnabled("shipping")) {
1497 print '<tr><td class="">';
1498 if (isModEnabled("shipping")) {
1499 print $langs->trans("ContactForOrdersOrShipments");
1500 } else {
1501 print $langs->trans("ContactForOrders");
1502 }
1503 print '</td><td>';
1504 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>';
1505 if (isModEnabled("shipping")) {
1506 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrderOrShipments").'</span>';
1507 }
1508 print $object->ref_commande ? $object->ref_commande : $none;
1509 print '</td></tr>';
1510 }
1511
1512 if (isModEnabled('contract')) {
1513 print '<tr><td class="">'.$langs->trans("ContactForContracts").'</td><td>';
1514 print $object->ref_contrat ? $object->ref_contrat : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>';
1515 print '</td></tr>';
1516 }
1517
1518 if (isModEnabled('invoice')) {
1519 print '<tr><td class="">'.$langs->trans("ContactForInvoices").'</td><td>';
1520 print $object->ref_facturation ? $object->ref_facturation : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>';
1521 print '</td></tr>';
1522 }
1523
1524 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td>';
1525 if ($object->user_id) {
1526 $dolibarr_user = new User($db);
1527 $result = $dolibarr_user->fetch($object->user_id);
1528 print $dolibarr_user->getLoginUrl(-1);
1529 } else {
1530 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1531 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
1532 print '<a class="aaa" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user&token='.newToken().'">'.img_picto($langs->trans("CreateDolibarrLogin"), 'add', 'class="pictofixedwidth"').$langs->trans("CreateDolibarrLogin").'</a>';
1533 }
1534 }
1535 print '</td></tr>';
1536
1537 print "</table>";
1538
1539 print '</div></div>';
1540 print '<div class="clearboth"></div>';
1541
1542 print dol_get_fiche_end();
1543
1544
1545 /*
1546 * Action bar
1547 */
1548 print '<div class="tabsAction">';
1549
1550 $parameters = array();
1551 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1552 if (empty($reshook) && $action != 'presend') {
1553 if (empty($user->socid)) {
1554 if (!empty($object->email)) {
1555 $langs->load("mails");
1556 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
1557 } else {
1558 $langs->load("mails");
1559 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
1560 }
1561 }
1562
1563 if ($user->hasRight('societe', 'contact', 'creer')) {
1564 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
1565 }
1566
1567 // Activer
1568 if ($object->status == 0 && $user->hasRight('societe', 'contact', 'creer')) {
1569 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
1570 }
1571 // Desactiver
1572 if ($object->status == 1 && $user->hasRight('societe', 'contact', 'creer')) {
1573 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
1574 }
1575
1576 // Delete
1577 if ($user->hasRight('societe', 'contact', 'supprimer')) {
1578 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().($backtopage ? '&backtopage='.urlencode($backtopage) : ''), 'delete', $user->hasRight('societe', 'contact', 'supprimer'));
1579 }
1580 }
1581
1582 print "</div>";
1583
1584 //Select mail models is same action as presend
1585 if (GETPOST('modelselected')) {
1586 $action = 'presend';
1587 }
1588
1589 if ($action != 'presend') {
1590 print '<div class="fichecenter"><div class="fichehalfleft">';
1591
1592 print '</div><div class="fichehalfright">';
1593
1594 $MAXEVENT = 10;
1595
1596 $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
1597
1598 // List of actions on element
1599 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1600 $formactions = new FormActions($db);
1601 $somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
1602
1603 print '</div></div>';
1604 }
1605
1606 // Presend form
1607 $modelmail = 'contact';
1608 $defaulttopic = 'Information';
1609 $diroutput = $conf->societe->dir_output.'/contact/';
1610 $trackid = 'ctc'.$object->id;
1611
1612 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1613 }
1614}
1615
1616
1617llxFooter();
1618
1619$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$c
Definition line.php:334
Class to manage canvas.
Class to manage categories.
Class to manage contact/addresses.
Class to manage a WYSIWYG editor.
Class to manage building of HTML components.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
div refaddress div address
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.