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