dolibarr  17.0.4
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 $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1];
58 
59 // Security check - Protection if external user
60 //if ($user->socid > 0) accessforbidden();
61 //if ($user->socid > 0) $socid = $user->socid;
62 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
63 //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
64 if (!isModEnabled('hrm')) accessforbidden();
65 if (empty($permissiontoread)) accessforbidden();
66 
67 
68 /*
69  * Actions
70  */
71 
72 if ($action == 'confirm_delete' && $confirm == "yes") {
73  $result = $object->delete($id);
74  if ($result >= 0) {
75  header("Location: ../admin/admin_establishment.php");
76  exit;
77  } else {
78  setEventMessages($object->error, $object->errors, 'errors');
79  }
80 } elseif ($action == 'add') {
81  if (!$cancel) {
82  $error = 0;
83 
84  $object->label = GETPOST('label', 'alpha');
85  if (empty($object->label)) {
86  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
87  $error++;
88  }
89 
90  if (empty($error)) {
91  $object->address = GETPOST('address', 'alpha');
92  $object->zip = GETPOST('zipcode', 'alpha');
93  $object->town = GETPOST('town', 'alpha');
94  $object->country_id = GETPOST("country_id", 'int');
95  $object->status = GETPOST('status', 'int');
96  $object->fk_user_author = $user->id;
97  $object->datec = dol_now();
98  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
99 
100  $id = $object->create($user);
101 
102  if ($id > 0) {
103  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
104  exit;
105  } else {
106  setEventMessages($object->error, $object->errors, 'errors');
107  }
108  } else {
109  $action = 'create';
110  }
111  } else {
112  header("Location: ../admin/admin_establishment.php");
113  exit;
114  }
115 } elseif ($action == 'update') {
116  // Update record
117  $error = 0;
118 
119  if (!$cancel) {
120  $name = GETPOST('label', 'alpha');
121  if (empty($name)) {
122  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
123  $error++;
124  }
125 
126  if (empty($error)) {
127  $object->label = GETPOST('label', 'alphanohtml');
128  $object->address = GETPOST('address', 'alpha');
129  $object->zip = GETPOST('zipcode', 'alpha');
130  $object->town = GETPOST('town', 'alpha');
131  $object->country_id = GETPOST('country_id', 'int');
132  $object->fk_user_mod = $user->id;
133  $object->status = GETPOST('status', 'int');
134  $object->entity = GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity;
135 
136  $result = $object->update($user);
137 
138  if ($result > 0) {
139  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
140  exit;
141  } else {
142  setEventMessages($object->error, $object->errors, 'errors');
143  }
144  }
145  } else {
146  header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int'));
147  exit;
148  }
149 }
150 
151 /*
152  * View
153  */
154 
155 llxHeader();
156 
157 $form = new Form($db);
158 $formcompany = new FormCompany($db);
159 
160 /*
161  * Action create
162  */
163 if ($action == 'create') {
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 
170  print dol_get_fiche_head();
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").'" autofocus></td>';
178  print '</tr>';
179 
180  // Entity
181  /*
182  if (isModEnabled('multicompany')) {
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) {
232  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
233  }
234  print '</td>';
235  print '</tr>';
236 
237  // Status
238  print '<tr>';
239  print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
240  print '<td>';
241  print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
242  print '</td></tr>';
243 
244  print '</table>';
245 
246  print dol_get_fiche_end();
247 
248  print '<div class="center">';
249  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
250  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
251  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
252  print '</div>';
253 
254  print '</form>';
255 }
256 
257 // Part to edit record
258 if ((!empty($id) || !empty($ref)) && $action == 'edit') {
259  $result = $object->fetch($id);
260  if ($result > 0) {
261  $head = establishment_prepare_head($object);
262 
263  if ($action == 'edit') {
264  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
265 
266  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
267  print '<input type="hidden" name="token" value="'.newToken().'">';
268  print '<input type="hidden" name="action" value="update">';
269  print '<input type="hidden" name="id" value="'.$id.'">';
270 
271  print '<table class="border centpercent">';
272 
273  // Ref
274  print "<tr>";
275  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
276  print $object->id;
277  print '</td></tr>';
278 
279  // Name
280  print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
281  print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
282  print '</td></tr>';
283 
284  // Entity
285  /*
286  if (isModEnabled('multicompany')) {
287  print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
288  print '<td class="maxwidthonsmartphone">';
289  print $object->entity > 0 ? $object->entity : $conf->entity;
290  print '</td></tr>';
291  }*/
292 
293  // Address
294  print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
295  print '<td>';
296  print '<input name="address" id="address" value="'.$object->address.'">';
297  print '</td></tr>';
298 
299  // Zipcode / Town
300  print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
301  print $formcompany->select_ziptown($object->zip, 'zipcode', array(
302  'town',
303  'selectcountry_id'
304  ), 6).'</tr>';
305  print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
306  print $formcompany->select_ziptown($object->town, 'town', array(
307  'zipcode',
308  'selectcountry_id'
309  )).'</td></tr>';
310 
311  // Country
312  print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
313  print '<td class="maxwidthonsmartphone">';
314  print $form->select_country($object->country_id, 'country_id');
315  if ($user->admin) {
316  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
317  }
318  print '</td>';
319  print '</tr>';
320 
321  // Status
322  print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
323  print $form->selectarray('status', $status2label, $object->status);
324  print '</td></tr>';
325 
326  print '</table>';
327 
328  print dol_get_fiche_end();
329 
330  print $form->buttonsSaveCancel();
331 
332  print '</form>';
333  }
334  } else {
335  dol_print_error($db);
336  }
337 }
338 
339 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
340  $res = $object->fetch_optionals();
341 
342  $head = establishment_prepare_head($object);
343  print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
344 
345  // Confirmation to delete
346  if ($action == 'delete') {
347  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
348  }
349 
350 
351  // Object card
352  // ------------------------------------------------------------
353 
354  $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
355 
356  $morehtmlref = '<div class="refidno">';
357  $morehtmlref .= '</div>';
358 
359  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
360 
361 
362  print '<div class="fichecenter">';
363  //print '<div class="fichehalfleft">';
364  print '<div class="underbanner clearboth"></div>';
365  print '<table class="border centpercent">'."\n";
366 
367  // Name
368  print '<tr>';
369  print '<td class="titlefield">'.$langs->trans("Label").'</td>';
370  print '<td>'.$object->label.'</td>';
371  print '</tr>';
372 
373  // Entity
374  /*
375  if (!isModEnabled('multicompany') {
376  print '<tr>';
377  print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
378  print '<td>'.$object->entity.'</td>';
379  print '</tr>';
380  }*/
381 
382  // Address
383  print '<tr>';
384  print '<td>'.$langs->trans("Address").'</td>';
385  print '<td>'.$object->address.'</td>';
386  print '</tr>';
387 
388  // Zipcode
389  print '<tr>';
390  print '<td>'.$langs->trans("Zip").'</td>';
391  print '<td>'.$object->zip.'</td>';
392  print '</tr>';
393 
394  // Town
395  print '<tr>';
396  print '<td>'.$langs->trans("Town").'</td>';
397  print '<td>'.$object->town.'</td>';
398  print '</tr>';
399 
400  // Country
401  print '<tr>';
402  print '<td>'.$langs->trans("Country").'</td>';
403  print '<td>';
404  if ($object->country_id > 0) {
405  $img = picto_from_langcode($object->country_code);
406  print $img ? $img.' ' : '';
407  print getCountry($object->getCountryCode(), 0, $db);
408  }
409  print '</td>';
410  print '</tr>';
411 
412  print '</table>';
413  print '</div>';
414 
415  print '<div class="clearboth"></div><br>';
416 
417  print dol_get_fiche_end();
418 
419  /*
420  * Action bar
421  */
422  print '<div class="tabsAction">';
423 
424  // Modify
425  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
426 
427  // Delete
428  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
429 
430  print '</div>';
431 }
432 
433 // End of page
434 llxFooter();
435 $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='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.