dolibarr  16.0.1
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->project->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 $object = new Expedition($db);
45 if ($id > 0 || !empty($ref)) {
46  $object->fetch($id, $ref);
47  $object->fetch_thirdparty();
48 
49  if (!empty($object->origin)) {
50  $typeobject = $object->origin;
51  $origin = $object->origin;
52  $object->fetch_origin();
53  }
54 
55  // Linked documents
56  if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
57  $objectsrc = new Commande($db);
58  $objectsrc->fetch($object->$typeobject->id);
59  }
60  if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
61  $objectsrc = new Propal($db);
62  $objectsrc->fetch($object->$typeobject->id);
63  }
64 }
65 
66 // Security check
67 if ($user->socid) {
68  $socid = $user->socid;
69 }
70 $result = restrictedArea($user, 'expedition', $object->id, '');
71 
72 
73 /*
74  * Actions
75  */
76 
77 if ($action == 'addcontact' && $user->rights->expedition->creer) {
78  if ($result > 0 && $id > 0) {
79  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
80  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
81  $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
82  }
83 
84  if ($result >= 0) {
85  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
86  exit;
87  } else {
88  if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
89  $langs->load("errors");
90  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
91  } else {
92  $mesg = $objectsrc->error;
93  $mesgs = $objectsrc->errors;
94  }
95  setEventMessages($mesg, $mesgs, 'errors');
96  }
97 } elseif ($action == 'swapstatut' && $user->rights->expedition->creer) {
98  // bascule du statut d'un contact
99  $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
100 } elseif ($action == 'deletecontact' && $user->rights->expedition->creer) {
101  // Efface un contact
102  $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
103 
104  if ($result >= 0) {
105  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
106  exit;
107  } else {
108  dol_print_error($db);
109  }
110 }
111 
112 
113 /*
114  * View
115  */
116 
117 
118 $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
119 
120 llxHeader('', $langs->trans('Order'), $help_url);
121 
122 $form = new Form($db);
123 $formcompany = new FormCompany($db);
124 $formother = new FormOther($db);
125 $contactstatic = new Contact($db);
126 $userstatic = new User($db);
127 
128 
129 /* *************************************************************************** */
130 /* */
131 /* Mode vue et edition */
132 /* */
133 /* *************************************************************************** */
134 
135 if ($id > 0 || !empty($ref)) {
136  $langs->trans("OrderCard");
137 
138  $head = shipping_prepare_head($object);
139  print dol_get_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, $object->picto);
140 
141 
142  // Shipment card
143  $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
144 
145  $morehtmlref = '<div class="refidno">';
146  // Ref customer shipment
147  $morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
148  $morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
149  // Thirdparty
150  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
151  // Project
152  if (!empty($conf->project->enabled)) {
153  $langs->load("projects");
154  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
155  if (0) { // Do not change on shipment
156  if ($action != 'classify') {
157  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
158  }
159  if ($action == 'classify') {
160  // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
161  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
162  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
163  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
164  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
165  $morehtmlref .= '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
166  $morehtmlref .= '</form>';
167  } else {
168  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
169  }
170  } else {
171  // We don't have project on shipment, so we will use the project or source object instead
172  // TODO Add project on shipment
173  $morehtmlref .= ' : ';
174  if (!empty($objectsrc->fk_project)) {
175  $proj = new Project($db);
176  $proj->fetch($objectsrc->fk_project);
177  $morehtmlref .= ' : '.$proj->getNomUrl(1);
178  if ($proj->title) {
179  $morehtmlref .= ' - '.$proj->title;
180  }
181  } else {
182  $morehtmlref .= '';
183  }
184  }
185  }
186  $morehtmlref .= '</div>';
187 
188 
189  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
190 
191 
192  print '<div class="fichecenter">';
193  //print '<div class="fichehalfleft">';
194  print '<div class="underbanner clearboth"></div>';
195 
196  print '<table class="border centpercent tableforfield">';
197 
198  // Linked documents
199  if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
200  print '<tr><td class="titlefield">';
201  $objectsrc = new Commande($db);
202  $objectsrc->fetch($object->$typeobject->id);
203  print $langs->trans("RefOrder").'</td>';
204  print '<td colspan="3">';
205  print $objectsrc->getNomUrl(1, 'commande');
206  print "</td>\n";
207  print '</tr>';
208  }
209  if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
210  print '<tr><td class="titlefield">';
211  $objectsrc = new Propal($db);
212  $objectsrc->fetch($object->$typeobject->id);
213  print $langs->trans("RefProposal").'</td>';
214  print '<td colspan="3">';
215  print $objectsrc->getNomUrl(1, 'expedition');
216  print "</td>\n";
217  print '</tr>';
218  }
219 
220  print "</table>";
221 
222 
223  //print '</div>';
224  //print '<div class="fichehalfright">';
225  //print '<div class="underbanner clearboth"></div>';
226 
227 
228  //print '</div>';
229  print '</div>';
230 
231  print '<div class="clearboth"></div>';
232 
233 
234  print dol_get_fiche_end();
235 
236  // Lines of contacts
237  echo '<br>';
238 
239  // Contacts lines (modules that overwrite templates must declare this into descriptor)
240  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
241  $preselectedtypeofcontact = dol_getIdFromCode($db, 'SHIPPING', 'c_type_contact', 'code', 'rowid');
242  foreach ($dirtpls as $reldir) {
243  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
244  if ($res) {
245  break;
246  }
247  }
248 }
249 
250 // End of page
251 llxFooter();
252 $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.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0, $filters= '')
Return an id or code from a code or id.
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:116
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, $mode=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
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...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
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:73
Class to manage proposals.