dolibarr  19.0.0-dev
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 
23 // Load Dolibarr environment
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('admin', 'hrm'));
32 
33 $error = 0;
34 
35 $action = GETPOST('action', 'aZ09');
36 $cancel = GETPOST('cancel', 'alpha');
37 $confirm = GETPOST('confirm', 'alpha');
38 $id = GETPOST('id', 'int');
39 
40 // List of status
41 static $tmpstatus2label = array(
42  '0'=>'CloseEtablishment',
43  '1'=>'OpenEtablishment'
44 );
45 $status2label = array('');
46 foreach ($tmpstatus2label as $key => $val) {
47  $status2label[$key] = $langs->trans($val);
48 }
49 
50 $object = new Establishment($db);
51 
52 // Load object
53 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
54 
55 $permissiontoread = $user->admin;
56 $permissiontoadd = $user->admin; // Used by the include of actions_addupdatedelete.inc.php
57 $permissiontodelete = $user->admin;
58 $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1];
59 
60 // Security check - Protection if external user
61 //if ($user->socid > 0) accessforbidden();
62 //if ($user->socid > 0) $socid = $user->socid;
63 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
64 //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
65 if (!isModEnabled('hrm')) accessforbidden();
66 if (empty($permissiontoread)) accessforbidden();
67 
68 
69 /*
70  * Actions
71  */
72 
73 if ($action == 'confirm_delete' && $confirm == "yes") {
74  $result = $object->delete($id);
75  if ($result >= 0) {
76  header("Location: ../admin/admin_establishment.php");
77  exit;
78  } else {
79  setEventMessages($object->error, $object->errors, 'errors');
80  }
81 } elseif ($action == 'add') {
82  if (!$cancel) {
83  $error = 0;
84 
85  $object->label = GETPOST('label', 'alpha');
86  if (empty($object->label)) {
87  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
88  $error++;
89  }
90 
91  if (empty($error)) {
92  $object->address = GETPOST('address', 'alpha');
93  $object->zip = GETPOST('zipcode', 'alpha');
94  $object->town = GETPOST('town', 'alpha');
95  $object->country_id = GETPOST("country_id", 'int');
96  $object->status = GETPOST('status', 'int');
97  $object->fk_user_author = $user->id;
98  $object->datec = dol_now();
99  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
100 
101  $id = $object->create($user);
102 
103  if ($id > 0) {
104  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
105  exit;
106  } else {
107  setEventMessages($object->error, $object->errors, 'errors');
108  }
109  } else {
110  $action = 'create';
111  }
112  } else {
113  header("Location: ../admin/admin_establishment.php");
114  exit;
115  }
116 } elseif ($action == 'update') {
117  // Update record
118  $error = 0;
119 
120  if (!$cancel) {
121  $name = GETPOST('label', 'alpha');
122  if (empty($name)) {
123  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
124  $error++;
125  }
126 
127  if (empty($error)) {
128  $object->label = GETPOST('label', 'alphanohtml');
129  $object->address = GETPOST('address', 'alpha');
130  $object->zip = GETPOST('zipcode', 'alpha');
131  $object->town = GETPOST('town', 'alpha');
132  $object->country_id = GETPOST('country_id', 'int');
133  $object->fk_user_mod = $user->id;
134  $object->status = GETPOST('status', 'int');
135  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
136 
137  $result = $object->update($user);
138 
139  if ($result > 0) {
140  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
141  exit;
142  } else {
143  setEventMessages($object->error, $object->errors, 'errors');
144  }
145  }
146  } else {
147  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
148  exit;
149  }
150 }
151 
152 /*
153  * View
154  */
155 
156 llxHeader();
157 
158 $form = new Form($db);
159 $formcompany = new FormCompany($db);
160 
161 /*
162  * Action create
163  */
164 if ($action == 'create') {
165  print load_fiche_titre($langs->trans("NewEstablishment"));
166 
167  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
168  print '<input type="hidden" name="token" value="'.newToken().'">';
169  print '<input type="hidden" name="action" value="add">';
170 
171  print dol_get_fiche_head();
172 
173  print '<table class="border centpercent">';
174 
175  // Name
176  print '<tr>';
177  print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
178  print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'" autofocus></td>';
179  print '</tr>';
180 
181  // Entity
182  /*
183  if (isModEnabled('multicompany')) {
184  print '<tr>';
185  print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
186  print '<td class="maxwidthonsmartphone">';
187  print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
188  print '</td>';
189  print '</tr>';
190  } */
191 
192  // Address
193  print '<tr>';
194  print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
195  print '<td>';
196  print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
197  print '</td>';
198  print '</tr>';
199 
200  // Zipcode
201  print '<tr>';
202  print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
203  print '<td>';
204  print $formcompany->select_ziptown(
205  GETPOST('zipcode', 'alpha'),
206  'zipcode',
207  array(
208  'town',
209  'selectcountry_id'
210  ),
211  6
212  );
213  print '</td>';
214  print '</tr>';
215 
216  // Town
217  print '<tr>';
218  print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
219  print '<td>';
220  print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
221  'zipcode',
222  'selectcountry_id'
223  ));
224  print '</td>';
225  print '</tr>';
226 
227  // Country
228  print '<tr>';
229  print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
230  print '<td class="maxwidthonsmartphone">';
231  print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id');
232  if ($user->admin) {
233  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
234  }
235  print '</td>';
236  print '</tr>';
237 
238  // Status
239  print '<tr>';
240  print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
241  print '<td>';
242  print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
243  print '</td></tr>';
244 
245  print '</table>';
246 
247  print dol_get_fiche_end();
248 
249  print '<div class="center">';
250  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
251  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
252  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
253  print '</div>';
254 
255  print '</form>';
256 }
257 
258 // Part to edit record
259 if ((!empty($id) || !empty($ref)) && $action == 'edit') {
260  $result = $object->fetch($id);
261  if ($result > 0) {
262  $head = establishment_prepare_head($object);
263 
264  if ($action == 'edit') {
265  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
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 (isModEnabled('multicompany')) {
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) {
317  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
318  }
319  print '</td>';
320  print '</tr>';
321 
322  // Status
323  print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
324  print $form->selectarray('status', $status2label, $object->status);
325  print '</td></tr>';
326 
327  print '</table>';
328 
329  print dol_get_fiche_end();
330 
331  print $form->buttonsSaveCancel();
332 
333  print '</form>';
334  }
335  } else {
336  dol_print_error($db);
337  }
338 }
339 
340 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
341  $res = $object->fetch_optionals();
342 
343  $head = establishment_prepare_head($object);
344  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
345 
346  // Confirmation to delete
347  if ($action == 'delete') {
348  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
349  }
350 
351 
352  // Object card
353  // ------------------------------------------------------------
354 
355  $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
356 
357  $morehtmlref = '<div class="refidno">';
358  $morehtmlref .= '</div>';
359 
360  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
361 
362 
363  print '<div class="fichecenter">';
364  //print '<div class="fichehalfleft">';
365  print '<div class="underbanner clearboth"></div>';
366  print '<table class="border centpercent">'."\n";
367 
368  // Name
369  print '<tr>';
370  print '<td class="titlefield">'.$langs->trans("Label").'</td>';
371  print '<td>'.$object->label.'</td>';
372  print '</tr>';
373 
374  // Entity
375  /*
376  if (!isModEnabled('multicompany') {
377  print '<tr>';
378  print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
379  print '<td>'.$object->entity.'</td>';
380  print '</tr>';
381  }*/
382 
383  // Address
384  print '<tr>';
385  print '<td>'.$langs->trans("Address").'</td>';
386  print '<td>'.$object->address.'</td>';
387  print '</tr>';
388 
389  // Zipcode
390  print '<tr>';
391  print '<td>'.$langs->trans("Zip").'</td>';
392  print '<td>'.$object->zip.'</td>';
393  print '</tr>';
394 
395  // Town
396  print '<tr>';
397  print '<td>'.$langs->trans("Town").'</td>';
398  print '<td>'.$object->town.'</td>';
399  print '</tr>';
400 
401  // Country
402  print '<tr>';
403  print '<td>'.$langs->trans("Country").'</td>';
404  print '<td>';
405  if ($object->country_id > 0) {
406  $img = picto_from_langcode($object->country_code);
407  print $img ? $img.' ' : '';
408  print getCountry($object->getCountryCode(), 0, $db);
409  }
410  print '</td>';
411  print '</tr>';
412 
413  print '</table>';
414  print '</div>';
415 
416  print '<div class="clearboth"></div><br>';
417 
418  print dol_get_fiche_end();
419 
420  /*
421  * Action bar
422  */
423  print '<div class="tabsAction">';
424 
425  // Modify
426  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
427 
428  // Delete
429  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
430 
431  print '</div>';
432 }
433 
434 // End of page
435 llxFooter();
436 $db->close();
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 establishments.
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.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
establishment_prepare_head($object)
Return head table for establishment tabs screen.
Definition: hrm.lib.php:30
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_now($mode='auto')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.