dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.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
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31
41// Load translation files required by the page
42$langs->loadLangs(array('admin', 'hrm'));
43
44$error = 0;
45
46$action = GETPOST('action', 'aZ09');
47$cancel = GETPOST('cancel', 'alpha');
48$confirm = GETPOST('confirm', 'alpha');
49$id = GETPOSTINT('id');
50
51// List of status
52static $tmpstatus2label = array(
53 '0' => 'CloseEtablishment',
54 '1' => 'OpenEtablishment'
55);
56$status2label = array('');
57foreach ($tmpstatus2label as $key => $val) {
58 $status2label[$key] = $langs->trans($val);
59}
60
61$object = new Establishment($db);
62
63// Load object
64include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
65
66$permissiontoread = $user->admin;
67$permissiontoadd = $user->admin; // Used by the include of actions_addupdatedelete.inc.php
68$permissiontodelete = $user->admin;
69
70$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1];
71
72// Security check - Protection if external user
73//if ($user->socid > 0) accessforbidden();
74//if ($user->socid > 0) $socid = $user->socid;
75//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
76//restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
77if (!isModEnabled('hrm')) {
79}
80if (empty($permissiontoread)) {
82}
83
84
85/*
86 * Actions
87 */
88
89if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) {
90 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
91 $result = $object->delete($user);
92 if ($result >= 0) {
93 header("Location: ../admin/admin_establishment.php");
94 exit;
95 } else {
96 setEventMessages($object->error, $object->errors, 'errors');
97 }
98} elseif ($action == 'add' && $permissiontoadd) {
99 if (!$cancel) {
100 $error = 0;
101
102 $object->label = GETPOST('label', 'alpha');
103 if (empty($object->label)) {
104 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
105 $error++;
106 }
107
108 if (empty($error)) {
109 $object->address = GETPOST('address', 'alpha');
110 $object->zip = GETPOST('zipcode', 'alpha');
111 $object->town = GETPOST('town', 'alpha');
112 $object->country_id = GETPOSTINT("country_id");
113 $object->status = GETPOSTINT('status');
114 $object->fk_user_author = $user->id;
115 $object->datec = dol_now();
116 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
117
118 $id = $object->create($user);
119
120 if ($id > 0) {
121 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
122 exit;
123 } else {
124 setEventMessages($object->error, $object->errors, 'errors');
125 }
126 } else {
127 $action = 'create';
128 }
129 } else {
130 header("Location: ../admin/admin_establishment.php");
131 exit;
132 }
133} elseif ($action == 'update' && $permissiontoadd) {
134 // Update record
135 $error = 0;
136
137 if (!$cancel) {
138 $name = GETPOST('label', 'alpha');
139 if (empty($name)) {
140 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
141 $error++;
142 }
143
144 if (empty($error)) {
145 $object->label = GETPOST('label', 'alphanohtml');
146 $object->address = GETPOST('address', 'alpha');
147 $object->zip = GETPOST('zipcode', 'alpha');
148 $object->town = GETPOST('town', 'alpha');
149 $object->country_id = GETPOSTINT('country_id');
150 $object->fk_user_mod = $user->id;
151 $object->status = GETPOSTINT('status');
152 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
153
154 $result = $object->update($user);
155
156 if ($result > 0) {
157 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
158 exit;
159 } else {
160 setEventMessages($object->error, $object->errors, 'errors');
161 }
162 }
163 } else {
164 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
165 exit;
166 }
167}
168
169
170/*
171 * View
172 */
173
174llxHeader();
175
176$form = new Form($db);
177$formcompany = new FormCompany($db);
178
179// Action create
180if ($action == 'create') {
181 print load_fiche_titre($langs->trans("NewEstablishment"));
182
183 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
184 print '<input type="hidden" name="token" value="'.newToken().'">';
185 print '<input type="hidden" name="action" value="add">';
186
187 print dol_get_fiche_head();
188
189 print '<table class="border centpercent">';
190
191 // Name
192 print '<tr>';
193 print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
194 print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'" autofocus></td>';
195 print '</tr>';
196
197 // Entity
198 /*
199 if (isModEnabled('multicompany')) {
200 print '<tr>';
201 print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
202 print '<td class="maxwidthonsmartphone">';
203 print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
204 print '</td>';
205 print '</tr>';
206 } */
207
208 // Address
209 print '<tr>';
210 print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
211 print '<td>';
212 print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
213 print '</td>';
214 print '</tr>';
215
216 // Zipcode
217 print '<tr>';
218 print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
219 print '<td>';
220 print $formcompany->select_ziptown(
221 GETPOST('zipcode', 'alpha'),
222 'zipcode',
223 array(
224 'town',
225 'selectcountry_id'
226 ),
227 6
228 );
229 print '</td>';
230 print '</tr>';
231
232 // Town
233 print '<tr>';
234 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
235 print '<td>';
236 print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
237 'zipcode',
238 'selectcountry_id'
239 ));
240 print '</td>';
241 print '</tr>';
242
243 // Country
244 print '<tr>';
245 print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
246 print '<td class="maxwidthonsmartphone">';
247 print $form->select_country((string) (GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : ($object->country_id ? $object->country_id : $mysoc->country_id)), 'country_id');
248 if ($user->admin) {
249 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
250 }
251 print '</td>';
252 print '</tr>';
253
254 // Status
255 print '<tr>';
256 print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
257 print '<td>';
258 print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
259 print '</td></tr>';
260
261 print '</table>';
262
263 print dol_get_fiche_end();
264
265 print '<div class="center">';
266 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
267 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
268 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
269 print '</div>';
270
271 print '</form>';
272}
273
274// Part to edit record
275if ((!empty($id) || !empty($ref)) && $action == 'edit') {
276 $result = $object->fetch($id);
277 if ($result > 0) {
278 $head = establishment_prepare_head($object);
279
280 if ($action == 'edit') {
281 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
282
283 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
284 print '<input type="hidden" name="token" value="'.newToken().'">';
285 print '<input type="hidden" name="action" value="update">';
286 print '<input type="hidden" name="id" value="'.$id.'">';
287
288 print '<table class="border centpercent">';
289
290 // Ref
291 print "<tr>";
292 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
293 print $object->id;
294 print '</td></tr>';
295
296 // Name
297 print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
298 print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
299 print '</td></tr>';
300
301 // Entity
302 /*
303 if (isModEnabled('multicompany')) {
304 print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
305 print '<td class="maxwidthonsmartphone">';
306 print $object->entity > 0 ? $object->entity : $conf->entity;
307 print '</td></tr>';
308 }*/
309
310 // Address
311 print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
312 print '<td>';
313 print '<input name="address" id="address" value="'.$object->address.'">';
314 print '</td></tr>';
315
316 // Zipcode / Town
317 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
318 print $formcompany->select_ziptown($object->zip, 'zipcode', array(
319 'town',
320 'selectcountry_id'
321 ), 6).'</tr>';
322 print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
323 print $formcompany->select_ziptown($object->town, 'town', array(
324 'zipcode',
325 'selectcountry_id'
326 )).'</td></tr>';
327
328 // Country
329 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
330 print '<td class="maxwidthonsmartphone">';
331 print $form->select_country((string) $object->country_id, 'country_id');
332 if ($user->admin) {
333 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
334 }
335 print '</td>';
336 print '</tr>';
337
338 // Status
339 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
340 print $form->selectarray('status', $status2label, $object->status);
341 print '</td></tr>';
342
343 print '</table>';
344
345 print dol_get_fiche_end();
346
347 print $form->buttonsSaveCancel();
348
349 print '</form>';
350 }
351 } else {
352 dol_print_error($db);
353 }
354}
355
356if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
357 $res = $object->fetch_optionals();
358
359 $head = establishment_prepare_head($object);
360 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
361
362 // Confirmation to delete
363 if ($action == 'delete') {
364 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
365 }
366
367
368 // Object card
369 // ------------------------------------------------------------
370
371 $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
372
373 $morehtmlref = '<div class="refidno">';
374 $morehtmlref .= '</div>';
375
376 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
377
378
379 print '<div class="fichecenter">';
380 //print '<div class="fichehalfleft">';
381 print '<div class="underbanner clearboth"></div>';
382 print '<table class="border centpercent">'."\n";
383
384 // Name
385 print '<tr>';
386 print '<td class="titlefield">'.$langs->trans("Label").'</td>';
387 print '<td>'.$object->label.'</td>';
388 print '</tr>';
389
390 // Entity
391 /*
392 if (!isModEnabled('multicompany') {
393 print '<tr>';
394 print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
395 print '<td>'.$object->entity.'</td>';
396 print '</tr>';
397 }*/
398
399 // Address
400 print '<tr>';
401 print '<td>'.$langs->trans("Address").'</td>';
402 print '<td>'.$object->address.'</td>';
403 print '</tr>';
404
405 // Zipcode
406 print '<tr>';
407 print '<td>'.$langs->trans("Zip").'</td>';
408 print '<td>'.$object->zip.'</td>';
409 print '</tr>';
410
411 // Town
412 print '<tr>';
413 print '<td>'.$langs->trans("Town").'</td>';
414 print '<td>'.$object->town.'</td>';
415 print '</tr>';
416
417 // Country
418 print '<tr>';
419 print '<td>'.$langs->trans("Country").'</td>';
420 print '<td>';
421 if ($object->country_id > 0) {
422 $img = picto_from_langcode($object->country_code);
423 print $img ? $img.' ' : '';
424 print getCountry($object->getCountryCode(), '', $db);
425 }
426 print '</td>';
427 print '</tr>';
428
429 print '</table>';
430 print '</div>';
431
432 print '<div class="clearboth"></div><br>';
433
434 print dol_get_fiche_end();
435
436 /*
437 * Action bar
438 */
439 print '<div class="tabsAction">';
440
441 // Modify
442 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
443
444 // Delete
445 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete, array('attr' => array('class' => 'reposition')))."\n";
446
447 print '</div>';
448}
449
450// End of page
451llxFooter();
452$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
global $mysoc
establishment_prepare_head($object)
Return head table for establishment tabs screen.
Definition hrm.lib.php:32
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.