dolibarr  16.0.5
knowledgerecord_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 Frédéric France <frederic.france@netlogic.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 
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 
33 // load knowledgemanagement libraries
34 require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
35 
36 // for other modules
37 if (!empty($conf->categorie->enabled)) {
38  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
39 }
40 //dol_include_once('/othermodule/class/otherobject.class.php');
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array("knowledgemanagement", "other"));
44 
45 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
46 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
47 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
48 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
49 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
50 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
51 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'knowledgerecordlist'; // To manage different context of search
52 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
53 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
54 $mode = GETPOST('mode', 'aZ09');
55 
56 $id = GETPOST('id', 'int');
57 
58 $searchCategoryKnowledgemanagementList = GETPOST('search_category_knowledgemanagement_list', 'array');
59 $searchCategoryKnowledgemanagementOperator = 0;
60 if (GETPOSTISSET('formfilteraction')) {
61  $searchCategoryKnowledgemanagementOperator = GETPOST('search_category_knowledgemanagement_operator', 'int');
62 } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
63  $searchCategoryKnowledgemanagementOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
64 }
65 // Load variable for pagination
66 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
67 $sortfield = GETPOST('sortfield', 'aZ09comma');
68 $sortorder = GETPOST('sortorder', 'aZ09comma');
69 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
70 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
71  $page = 0;
72 } // If $page is not defined, or '' or -1 or if we click on clear filters
73 $offset = $limit * $page;
74 $pageprev = $page - 1;
75 $pagenext = $page + 1;
76 
77 // Initialize technical objects
78 $object = new KnowledgeRecord($db);
79 $extrafields = new ExtraFields($db);
80 $diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
81 $hookmanager->initHooks(array('knowledgerecordlist')); // Note that conf->hooks_modules contains array
82 
83 // Fetch optionals attributes and labels
84 $extrafields->fetch_name_optionals_label($object->table_element);
85 //$extrafields->fetch_name_optionals_label($object->table_element_line);
86 
87 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
88 
89 // Default sort order (if not yet defined by previous GETPOST)
90 if (!$sortfield) {
91  reset($object->fields); // Reset is required to avoid key() to return null.
92  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
93 }
94 if (!$sortorder) {
95  $sortorder = "ASC";
96 }
97 
98 // Initialize array of search criterias
99 $search_all = GETPOST('search_all', 'alphanohtml');
100 $search = array();
101 foreach ($object->fields as $key => $val) {
102  if ($key == "lang") {
103  $search[$key] = GETPOST('search_'.$key, 'alpha')!='0' ? GETPOST('search_'.$key, 'alpha') : '';
104  } else {
105  $search[$key] = GETPOST('search_'.$key, 'alpha');
106  }
107 
108  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
109  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
110  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
111  }
112 }
113 
114 // List of fields to search into when doing a "search in all"
115 $fieldstosearchall = array();
116 foreach ($object->fields as $key => $val) {
117  if (!empty($val['searchall'])) {
118  $fieldstosearchall['t.'.$key] = $val['label'];
119  }
120 }
121 
122 // Definition of array of fields for columns
123 $arrayfields = array();
124 foreach ($object->fields as $key => $val) {
125  // If $val['visible']==0, then we never show the field
126  if (!empty($val['visible'])) {
127  $visible = (int) dol_eval($val['visible'], 1);
128  $arrayfields['t.'.$key] = array(
129  'label'=>$val['label'],
130  'checked'=>(($visible < 0) ? 0 : 1),
131  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
132  'position'=>$val['position'],
133  'help'=> isset($val['help']) ? $val['help'] : ''
134  );
135  }
136 }
137 // Extra fields
138 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
139 
140 $object->fields = dol_sort_array($object->fields, 'position');
141 $arrayfields = dol_sort_array($arrayfields, 'position');
142 
143 $permissiontoread = $user->rights->knowledgemanagement->knowledgerecord->read;
144 $permissiontoadd = $user->rights->knowledgemanagement->knowledgerecord->write;
145 $permissiontodelete = $user->rights->knowledgemanagement->knowledgerecord->delete;
146 
147 // Security check
148 if (empty($conf->knowledgemanagement->enabled)) {
149  accessforbidden('Module not enabled');
150 }
151 $socid = 0;
152 if ($user->socid > 0) { // Protection if external user
153  //$socid = $user->socid;
154  accessforbidden();
155 }
156 //$result = restrictedArea($user, 'knowledgemanagement');
157 //if (!$permissiontoread) accessforbidden();
158 
159 
160 
161 /*
162  * Actions
163  */
164 
165 if (GETPOST('cancel', 'alpha')) {
166  $action = 'list';
167  $massaction = '';
168 }
169 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
170  $massaction = '';
171 }
172 
173 $parameters = array();
174 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
175 if ($reshook < 0) {
176  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
177 }
178 
179 if (empty($reshook)) {
180  // Selection of new fields
181  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
182 
183  // Purge search criteria
184  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
185  foreach ($object->fields as $key => $val) {
186  $search[$key] = '';
187  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
188  $search[$key.'_dtstart'] = '';
189  $search[$key.'_dtend'] = '';
190  }
191  }
192  $toselect = array();
193  $search_array_options = array();
194  }
195  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
196  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
197  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
198  }
199  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
200  $searchCategoryKnowledgemanagementOperator = 0;
201  $searchCategoryKnowledgemanagementList = array();
202  }
203 
204  // Mass actions
205  $objectclass = 'KnowledgeRecord';
206  $objectlabel = 'KnowledgeRecord';
207  $uploaddir = $conf->knowledgemanagement->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 $user_temp = new User($db);
219 $formadmin = new FormAdmin($db);
220 
221 $now = dol_now();
222 
223 //$help_url="EN:Module_KnowledgeRecord|FR:Module_KnowledgeRecord_FR|ES:Módulo_KnowledgeRecord";
224 $help_url = '';
225 $title = $langs->trans('KnowledgeRecords');
226 $morejs = array();
227 $morecss = array();
228 
229 
230 // Build and execute select
231 // --------------------------------------------------------------------
232 $sql = 'SELECT ';
233 $sql .= $object->getFieldList('t');
234 // Add fields from extrafields
235 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
236  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
237  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
238  }
239 }
240 // Add fields from hooks
241 $parameters = array();
242 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
243 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
244 $sql = preg_replace('/,\s*$/', '', $sql);
245 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
246 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
247  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
248 }
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 (array_key_exists($key, $object->fields)) {
260  if ($key == 'status' && $search[$key] == -1) {
261  continue;
262  }
263  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
264  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
265  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
266  $search[$key] = '';
267  }
268  $mode_search = 2;
269  }
270  if ($search[$key] != '') {
271  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
272  }
273  } else {
274  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
275  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
276  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
277  if (preg_match('/_dtstart$/', $key)) {
278  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
279  }
280  if (preg_match('/_dtend$/', $key)) {
281  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
282  }
283  }
284  }
285  }
286 }
287 
288 // Search for tag/category ($searchCategoryKnowledgemanagementList is an array of ID)
289 if (!empty($searchCategoryKnowledgemanagementList)) {
290  $searchCategoryKnowledgemanagementSqlList = array();
291  $listofcategoryid = '';
292  foreach ($searchCategoryKnowledgemanagementList as $searchCategoryKnowledgemanagement) {
293  if (intval($searchCategoryKnowledgemanagement) == -2) {
294  $searchCategoryKnowledgemanagementSqlList[] = "NOT EXISTS (SELECT ck.fk_knowledgemanagement FROM ".MAIN_DB_PREFIX."categorie_knowledgemanagement as ck WHERE t.rowid = ck.fk_knowledgemanagement)";
295  } elseif (intval($searchCategoryKnowledgemanagement) > 0) {
296  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryKnowledgemanagement);
297  }
298  }
299  if ($listofcategoryid) {
300  $searchCategoryKnowledgemanagementSqlList[] = " EXISTS (SELECT ck.fk_knowledgemanagement FROM ".MAIN_DB_PREFIX."categorie_knowledgemanagement as ck WHERE t.rowid = ck.fk_knowledgemanagement AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
301  }
302  if ($searchCategoryKnowledgemanagementOperator == 1) {
303  if (!empty($searchCategoryKnowledgemanagementSqlList)) {
304  $sql .= " AND (".implode(' OR ', $searchCategoryKnowledgemanagementSqlList).")";
305  }
306  } else {
307  if (!empty($searchCategoryKnowledgemanagementSqlList)) {
308  $sql .= " AND (".implode(' AND ', $searchCategoryKnowledgemanagementSqlList).")";
309  }
310  }
311 }
312 
313 if ($search_all) {
314  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
315 }
316 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
317 // Add where from extra fields
318 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
319 // Add where from hooks
320 $parameters = array();
321 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
322 $sql .= $hookmanager->resPrint;
323 
324 /* If a group by is required
325 $sql.= " GROUP BY ";
326 foreach($object->fields as $key => $val) {
327  $sql .= "t.".$key.", ";
328 }
329 // Add fields from extrafields
330 if (! empty($extrafields->attributes[$object->table_element]['label'])) {
331  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
332 }
333 // Add where from hooks
334 $parameters=array();
335 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
336 $sql.=$hookmanager->resPrint;
337 $sql=preg_replace('/,\s*$/','', $sql);
338 */
339 
340 // Count total nb of records
341 $nbtotalofrecords = '';
342 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
343  $resql = $db->query($sql);
344  $nbtotalofrecords = $db->num_rows($resql);
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 // Complete request and execute it with limit
354 $sql .= $db->order($sortfield, $sortorder);
355 if ($limit) {
356  $sql .= $db->plimit($limit + 1, $offset);
357 }
358 
359 $resql = $db->query($sql);
360 if (!$resql) {
361  dol_print_error($db);
362  exit;
363 }
364 
365 $num = $db->num_rows($resql);
366 
367 
368 // Direct jump if only one record found
369 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
370  $obj = $db->fetch_object($resql);
371  $id = $obj->rowid;
372  header("Location: ".dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?id='.$id);
373  exit;
374 }
375 
376 
377 // Output page
378 // --------------------------------------------------------------------
379 
380 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
381 
382 
383 $arrayofselected = is_array($toselect) ? $toselect : array();
384 
385 $param = '';
386 if (!empty($mode)) {
387  $param .= '&mode='.urlencode($mode);
388 }
389 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
390  $param .= '&contextpage='.urlencode($contextpage);
391 }
392 if ($limit > 0 && $limit != $conf->liste_limit) {
393  $param .= '&limit='.urlencode($limit);
394 }
395 foreach ($search as $key => $val) {
396  if (is_array($search[$key]) && count($search[$key])) {
397  foreach ($search[$key] as $skey) {
398  if ($skey != '') {
399  $param .= '&search_'.$key.'[]='.urlencode($skey);
400  }
401  }
402  } elseif ($search[$key] != '') {
403  $param .= '&search_'.$key.'='.urlencode($search[$key]);
404  }
405 }
406 if ($optioncss != '') {
407  $param .= '&optioncss='.urlencode($optioncss);
408 }
409 // Add $param from extra fields
410 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
411 // Add $param from hooks
412 $parameters = array();
413 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
414 $param .= $hookmanager->resPrint;
415 
416 // List of mass actions available
417 $arrayofmassactions = array(
418  'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
419  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
420  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
421  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
422 );
423 if ($permissiontodelete) {
424  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
425 }
426 
427 if (isModEnabled('category') && $user->rights->knowledgemanagement->knowledgerecord->write) {
428  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
429 }
430 
431 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
432  $arrayofmassactions = array();
433 }
434 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
435 
436 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
437 if ($optioncss != '') {
438  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
439 }
440 print '<input type="hidden" name="token" value="'.newToken().'">';
441 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
442 print '<input type="hidden" name="action" value="list">';
443 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
444 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
445 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
446 
447 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
448 
449 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
450 
451 // Add code for pre mass action (confirmation or email presend form)
452 $topicmail = "SendKnowledgeRecordRef";
453 $modelmail = "knowledgerecord";
454 $objecttmp = new KnowledgeRecord($db);
455 $trackid = 'xxxx'.$object->id;
456 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
457 
458 if ($search_all) {
459  $setupstring = '';
460  foreach ($fieldstosearchall as $key => $val) {
461  $fieldstosearchall[$key] = $langs->trans($val);
462  $setupstring .= $key."=".$val.";";
463  }
464  print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
465  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
466 }
467 
468 $moreforfilter = '';
469 /*$moreforfilter.='<div class="divsearchfield">';
470 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
471 $moreforfilter.= '</div>';*/
472 
473 // Filter on categories
474 $moreforfilter = '';
475 if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
476  $moreforfilter .= '<div class="divsearchfield">';
477  $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
478  $categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1);
479  $categoriesKnowledgeArr[-2] = '- '.$langs->trans('NotCategorized').' -';
480  $moreforfilter .= Form::multiselectarray('search_category_knowledgemanagement_list', $categoriesKnowledgeArr, $searchCategoryKnowledgemanagementList, 0, 0, 'minwidth300');
481  $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_knowledgemanagement_operator" name="search_category_knowledgemanagement_operator" value="1"'.($searchCategoryKnowledgemanagementOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="search_category_knowledgemanagement_operator">'.$langs->trans('UseOrOperatorForCategories').'</label>';
482  $moreforfilter .= '</div>';
483 }
484 
485 $parameters = array();
486 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
487 if (empty($reshook)) {
488  $moreforfilter .= $hookmanager->resPrint;
489 } else {
490  $moreforfilter = $hookmanager->resPrint;
491 }
492 
493 if (!empty($moreforfilter)) {
494  print '<div class="liste_titre liste_titre_bydiv centpercent">';
495  print $moreforfilter;
496  print '</div>';
497 }
498 
499 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
500 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
501 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
502 
503 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
504 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
505 
506 
507 // Fields title search
508 // --------------------------------------------------------------------
509 print '<tr class="liste_titre">';
510 // Action column
511 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
512  print '<td class="liste_titre maxwidthsearch">';
513  $searchpicto = $form->showFilterButtons('left');
514  print $searchpicto;
515  print '</td>';
516 }
517 foreach ($object->fields as $key => $val) {
518  $searchkey = empty($search[$key]) ? '' : $search[$key];
519  $cssforfield = (empty($val['css']) ? '' : $val['css']);
520  if ($key == 'status') {
521  $cssforfield .= ($cssforfield ? ' ' : '').'center';
522  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
523  $cssforfield .= ($cssforfield ? ' ' : '').'center';
524  } elseif (in_array($val['type'], array('timestamp'))) {
525  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
526  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
527  $cssforfield .= ($cssforfield ? ' ' : '').'right';
528  }
529  if (!empty($arrayfields['t.'.$key]['checked'])) {
530  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
531 
532  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
533  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
534  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
535  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
536  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
537  print '<div class="nowrap">';
538  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
539  print '</div>';
540  print '<div class="nowrap">';
541  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
542  print '</div>';
543  } elseif ($key == 'lang') {
544  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
545  $formadmin = new FormAdmin($db);
546  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
547  } else {
548  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
549  }
550  print '</td>';
551  }
552 }
553 // Extra fields
554 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
555 
556 // Fields from hook
557 $parameters = array('arrayfields'=>$arrayfields);
558 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
559 print $hookmanager->resPrint;
560 // Action column
561 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
562  print '<td class="liste_titre maxwidthsearch">';
563  $searchpicto = $form->showFilterButtons();
564  print $searchpicto;
565  print '</td>';
566 }
567 print '</tr>'."\n";
568 
569 $totalarray = array();
570 $totalarray['nbfield'] = 0;
571 
572 // Fields title label
573 // --------------------------------------------------------------------
574 print '<tr class="liste_titre">';
575 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
576  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
577 }
578 foreach ($object->fields as $key => $val) {
579  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
580  if ($key == 'status') {
581  $cssforfield .= ($cssforfield ? ' ' : '').'center';
582  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
583  $cssforfield .= ($cssforfield ? ' ' : '').'center';
584  } elseif (in_array($val['type'], array('timestamp'))) {
585  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
586  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
587  $cssforfield .= ($cssforfield ? ' ' : '').'right';
588  }
589  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
590  if (!empty($arrayfields['t.'.$key]['checked'])) {
591  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
592  $totalarray['nbfield']++;
593  }
594 }
595 // Extra fields
596 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
597 // Hook fields
598 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
599 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
600 print $hookmanager->resPrint;
601 // Action column
602 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
603  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
604 }
605 $totalarray['nbfield']++;
606 print '</tr>'."\n";
607 
608 
609 // Detect if we need a fetch on each output line
610 $needToFetchEachLine = 0;
611 if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
612  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
613  if (preg_match('/\$object/', $val)) {
614  $needToFetchEachLine++; // There is at least one compute field that use $object
615  }
616  }
617 }
618 
619 
620 // Loop on record
621 // --------------------------------------------------------------------
622 $i = 0;
623 $savnbfield = $totalarray['nbfield'];
624 $totalarray['nbfield'] = 0;
625 $imaxinloop = ($limit ? min($num, $limit) : $num);
626 while ($i < $imaxinloop) {
627  $obj = $db->fetch_object($resql);
628  if (empty($obj)) {
629  break; // Should not happen
630  }
631 
632  // Store properties in $object
633  $object->setVarsFromFetchObj($obj);
634 
635  // Show here line of result
636  $j = 0;
637  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
638  // Action column
639  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
640  print '<td class="nowrap center">';
641  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
642  $selected = 0;
643  if (in_array($object->id, $arrayofselected)) {
644  $selected = 1;
645  }
646  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
647  }
648  print '</td>';
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 ? ' ' : '').'nowrap';
660  } elseif ($key == 'ref') {
661  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
662  }
663 
664  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
665  $cssforfield .= ($cssforfield ? ' ' : '').'right';
666  }
667  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
668  if (!empty($arrayfields['t.'.$key]['checked'])) {
669  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
670  if (preg_match('/tdoverflow/', $cssforfield)) {
671  print ' title="'.dol_escape_htmltag($object->$key).'"';
672  }
673  print '>';
674  if ($key == 'status') {
675  print $object->getLibStatut(5);
676  } elseif ($key == 'rowid') {
677  print $object->showOutputField($val, $key, $object->id, '');
678  } elseif ($key == 'fk_user_creat') {
679  if ($object->fk_user_creat > 0) {
680  if (isset($conf->cache['user'][$object->fk_user_creat])) {
681  $user_temp = $conf->cache['user'][$object->fk_user_creat];
682  } else {
683  $user_temp = new User($db);
684  $user_temp->fetch($object->fk_user_creat);
685  $conf->cache['user'][$object->fk_user_creat] = $user_temp;
686  }
687  print $user_temp->getNomUrl(-1);
688  }
689  } elseif ($key == 'fk_user_modif') {
690  if ($object->fk_user_modif > 0) {
691  if (isset($conf->cache['user'][$object->fk_user_modif])) {
692  $user_temp = $conf->cache['user'][$object->fk_user_modif];
693  } else {
694  $user_temp = new User($db);
695  $user_temp->fetch($object->fk_user_modif);
696  $conf->cache['user'][$object->fk_user_modif] = $user_temp;
697  }
698  print $user_temp->getNomUrl(-1);
699  }
700  } elseif ($key == 'fk_user_valid') {
701  if ($object->fk_user_valid > 0) {
702  if (isset($conf->cache['user'][$object->fk_user_valid])) {
703  $user_temp = $conf->cache['user'][$object->fk_user_valid];
704  } else {
705  $user_temp = new User($db);
706  $user_temp->fetch($object->fk_user_valid);
707  $conf->cache['user'][$object->fk_user_valid] = $user_temp;
708  }
709  print $user_temp->getNomUrl(-1);
710  }
711  } elseif ($key == 'lang') {
712  $labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
713  print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
714  print $labellang;
715  } else {
716  print $object->showOutputField($val, $key, $object->$key, '');
717  }
718  print '</td>';
719  if (!$i) {
720  $totalarray['nbfield']++;
721  }
722  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
723  if (!$i) {
724  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
725  }
726  if (!isset($totalarray['val'])) {
727  $totalarray['val'] = array();
728  }
729  if (!isset($totalarray['val']['t.'.$key])) {
730  $totalarray['val']['t.'.$key] = 0;
731  }
732  $totalarray['val']['t.'.$key] += $object->$key;
733  }
734  }
735  }
736  // Extra fields
737  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
738  // Fields from hook
739  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
740  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
741  print $hookmanager->resPrint;
742  // Action column
743  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
744  print '<td class="nowrap center">';
745  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
746  $selected = 0;
747  if (in_array($object->id, $arrayofselected)) {
748  $selected = 1;
749  }
750  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
751  }
752  print '</td>';
753  }
754  if (!$i) {
755  $totalarray['nbfield']++;
756  }
757 
758  print '</tr>'."\n";
759 
760  $i++;
761 }
762 
763 // Show total line
764 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
765 
766 // If no record found
767 if ($num == 0) {
768  $colspan = 1;
769  foreach ($arrayfields as $key => $val) {
770  if (!empty($val['checked'])) {
771  $colspan++;
772  }
773  }
774  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
775 }
776 
777 
778 $db->free($resql);
779 
780 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
781 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
782 print $hookmanager->resPrint;
783 
784 print '</table>'."\n";
785 print '</div>'."\n";
786 
787 print '</form>'."\n";
788 
789 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
790  $hidegeneratedfilelistifempty = 1;
791  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
792  $hidegeneratedfilelistifempty = 0;
793  }
794 
795  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
796  $formfile = new FormFile($db);
797 
798  // Show list of available documents
799  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
800  $urlsource .= str_replace('&amp;', '&', $param);
801 
802  $filedir = $diroutputmassaction;
803  $genallowed = $permissiontoread;
804  $delallowed = $permissiontoadd;
805 
806  print $formfile->showdocuments('massfilesarea_knowledgemanagement', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
807 }
808 
809 // End of page
810 llxFooter();
811 $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
KnowledgeRecord
Class for KnowledgeRecord.
Definition: knowledgerecord.class.php:32
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:8742
$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
$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
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
Form\multiselectarray
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Definition: html.form.class.php:8256
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
User
Class to manage Dolibarr users.
Definition: user.class.php:44
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
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
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