dolibarr  18.0.6
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 
71 // TODO Test on reception module on only
72 if ($origin == 'reception') {
73  $result = restrictedArea($user, $origin, $object->id);
74 } else {
75  if ($origin == 'supplierorder' || $origin == 'order_supplier') {
76  $result = restrictedArea($user, 'fournisseur', $object, 'commande_fournisseur', 'commande');
77  } elseif (!$user->hasRight($origin, 'lire') && !$user->hasRight($origin, 'read')) {
79  }
80 }
81 
82 if (isModEnabled("reception")) {
83  $permissiontoread = $user->rights->reception->lire;
84  $permissiontoadd = $user->rights->reception->creer;
85  $permissiondellink = $user->rights->reception->creer; // Used by the include of actions_dellink.inc.php
86  $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)));
87  $permissiontodelete = $user->rights->reception->supprimer;
88 } else {
89  $permissiontoread = $user->rights->fournisseur->commande->receptionner;
90  $permissiontoadd = $user->rights->fournisseur->commande->receptionner;
91  $permissiondellink = $user->rights->fournisseur->commande->receptionner; // Used by the include of actions_dellink.inc.php
92  $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)));
93  $permissiontodelete = $user->rights->fournisseur->commande->receptionner;
94 }
95 
96 
97 /*
98  * Actions
99  */
100 
101 if ($action == 'addcontact' && $user->rights->reception->creer) {
102  if ($result > 0 && $id > 0) {
103  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
104  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
105  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
106  }
107 
108  if ($result >= 0) {
109  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
110  exit;
111  } else {
112  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
113  $langs->load("errors");
114  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
115  } else {
116  $mesg = $objectsrc->error;
117  $mesgs = $objectsrc->errors;
118  }
119  setEventMessages($mesg, $mesgs, 'errors');
120  }
121 } elseif ($action == 'swapstatut' && $user->rights->reception->creer) {
122  // bascule du statut d'un contact
123  $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
124 } elseif ($action == 'deletecontact' && $user->rights->reception->creer) {
125  // Efface un contact
126  $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
127 
128  if ($result >= 0) {
129  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
130  exit;
131  } else {
132  dol_print_error($db);
133  }
134 }
135 
136 
137 /*
138  * View
139  */
140 
141 llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
142 
143 $form = new Form($db);
144 $formcompany = new FormCompany($db);
145 $formother = new FormOther($db);
146 $contactstatic = new Contact($db);
147 $userstatic = new User($db);
148 
149 
150 // View mode
151 
152 if ($id > 0 || !empty($ref)) {
153  $langs->trans("OrderCard");
154 
155  $head = reception_prepare_head($object);
156  print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert');
157 
158 
159  // Reception card
160  $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
161 
162  $morehtmlref = '<div class="refidno">';
163  // Ref customer reception
164  $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
165  $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
166  // Thirdparty
167  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
168  // Project
169  if (isModEnabled('project')) {
170  $langs->load("projects");
171  $morehtmlref .= '<br>';
172  if (0) { // Do not change on reception
173  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
174  if ($action != 'classify' && $permissiontoadd) {
175  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
176  }
177  $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');
178  } else {
179  if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
180  $proj = new Project($db);
181  $proj->fetch($objectsrc->fk_project);
182  $morehtmlref .= $proj->getNomUrl(1);
183  if ($proj->title) {
184  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
185  }
186  }
187  }
188  }
189  $morehtmlref .= '</div>';
190 
191  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
192 
193 
194  print '<div class="fichecenter">';
195  //print '<div class="fichehalfleft">';
196  print '<div class="underbanner clearboth"></div>';
197 
198  print '<table class="border centpercent tableforfield">';
199  // Linked documents
200  if ($origin == 'order_supplier' && $object->$typeobject->id && isModEnabled("supplier_order")) {
201  print '<tr><td class="titlefield">';
202  $objectsrc = new CommandeFournisseur($db);
203  $objectsrc->fetch($object->$typeobject->id);
204  print $langs->trans("RefOrder").'</td>';
205  print '<td colspan="3">';
206  print $objectsrc->getNomUrl(1, 'commande');
207  print "</td>\n";
208  print '</tr>';
209  }
210  if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
211  print '<tr><td class="titlefield">';
212  $objectsrc = new Propal($db);
213  $objectsrc->fetch($object->$typeobject->id);
214  print $langs->trans("RefProposal").'</td>';
215  print '<td colspan="3">';
216  print $objectsrc->getNomUrl(1, 'reception');
217  print "</td>\n";
218  print '</tr>';
219  }
220 
221  print "</table>";
222 
223 
224  //print '</div>';
225  //print '<div class="fichehalfright">';
226  //print '<div class="underbanner clearboth"></div>';
227 
228 
229  //print '</div>';
230  print '</div>';
231 
232  print '<div class="clearboth"></div>';
233 
234 
235  print dol_get_fiche_end();
236 
237  // Lines of contacts
238  echo '<br>';
239 
240  // Contacts lines (modules that overwrite templates must declare this into descriptor)
241  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
242  foreach ($dirtpls as $reldir) {
243  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
244  if ($res) {
245  break;
246  }
247  }
248 }
249 
250 llxFooter();
251 
252 $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.