dolibarr 22.0.5
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 * 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 $result = $object->delete($user);
91 if ($result >= 0) {
92 header("Location: ../admin/admin_establishment.php");
93 exit;
94 } else {
95 setEventMessages($object->error, $object->errors, 'errors');
96 }
97} elseif ($action == 'add' && $permissiontoadd) {
98 if (!$cancel) {
99 $error = 0;
100
101 $object->label = GETPOST('label', 'alpha');
102 if (empty($object->label)) {
103 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
104 $error++;
105 }
106
107 if (empty($error)) {
108 $object->address = GETPOST('address', 'alpha');
109 $object->zip = GETPOST('zipcode', 'alpha');
110 $object->town = GETPOST('town', 'alpha');
111 $object->country_id = GETPOSTINT("country_id");
112 $object->status = GETPOSTINT('status');
113 $object->fk_user_author = $user->id;
114 $object->datec = dol_now();
115 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
116
117 $id = $object->create($user);
118
119 if ($id > 0) {
120 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
121 exit;
122 } else {
123 setEventMessages($object->error, $object->errors, 'errors');
124 }
125 } else {
126 $action = 'create';
127 }
128 } else {
129 header("Location: ../admin/admin_establishment.php");
130 exit;
131 }
132} elseif ($action == 'update' && $permissiontoadd) {
133 // Update record
134 $error = 0;
135
136 if (!$cancel) {
137 $name = GETPOST('label', 'alpha');
138 if (empty($name)) {
139 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
140 $error++;
141 }
142
143 if (empty($error)) {
144 $object->label = GETPOST('label', 'alphanohtml');
145 $object->address = GETPOST('address', 'alpha');
146 $object->zip = GETPOST('zipcode', 'alpha');
147 $object->town = GETPOST('town', 'alpha');
148 $object->country_id = GETPOSTINT('country_id');
149 $object->fk_user_mod = $user->id;
150 $object->status = GETPOSTINT('status');
151 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
152
153 $result = $object->update($user);
154
155 if ($result > 0) {
156 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
157 exit;
158 } else {
159 setEventMessages($object->error, $object->errors, 'errors');
160 }
161 }
162 } else {
163 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
164 exit;
165 }
166}
167
168
169/*
170 * View
171 */
172
173llxHeader();
174
175$form = new Form($db);
176$formcompany = new FormCompany($db);
177
178// Action create
179if ($action == 'create') {
180 print load_fiche_titre($langs->trans("NewEstablishment"));
181
182 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
183 print '<input type="hidden" name="token" value="'.newToken().'">';
184 print '<input type="hidden" name="action" value="add">';
185
186 print dol_get_fiche_head();
187
188 print '<table class="border centpercent">';
189
190 // Name
191 print '<tr>';
192 print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
193 print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'" autofocus></td>';
194 print '</tr>';
195
196 // Entity
197 /*
198 if (isModEnabled('multicompany')) {
199 print '<tr>';
200 print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
201 print '<td class="maxwidthonsmartphone">';
202 print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
203 print '</td>';
204 print '</tr>';
205 } */
206
207 // Address
208 print '<tr>';
209 print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
210 print '<td>';
211 print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
212 print '</td>';
213 print '</tr>';
214
215 // Zipcode
216 print '<tr>';
217 print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
218 print '<td>';
219 print $formcompany->select_ziptown(
220 GETPOST('zipcode', 'alpha'),
221 'zipcode',
222 array(
223 'town',
224 'selectcountry_id'
225 ),
226 6
227 );
228 print '</td>';
229 print '</tr>';
230
231 // Town
232 print '<tr>';
233 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
234 print '<td>';
235 print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
236 'zipcode',
237 'selectcountry_id'
238 ));
239 print '</td>';
240 print '</tr>';
241
242 // Country
243 print '<tr>';
244 print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
245 print '<td class="maxwidthonsmartphone">';
246 print $form->select_country((string) (GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : ($object->country_id ? $object->country_id : $mysoc->country_id)), 'country_id');
247 if ($user->admin) {
248 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
249 }
250 print '</td>';
251 print '</tr>';
252
253 // Status
254 print '<tr>';
255 print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
256 print '<td>';
257 print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
258 print '</td></tr>';
259
260 print '</table>';
261
262 print dol_get_fiche_end();
263
264 print '<div class="center">';
265 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
266 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
267 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
268 print '</div>';
269
270 print '</form>';
271}
272
273// Part to edit record
274if ((!empty($id) || !empty($ref)) && $action == 'edit') {
275 $result = $object->fetch($id);
276 if ($result > 0) {
278
279 if ($action == 'edit') {
280 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
281
282 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
283 print '<input type="hidden" name="token" value="'.newToken().'">';
284 print '<input type="hidden" name="action" value="update">';
285 print '<input type="hidden" name="id" value="'.$id.'">';
286
287 print '<table class="border centpercent">';
288
289 // Ref
290 print "<tr>";
291 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
292 print $object->id;
293 print '</td></tr>';
294
295 // Name
296 print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
297 print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
298 print '</td></tr>';
299
300 // Entity
301 /*
302 if (isModEnabled('multicompany')) {
303 print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
304 print '<td class="maxwidthonsmartphone">';
305 print $object->entity > 0 ? $object->entity : $conf->entity;
306 print '</td></tr>';
307 }*/
308
309 // Address
310 print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
311 print '<td>';
312 print '<input name="address" id="address" value="'.$object->address.'">';
313 print '</td></tr>';
314
315 // Zipcode / Town
316 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
317 print $formcompany->select_ziptown($object->zip, 'zipcode', array(
318 'town',
319 'selectcountry_id'
320 ), 6).'</tr>';
321 print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
322 print $formcompany->select_ziptown($object->town, 'town', array(
323 'zipcode',
324 'selectcountry_id'
325 )).'</td></tr>';
326
327 // Country
328 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
329 print '<td class="maxwidthonsmartphone">';
330 print $form->select_country((string) $object->country_id, 'country_id');
331 if ($user->admin) {
332 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
333 }
334 print '</td>';
335 print '</tr>';
336
337 // Status
338 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
339 print $form->selectarray('status', $status2label, $object->status);
340 print '</td></tr>';
341
342 print '</table>';
343
344 print dol_get_fiche_end();
345
346 print $form->buttonsSaveCancel();
347
348 print '</form>';
349 }
350 } else {
351 dol_print_error($db);
352 }
353}
354
355if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
356 $res = $object->fetch_optionals();
357
359 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
360
361 // Confirmation to delete
362 if ($action == 'delete') {
363 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
364 }
365
366
367 // Object card
368 // ------------------------------------------------------------
369
370 $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
371
372 $morehtmlref = '<div class="refidno">';
373 $morehtmlref .= '</div>';
374
375 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
376
377
378 print '<div class="fichecenter">';
379 //print '<div class="fichehalfleft">';
380 print '<div class="underbanner clearboth"></div>';
381 print '<table class="border centpercent">'."\n";
382
383 // Name
384 print '<tr>';
385 print '<td class="titlefield">'.$langs->trans("Label").'</td>';
386 print '<td>'.$object->label.'</td>';
387 print '</tr>';
388
389 // Entity
390 /*
391 if (!isModEnabled('multicompany') {
392 print '<tr>';
393 print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
394 print '<td>'.$object->entity.'</td>';
395 print '</tr>';
396 }*/
397
398 // Address
399 print '<tr>';
400 print '<td>'.$langs->trans("Address").'</td>';
401 print '<td>'.$object->address.'</td>';
402 print '</tr>';
403
404 // Zipcode
405 print '<tr>';
406 print '<td>'.$langs->trans("Zip").'</td>';
407 print '<td>'.$object->zip.'</td>';
408 print '</tr>';
409
410 // Town
411 print '<tr>';
412 print '<td>'.$langs->trans("Town").'</td>';
413 print '<td>'.$object->town.'</td>';
414 print '</tr>';
415
416 // Country
417 print '<tr>';
418 print '<td>'.$langs->trans("Country").'</td>';
419 print '<td>';
420 if ($object->country_id > 0) {
421 $img = picto_from_langcode($object->country_code);
422 print $img ? $img.' ' : '';
423 print getCountry($object->getCountryCode(), '', $db);
424 }
425 print '</td>';
426 print '</tr>';
427
428 print '</table>';
429 print '</div>';
430
431 print '<div class="clearboth"></div><br>';
432
433 print dol_get_fiche_end();
434
435 /*
436 * Action bar
437 */
438 print '<div class="tabsAction">';
439
440 // Modify
441 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
442
443 // Delete
444 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
445
446 print '</div>';
447}
448
449// End of page
450llxFooter();
451$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
establishment_prepare_head($object)
Return head table for establishment tabs screen.
Definition hrm.lib.php:31
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, $morecssdiv='')
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.