dolibarr  19.0.0-dev
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 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("resource", "companies", "other"));
32 
33 // Get parameters
34 $id = GETPOST('id', 'int');
35 $action = GETPOST('action', 'alpha');
36 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
37 
38 $lineid = GETPOST('lineid', 'int');
39 $element = GETPOST('element', 'alpha');
40 $element_id = GETPOST('element_id', 'int');
41 $resource_id = GETPOST('resource_id', 'int');
42 
43 $sortorder = GETPOST('sortorder', 'aZ09comma');
44 $sortfield = GETPOST('sortfield', 'aZ09comma');
45 $optioncss = GETPOST('optioncss', 'alpha');
46 
47 // Initialize context for list
48 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist';
49 
50 // Initialize technical objects
51 $object = new Dolresource($db);
52 $extrafields = new ExtraFields($db);
53 
54 // fetch optionals attributes and labels
55 $extrafields->fetch_name_optionals_label($object->table_element);
56 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
57 if (!is_array($search_array_options)) {
58  $search_array_options = array();
59 }
60 $search_ref = GETPOST("search_ref", 'alpha');
61 $search_type = GETPOST("search_type", 'alpha');
62 
63 // Load variable for pagination
64 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
65 
66 $filter = array();
67 
68 $hookmanager->initHooks(array('resourcelist'));
69 
70 if (empty($sortorder)) {
71  $sortorder = "ASC";
72 }
73 if (empty($sortfield)) {
74  $sortfield = "t.ref";
75 }
76 if (empty($arch)) {
77  $arch = 0;
78 }
79 
80 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
81 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
82 if (empty($page) || $page == -1) {
83  $page = 0;
84 } // If $page is not defined, or '' or -1
85 $offset = $limit * $page;
86 $pageprev = $page - 1;
87 $pagenext = $page + 1;
88 
89 $arrayfields = array(
90  't.ref' => array(
91  'label' => $langs->trans("Ref"),
92  'checked' => 1
93  ),
94  'ty.label' => array(
95  'label' => $langs->trans("ResourceType"),
96  'checked' => 1
97  ),
98 );
99 // Extra fields
100 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
101 
102 $object->fields = dol_sort_array($object->fields, 'position');
103 $arrayfields = dol_sort_array($arrayfields, 'position');
104 
105 
106 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
107 
108 // Do we click on purge search criteria ?
109 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
110  $search_ref = "";
111  $search_type = "";
112  $search_array_options = array();
113  $filter = array();
114 }
115 
116 if (empty($user->rights->resource->read)) {
117  accessforbidden();
118 }
119 
120 
121 /*
122  * Actions
123  */
124 
125 if (GETPOST('cancel', 'alpha')) {
126  $action = 'list';
127  $massaction = '';
128 }
129 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
130  $massaction = '';
131 }
132 
133 $parameters = array();
134 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
135 if ($reshook < 0) {
136  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
137 }
138 
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 
146 //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
147 $help_url = '';
148 $title = $langs->trans('Resources');
149 llxHeader('', $title, $help_url);
150 
151 
152 $sql = '';
153 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
154 
155 $param = '';
156 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
157  $param .= '&contextpage='.urlencode($contextpage);
158 }
159 if ($limit > 0 && $limit != $conf->liste_limit) {
160  $param .= '&limit='.((int) $limit);
161 }
162 
163 if ($search_ref != '') {
164  $param .= '&search_ref='.urlencode($search_ref);
165  $filter['t.ref'] = $search_ref;
166 }
167 if ($search_type != '') {
168  $param .= '&search_type='.urlencode($search_type);
169  $filter['ty.label'] = $search_type;
170 }
171 
172 // Including the previous script generate the correct SQL filter for all the extrafields
173 // we are playing with the behaviour of the Dolresource::fetchAll() by generating a fake
174 // extrafields filter key to make it works
175 $filter['ef.resource'] = $sql;
176 
177 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
178 
179 // Add $param from extra fields
180 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
181 
182 
183 // Confirmation suppression resource line
184 if ($action == 'delete_resource') {
185  print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1);
186 }
187 
188 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
189 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
190 
191 
192 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
193 if ($optioncss != '') {
194  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
195 }
196 print '<input type="hidden" name="token" value="'.newToken().'">';
197 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
198 print '<input type="hidden" name="action" value="list">';
199 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
200 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
201 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
202 
203 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
204  $ret = $object->fetchAll('', '', 0, 0, $filter);
205  if ($ret == -1) {
206  dol_print_error($db, $object->error);
207  exit;
208  } else {
209  $nbtotalofrecords = $ret;
210  }
211 }
212 
213 // Load object list
214 $ret = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
215 if ($ret == -1) {
216  dol_print_error($db, $object->error);
217  exit;
218 } else {
219  $newcardbutton = '';
220  if ($user->rights->resource->write) {
221  $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create');
222  }
223 
224  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1);
225 }
226 
227 $moreforfilter = '';
228 
229 print '<div class="div-table-responsive">';
230 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
231 
232 print '<tr class="liste_titre_filter">';
233 // Action column
234 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
235  print '<td class="liste_titre maxwidthsearch">';
236  $searchpicto = $form->showFilterAndCheckAddButtons(0);
237  print $searchpicto;
238  print '</td>';
239 }
240 if (!empty($arrayfields['t.ref']['checked'])) {
241  print '<td class="liste_titre">';
242  print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
243  print '</td>';
244 }
245 if (!empty($arrayfields['ty.label']['checked'])) {
246  print '<td class="liste_titre">';
247  print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
248  print '</td>';
249 }
250 // Extra fields
251 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
252 // Action column
253 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
254  print '<td class="liste_titre maxwidthsearch">';
255  $searchpicto = $form->showFilterAndCheckAddButtons(0);
256  print $searchpicto;
257  print '</td>';
258 }
259 print "</tr>\n";
260 
261 print '<tr class="liste_titre">';
262 // Action column
263 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
264  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
265 }
266 if (!empty($arrayfields['t.ref']['checked'])) {
267  print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
268 }
269 if (!empty($arrayfields['ty.label']['checked'])) {
270  print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder);
271 }
272 // Extra fields
273 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
274 // Action column
275 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
276  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
277 }
278 print "</tr>\n";
279 
280 
281 if ($ret) {
282  foreach ($object->lines as $resource) {
283  print '<tr class="oddeven">';
284 
285  // Action column
286  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
287  print '<td class="center">';
288  print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
289  print img_edit();
290  print '</a>';
291  print '&nbsp;';
292  print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
293  print img_delete('', 'class="marginleftonly"');
294  print '</a>';
295  print '</td>';
296  }
297 
298  if (!empty($arrayfields['t.ref']['checked'])) {
299  print '<td>';
300  print $resource->getNomUrl(5);
301  print '</td>';
302  if (!$i) {
303  $totalarray['nbfield']++;
304  }
305  }
306 
307  if (!empty($arrayfields['ty.label']['checked'])) {
308  print '<td>';
309  print $resource->type_label;
310  print '</td>';
311  if (!$i) {
312  $totalarray['nbfield']++;
313  }
314  }
315  // Extra fields
316  $obj = (Object) $resource->array_options;
317  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
318 
319  // Action column
320  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
321  print '<td class="center">';
322  print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
323  print img_edit();
324  print '</a>';
325  print '&nbsp;';
326  print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
327  print img_delete('', 'class="marginleftonly"');
328  print '</a>';
329  print '</td>';
330  }
331  if (!$i) {
332  $totalarray['nbfield']++;
333  }
334 
335  print '</tr>';
336  }
337 } else {
338  $colspan = 1;
339  foreach ($arrayfields as $key => $val) {
340  if (!empty($val['checked'])) {
341  $colspan++;
342  }
343  }
344  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
345 }
346 
347 print '</table>';
348 print "</form>\n";
349 
350 // End of page
351 llxFooter();
352 $db->close();
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:118
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
DAO Resource object.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.