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@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 <https://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', 'aZ09');
43 
44 // Security check
45 if ($user->socid) $socid = $user->socid;
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  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
84  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
85  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
86  }
87 
88  if ($result >= 0)
89  {
90  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
91  exit;
92  } else {
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 elseif ($action == 'swapstatut' && $user->rights->expedition->creer)
107 {
108  $result = $objectsrc->swapContactStatus(GETPOST('ligne'));
109 }
110 
111 // Efface un contact
112 elseif ($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  } else {
121  dol_print_error($db);
122  }
123 }
124 /*
125 elseif ($action == 'setaddress' && $user->rights->expedition->creer)
126 {
127  $object->fetch($id);
128  $result=$object->setDeliveryAddress($_POST['fk_address']);
129  if ($result < 0) dol_print_error($db,$object->error);
130 }*/
131 
132 
133 /*
134  * View
135  */
136 
137 llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
138 
139 $form = new Form($db);
140 $formcompany = new FormCompany($db);
141 $formother = new FormOther($db);
142 $contactstatic = new Contact($db);
143 $userstatic = new User($db);
144 
145 
146 /* *************************************************************************** */
147 /* */
148 /* Mode vue et edition */
149 /* */
150 /* *************************************************************************** */
151 
152 if ($id > 0 || !empty($ref))
153 {
154  $langs->trans("OrderCard");
155 
156  $head = shipping_prepare_head($object);
157  print dol_get_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');
158 
159 
160  // Shipment card
161  $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
162 
163  $morehtmlref = '<div class="refidno">';
164  // Ref customer shipment
165  $morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
166  $morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
167  // Thirdparty
168  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
169  // Project
170  if (!empty($conf->projet->enabled)) {
171  $langs->load("projects");
172  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
173  if (0) { // Do not change on shipment
174  if ($action != 'classify') {
175  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
176  }
177  if ($action == 'classify') {
178  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
179  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
180  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
181  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
182  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
183  $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
184  $morehtmlref .= '</form>';
185  } else {
186  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
187  }
188  } else {
189  // We don't have project on shipment, so we will use the project or source object instead
190  // TODO Add project on shipment
191  $morehtmlref .= ' : ';
192  if (!empty($objectsrc->fk_project)) {
193  $proj = new Project($db);
194  $proj->fetch($objectsrc->fk_project);
195  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
196  $morehtmlref .= $proj->ref;
197  $morehtmlref .= '</a>';
198  } else {
199  $morehtmlref .= '';
200  }
201  }
202  }
203  $morehtmlref .= '</div>';
204 
205 
206  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
207 
208 
209  print '<div class="fichecenter">';
210  //print '<div class="fichehalfleft">';
211  print '<div class="underbanner clearboth"></div>';
212 
213  print '<table class="border centpercent tableforfield">';
214 
215  // Linked documents
216  if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
217  {
218  print '<tr><td class="titlefield">';
219  $objectsrc = new Commande($db);
220  $objectsrc->fetch($object->$typeobject->id);
221  print $langs->trans("RefOrder").'</td>';
222  print '<td colspan="3">';
223  print $objectsrc->getNomUrl(1, 'commande');
224  print "</td>\n";
225  print '</tr>';
226  }
227  if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
228  {
229  print '<tr><td class="titlefield">';
230  $objectsrc = new Propal($db);
231  $objectsrc->fetch($object->$typeobject->id);
232  print $langs->trans("RefProposal").'</td>';
233  print '<td colspan="3">';
234  print $objectsrc->getNomUrl(1, 'expedition');
235  print "</td>\n";
236  print '</tr>';
237  }
238 
239  print "</table>";
240 
241 
242  //print '</div>';
243  //print '<div class="fichehalfright">';
244  //print '<div class="ficheaddleft">';
245  //print '<div class="underbanner clearboth"></div>';
246 
247 
248  //print '</div>';
249  //print '</div>';
250  print '</div>';
251 
252  print '<div class="clearboth"></div>';
253 
254 
256 
257  // Lines of contacts
258  echo '<br>';
259 
260  // Contacts lines (modules that overwrite templates must declare this into descriptor)
261  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
262  $preselectedtypeofcontact = dol_getIdFromCode($db, 'SHIPPING', 'c_type_contact', 'code', 'rowid');
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();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
shipping_prepare_head($object)
Prepare array with list of tabs.
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 shipments.
Class to manage customers orders.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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.