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