dolibarr/htdocs/contact/card.php
VIAL-GOUTEYRON Quentin ea54342891
NEW Drag and drop a file on the 23 remaining cards (#39473)
* FIX Drag and drop of a file reports a wrong error, or none at all

The error handler of dragAndDropFileUpload() had three defects that all end on
the user believing the file was attached when it was not.

 - The first assignment of the message was dead code, there was no return after
   the test on the http code 403, so a refusal was reported as a generic error.
 - The key ErrorUploadPermissionDenied it used exists in no language file, so
   the raw key was shown.
 - JSON.parse() was called with no try/catch on an answer that is not always a
   json, a fatal error of the endpoint or a request over post_max_size for
   example. The exception left the user on a page with no message at all.
 - An empty list of files was treated as a success, while it means the endpoint
   stored nothing.

The value of PHP_SELF is also escaped before it is written into the 6 generated
javascript strings. It holds the path info of the request on a server that
accepts it, so it is a user input. dol_escape_js() is called with the mode that
escapes a double quote by a double quote, the strings being delimited by double
quotes, and the sequence '</' is escaped too because the function does not do it
and the path info could otherwise close the script tag and open one of its own.

Adds the key ErrorOnAtLeastOneFileUpload to en_US, used when some files of a
batch failed and some did not.

* FIX getMultidirOutput returns a directory the Documents tab does not read

Four defects of the same function, all ending on a file stored where the user
will never see it, or written outside the documents directory.

 - The ref of the project of a task was only passed through dol_sanitizePathName(),
   which keeps a slash, a colon and the accented chars, while projet/tasks/document.php
   sanitizes it with dol_sanitizeFileName(). A project ref holding a slash even
   created an extra level of directory. Measured on real databases: 304 projects
   over 330 hold a slash on one of them, carrying 701 tasks over 824.
 - The same case calls $object->fetchProject() with no guard, while the signature
   of the function accepts an object that is not a CommonObject, and even a null
   when a module is given. Such a caller gets a fatal error where it expects the
   error string. No core caller is in that case today, an external module or a
   hook can be.
 - The entity of the object may have no declared directory, an object shared by
   another entity for example. The undefined index returned a relative path, so
   the caller read or wrote under the web root. The current entity is used
   instead, and the fallback is logged because the directory is then not the one
   of the entity of the object, which matters for a caller that deletes files.
 - When the current entity has no declared directory either, the fallback
   returned the sub directory alone, again a relative path. The same error than
   for a module that declares no directory at all is now returned.

Adds the sub directory of a partnership and of a stock transfer, which their own
document tabs already read.

* FIX getElementProperties answers wrong properties for 9 elements

A customer payment, a supplier payment, a various payment, a stock transfer and
the 4 objects of the hrm module had no properties at all, or wrong ones, so any
caller that resolves a class, a table or a document directory from an element
failed on them.

 - payment, payment_supplier and payment_various had no branch. The branch of a
   customer payment tests $elementType and not $element, because the rule on the
   elements named myobject_mysubobject rewrites $element to 'payment' for
   'payment_salary' too, which is stored somewhere else.
 - job, position, skill and evaluation answered a wrong table (hrm_job_user for
   a position, and so on) and no sub directory, while their document tabs read
   one named after the element.
 - stocktransfer answered an empty classname, because it is not the ucfirst() of
   the element, so a caller doing new $classname($db) ended on a fatal error.
 - The sub directory was concatenated even when the module is disabled and the
   directory is empty, which answered a path at the root of the file system.
 - A contact and a conference are stored into a sub directory their tab reads.

isModEnabled('invoice') is tested for a customer payment: there is no module
named 'compta', so testing it was always false, while $conf->compta->payment is
set unconditionally by Conf::setValues() and could not be used as a proxy.

* FIX Access refused to everyone on 11 objects of the core

restrictedArea() and checkUserAccessToObject() refuse the access to objects that
no permission and no rule can match, whatever the user, an administrator
included.

 - The hrm module declares no permission at its first level, only 'all', and the
   stocktransfer module only 'stocktransfer'. A check on the module itself
   therefore tests a permission that does not exist. The mapping is the same one
   as into User::hasRight().
 - The module of an event organization declares no permission at all, its whole
   permission block being commented out on purpose, and its cards check the
   parent project instead. The feature is mapped onto that project, with the two
   guards the card has: an external user is refused, and so is a conference with
   no parent project, whose id of 0 would otherwise grant an access with no check
   on the record at all.
 - The default rule of checkUserAccessToObject() builds its sql on the columns
   entity and fk_soc of the table. llx_asset, llx_paiement, llx_paiementfourn and
   llx_workstation_workstation have no fk_soc, and llx_hrm_job, llx_hrm_job_user
   and llx_hrm_skill have neither. The sql failed, so the access was refused to
   every user this rule applies to. These tables are now checked on their entity
   only, which is what the $check rule already does for the same class of tables,
   and the 3 tables of hrm can be checked on nothing at all. The rule is selected
   on the table and not on the element, because $object is an id and not an
   object for most of the callers, the cards of an asset and of a workstation
   included, which are broken today for any user without the permission to see
   all third parties.
 - An external user is refused explicitly on those tables: none of these objects
   is linked to a third party, so the default rule refused him through a link
   that does not exist, and the rules that replace it do not look at the third
   party of the user at all.

Measured on a vanilla instance with 5 profiles, an administrator, an internal
user with every right, one without the permission to see all third parties, one
that is not a sales representative of the third party of the object, and an
external user: the 11 objects go from refused to granted for the internal users
and stay refused for the external one, and the 26 other elements answer exactly
the same for the 5 profiles.

* FIX A file dropped on a card is lost, or reported as refused when it was stored

FileUpload stores the file into a directory that the "Attached files" tab of the
object never reads, so the user attaches a file that no screen will ever show,
and nothing is indexed in database to find it back. Measured on real databases:
216487 thirdparties over 216887 and 157852 products over 280319 are in that case
on the cards that already enable the drag and drop.

 - The directory of the object is now forged with get_exdir(), the way the tabs
   do: it always uses the id for a thirdparty, whose ref is a company name and is
   not unique, and it falls back on the id when the ref is empty. The sub
   directory of the module is read with getMultidirOutput(), which knows the
   elements that store their documents into one. That function does not return
   an empty string when it fails but a string starting with 'error-', so only an
   absolute path is accepted: writing into that string would create the files
   under the web root.
 - fetchObjectByElement() returns an object even when fetch() returned 0. The
   object was then not loaded, and the file was stored at the root of the
   directory of the module, out of any object. The constructor now throws, and
   the endpoint answers the error with the same json contract than a successful
   call so that the caller can show it, instead of a fatal error and an http 500.
 - An attachment of the same name was silently overwritten, dol_move_uploaded_file()
   being called with $allowoverwrite = 1 while the name was checked before the
   ref of the object was added as a prefix. The check is done again on the final
   name, and on the .noexe suffixed name too, which that function appends to an
   executable file.
 - An executable file was renamed with that .noexe suffix and then reported as an
   error, while it was correctly stored.
 - The endpoint called restrictedArea() with an empty feature when the element is
   unknown, and the loop of that function then takes no branch at all and grants
   the access with no check. It refuses before, with the same http code and the
   same message than a refusal, so that a user cannot tell an object that exists
   but is not allowed from an object that does not exist. The refusal of an
   external user on an object of another third party answered a message of its
   own, which allowed the same enumeration.

Comes with the tests of the path resolution, of the fallback of get_exdir(), of
the rejection of the error string of getMultidirOutput(), and of the file name
deduplication.

* FIX Remove the drop area from 13 cards where dropping a file is harmful

Two distinct groups, both of them removing a drop area that only produces a
result the user does not want.

7 pages have no "Attached files" tab at all, so a file dropped on them can be
reached by no screen: a fiscal year and its info page, an accounting model, a
webhook trigger history, an intracomm report, a bookcal calendar and its booking
list. Measured: 4 of them accepted the upload and wrote an orphan file, the
accounting model wrote it at the root of the directory of the module, out of any
object, and the 2 bookcal ones answered an http 500.

6 cards print their tabs inside their edit form, so the drop area covered that
form: a product, an expense report, a VAT payment, a social contribution, a loan
and a salary. Dropping a file there reloads the page, which discards what the
user is typing. A product and an expense report have a second call for the read
only view, so the drop area is only removed from the call of the edit branch;
the 4 others share a single call between both views, so the parameter is now
conditional.

* NEW Drag and drop a file on the 23 remaining cards

Every card of the core that owns an "Attached files" tab can now receive a file
by drag and drop, which was the case of 32 of them only. The 23 added here are
an asset, an event, a various payment, a customer payment, a contact, a donation,
a conference or booth, a shipment, a supplier payment, a leave request, an
evaluation, a job, a position, a skill, a knowledge record, a manufacturing
order, a partnership, a lot, a stock transfer, a task, a reception, a resource
and a workstation.

The tab bar of a leave request and of a resource is printed inside their edit
form, so the drop area is not enabled there: dropping a file reloads the page,
which would discard what the user is typing. The card of a supplier payment
prints its tab bar even when the object was not loaded, so the drop area is only
enabled when it is.

* FIX getMultidirOutput refuses an entity with no directory instead of falling back [skip-claudemd]

The previous revision of this PR fell back on the directory of the current
entity when the entity of the object had none, with a LOG_WARNING. On a
multicompany install that made a caller read, write and above all delete
files in the directory of another entity. Refuse instead: the function
already answers 'error-diroutput-not-defined-for-this-object' when the
module declares no directory at all, so the caller has one behaviour to
handle, not two.

The entity is cast to int, which is what the array index needs and what
silences the four PhanTypeMismatchDimFetchNullable this function reported.

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-08-19 02:46:21 +02:00

1671 lines
67 KiB
PHP

<?php
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2020-2026 Open-Dsi <support@open-dsi.fr>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/contact/card.php
* \ingroup societe
* \brief Card of a contact
*/
// Load Dolibarr environment
require '../main.inc.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var ExtraFields $extrafields
* @var HookManager $hookmanager
* @var Societe $mysoc
* @var Translate $langs
* @var User $user
*/
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
$error = 0;
$errors = array();
// Get parameters
$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
$confirm = GETPOST('confirm', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$id = GETPOSTINT('id');
$socid = GETPOSTINT('socid');
// Initialize a technical object
$object = new Contact($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$socialnetworks = getArrayOfSocialNetworks();
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$object->getCanvas($id);
$objcanvas = null;
$canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
if (!empty($canvas)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
$objcanvas = new Canvas($db, $action);
$objcanvas->getCanvas('contact', 'contactcard', $canvas);
}
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
$hookmanager->initHooks(array('contactcard', 'globalcard'));
if ($id > 0) {
$object->fetch($id);
$object->info($id);
}
if (!($object->id > 0) && $action == 'view') {
$langs->load("errors");
print($langs->trans('ErrorRecordNotFound'));
exit;
}
$triggermodname = 'CONTACT_MODIFY';
$permissiontoadd = $user->hasRight('societe', 'contact', 'creer');
$permissiontoeditextra = $permissiontoadd;
if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
// For action 'update_extras', is there a specific permission set for the attribute to update
$permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
}
// Security check
if ($user->socid) {
$socid = $user->socid;
}
if ($object->priv && $object->user_creation_id != $user->id) {
accessforbidden();
}
$result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
/*
* Actions
*/
$parameters = array('id' => $id, 'objcanvas' => $objcanvas);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
$backurlforlist = DOL_URL_ROOT.'/contact/list.php';
if (empty($backtopage) || ($cancel && empty($id))) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
$backtopage = $backurlforlist;
} else {
$backtopage = DOL_URL_ROOT.'/contact/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
}
}
}
if ($cancel) {
if (!empty($backtopageforcancel)) {
header("Location: ".$backtopageforcancel);
exit;
} elseif (!empty($backtopage)) {
header("Location: ".$backtopage);
exit;
}
$action = '';
}
// Create user from contact
if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->hasRight('user', 'user', 'creer')) {
// Recuperation contact actuel
$result = $object->fetch($id);
if ($result > 0) {
$db->begin();
// Creation user
$nuser = new User($db);
$result = $nuser->create_from_contact($object, GETPOST("login")); // Do not use GETPOST(alpha)
if ($result > 0) {
$result2 = $nuser->setPassword($user, GETPOST("password"), 0, 0, 1); // Do not use GETPOST(alpha)
if (is_int($result2) && $result2 < 0) {
$error = $nuser->error;
$errors = $nuser->errors;
$db->rollback();
} else {
$db->commit();
}
} else {
$error = $nuser->error;
$errors = $nuser->errors;
$db->rollback();
}
if ($error) {
setEventMessage($langs->trans('ImpossibleToCreateUserFromContact').' : '.$nuser->errorsToString(), 'errors');
}
} else {
$error = $object->error;
$errors = $object->errors;
}
}
// Confirmation deactivation
if ($action == 'disable' && $permissiontoadd) {
$object->fetch($id);
if ($object->setstatus(0) < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation activation
if ($action == 'enable' && $permissiontoadd) {
$object->fetch($id);
if ($object->setstatus(1) < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Add contact
if ($action == 'add' && $permissiontoadd) {
$db->begin();
if ($canvas) {
$object->canvas = $canvas;
}
$object->entity = ((GETPOSTISSET('entity') && GETPOST('entity') != '') ? GETPOSTINT('entity') : $conf->entity);
$object->socid = $socid;
$object->lastname = (string) GETPOST("lastname", 'alpha');
$object->firstname = (string) GETPOST("firstname", 'alpha');
$object->civility_code = (string) GETPOST("civility_code", 'alpha');
$object->poste = (string) GETPOST("poste", 'alpha');
$object->address = (string) GETPOST("address", 'alpha');
$object->zip = (string) GETPOST("zipcode", 'alpha');
$object->town = (string) GETPOST("town", 'alpha');
$object->country_id = GETPOSTINT("country_id");
$object->state_id = GETPOSTINT("state_id");
$object->socialnetworks = array();
if (isModEnabled('socialnetworks')) {
foreach ($socialnetworks as $key => $value) {
if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
$object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
}
}
}
$object->email = (string) GETPOST('email', 'email');
$object->no_email = GETPOSTINT("no_email");
$object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
$object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
$object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
$object->fax = (string) GETPOST("fax", 'alpha');
$object->priv = GETPOSTINT("priv");
$object->note_public = (string) GETPOST("note_public", 'restricthtml');
$object->note_private = (string) GETPOST("note_private", 'restricthtml');
$object->roles = GETPOST("roles", 'array'); // Suppose this is proper array, ideally verified @phpstan-ignore assign.propertyType
$object->status = 1; //Default status to Actif
$object->statut = 1; //Default status to Actif
// Note: Correct date should be completed with location to have exact GM time of birth.
$object->birthday = dol_mktime(0, 0, 0, GETPOSTINT("birthdaymonth"), GETPOSTINT("birthdayday"), GETPOSTINT("birthdayyear"));
$object->birthday_alert = (GETPOST('birthday_alert', 'alpha') == "on" ? 1 : 0);
//Default language
$object->default_lang = GETPOST('default_lang');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) {
$error++;
$action = 'create';
}
if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && $object->no_email == -1 && !empty($object->email)) {
$error++;
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
$action = 'create';
}
if (!empty($object->email) && !isValidEmail($object->email)) {
$langs->load("errors");
$error++;
$errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
$action = 'create';
}
if (empty($object->lastname)) {
$error++;
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
$action = 'create';
}
if (empty($error)) {
$id = $object->create($user);
if ($id <= 0) {
$error++;
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
$action = 'create';
}
}
if (empty($error)) {
// Categories association
$contcats = GETPOST('contcats', 'array');
if (count($contcats) > 0) {
$result = $object->setCategories($contcats);
if ($result <= 0) {
$error++;
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
$action = 'create';
}
}
}
if (empty($error) && isModEnabled('mailing') && !empty($object->email)) {
// Add mass emailing flag into table mailing_unsubscribe
$result = $object->setNoEmail($object->no_email);
if ($result < 0) {
$error++;
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
$action = 'create';
}
}
if (empty($error) && $id > 0) {
$db->commit();
if (!empty($backtopage)) {
$url = str_replace('__ID__', (string) $id, $backtopage);
} else {
$url = 'card.php?id='.$id;
}
header("Location: ".$url);
exit;
} else {
$db->rollback();
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'contact', 'supprimer')) {
$result = $object->fetch($id);
$object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
$result = $object->delete($user);
if ($result > 0) {
setEventMessages("RecordDeleted", null, 'mesgs');
if ($backurlforlist) {
header("Location: ".$backurlforlist);
exit;
} else {
header("Location: ".DOL_URL_ROOT.'/contact/list.php');
exit;
}
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Merge a contact into the current one. As on the third party card, the confirmation popup submits
// with a GET, the request being protected by the CSRF token of main.inc.php. All the permission and
// perimeter checks on the two contacts are done by Contact::mergeContact() itself.
if ($action == 'confirm_merge' && $confirm == 'yes' && $permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
$contact_origin_id = GETPOSTINT('contact_origin');
if ($contact_origin_id <= 0) {
$langs->load('errors');
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('MergeOriginContact')), null, 'errors');
} else {
// fetch() returns the id when found, 2 when several records were found, 0 when not found
// and -1 on error: a plain "<= 0" test would report an empty error on the not found case
$result = $object->fetch($id);
if ($result == 0) {
$langs->load('errors');
setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
} elseif ($result != $id) {
$langs->load('errors');
setEventMessages($object->error ? $object->error : $langs->trans('ErrorBadParameters'), $object->errors, 'errors');
} elseif ($object->mergeContact($contact_origin_id) < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
setEventMessages($langs->trans('ContactsMergeSuccess'), null, 'mesgs');
// The merge is committed, but the files are moved afterwards and may have failed
if (!empty($object->warnings)) {
setEventMessages(null, $object->warnings, 'warnings');
}
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$object->id);
exit;
}
}
}
if ($action == 'update' && empty($cancel) && $permissiontoadd) {
if (!GETPOST("lastname", 'alpha')) {
$error++;
$errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$action = 'edit';
}
if (isModEnabled('mailing') && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2 && GETPOSTINT("no_email") == -1 && !empty(GETPOST('email', 'email'))) {
$error++;
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
$action = 'edit';
}
if (!empty(GETPOST('email', 'email')) && !isValidEmail(GETPOST('email', 'email'))) {
$langs->load("errors");
$error++;
$errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
$action = 'edit';
}
if (!$error) {
$contactid = GETPOSTINT("contactid");
$object->fetch($contactid);
$object->fetchRoles();
// Photo save
$dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity]."/contact/".$object->id."/photos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if (GETPOST('deletephoto') && $object->photo) {
$fileimg = $dir.'/'.$object->photo;
$dirthumbs = $dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
$object->photo = '';
}
if ($file_OK) {
if (image_format_supported($_FILES['photo']['name']) > 0) {
dol_mkdir($dir);
if (@is_dir($dir)) {
$newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
if (!($result > 0)) {
$errors[] = "ErrorFailedToSaveFile";
} else {
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
// Create thumbs
$object->addThumbs($newfile);
}
}
} else {
$errors[] = "ErrorBadImageFormat";
}
} else {
switch ($_FILES['photo']['error']) {
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
$errors[] = "ErrorFileSizeTooLarge";
break;
case 3: //uploaded file was only partially uploaded
$errors[] = "ErrorFilePartiallyUploaded";
break;
}
}
$object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
$object->socid = $socid;
$object->lastname = (string) GETPOST("lastname", 'alpha');
$object->firstname = (string) GETPOST("firstname", 'alpha');
$object->civility_code = (string) GETPOST("civility_code", 'alpha');
$object->poste = (string) GETPOST("poste", 'alpha');
$object->address = (string) GETPOST("address", 'alpha');
$object->zip = (string) GETPOST("zipcode", 'alpha');
$object->town = (string) GETPOST("town", 'alpha');
$object->state_id = GETPOSTINT("state_id");
$object->country_id = GETPOSTINT("country_id");
$object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
$object->no_email = GETPOSTINT("no_email");
$object->socialnetworks = array();
if (isModEnabled('socialnetworks')) {
foreach ($socialnetworks as $key => $value) {
if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
$object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
}
}
}
$object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
$object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
$object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
$object->fax = (string) GETPOST("fax", 'alpha');
$object->priv = GETPOSTINT("priv");
$object->note_public = (string) GETPOST("note_public", 'restricthtml');
$object->note_private = (string) GETPOST("note_private", 'restricthtml');
// Suppose this is proper array, ideally verified @phpstan-ignore-next-line assign.propertyType
$object->roles = GETPOST("roles", 'array'); // Note GETPOSTISSET("role") is null when combo is empty
//Default language
$object->default_lang = GETPOST('default_lang');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
if ($ret < 0) {
$error++;
}
if (!$error) {
$result = $object->update($contactid, $user);
if ($result > 0) {
// Categories association
$categories = GETPOST('contcats', 'array');
$object->setCategories($categories);
// Update mass emailing flag into table mailing_unsubscribe
if (GETPOSTISSET('no_email') && $object->email) {
$no_email = GETPOSTINT('no_email');
$result = $object->setNoEmail($no_email);
if ($result < 0) {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
} else {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
if (!$error && empty($errors)) {
if (!empty($backtopage)) {
header("Location: ".$backtopage);
exit;
}
$action = 'view';
} else {
$action = 'edit';
}
}
if ($action == 'setprospectcontactlevel' && $permissiontoadd) {
$object->fetch($id);
$object->fk_prospectlevel = GETPOST('prospect_contact_level_id', 'alpha');
$result = $object->update($object->id, $user);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
// set communication status
if ($action == 'setstcomm' && $permissiontoadd) {
$object->fetch($id);
$object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
$result = $object->update($object->id, $user);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Update extrafields
if ($action == 'update_extras' && $permissiontoeditextra) {
$object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
$attribute_name = GETPOST('attribute', 'aZ09');
// Fill array 'array_options' with data from update form
$ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
if ($ret < 0) {
$error++;
}
if (!$error) {
$result = $object->updateExtraField($attribute_name, 'CONTACT_MODIFY');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
if ($error) {
$action = 'edit_extras';
}
}
// Actions to send emails
$triggersendname = 'CONTACT_SENTBYMAIL';
$paramname = 'id';
$mode = 'emailfromcontact';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
}
/*
* View
*/
$form = new Form($db);
$formadmin = new FormAdmin($db);
$formcompany = new FormCompany($db);
$objsoc = new Societe($db);
if ($socid > 0) {
$objsoc->fetch($socid);
}
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
$title = $object->lastname;
}
if (empty($object->id)) {
$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
}
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card');
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
if (empty($object->error) && $id) {
$object = new Contact($db);
$result = $object->fetch($id);
if ($result <= 0) {
dol_print_error(null, $object->error);
}
}
$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
$objcanvas->display_canvas($action); // Show template
} else {
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
// Confirm deleting contact
if ($user->hasRight('societe', 'contact', 'supprimer')) {
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
}
}
// Confirm merging contact
if ($action == 'merge' && $permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
// The current contact is excluded with the $filter parameter and not with $exclude, the latter
// being applied by selectcontacts() only when it receives an array while the ajax branch gives
// it a string. With CONTACT_USE_SEARCH_TO_SELECT the exclusion is lost anyway, contact/ajax
// /contact.php overwriting the filter it receives: merging a contact into itself is then refused
// by mergeContact() instead. The third party is shown to tell homonyms apart.
$formquestion = array(
array(
'name' => 'contact_origin',
'label' => $langs->trans("MergeOriginContact"),
'type' => 'other',
'value' => $form->select_contact(0, '', 'contact_origin', 1, '', '', 1, 'minwidth200', false, 1, 0, array(), '', '', '', '(sp.rowid:!=:'.((int) $id).')')
)
);
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("MergeContacts"), $langs->trans("ConfirmMergeContacts"), "confirm_merge", $formquestion, 'no', 1, 300);
}
/*
* Onglets
*/
$head = array();
if ($id > 0) {
// Si edition contact deja existent
$object = new Contact($db);
$res = $object->fetch($id, $user);
if ($res < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
$object->fetchRoles();
// Show tabs
$head = contact_prepare_head($object);
}
if ($user->hasRight('societe', 'contact', 'creer')) {
if ($action == 'create') {
/*
* Card in create mode
*/
$object->canvas = $canvas;
$object->state_id = GETPOSTINT("state_id");
// We set country_id, country_code and label for the selected country
$object->country_id = GETPOST("country_id") ? GETPOSTINT("country_id") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
if ($object->country_id) {
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
$linkback = '';
print load_fiche_titre($title, $linkback, 'address');
// Show errors
dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
if ($conf->use_javascript_ajax) {
print "\n".'<script type="text/javascript">'."\n";
print 'jQuery(document).ready(function () {
jQuery("#selectcountry_id").change(function() {
document.formsoc.action.value="create";
document.formsoc.submit();
});
$("#copyaddressfromsoc").click(function() {
$(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
$(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
$(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
$(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
/* set country at end because it will trigger page refresh */
console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
$(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
});
})'."\n";
print '</script>'."\n";
}
print '<form method="post" name="formsoc" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if (!empty($objsoc)) {
print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
}
print dol_get_fiche_head($head, 'card', '', 0, '');
print '<table class="border centpercent">';
// Name
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname", 'alpha') ? GETPOST("lastname", 'alpha') : $object->lastname).'" autofocus="autofocus"></td>';
print '</tr>';
// Firstname
print '<tr>';
print '<td><label for="firstname">';
print $form->textwithpicto($langs->trans("Firstname"), $langs->trans("KeepEmptyIfGenericAddress")).'</label></td>';
print '<td colspan="3"><input name="firstname" id="firstname"type="text" class="minwidth200" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname", 'alpha') ? GETPOST("firstname", 'alpha') : $object->firstname).'"></td>';
print '</tr>';
// Company
if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
if ($socid > 0) {
print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
print '<td colspan="3" class="maxwidthonsmartphone">';
print $objsoc->getNomUrl(1, 'contact');
print '</td>';
print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
print '</td></tr>';
} else {
print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($socid, 'socid', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
print '</td></tr>';
}
}
// Civility
if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
print '</td></tr>';
}
// Job position
print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
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>';
$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
$colspan = 3;
if ($conf->use_javascript_ajax && $socid > 0) {
$colspan = 2;
}
// Address
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->address)) == 0) {
$object->address = $objsoc->address; // Predefined with third party
}
print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
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>';
if ($conf->use_javascript_ajax && $socid > 0) {
$rowspan = 3;
if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
$rowspan++;
}
print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
print '</td>';
}
print '</tr>';
// Zip / Town
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->zip)) == 0) {
$object->zip = $objsoc->zip; // Predefined with third party
}
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->town)) == 0) {
$object->town = $objsoc->town; // Predefined with third party
}
print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
print '</td></tr>';
// Country
print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
print $form->select_country((GETPOSTISSET("country_id") ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td></tr>';
// State
if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
} else {
print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
}
if ($object->country_id) {
print img_picto('', 'state', 'class="pictofixedwidth"');
print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
} else {
print $countrynotdefined;
}
print '</td></tr>';
}
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->phone_pro)) == 0) {
$object->phone_pro = $objsoc->phone; // Predefined with third party
}
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->fax)) == 0) {
$object->fax = $objsoc->fax; // Predefined with third party
}
// Phone / Fax
print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
print '</td>';
print '</tr>';
print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150 widthcentpercentminusx');
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150 widthcentpercentminusx');
print '</td>';
print '</tr>';
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->email)) == 0) {
$object->email = $objsoc->email; // Predefined with third party
}
// Email
print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
print '<td>';
print img_picto('', 'object_email', 'class="pictofixedwidth"');
print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
print '</tr>';
// Unsubscribe
if (isModEnabled('mailing')) {
if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
print "\n".'<script type="text/javascript">'."\n";
print '$(document).ready(function () {
$("#email").keyup(function() {
if ($(this).val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
});
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<tr>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>';
// Default value is in MAILING_CONTACT_DEFAULT_BULK_STATUS that you can modify in setup of module emailing
print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS')), 1, false, (int) (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2));
print '</td>';
print '</tr>';
}
// Social network
if (isModEnabled('socialnetworks')) {
$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
$object->showSocialNetwork($socialnetworks, $colspan);
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
}
// Visibility
print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
$selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ? GETPOST("priv", 'alpha') : $object->priv), 0);
print '</td></tr>';
// Default language
if (getDolGlobalInt('MAIN_MULTILANGS')) {
print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, array(), 1, 0, 0, 'maxwidth200 widthcentpercentminusx');
print '</td>';
print '</tr>';
}
// Categories
if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', 'parent', 64, 0, 3);
print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), 0, 0, '', 0, '90%');
print "</td></tr>";
}
// Contact by default
if ($socid > 0) {
print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
print '<td colspan="3">';
$contactType = $object->listeTypeContacts('external', 0, 1);
print img_picto('', 'contact', 'class="pictofixedwidth"').$form->multiselectarray('roles', $contactType, array(), 0, 0, '', 0, '90%');
print '</td></tr>';
}
// Other attributes
$parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
print "</table><br>";
print '<hr style="margin-bottom: 20px">';
// Add personal information
print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
print '<table class="border centpercent">';
// Date To Birth
print '<tr><td class="titlefieldcreate"><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td colspan="3">';
$form = new Form($db);
if ($object->birthday) {
print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
} else {
print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
}
print ' &nbsp; <label for="birthday_alert">'.$langs->trans("Alert").'</label> ';
if (!empty($object->birthday_alert)) {
print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
} else {
print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
}
print '</td>';
print '</tr>';
print "</table>";
print dol_get_fiche_end();
print $form->buttonsSaveCancel("Add");
print "</form>";
} elseif ($action == 'edit' && !empty($id)) {
/*
* Card in edit mode
*/
// We set country_id, and country_code label of the chosen country
if (GETPOSTISSET("country_id") || $object->country_id) {
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
$objsoc = new Societe($db);
$objsoc->fetch($object->socid);
// Show errors
dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
if ($conf->use_javascript_ajax) {
print "\n".'<script type="text/javascript">'."\n";
print 'jQuery(document).ready(function () {
jQuery("#selectcountry_id").change(function() {
document.formsoc.action.value="edit";
document.formsoc.submit();
});
$("#copyaddressfromsoc").click(function() {
$(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
$(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
$(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
console.log("Set state_id to '.dol_escape_js((string) $objsoc->state_id).'");
$(\'select[name="state_id"]\').val("'.dol_escape_js((string) $objsoc->state_id).'").trigger("change");
/* set country at end because it will trigger page refresh */
console.log("Set country id to '.dol_escape_js((string) $objsoc->country_id).'");
$(\'select[name="country_id"]\').val("'.dol_escape_js((string) $objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
});
})'."\n";
print '</script>'."\n";
}
print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="contactid" value="'.$object->id.'">';
if (!empty($backtopage)) {
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
}
print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
print '<table class="border centpercent">';
// Ref/ID
if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
print $object->ref;
print '</td></tr>';
}
// Lastname
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
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>';
print '</tr>';
print '<tr>';
// Firstname
print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
print '</tr>';
// Company
if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
print '<td colspan="3" class="maxwidthonsmartphone">';
print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(GETPOSTINT('socid') ? GETPOSTINT('socid') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
print '</td>';
print '</tr>';
}
// Civility
if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
print '</td></tr>';
}
// Job position
print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
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>';
$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
// Address
print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
print '<td colspan="3">';
print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
print '</div><div class="paddingrightonly valignmiddle inline-block">';
if (!empty($conf->use_javascript_ajax)) {
print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
}
print '</div>';
print '</td>';
// Zip / Town
print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
print '</td></tr>';
// Country
print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td></tr>';
// State
if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
if (getDolGlobalString('MAIN_SHOW_REGION_IN_STATE_SELECT') && (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) {
print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
} else {
print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
}
print img_picto('', 'state', 'class="pictofixedwidth"');
print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
print '</td></tr>';
}
// Phone
print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150', 80);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150', 80);
print '</td></tr>';
print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
print '<td>';
print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150', 80);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
print '<td>';
print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150', 80);
print '</td></tr>';
// EMail
print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (int) (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';
print '<td>';
print img_picto('', 'object_email', 'class="pictofixedwidth"');
print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
if (isModEnabled('mailing')) {
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
$langs->load("mails");
print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
print '<td>'.$object->getNbOfEMailings().'</td>';
} else {
print '<td colspan="2"></td>';
}
print '</tr>';
// Unsubscribe
if (isModEnabled('mailing')) {
if ($conf->use_javascript_ajax && getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2) {
print "\n".'<script type="text/javascript">'."\n";
print '
jQuery(document).ready(function () {
function init_check_no_email(input) {
if (input.val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
}
$("#email").keyup(function() {
init_check_no_email($(this));
});
init_check_no_email($("#email"));
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<tr>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>';
$useempty = (getDolGlobalInt('MAILING_CONTACT_DEFAULT_BULK_STATUS') == 2);
print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOSTINT("no_email") : $object->no_email), 1, false, (int) $useempty);
print '</td>';
print '</tr>';
}
// Social network
if (isModEnabled('socialnetworks')) {
$colspan = ($conf->browser->layout == 'phone' ? 2 : 4);
$object->showSocialNetwork($socialnetworks, $colspan);
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
}
// Visibility
print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
$selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
print $form->selectarray('priv', $selectarray, $object->priv, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth150');
print '</td></tr>';
// Default language
if (getDolGlobalInt('MAIN_MULTILANGS')) {
print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
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');
print '</td>';
print '</tr>';
}
// Note Public
print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
$doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);
print '</td></tr>';
// Note Private
print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
$doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);
print '</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td colspan="3">';
print $object->getLibStatut(4);
print '</td></tr>';
// Categories
if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
$arrayselected = array();
print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
print '<td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, '', '', 64, 0, 3);
$c = new Categorie($db);
$cats = $c->containing($object->id, 'contact');
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, 0, 0, '', 0, '90%');
print "</td></tr>";
}
// Contact by default
if (!empty($object->socid)) {
print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
print '<td colspan="3">';
print img_picto('', 'category', 'class="pictofixedwidth"').$formcompany->showRoles("roles", $object, 'edit', $object->roles, '');
print '</td></tr>';
}
// Other attributes
$parameters = array('colspan' => ' colspan="3"', 'cols' => '3', 'colspanvalue' => '3');
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
$object->load_ref_elements();
if (isModEnabled('order')) {
print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
print '</td></tr>';
}
if (isModEnabled("propal")) {
print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
print '</td></tr>';
}
if (isModEnabled('contract')) {
print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
print '</td></tr>';
}
if (isModEnabled('invoice')) {
print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
print '</td></tr>';
}
// Login Dolibarr
print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
if ($object->user_id) {
$dolibarr_user = new User($db);
$result = $dolibarr_user->fetch($object->user_id);
print $dolibarr_user->getLoginUrl(1);
} else {
print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
}
print '</td></tr>';
// Photo
print '<tr>';
print '<td>'.$langs->trans("PhotoFile").'</td>';
print '<td colspan="3">';
if ($object->photo) {
print $form->showphoto('contact', $object);
print "<br>\n";
}
print '<table class="nobordernopadding">';
if ($object->photo) {
print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
}
//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
print '<tr><td>';
$maxfilesizearray = getMaxFileSizeArray();
$maxmin = $maxfilesizearray['maxmin'];
if ($maxmin > 0) {
print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
}
print '<input type="file" class="flat maxwidth200" name="photo" id="photoinput">';
print '</td></tr>';
print '</table>';
print '</td>';
print '</tr>';
print '</table>';
print dol_get_fiche_end();
print $form->buttonsSaveCancel();
print "</form>";
}
}
// Select mail models is same action as presend
if (GETPOST('modelselected', 'alpha')) {
$action = 'presend';
}
// View mode
if (!empty($id) && $action != 'edit' && $action != 'create') {
$objsoc = new Societe($db);
// Show errors
dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
print dol_get_fiche_head($head, 'card', $title, -1, 'contact', 0, '', '', 0, '', 1);
if ($action == 'create_user') {
// Full firstname and lastname separated with a dot : firstname.lastname
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$login = dol_buildlogin($object->lastname, $object->firstname);
$generated_password = '';
if (empty($ldap_sid)) { // TODO ldap_sid ?
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$generated_password = getRandomPassword(false);
}
$password = $generated_password;
// Create a form array
$formquestion = array(
array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
//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')))
);
$text = $langs->trans("ConfirmCreateContact").'<br>';
if (isModEnabled("societe")) {
if ($object->socid > 0) {
$text .= $langs->trans("UserWillBeExternalUser");
} else {
$text .= $langs->trans("UserWillBeInternalUser");
}
}
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
}
$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
$morehtmlref .= '</a>';
$morehtmlref .= '<div class="refidno">';
if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
$objsoc->fetch($object->socid);
// Thirdparty
if ($objsoc->id > 0) {
$morehtmlref .= $objsoc->getNomUrl(1, 'contact');
} else {
$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
}
}
$morehtmlref .= '</div>';
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">';
// Civility
if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
print $object->getCivilityLabel();
print '</td></tr>';
}
// Job / position
print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
// Email
if (isModEnabled('mailing')) {
$langs->load("mails");
print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
print '<td><a class="badge badge-info" href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
}
// Unsubscribe opt-out
if (isModEnabled('mailing')) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
if ($object->email) {
print yn($object->no_email);
} else {
print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
}
print '</td></tr>';
}
// Default language
if (getDolGlobalInt('MAIN_MULTILANGS')) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
//$s=picto_from_langcode($object->default_lang);
//print ($s?$s.' ':'');
$langs->load("languages");
$labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
print $object->LibPubPriv($object->priv, 1);
print '</td></tr>';
print '</table>';
print '</div>';
$object->fetch_thirdparty();
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield centpercent">';
if (getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) {
if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
// Level of prospect
print '<tr><td class="">';
print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
print $langs->trans('ProspectLevel');
print '<td>';
if ($action != 'editlevel' && $user->hasRight('societe', 'contact', 'creer')) {
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
if ($action == 'editlevel') {
$formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, (int) $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
} else {
print $object->getLibProspLevel();
}
print "</td>";
print '</tr>';
// Status of prospection
$object->loadCacheOfProspStatus();
print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
print ' &nbsp; &nbsp; ';
print '<div class="floatright">';
foreach ($object->cacheprospectstatus as $key => $val) {
$titlealt = 'default';
if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
$titlealt = $val['label'];
}
if ($object->stcomm_id != $val['id']) {
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>';
}
}
print '</div></td></tr>';
}
}
// Categories
if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
print '<tr><td class="">'.$langs->trans("Categories").'</td>';
print '<td>';
print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
print '</td></tr>';
}
// Contact by default for
if (!empty($object->socid)) {
print '<tr><td class="">'.$langs->trans("ContactByDefaultFor").'</td>';
print '<td>';
print $formcompany->showRoles("roles", $object, 'view', $object->roles, '');
print '</td></tr>';
}
// Other attributes
$parameters = array('socid' => $socid);
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
$object->load_ref_elements();
if (isModEnabled("propal")) {
print '<tr><td class="">'.$langs->trans("ContactForProposals").'</td><td>';
print $object->ref_propal ? $object->ref_propal : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'<span>';
print '</td></tr>';
}
if (isModEnabled('order') || isModEnabled("shipping")) {
print '<tr><td class="">';
if (isModEnabled("shipping")) {
print $langs->trans("ContactForOrdersOrShipments");
} else {
print $langs->trans("ContactForOrders");
}
print '</td><td>';
$none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>';
if (isModEnabled("shipping")) {
$none = '<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrderOrShipments").'</span>';
}
print $object->ref_commande ? $object->ref_commande : $none;
print '</td></tr>';
}
if (isModEnabled('contract')) {
print '<tr><td class="">'.$langs->trans("ContactForContracts").'</td><td>';
print $object->ref_contrat ? $object->ref_contrat : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>';
print '</td></tr>';
}
if (isModEnabled('invoice')) {
print '<tr><td class="">'.$langs->trans("ContactForInvoices").'</td><td>';
print $object->ref_facturation ? $object->ref_facturation : '<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>';
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td>';
if ($object->user_id) {
$dolibarr_user = new User($db);
$result = $dolibarr_user->fetch($object->user_id);
print $dolibarr_user->getLoginUrl(-1);
} else {
//print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
if (!$object->user_id && $user->hasRight('user', 'user', 'creer')) {
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>';
}
}
print '</td></tr>';
print "</table>";
print '</div></div>';
print '<div class="clearboth"></div>';
print dol_get_fiche_end();
/*
* Action bar
*/
print '<div class="tabsAction">';
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && $action != 'presend') {
if (empty($user->socid)) {
if (!empty($object->email)) {
$langs->load("mails");
print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
} else {
$langs->load("mails");
print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
}
}
if ($user->hasRight('societe', 'contact', 'creer')) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
}
// Activer
if ($object->status == 0 && $user->hasRight('societe', 'contact', 'creer')) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
}
// Desactiver
if ($object->status == 1 && $user->hasRight('societe', 'contact', 'creer')) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
}
// Merge
if ($permissiontoadd && $user->hasRight('societe', 'contact', 'supprimer')) {
print dolGetButtonAction($langs->trans("MergeContacts"), $langs->trans("Merge"), 'danger', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=merge&token='.newToken(), '', $user->hasRight('societe', 'contact', 'supprimer'));
}
// Delete
if ($user->hasRight('societe', 'contact', 'supprimer')) {
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'));
}
}
print "</div>";
//Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
if ($action != 'presend') {
print '<div class="fichecenter"><div class="fichehalfleft">';
print '</div><div class="fichehalfright">';
$MAXEVENT = 10;
$morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
// List of actions on element
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
$formactions = new FormActions($db);
$somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
print '</div></div>';
}
// Presend form
$modelmail = 'contact';
$defaulttopic = 'Information';
$diroutput = $conf->societe->dir_output.'/contact/';
$trackid = 'ctc'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
}
}
llxFooter();
$db->close();