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