dolibarr  20.0.0-beta
stocktransfer_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) ---Put here your own copyright and developer email---
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 // Load Dolibarr environment
27 require '../../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("stocks", "other"));
36 
37 // Get parameters
38 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
39 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
40 $show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
41 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
42 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
43 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
44 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'stocktransferlist'; // To manage different context of search
45 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
46 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
47 
48 $id = GETPOSTINT('id');
49 
50 // Load variable for pagination
51 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
52 $sortfield = GETPOST('sortfield', 'aZ09comma');
53 $sortorder = GETPOST('sortorder', 'aZ09comma');
54 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
55 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
56  // If $page is not defined, or '' or -1 or if we click on clear filters
57  $page = 0;
58 }
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 
63 // Initialize technical objects
64 $object = new StockTransfer($db);
65 $extrafields = new ExtraFields($db);
66 $diroutputmassaction = getMultidirOutput($object).'/temp/massgeneration/'.$user->id;
67 $hookmanager->initHooks(array('stocktransferlist')); // Note that conf->hooks_modules contains array
68 
69 // Fetch optionals attributes and labels
70 $extrafields->fetch_name_optionals_label($object->table_element);
71 //$extrafields->fetch_name_optionals_label($object->table_element_line);
72 
73 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
74 
75 // Default sort order (if not yet defined by previous GETPOST)
76 if (!$sortfield) {
77  reset($object->fields); // Reset is required to avoid key() to return null.
78  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
79 }
80 if (!$sortorder) {
81  $sortorder = "ASC";
82 }
83 
84 // Initialize array of search criteria
85 $search_all = trim(GETPOST('search_all', 'alphanohtml'));
86 $search = array();
87 foreach ($object->fields as $key => $val) {
88  if (GETPOST('search_'.$key, 'alpha') !== '') {
89  $search[$key] = GETPOST('search_'.$key, 'alpha');
90  }
91  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
92  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
93  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
94  }
95 }
96 
97 // List of fields to search into when doing a "search in all"
98 $fieldstosearchall = array();
99 foreach ($object->fields as $key => $val) {
100  if (!empty($val['searchall'])) {
101  $fieldstosearchall['t.'.$key] = $val['label'];
102  }
103 }
104 
105 // Definition of array of fields for columns
106 $arrayfields = array();
107 foreach ($object->fields as $key => $val) {
108  // If $val['visible']==0, then we never show the field
109  if (!empty($val['visible'])) {
110  $visible = (int) dol_eval($val['visible'], 1);
111  $arrayfields['t.'.$key] = array(
112  'label'=>$val['label'],
113  'checked'=>(($visible < 0) ? 0 : 1),
114  'enabled'=>(abs($visible) != 3 && (int) dol_eval($val['enabled'], 1)),
115  'position'=>$val['position'],
116  'help'=> isset($val['help']) ? $val['help'] : ''
117  );
118  }
119 }
120 // Extra fields
121 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
122 
123 $object->fields = dol_sort_array($object->fields, 'position');
124 $arrayfields = dol_sort_array($arrayfields, 'position');
125 
126 $permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
127 $permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
128 $permissiontodelete = $user->hasRight('stocktransfer', 'stocktransfer', 'delete');
129 
130 // Security check
131 if (empty($conf->stocktransfer->enabled)) {
132  accessforbidden('Module not enabled');
133 }
134 
135 // Security check (enable the most restrictive one)
136 if ($user->socid > 0) {
137  accessforbidden();
138 }
139 //$result = restrictedArea($user, 'stocktransfer', $id, '');
140 if (!$permissiontoread) {
141  accessforbidden();
142 }
143 
144 
145 
146 /*
147  * Actions
148  */
149 
150 if (GETPOST('cancel', 'alpha')) {
151  $action = 'list';
152  $massaction = '';
153 }
154 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
155  $massaction = '';
156 }
157 
158 $parameters = array();
159 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
160 if ($reshook < 0) {
161  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
162 }
163 
164 if (empty($reshook)) {
165  // Selection of new fields
166  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
167 
168  // Purge search criteria
169  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
170  foreach ($object->fields as $key => $val) {
171  $search[$key] = '';
172  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
173  $search[$key.'_dtstart'] = '';
174  $search[$key.'_dtend'] = '';
175  }
176  }
177  $toselect = array();
178  $search_array_options = array();
179  }
180  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
181  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
182  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
183  }
184 
185  // Mass actions
186  $objectclass = 'StockTransfer';
187  $objectlabel = 'StockTransfer';
188  $uploaddir = $conf->stocktransfer->dir_output;
189  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
190 }
191 
192 
193 
194 /*
195  * View
196  */
197 
198 $form = new Form($db);
199 
200 $now = dol_now();
201 
202 $title = $langs->trans('StockTransferList');
203 //$help_url="EN:Module_StockTransfer|FR:Module_StockTransfer_FR|ES:Módulo_StockTransfer";
204 $help_url = '';
205 $morejs = array();
206 $morecss = array();
207 
208 
209 // Build and execute select
210 // --------------------------------------------------------------------
211 $sql = 'SELECT ';
212 $sql .= $object->getFieldList('t');
213 // Add fields from extrafields
214 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
215  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
216  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
217  }
218 }
219 // Add fields from hooks
220 $parameters = array();
221 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
222 $sql .= $hookmanager->resPrint;
223 $sql = preg_replace('/,\s*$/', '', $sql);
224 
225 $sqlfields = $sql; // $sql fields to remove for count total
226 
227 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
228 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
229  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
230 }
231 // Add table from hooks
232 $parameters = array();
233 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
234 $sql .= $hookmanager->resPrint;
235 if ($object->ismultientitymanaged == 1) {
236  $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
237 } else {
238  $sql .= " WHERE 1 = 1";
239 }
240 foreach ($search as $key => $val) {
241  if (array_key_exists($key, $object->fields)) {
242  if ($key == 'status' && $search[$key] == -1) {
243  continue;
244  }
245  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
246  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
247  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
248  $search[$key] = '';
249  }
250  $mode_search = 2;
251  }
252  if ($search[$key] != '') {
253  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
254  }
255  } else {
256  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
257  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
258  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
259  if (preg_match('/_dtstart$/', $key)) {
260  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
261  }
262  if (preg_match('/_dtend$/', $key)) {
263  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
264  }
265  }
266  }
267  }
268 }
269 if ($search_all) {
270  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
271 }
272 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
273 // Add where from extra fields
274 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
275 // Add where from hooks
276 $parameters = array();
277 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
278 $sql .= $hookmanager->resPrint;
279 
280 /* If a group by is required
281 $sql.= " GROUP BY ";
282 foreach($object->fields as $key => $val) {
283  $sql .= "t.".$db->escape($key).", ";
284 }
285 // Add fields from extrafields
286 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
287  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
288  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
289  }
290 }
291 // Add groupby from hooks
292 $parameters=array();
293 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
294 $sql.=$hookmanager->resPrint;
295 $sql=preg_replace('/,\s*$/','', $sql);
296 */
297 
298 // Count total nb of records
299 $nbtotalofrecords = '';
300 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
301  /* The fast and low memory method to get and count full list converts the sql into a sql count */
302  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
303  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
304  $resql = $db->query($sqlforcount);
305  if ($resql) {
306  $objforcount = $db->fetch_object($resql);
307  $nbtotalofrecords = $objforcount->nbtotalofrecords;
308  } else {
309  dol_print_error($db);
310  }
311 
312  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
313  $page = 0;
314  $offset = 0;
315  }
316  $db->free($resql);
317 }
318 
319 // Complete request and execute it with limit
320 $sql .= $db->order($sortfield, $sortorder);
321 if ($limit) {
322  $sql .= $db->plimit($limit + 1, $offset);
323 }
324 
325 $resql = $db->query($sql);
326 if (!$resql) {
327  dol_print_error($db);
328  exit;
329 }
330 
331 $num = $db->num_rows($resql);
332 
333 // Direct jump if only one record found
334 if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
335  $obj = $db->fetch_object($resql);
336  $id = $obj->rowid;
337  header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id);
338  exit;
339 }
340 
341 
342 // Output page
343 // --------------------------------------------------------------------
344 
345 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
346 
347 // Example : Adding jquery code
348 // print '<script type="text/javascript">
349 // jQuery(document).ready(function() {
350 // function init_myfunc()
351 // {
352 // jQuery("#myid").removeAttr(\'disabled\');
353 // jQuery("#myid").attr(\'disabled\',\'disabled\');
354 // }
355 // init_myfunc();
356 // jQuery("#mybutton").click(function() {
357 // init_myfunc();
358 // });
359 // });
360 // </script>';
361 
362 $arrayofselected = is_array($toselect) ? $toselect : array();
363 
364 $param = '';
365 if (!empty($mode)) {
366  $param .= '&mode='.urlencode($mode);
367 }
368 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
369  $param .= '&contextpage='.urlencode($contextpage);
370 }
371 if ($limit > 0 && $limit != $conf->liste_limit) {
372  $param .= '&limit='.((int) $limit);
373 }
374 if ($optioncss != '') {
375  $param .= '&optioncss='.urlencode($optioncss);
376 }
377 foreach ($search as $key => $val) {
378  if (is_array($search[$key])) {
379  foreach ($search[$key] as $skey) {
380  if ($skey != '') {
381  $param .= '&search_'.$key.'[]='.urlencode($skey);
382  }
383  }
384  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
385  $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
386  $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
387  $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
388  } elseif ($search[$key] != '') {
389  $param .= '&search_'.$key.'='.urlencode($search[$key]);
390  }
391 }
392 // Add $param from extra fields
393 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
394 // Add $param from hooks
395 $parameters = array('param' => &$param);
396 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
397 $param .= $hookmanager->resPrint;
398 
399 // List of mass actions available
400 $arrayofmassactions = array(
401  //'validate'=>$langs->trans("Validate"),
402  //'generate_doc'=>$langs->trans("ReGeneratePDF"),
403  //'builddoc'=>$langs->trans("PDFMerge"),
404  //'presend'=>$langs->trans("SendByMail"),
405 );
406 if (!empty($permissiontodelete)) {
407  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
408 }
409 if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
410  $arrayofmassactions = array();
411 }
412 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
413 
414 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
415 if ($optioncss != '') {
416  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
417 }
418 print '<input type="hidden" name="token" value="'.newToken().'">';
419 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
420 print '<input type="hidden" name="action" value="list">';
421 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
422 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
423 print '<input type="hidden" name="page" value="'.$page.'">';
424 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
425 print '<input type="hidden" name="page_y" value="">';
426 print '<input type="hidden" name="mode" value="'.$mode.'">';
427 
428 $newcardbutton = '';
429 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
430 
431 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
432 
433 // Add code for pre mass action (confirmation or email presend form)
434 $topicmail = "SendStockTransferRef";
435 $modelmail = "stocktransfer";
436 $objecttmp = new StockTransfer($db);
437 $trackid = 'xxxx'.$object->id;
438 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
439 
440 if ($search_all) {
441  $setupstring = '';
442  foreach ($fieldstosearchall as $key => $val) {
443  $fieldstosearchall[$key] = $langs->trans($val);
444  $setupstring .= $key."=".$val.";";
445  }
446  print '<!-- Search done like if STOCKTRANSFER_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
447  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
448 }
449 
450 $moreforfilter = '';
451 /*$moreforfilter.='<div class="divsearchfield">';
452 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
453 $moreforfilter.= '</div>';*/
454 
455 $parameters = array();
456 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
457 if (empty($reshook)) {
458  $moreforfilter .= $hookmanager->resPrint;
459 } else {
460  $moreforfilter = $hookmanager->resPrint;
461 }
462 
463 if (!empty($moreforfilter)) {
464  print '<div class="liste_titre liste_titre_bydiv centpercent">';
465  print $moreforfilter;
466  $parameters = array();
467  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
468  print $hookmanager->resPrint;
469  print '</div>';
470 }
471 
472 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
473 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
474 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
475 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
476 
477 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
478 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
479 
480 
481 // Fields title search
482 // --------------------------------------------------------------------
483 print '<tr class="liste_titre_filter">';
484 // Action column
485 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
486  print '<td class="liste_titre center maxwidthsearch">';
487  $searchpicto = $form->showFilterButtons('left');
488  print $searchpicto;
489  print '</td>';
490 }
491 foreach ($object->fields as $key => $val) {
492  $searchkey = empty($search[$key]) ? '' : $search[$key];
493  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
494  if ($key == 'status') {
495  $cssforfield .= ($cssforfield ? ' ' : '').'center';
496  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
497  $cssforfield .= ($cssforfield ? ' ' : '').'center';
498  } elseif (in_array($val['type'], array('timestamp'))) {
499  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
500  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
501  $cssforfield .= ($cssforfield ? ' ' : '').'right';
502  }
503  if (!empty($arrayfields['t.'.$key]['checked'])) {
504  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
505  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
506  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
507  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
508  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
509  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
510  print '<div class="nowrap">';
511  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
512  print '</div>';
513  print '<div class="nowrap">';
514  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
515  print '</div>';
516  } elseif ($key == 'lang') {
517  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
518  $formadmin = new FormAdmin($db);
519  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
520  } else {
521  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
522  }
523  print '</td>';
524  }
525 }
526 // Extra fields
527 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
528 
529 // Fields from hook
530 $parameters = array('arrayfields'=>$arrayfields);
531 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
532 print $hookmanager->resPrint;
533 // Action column
534 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
535  print '<td class="liste_titre center maxwidthsearch">';
536  $searchpicto = $form->showFilterButtons();
537  print $searchpicto;
538  print '</td>';
539 }
540 print '</tr>'."\n";
541 
542 $totalarray = array();
543 $totalarray['nbfield'] = 0;
544 
545 // Fields title label
546 // --------------------------------------------------------------------
547 print '<tr class="liste_titre">';
548 // Action column
549 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
550  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
551  $totalarray['nbfield']++;
552 }
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')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
562  $cssforfield .= ($cssforfield ? ' ' : '').'right';
563  }
564  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
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.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
567  $totalarray['nbfield']++;
568  }
569 }
570 // Extra fields
571 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
572 // Hook fields
573 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
574 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
575 print $hookmanager->resPrint;
576 // Action column
577 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
578  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
579  $totalarray['nbfield']++;
580 }
581 print '</tr>'."\n";
582 
583 
584 // Detect if we need a fetch on each output line
585 $needToFetchEachLine = 0;
586 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
587  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
588  if (!is_null($val) && preg_match('/\$object/', $val)) {
589  $needToFetchEachLine++; // There is at least one compute field that use $object
590  }
591  }
592 }
593 
594 
595 // Loop on record
596 // --------------------------------------------------------------------
597 $i = 0;
598 $savnbfield = $totalarray['nbfield'];
599 $totalarray = array();
600 $totalarray['nbfield'] = 0;
601 $imaxinloop = ($limit ? min($num, $limit) : $num);
602 while ($i < $imaxinloop) {
603  $obj = $db->fetch_object($resql);
604  if (empty($obj)) {
605  break; // Should not happen
606  }
607 
608  // Store properties in $object
609  $object->setVarsFromFetchObj($obj);
610 
611  if ($mode == 'kanban') {
612  if ($i == 0) {
613  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
614  print '<div class="box-flex-container kanban">';
615  }
616  // Output Kanban
617  $selected = -1;
618  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
619  $selected = 0;
620  if (in_array($object->id, $arrayofselected)) {
621  $selected = 1;
622  }
623  }
624  //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
625  print $object->getKanbanView('', array('selected' => $selected));
626  if ($i == ($imaxinloop - 1)) {
627  print '</div>';
628  print '</td></tr>';
629  }
630  } else {
631  // Show line of result
632  $j = 0;
633  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
634 
635  // Action column
636  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
637  print '<td class="nowrap center">';
638  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
639  $selected = 0;
640  if (in_array($object->id, $arrayofselected)) {
641  $selected = 1;
642  }
643  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
644  }
645  print '</td>';
646  if (!$i) {
647  $totalarray['nbfield']++;
648  }
649  }
650  foreach ($object->fields as $key => $val) {
651  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
652  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
653  $cssforfield .= ($cssforfield ? ' ' : '').'center';
654  } elseif ($key == 'status') {
655  $cssforfield .= ($cssforfield ? ' ' : '').'center';
656  }
657 
658  if (in_array($val['type'], array('timestamp'))) {
659  $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
660  } elseif ($key == 'ref') {
661  $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
662  }
663 
664  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
665  $cssforfield .= ($cssforfield ? ' ' : '').'right';
666  }
667  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
668 
669  if (!empty($arrayfields['t.'.$key]['checked'])) {
670  print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
671  if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
672  print ' title="'.dol_escape_htmltag($object->$key).'"';
673  }
674  print '>';
675  if ($key == 'status') {
676  print $object->getLibStatut(5);
677  } elseif ($key == 'rowid') {
678  print $object->showOutputField($val, $key, $object->id, '');
679  } else {
680  print $object->showOutputField($val, $key, $object->$key, '');
681  }
682  print '</td>';
683  if (!$i) {
684  $totalarray['nbfield']++;
685  }
686  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
687  if (!$i) {
688  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
689  }
690  if (!isset($totalarray['val'])) {
691  $totalarray['val'] = array();
692  }
693  if (!isset($totalarray['val']['t.'.$key])) {
694  $totalarray['val']['t.'.$key] = 0;
695  }
696  $totalarray['val']['t.'.$key] += $object->$key;
697  }
698  }
699  }
700  // Extra fields
701  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
702  // Fields from hook
703  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
704  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
705  print $hookmanager->resPrint;
706  // Action column
707  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
708  print '<td class="nowrap center">';
709  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
710  $selected = 0;
711  if (in_array($object->id, $arrayofselected)) {
712  $selected = 1;
713  }
714  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
715  }
716  print '</td>';
717  if (!$i) {
718  $totalarray['nbfield']++;
719  }
720  }
721 
722  print '</tr>'."\n";
723  }
724 
725  $i++;
726 }
727 
728 // Show total line
729 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
730 
731 // If no record found
732 if ($num == 0) {
733  $colspan = 1;
734  foreach ($arrayfields as $key => $val) {
735  if (!empty($val['checked'])) {
736  $colspan++;
737  }
738  }
739  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
740 }
741 
742 
743 $db->free($resql);
744 
745 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
746 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
747 print $hookmanager->resPrint;
748 
749 print '</table>'."\n";
750 print '</div>'."\n";
751 
752 print '</form>'."\n";
753 
754 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
755  $hidegeneratedfilelistifempty = 1;
756  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
757  $hidegeneratedfilelistifempty = 0;
758  }
759 
760  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
761  $formfile = new FormFile($db);
762 
763  // Show list of available documents
764  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
765  $urlsource .= str_replace('&amp;', '&', $param);
766 
767  $filedir = $diroutputmassaction;
768  $genallowed = $permissiontoread;
769  $delallowed = $permissiontoadd;
770 
771  print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
772 }
773 
774 // End of page
775 llxFooter();
776 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage standard extra fields.
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 for StockTransfer.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists('str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists('str_contains')) getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files,...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.