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