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