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