dolibarr 21.0.0-beta
admin_establishment.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
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
29
38// Load translation files required by the page
39$langs->loadLangs(array('admin', 'hrm'));
40
41$error = 0;
42
43// Permissions
44$permissiontoread = $user->admin;
45$permissiontoadd = $user->admin;
46
47// Security check - Protection if external user
48//if ($user->socid > 0) accessforbidden();
49//if ($user->socid > 0) $socid = $user->socid;
50//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
51//restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', 0);
52if (!isModEnabled('hrm')) {
54}
55if (empty($permissiontoread)) {
57}
58
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$sortfield = GETPOST('sortfield', 'aZ09comma');
61if (!$sortorder) {
62 $sortorder = "DESC";
63}
64if (!$sortfield) {
65 $sortfield = "e.rowid";
66}
67
68if (empty($page) || $page == -1) {
69 $page = 0;
70}
71
72$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
73$offset = $limit * $page;
74$pageprev = $page - 1;
75$pagenext = $page + 1;
76
77
78/*
79 * Actions
80 */
81
82// None
83
84
85/*
86 * View
87 */
88
89$form = new Form($db);
90$establishmenttmp = new Establishment($db);
91
92$title = $langs->trans('Establishments');
93
94llxHeader('', $title, '');
95
96
97// Subheader
98$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
99print load_fiche_titre($langs->trans("HRMSetup"), $linkback, 'title_setup');
100
101
102// Configuration header
103$head = hrmAdminPrepareHead();
104print dol_get_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "hrm", 0, '');
105
106$param = '';
107
108$sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
109$sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
110$sql .= " WHERE e.entity IN (".getEntity('establishment').')';
111
112// Count total nb of records
113$nbtotalofrecords = '';
114if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
115 $resql = $db->query($sql);
116 $nbtotalofrecords = $db->num_rows($resql);
117
118 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
119 $page = 0;
120 $offset = 0;
121 }
122 $db->free($resql);
123}
124
125$sql .= $db->order($sortfield, $sortorder);
126$sql .= $db->plimit($limit + 1, $offset);
127
128$newcardbutton = '';
129$newcardbutton .= dolGetButtonTitle($langs->trans('NewEstablishment'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/hrm/establishment/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
130
131print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit, 0, 0, 1);
132
133
134$result = $db->query($sql);
135if ($result) {
136 $num = $db->num_rows($result);
137 $i = 0;
138
139 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
140 print '<table class="noborder centpercent">';
141 print '<tr class="liste_titre">';
142 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
143 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "e.label", "", "", "", $sortfield, $sortorder);
144 print_liste_field_titre("Address", $_SERVER["PHP_SELF"], "e.address", "", "", "", $sortfield, $sortorder);
145 print_liste_field_titre("Zip", $_SERVER["PHP_SELF"], "e.zip", "", "", "", $sortfield, $sortorder);
146 print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "e.town", "", "", "", $sortfield, $sortorder);
147 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right ');
148 print "</tr>\n";
149
150 if ($num > 0) {
151 $establishmentstatic = new Establishment($db);
152
153 while ($i < min($num, $limit)) {
154 $obj = $db->fetch_object($result);
155
156 $establishmentstatic->id = $obj->rowid;
157 $establishmentstatic->ref = $obj->ref;
158 $establishmentstatic->label = $obj->label;
159 $establishmentstatic->status = $obj->status;
160
161 print '<tr class="oddeven">';
162 print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
163 print '<td>'.dol_escape_htmltag($obj->label).'</td>';
164 print '<td>'.dol_escape_htmltag($obj->address).'</td>';
165 print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
166 print '<td>'.dol_escape_htmltag($obj->town).'</td>';
167 print '<td class="right">';
168 print $establishmentstatic->getLibStatut(5);
169 print '</td>';
170 print "</tr>\n";
171
172 $i++;
173 }
174 } else {
175 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
176 }
177
178 print '</table>';
179 print '</div>';
180} else {
181 dol_print_error($db);
182}
183
184print dol_get_fiche_end();
185
186// End of page
187llxFooter();
188$db->close();
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 manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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...
hrmAdminPrepareHead()
Prepare admin pages header.
Definition hrm.lib.php:35
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.