dolibarr 20.0.0
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 *
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
35// Load Dolibarr environment
36require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
45require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
46require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
47if (isModEnabled('member')) {
48 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
49}
50
51// Load translation files required by the page
52$langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
53
54if (isModEnabled('category')) {
55 $langs->load("categories");
56}
57if (isModEnabled('incoterm')) {
58 $langs->load("incoterm");
59}
60if (isModEnabled('notification')) {
61 $langs->load("mails");
62}
63
64$error = 0;
65$errors = array();
66
67
68// Get parameters
69$action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
70$cancel = GETPOST('cancel', 'alpha');
71$backtopage = GETPOST('backtopage', 'alpha');
72$confirm = GETPOST('confirm');
73$socid = GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id');
74
75if ($user->socid) {
76 $socid = $user->socid;
77}
78
79if (empty($socid) && $action == 'view') {
80 $action = 'create';
81}
82
83// Initialize objects
84$object = new Societe($db);
85$extrafields = new ExtraFields($db);
86
87// fetch optionals attributes and labels
88$extrafields->fetch_name_optionals_label($object->table_element);
89
90// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
91$hookmanager->initHooks(array('thirdpartycontact', 'globalcard'));
92
93if ($object->fetch($socid) <= 0 && $action == 'view') {
94 $langs->load("errors");
95 print($langs->trans('ErrorRecordNotFound'));
96 exit;
97}
98
99// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
100$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
101$objcanvas = null;
102if (!empty($canvas)) {
103 require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
104 $objcanvas = new Canvas($db, $action);
105 $objcanvas->getCanvas('thirdparty', 'card', $canvas);
106}
107
108// Security check
109$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
110if (!$user->hasRight('societe', 'contact', 'lire')) {
112}
113
114
115/*
116 * Actions
117 */
118
119$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
120$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
121if ($reshook < 0) {
122 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
123}
124
125if (empty($reshook)) {
126 if ($cancel) {
127 $action = '';
128 if (!empty($backtopage)) {
129 header("Location: ".$backtopage);
130 exit;
131 }
132 }
133
134 // Selection of new fields
135 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
136}
137
138if ($action == 'confirm_delete' && $user->hasRight('societe', 'contact', 'delete')) {
139 $id = GETPOST('id', 'int');
140 if (!empty($id) && $socid > 0) {
141 $db->begin();
142
143 $sql = "DELETE t, et FROM ".MAIN_DB_PREFIX."socpeople AS t";
144 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields AS et ON t.rowid = et.fk_object";
145 $sql .= " WHERE t.fk_soc = ".((int) $socid);
146 $sql .= " AND t.rowid = ".((int) $id);
147 $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";
148
149 $result = $db->query($sql);
150 if (!$result) {
151 setEventMessages($db->lasterror(), null, 'errors');
152 $db->rollback();
153 } else {
154 $db->commit();
155 setEventMessages('ContactDeleted', null, 'mesgs');
156 header("Location: ".$_SERVER['PHP_SELF']."?id=".$socid);
157 exit();
158 }
159 }
160}
161
162/*
163 * View
164 */
165
166$form = new Form($db);
167$formfile = new FormFile($db);
168$formadmin = new FormAdmin($db);
169$formcompany = new FormCompany($db);
170
171if ($socid > 0 && empty($object->id)) {
172 $result = $object->fetch($socid);
173 if ($result <= 0) {
174 dol_print_error(null, $object->error);
175 }
176}
177
178$title = $langs->trans("ThirdParty");
179if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
180 $title = $object->name." - ".$langs->trans('ContactsAddresses');
181}
182$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
183llxHeader('', $title, $help_url);
184
185$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
186
187
188if (!empty($object->id)) {
189 $res = $object->fetch_optionals();
190}
191//if ($res < 0) { dol_print_error($db); exit; }
192
193
194$head = societe_prepare_head($object);
195
196print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), 0, 'company');
197
198$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
199
200dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
201
202print dol_get_fiche_end();
203
204print '<br>';
205
206if ($action != 'presend') {
207 // Contacts list
208 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
209 $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1);
210 }
211}
212if ($action == 'delete') {
213 $formconfirm = $form->formconfirm(
214 $_SERVER["PHP_SELF"].'?id='.GETPOST('id').'&socid='.$object->id,
215 $langs->trans('Delete'),
216 $langs->trans('ConfirmDeleteContact', GETPOST('id', 'alpha')),
217 'confirm_delete',
218 '',
219 0,
220 1
221 );
222 print $formconfirm;
223}
224
225// End of page
226llxFooter();
227$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage canvas.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
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.