dolibarr  19.0.0-dev
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 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.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 (isModEnabled('project')) {
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 // Load translation files required by the page
39 $langs->loadLangs(array('orders', 'sendings', 'companies'));
40 
41 $id = GETPOST('id', 'int');
42 $ref = GETPOST('ref', 'alpha');
43 $action = GETPOST('action', 'aZ09');
44 
45 $object = new Expedition($db);
46 if ($id > 0 || !empty($ref)) {
47  $object->fetch($id, $ref);
48  $object->fetch_thirdparty();
49 
50  if (!empty($object->origin)) {
51  $typeobject = $object->origin;
52  $origin = $object->origin;
53  $object->fetch_origin();
54  }
55 
56  // Linked documents
57  if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
58  $objectsrc = new Commande($db);
59  $objectsrc->fetch($object->$typeobject->id);
60  }
61  if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
62  $objectsrc = new Propal($db);
63  $objectsrc->fetch($object->$typeobject->id);
64  }
65 }
66 
67 // Security check
68 if ($user->socid) {
69  $socid = $user->socid;
70 }
71 $result = restrictedArea($user, 'expedition', $object->id, '');
72 
73 
74 /*
75  * Actions
76  */
77 
78 if ($action == 'addcontact' && $user->rights->expedition->creer) {
79  if ($result > 0 && $id > 0) {
80  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
81  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
82  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
83  }
84 
85  if ($result >= 0) {
86  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
87  exit;
88  } else {
89  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
90  $langs->load("errors");
91  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
92  } else {
93  $mesg = $objectsrc->error;
94  $mesgs = $objectsrc->errors;
95  }
96  setEventMessages($mesg, $mesgs, 'errors');
97  }
98 } elseif ($action == 'swapstatut' && $user->rights->expedition->creer) {
99  // bascule du statut d'un contact
100  $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
101 } elseif ($action == 'deletecontact' && $user->rights->expedition->creer) {
102  // Efface un contact
103  $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
104 
105  if ($result >= 0) {
106  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
107  exit;
108  } else {
109  dol_print_error($db);
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 
118 
119 $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
120 
121 llxHeader('', $langs->trans('Order'), $help_url);
122 
123 $form = new Form($db);
124 $formcompany = new FormCompany($db);
125 $formother = new FormOther($db);
126 $contactstatic = new Contact($db);
127 $userstatic = new User($db);
128 
129 
130 /* *************************************************************************** */
131 /* */
132 /* Mode vue et edition */
133 /* */
134 /* *************************************************************************** */
135 
136 if ($id > 0 || !empty($ref)) {
137  $langs->trans("OrderCard");
138 
139  $head = shipping_prepare_head($object);
140  print dol_get_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, $object->picto);
141 
142 
143  // Shipment card
144  $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
145 
146  $morehtmlref = '<div class="refidno">';
147  // Ref customer shipment
148  $morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
149  $morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
150  // Thirdparty
151  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
152  // Project
153  if (isModEnabled('project')) {
154  $langs->load("projects");
155  $morehtmlref .= '<br>';
156  if (0) { // Do not change on shipment
157  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
158  if ($action != 'classify') {
159  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
160  }
161  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
162  } else {
163  if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
164  $proj = new Project($db);
165  $proj->fetch($objectsrc->fk_project);
166  $morehtmlref .= $proj->getNomUrl(1);
167  if ($proj->title) {
168  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
169  }
170  }
171  }
172  }
173  $morehtmlref .= '</div>';
174 
175 
176  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
177 
178 
179  print '<div class="fichecenter">';
180  //print '<div class="fichehalfleft">';
181  print '<div class="underbanner clearboth"></div>';
182 
183  print '<table class="border centpercent tableforfield">';
184 
185  // Linked documents
186  if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
187  print '<tr><td class="titlefield">';
188  $objectsrc = new Commande($db);
189  $objectsrc->fetch($object->$typeobject->id);
190  print $langs->trans("RefOrder").'</td>';
191  print '<td colspan="3">';
192  print $objectsrc->getNomUrl(1, 'commande');
193  print "</td>\n";
194  print '</tr>';
195  }
196  if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
197  print '<tr><td class="titlefield">';
198  $objectsrc = new Propal($db);
199  $objectsrc->fetch($object->$typeobject->id);
200  print $langs->trans("RefProposal").'</td>';
201  print '<td colspan="3">';
202  print $objectsrc->getNomUrl(1, 'expedition');
203  print "</td>\n";
204  print '</tr>';
205  }
206 
207  print "</table>";
208 
209 
210  //print '</div>';
211  //print '<div class="fichehalfright">';
212  //print '<div class="underbanner clearboth"></div>';
213 
214 
215  //print '</div>';
216  print '</div>';
217 
218  print '<div class="clearboth"></div>';
219 
220 
221  print dol_get_fiche_end();
222 
223  // Lines of contacts
224  echo '<br>';
225 
226  // Contacts lines (modules that overwrite templates must declare this into descriptor)
227  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
228  $preselectedtypeofcontact = dol_getIdFromCode($db, 'SHIPPING', 'c_type_contact', 'code', 'rowid');
229  foreach ($dirtpls as $reldir) {
230  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
231  if ($res) {
232  break;
233  }
234  }
235 }
236 
237 // End of page
238 llxFooter();
239 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage customers orders.
Class to manage contact/addresses.
Class to manage shipments.
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.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage projects.
Class to manage proposals.
Class to manage Dolibarr users.
Definition: user.class.php:48
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
restrictedArea(User $user, $features, $object=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.
shipping_prepare_head($object)
Prepare array with list of tabs.