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