dolibarr  9.0.0
admin_establishment.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
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 <http://www.gnu.org/licenses/>.
16  */
17 
23 require '../../main.inc.php';
24 require_once DOL_DOCUMENT_ROOT.'/core/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 if (! $user->admin)
32 
33 $error=0;
34 
35 // List of statut
36 static $tmpstatus2label=array(
37  '0'=>'OpenEtablishment',
38  '1'=>'CloseEtablishment'
39 );
40 $status2label=array('');
41 foreach ($tmpstatus2label as $key => $val) $status2label[$key]=$langs->trans($val);
42 
43 /*
44  * Actions
45  */
46 
47 /*
48  * View
49  */
50 llxHeader('', $langs->trans("Establishments"));
51 
52 $sortorder = GETPOST("sortorder");
53 $sortfield = GETPOST("sortfield");
54 if (!$sortorder) $sortorder="DESC";
55 if (!$sortfield) $sortfield="e.rowid";
56 
57 if ($page == -1) {
58  $page = 0 ;
59 }
60 
61 $offset = $conf->liste_limit * $page;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
64 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
65 
66 $form = new Form($db);
67 $establishmenttmp=new Establishment($db);
68 
69 dol_htmloutput_mesg($mesg);
70 
71 // Subheader
72 $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
73 print load_fiche_titre($langs->trans("HRMSetup"), $linkback);
74 
75 // Configuration header
76 $head = hrm_admin_prepare_head();
77 dol_fiche_head($head, 'establishments', $langs->trans("HRM"), -1, "user");
78 
79 $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status";
80 $sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
81 $sql.= " WHERE e.entity = ".$conf->entity;
82 $sql.= $db->order($sortfield,$sortorder);
83 $sql.= $db->plimit($limit+1, $offset);
84 
85 $result = $db->query($sql);
86 if ($result)
87 {
88  $num = $db->num_rows($result);
89  $i = 0;
90 
91  // Load attribute_label
92  print '<table class="noborder" width="100%">';
93  print '<tr class="liste_titre">';
94  print_liste_field_titre("Name",$_SERVER["PHP_SELF"],"e.name","","","",$sortfield,$sortorder);
95  print_liste_field_titre("Address",$_SERVER["PHP_SELF"],"e.address","","","",$sortfield,$sortorder);
96  print_liste_field_titre("Zipcode",$_SERVER["PHP_SELF"],"e.zip","","","",$sortfield,$sortorder);
97  print_liste_field_titre("Town",$_SERVER["PHP_SELF"],"e.town","","","",$sortfield,$sortorder);
98  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"e.status","","",'align="right"',$sortfield,$sortorder);
99  print "</tr>\n";
100 
101  if ($num > 0)
102  {
103  $establishmentstatic=new Establishment($db);
104 
105  while ($i < min($num,$limit))
106  {
107  $obj = $db->fetch_object($result);
108 
109  $establishmentstatic->id=$obj->rowid;
110  $establishmentstatic->name=$obj->name;
111  $establishmentstatic->status=$obj->status;
112 
113 
114  print '<tr class="oddeven">';
115  print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
116  print '<td align="left">'.$obj->address.'</td>';
117  print '<td align="left">'.$obj->zip.'</td>';
118  print '<td align="left">'.$obj->town.'</td>';
119 
120  print '<td align="right">';
121  print $establishmentstatic->getLibStatut(5);
122  print '</td>';
123  print "</tr>\n";
124 
125  $i++;
126  }
127  }
128  else
129  {
130  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
131  }
132 
133  print '</table>';
134 }
135 else
136 {
137  dol_print_error($db);
138 }
139 
140 dol_fiche_end();
141 
142 // Buttons
143 print '<div class="tabsAction">';
144 print '<a class="butAction" href="../establishment/card.php?action=create">'.$langs->trans("NewEstablishment").'</a>';
145 print '</div>';
146 
147 // End of page
148 llxFooter();
149 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
hrm_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: hrm.lib.php:64
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
Class to manage establishments.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).