dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
3  * Copyright (C) 2022 Open-Dsi <support@open-dsi.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array("products", "other"));
31 
32 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
33 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
34 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
35 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
36 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
37 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
38 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'productattributelist'; // To manage different context of search
39 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
40 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
41 
42 $id = GETPOST('id', 'int');
43 
44 // Load variable for pagination
45 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
46 $sortfield = GETPOST('sortfield', 'aZ09comma');
47 $sortorder = GETPOST('sortorder', 'aZ09comma');
48 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
50  // If $page is not defined, or '' or -1 or if we click on clear filters
51  $page = 0;
52 }
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 
57 // Initialize technical objects
58 $object = new ProductAttribute($db);
59 //$extrafields = new ExtraFields($db);
60 $diroutputmassaction = $conf->variants->dir_output.'/temp/massgeneration/'.$user->id;
61 $hookmanager->initHooks(array('productattributelist')); // Note that conf->hooks_modules contains array
62 
63 // Fetch optionals attributes and labels
64 //$extrafields->fetch_name_optionals_label($object->table_element);
65 
66 //$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
67 
68 // Default sort order (if not yet defined by previous GETPOST)
69 if (!$sortfield) {
70  $sortfield = "t.position"; // Set here default search field. By default 1st field in definition.
71 }
72 if (!$sortorder) {
73  $sortorder = "ASC";
74 }
75 
76 // Initialize array of search criterias
77 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
78 $search = array();
79 foreach ($object->fields as $key => $val) {
80  if (GETPOST('search_'.$key, 'alpha') !== '') {
81  $search[$key] = GETPOST('search_'.$key, 'alpha');
82  }
83  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
84  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
85  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
86  }
87 }
88 $search['nb_of_values'] = GETPOST('search_nb_of_values', 'alpha');
89 $search['nb_products'] = GETPOST('search_nb_products', 'alpha');
90 
91 // List of fields to search into when doing a "search in all"
92 $fieldstosearchall = array();
93 foreach ($object->fields as $key => $val) {
94  if (!empty($val['searchall'])) {
95  $fieldstosearchall['t.'.$key] = $val['label'];
96  }
97 }
98 
99 // Definition of array of fields for columns
100 $arrayfields = array();
101 foreach ($object->fields as $key => $val) {
102  // If $val['visible']==0, then we never show the field
103  if (!empty($val['visible'])) {
104  $visible = (int) dol_eval($val['visible'], 1);
105  $arrayfields['t.'.$key] = array(
106  'label'=>$val['label'],
107  'checked'=>(($visible < 0) ? 0 : 1),
108  'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
109  'position'=>$val['position'],
110  'help'=> isset($val['help']) ? $val['help'] : ''
111  );
112  }
113 }
114 $arrayfields['nb_of_values'] = array(
115  'label' => $langs->trans('NbOfDifferentValues'),
116  'checked' => 1,
117  'enabled' => 1,
118  'position' => 40,
119  'help' => ''
120 );
121 $arrayfields['nb_products'] = array(
122  'label' => $langs->trans('NbProducts'),
123  'checked' => 1,
124  'enabled' => 1,
125  'position' => 50,
126  'help' => ''
127 );
128 // Extra fields
129 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
130 
131 $object->fields = dol_sort_array($object->fields, 'position');
132 $arrayfields = dol_sort_array($arrayfields, 'position');
133 
134 $permissiontoread = $user->rights->variants->read;
135 $permissiontoadd = $user->rights->variants->write;
136 $permissiontodelete = $user->rights->variants->delete;
137 
138 // Security check
139 if (empty($conf->variants->enabled)) {
140  accessforbidden('Module not enabled');
141 }
142 $socid = 0;
143 if ($user->socid > 0) { // Protection if external user
144  //$socid = $user->socid;
145  accessforbidden();
146 }
147 if (!$permissiontoread) accessforbidden();
148 
149 
150 /*
151  * Actions
152  */
153 
154 if (GETPOST('cancel', 'alpha')) {
155  $action = 'list';
156  $massaction = '';
157 }
158 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
159  $massaction = '';
160 }
161 
162 $parameters = array();
163 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
164 if ($reshook < 0) {
165  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
166 }
167 
168 if (empty($reshook)) {
169  // Selection of new fields
170  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
171 
172  // Purge search criteria
173  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
174  foreach ($object->fields as $key => $val) {
175  $search[$key] = '';
176  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
177  $search[$key.'_dtstart'] = '';
178  $search[$key.'_dtend'] = '';
179  }
180  }
181  $search['nb_of_values'] = '';
182  $search['nb_products'] = '';
183  $toselect = array();
184  $search_array_options = array();
185  }
186  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
187  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
188  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
189  }
190 
191  if ($action == 'up' && $permissiontoadd) {
192  $object->attributeMoveUp($rowid);
193 
194  header('Location: '.$_SERVER['PHP_SELF']);
195  exit();
196  } elseif ($action == 'down' && $permissiontoadd) {
197  $object->attributeMoveDown($rowid);
198 
199  header('Location: '.$_SERVER['PHP_SELF']);
200  exit();
201  }
202 
203  // Mass actions
204  $objectclass = 'ProductAttribute';
205  $objectlabel = 'ProductAttribute';
206  $uploaddir = $conf->variants->dir_output;
207  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
208 }
209 
210 
211 
212 /*
213  * View
214  */
215 
216 $form = new Form($db);
217 
218 $now = dol_now();
219 
220 $help_url = '';
221 $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("ProductAttributes"));
222 $morejs = array();
223 $morecss = array();
224 
225 
226 // Build and execute select
227 // --------------------------------------------------------------------
228 $sql = "SELECT ";
229 $sql .= " COUNT(DISTINCT pav.rowid) AS nb_of_values, COUNT(DISTINCT pac2v.fk_prod_combination) AS nb_products,";
230 $sql .= $object->getFieldList("t");
231 // Add fields from extrafields
232 //if (!empty($extrafields->attributes[$object->table_element]['label'])) {
233 // foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
234 // $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.", " : "");
235 // }
236 //}
237 // Add fields from hooks
238 $parameters = array();
239 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
240 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
241 $sql = preg_replace('/,\s*$/', '', $sql);
242 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
243 //if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
244 // $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
245 //}
246 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination2val AS pac2v ON pac2v.fk_prod_attr = t.rowid";
247 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_value AS pav ON pav.fk_product_attribute = t.rowid";
248 // Add table from hooks
249 $parameters = array();
250 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
251 $sql .= $hookmanager->resPrint;
252 if ($object->ismultientitymanaged == 1) {
253  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
254 } else {
255  $sql .= " WHERE 1 = 1";
256 }
257 foreach ($search as $key => $val) {
258  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
259  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
260  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
261  if (preg_match('/_dtstart$/', $key)) {
262  $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
263  }
264  if (preg_match('/_dtend$/', $key)) {
265  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
266  }
267  }
268  } elseif (array_key_exists($key, $object->fields)) {
269  if ($key == 'status' && $search[$key] == -1) {
270  continue;
271  }
272  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
273  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
274  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
275  $search[$key] = '';
276  }
277  $mode_search = 2;
278  }
279  if ($search[$key] != '') {
280  $sql .= natural_search("t.".$key, $search[$key], (($key == 'status') ? 2 : $mode_search));
281  }
282  }
283 }
284 if ($search_all) {
285  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
286 }
287 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
288 // Add where from extra fields
289 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
290 // Add where from hooks
291 $parameters = array();
292 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
293 $sql .= $hookmanager->resPrint;
294 
295 $hasgroupby = true;
296 $sql .= " GROUP BY ";
297 foreach ($object->fields as $key => $val) {
298  $sql .= "t." . $key . ", ";
299 }
300 // Add fields from extrafields
301 //if (!empty($extrafields->attributes[$object->table_element]['label'])) {
302 // foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
303 // $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
304 // }
305 //}
306 // Add where from hooks
307 $parameters = array();
308 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
309 $sql .= $hookmanager->resPrint;
310 $sql = preg_replace("/,\s*$/", "", $sql);
311 
312 $sql .= " HAVING 1=1";
313 if ($search['nb_of_values'] != '') {
314  $sql .= natural_search("nb_of_values", $search['nb_of_values'], 1);
315 }
316 if ($search['nb_products'] != '') {
317  $sql .= natural_search("nb_products", $search['nb_products'], 1);
318 }
319 // Add HAVING from hooks
320 $parameters = array();
321 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
322 $sql .= empty($hookmanager->resPrint) ? "" : " ".$hookmanager->resPrint;
323 
324 // Count total nb of records
325 $nbtotalofrecords = '';
326 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
327  /* This old and fast method to get and count full list returns all record so use a high amount of memory.
328  $resql = $db->query($sql);
329  $nbtotalofrecords = $db->num_rows($resql);
330  */
331  /* The slow method does not consume memory on mysql (not tested on pgsql) */
332  /*$resql = $db->query($sql, 0, 'auto', 1);
333  while ($db->fetch_object($resql)) {
334  $nbtotalofrecords++;
335  }*/
336  /* The fast and low memory method to get and count full list converts the sql into a sql count */
337  $sqlforcount = preg_replace("/^SELECT[a-z0-9\._\s\(\),]+FROM/i", "SELECT COUNT(*) as nbtotalofrecords FROM", $sql);
338  $resql = $db->query($sqlforcount);
339  if ($resql) {
340  if ($hasgroupby) {
341  $nbtotalofrecords = $db->num_rows($resql);
342  } else {
343  $objforcount = $db->fetch_object($resql);
344  $nbtotalofrecords = $objforcount->nbtotalofrecords;
345  }
346  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
347  $page = 0;
348  $offset = 0;
349  }
350  $db->free($resql);
351  }
352 }
353 
354 // Complete request and execute it with limit
355 $sql .= $db->order($sortfield, $sortorder);
356 if ($limit) {
357  $sql .= $db->plimit($limit + 1, $offset);
358 }
359 
360 $resql = $db->query($sql);
361 if (!$resql) {
362  dol_print_error($db);
363  exit;
364 }
365 
366 $num = $db->num_rows($resql);
367 
368 
369 // Direct jump if only one record found
370 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
371  $obj = $db->fetch_object($resql);
372  $id = $obj->rowid;
373  header("Location: " . dol_buildpath('/variants/card.php', 2) . '?id=' . $id);
374  exit;
375 }
376 
377 
378 // Output page
379 // --------------------------------------------------------------------
380 
381 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
382 
383 $arrayofselected = is_array($toselect) ? $toselect : array();
384 
385 $param = '';
386 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
387  $param .= '&contextpage='.urlencode($contextpage);
388 }
389 if ($limit > 0 && $limit != $conf->liste_limit) {
390  $param .= '&limit='.urlencode($limit);
391 }
392 foreach ($search as $key => $val) {
393  if (is_array($search[$key]) && count($search[$key])) {
394  foreach ($search[$key] as $skey) {
395  if ($skey != '') {
396  $param .= '&search_'.$key.'[]='.urlencode($skey);
397  }
398  }
399  } elseif ($search[$key] != '') {
400  $param .= '&search_'.$key.'='.urlencode($search[$key]);
401  }
402 }
403 if ($optioncss != '') {
404  $param .= '&optioncss='.urlencode($optioncss);
405 }
406 // Add $param from extra fields
407 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
408 // Add $param from hooks
409 $parameters = array();
410 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
411 $param .= $hookmanager->resPrint;
412 
413 // List of mass actions available
414 $arrayofmassactions = array(
415  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
416  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
417  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
418  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
419 );
420 if ($permissiontodelete) {
421  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
422 }
423 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
424  $arrayofmassactions = array();
425 }
426 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
427 
428 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
429 if ($optioncss != '') {
430  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
431 }
432 print '<input type="hidden" name="token" value="'.newToken().'">';
433 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
434 print '<input type="hidden" name="action" value="list">';
435 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
436 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
437 print '<input type="hidden" name="page" value="'.$page.'">';
438 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
439 
440 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
441 
442 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
443 
444 // Add code for pre mass action (confirmation or email presend form)
445 $topicmail = "SendProductAttributeRef";
446 $modelmail = "productattribute";
447 $objecttmp = new ProductAttribute($db);
448 $trackid = 'pa'.$object->id;
449 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
450 
451 if ($search_all) {
452  foreach ($fieldstosearchall as $key => $val) {
453  $fieldstosearchall[$key] = $langs->trans($val);
454  }
455  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
456 }
457 
458 $moreforfilter = '';
459 /*$moreforfilter.='<div class="divsearchfield">';
460 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
461 $moreforfilter.= '</div>';*/
462 
463 $parameters = array();
464 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
465 if (empty($reshook)) {
466  $moreforfilter .= $hookmanager->resPrint;
467 } else {
468  $moreforfilter = $hookmanager->resPrint;
469 }
470 
471 if (!empty($moreforfilter)) {
472  print '<div class="liste_titre liste_titre_bydiv centpercent">';
473  print $moreforfilter;
474  print '</div>';
475 }
476 
477 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
478 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
479 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
480 
481 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
482 print '<table id="tableattributes" class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
483 
484 
485 // Fields title search
486 // --------------------------------------------------------------------
487 print '<tr class="liste_titre">';
488 foreach ($object->fields as $key => $val) {
489  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
490  if ($key == 'status') {
491  $cssforfield .= ($cssforfield ? ' ' : '').'center';
492  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
493  $cssforfield .= ($cssforfield ? ' ' : '').'center';
494  } elseif (in_array($val['type'], array('timestamp'))) {
495  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
496  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
497  $cssforfield .= ($cssforfield ? ' ' : '').'right';
498  }
499  if (!empty($arrayfields['t.'.$key]['checked'])) {
500  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
501  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
502  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
503  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
504  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
505  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
506  print '<div class="nowrap">';
507  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
508  print '</div>';
509  print '<div class="nowrap">';
510  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
511  print '</div>';
512  } elseif ($key == 'lang') {
513  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
514  $formadmin = new FormAdmin($db);
515  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
516  } else {
517  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
518  }
519  print '</td>';
520  }
521 }
522 // Extra fields
523 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
524 $key = 'nb_of_values';
525 if (!empty($arrayfields[$key]['checked'])) {
526  print '<td class="liste_titre center">';
527  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
528  print '</td>';
529 }
530 $key = 'nb_products';
531 if (!empty($arrayfields[$key]['checked'])) {
532  print '<td class="liste_titre center">';
533  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
534  print '</td>';
535 }
536 // Fields from hook
537 $parameters = array('arrayfields'=>$arrayfields);
538 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
539 print $hookmanager->resPrint;
540 // Action column
541 print '<td class="liste_titre linecoledit width25"></td>';
542 print '<td class="liste_titre maxwidthsearch">';
543 $searchpicto = $form->showFilterButtons();
544 print $searchpicto;
545 print '</td>';
546 print '<td class="liste_titre linecolmove width25"></td>';
547 print '</tr>'."\n";
548 
549 
550 // Fields title label
551 // --------------------------------------------------------------------
552 print '<tr class="liste_titre">';
553 foreach ($object->fields as $key => $val) {
554  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
555  if ($key == 'status') {
556  $cssforfield .= ($cssforfield ? ' ' : '').'center';
557  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
558  $cssforfield .= ($cssforfield ? ' ' : '').'center';
559  } elseif (in_array($val['type'], array('timestamp'))) {
560  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
561  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
562  $cssforfield .= ($cssforfield ? ' ' : '').'right';
563  }
564  if (!empty($arrayfields['t.'.$key]['checked'])) {
565  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
566  }
567 }
568 // Extra fields
569 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
570 $key = 'nb_of_values';
571 if (!empty($arrayfields[$key]['checked'])) {
572  print getTitleFieldOfList($arrayfields[$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, 'class="center"', $sortfield, $sortorder, 'center ')."\n";
573 }
574 $key = 'nb_products';
575 if (!empty($arrayfields[$key]['checked'])) {
576  print getTitleFieldOfList($arrayfields[$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, 'class="center"', $sortfield, $sortorder, 'center ')."\n";
577 }
578 // Hook fields
579 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
580 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
581 print $hookmanager->resPrint;
582 // Action column
583 print getTitleFieldOfList('', 0, '', '', '', '', '', '', '', 'linecoledit ')."\n";
584 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
585 print getTitleFieldOfList('', 0, '', '', '', '', '', '', '', 'linecolmove ')."\n";
586 print '</tr>'."\n";
587 
588 
589 // Detect if we need a fetch on each output line
590 $needToFetchEachLine = 0;
591 //if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
592 // foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
593 // if (preg_match('/\$object/', $val)) {
594 // $needToFetchEachLine++; // There is at least one compute field that use $object
595 // }
596 // }
597 //}
598 
599 
600 // Loop on record
601 // --------------------------------------------------------------------
602 $i = 0;
603 $totalarray = array();
604 $totalarray['nbfield'] = 0;
605 while ($i < ($limit ? min($num, $limit) : $num)) {
606  $obj = $db->fetch_object($resql);
607  if (empty($obj)) {
608  break; // Should not happen
609  }
610 
611  $object->setVarsFromFetchObj($obj);
612 
613  // Show here line of result
614  print '<tr id="row-' . $obj->rowid . '" class="oddeven drag drop">';
615  foreach ($object->fields as $key => $val) {
616  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
617  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
618  $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
619  } elseif ($key == 'status') {
620  $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
621  }
622 
623  if (in_array($val['type'], array('timestamp'))) {
624  $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
625  } elseif ($key == 'ref') {
626  $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
627  }
628 
629  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
630  $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
631  }
632  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
633 
634  if (!empty($arrayfields['t.' . $key]['checked'])) {
635  print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
636  if ($key == 'status') {
637  print $object->getLibStatut(5);
638  } elseif ($key == 'rowid') {
639  print $object->showOutputField($val, $key, $object->id, '');
640  } else {
641  print $object->showOutputField($val, $key, $object->$key, '');
642  }
643  print '</td>';
644  if (!$i) {
645  $totalarray['nbfield']++;
646  }
647  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
648  if (!$i) {
649  $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
650  }
651  if (!isset($totalarray['val'])) {
652  $totalarray['val'] = array();
653  }
654  if (!isset($totalarray['val']['t.' . $key])) {
655  $totalarray['val']['t.' . $key] = 0;
656  }
657  $totalarray['val']['t.' . $key] += $object->$key;
658  }
659  }
660  }
661  // Extra fields
662  //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
663  $key = 'nb_of_values';
664  if (!empty($arrayfields[$key]['checked'])) {
665  print '<td class="center">';
666  print $obj->$key;
667  print '</td>';
668  if (!$i) {
669  $totalarray['nbfield']++;
670  }
671  }
672  $key = 'nb_products';
673  if (!empty($arrayfields[$key]['checked'])) {
674  print '<td class="center">';
675  print $obj->$key;
676  print '</td>';
677  if (!$i) {
678  $totalarray['nbfield']++;
679  }
680  }
681  // Fields from hook
682  $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
683  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
684  print $hookmanager->resPrint;
685  // Action column
686  print '<td class="linecoledit center width25">';
687  if ($permissiontoadd) {
688  print '<a class="editfielda reposition" href="' . DOL_URL_ROOT . '/variants/card.php?id=' . $obj->rowid . '&action=edit&save_lastsearch_values=1&backtopage=' . urlencode($_SERVER['PHP_SELF']) . '">' . img_edit() . '</a>';
689  }
690  print '</td>';
691  if (!$i) {
692  $totalarray['nbfield']++;
693  }
694  print '<td class="nowrap center">';
695  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
696  $selected = 0;
697  if (in_array($object->id, $arrayofselected)) {
698  $selected = 1;
699  }
700  print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
701  }
702  print '</td>';
703  if (!$i) {
704  $totalarray['nbfield']++;
705  }
706  print '<td class="center linecolmove tdlineupdown">';
707  if ($i > 0) {
708  print '<a class="lineupdown" href="' . $_SERVER['PHP_SELF'] . '?action=up&amp;rowid=' . $obj->rowid . '">' . img_up('default', 0, 'imgupforline') . '</a>';
709  }
710  if ($i < $num - 1) {
711  print '<a class="lineupdown" href="' . $_SERVER['PHP_SELF'] . '?action=down&amp;rowid=' . $obj->rowid . '">' . img_down('default', 0, 'imgdownforline') . '</a>';
712  }
713  print '</td>';
714  if (!$i) {
715  $totalarray['nbfield']++;
716  }
717 
718  print '</tr>' . "\n";
719 
720  $i++;
721 }
722 
723 // Show total line
724 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
725 
726 // If no record found
727 if ($num == 0) {
728  $colspan = 3;
729  foreach ($arrayfields as $key => $val) {
730  if (!empty($val['checked'])) {
731  $colspan++;
732  }
733  }
734  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
735 }
736 
737 $db->free($resql);
738 
739 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
740 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
741 print $hookmanager->resPrint;
742 
743 print '</table>'."\n";
744 print '</div>'."\n";
745 
746 print '</form>'."\n";
747 
748 $forcereloadpage = empty($conf->global->MAIN_FORCE_RELOAD_PAGE) ? 0 : 1;
749 $tagidfortablednd = (empty($tagidfortablednd) ? 'tableattributes' : $tagidfortablednd);
750 ?>
751  <script>
752  $(document).ready(function(){
753  $(".imgupforline, .imgdownforline").hide();
754  $(".lineupdown").removeAttr('href');
755  $(".tdlineupdown")
756  .css("background-image", 'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)')
757  .css("background-repeat", "no-repeat")
758  .css("background-position", "center center")
759  .hover(
760  function () {
761  $(this).addClass('showDragHandle');
762  }, function () {
763  $(this).removeClass('showDragHandle');
764  }
765  );
766 
767  $("#<?php echo $tagidfortablednd; ?>").tableDnD({
768  onDrop: function(table, row) {
769  console.log('drop');
770  $('#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr('id', ''); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
771  $('#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr('id', ''); // Set id to empty value in order to ignore them in tableDnDSerialize function
772  var reloadpage = "<?php echo $forcereloadpage; ?>";
773  var roworder = cleanSerialize(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
774  $.post("<?php echo DOL_URL_ROOT; ?>/variants/ajax/orderAttribute.php",
775  {
776  roworder: roworder,
777  token: "<?php echo currentToken(); ?>"
778  },
779  function() {
780  if (reloadpage == 1) {
781  location.href = '<?php echo dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']); ?>';
782  }
783  });
784  },
785  onDragClass: "dragClass",
786  dragHandle: "td.tdlineupdown"
787  });
788  });
789  </script>
790 <?php
791 
792 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
793  $hidegeneratedfilelistifempty = 1;
794  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
795  $hidegeneratedfilelistifempty = 0;
796  }
797 
798  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
799  $formfile = new FormFile($db);
800 
801  // Show list of available documents
802  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
803  $urlsource .= str_replace('&amp;', '&', $param);
804 
805  $filedir = $diroutputmassaction;
806  $genallowed = $permissiontoread;
807  $delallowed = $permissiontoadd;
808 
809  print $formfile->showdocuments('massfilesarea_productattribute', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
810 }
811 
812 // End of page
813 llxFooter();
814 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
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
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
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_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
img_up
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
Definition: functions.lib.php:4615
ProductAttribute
Class ProductAttribute Used to represent a product attribute.
Definition: ProductAttribute.class.php:25
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
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
img_down
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
Definition: functions.lib.php:4596
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
natural_search
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...
Definition: functions.lib.php:9420
dol_eval
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
Definition: functions.lib.php:8611
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$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
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
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
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