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