dolibarr  16.0.1
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 if (!empty($conf->project->enabled)) {
34  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
36 }
37 
38 $langs->loadLangs(array("orders", "receptions", "companies"));
39 
40 $id = GETPOST('id', 'int');
41 $ref = GETPOST('ref', 'alpha');
42 $action = GETPOST('action', 'aZ09');
43 
44 $object = new Reception($db);
45 if ($id > 0 || !empty($ref)) {
46  $object->fetch($id, $ref);
47  $object->fetch_thirdparty();
48 
49  if (!empty($object->origin)) {
50  $origin = $object->origin;
51 
52  $object->fetch_origin();
53  $typeobject = $object->origin;
54  }
55 
56  // Linked documents
57  if ($origin == 'order_supplier' && $object->$typeobject->id && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))) {
58  $objectsrc = new CommandeFournisseur($db);
59  $objectsrc->fetch($object->$typeobject->id);
60  }
61 }
62 
63 // Security check
64 if ($user->socid > 0) {
65  $socid = $user->socid;
66 }
67 if ($origin == 'reception') {
68  $result = restrictedArea($user, $origin, $object->id);
69 } else {
70  if ($origin == 'supplierorder' || $origin == 'order_supplier') {
71  $result = restrictedArea($user, 'fournisseur', $origin_id, 'commande_fournisseur', 'commande');
72  } elseif (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) {
74  }
75 }
76 
77 
78 /*
79  * Actions
80  */
81 
82 if ($action == 'addcontact' && $user->rights->reception->creer) {
83  if ($result > 0 && $id > 0) {
84  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
85  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
86  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
87  }
88 
89  if ($result >= 0) {
90  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
91  exit;
92  } else {
93  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
94  $langs->load("errors");
95  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
96  } else {
97  $mesg = $objectsrc->error;
98  $mesgs = $objectsrc->errors;
99  }
100  setEventMessages($mesg, $mesgs, 'errors');
101  }
102 } elseif ($action == 'swapstatut' && $user->rights->reception->creer) {
103  // bascule du statut d'un contact
104  $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
105 } elseif ($action == 'deletecontact' && $user->rights->reception->creer) {
106  // Efface un contact
107  $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
108 
109  if ($result >= 0) {
110  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
111  exit;
112  } else {
113  dol_print_error($db);
114  }
115 }
116 
117 
118 /*
119  * View
120  */
121 
122 llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
123 
124 $form = new Form($db);
125 $formcompany = new FormCompany($db);
126 $formother = new FormOther($db);
127 $contactstatic = new Contact($db);
128 $userstatic = new User($db);
129 
130 
131 // View mode
132 
133 if ($id > 0 || !empty($ref)) {
134  $langs->trans("OrderCard");
135 
136  $head = reception_prepare_head($object);
137  print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert');
138 
139 
140  // Reception card
141  $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
142 
143  $morehtmlref = '<div class="refidno">';
144  // Ref customer reception
145  $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
146  $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
147  // Thirdparty
148  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
149  // Project
150  if (!empty($conf->project->enabled)) {
151  $langs->load("projects");
152  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
153  if (0) { // Do not change on reception
154  if ($action != 'classify') {
155  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
156  }
157  if ($action == 'classify') {
158  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
159  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
160  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
161  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
162  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
163  $morehtmlref .= '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
164  $morehtmlref .= '</form>';
165  } else {
166  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
167  }
168  } else {
169  // We don't have project on reception, so we will use the project or source object instead
170  // TODO Add project on reception
171  $morehtmlref .= ' : ';
172  if (!empty($objectsrc->fk_project)) {
173  $proj = new Project($db);
174  $proj->fetch($objectsrc->fk_project);
175  $morehtmlref .= ' : '.$proj->getNomUrl(1);
176  if ($proj->title) {
177  $morehtmlref .= ' - '.$proj->title;
178  }
179  } else {
180  $morehtmlref .= '';
181  }
182  }
183  }
184  $morehtmlref .= '</div>';
185 
186  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
187 
188 
189  print '<div class="fichecenter">';
190  //print '<div class="fichehalfleft">';
191  print '<div class="underbanner clearboth"></div>';
192 
193  print '<table class="border centpercent">';
194  // Linked documents
195  if ($origin == 'order_supplier' && $object->$typeobject->id && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))) {
196  print '<tr><td class="titlefield">';
197  $objectsrc = new CommandeFournisseur($db);
198  $objectsrc->fetch($object->$typeobject->id);
199  print $langs->trans("RefOrder").'</td>';
200  print '<td colspan="3">';
201  print $objectsrc->getNomUrl(1, 'commande');
202  print "</td>\n";
203  print '</tr>';
204  }
205  if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
206  print '<tr><td class="titlefield">';
207  $objectsrc = new Propal($db);
208  $objectsrc->fetch($object->$typeobject->id);
209  print $langs->trans("RefProposal").'</td>';
210  print '<td colspan="3">';
211  print $objectsrc->getNomUrl(1, 'reception');
212  print "</td>\n";
213  print '</tr>';
214  }
215 
216  print "</table>";
217 
218 
219  //print '</div>';
220  //print '<div class="fichehalfright">';
221  //print '<div class="underbanner clearboth"></div>';
222 
223 
224  //print '</div>';
225  print '</div>';
226 
227  print '<div class="clearboth"></div>';
228 
229 
230  print dol_get_fiche_end();
231 
232  // Lines of contacts
233  echo '<br>';
234 
235  // Contacts lines (modules that overwrite templates must declare this into descriptor)
236  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
237  foreach ($dirtpls as $reldir) {
238  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
239  if ($res) {
240  break;
241  }
242  }
243 }
244 
245 llxFooter();
246 
247 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage receptions.
Classe permettant la generation de composants html autre Only common components are here...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage predefined suppliers products.
restrictedArea($user, $features, $objectid=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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
reception_prepare_head(Reception $object)
Prepare array with list of tabs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:73
Class to manage proposals.