dolibarr  9.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@inodbox.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 <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 if (! empty($conf->projet->enabled)) {
33  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35 }
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('orders', 'sendings', 'companies'));
39 
40 $id=GETPOST('id','int');
41 $ref=GETPOST('ref','alpha');
42 $action=GETPOST('action','alpha');
43 
44 // Security check
45 if ($user->societe_id) $socid=$user->societe_id;
46 $result = restrictedArea($user, 'expedition', $id,'');
47 
48 $object = new Expedition($db);
49 if ($id > 0 || ! empty($ref))
50 {
51  $object->fetch($id, $ref);
52  $object->fetch_thirdparty();
53 
54  if (!empty($object->origin))
55  {
56  $typeobject = $object->origin;
57  $origin = $object->origin;
58  $object->fetch_origin();
59  }
60 
61  // Linked documents
62  if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
63  {
64  $objectsrc=new Commande($db);
65  $objectsrc->fetch($object->$typeobject->id);
66  }
67  if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
68  {
69  $objectsrc=new Propal($db);
70  $objectsrc->fetch($object->$typeobject->id);
71  }
72 }
73 
74 
75 /*
76  * Actions
77  */
78 
79 if ($action == 'addcontact' && $user->rights->expedition->creer)
80 {
81  if ($result > 0 && $id > 0)
82  {
83  $result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
84  }
85 
86  if ($result >= 0)
87  {
88  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89  exit;
90  }
91  else
92  {
93  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
94  {
95  $langs->load("errors");
96  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
97  } else {
98  $mesg = $objectsrc->error;
99  $mesgs = $objectsrc->errors;
100  }
101  setEventMessages($mesg, $mesgs, 'errors');
102  }
103 }
104 
105 // bascule du statut d'un contact
106 else if ($action == 'swapstatut' && $user->rights->expedition->creer)
107 {
108  $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
109 }
110 
111 // Efface un contact
112 else if ($action == 'deletecontact' && $user->rights->expedition->creer)
113 {
114  $result = $objectsrc->delete_contact(GETPOST("lineid"));
115 
116  if ($result >= 0)
117  {
118  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
119  exit;
120  }
121  else {
122  dol_print_error($db);
123  }
124 }
125 /*
126 else if ($action == 'setaddress' && $user->rights->expedition->creer)
127 {
128  $object->fetch($id);
129  $result=$object->setDeliveryAddress($_POST['fk_address']);
130  if ($result < 0) dol_print_error($db,$object->error);
131 }*/
132 
133 
134 /*
135  * View
136  */
137 
138 llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
139 
140 $form = new Form($db);
141 $formcompany = new FormCompany($db);
142 $formother = new FormOther($db);
143 $contactstatic=new Contact($db);
144 $userstatic=new User($db);
145 
146 
147 /* *************************************************************************** */
148 /* */
149 /* Mode vue et edition */
150 /* */
151 /* *************************************************************************** */
152 
153 if ($id > 0 || ! empty($ref))
154 {
155  $langs->trans("OrderCard");
156 
157  $head = shipping_prepare_head($object);
158  dol_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');
159 
160 
161  // Shipment card
162  $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
163 
164  $morehtmlref='<div class="refidno">';
165  // Ref customer shipment
166  $morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
167  $morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
168  // Thirdparty
169  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
170  // Project
171  if (! empty($conf->projet->enabled)) {
172  $langs->load("projects");
173  $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
174  if (0) { // Do not change on shipment
175  if ($action != 'classify') {
176  $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
177  }
178  if ($action == 'classify') {
179  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
180  $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
181  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
182  $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
183  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
184  $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
185  $morehtmlref .= '</form>';
186  } else {
187  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
188  }
189  } else {
190  // We don't have project on shipment, so we will use the project or source object instead
191  // TODO Add project on shipment
192  $morehtmlref .= ' : ';
193  if (! empty($objectsrc->fk_project)) {
194  $proj = new Project($db);
195  $proj->fetch($objectsrc->fk_project);
196  $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
197  $morehtmlref .= $proj->ref;
198  $morehtmlref .= '</a>';
199  } else {
200  $morehtmlref .= '';
201  }
202  }
203  }
204  $morehtmlref.='</div>';
205 
206 
207  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
208 
209 
210  print '<div class="fichecenter">';
211  //print '<div class="fichehalfleft">';
212  print '<div class="underbanner clearboth"></div>';
213 
214  print '<table class="border centpercent">';
215 
216  // Linked documents
217  if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
218  {
219  print '<tr><td class="titlefield">';
220  $objectsrc=new Commande($db);
221  $objectsrc->fetch($object->$typeobject->id);
222  print $langs->trans("RefOrder").'</td>';
223  print '<td colspan="3">';
224  print $objectsrc->getNomUrl(1,'commande');
225  print "</td>\n";
226  print '</tr>';
227  }
228  if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
229  {
230  print '<tr><td class="titlefield">';
231  $objectsrc=new Propal($db);
232  $objectsrc->fetch($object->$typeobject->id);
233  print $langs->trans("RefProposal").'</td>';
234  print '<td colspan="3">';
235  print $objectsrc->getNomUrl(1,'expedition');
236  print "</td>\n";
237  print '</tr>';
238  }
239 
240  print "</table>";
241 
242 
243  //print '</div>';
244  //print '<div class="fichehalfright">';
245  //print '<div class="ficheaddleft">';
246  //print '<div class="underbanner clearboth"></div>';
247 
248 
249  //print '</div>';
250  //print '</div>';
251  print '</div>';
252 
253  print '<div class="clearboth"></div>';
254 
255 
256  dol_fiche_end();
257 
258  // Lignes de contacts
259  echo '<br>';
260 
261  // Contacts lines (modules that overwrite templates must declare this into descriptor)
262  $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
263  foreach($dirtpls as $reldir)
264  {
265  $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
266  if ($res) break;
267  }
268 }
269 
270 // End of page
271 llxFooter();
272 $db->close();
shipping_prepare_head($object)
Prepare array with list of tabs.
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage contact/addresses.
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
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...
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage shipments.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage customers orders.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
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.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
Class to manage proposals.