dolibarr 23.0.3
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3 * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
32require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36if (isModEnabled('project')) {
37 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39}
40require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
42
51$langs->loadLangs(array("orders", "receptions", "companies"));
52
53$id = GETPOSTINT('id');
54$ref = GETPOST('ref', 'alpha');
55$action = GETPOST('action', 'aZ09');
56
57$object = new Reception($db);
58$typeobject = '';
59$origin = '';
60if ($id > 0 || !empty($ref)) {
61 $object->fetch($id, $ref);
62 $object->fetch_thirdparty();
63
64 if (!empty($object->origin)) {
65 $origin = (string) $object->origin;
66 $typeobject = $object->origin;
67
68 $object->fetch_origin();
69 }
70
71 // Linked documents
72 if ($origin == 'order_supplier' && $object->origin_object->id && isModEnabled("supplier_order")) {
73 $objectsrc = new CommandeFournisseur($db);
74 $objectsrc->fetch($object->origin_object->id);
75 }
76}
77
78// Security check
79if ($user->socid > 0) {
80 $socid = $user->socid;
81}
82
83// TODO Test on reception module on only
84if ($origin == 'reception') {
85 $result = restrictedArea($user, $origin, $object->id);
86} else {
87 if ($origin == 'supplierorder' || $origin == 'order_supplier') {
88 $result = restrictedArea($user, 'fournisseur', $object, 'commande_fournisseur', 'commande');
89 } elseif (!$user->hasRight($origin, 'lire') && !$user->hasRight($origin, 'read')) {
91 }
92}
93
94if (isModEnabled("reception")) {
95 $permissiontoread = $user->hasRight('reception', 'lire');
96 $permissiontoadd = $user->hasRight('reception', 'creer');
97 $permissiondellink = $user->hasRight('reception', 'creer'); // Used by the include of actions_dellink.inc.php
98 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')));
99 $permissiontodelete = $user->hasRight('reception', 'supprimer');
100} else {
101 $permissiontoread = $user->hasRight('fournisseur', 'commande', 'receptionner');
102 $permissiontoadd = $user->hasRight('fournisseur', 'commande', 'receptionner');
103 $permissiondellink = $user->hasRight('fournisseur', 'commande', 'receptionner'); // Used by the include of actions_dellink.inc.php
104 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande', 'receptionner')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande_advance', 'check')));
105 $permissiontodelete = $user->hasRight('fournisseur', 'commande', 'receptionner');
106}
107
108
109/*
110 * Actions
111 */
112
113if ($action == 'addcontact' && $user->hasRight('reception', 'creer')) {
114 if ($result > 0 && $id > 0) {
115 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
116 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
117 $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
118 }
119
120 if ($result >= 0) {
121 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
122 exit;
123 } else {
124 if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
125 $langs->load("errors");
126 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
127 } else {
128 $mesg = $objectsrc->error;
129 $mesgs = $objectsrc->errors;
130 }
131 setEventMessages($mesg, $mesgs, 'errors');
132 }
133} elseif ($action == 'swapstatut' && $user->hasRight('reception', 'creer')) {
134 // bascule du statut d'un contact
135 $result = $objectsrc->swapContactStatus(GETPOSTINT('ligne'));
136} elseif ($action == 'deletecontact' && $user->hasRight('reception', 'creer')) {
137 // Efface un contact
138 $result = $objectsrc->delete_contact(GETPOSTINT("lineid"));
139
140 if ($result >= 0) {
141 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
142 exit;
143 } else {
144 dol_print_error($db);
145 }
146}
147
148
149/*
150 * View
151 */
152
153$help_url = 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes';
154llxHeader('', $langs->trans('Reception'), $help_url, '', 0, 0, '', '', '', 'mod-reception page-card_contact');
155
156$form = new Form($db);
157$formcompany = new FormCompany($db);
158$formother = new FormOther($db);
159$contactstatic = new Contact($db);
160$userstatic = new User($db);
161
162
163// View mode
164
165if ($id > 0 || !empty($ref)) {
166 $langs->trans("OrderCard");
167
168 $head = reception_prepare_head($object);
169 print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert');
170
171
172 // Reception card
173 $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
174
175 $morehtmlref = '<div class="refidno">';
176 // Ref customer reception
177 $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
178 $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
179 // Thirdparty
180 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
181 // Project
182 if (isModEnabled('project')) {
183 $langs->load("projects");
184 $morehtmlref .= '<br>';
185 if (0) { // @phpstan-ignore-line Do not change on reception
186 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
187 if ($action != 'classify' && $permissiontoadd) {
188 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
189 }
190 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
191 } else {
192 if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
193 $proj = new Project($db);
194 $proj->fetch($objectsrc->fk_project);
195 $morehtmlref .= $proj->getNomUrl(1);
196 if ($proj->title) {
197 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
198 }
199 }
200 }
201 }
202 $morehtmlref .= '</div>';
203
204 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
205
206
207 print '<div class="fichecenter">';
208 //print '<div class="fichehalfleft">';
209 print '<div class="underbanner clearboth"></div>';
210
211 print '<table class="border centpercent tableforfield">';
212 // Linked documents
213 if ($origin == 'order_supplier' && $object->origin_object->id && isModEnabled("supplier_order")) {
214 print '<tr><td class="titlefield">';
215 $objectsrc = new CommandeFournisseur($db);
216 $objectsrc->fetch($object->origin_object->id);
217 print $langs->trans("RefOrder").'</td>';
218 print '<td colspan="3">';
219 print $objectsrc->getNomUrl(1, 'commande');
220 print "</td>\n";
221 print '</tr>';
222 }
223 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
224 print '<tr><td class="titlefield">';
225 $objectsrc = new Propal($db);
226 $objectsrc->fetch($object->origin_object->id);
227 print $langs->trans("RefProposal").'</td>';
228 print '<td colspan="3">';
229 print $objectsrc->getNomUrl(1, 'reception');
230 print "</td>\n";
231 print '</tr>';
232 }
233
234 print "</table>";
235
236
237 //print '</div>';
238 //print '<div class="fichehalfright">';
239 //print '<div class="underbanner clearboth"></div>';
240
241
242 //print '</div>';
243 print '</div>';
244
245 print '<div class="clearboth"></div>';
246
247
248 print dol_get_fiche_end();
249
250 // Lines of contacts
251 echo '<br>';
252
253 // Contacts lines (modules that overwrite templates must declare this into descriptor)
254 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
255 foreach ($dirtpls as $reldir) {
256 $file = dol_buildpath($reldir.'/contacts.tpl.php');
257 if (file_exists($file)) {
258 $res = @include $file;
259 if ($res) {
260 break;
261 }
262 }
263 }
264}
265
266llxFooter();
267
268$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 predefined suppliers products.
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage projects.
Class to manage proposals.
Class to manage receptions.
Class to manage Dolibarr users.
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_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
reception_prepare_head(Reception $object)
Prepare array with list of tabs.
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.