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