dolibarr  x.y.z
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 (isModEnabled('categorie')) {
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', 0, '', 'knowledgerecord');
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  if ($searchCategoryKnowledgemanagementOperator == 0) {
297  $searchCategoryKnowledgemanagementSqlList[] = " EXISTS (SELECT ck.fk_knowledgemanagement FROM ".MAIN_DB_PREFIX."categorie_knowledgemanagement as ck WHERE t.rowid = ck.fk_knowledgemanagement AND ck.fk_categorie = ".((int) $searchCategoryKnowledgemanagement).")";
298  } else {
299  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryKnowledgemanagement);
300  }
301  }
302  }
303  if ($listofcategoryid) {
304  $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)."))";
305  }
306  if ($searchCategoryKnowledgemanagementOperator == 1) {
307  if (!empty($searchCategoryKnowledgemanagementSqlList)) {
308  $sql .= " AND (".implode(' OR ', $searchCategoryKnowledgemanagementSqlList).")";
309  }
310  } else {
311  if (!empty($searchCategoryKnowledgemanagementSqlList)) {
312  $sql .= " AND (".implode(' AND ', $searchCategoryKnowledgemanagementSqlList).")";
313  }
314  }
315 }
316 
317 if ($search_all) {
318  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
319 }
320 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
321 // Add where from extra fields
322 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
323 // Add where from hooks
324 $parameters = array();
325 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
326 $sql .= $hookmanager->resPrint;
327 
328 /* If a group by is required
329 $sql.= " GROUP BY ";
330 foreach($object->fields as $key => $val) {
331  $sql .= "t.".$key.", ";
332 }
333 // Add fields from extrafields
334 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
335  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
336 }
337 // Add where from hooks
338 $parameters=array();
339 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
340 $sql.=$hookmanager->resPrint;
341 $sql=preg_replace('/,\s*$/','', $sql);
342 */
343 
344 // Count total nb of records
345 $nbtotalofrecords = '';
346 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
347  $resql = $db->query($sql);
348  $nbtotalofrecords = $db->num_rows($resql);
349 
350  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
351  $page = 0;
352  $offset = 0;
353  }
354  $db->free($resql);
355 }
356 
357 // Complete request and execute it with limit
358 $sql .= $db->order($sortfield, $sortorder);
359 if ($limit) {
360  $sql .= $db->plimit($limit + 1, $offset);
361 }
362 
363 $resql = $db->query($sql);
364 if (!$resql) {
365  dol_print_error($db);
366  exit;
367 }
368 
369 $num = $db->num_rows($resql);
370 
371 
372 // Direct jump if only one record found
373 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
374  $obj = $db->fetch_object($resql);
375  $id = $obj->rowid;
376  header("Location: ".dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?id='.$id);
377  exit;
378 }
379 
380 
381 // Output page
382 // --------------------------------------------------------------------
383 
384 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
385 
386 
387 $arrayofselected = is_array($toselect) ? $toselect : array();
388 
389 $param = '';
390 if (!empty($mode)) {
391  $param .= '&mode='.urlencode($mode);
392 }
393 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
394  $param .= '&contextpage='.urlencode($contextpage);
395 }
396 if ($limit > 0 && $limit != $conf->liste_limit) {
397  $param .= '&limit='.urlencode($limit);
398 }
399 foreach ($search as $key => $val) {
400  if (is_array($search[$key]) && count($search[$key])) {
401  foreach ($search[$key] as $skey) {
402  if ($skey != '') {
403  $param .= '&search_'.$key.'[]='.urlencode($skey);
404  }
405  }
406  } elseif ($search[$key] != '') {
407  $param .= '&search_'.$key.'='.urlencode($search[$key]);
408  }
409 }
410 if ($optioncss != '') {
411  $param .= '&optioncss='.urlencode($optioncss);
412 }
413 // Add $param from extra fields
414 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
415 // Add $param from hooks
416 $parameters = array();
417 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
418 $param .= $hookmanager->resPrint;
419 
420 // List of mass actions available
421 $arrayofmassactions = array(
422  'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
423  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
424  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
425  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
426 );
427 if ($permissiontodelete) {
428  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
429 }
430 
431 if (isModEnabled('category') && $user->rights->knowledgemanagement->knowledgerecord->write) {
432  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
433 }
434 
435 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
436  $arrayofmassactions = array();
437 }
438 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
439 
440 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
441 if ($optioncss != '') {
442  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
443 }
444 print '<input type="hidden" name="token" value="'.newToken().'">';
445 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
446 print '<input type="hidden" name="action" value="list">';
447 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
448 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
449 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
450 
451 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
452 
453 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
454 
455 // Add code for pre mass action (confirmation or email presend form)
456 $topicmail = "SendKnowledgeRecordRef";
457 $modelmail = "knowledgerecord";
458 $objecttmp = new KnowledgeRecord($db);
459 $trackid = 'xxxx'.$object->id;
460 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
461 
462 if ($search_all) {
463  $setupstring = '';
464  foreach ($fieldstosearchall as $key => $val) {
465  $fieldstosearchall[$key] = $langs->trans($val);
466  $setupstring .= $key."=".$val.";";
467  }
468  print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
469  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
470 }
471 
472 $moreforfilter = '';
473 /*$moreforfilter.='<div class="divsearchfield">';
474 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
475 $moreforfilter.= '</div>';*/
476 
477 // Filter on categories
478 $moreforfilter = '';
479 if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
480  $moreforfilter .= '<div class="divsearchfield">';
481  $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
482  $categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1);
483  $categoriesKnowledgeArr[-2] = '- '.$langs->trans('NotCategorized').' -';
484  $moreforfilter .= Form::multiselectarray('search_category_knowledgemanagement_list', $categoriesKnowledgeArr, $searchCategoryKnowledgemanagementList, 0, 0, 'minwidth300');
485  $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>';
486  $moreforfilter .= '</div>';
487 }
488 
489 $parameters = array();
490 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
491 if (empty($reshook)) {
492  $moreforfilter .= $hookmanager->resPrint;
493 } else {
494  $moreforfilter = $hookmanager->resPrint;
495 }
496 
497 if (!empty($moreforfilter)) {
498  print '<div class="liste_titre liste_titre_bydiv centpercent">';
499  print $moreforfilter;
500  print '</div>';
501 }
502 
503 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
504 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
505 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
506 
507 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
508 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
509 
510 
511 // Fields title search
512 // --------------------------------------------------------------------
513 print '<tr class="liste_titre">';
514 // Action column
515 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
516  print '<td class="liste_titre maxwidthsearch">';
517  $searchpicto = $form->showFilterButtons('left');
518  print $searchpicto;
519  print '</td>';
520 }
521 foreach ($object->fields as $key => $val) {
522  $searchkey = empty($search[$key]) ? '' : $search[$key];
523  $cssforfield = (empty($val['css']) ? '' : $val['css']);
524  if ($key == 'status') {
525  $cssforfield .= ($cssforfield ? ' ' : '').'center';
526  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
527  $cssforfield .= ($cssforfield ? ' ' : '').'center';
528  } elseif (in_array($val['type'], array('timestamp'))) {
529  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
530  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
531  $cssforfield .= ($cssforfield ? ' ' : '').'right';
532  }
533  if (!empty($arrayfields['t.'.$key]['checked'])) {
534  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
535 
536  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
537  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
538  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
539  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
540  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
541  print '<div class="nowrap">';
542  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
543  print '</div>';
544  print '<div class="nowrap">';
545  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
546  print '</div>';
547  } elseif ($key == 'lang') {
548  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
549  $formadmin = new FormAdmin($db);
550  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
551  } else {
552  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
553  }
554  print '</td>';
555  }
556 }
557 // Extra fields
558 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
559 
560 // Fields from hook
561 $parameters = array('arrayfields'=>$arrayfields);
562 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
563 print $hookmanager->resPrint;
564 // Action column
565 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
566  print '<td class="liste_titre maxwidthsearch">';
567  $searchpicto = $form->showFilterButtons();
568  print $searchpicto;
569  print '</td>';
570 }
571 print '</tr>'."\n";
572 
573 $totalarray = array();
574 $totalarray['nbfield'] = 0;
575 
576 // Fields title label
577 // --------------------------------------------------------------------
578 print '<tr class="liste_titre">';
579 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
580  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
581 }
582 foreach ($object->fields as $key => $val) {
583  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
584  if ($key == 'status') {
585  $cssforfield .= ($cssforfield ? ' ' : '').'center';
586  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
587  $cssforfield .= ($cssforfield ? ' ' : '').'center';
588  } elseif (in_array($val['type'], array('timestamp'))) {
589  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
590  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
591  $cssforfield .= ($cssforfield ? ' ' : '').'right';
592  }
593  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
594  if (!empty($arrayfields['t.'.$key]['checked'])) {
595  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
596  $totalarray['nbfield']++;
597  }
598 }
599 // Extra fields
600 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
601 // Hook fields
602 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
603 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
604 print $hookmanager->resPrint;
605 // Action column
606 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
607  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
608 }
609 $totalarray['nbfield']++;
610 print '</tr>'."\n";
611 
612 
613 // Detect if we need a fetch on each output line
614 $needToFetchEachLine = 0;
615 if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
616  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
617  if (preg_match('/\$object/', $val)) {
618  $needToFetchEachLine++; // There is at least one compute field that use $object
619  }
620  }
621 }
622 
623 
624 // Loop on record
625 // --------------------------------------------------------------------
626 $i = 0;
627 $savnbfield = $totalarray['nbfield'];
628 $totalarray['nbfield'] = 0;
629 $imaxinloop = ($limit ? min($num, $limit) : $num);
630 while ($i < $imaxinloop) {
631  $obj = $db->fetch_object($resql);
632  if (empty($obj)) {
633  break; // Should not happen
634  }
635 
636  // Store properties in $object
637  $object->setVarsFromFetchObj($obj);
638 
639  // Show here line of result
640  $j = 0;
641  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
642  // Action column
643  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
644  print '<td class="nowrap center">';
645  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
646  $selected = 0;
647  if (in_array($object->id, $arrayofselected)) {
648  $selected = 1;
649  }
650  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
651  }
652  print '</td>';
653  }
654  foreach ($object->fields as $key => $val) {
655  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
656  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
657  $cssforfield .= ($cssforfield ? ' ' : '').'center';
658  } elseif ($key == 'status') {
659  $cssforfield .= ($cssforfield ? ' ' : '').'center';
660  }
661 
662  if (in_array($val['type'], array('timestamp'))) {
663  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
664  } elseif ($key == 'ref') {
665  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
666  }
667 
668  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
669  $cssforfield .= ($cssforfield ? ' ' : '').'right';
670  }
671  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
672  if (!empty($arrayfields['t.'.$key]['checked'])) {
673  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
674  if (preg_match('/tdoverflow/', $cssforfield)) {
675  print ' title="'.dol_escape_htmltag($object->$key).'"';
676  }
677  print '>';
678  if ($key == 'status') {
679  print $object->getLibStatut(5);
680  } elseif ($key == 'rowid') {
681  print $object->showOutputField($val, $key, $object->id, '');
682  } elseif ($key == 'fk_user_creat') {
683  if ($object->fk_user_creat > 0) {
684  if (isset($conf->cache['user'][$object->fk_user_creat])) {
685  $user_temp = $conf->cache['user'][$object->fk_user_creat];
686  } else {
687  $user_temp = new User($db);
688  $user_temp->fetch($object->fk_user_creat);
689  $conf->cache['user'][$object->fk_user_creat] = $user_temp;
690  }
691  print $user_temp->getNomUrl(-1);
692  }
693  } elseif ($key == 'fk_user_modif') {
694  if ($object->fk_user_modif > 0) {
695  if (isset($conf->cache['user'][$object->fk_user_modif])) {
696  $user_temp = $conf->cache['user'][$object->fk_user_modif];
697  } else {
698  $user_temp = new User($db);
699  $user_temp->fetch($object->fk_user_modif);
700  $conf->cache['user'][$object->fk_user_modif] = $user_temp;
701  }
702  print $user_temp->getNomUrl(-1);
703  }
704  } elseif ($key == 'fk_user_valid') {
705  if ($object->fk_user_valid > 0) {
706  if (isset($conf->cache['user'][$object->fk_user_valid])) {
707  $user_temp = $conf->cache['user'][$object->fk_user_valid];
708  } else {
709  $user_temp = new User($db);
710  $user_temp->fetch($object->fk_user_valid);
711  $conf->cache['user'][$object->fk_user_valid] = $user_temp;
712  }
713  print $user_temp->getNomUrl(-1);
714  }
715  } elseif ($key == 'lang') {
716  $labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
717  print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
718  print $labellang;
719  } else {
720  print $object->showOutputField($val, $key, $object->$key, '');
721  }
722  print '</td>';
723  if (!$i) {
724  $totalarray['nbfield']++;
725  }
726  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
727  if (!$i) {
728  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
729  }
730  if (!isset($totalarray['val'])) {
731  $totalarray['val'] = array();
732  }
733  if (!isset($totalarray['val']['t.'.$key])) {
734  $totalarray['val']['t.'.$key] = 0;
735  }
736  $totalarray['val']['t.'.$key] += $object->$key;
737  }
738  }
739  }
740  // Extra fields
741  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
742  // Fields from hook
743  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
744  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
745  print $hookmanager->resPrint;
746  // Action column
747  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
748  print '<td class="nowrap center">';
749  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
750  $selected = 0;
751  if (in_array($object->id, $arrayofselected)) {
752  $selected = 1;
753  }
754  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
755  }
756  print '</td>';
757  }
758  if (!$i) {
759  $totalarray['nbfield']++;
760  }
761 
762  print '</tr>'."\n";
763 
764  $i++;
765 }
766 
767 // Show total line
768 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
769 
770 // If no record found
771 if ($num == 0) {
772  $colspan = 1;
773  foreach ($arrayfields as $key => $val) {
774  if (!empty($val['checked'])) {
775  $colspan++;
776  }
777  }
778  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
779 }
780 
781 
782 $db->free($resql);
783 
784 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
785 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
786 print $hookmanager->resPrint;
787 
788 print '</table>'."\n";
789 print '</div>'."\n";
790 
791 print '</form>'."\n";
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_knowledgemanagement', '', $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 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.
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.
Class for KnowledgeRecord.
Class to manage Dolibarr users.
Definition: user.class.php:45
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...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
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.
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.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.