dolibarr  13.0.2
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-2019 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', 'alpha');
42 $sortfield = GETPOST('sortfield', 'aZ09comma');
43 
44 // Initialize context for list
45 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist';
46 
47 // Initialize technical objects
48 $object = new Dolresource($db);
49 $extrafields = new ExtraFields($db);
50 
51 // fetch optionals attributes and labels
52 $extrafields->fetch_name_optionals_label($object->table_element);
53 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
54 if (!is_array($search_array_options)) $search_array_options = array();
55 $search_ref = GETPOST("search_ref", 'alpha');
56 $search_type = GETPOST("search_type", 'alpha');
57 
58 // Load variable for pagination
59 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
60 
61 
62 $filter = array();
63 
64 $param = '';
65 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&amp;contextpage='.urlencode($contextpage);
66 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&amp;limit='.urlencode($limit);
67 
68 if ($search_ref != '') {
69  $param .= '&search_ref='.urlencode($search_ref);
70  $filter['t.ref'] = $search_ref;
71 }
72 if ($search_type != '') {
73  $param .= '&search_type='.urlencode($search_type);
74  $filter['ty.label'] = $search_type;
75 }
76 
77 // Add $param from extra fields
78 foreach ($search_array_options as $key => $val)
79 {
80  $crit = $val;
81  $tmpkey = preg_replace('/search_options_/', '', $key);
82  $typ = $extrafields->attributes[$object->table_element]['type'][$tmpkey];
83  if ($val != '') {
84  $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
85  }
86  $mode_search = 0;
87  if (in_array($typ, array('int', 'double', 'real'))) $mode_search = 1; // Search on a numeric
88  if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1') $mode_search = 2; // Search on a foreign key int
89  if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0') && (!in_array($typ, array('link')) || $crit != '-1'))
90  {
91  $filter['ef.'.$tmpkey] = natural_search('ef.'.$tmpkey, $crit, $mode_search);
92  }
93 }
94 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
95 
96 
97 $hookmanager->initHooks(array('resourcelist'));
98 
99 if (empty($sortorder)) $sortorder = "ASC";
100 if (empty($sortfield)) $sortfield = "t.ref";
101 if (empty($arch)) $arch = 0;
102 
103 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
104 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
105 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
106 $offset = $limit * $page;
107 $pageprev = $page - 1;
108 $pagenext = $page + 1;
109 
110 if (!$user->rights->resource->read) {
111  accessforbidden();
112 }
113 $arrayfields = array(
114  't.ref' => array(
115  'label' => $langs->trans("Ref"),
116  'checked' => 1
117  ),
118  'ty.label' => array(
119  'label' => $langs->trans("ResourceType"),
120  'checked' => 1
121  ),
122 );
123 // Extra fields
124 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
125 
126 $object->fields = dol_sort_array($object->fields, 'position');
127 $arrayfields = dol_sort_array($arrayfields, 'position');
128 
129 
130 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
131 
132 // Do we click on purge search criteria ?
133 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
134 {
135  $search_ref = "";
136  $search_type = "";
137  $search_array_options = array();
138  $filter = array();
139 }
140 
141 
142 /*
143  * Action
144  */
145 
146 $parameters = array();
147 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
148 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
149 
150 
151 /*
152  * View
153  */
154 
155 $form = new Form($db);
156 
157 $pagetitle = $langs->trans('ResourcePageIndex');
158 llxHeader('', $pagetitle, '');
159 
160 // Confirmation suppression resource line
161 if ($action == 'delete_resource')
162 {
163  print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1);
164 }
165 
166 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
167 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);
168 
169 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
170 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
171 print '<input type="hidden" name="token" value="'.newToken().'">';
172 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
173 print '<input type="hidden" name="action" value="list">';
174 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
175 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
176 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
177 
178 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
179 {
180  $ret = $object->fetch_all('', '', 0, 0, $filter);
181  if ($ret == -1) {
182  dol_print_error($db, $object->error);
183  exit;
184  } else {
185  $nbtotalofrecords = $ret;
186  }
187 }
188 
189 // Load object list
190 $ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset, $filter);
191 if ($ret == -1) {
192  dol_print_error($db, $object->error);
193  exit;
194 } else {
195  $newcardbutton = '';
196  if ($user->rights->resource->write)
197  {
198  $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create');
199  }
200 
201  print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1);
202 }
203 
204 $moreforfilter = '';
205 
206 print '<div class="div-table-responsive">';
207 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
208 
209 print '<tr class="liste_titre_filter">';
210 if (!empty($arrayfields['t.ref']['checked']))
211 {
212  print '<td class="liste_titre">';
213  print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
214  print '</td>';
215 }
216 if (!empty($arrayfields['ty.label']['checked']))
217 {
218  print '<td class="liste_titre">';
219  print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
220  print '</td>';
221 }
222 // Extra fields
223 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
224 // Action column
225 print '<td class="liste_titre maxwidthsearch">';
226 $searchpicto = $form->showFilterAndCheckAddButtons(0);
227 print $searchpicto;
228 print '</td>';
229 print "</tr>\n";
230 
231 print '<tr class="liste_titre">';
232 if (!empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
233 if (!empty($arrayfields['ty.label']['checked'])) print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder);
234 // Extra fields
235 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
236 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
237 print "</tr>\n";
238 
239 
240 if ($ret)
241 {
242  foreach ($object->lines as $resource)
243  {
244  print '<tr class="oddeven">';
245 
246  if (!empty($arrayfields['t.ref']['checked']))
247  {
248  print '<td>';
249  print $resource->getNomUrl(5);
250  print '</td>';
251  if (!$i) $totalarray['nbfield']++;
252  }
253 
254  if (!empty($arrayfields['ty.label']['checked']))
255  {
256  print '<td>';
257  print $resource->type_label;
258  print '</td>';
259  if (!$i) $totalarray['nbfield']++;
260  }
261  // Extra fields
262  $obj = (Object) $resource->array_options;
263  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
264 
265  print '<td class="center">';
266  print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
267  print img_edit();
268  print '</a>';
269  print '&nbsp;';
270  print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
271  print img_delete('', 'class="marginleftonly"');
272  print '</a>';
273  print '</td>';
274  if (!$i) $totalarray['nbfield']++;
275 
276  print '</tr>';
277  }
278 } else {
279  $colspan = 1;
280  foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
281  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
282 }
283 
284 print '</table>';
285 print "</form>\n";
286 
287 // End of page
288 llxFooter();
289 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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 ...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print $_SERVER["PHP_SELF"]
Edit parameters.
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
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
DAO Resource object.