dolibarr 20.0.0
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
24require '../../main.inc.php';
25require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
26require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28require_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 = GETPOSTINT('id');
39
40// List of status
41static $tmpstatus2label = array(
42 '0'=>'CloseEtablishment',
43 '1'=>'OpenEtablishment'
44);
45$status2label = array('');
46foreach ($tmpstatus2label as $key => $val) {
47 $status2label[$key] = $langs->trans($val);
48}
49
50$object = new Establishment($db);
51
52// Load object
53include 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);
65if (!isModEnabled('hrm')) {
67}
68if (empty($permissiontoread)) {
70}
71
72
73/*
74 * Actions
75 */
76
77if ($action == 'confirm_delete' && $confirm == "yes") {
78 $result = $object->delete($user);
79 if ($result >= 0) {
80 header("Location: ../admin/admin_establishment.php");
81 exit;
82 } else {
83 setEventMessages($object->error, $object->errors, 'errors');
84 }
85} elseif ($action == 'add') {
86 if (!$cancel) {
87 $error = 0;
88
89 $object->label = GETPOST('label', 'alpha');
90 if (empty($object->label)) {
91 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
92 $error++;
93 }
94
95 if (empty($error)) {
96 $object->address = GETPOST('address', 'alpha');
97 $object->zip = GETPOST('zipcode', 'alpha');
98 $object->town = GETPOST('town', 'alpha');
99 $object->country_id = GETPOSTINT("country_id");
100 $object->status = GETPOSTINT('status');
101 $object->fk_user_author = $user->id;
102 $object->datec = dol_now();
103 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
104
105 $id = $object->create($user);
106
107 if ($id > 0) {
108 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
109 exit;
110 } else {
111 setEventMessages($object->error, $object->errors, 'errors');
112 }
113 } else {
114 $action = 'create';
115 }
116 } else {
117 header("Location: ../admin/admin_establishment.php");
118 exit;
119 }
120} elseif ($action == 'update') {
121 // Update record
122 $error = 0;
123
124 if (!$cancel) {
125 $name = GETPOST('label', 'alpha');
126 if (empty($name)) {
127 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Label')), null, 'errors');
128 $error++;
129 }
130
131 if (empty($error)) {
132 $object->label = GETPOST('label', 'alphanohtml');
133 $object->address = GETPOST('address', 'alpha');
134 $object->zip = GETPOST('zipcode', 'alpha');
135 $object->town = GETPOST('town', 'alpha');
136 $object->country_id = GETPOSTINT('country_id');
137 $object->fk_user_mod = $user->id;
138 $object->status = GETPOSTINT('status');
139 $object->entity = GETPOSTINT('entity') > 0 ? GETPOSTINT('entity') : $conf->entity;
140
141 $result = $object->update($user);
142
143 if ($result > 0) {
144 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
145 exit;
146 } else {
147 setEventMessages($object->error, $object->errors, 'errors');
148 }
149 }
150 } else {
151 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
152 exit;
153 }
154}
155
156/*
157 * View
158 */
159
160llxHeader();
161
162$form = new Form($db);
163$formcompany = new FormCompany($db);
164
165/*
166 * Action create
167 */
168if ($action == 'create') {
169 print load_fiche_titre($langs->trans("NewEstablishment"));
170
171 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
172 print '<input type="hidden" name="token" value="'.newToken().'">';
173 print '<input type="hidden" name="action" value="add">';
174
175 print dol_get_fiche_head();
176
177 print '<table class="border centpercent">';
178
179 // Name
180 print '<tr>';
181 print '<td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td>';
182 print '<td><input name="label" id="label" value="'.GETPOST("label", "alphanohtml").'" autofocus></td>';
183 print '</tr>';
184
185 // Entity
186 /*
187 if (isModEnabled('multicompany')) {
188 print '<tr>';
189 print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
190 print '<td class="maxwidthonsmartphone">';
191 print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
192 print '</td>';
193 print '</tr>';
194 } */
195
196 // Address
197 print '<tr>';
198 print '<td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
199 print '<td>';
200 print '<input name="address" id="address" class="qutrevingtpercent" value="'.GETPOST('address', 'alphanohtml').'">';
201 print '</td>';
202 print '</tr>';
203
204 // Zipcode
205 print '<tr>';
206 print '<td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td>';
207 print '<td>';
208 print $formcompany->select_ziptown(
209 GETPOST('zipcode', 'alpha'),
210 'zipcode',
211 array(
212 'town',
213 'selectcountry_id'
214 ),
215 6
216 );
217 print '</td>';
218 print '</tr>';
219
220 // Town
221 print '<tr>';
222 print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td>';
223 print '<td>';
224 print $formcompany->select_ziptown(GETPOSTISSET('town') ? GETPOST('town', 'alpha') : $object->town, 'town', array(
225 'zipcode',
226 'selectcountry_id'
227 ));
228 print '</td>';
229 print '</tr>';
230
231 // Country
232 print '<tr>';
233 print '<td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
234 print '<td class="maxwidthonsmartphone">';
235 print $form->select_country(GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : ($object->country_id ? $object->country_id : $mysoc->country_id), 'country_id');
236 if ($user->admin) {
237 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
238 }
239 print '</td>';
240 print '</tr>';
241
242 // Status
243 print '<tr>';
244 print '<td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td>';
245 print '<td>';
246 print $form->selectarray('status', $status2label, GETPOSTISSET('status') ? GETPOST('status', 'alpha') : 1);
247 print '</td></tr>';
248
249 print '</table>';
250
251 print dol_get_fiche_end();
252
253 print '<div class="center">';
254 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
255 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
256 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
257 print '</div>';
258
259 print '</form>';
260}
261
262// Part to edit record
263if ((!empty($id) || !empty($ref)) && $action == 'edit') {
264 $result = $object->fetch($id);
265 if ($result > 0) {
267
268 if ($action == 'edit') {
269 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), 0, $object->picto);
270
271 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
272 print '<input type="hidden" name="token" value="'.newToken().'">';
273 print '<input type="hidden" name="action" value="update">';
274 print '<input type="hidden" name="id" value="'.$id.'">';
275
276 print '<table class="border centpercent">';
277
278 // Ref
279 print "<tr>";
280 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
281 print $object->id;
282 print '</td></tr>';
283
284 // Name
285 print '<tr><td>'.$form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
286 print '<input name="label" id="label" class="flat" value="'.$object->label.'">';
287 print '</td></tr>';
288
289 // Entity
290 /*
291 if (isModEnabled('multicompany')) {
292 print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
293 print '<td class="maxwidthonsmartphone">';
294 print $object->entity > 0 ? $object->entity : $conf->entity;
295 print '</td></tr>';
296 }*/
297
298 // Address
299 print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
300 print '<td>';
301 print '<input name="address" id="address" value="'.$object->address.'">';
302 print '</td></tr>';
303
304 // Zipcode / Town
305 print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
306 print $formcompany->select_ziptown($object->zip, 'zipcode', array(
307 'town',
308 'selectcountry_id'
309 ), 6).'</tr>';
310 print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
311 print $formcompany->select_ziptown($object->town, 'town', array(
312 'zipcode',
313 'selectcountry_id'
314 )).'</td></tr>';
315
316 // Country
317 print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td>';
318 print '<td class="maxwidthonsmartphone">';
319 print $form->select_country($object->country_id, 'country_id');
320 if ($user->admin) {
321 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
322 }
323 print '</td>';
324 print '</tr>';
325
326 // Status
327 print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0, 'string', '', 1).'</td><td>';
328 print $form->selectarray('status', $status2label, $object->status);
329 print '</td></tr>';
330
331 print '</table>';
332
333 print dol_get_fiche_end();
334
335 print $form->buttonsSaveCancel();
336
337 print '</form>';
338 }
339 } else {
340 dol_print_error($db);
341 }
342}
343
344if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
345 $res = $object->fetch_optionals();
346
348 print dol_get_fiche_head($head, 'card', $langs->trans("Establishment"), -1, $object->picto);
349
350 // Confirmation to delete
351 if ($action == 'delete') {
352 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteEstablishment"), $langs->trans("ConfirmDeleteEstablishment"), "confirm_delete");
353 }
354
355
356 // Object card
357 // ------------------------------------------------------------
358
359 $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/admin/admin_establishment.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
360
361 $morehtmlref = '<div class="refidno">';
362 $morehtmlref .= '</div>';
363
364 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', $morehtmlref);
365
366
367 print '<div class="fichecenter">';
368 //print '<div class="fichehalfleft">';
369 print '<div class="underbanner clearboth"></div>';
370 print '<table class="border centpercent">'."\n";
371
372 // Name
373 print '<tr>';
374 print '<td class="titlefield">'.$langs->trans("Label").'</td>';
375 print '<td>'.$object->label.'</td>';
376 print '</tr>';
377
378 // Entity
379 /*
380 if (!isModEnabled('multicompany') {
381 print '<tr>';
382 print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
383 print '<td>'.$object->entity.'</td>';
384 print '</tr>';
385 }*/
386
387 // Address
388 print '<tr>';
389 print '<td>'.$langs->trans("Address").'</td>';
390 print '<td>'.$object->address.'</td>';
391 print '</tr>';
392
393 // Zipcode
394 print '<tr>';
395 print '<td>'.$langs->trans("Zip").'</td>';
396 print '<td>'.$object->zip.'</td>';
397 print '</tr>';
398
399 // Town
400 print '<tr>';
401 print '<td>'.$langs->trans("Town").'</td>';
402 print '<td>'.$object->town.'</td>';
403 print '</tr>';
404
405 // Country
406 print '<tr>';
407 print '<td>'.$langs->trans("Country").'</td>';
408 print '<td>';
409 if ($object->country_id > 0) {
410 $img = picto_from_langcode($object->country_code);
411 print $img ? $img.' ' : '';
412 print getCountry($object->getCountryCode(), 0, $db);
413 }
414 print '</td>';
415 print '</tr>';
416
417 print '</table>';
418 print '</div>';
419
420 print '<div class="clearboth"></div><br>';
421
422 print dol_get_fiche_end();
423
424 /*
425 * Action bar
426 */
427 print '<div class="tabsAction">';
428
429 // Modify
430 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$id.'">'.$langs->trans('Modify').'</a>';
431
432 // Delete
433 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
434
435 print '</div>';
436}
437
438// End of page
439llxFooter();
440$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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:30
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.