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