dolibarr 21.0.0-alpha
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')) {
45}
46if (empty($permissiontoread)) {
48}
49
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$sortfield = GETPOST('sortfield', 'aZ09comma');
52if (!$sortorder) {
53 $sortorder = "DESC";
54}
55if (!$sortfield) {
56 $sortfield = "e.rowid";
57}
58
59if (empty($page) || $page == -1) {
60 $page = 0;
61}
62
63$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67
68
69/*
70 * Actions
71 */
72
73// None
74
75
76/*
77 * View
78 */
79
80$form = new Form($db);
81$establishmenttmp = new Establishment($db);
82
83$title = $langs->trans('Establishments');
84
85llxHeader('', $title, '');
86
87
88// Subheader
89$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
90print load_fiche_titre($langs->trans("HRMSetup"), $linkback, 'title_setup');
91
92
93// Configuration header
94$head = hrmAdminPrepareHead();
95print dol_get_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "hrm", 0, '');
96
97$param = '';
98
99$sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
100$sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
101$sql .= " WHERE e.entity IN (".getEntity('establishment').')';
102
103// Count total nb of records
104$nbtotalofrecords = '';
105if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
106 $resql = $db->query($sql);
107 $nbtotalofrecords = $db->num_rows($resql);
108
109 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
110 $page = 0;
111 $offset = 0;
112 }
113 $db->free($resql);
114}
115
116$sql .= $db->order($sortfield, $sortorder);
117$sql .= $db->plimit($limit + 1, $offset);
118
119$newcardbutton = '';
120$newcardbutton .= dolGetButtonTitle($langs->trans('NewEstablishment'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/hrm/establishment/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
121
122print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit, 0, 0, 1);
123
124
125$result = $db->query($sql);
126if ($result) {
127 $num = $db->num_rows($result);
128 $i = 0;
129
130 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
131 print '<table class="noborder centpercent">';
132 print '<tr class="liste_titre">';
133 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
134 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "e.label", "", "", "", $sortfield, $sortorder);
135 print_liste_field_titre("Address", $_SERVER["PHP_SELF"], "e.address", "", "", "", $sortfield, $sortorder);
136 print_liste_field_titre("Zip", $_SERVER["PHP_SELF"], "e.zip", "", "", "", $sortfield, $sortorder);
137 print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "e.town", "", "", "", $sortfield, $sortorder);
138 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.status", "", "", '', $sortfield, $sortorder, 'right ');
139 print "</tr>\n";
140
141 if ($num > 0) {
142 $establishmentstatic = new Establishment($db);
143
144 while ($i < min($num, $limit)) {
145 $obj = $db->fetch_object($result);
146
147 $establishmentstatic->id = $obj->rowid;
148 $establishmentstatic->ref = $obj->ref;
149 $establishmentstatic->label = $obj->label;
150 $establishmentstatic->status = $obj->status;
151
152 print '<tr class="oddeven">';
153 print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
154 print '<td>'.dol_escape_htmltag($obj->label).'</td>';
155 print '<td>'.dol_escape_htmltag($obj->address).'</td>';
156 print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
157 print '<td>'.dol_escape_htmltag($obj->town).'</td>';
158 print '<td class="right">';
159 print $establishmentstatic->getLibStatut(5);
160 print '</td>';
161 print "</tr>\n";
162
163 $i++;
164 }
165 } else {
166 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
167 }
168
169 print '</table>';
170 print '</div>';
171} else {
172 dol_print_error($db);
173}
174
175print dol_get_fiche_end();
176
177// End of page
178llxFooter();
179$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:70
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.