dolibarr 25.0.0-alpha
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 // Retrieve current contact
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 $object->civility_code = (string) GETPOST("civility_code", 'alpha');
230 $object->poste = (string) GETPOST("poste", 'alpha');
231 $object->address = (string) GETPOST("address", 'alpha');
232 $object->zip = (string) GETPOST("zipcode", 'alpha');
233 $object->town = (string) GETPOST("town", 'alpha');
234 $object->country_id = GETPOSTINT("country_id");
235 $object->state_id = GETPOSTINT("state_id");
236 $object->socialnetworks = array();
237 if (isModEnabled('socialnetworks')) {
238 foreach ($socialnetworks as $key => $value) {
239 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
240 $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
241 }
242 }
243 }
244 $object->email = (string) GETPOST('email', 'email');
245 $object->no_email = GETPOSTINT("no_email");
246 $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
247 $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
248 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
249 $object->fax = (string) GETPOST("fax", 'alpha');
250 $object->priv = GETPOSTINT("priv");
251 $object->note_public = (string) GETPOST("note_public", 'restricthtml');
252 $object->note_private = (string) GETPOST("note_private", 'restricthtml');
253 $object->roles = GETPOST("roles", 'array'); // Suppose this is proper array, ideally verified @phpstan-ignore assign.propertyType
254
255 $object->status = 1; //Default status to Actif
256 $object->statut = 1; //Default status to Actif
257
258 // Note: Correct date should be completed with location to have exact GM time of birth.
259 $object->birthday = dol_mktime(0, 0, 0, GETPOSTINT("birthdaymonth"), GETPOSTINT("birthdayday"), GETPOSTINT("birthdayyear"));
260 $object->birthday_alert = (GETPOST('birthday_alert', 'alpha') == "on" ? 1 : 0);
261
262 //Default language
263 $object->default_lang = GETPOST('default_lang');
264
265 // Fill array 'array_options' with data from add form
266 $ret = $extrafields->setOptionalsFromPost(null, $object);
267 if ($ret < 0) {
268 $error++;
269 $action = 'create';
270 }
271
272 if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && $object->no_email == -1 && !empty($object->email)) {
273 $error++;
274 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
275 $action = 'create';
276 }
277
278 if (!empty($object->email) && !isValidEmail($object->email)) {
279 $langs->load("errors");
280 $error++;
281 $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
282 $action = 'create';
283 }
284
285 if (empty($object->lastname)) {
286 $error++;
287 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
288 $action = 'create';
289 }
290
291 if (empty($error)) {
292 $id = $object->create($user);
293 if ($id <= 0) {
294 $error++;
295 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
296 $action = 'create';
297 }
298 }
299
300 if (empty($error)) {
301 // Categories association
302 $contcats = GETPOST('contcats', 'array');
303 if (count($contcats) > 0) {
304 $result = $object->setCategories($contcats);
305 if ($result <= 0) {
306 $error++;
307 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
308 $action = 'create';
309 }
310 }
311 }
312
313 if (empty($error) && isModEnabled('mailing') && !empty($object->email)) {
314 // Add mass emailing flag into table mailing_unsubscribe
315 $result = $object->setNoEmail($object->no_email);
316 if ($result < 0) {
317 $error++;
318 $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
319 $action = 'create';
320 }
321 }
322
323 if (empty($error) && $id > 0) {
324 $db->commit();
325 if (!empty($backtopage)) {
326 $url = str_replace('__ID__', (string) $id, $backtopage);
327 } else {
328 $url = 'card.php?id='.$id;
329 }
330 header("Location: ".$url);
331 exit;
332 } else {
333 $db->rollback();
334 }
335 }
336
337 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'contact', 'supprimer')) {
338 $result = $object->fetch($id);
339 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
340
341 $result = $object->delete($user);
342 if ($result > 0) {
343 setEventMessages("RecordDeleted", null, 'mesgs');
344 if ($backurlforlist) {
345 header("Location: ".$backurlforlist);
346 exit;
347 } else {
348 header("Location: ".DOL_URL_ROOT.'/contact/list.php');
349 exit;
350 }
351 } else {
352 setEventMessages($object->error, $object->errors, 'errors');
353 }
354 }
355
356 // Merge a contact into the current one. As on the third party card, the confirmation popup submits
357 // with a GET, the request being protected by the CSRF token of main.inc.php. All the permission and
358 // perimeter checks on the two contacts are done by Contact::mergeContact() itself.
359 if ($action == 'confirm_merge' && $confirm == 'yes' && $permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
360 $contact_origin_id = GETPOSTINT('contact_origin');
361
362 if ($contact_origin_id <= 0) {
363 $langs->load('errors');
364 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('MergeOriginContact')), null, 'errors');
365 } else {
366 // fetch() returns the id when found, 2 when several records were found, 0 when not found
367 // and -1 on error: a plain "<= 0" test would report an empty error on the not found case
368 $result = $object->fetch($id);
369 if ($result == 0) {
370 $langs->load('errors');
371 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
372 } elseif ($result != $id) {
373 $langs->load('errors');
374 setEventMessages($object->error ? $object->error : $langs->trans('ErrorBadParameters'), $object->errors, 'errors');
375 } elseif ($object->mergeContact($contact_origin_id) < 0) {
376 setEventMessages($object->error, $object->errors, 'errors');
377 } else {
378 setEventMessages($langs->trans('ContactsMergeSuccess'), null, 'mesgs');
379 // The merge is committed, but the files are moved afterwards and may have failed
380 if (!empty($object->warnings)) {
381 setEventMessages(null, $object->warnings, 'warnings');
382 }
383 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$object->id);
384 exit;
385 }
386 }
387 }
388
389 if ($action == 'update' && empty($cancel) && $permissiontoadd) {
390 if (!GETPOST("lastname", 'alpha')) {
391 $error++;
392 $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
393 $action = 'edit';
394 }
395
396 if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && GETPOSTINT("no_email") == -1 && !empty(GETPOST('email', 'email'))) {
397 $error++;
398 $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
399 $action = 'edit';
400 }
401
402 if (!empty(GETPOST('email', 'email')) && !isValidEmail(GETPOST('email', 'email'))) {
403 $langs->load("errors");
404 $error++;
405 $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
406 $action = 'edit';
407 }
408
409 if (!$error) {
410 $contactid = GETPOSTINT("contactid");
411 $object->fetch($contactid);
412 $object->fetchRoles();
413
414 // Photo save
415 $dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/contact/".$object->id."/photos";
416 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
417 if (GETPOST('deletephoto') && $object->photo) {
418 $fileimg = $dir.'/'.$object->photo;
419 $dirthumbs = $dir.'/thumbs';
420 dol_delete_file($fileimg);
421 dol_delete_dir_recursive($dirthumbs);
422 $object->photo = '';
423 }
424 if ($file_OK) {
425 if (image_format_supported($_FILES['photo']['name']) > 0) {
426 dol_mkdir($dir);
427
428 if (@is_dir($dir)) {
429 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
430 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
431
432 if (!($result > 0)) {
433 $errors[] = "ErrorFailedToSaveFile";
434 } else {
435 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
436
437 // Create thumbs
438 $object->addThumbs($newfile);
439 }
440 }
441 } else {
442 $errors[] = "ErrorBadImageFormat";
443 }
444 } else {
445 switch ($_FILES['photo']['error']) {
446 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
447 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
448 $errors[] = "ErrorFileSizeTooLarge";
449 break;
450 case 3: //uploaded file was only partially uploaded
451 $errors[] = "ErrorFilePartiallyUploaded";
452 break;
453 }
454 }
455
456 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
457
458 $object->socid = $socid;
459 $object->lastname = (string) GETPOST("lastname", 'alpha');
460 $object->firstname = (string) GETPOST("firstname", 'alpha');
461 $object->civility_code = (string) GETPOST("civility_code", 'alpha');
462 $object->poste = (string) GETPOST("poste", 'alpha');
463
464 $object->address = (string) GETPOST("address", 'alpha');
465 $object->zip = (string) GETPOST("zipcode", 'alpha');
466 $object->town = (string) GETPOST("town", 'alpha');
467 $object->state_id = GETPOSTINT("state_id");
468 $object->country_id = GETPOSTINT("country_id");
469
470 $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
471 $object->no_email = GETPOSTINT("no_email");
472 $object->socialnetworks = array();
473 if (isModEnabled('socialnetworks')) {
474 foreach ($socialnetworks as $key => $value) {
475 if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
476 $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
477 }
478 }
479 }
480 $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
481 $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
482 $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
483 $object->fax = (string) GETPOST("fax", 'alpha');
484 $object->priv = GETPOSTINT("priv");
485 $object->note_public = (string) GETPOST("note_public", 'restricthtml');
486 $object->note_private = (string) GETPOST("note_private", 'restricthtml');
487
488 // Suppose this is proper array, ideally verified @phpstan-ignore-next-line assign.propertyType
489 $object->roles = GETPOST("roles", 'array'); // Note GETPOSTISSET("role") is null when combo is empty
490
491 //Default language
492 $object->default_lang = GETPOST('default_lang');
493
494 // Fill array 'array_options' with data from add form
495 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
496 if ($ret < 0) {
497 $error++;
498 }
499
500 if (!$error) {
501 $result = $object->update($contactid, $user);
502
503 if ($result > 0) {
504 // Categories association
505 $categories = GETPOST('contcats', 'array');
506 $object->setCategories($categories);
507
508 // Update mass emailing flag into table mailing_unsubscribe
509 if (GETPOSTISSET('no_email') && $object->email) {
510 $no_email = GETPOSTINT('no_email');
511 $result = $object->setNoEmail($no_email);
512 if ($result < 0) {
513 $error++;
514 setEventMessages($object->error, $object->errors, 'errors');
515 }
516 }
517 } else {
518 $error++;
519 setEventMessages($object->error, $object->errors, 'errors');
520 }
521 }
522 }
523
524 if (!$error && empty($errors)) {
525 if (!empty($backtopage)) {
526 header("Location: ".$backtopage);
527 exit;
528 }
529 $action = 'view';
530 } else {
531 $action = 'edit';
532 }
533 }
534
535 if ($action == 'setprospectcontactlevel' && $permissiontoadd) {
536 $object->fetch($id);
537 $object->fk_prospectlevel = GETPOST('prospect_contact_level_id', 'alpha');
538 $result = $object->update($object->id, $user);
539 if ($result < 0) {
540 setEventMessages($object->error, $object->errors, 'errors');
541 }
542 }
543
544 // set communication status
545 if ($action == 'setstcomm' && $permissiontoadd) {
546 $object->fetch($id);
547 $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
548 $result = $object->update($object->id, $user);
549 if ($result < 0) {
550 setEventMessages($object->error, $object->errors, 'errors');
551 }
552 }
553
554 // Update extrafields
555 if ($action == 'update_extras' && $permissiontoeditextra) {
556 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
557
558 $attribute_name = GETPOST('attribute', 'aZ09');
559
560 // Fill array 'array_options' with data from update form
561 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
562 if ($ret < 0) {
563 $error++;
564 }
565
566 if (!$error) {
567 $result = $object->updateExtraField($attribute_name, 'CONTACT_MODIFY');
568 if ($result < 0) {
569 setEventMessages($object->error, $object->errors, 'errors');
570 $error++;
571 }
572 }
573
574 if ($error) {
575 $action = 'edit_extras';
576 }
577 }
578
579 // Actions to send emails
580 $triggersendname = 'CONTACT_SENTBYMAIL';
581 $paramname = 'id';
582 $mode = 'emailfromcontact';
583 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
584}
585
586
587/*
588 * View
589 */
590
591$form = new Form($db);
592$formadmin = new FormAdmin($db);
593$formcompany = new FormCompany($db);
594
595$objsoc = new Societe($db);
596if ($socid > 0) {
597 $objsoc->fetch($socid);
598}
599
600$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
601if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
602 $title = $object->lastname;
603}
604if (empty($object->id)) {
605 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
606}
607$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
608
609llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card');
610
611$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
612
613if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
614 // -----------------------------------------
615 // When used with CANVAS
616 // -----------------------------------------
617 if (empty($object->error) && $id) {
618 $object = new Contact($db);
619 $result = $object->fetch($id);
620 if ($result <= 0) {
621 dol_print_error(null, $object->error);
622 }
623 }
624 $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
625 $objcanvas->display_canvas($action); // Show template
626} else {
627 // -----------------------------------------
628 // When used in standard mode
629 // -----------------------------------------
630
631 // Confirm deleting contact
632 if ($user->hasRight('societe', 'contact', 'supprimer')) {
633 if ($action == 'delete') {
634 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
635 }
636 }
637
638 // Confirm merging contact
639 if ($action == 'merge' && $permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
640 // The current contact is excluded with the $filter parameter and not with $exclude, the latter
641 // being applied by selectcontacts() only when it receives an array while the ajax branch gives
642 // it a string. With CONTACT_USE_SEARCH_TO_SELECT the exclusion is lost anyway, contact/ajax
643 // /contact.php overwriting the filter it receives: merging a contact into itself is then refused
644 // by mergeContact() instead. The third party is shown to tell homonyms apart.
645 $formquestion = array(
646 array(
647 'name' => 'contact_origin',
648 'label' => $langs->trans("MergeOriginContact"),
649 'type' => 'other',
650 'value' => $form->select_contact(0, '', 'contact_origin', 1, '', '', 1, 'minwidth200', false, 1, 0, array(), '', '', '', '(sp.rowid:!=:'.((int) $id).')')
651 )
652 );
653
654 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("MergeContacts"), $langs->trans("ConfirmMergeContacts"), "confirm_merge", $formquestion, 'no', 1, 300);
655 }
656
657 /*
658 * Onglets
659 */
660 $head = array();
661 if ($id > 0) {
662 // Si edition contact deja existent
663 $object = new Contact($db);
664 $res = $object->fetch($id, $user);
665 if ($res < 0) {
666 setEventMessages($object->error, $object->errors, 'errors');
667 }
668
669 $object->fetchRoles();
670
671 // Show tabs
672 $head = contact_prepare_head($object);
673 }
674
675 if ($user->hasRight('societe', 'contact', 'creer')) {
676 if ($action == 'create') {
677 /*
678 * Card in create mode
679 */
680 $object->canvas = $canvas;
681
682 $object->state_id = GETPOSTINT("state_id");
683
684 // We set country_id, country_code and label for the selected country
685 $object->country_id = GETPOST("country_id") ? GETPOSTINT("country_id") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
686 if ($object->country_id) {
687 $tmparray = getCountry($object->country_id, 'all');
688 $object->country_code = $tmparray['code'];
689 $object->country = $tmparray['label'];
690 }
691
692 $linkback = '';
693
694 print load_fiche_titre($title, $linkback, 'address');
695
696 // Show errors
697 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
698
699 if ($conf->use_javascript_ajax) {
700 print "\n".'<script type="text/javascript">'."\n";
701 print 'jQuery(document).ready(function () {
702 jQuery("#selectcountry_id").change(function() {
703 document.formsoc.action.value="create";
704 document.formsoc.submit();
705 });
706
707 $("#copyaddressfromsoc").click(function() {
708 $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
709 $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
710 $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
711 console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
712 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
713 /* set country at end because it will trigger page refresh */
714 console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
715 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
716 });
717 })'."\n";
718 print '</script>'."\n";
719 }
720
721 print '<form method="post" name="formsoc" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
722 print '<input type="hidden" name="token" value="'.newToken().'">';
723 print '<input type="hidden" name="action" value="add">';
724 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
725 if (!empty($objsoc)) {
726 print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
727 }
728
729 print dol_get_fiche_head($head, 'card', '', 0, '');
730
731 print '<table class="border centpercent">';
732
733 // Name
734 print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
735 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>';
736 print '</tr>';
737
738 // Firstname
739 print '<tr>';
740 print '<td><label for="firstname">';
741 print $form->textwithpicto($langs->trans("Firstname"), $langs->trans("KeepEmptyIfGenericAddress")).'</label></td>';
742 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>';
743 print '</tr>';
744
745 // Company
746 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
747 if ($socid > 0) {
748 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
749 print '<td colspan="3" class="maxwidthonsmartphone">';
750 print $objsoc->getNomUrl(1, 'contact');
751 print '</td>';
752 print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
753 print '</td></tr>';
754 } else {
755 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
756 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($socid, 'socid', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
757 print '</td></tr>';
758 }
759 }
760
761 // Civility
762 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
763 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
764 print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
765 print '</td></tr>';
766 }
767
768 // Job position
769 print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
770 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>';
771
772 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
773 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
774
775 $colspan = 3;
776 if ($conf->use_javascript_ajax && $socid > 0) {
777 $colspan = 2;
778 }
779
780 // Address
781 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->address)) == 0) {
782 $object->address = $objsoc->address; // Predefined with third party
783 }
784 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
785 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>';
786
787 if ($conf->use_javascript_ajax && $socid > 0) {
788 $rowspan = 3;
789 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
790 $rowspan++;
791 }
792
793 print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
794 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
795 print '</td>';
796 }
797 print '</tr>';
798
799 // Zip / Town
800 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->zip)) == 0) {
801 $object->zip = $objsoc->zip; // Predefined with third party
802 }
803 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->town)) == 0) {
804 $object->town = $objsoc->town; // Predefined with third party
805 }
806 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
807 print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
808 print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
809 print '</td></tr>';
810
811 // Country
812 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
813 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
814 print $form->select_country((GETPOSTISSET("country_id") ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
815 if ($user->admin) {
816 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
817 }
818 print '</td></tr>';
819
820 // State
821 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
822 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
823 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
824 } else {
825 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
826 }
827
828 if ($object->country_id) {
829 print img_picto('', 'state', 'class="pictofixedwidth"');
830 print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
831 } else {
832 print $countrynotdefined;
833 }
834 print '</td></tr>';
835 }
836
837 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->phone_pro)) == 0) {
838 $object->phone_pro = $objsoc->phone; // Predefined with third party
839 }
840 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->fax)) == 0) {
841 $object->fax = $objsoc->fax; // Predefined with third party
842 }
843
844 // Phone / Fax
845 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
846 print '<td>';
847 print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
848 print '</td>';
849 if ($conf->browser->layout == 'phone') {
850 print '</tr><tr>';
851 }
852
853 print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
854 print '<td>';
855 print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
856 print '</td>';
857 print '</tr>';
858
859 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
860 print '<td>';
861 print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150 widthcentpercentminusx');
862 print '</td>';
863 if ($conf->browser->layout == 'phone') {
864 print '</tr><tr>';
865 }
866
867 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
868 print '<td>';
869 print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150 widthcentpercentminusx');
870 print '</td>';
871 print '</tr>';
872
873 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->email)) == 0) {
874 $object->email = $objsoc->email; // Predefined with third party
875 }
876
877 // Email
878 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
879 print '<td>';
880 print img_picto('', 'object_email', 'class="pictofixedwidth"');
881 print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
882 print '</tr>';
883
884 // Unsubscribe
885 if (isModEnabled('mailing')) {
886 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
887 print "\n".'<script type="text/javascript">'."\n";
888 print '$(document).ready(function () {
889 $("#email").keyup(function() {
890 if ($(this).val()!="") {
891 $(".noemail").addClass("fieldrequired");
892 } else {
893 $(".noemail").removeClass("fieldrequired");
894 }
895 });
896 })'."\n";
897 print '</script>'."\n";
898 }
899 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
900 $result = $object->getNoEmail();
901 if ($result < 0) {
902 setEventMessages($object->error, $object->errors, 'errors');
903 }
904 }
905 print '<tr>';
906 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
907 print '<td>';
908 // Default value is in MAILING_CONTACT_DEFAULT_BULK_STATUS that you can modify in setup of module emailing
909 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));
910 print '</td>';
911 print '</tr>';
912 }
913
914 // Social network
915 if (isModEnabled('socialnetworks')) {
916 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
917
918 $object->showSocialNetwork($socialnetworks, $colspan);
919
920 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
921 }
922
923 // Visibility
924 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
925 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
926 print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ? GETPOST("priv", 'alpha') : $object->priv), 0);
927 print '</td></tr>';
928
929 // Default language
930 if (getDolGlobalInt('MAIN_MULTILANGS')) {
931 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
932 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');
933 print '</td>';
934 print '</tr>';
935 }
936
937 // Categories
938 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
939 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
940 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', 'parent', 64, 0, 3);
941 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), 0, 0, '', 0, '90%');
942 print "</td></tr>";
943 }
944
945 // Contact by default
946 if ($socid > 0) {
947 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
948 print '<td colspan="3">';
949 $contactType = $object->listeTypeContacts('external', 0, 1);
950 print img_picto('', 'contact', 'class="pictofixedwidth"').$form->multiselectarray('roles', $contactType, array(), 0, 0, '', 0, '90%');
951 print '</td></tr>';
952 }
953
954 // Other attributes
955 $parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
956 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
957
958 print "</table><br>";
959
960 print '<hr style="margin-bottom: 20px">';
961
962 // Add personal information
963 print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
964
965 print '<table class="border centpercent">';
966
967 // Date To Birth
968 print '<tr><td class="titlefieldcreate"><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td colspan="3">';
969 $form = new Form($db);
970 if ($object->birthday) {
971 print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
972 } else {
973 print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
974 }
975
976 print ' &nbsp; <label for="birthday_alert">'.$langs->trans("Alert").'</label> ';
977 if (!empty($object->birthday_alert)) {
978 print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
979 } else {
980 print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
981 }
982 print '</td>';
983 print '</tr>';
984
985 print "</table>";
986
987 print dol_get_fiche_end();
988
989 print $form->buttonsSaveCancel("Add");
990
991 print "</form>";
992 } elseif ($action == 'edit' && !empty($id)) {
993 /*
994 * Card in edit mode
995 */
996
997 // We set country_id, and country_code label of the chosen country
998 if (GETPOSTISSET("country_id") || $object->country_id) {
999 $tmparray = getCountry($object->country_id, 'all');
1000 $object->country_code = $tmparray['code'];
1001 $object->country = $tmparray['label'];
1002 }
1003
1004 $objsoc = new Societe($db);
1005 $objsoc->fetch($object->socid);
1006
1007 // Show errors
1008 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
1009
1010 if ($conf->use_javascript_ajax) {
1011 print "\n".'<script type="text/javascript">'."\n";
1012 print 'jQuery(document).ready(function () {
1013 jQuery("#selectcountry_id").change(function() {
1014 document.formsoc.action.value="edit";
1015 document.formsoc.submit();
1016 });
1017
1018 $("#copyaddressfromsoc").click(function() {
1019 $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
1020 $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
1021 $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
1022 console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
1023 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
1024 /* set country at end because it will trigger page refresh */
1025 console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
1026 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
1027 });
1028 })'."\n";
1029 print '</script>'."\n";
1030 }
1031
1032 print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
1033 print '<input type="hidden" name="token" value="'.newToken().'">';
1034 print '<input type="hidden" name="id" value="'.$id.'">';
1035 print '<input type="hidden" name="action" value="update">';
1036 print '<input type="hidden" name="contactid" value="'.$object->id.'">';
1037 if (!empty($backtopage)) {
1038 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1039 }
1040
1041 print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
1042
1043 print '<table class="border centpercent">';
1044
1045 // Ref/ID
1046 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
1047 print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
1048 print $object->ref;
1049 print '</td></tr>';
1050 }
1051
1052 // Lastname
1053 print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
1054 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>';
1055 print '</tr>';
1056 print '<tr>';
1057 // Firstname
1058 print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
1059 print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
1060 print '</tr>';
1061
1062 // Company
1063 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1064 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
1065 print '<td colspan="3" class="maxwidthonsmartphone">';
1066 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(GETPOSTINT('socid') ? GETPOSTINT('socid') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
1067 print '</td>';
1068 print '</tr>';
1069 }
1070
1071 // Civility
1072 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
1073 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
1074 print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
1075 print '</td></tr>';
1076 }
1077
1078 // Job position
1079 print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
1080 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>';
1081
1082 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1083 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1084
1085 // Address
1086 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
1087 print '<td colspan="3">';
1088 print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
1089 print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
1090 print '</div><div class="paddingrightonly valignmiddle inline-block">';
1091 if (!empty($conf->use_javascript_ajax)) {
1092 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
1093 }
1094 print '</div>';
1095 print '</td>';
1096
1097 // Zip / Town
1098 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1099 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
1100 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1101 print '</td></tr>';
1102
1103 // Country
1104 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1105 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
1106 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
1107 if ($user->admin) {
1108 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1109 }
1110 print '</td></tr>';
1111
1112 // State
1113 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1114 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1115 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1116 } else {
1117 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1118 }
1119
1120 print img_picto('', 'state', 'class="pictofixedwidth"');
1121 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
1122 print '</td></tr>';
1123 }
1124
1125 // Phone
1126 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
1127 print '<td>';
1128 print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150', 80);
1129 print '</td>';
1130 if ($conf->browser->layout == 'phone') {
1131 print '</tr><tr>';
1132 }
1133
1134 print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
1135 print '<td>';
1136 print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150', 80);
1137 print '</td></tr>';
1138
1139 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
1140 print '<td>';
1141 print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150', 80);
1142 print '</td>';
1143 if ($conf->browser->layout == 'phone') {
1144 print '</tr><tr>';
1145 }
1146
1147 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
1148 print '<td>';
1149 print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150', 80);
1150 print '</td></tr>';
1151
1152 // EMail
1153 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (int) (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';
1154 print '<td>';
1155 print img_picto('', 'object_email', 'class="pictofixedwidth"');
1156 print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
1157 if (isModEnabled('mailing')) {
1158 if ($conf->browser->layout == 'phone') {
1159 print '</tr><tr>';
1160 }
1161 $langs->load("mails");
1162 print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
1163 print '<td>'.$object->getNbOfEMailings().'</td>';
1164 } else {
1165 print '<td colspan="2"></td>';
1166 }
1167 print '</tr>';
1168
1169 // Unsubscribe
1170 if (isModEnabled('mailing')) {
1171 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1172 print "\n".'<script type="text/javascript">'."\n";
1173
1174 print '
1175 jQuery(document).ready(function () {
1176 function init_check_no_email(input) {
1177 if (input.val()!="") {
1178 $(".noemail").addClass("fieldrequired");
1179 } else {
1180 $(".noemail").removeClass("fieldrequired");
1181 }
1182 }
1183 $("#email").keyup(function() {
1184 init_check_no_email($(this));
1185 });
1186 init_check_no_email($("#email"));
1187 })'."\n";
1188 print '</script>'."\n";
1189 }
1190 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1191 $result = $object->getNoEmail();
1192 if ($result < 0) {
1193 setEventMessages($object->error, $object->errors, 'errors');
1194 }
1195 }
1196 print '<tr>';
1197 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1198 print '<td>';
1199 $useempty = (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
1200 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, false, (int) $useempty);
1201 print '</td>';
1202 print '</tr>';
1203 }
1204
1205 // Social network
1206 if (isModEnabled('socialnetworks')) {
1207 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1208
1209 $object->showSocialNetwork($socialnetworks, $colspan);
1210
1211 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1212 }
1213
1214 // Visibility
1215 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
1216 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
1217 print $form->selectarray('priv', $selectarray, $object->priv, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth150');
1218 print '</td></tr>';
1219
1220 // Default language
1221 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1222 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1223 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');
1224 print '</td>';
1225 print '</tr>';
1226 }
1227
1228 // Note Public
1229 print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
1230 $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1231 print $doleditor->Create(1);
1232 print '</td></tr>';
1233
1234 // Note Private
1235 print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
1236 $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1237 print $doleditor->Create(1);
1238 print '</td></tr>';
1239
1240 // Status
1241 print '<tr><td>'.$langs->trans("Status").'</td>';
1242 print '<td colspan="3">';
1243 print $object->getLibStatut(4);
1244 print '</td></tr>';
1245
1246 // Categories
1247 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1248 $arrayselected = array();
1249 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
1250 print '<td colspan="3">';
1251 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', '', 64, 0, 3);
1252 $c = new Categorie($db);
1253 $cats = $c->containing($object->id, 'contact');
1254 foreach ($cats as $cat) {
1255 $arrayselected[] = $cat->id;
1256 }
1257 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, 0, 0, '', 0, '90%');
1258 print "</td></tr>";
1259 }
1260
1261 // Contact by default
1262 if (!empty($object->socid)) {
1263 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
1264 print '<td colspan="3">';
1265 print img_picto('', 'category', 'class="pictofixedwidth"').$formcompany->showRoles("roles", $object, 'edit', $object->roles, '');
1266 print '</td></tr>';
1267 }
1268
1269 // Other attributes
1270 $parameters = array('colspan' => ' colspan="3"', 'cols' => '3', 'colspanvalue' => '3');
1271 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1272
1273 $object->load_ref_elements();
1274
1275 if (isModEnabled('order')) {
1276 print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
1277 print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
1278 print '</td></tr>';
1279 }
1280
1281 if (isModEnabled("propal")) {
1282 print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1283 print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
1284 print '</td></tr>';
1285 }
1286
1287 if (isModEnabled('contract')) {
1288 print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1289 print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
1290 print '</td></tr>';
1291 }
1292
1293 if (isModEnabled('invoice')) {
1294 print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1295 print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
1296 print '</td></tr>';
1297 }
1298
1299 // Login Dolibarr
1300 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1301 if ($object->user_id) {
1302 $dolibarr_user = new User($db);
1303 $result = $dolibarr_user->fetch($object->user_id);
1304 print $dolibarr_user->getLoginUrl(1);
1305 } else {
1306 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1307 }
1308 print '</td></tr>';
1309
1310 // Photo
1311 print '<tr>';
1312 print '<td>'.$langs->trans("PhotoFile").'</td>';
1313 print '<td colspan="3">';
1314 if ($object->photo) {
1315 print $form->showphoto('contact', $object);
1316 print "<br>\n";
1317 }
1318 print '<table class="nobordernopadding">';
1319 if ($object->photo) {
1320 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1321 }
1322 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1323 print '<tr><td>';
1324 $maxfilesizearray = getMaxFileSizeArray();
1325 $maxmin = $maxfilesizearray['maxmin'];
1326 if ($maxmin > 0) {
1327 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1328 }
1329 print '<input type="file" class="flat maxwidth200" name="photo" id="photoinput">';
1330 print '</td></tr>';
1331 print '</table>';
1332
1333 print '</td>';
1334 print '</tr>';
1335
1336 print '</table>';
1337
1338 print dol_get_fiche_end();
1339
1340 print $form->buttonsSaveCancel();
1341
1342 print "</form>";
1343 }
1344 }
1345
1346 // Select mail models is same action as presend
1347 if (GETPOST('modelselected', 'alpha')) {
1348 $action = 'presend';
1349 }
1350
1351 // View mode
1352 if (!empty($id) && $action != 'edit' && $action != 'create') {
1353 $objsoc = new Societe($db);
1354
1355 // Show errors
1356 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
1357
1358 print dol_get_fiche_head($head, 'card', $title, -1, 'contact', 0, '', '', 0, '', 1);
1359
1360 if ($action == 'create_user') {
1361 // Full firstname and lastname separated with a dot : firstname.lastname
1362 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1363 $login = dol_buildlogin($object->lastname, $object->firstname);
1364
1365 $generated_password = '';
1366 if (empty($ldap_sid)) { // TODO ldap_sid ?
1367 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1368 $generated_password = getRandomPassword(false);
1369 }
1370 $password = $generated_password;
1371
1372 // Create a form array
1373 $formquestion = array(
1374 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
1375 array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
1376 //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')))
1377 );
1378 $text = $langs->trans("ConfirmCreateContact").'<br>';
1379 if (isModEnabled("societe")) {
1380 if ($object->socid > 0) {
1381 $text .= $langs->trans("UserWillBeExternalUser");
1382 } else {
1383 $text .= $langs->trans("UserWillBeInternalUser");
1384 }
1385 }
1386 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1387 }
1388
1389 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1390
1391 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
1392 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
1393 $morehtmlref .= '</a>';
1394
1395 $morehtmlref .= '<div class="refidno">';
1396 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1397 $objsoc->fetch($object->socid);
1398 // Thirdparty
1399 if ($objsoc->id > 0) {
1400 $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
1401 } else {
1402 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
1403 }
1404 }
1405 $morehtmlref .= '</div>';
1406
1407 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1408
1409
1410 print '<div class="fichecenter">';
1411 print '<div class="fichehalfleft">';
1412
1413 print '<div class="underbanner clearboth"></div>';
1414 print '<table class="border tableforfield" width="100%">';
1415
1416 // Civility
1417 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
1418 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
1419 print $object->getCivilityLabel();
1420 print '</td></tr>';
1421 }
1422
1423 // Job / position
1424 print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
1425
1426 // Email
1427 if (isModEnabled('mailing')) {
1428 $langs->load("mails");
1429 print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
1430 print '<td><a class="badge badge-info" href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
1431 }
1432
1433 // Unsubscribe opt-out
1434 if (isModEnabled('mailing')) {
1435 $result = $object->getNoEmail();
1436 if ($result < 0) {
1437 setEventMessages($object->error, $object->errors, 'errors');
1438 }
1439 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
1440 if ($object->email) {
1441 print yn($object->no_email);
1442 } else {
1443 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
1444 }
1445 print '</td></tr>';
1446 }
1447
1448 // Default language
1449 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1450 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1451 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1452 //$s=picto_from_langcode($object->default_lang);
1453 //print ($s?$s.' ':'');
1454 $langs->load("languages");
1455 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1456 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1457 print $labellang;
1458 print '</td></tr>';
1459 }
1460
1461 print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
1462 print $object->LibPubPriv($object->priv, 1);
1463 print '</td></tr>';
1464
1465 print '</table>';
1466 print '</div>';
1467
1468 $object->fetch_thirdparty();
1469
1470
1471 print '<div class="fichehalfright">';
1472
1473 print '<div class="underbanner clearboth"></div>';
1474 print '<table class="border tableforfield centpercent">';
1475
1476
1477 if (getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) {
1478 if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
1479 // Level of prospect
1480 print '<tr><td class="">';
1481 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
1482 print $langs->trans('ProspectLevel');
1483 print '<td>';
1484 if ($action != 'editlevel' && $user->hasRight('societe', 'contact', 'creer')) {
1485 print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
1486 }
1487 print '</tr></table>';
1488 print '</td><td>';
1489 if ($action == 'editlevel') {
1490 $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
1491 } else {
1492 print $object->getLibProspLevel();
1493 }
1494 print "</td>";
1495 print '</tr>';
1496
1497 // Status of prospection
1498 $object->loadCacheOfProspStatus();
1499 print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
1500 print ' &nbsp; &nbsp; ';
1501 print '<div class="floatright">';
1502 foreach ($object->cacheprospectstatus as $key => $val) {
1503 $titlealt = 'default';
1504 if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1505 $titlealt = $val['label'];
1506 }
1507 if ($object->stcomm_id != $val['id']) {
1508 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>';
1509 }
1510 }
1511 print '</div></td></tr>';
1512 }
1513 }
1514
1515 // Categories
1516 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1517 print '<tr><td class="">'.$langs->trans("Categories").'</td>';
1518 print '<td>';
1519 print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
1520 print '</td></tr>';
1521 }
1522
1523 // Contact by default for
1524 if (!empty($object->socid)) {
1525 print '<tr><td class="">'.$langs->trans("ContactByDefaultFor").'</td>';
1526 print '<td>';
1527 print $formcompany->showRoles("roles", $object, 'view', $object->roles, '');
1528 print '</td></tr>';
1529 }
1530
1531 // Other attributes
1532 $parameters = array('socid' => $socid);
1533 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1534
1535 $object->load_ref_elements();
1536
1537 if (isModEnabled("propal")) {
1538 print '<tr><td class="">'.$langs->trans("ContactForProposals").'</td><td>';
1539 print $object->ref_propal ? $object->ref_propal : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'<span>';
1540 print '</td></tr>';
1541 }
1542
1543 if (isModEnabled('order') || isModEnabled("shipping")) {
1544 print '<tr><td class="">';
1545 if (isModEnabled("shipping")) {
1546 print $langs->trans("ContactForOrdersOrShipments");
1547 } else {
1548 print $langs->trans("ContactForOrders");
1549 }
1550 print '</td><td>';
1551 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>';
1552 if (isModEnabled("shipping")) {
1553 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrderOrShipments").'</span>';
1554 }
1555 print $object->ref_commande ? $object->ref_commande : $none;
1556 print '</td></tr>';
1557 }
1558
1559 if (isModEnabled('contract')) {
1560 print '<tr><td class="">'.$langs->trans("ContactForContracts").'</td><td>';
1561 print $object->ref_contrat ? $object->ref_contrat : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>';
1562 print '</td></tr>';
1563 }
1564
1565 if (isModEnabled('invoice')) {
1566 print '<tr><td class="">'.$langs->trans("ContactForInvoices").'</td><td>';
1567 print $object->ref_facturation ? $object->ref_facturation : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>';
1568 print '</td></tr>';
1569 }
1570
1571 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td>';
1572 if ($object->user_id) {
1573 $dolibarr_user = new User($db);
1574 $result = $dolibarr_user->fetch($object->user_id);
1575 print $dolibarr_user->getLoginUrl(-1);
1576 } else {
1577 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1578 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
1579 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>';
1580 }
1581 }
1582 print '</td></tr>';
1583
1584 print "</table>";
1585
1586 print '</div></div>';
1587 print '<div class="clearboth"></div>';
1588
1589 print dol_get_fiche_end();
1590
1591
1592 /*
1593 * Action bar
1594 */
1595 print '<div class="tabsAction">';
1596
1597 $parameters = array();
1598 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1599 if (empty($reshook) && $action != 'presend') {
1600 if (empty($user->socid)) {
1601 if (!empty($object->email)) {
1602 $langs->load("mails");
1603 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
1604 } else {
1605 $langs->load("mails");
1606 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
1607 }
1608 }
1609
1610 if ($user->hasRight('societe', 'contact', 'creer')) {
1611 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
1612 }
1613
1614 // Activer
1615 if ($object->status == 0 && $user->hasRight('societe', 'contact', 'creer')) {
1616 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
1617 }
1618 // Desactiver
1619 if ($object->status == 1 && $user->hasRight('societe', 'contact', 'creer')) {
1620 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
1621 }
1622
1623 // Merge
1624 if ($permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
1625 print dolGetButtonAction($langs->trans("MergeContacts"), $langs->trans("Merge"), 'danger', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=merge&token='.newToken(), '', $user->hasRight('societe', 'contact', 'supprimer'));
1626 }
1627
1628 // Delete
1629 if ($user->hasRight('societe', 'contact', 'supprimer')) {
1630 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'));
1631 }
1632 }
1633
1634 print "</div>";
1635
1636 //Select mail models is same action as presend
1637 if (GETPOST('modelselected')) {
1638 $action = 'presend';
1639 }
1640
1641 if ($action != 'presend') {
1642 print '<div class="fichecenter"><div class="fichehalfleft">';
1643
1644 print '</div><div class="fichehalfright">';
1645
1646 $MAXEVENT = 10;
1647
1648 $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
1649
1650 // List of actions on element
1651 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1652 $formactions = new FormActions($db);
1653 $somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
1654
1655 print '</div></div>';
1656 }
1657
1658 // Presend form
1659 $modelmail = 'contact';
1660 $defaulttopic = 'Information';
1661 $diroutput = $conf->societe->dir_output.'/contact/';
1662 $trackid = 'ctc'.$object->id;
1663
1664 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1665 }
1666}
1667
1668
1669llxFooter();
1670
1671$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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
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 =...
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.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
div refaddress div address
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.
Definition html.lib.php:519
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
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.
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.
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.
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.
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
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.