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