dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
3  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
4  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array("resource", "companies", "other"));
31 
32 // Get parameters
33 $id = GETPOST('id', 'int');
34 $action = GETPOST('action', 'alpha');
35 
36 $lineid = GETPOST('lineid', 'int');
37 $element = GETPOST('element', 'alpha');
38 $element_id = GETPOST('element_id', 'int');
39 $resource_id = GETPOST('resource_id', 'int');
40 
41 $sortorder = GETPOST('sortorder', 'aZ09comma');
42 $sortfield = GETPOST('sortfield', 'aZ09comma');
43 $optioncss = GETPOST('optioncss', 'alpha');
44 
45 // Initialize context for list
46 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist';
47 
48 // Initialize technical objects
49 $object = new Dolresource($db);
50 $extrafields = new ExtraFields($db);
51 
52 // fetch optionals attributes and labels
53 $extrafields->fetch_name_optionals_label($object->table_element);
54 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
55 if (!is_array($search_array_options)) {
56  $search_array_options = array();
57 }
58 $search_ref = GETPOST("search_ref", 'alpha');
59 $search_type = GETPOST("search_type", 'alpha');
60 
61 // Load variable for pagination
62 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
63 
64 $filter = array();
65 
66 $hookmanager->initHooks(array('resourcelist'));
67 
68 if (empty($sortorder)) {
69  $sortorder = "ASC";
70 }
71 if (empty($sortfield)) {
72  $sortfield = "t.ref";
73 }
74 if (empty($arch)) {
75  $arch = 0;
76 }
77 
78 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
79 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
80 if (empty($page) || $page == -1) {
81  $page = 0;
82 } // If $page is not defined, or '' or -1
83 $offset = $limit * $page;
84 $pageprev = $page - 1;
85 $pagenext = $page + 1;
86 
87 $arrayfields = array(
88  't.ref' => array(
89  'label' => $langs->trans("Ref"),
90  'checked' => 1
91  ),
92  'ty.label' => array(
93  'label' => $langs->trans("ResourceType"),
94  'checked' => 1
95  ),
96 );
97 // Extra fields
98 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
99 
100 $object->fields = dol_sort_array($object->fields, 'position');
101 $arrayfields = dol_sort_array($arrayfields, 'position');
102 
103 
104 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
105 
106 // Do we click on purge search criteria ?
107 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
108  $search_ref = "";
109  $search_type = "";
110  $search_array_options = array();
111  $filter = array();
112 }
113 
114 if (empty($user->rights->resource->read)) {
115  accessforbidden();
116 }
117 
118 
119 /*
120  * Actions
121  */
122 
123 if (GETPOST('cancel', 'alpha')) {
124  $action = 'list';
125  $massaction = '';
126 }
127 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
128  $massaction = '';
129 }
130 
131 $parameters = array();
132 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
133 if ($reshook < 0) {
134  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
135 }
136 
137 
138 /*
139  * View
140  */
141 
142 $form = new Form($db);
143 
144 //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
145 $help_url = '';
146 $title = $langs->trans('Resources');
147 llxHeader('', $title, $help_url);
148 
149 
150 $sql = '';
151 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
152 
153 $param = '';
154 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
155  $param .= '&contextpage='.urlencode($contextpage);
156 }
157 if ($limit > 0 && $limit != $conf->liste_limit) {
158  $param .= '&limit='.urlencode($limit);
159 }
160 
161 if ($search_ref != '') {
162  $param .= '&search_ref='.urlencode($search_ref);
163  $filter['t.ref'] = $search_ref;
164 }
165 if ($search_type != '') {
166  $param .= '&search_type='.urlencode($search_type);
167  $filter['ty.label'] = $search_type;
168 }
169 
170 // Including the previous script generate the correct SQL filter for all the extrafields
171 // we are playing with the behaviour of the Dolresource::fetch_all() by generating a fake
172 // extrafields filter key to make it works
173 $filter['ef.resource'] = $sql;
174 
175 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
176 
177 // Add $param from extra fields
178 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
179 
180 
181 // Confirmation suppression resource line
182 if ($action == 'delete_resource') {
183  print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1);
184 }
185 
186 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
187 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);
188 
189 
190 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
191 if ($optioncss != '') {
192  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
193 }
194 print '<input type="hidden" name="token" value="'.newToken().'">';
195 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
196 print '<input type="hidden" name="action" value="list">';
197 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
198 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
199 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
200 
201 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
202  $ret = $object->fetchAll('', '', 0, 0, $filter);
203  if ($ret == -1) {
204  dol_print_error($db, $object->error);
205  exit;
206  } else {
207  $nbtotalofrecords = $ret;
208  }
209 }
210 
211 // Load object list
212 $ret = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
213 if ($ret == -1) {
214  dol_print_error($db, $object->error);
215  exit;
216 } else {
217  $newcardbutton = '';
218  if ($user->rights->resource->write) {
219  $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create');
220  }
221 
222  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1);
223 }
224 
225 $moreforfilter = '';
226 
227 print '<div class="div-table-responsive">';
228 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
229 
230 print '<tr class="liste_titre_filter">';
231 if (!empty($arrayfields['t.ref']['checked'])) {
232  print '<td class="liste_titre">';
233  print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
234  print '</td>';
235 }
236 if (!empty($arrayfields['ty.label']['checked'])) {
237  print '<td class="liste_titre">';
238  print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
239  print '</td>';
240 }
241 // Extra fields
242 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
243 // Action column
244 print '<td class="liste_titre maxwidthsearch">';
245 $searchpicto = $form->showFilterAndCheckAddButtons(0);
246 print $searchpicto;
247 print '</td>';
248 print "</tr>\n";
249 
250 print '<tr class="liste_titre">';
251 if (!empty($arrayfields['t.ref']['checked'])) {
252  print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
253 }
254 if (!empty($arrayfields['ty.label']['checked'])) {
255  print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder);
256 }
257 // Extra fields
258 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
259 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
260 print "</tr>\n";
261 
262 
263 if ($ret) {
264  foreach ($object->lines as $resource) {
265  print '<tr class="oddeven">';
266 
267  if (!empty($arrayfields['t.ref']['checked'])) {
268  print '<td>';
269  print $resource->getNomUrl(5);
270  print '</td>';
271  if (!$i) {
272  $totalarray['nbfield']++;
273  }
274  }
275 
276  if (!empty($arrayfields['ty.label']['checked'])) {
277  print '<td>';
278  print $resource->type_label;
279  print '</td>';
280  if (!$i) {
281  $totalarray['nbfield']++;
282  }
283  }
284  // Extra fields
285  $obj = (Object) $resource->array_options;
286  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
287 
288  print '<td class="center">';
289  print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
290  print img_edit();
291  print '</a>';
292  print '&nbsp;';
293  print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
294  print img_delete('', 'class="marginleftonly"');
295  print '</a>';
296  print '</td>';
297  if (!$i) {
298  $totalarray['nbfield']++;
299  }
300 
301  print '</tr>';
302  }
303 } else {
304  $colspan = 1;
305  foreach ($arrayfields as $key => $val) {
306  if (!empty($val['checked'])) {
307  $colspan++;
308  }
309  }
310  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
311 }
312 
313 print '</table>';
314 print "</form>\n";
315 
316 // End of page
317 llxFooter();
318 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
Dolresource
DAO Resource object.
Definition: dolresource.class.php:30
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
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
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
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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
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