dolibarr 21.0.0-alpha
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 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 a 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 a technical object to manage hooks of page. Note that conf->hooks_modules contains an 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, '', 0, 0, '', '', '', 'mod-societe page-contact-card');
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((string) $objsoc->state_id).'");
666 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $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((string) $objsoc->country_id).'");
669 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $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 = ($conf->browser->layout == 'phone' ? 2 : 4);
725 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
726
727 $colspan = 3;
728 if ($conf->use_javascript_ajax && $socid > 0) {
729 $colspan = 2;
730 }
731
732 // Address
733 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->address)) == 0) {
734 $object->address = $objsoc->address; // Predefined with third party
735 }
736 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
737 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>';
738
739 if ($conf->use_javascript_ajax && $socid > 0) {
740 $rowspan = 3;
741 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
742 $rowspan++;
743 }
744
745 print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
746 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
747 print '</td>';
748 }
749 print '</tr>';
750
751 // Zip / Town
752 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->zip)) == 0) {
753 $object->zip = $objsoc->zip; // Predefined with third party
754 }
755 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->town)) == 0) {
756 $object->town = $objsoc->town; // Predefined with third party
757 }
758 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
759 print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
760 print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
761 print '</td></tr>';
762
763 // Country
764 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
765 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
766 print $form->select_country((GETPOST("country_id", 'alpha') ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
767 if ($user->admin) {
768 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
769 }
770 print '</td></tr>';
771
772 // State
773 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
774 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
775 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
776 } else {
777 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
778 }
779
780 if ($object->country_id) {
781 print img_picto('', 'state', 'class="pictofixedwidth"');
782 print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
783 } else {
784 print $countrynotdefined;
785 }
786 print '</td></tr>';
787 }
788
789 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->phone_pro)) == 0) {
790 $object->phone_pro = $objsoc->phone; // Predefined with third party
791 }
792 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->fax)) == 0) {
793 $object->fax = $objsoc->fax; // Predefined with third party
794 }
795
796 // Phone / Fax
797 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
798 print '<td>';
799 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
800 print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" value="'.(GETPOSTISSET('phone_pro') ? GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
801 if ($conf->browser->layout == 'phone') {
802 print '</tr><tr>';
803 }
804 print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
805 print '<td>';
806 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
807 print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td>';
808 print '</tr>';
809
810 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
811 print '<td>';
812 print img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"');
813 print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
814 if ($conf->browser->layout == 'phone') {
815 print '</tr><tr>';
816 }
817 print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
818 print '<td>';
819 print img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"');
820 print '<input type="text" name="fax" id="fax" class="maxwidth200" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
821 print '</tr>';
822
823 if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->email)) == 0) {
824 $object->email = $objsoc->email; // Predefined with third party
825 }
826
827 // Email
828 print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
829 print '<td>';
830 print img_picto('', 'object_email', 'class="pictofixedwidth"');
831 print '<input type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
832 print '</tr>';
833
834 // Unsubscribe
835 if (isModEnabled('mailing')) {
836 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
837 print "\n".'<script type="text/javascript">'."\n";
838 print '$(document).ready(function () {
839 $("#email").keyup(function() {
840 if ($(this).val()!="") {
841 $(".noemail").addClass("fieldrequired");
842 } else {
843 $(".noemail").removeClass("fieldrequired");
844 }
845 });
846 })'."\n";
847 print '</script>'."\n";
848 }
849 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
850 $result = $object->getNoEmail();
851 if ($result < 0) {
852 setEventMessages($object->error, $object->errors, 'errors');
853 }
854 }
855 print '<tr>';
856 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
857 print '<td>';
858 // Default value is in MAILING_CONTACT_DEFAULT_BULK_STATUS that you can modify in setup of module emailing
859 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));
860 print '</td>';
861 print '</tr>';
862 }
863
864 // Social network
865 if (isModEnabled('socialnetworks')) {
866 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
867
868 $object->showSocialNetwork($socialnetworks, $colspan);
869
870 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
871 }
872
873 // Visibility
874 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
875 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
876 print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ? GETPOST("priv", 'alpha') : $object->priv), 0);
877 print '</td></tr>';
878
879 // Default language
880 if (getDolGlobalInt('MAIN_MULTILANGS')) {
881 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
882 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');
883 print '</td>';
884 print '</tr>';
885 }
886
887 // Categories
888 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
889 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
890 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', 'parent', 64, 0, 3);
891 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, null, null, '90%');
892 print "</td></tr>";
893 }
894
895 // Contact by default
896 if (!empty($socid)) {
897 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
898 print '<td colspan="3">';
899 $contactType = $object->listeTypeContacts('external', 0, 1);
900 print img_picto('', 'contact', 'class="pictofixedwidth"').$form->multiselectarray('roles', $contactType, array(), 0, 0, '', 0, '90%');
901 print '</td></tr>';
902 }
903
904 // Other attributes
905 $parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
906 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
907
908 print "</table><br>";
909
910 print '<hr style="margin-bottom: 20px">';
911
912 // Add personal information
913 print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
914
915 print '<table class="border centpercent">';
916
917 // Date To Birth
918 print '<tr><td><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td>';
919 $form = new Form($db);
920 if ($object->birthday) {
921 print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
922 } else {
923 print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
924 }
925 print '</td>';
926
927 print '<td><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
928 if (!empty($object->birthday_alert)) {
929 print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
930 } else {
931 print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
932 }
933 print '</td>';
934 print '</tr>';
935
936 print "</table>";
937
938 print dol_get_fiche_end();
939
940 print $form->buttonsSaveCancel("Add");
941
942 print "</form>";
943 } elseif ($action == 'edit' && !empty($id)) {
944 /*
945 * Card in edit mode
946 */
947
948 // We set country_id, and country_code label of the chosen country
949 if (GETPOSTISSET("country_id") || $object->country_id) {
950 $tmparray = getCountry($object->country_id, 'all');
951 $object->country_code = $tmparray['code'];
952 $object->country = $tmparray['label'];
953 }
954
955 $objsoc = new Societe($db);
956 $objsoc->fetch($object->socid);
957
958 // Show errors
959 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
960
961 if ($conf->use_javascript_ajax) {
962 print "\n".'<script type="text/javascript">'."\n";
963 print 'jQuery(document).ready(function () {
964 jQuery("#selectcountry_id").change(function() {
965 document.formsoc.action.value="edit";
966 document.formsoc.submit();
967 });
968
969 $("#copyaddressfromsoc").click(function() {
970 $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
971 $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
972 $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
973 console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
974 $(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
975 /* set country at end because it will trigger page refresh */
976 console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
977 $(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
978 });
979 })'."\n";
980 print '</script>'."\n";
981 }
982
983 print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
984 print '<input type="hidden" name="token" value="'.newToken().'">';
985 print '<input type="hidden" name="id" value="'.$id.'">';
986 print '<input type="hidden" name="action" value="update">';
987 print '<input type="hidden" name="contactid" value="'.$object->id.'">';
988 if (!empty($backtopage)) {
989 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
990 }
991
992 print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
993
994 print '<table class="border centpercent">';
995
996 // Ref/ID
997 if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
998 print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
999 print $object->ref;
1000 print '</td></tr>';
1001 }
1002
1003 // Lastname
1004 print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
1005 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>';
1006 print '</tr>';
1007 print '<tr>';
1008 // Firstname
1009 print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
1010 print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
1011 print '</tr>';
1012
1013 // Company
1014 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1015 print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
1016 print '<td colspan="3" class="maxwidthonsmartphone">';
1017 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(GETPOSTINT('socid') ? GETPOSTINT('socid') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
1018 print '</td>';
1019 print '</tr>';
1020 }
1021
1022 // Civility
1023 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
1024 print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
1025 print '</td></tr>';
1026
1027 // Job position
1028 print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
1029 print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ? GETPOST("poste", 'alphanohtml') : $object->poste).'"></td></tr>';
1030
1031 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1032 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1033
1034 // Address
1035 print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
1036 print '<td colspan="3">';
1037 print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
1038 print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
1039 print '</div><div class="paddingrightonly valignmiddle inline-block">';
1040 if (!empty($conf->use_javascript_ajax)) {
1041 print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
1042 }
1043 print '</div>';
1044 print '</td>';
1045
1046 // Zip / Town
1047 print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1048 print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
1049 print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1050 print '</td></tr>';
1051
1052 // Country
1053 print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1054 print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
1055 print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
1056 if ($user->admin) {
1057 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1058 }
1059 print '</td></tr>';
1060
1061 // State
1062 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
1063 if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
1064 print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1065 } else {
1066 print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
1067 }
1068
1069 print img_picto('', 'state', 'class="pictofixedwidth"');
1070 print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
1071 print '</td></tr>';
1072 }
1073
1074 // Phone
1075 print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
1076 print '<td>';
1077 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
1078 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>';
1079 if ($conf->browser->layout == 'phone') {
1080 print '</tr><tr>';
1081 }
1082 print '<td>'.$form->editfieldkey('PhonePerso', 'fax', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
1083 print '<td>';
1084 print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
1085 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>';
1086
1087 print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
1088 print '<td>';
1089 print img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"');
1090 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>';
1091 if ($conf->browser->layout == 'phone') {
1092 print '</tr><tr>';
1093 }
1094 print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
1095 print '<td>';
1096 print img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"');
1097 print '<input type="text" name="fax" id="fax" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_fax') ? GETPOST('phone_fax', 'alpha') : $object->fax).'"></td></tr>';
1098
1099 // EMail
1100 print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (getDolGlobalString('SOCIETE_EMAIL_MANDATORY'))).'</td>';
1101 print '<td>';
1102 print img_picto('', 'object_email', 'class="pictofixedwidth"');
1103 print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
1104 if (isModEnabled('mailing')) {
1105 if ($conf->browser->layout == 'phone') {
1106 print '</tr><tr>';
1107 }
1108 $langs->load("mails");
1109 print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
1110 print '<td>'.$object->getNbOfEMailings().'</td>';
1111 } else {
1112 print '<td colspan="2"></td>';
1113 }
1114 print '</tr>';
1115
1116 // Unsubscribe
1117 if (isModEnabled('mailing')) {
1118 if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
1119 print "\n".'<script type="text/javascript">'."\n";
1120
1121 print '
1122 jQuery(document).ready(function () {
1123 function init_check_no_email(input) {
1124 if (input.val()!="") {
1125 $(".noemail").addClass("fieldrequired");
1126 } else {
1127 $(".noemail").removeClass("fieldrequired");
1128 }
1129 }
1130 $("#email").keyup(function() {
1131 init_check_no_email($(this));
1132 });
1133 init_check_no_email($("#email"));
1134 })'."\n";
1135 print '</script>'."\n";
1136 }
1137 if (!GETPOSTISSET("no_email") && !empty($object->email)) {
1138 $result = $object->getNoEmail();
1139 if ($result < 0) {
1140 setEventMessages($object->error, $object->errors, 'errors');
1141 }
1142 }
1143 print '<tr>';
1144 print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
1145 print '<td>';
1146 $useempty = (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
1147 print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, false, $useempty);
1148 print '</td>';
1149 print '</tr>';
1150 }
1151
1152 // Social network
1153 if (isModEnabled('socialnetworks')) {
1154 $colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
1155
1156 $object->showSocialNetwork($socialnetworks, $colspan);
1157
1158 print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
1159 }
1160
1161 // Visibility
1162 print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
1163 $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
1164 print $form->selectarray('priv', $selectarray, $object->priv, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth150');
1165 print '</td></tr>';
1166
1167 // Default language
1168 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1169 print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1170 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');
1171 print '</td>';
1172 print '</tr>';
1173 }
1174
1175 // Note Public
1176 print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
1177 $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1178 print $doleditor->Create(1);
1179 print '</td></tr>';
1180
1181 // Note Private
1182 print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
1183 $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1184 print $doleditor->Create(1);
1185 print '</td></tr>';
1186
1187 // Status
1188 print '<tr><td>'.$langs->trans("Status").'</td>';
1189 print '<td colspan="3">';
1190 print $object->getLibStatut(4);
1191 print '</td></tr>';
1192
1193 // Categories
1194 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1195 $arrayselected = array();
1196 print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
1197 print '<td colspan="3">';
1198 $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', '', 64, 0, 3);
1199 $c = new Categorie($db);
1200 $cats = $c->containing($object->id, 'contact');
1201 foreach ($cats as $cat) {
1202 $arrayselected[] = $cat->id;
1203 }
1204 print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
1205 print "</td></tr>";
1206 }
1207
1208 // Contact by default
1209 if (!empty($object->socid)) {
1210 print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
1211 print '<td colspan="3">';
1212 print img_picto('', 'category', 'class="pictofixedwidth"').$formcompany->showRoles("roles", $object, 'edit', $object->roles, '');
1213 print '</td></tr>';
1214 }
1215
1216 // Other attributes
1217 $parameters = array('colspan' => ' colspan="3"', 'cols' => '3', 'colspanvalue' => '3');
1218 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
1219
1220 $object->load_ref_elements();
1221
1222 if (isModEnabled('order')) {
1223 print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
1224 print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
1225 print '</td></tr>';
1226 }
1227
1228 if (isModEnabled("propal")) {
1229 print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
1230 print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
1231 print '</td></tr>';
1232 }
1233
1234 if (isModEnabled('contract')) {
1235 print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
1236 print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
1237 print '</td></tr>';
1238 }
1239
1240 if (isModEnabled('invoice')) {
1241 print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
1242 print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
1243 print '</td></tr>';
1244 }
1245
1246 // Login Dolibarr
1247 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
1248 if ($object->user_id) {
1249 $dolibarr_user = new User($db);
1250 $result = $dolibarr_user->fetch($object->user_id);
1251 print $dolibarr_user->getLoginUrl(1);
1252 } else {
1253 print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1254 }
1255 print '</td></tr>';
1256
1257 // Photo
1258 print '<tr>';
1259 print '<td>'.$langs->trans("PhotoFile").'</td>';
1260 print '<td colspan="3">';
1261 if ($object->photo) {
1262 print $form->showphoto('contact', $object);
1263 print "<br>\n";
1264 }
1265 print '<table class="nobordernopadding">';
1266 if ($object->photo) {
1267 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
1268 }
1269 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
1270 print '<tr><td>';
1271 $maxfilesizearray = getMaxFileSizeArray();
1272 $maxmin = $maxfilesizearray['maxmin'];
1273 if ($maxmin > 0) {
1274 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
1275 }
1276 print '<input type="file" class="flat maxwidth200" name="photo" id="photoinput">';
1277 print '</td></tr>';
1278 print '</table>';
1279
1280 print '</td>';
1281 print '</tr>';
1282
1283 print '</table>';
1284
1285 print dol_get_fiche_end();
1286
1287 print $form->buttonsSaveCancel();
1288
1289 print "</form>";
1290 }
1291 }
1292
1293 // Select mail models is same action as presend
1294 if (GETPOST('modelselected', 'alpha')) {
1295 $action = 'presend';
1296 }
1297
1298 // View mode
1299 if (!empty($id) && $action != 'edit' && $action != 'create') {
1300 $objsoc = new Societe($db);
1301
1302 // Show errors
1303 dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
1304
1305 print dol_get_fiche_head($head, 'card', $title, -1, 'contact');
1306
1307 if ($action == 'create_user') {
1308 // Full firstname and lastname separated with a dot : firstname.lastname
1309 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1310 $login = dol_buildlogin($object->lastname, $object->firstname);
1311
1312 $generated_password = '';
1313 if (empty($ldap_sid)) { // TODO ldap_sid ?
1314 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1315 $generated_password = getRandomPassword(false);
1316 }
1317 $password = $generated_password;
1318
1319 // Create a form array
1320 $formquestion = array(
1321 array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
1322 array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
1323 //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')))
1324 );
1325 $text = $langs->trans("ConfirmCreateContact").'<br>';
1326 if (isModEnabled("societe")) {
1327 if ($object->socid > 0) {
1328 $text .= $langs->trans("UserWillBeExternalUser");
1329 } else {
1330 $text .= $langs->trans("UserWillBeInternalUser");
1331 }
1332 }
1333 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
1334 }
1335
1336 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1337
1338 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
1339 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1340 $morehtmlref .= '</a>';
1341
1342 $morehtmlref .= '<div class="refidno">';
1343 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
1344 $objsoc->fetch($object->socid);
1345 // Thirdparty
1346 if ($objsoc->id > 0) {
1347 $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
1348 } else {
1349 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
1350 }
1351 }
1352 $morehtmlref .= '</div>';
1353
1354 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
1355
1356
1357 print '<div class="fichecenter">';
1358 print '<div class="fichehalfleft">';
1359
1360 print '<div class="underbanner clearboth"></div>';
1361 print '<table class="border tableforfield" width="100%">';
1362
1363 // Civility
1364 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
1365 print $object->getCivilityLabel();
1366 print '</td></tr>';
1367
1368 // Job / position
1369 print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
1370
1371 // Email
1372 if (isModEnabled('mailing')) {
1373 $langs->load("mails");
1374 print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
1375 print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
1376 }
1377
1378 // Unsubscribe opt-out
1379 if (isModEnabled('mailing')) {
1380 $result = $object->getNoEmail();
1381 if ($result < 0) {
1382 setEventMessages($object->error, $object->errors, 'errors');
1383 }
1384 print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
1385 if ($object->email) {
1386 print yn($object->no_email);
1387 } else {
1388 print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
1389 }
1390 print '</td></tr>';
1391 }
1392
1393 // Default language
1394 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1395 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1396 print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
1397 //$s=picto_from_langcode($object->default_lang);
1398 //print ($s?$s.' ':'');
1399 $langs->load("languages");
1400 $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
1401 print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
1402 print $labellang;
1403 print '</td></tr>';
1404 }
1405
1406 print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
1407 print $object->LibPubPriv($object->priv);
1408 print '</td></tr>';
1409
1410 print '</table>';
1411 print '</div>';
1412
1413 $object->fetch_thirdparty();
1414
1415
1416 print '<div class="fichehalfright">';
1417
1418 print '<div class="underbanner clearboth"></div>';
1419 print '<table class="border tableforfield centpercent">';
1420
1421
1422 if (getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) {
1423 if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
1424 // Level of prospect
1425 print '<tr><td class="titlefield">';
1426 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1427 print $langs->trans('ProspectLevel');
1428 print '<td>';
1429 if ($action != 'editlevel' && $user->hasRight('societe', 'contact', 'creer')) {
1430 print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
1431 }
1432 print '</tr></table>';
1433 print '</td><td>';
1434 if ($action == 'editlevel') {
1435 $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
1436 } else {
1437 print $object->getLibProspLevel();
1438 }
1439 print "</td>";
1440 print '</tr>';
1441
1442 // Status of prospection
1443 $object->loadCacheOfProspStatus();
1444 print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
1445 print ' &nbsp; &nbsp; ';
1446 print '<div class="floatright">';
1447 foreach ($object->cacheprospectstatus as $key => $val) {
1448 $titlealt = 'default';
1449 if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1450 $titlealt = $val['label'];
1451 }
1452 if ($object->stcomm_id != $val['id']) {
1453 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>';
1454 }
1455 }
1456 print '</div></td></tr>';
1457 }
1458 }
1459
1460 // Categories
1461 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1462 print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td>';
1463 print '<td>';
1464 print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
1465 print '</td></tr>';
1466 }
1467
1468 // Contact by default for
1469 if (!empty($object->socid)) {
1470 print '<tr><td class="titlefield">'.$langs->trans("ContactByDefaultFor").'</td>';
1471 print '<td>';
1472 print $formcompany->showRoles("roles", $object, 'view', $object->roles, '');
1473 print '</td></tr>';
1474 }
1475
1476 // Other attributes
1477 $parameters = array('socid' => $socid);
1478 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1479
1480 $object->load_ref_elements();
1481
1482 if (isModEnabled("propal")) {
1483 print '<tr><td class="titlefield tdoverflow">'.$langs->trans("ContactForProposals").'</td><td>';
1484 print $object->ref_propal ? $object->ref_propal : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'<span>';
1485 print '</td></tr>';
1486 }
1487
1488 if (isModEnabled('order') || isModEnabled("shipping")) {
1489 print '<tr><td class="titlefield tdoverflow">';
1490 if (isModEnabled("shipping")) {
1491 print $langs->trans("ContactForOrdersOrShipments");
1492 } else {
1493 print $langs->trans("ContactForOrders");
1494 }
1495 print '</td><td>';
1496 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>';
1497 if (isModEnabled("shipping")) {
1498 $none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrderOrShipments").'</span>';
1499 }
1500 print $object->ref_commande ? $object->ref_commande : $none;
1501 print '</td></tr>';
1502 }
1503
1504 if (isModEnabled('contract')) {
1505 print '<tr><td class="tdoverflow">'.$langs->trans("ContactForContracts").'</td><td>';
1506 print $object->ref_contrat ? $object->ref_contrat : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>';
1507 print '</td></tr>';
1508 }
1509
1510 if (isModEnabled('invoice')) {
1511 print '<tr><td class="tdoverflow">'.$langs->trans("ContactForInvoices").'</td><td>';
1512 print $object->ref_facturation ? $object->ref_facturation : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>';
1513 print '</td></tr>';
1514 }
1515
1516 print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td>';
1517 if ($object->user_id) {
1518 $dolibarr_user = new User($db);
1519 $result = $dolibarr_user->fetch($object->user_id);
1520 print $dolibarr_user->getLoginUrl(-1);
1521 } else {
1522 //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
1523 if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
1524 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>';
1525 }
1526 }
1527 print '</td></tr>';
1528
1529 print "</table>";
1530
1531 print '</div></div>';
1532 print '<div class="clearboth"></div>';
1533
1534 print dol_get_fiche_end();
1535
1536 /*
1537 * Action bar
1538 */
1539 print '<div class="tabsAction">';
1540
1541 $parameters = array();
1542 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1543 if (empty($reshook) && $action != 'presend') {
1544 if (empty($user->socid)) {
1545 if (!empty($object->email)) {
1546 $langs->load("mails");
1547 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>';
1548 } else {
1549 $langs->load("mails");
1550 print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
1551 }
1552 }
1553
1554 if ($user->hasRight('societe', 'contact', 'creer')) {
1555 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
1556 }
1557
1558 // Activer
1559 if ($object->statut == 0 && $user->hasRight('societe', 'contact', 'creer')) {
1560 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
1561 }
1562 // Desactiver
1563 if ($object->statut == 1 && $user->hasRight('societe', 'contact', 'creer')) {
1564 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
1565 }
1566
1567 // Delete
1568 if ($user->hasRight('societe', 'contact', 'supprimer')) {
1569 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'));
1570 }
1571 }
1572
1573 print "</div>";
1574
1575 //Select mail models is same action as presend
1576 if (GETPOST('modelselected')) {
1577 $action = 'presend';
1578 }
1579
1580 if ($action != 'presend') {
1581 print '<div class="fichecenter"><div class="fichehalfleft">';
1582
1583 print '</div><div class="fichehalfright">';
1584
1585 $MAXEVENT = 10;
1586
1587 $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
1588
1589 // List of actions on element
1590 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1591 $formactions = new FormActions($db);
1592 $somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
1593
1594 print '</div></div>';
1595 }
1596
1597 // Presend form
1598 $modelmail = 'contact';
1599 $defaulttopic = 'Information';
1600 $diroutput = $conf->societe->dir_output.'/contact/';
1601 $trackid = 'ctc'.$object->id;
1602
1603 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1604 }
1605}
1606
1607
1608llxFooter();
1609
1610$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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_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.
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)
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)
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.
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_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 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.
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.