dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
22 require '../../main.inc.php';
23 require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
24 require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
27 
28 // Load translation files required by the page
29 $langs->loadLangs(array('admin', 'hrm'));
30 
31 // Security check
32 if (!$user->admin) accessforbidden();
33 
34 $error = 0;
35 
36 $action = GETPOST('action', 'aZ09');
37 $cancel = GETPOST('cancel', 'alpha');
38 $confirm = GETPOST('confirm', 'alpha');
39 $id = GETPOST('id', 'int');
40 
41 // List of status
42 static $tmpstatus2label = array(
43  '0'=>'CloseEtablishment',
44  '1'=>'OpenEtablishment'
45 );
46 $status2label = array('');
47 foreach ($tmpstatus2label as $key => $val) $status2label[$key] = $langs->trans($val);
48 
49 $object = new Establishment($db);
50 
51 // Load object
52 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
53 
54 
55 /*
56  * Actions
57  */
58 
59 if ($action == 'confirm_delete' && $confirm == "yes")
60 {
61  $result = $object->delete($id);
62  if ($result >= 0)
63  {
64  header("Location: ../admin/admin_establishment.php");
65  exit;
66  } else {
67  setEventMessages($object->error, $object->errors, 'errors');
68  }
69 } elseif ($action == 'add')
70 {
71  if (!$cancel)
72  {
73  $error = 0;
74 
75  $object->label = GETPOST('label', 'alpha');
76  if (empty($object->label))
77  {
78  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
79  $error++;
80  }
81 
82  if (empty($error))
83  {
84  $object->address = GETPOST('address', 'alpha');
85  $object->zip = GETPOST('zipcode', 'alpha');
86  $object->town = GETPOST('town', 'alpha');
87  $object->country_id = $_POST["country_id"];
88  $object->status = GETPOST('status', 'int');
89  $object->fk_user_author = $user->id;
90  $object->datec = dol_now();
91  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
92 
93  $id = $object->create($user);
94 
95  if ($id > 0)
96  {
97  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
98  exit;
99  } else {
100  setEventMessages($object->error, $object->errors, 'errors');
101  }
102  } else {
103  $action = 'create';
104  }
105  } else {
106  header("Location: ../admin/admin_establishment.php");
107  exit;
108  }
109 }
110 
111 // Update record
112 elseif ($action == 'update')
113 {
114  $error = 0;
115 
116  if (!$cancel) {
117  $name = GETPOST('label', 'alpha');
118  if (empty($name)) {
119  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
120  $error++;
121  }
122 
123  if (empty($error))
124  {
125  $object->label = GETPOST('label', 'alphanohtml');
126  $object->address = GETPOST('address', 'alpha');
127  $object->zip = GETPOST('zipcode', 'alpha');
128  $object->town = GETPOST('town', 'alpha');
129  $object->country_id = GETPOST('country_id', 'int');
130  $object->fk_user_mod = $user->id;
131  $object->status = GETPOST('status', 'int');
132  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
133 
134  $result = $object->update($user);
135 
136  if ($result > 0)
137  {
138  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
139  exit;
140  } else {
141  setEventMessages($object->error, $object->errors, 'errors');
142  }
143  }
144  } else {
145  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']);
146  exit;
147  }
148 }
149 
150 /*
151  * View
152  */
153 
154 llxHeader();
155 
156 $form = new Form($db);
157 $formcompany = new FormCompany($db);
158 
159 /*
160  * Action create
161  */
162 if ($action == 'create')
163 {
164  print load_fiche_titre($langs->trans("NewEstablishment"));
165 
166  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
167  print '<input type="hidden" name="token" value="'.newToken().'">';
168  print '<input type="hidden" name="action" value="add">';
169 
171 
172  print '<table class="border centpercent">';
173 
174  // Name
175  print '<tr>';
176  print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
177  print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'"></td>';
178  print '</tr>';
179 
180  // Entity
181  /*
182  if (! empty($conf->multicompany->enabled)) {
183  print '<tr>';
184  print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
185  print '<td class="maxwidthonsmartphone">';
186  print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
187  print '</td>';
188  print '</tr>';
189  } */
190 
191  // Address
192  print '<tr>';
193  print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
194  print '<td>';
195  print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
196  print '</td>';
197  print '</tr>';
198 
199  // Zipcode
200  print '<tr>';
201  print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
202  print '<td>';
203  print $formcompany->select_ziptown(
204  GETPOST('zipcode', 'alpha'),
205  'zipcode',
206  array(
207  'town',
208  'selectcountry_id'
209  ),
210  6
211  );
212  print '</td>';
213  print '</tr>';
214 
215  // Town
216  print '<tr>';
217  print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
218  print '<td>';
219  print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
220  'zipcode',
221  'selectcountry_id'
222  ));
223  print '</td>';
224  print '</tr>';
225 
226  // Country
227  print '<tr>';
228  print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
229  print '<td class="maxwidthonsmartphone">';
230  print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id');
231  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
232  print '</td>';
233  print '</tr>';
234 
235  // Status
236  print '<tr>';
237  print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
238  print '<td>';
239  print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
240  print '</td></tr>';
241 
242  print '</table>';
243 
244  print dol_get_fiche_end();
245 
246  print '<div class="center">';
247  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
248  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
249  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
250  print '</div>';
251 
252  print '</form>';
253 }
254 
255 // Part to edit record
256 if (($id || $ref) && $action == 'edit')
257 {
258  $result = $object->fetch($id);
259  if ($result > 0)
260  {
261  $head = establishment_prepare_head($object);
262 
263  if ($action == 'edit')
264  {
265  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, 'building');
266 
267  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
268  print '<input type="hidden" name="token" value="'.newToken().'">';
269  print '<input type="hidden" name="action" value="update">';
270  print '<input type="hidden" name="id" value="'.$id.'">';
271 
272  print '<table class="border centpercent">';
273 
274  // Ref
275  print "<tr>";
276  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
277  print $object->id;
278  print '</td></tr>';
279 
280  // Name
281  print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
282  print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
283  print '</td></tr>';
284 
285  // Entity
286  /*
287  if (! empty($conf->multicompany->enabled)) {
288  print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
289  print '<td class="maxwidthonsmartphone">';
290  print $object->entity > 0 ? $object->entity : $conf->entity;
291  print '</td></tr>';
292  }*/
293 
294  // Address
295  print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
296  print '<td>';
297  print '<input name="address" id="address" value="'.$object->address.'">';
298  print '</td></tr>';
299 
300  // Zipcode / Town
301  print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
302  print $formcompany->select_ziptown($object->zip, 'zipcode', array(
303  'town',
304  'selectcountry_id'
305  ), 6).'</tr>';
306  print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
307  print $formcompany->select_ziptown($object->town, 'town', array(
308  'zipcode',
309  'selectcountry_id'
310  )).'</td></tr>';
311 
312  // Country
313  print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
314  print '<td class="maxwidthonsmartphone">';
315  print $form->select_country($object->country_id, 'country_id');
316  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
317  print '</td>';
318  print '</tr>';
319 
320  // Status
321  print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
322  print $form->selectarray('status', $status2label, $object->status);
323  print '</td></tr>';
324 
325  print '</table>';
326 
327  print dol_get_fiche_end();
328 
329  print '<div class="center">';
330  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
331  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
332  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
333  print '</div>';
334 
335  print '</form>';
336  }
337  } else dol_print_error($db);
338 }
339 
340 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
341 {
342  $res = $object->fetch_optionals();
343 
344  $head = establishment_prepare_head($object);
345  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, 'building');
346 
347  // Confirmation to delete
348  if ($action == 'delete')
349  {
350  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
351  }
352 
353 
354  // Object card
355  // ------------------------------------------------------------
356 
357  $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
358 
359  $morehtmlref = '<div class="refidno">';
360  $morehtmlref .= '</div>';
361 
362  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
363 
364 
365  print '<div class="fichecenter">';
366  //print '<div class="fichehalfleft">';
367  print '<div class="underbanner clearboth"></div>';
368  print '<table class="border centpercent">'."\n";
369 
370  // Name
371  print '<tr>';
372  print '<td class="titlefield">'.$langs->trans("Label").'</td>';
373  print '<td>'.$object->label.'</td>';
374  print '</tr>';
375 
376  // Entity
377  /*
378  if ($conf->multicompany->enabled) {
379  print '<tr>';
380  print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
381  print '<td>'.$object->entity.'</td>';
382  print '</tr>';
383  }*/
384 
385  // Address
386  print '<tr>';
387  print '<td>'.$langs->trans("Address").'</td>';
388  print '<td>'.$object->address.'</td>';
389  print '</tr>';
390 
391  // Zipcode
392  print '<tr>';
393  print '<td>'.$langs->trans("Zip").'</td>';
394  print '<td>'.$object->zip.'</td>';
395  print '</tr>';
396 
397  // Town
398  print '<tr>';
399  print '<td>'.$langs->trans("Town").'</td>';
400  print '<td>'.$object->town.'</td>';
401  print '</tr>';
402 
403  // Country
404  print '<tr>';
405  print '<td>'.$langs->trans("Country").'</td>';
406  print '<td>';
407  if ($object->country_id > 0)
408  {
409  $img = picto_from_langcode($object->country_code);
410  print $img ? $img.' ' : '';
411  print getCountry($object->getCountryCode(), 0, $db);
412  }
413  print '</td>';
414  print '</tr>';
415 
416  print '</table>';
417  print '</div>';
418 
419  print '<div class="clearboth"></div><br>';
420 
421  print dol_get_fiche_end();
422 
423  /*
424  * Barre d'actions
425  */
426 
427  print '<div class="tabsAction">';
428  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
429  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$id.'">'.$langs->trans('Delete').'</a>';
430  print '</div>';
431 }
432 
433 // End of page
434 llxFooter();
435 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage establishments.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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
establishment_prepare_head($object)
Return head table for establishment tabs screen.
Definition: hrm.lib.php:30
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:59
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.