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