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