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