dolibarr 22.0.5
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
4 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
8 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
11 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
12 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
13 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
14 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36// Load Dolibarr environment
37require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
47require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
48if (isModEnabled('member')) {
49 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
50}
51
60// Load translation files required by the page
61$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
62
63if (isModEnabled('category')) {
64 $langs->load("categories");
65}
66if (isModEnabled('incoterm')) {
67 $langs->load("incoterm");
68}
69if (isModEnabled('notification')) {
70 $langs->load("mails");
71}
72
73$error = 0;
74$errors = array();
75
76
77// Get parameters
78$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
79$cancel = GETPOST('cancel', 'alpha');
80$backtopage = GETPOST('backtopage', 'alpha');
81$confirm = GETPOST('confirm');
82$socid = GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id');
83$selectedfields = GETPOST('selectedfields', 'alpha');
84
85if ($user->socid) {
86 $socid = $user->socid;
87}
88
89if (empty($socid) && $action == 'view') {
90 $action = 'create';
91}
92
93// Initialize objects
94$object = new Societe($db);
95$extrafields = new ExtraFields($db);
96
97// fetch optionals attributes and labels
98$extrafields->fetch_name_optionals_label($object->table_element);
99
100// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
101$hookmanager->initHooks(array('thirdpartycontact', 'globalcard'));
102
103if ($object->fetch($socid) <= 0 && $action == 'view') {
104 $langs->load("errors");
105 print($langs->trans('ErrorRecordNotFound'));
106 exit;
107}
108
109// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
110$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
111$objcanvas = null;
112if (!empty($canvas)) {
113 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
114 $objcanvas = new Canvas($db, $action);
115 $objcanvas->getCanvas('thirdparty', 'card', $canvas);
116}
117
118// Security check
119$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
120if (!$user->hasRight('societe', 'contact', 'lire')) {
122}
123
124
125/*
126 * Actions
127 */
128
129$parameters = array('id' => $socid, 'objcanvas' => $objcanvas);
130$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
131if ($reshook < 0) {
132 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
133}
134
135if (empty($reshook)) {
136 if ($cancel) {
137 $action = '';
138 if (!empty($backtopage)) {
139 header("Location: ".$backtopage);
140 exit;
141 }
142 }
143
144 // Selection of new fields
145 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
146}
147
148if ($action == 'confirm_delete' && $user->hasRight('societe', 'contact', 'delete')) {
149 $id = GETPOSTINT('id');
150 if ($id > 0 && $socid > 0) {
151 $contact = new Contact($db);
152 $ret = $contact->fetch($id);
153 if ($ret > 0) {
154 if ($contact->priv == 0 || ($contact->user_modification_id == ((int) $user->id) && $contact->priv == 1)) {
155 $contact->oldcopy = clone $contact; // @phan-suppress-current-line PhanTypeMismatchProperty
156 $result = $contact->delete($user);
157 if ($result > 0) {
158 setEventMessages('RecordDeleted', null, 'mesgs');
159 header("Location: ".$_SERVER['PHP_SELF']."?id=".$socid);
160 exit();
161 } else {
162 setEventMessages($contact->error, $contact->errors, 'errors');
163 }
164 }
165 } else {
166 setEventMessages($contact->error, $contact->errors, 'errors');
167 }
168 }
169}
170
171/*
172 * View
173 */
174
175$form = new Form($db);
176$formfile = new FormFile($db);
177$formadmin = new FormAdmin($db);
178$formcompany = new FormCompany($db);
179
180if ($socid > 0 && empty($object->id)) {
181 $result = $object->fetch($socid);
182 if ($result <= 0) {
183 dol_print_error(null, $object->error);
184 }
185}
186
187$title = $langs->trans("ThirdParty");
188if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
189 $title = $object->name." - ".$langs->trans('ContactsAddresses');
190}
191$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
192llxHeader('', $title, $help_url);
193
194$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
195
196
197if (!empty($object->id)) {
198 $res = $object->fetch_optionals();
199}
200//if ($res < 0) { dol_print_error($db); exit; }
201
202
203$head = societe_prepare_head($object);
204
205print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), 0, 'company');
206
207$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
208
209$morehtmlref = '<a href="'.DOL_URL_ROOT.'/societe/vcard.php?id='.$socid.'" class="refid">';
210$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
211$morehtmlref .= '</a>';
212
213dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref, '', 0, '', '', 1);
214
215print dol_get_fiche_end();
216
217print '<br>';
218
219if ($action != 'presend') {
220 // Contacts list
221 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
222 $showuserlogin = in_array('u.user', explode(',', $selectedfields)) ? 1 : 0;
223 $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, $showuserlogin);
224 }
225}
226if ($action == 'delete') {
227 $formconfirm = $form->formconfirm(
228 $_SERVER["PHP_SELF"].'?id='.GETPOST('id').'&socid='.$object->id,
229 $langs->trans('Delete'),
230 $langs->trans('ConfirmDeleteContact', GETPOST('id', 'alpha')),
231 'confirm_delete',
232 '',
233 0,
234 1
235 );
236 print $formconfirm;
237}
238
239// End of page
240llxFooter();
241$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage canvas.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.