dolibarr  13.0.2
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->projet->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->load("orders");
39 $langs->load("receptions");
40 $langs->load("companies");
41 
42 $id = GETPOST('id', 'int');
43 $ref = GETPOST('ref', 'alpha');
44 $action = GETPOST('action', 'aZ09');
45 
46 // Security check
47 if ($user->socid) $socid = $user->socid;
48 $result = restrictedArea($user, 'reception', $id, '');
49 
50 $object = new Reception($db);
51 if ($id > 0 || !empty($ref))
52 {
53  $object->fetch($id, $ref);
54  $object->fetch_thirdparty();
55 
56  if (!empty($object->origin))
57  {
58  $origin = $object->origin;
59 
60  $object->fetch_origin();
61  $typeobject = $object->origin;
62  }
63 
64  // Linked documents
65  if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
66  {
67  $objectsrc = new CommandeFournisseur($db);
68  $objectsrc->fetch($object->$typeobject->id);
69  }
70 }
71 
72 
73 /*
74  * Actions
75  */
76 
77 if ($action == 'addcontact' && $user->rights->reception->creer)
78 {
79  if ($result > 0 && $id > 0)
80  {
81  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
82  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
83  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
84  }
85 
86  if ($result >= 0)
87  {
88  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89  exit;
90  } else {
91  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
92  {
93  $langs->load("errors");
94  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
95  } else {
96  $mesg = $objectsrc->error;
97  $mesgs = $objectsrc->errors;
98  }
99  setEventMessages($mesg, $mesgs, 'errors');
100  }
101 }
102 
103 // bascule du statut d'un contact
104 elseif ($action == 'swapstatut' && $user->rights->reception->creer)
105 {
106  $result = $objectsrc->swapContactStatus(GETPOST('ligne'));
107 }
108 
109 // Efface un contact
110 elseif ($action == 'deletecontact' && $user->rights->reception->creer)
111 {
112  $result = $objectsrc->delete_contact(GETPOST("lineid"));
113 
114  if ($result >= 0)
115  {
116  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
117  exit;
118  } else {
119  dol_print_error($db);
120  }
121 }
122 /*
123 elseif ($action == 'setaddress' && $user->rights->reception->creer)
124 {
125  $object->fetch($id);
126  $result=$object->setDeliveryAddress($_POST['fk_address']);
127  if ($result < 0) dol_print_error($db,$object->error);
128 }*/
129 
130 
131 /*
132  * View
133  */
134 
135 llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
136 
137 $form = new Form($db);
138 $formcompany = new FormCompany($db);
139 $formother = new FormOther($db);
140 $contactstatic = new Contact($db);
141 $userstatic = new User($db);
142 
143 
144 /* *************************************************************************** */
145 /* */
146 /* Mode vue et edition */
147 /* */
148 /* *************************************************************************** */
149 
150 if ($id > 0 || !empty($ref))
151 {
152  $langs->trans("OrderCard");
153 
154  $head = reception_prepare_head($object);
155  print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert');
156 
157 
158  // Reception card
159  $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
160 
161  $morehtmlref = '<div class="refidno">';
162  // Ref customer reception
163  $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
164  $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
165  // Thirdparty
166  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
167  // Project
168  if (!empty($conf->projet->enabled)) {
169  $langs->load("projects");
170  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
171  if (0) { // Do not change on reception
172  if ($action != 'classify') {
173  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
174  }
175  if ($action == 'classify') {
176  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
177  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
178  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
179  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
180  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
181  $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
182  $morehtmlref .= '</form>';
183  } else {
184  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
185  }
186  } else {
187  // We don't have project on reception, so we will use the project or source object instead
188  // TODO Add project on reception
189  $morehtmlref .= ' : ';
190  if (!empty($objectsrc->fk_project)) {
191  $proj = new Project($db);
192  $proj->fetch($objectsrc->fk_project);
193  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
194  $morehtmlref .= $proj->ref;
195  $morehtmlref .= '</a>';
196  } else {
197  $morehtmlref .= '';
198  }
199  }
200  }
201  $morehtmlref .= '</div>';
202 
203  $object->picto = 'sending';
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">';
212  // Linked documents
213  if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
214  {
215  print '<tr><td class="titlefield">';
216  $objectsrc = new CommandeFournisseur($db);
217  $objectsrc->fetch($object->$typeobject->id);
218  print $langs->trans("RefOrder").'</td>';
219  print '<td colspan="3">';
220  print $objectsrc->getNomUrl(1, 'commande');
221  print "</td>\n";
222  print '</tr>';
223  }
224  if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
225  {
226  print '<tr><td class="titlefield">';
227  $objectsrc = new Propal($db);
228  $objectsrc->fetch($object->$typeobject->id);
229  print $langs->trans("RefProposal").'</td>';
230  print '<td colspan="3">';
231  print $objectsrc->getNomUrl(1, 'reception');
232  print "</td>\n";
233  print '</tr>';
234  }
235 
236  print "</table>";
237 
238 
239  //print '</div>';
240  //print '<div class="fichehalfright">';
241  //print '<div class="ficheaddleft">';
242  //print '<div class="underbanner clearboth"></div>';
243 
244 
245  //print '</div>';
246  //print '</div>';
247  print '</div>';
248 
249  print '<div class="clearboth"></div>';
250 
251 
253 
254  // Lines of contacts
255  echo '<br>';
256 
257  // Contacts lines (modules that overwrite templates must declare this into descriptor)
258  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
259  foreach ($dirtpls as $reldir)
260  {
261  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
262  if ($res) break;
263  }
264 }
265 
266 llxFooter();
267 
268 $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.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
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...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage predefined suppliers products.
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
Definition: index.php:89
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.
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:59
Class to manage proposals.