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