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