knowledgerecord_list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. /**
  19. * \file knowledgerecord_list.php
  20. * \ingroup knowledgemanagement
  21. * \brief List page for knowledgerecord
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. // load knowledgemanagement libraries
  30. require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
  31. // for other modules
  32. if (!empty($conf->categorie->enabled)) {
  33. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  34. }
  35. //dol_include_once('/othermodule/class/otherobject.class.php');
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("knowledgemanagement", "other"));
  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 = GETPOST('show_files', 'int'); // 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') : 'knowledgerecordlist'; // 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. $id = GETPOST('id', 'int');
  48. $searchCategoryKnowledgemanagementList = GETPOST('search_category_knowledgemanagement_list', 'array');
  49. $searchCategoryKnowledgemanagementOperator = 0;
  50. if (GETPOSTISSET('formfilteraction')) {
  51. $searchCategoryKnowledgemanagementOperator = GETPOST('search_category_knowledgemanagement_operator', 'int');
  52. } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
  53. $searchCategoryKnowledgemanagementOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  54. }
  55. // Load variable for pagination
  56. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  57. $sortfield = GETPOST('sortfield', 'aZ09comma');
  58. $sortorder = GETPOST('sortorder', 'aZ09comma');
  59. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  60. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  61. $page = 0;
  62. } // If $page is not defined, or '' or -1 or if we click on clear filters
  63. $offset = $limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. // Initialize technical objects
  67. $object = new KnowledgeRecord($db);
  68. $extrafields = new ExtraFields($db);
  69. $diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
  70. $hookmanager->initHooks(array('knowledgerecordlist')); // Note that conf->hooks_modules contains array
  71. // Fetch optionals attributes and labels
  72. $extrafields->fetch_name_optionals_label($object->table_element);
  73. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  74. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  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. // Initialize array of search criterias
  84. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  85. $search = array();
  86. foreach ($object->fields as $key => $val) {
  87. if (GETPOST('search_'.$key, 'alpha') !== '') {
  88. if ($key == "lang") {
  89. $search[$key] = GETPOST('search_'.$key, 'alpha')!='0' ? GETPOST('search_'.$key, 'alpha') : '';
  90. } else {
  91. $search[$key] = GETPOST('search_'.$key, 'alpha');
  92. }
  93. }
  94. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  95. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  96. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  97. }
  98. }
  99. // List of fields to search into when doing a "search in all"
  100. $fieldstosearchall = array();
  101. foreach ($object->fields as $key => $val) {
  102. if (!empty($val['searchall'])) {
  103. $fieldstosearchall['t.'.$key] = $val['label'];
  104. }
  105. }
  106. // Definition of array of fields for columns
  107. $arrayfields = array();
  108. foreach ($object->fields as $key => $val) {
  109. // If $val['visible']==0, then we never show the field
  110. if (!empty($val['visible'])) {
  111. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  112. $arrayfields['t.'.$key] = array(
  113. 'label'=>$val['label'],
  114. 'checked'=>(($visible < 0) ? 0 : 1),
  115. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  116. 'position'=>$val['position'],
  117. 'help'=> isset($val['help']) ? $val['help'] : ''
  118. );
  119. }
  120. }
  121. // Extra fields
  122. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  123. $object->fields = dol_sort_array($object->fields, 'position');
  124. $arrayfields = dol_sort_array($arrayfields, 'position');
  125. $permissiontoread = $user->rights->knowledgemanagement->knowledgerecord->read;
  126. $permissiontoadd = $user->rights->knowledgemanagement->knowledgerecord->write;
  127. $permissiontodelete = $user->rights->knowledgemanagement->knowledgerecord->delete;
  128. // Security check
  129. if (empty($conf->knowledgemanagement->enabled)) {
  130. accessforbidden('Module not enabled');
  131. }
  132. $socid = 0;
  133. if ($user->socid > 0) { // Protection if external user
  134. //$socid = $user->socid;
  135. accessforbidden();
  136. }
  137. //$result = restrictedArea($user, 'knowledgemanagement');
  138. //if (!$permissiontoread) accessforbidden();
  139. /*
  140. * Actions
  141. */
  142. if (GETPOST('cancel', 'alpha')) {
  143. $action = 'list';
  144. $massaction = '';
  145. }
  146. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  147. $massaction = '';
  148. }
  149. $parameters = array();
  150. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  151. if ($reshook < 0) {
  152. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  153. }
  154. if (empty($reshook)) {
  155. // Selection of new fields
  156. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  157. // Purge search criteria
  158. 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
  159. foreach ($object->fields as $key => $val) {
  160. $search[$key] = '';
  161. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  162. $search[$key.'_dtstart'] = '';
  163. $search[$key.'_dtend'] = '';
  164. }
  165. }
  166. $toselect = array();
  167. $search_array_options = array();
  168. }
  169. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  170. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  171. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  172. }
  173. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  174. $searchCategoryKnowledgemanagementOperator = 0;
  175. $searchCategoryKnowledgemanagementList = array();
  176. }
  177. // Mass actions
  178. $objectclass = 'KnowledgeRecord';
  179. $objectlabel = 'KnowledgeRecord';
  180. $uploaddir = $conf->knowledgemanagement->dir_output;
  181. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. $user_temp = new User($db);
  188. $formadmin = new FormAdmin($db);
  189. $now = dol_now();
  190. //$help_url="EN:Module_KnowledgeRecord|FR:Module_KnowledgeRecord_FR|ES:Módulo_KnowledgeRecord";
  191. $help_url = '';
  192. $title = $langs->trans('ListKnowledgeRecord');
  193. $morejs = array();
  194. $morecss = array();
  195. // Build and execute select
  196. // --------------------------------------------------------------------
  197. $sql = 'SELECT ';
  198. $sql .= $object->getFieldList('t');
  199. // Add fields from extrafields
  200. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  201. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  202. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key.', ' : '');
  203. }
  204. }
  205. // Add fields from hooks
  206. $parameters = array();
  207. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  208. $sql .= preg_replace('/^,/', ',', $hookmanager->resPrint);
  209. $sql = preg_replace('/,\s*$/', '', $sql);
  210. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  211. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  212. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  213. }
  214. if (!empty($searchCategoryKnowledgemanagementList) || !empty($catid)) {
  215. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_knowledgemanagement as ck ON t.rowid = ck.fk_knowledgemanagement"; // We'll need this table joined to the select in order to filter by categ
  216. }
  217. // Add table from hooks
  218. $parameters = array();
  219. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  220. $sql .= $hookmanager->resPrint;
  221. if ($object->ismultientitymanaged == 1) {
  222. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  223. } else {
  224. $sql .= " WHERE 1 = 1";
  225. }
  226. foreach ($search as $key => $val) {
  227. if (array_key_exists($key, $object->fields)) {
  228. if ($key == 'status' && $search[$key] == -1) {
  229. continue;
  230. }
  231. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  232. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  233. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  234. $search[$key] = '';
  235. }
  236. $mode_search = 2;
  237. }
  238. if ($search[$key] != '') {
  239. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  240. }
  241. } else {
  242. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  243. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  244. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  245. if (preg_match('/_dtstart$/', $key)) {
  246. $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
  247. }
  248. if (preg_match('/_dtend$/', $key)) {
  249. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  250. }
  251. }
  252. }
  253. }
  254. }
  255. //Search for tag/category
  256. $searchCategoryKnowledgemanagementSqlList = array();
  257. if ($searchCategoryKnowledgemanagementOperator == 1) {
  258. foreach ($searchCategoryKnowledgemanagementList as $searchCategoryKnowledgemanagement) {
  259. if (intval($searchCategoryKnowledgemanagement) == -2) {
  260. $searchCategoryKnowledgemanagementSqlList[] = "ck.fk_categorie IS NULL";
  261. } elseif (intval($searchCategoryKnowledgemanagement) > 0) {
  262. $searchCategoryKnowledgemanagementSqlList[] = "ck.fk_categorie = ".$db->escape($searchCategoryKnowledgemanagement);
  263. }
  264. }
  265. if (!empty($searchCategoryKnowledgemanagementSqlList)) {
  266. $sql .= " AND (".implode(' OR ', $searchCategoryKnowledgemanagementSqlList).")";
  267. }
  268. } else {
  269. foreach ($searchCategoryKnowledgemanagementList as $searchCategoryKnowledgemanagement) {
  270. if (intval($searchCategoryKnowledgemanagement) == -2) {
  271. $searchCategoryKnowledgemanagementSqlList[] = "ck.fk_categorie IS NULL";
  272. } elseif (intval($searchCategoryKnowledgemanagement) > 0) {
  273. $searchCategoryKnowledgemanagementSqlList[] = "t.rowid IN (SELECT fk_knowledgemanagement FROM ".MAIN_DB_PREFIX."categorie_knowledgemanagement WHERE fk_categorie = ".((int) $searchCategoryKnowledgemanagement).")";
  274. }
  275. }
  276. if (!empty($searchCategoryKnowledgemanagementSqlList)) {
  277. $sql .= " AND (".implode(' AND ', $searchCategoryKnowledgemanagementSqlList).")";
  278. }
  279. }
  280. if ($search_all) {
  281. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  282. }
  283. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  284. // Add where from extra fields
  285. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  286. // Add where from hooks
  287. $parameters = array();
  288. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  289. $sql .= $hookmanager->resPrint;
  290. /* If a group by is required
  291. $sql.= " GROUP BY ";
  292. foreach($object->fields as $key => $val) {
  293. $sql .= "t.".$key.", ";
  294. }
  295. // Add fields from extrafields
  296. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  297. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  298. }
  299. // Add where from hooks
  300. $parameters=array();
  301. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
  302. $sql.=$hookmanager->resPrint;
  303. $sql=preg_replace('/,\s*$/','', $sql);
  304. */
  305. $sql .= $db->order($sortfield, $sortorder);
  306. // Count total nb of records
  307. $nbtotalofrecords = '';
  308. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  309. $resql = $db->query($sql);
  310. $nbtotalofrecords = $db->num_rows($resql);
  311. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  312. $page = 0;
  313. $offset = 0;
  314. }
  315. }
  316. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  317. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  318. $num = $nbtotalofrecords;
  319. } else {
  320. if ($limit) {
  321. $sql .= $db->plimit($limit + 1, $offset);
  322. }
  323. $resql = $db->query($sql);
  324. if (!$resql) {
  325. dol_print_error($db);
  326. exit;
  327. }
  328. $num = $db->num_rows($resql);
  329. }
  330. // Direct jump if only one record found
  331. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  332. $obj = $db->fetch_object($resql);
  333. $id = $obj->rowid;
  334. header("Location: ".dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?id='.$id);
  335. exit;
  336. }
  337. // Output page
  338. // --------------------------------------------------------------------
  339. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  340. $arrayofselected = is_array($toselect) ? $toselect : array();
  341. $param = '';
  342. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  343. $param .= '&contextpage='.urlencode($contextpage);
  344. }
  345. if ($limit > 0 && $limit != $conf->liste_limit) {
  346. $param .= '&limit='.urlencode($limit);
  347. }
  348. foreach ($search as $key => $val) {
  349. if (is_array($search[$key]) && count($search[$key])) {
  350. foreach ($search[$key] as $skey) {
  351. $param .= '&search_'.$key.'[]='.urlencode($skey);
  352. }
  353. } else {
  354. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  355. }
  356. }
  357. if ($optioncss != '') {
  358. $param .= '&optioncss='.urlencode($optioncss);
  359. }
  360. // Add $param from extra fields
  361. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  362. // Add $param from hooks
  363. $parameters = array();
  364. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  365. $param .= $hookmanager->resPrint;
  366. // List of mass actions available
  367. $arrayofmassactions = array(
  368. 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  369. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  370. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  371. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  372. );
  373. if ($permissiontodelete) {
  374. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  375. }
  376. if ($user->rights->knowledgemanagement->knowledgerecord->write) {
  377. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  378. }
  379. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  380. $arrayofmassactions = array();
  381. }
  382. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  383. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  384. if ($optioncss != '') {
  385. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  386. }
  387. print '<input type="hidden" name="token" value="'.newToken().'">';
  388. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  389. print '<input type="hidden" name="action" value="list">';
  390. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  391. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  392. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  393. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  394. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  395. // Add code for pre mass action (confirmation or email presend form)
  396. $topicmail = "SendKnowledgeRecordRef";
  397. $modelmail = "knowledgerecord";
  398. $objecttmp = new KnowledgeRecord($db);
  399. $trackid = 'xxxx'.$object->id;
  400. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  401. if ($search_all) {
  402. foreach ($fieldstosearchall as $key => $val) {
  403. $fieldstosearchall[$key] = $langs->trans($val);
  404. }
  405. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  406. }
  407. $moreforfilter = '';
  408. /*$moreforfilter.='<div class="divsearchfield">';
  409. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  410. $moreforfilter.= '</div>';*/
  411. // Filter on categories
  412. $moreforfilter = '';
  413. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  414. $moreforfilter .= '<div class="divsearchfield">';
  415. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
  416. $categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1);
  417. $categoriesKnowledgeArr[-2] = '- '.$langs->trans('NotCategorized').' -';
  418. $moreforfilter .= Form::multiselectarray('search_category_knowledgemanagement_list', $categoriesKnowledgeArr, $searchCategoryKnowledgemanagementList, 0, 0, 'minwidth300');
  419. $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>';
  420. $moreforfilter .= '</div>';
  421. }
  422. $parameters = array();
  423. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  424. if (empty($reshook)) {
  425. $moreforfilter .= $hookmanager->resPrint;
  426. } else {
  427. $moreforfilter = $hookmanager->resPrint;
  428. }
  429. if (!empty($moreforfilter)) {
  430. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  431. print $moreforfilter;
  432. print '</div>';
  433. }
  434. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  435. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  436. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  437. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  438. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  439. // Fields title search
  440. // --------------------------------------------------------------------
  441. print '<tr class="liste_titre">';
  442. foreach ($object->fields as $key => $val) {
  443. $searchkey = empty($search[$key]) ? '' : $search[$key];
  444. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  445. if ($key == 'status') {
  446. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  447. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  448. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  449. } elseif (in_array($val['type'], array('timestamp'))) {
  450. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  451. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  452. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  453. }
  454. if (!empty($arrayfields['t.'.$key]['checked'])) {
  455. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  456. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  457. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $searchkey, $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  458. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
  459. print $object->showInputField($val, $key, $searchkey, '', '', 'search_', 'maxwidth125', 1);
  460. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  461. print '<div class="nowrap">';
  462. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  463. print '</div>';
  464. print '<div class="nowrap">';
  465. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  466. print '</div>';
  467. } elseif ($key == 'lang') {
  468. print $formadmin->select_language($searchkey, 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  469. } else {
  470. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($searchkey).'">';
  471. }
  472. print '</td>';
  473. }
  474. }
  475. // Extra fields
  476. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  477. // Fields from hook
  478. $parameters = array('arrayfields'=>$arrayfields);
  479. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  480. print $hookmanager->resPrint;
  481. // Action column
  482. print '<td class="liste_titre maxwidthsearch">';
  483. $searchpicto = $form->showFilterButtons();
  484. print $searchpicto;
  485. print '</td>';
  486. print '</tr>'."\n";
  487. // Fields title label
  488. // --------------------------------------------------------------------
  489. print '<tr class="liste_titre">';
  490. foreach ($object->fields as $key => $val) {
  491. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  492. if ($key == 'status') {
  493. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  494. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  495. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  496. } elseif (in_array($val['type'], array('timestamp'))) {
  497. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  498. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  499. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  500. }
  501. if (!empty($arrayfields['t.'.$key]['checked'])) {
  502. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  503. }
  504. }
  505. // Extra fields
  506. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  507. // Hook fields
  508. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  509. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  510. print $hookmanager->resPrint;
  511. // Action column
  512. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  513. print '</tr>'."\n";
  514. // Detect if we need a fetch on each output line
  515. $needToFetchEachLine = 0;
  516. if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  517. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  518. if (preg_match('/\$object/', $val)) {
  519. $needToFetchEachLine++; // There is at least one compute field that use $object
  520. }
  521. }
  522. }
  523. // Loop on record
  524. // --------------------------------------------------------------------
  525. $i = 0;
  526. $totalarray = array();
  527. while ($i < ($limit ? min($num, $limit) : $num)) {
  528. $obj = $db->fetch_object($resql);
  529. if (empty($obj)) {
  530. break; // Should not happen
  531. }
  532. // Store properties in $object
  533. $object->setVarsFromFetchObj($obj);
  534. // Show here line of result
  535. print '<tr class="oddeven">';
  536. $totalarray['nbfield'] = 0;
  537. foreach ($object->fields as $key => $val) {
  538. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  539. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  540. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  541. } elseif ($key == 'status') {
  542. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  543. }
  544. if (in_array($val['type'], array('timestamp'))) {
  545. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  546. } elseif ($key == 'ref') {
  547. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  548. }
  549. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status'))) {
  550. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  551. }
  552. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  553. if (!empty($arrayfields['t.'.$key]['checked'])) {
  554. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  555. if ($key == 'status') {
  556. print $object->getLibStatut(5);
  557. } elseif ($key == 'fk_user_creat') {
  558. if ($object->fk_user_creat > 0) {
  559. if (isset($conf->cache['user'][$object->fk_user_creat])) {
  560. $user_temp = $conf->cache['user'][$object->fk_user_creat];
  561. } else {
  562. $user_temp = new User($db);
  563. $user_temp->fetch($object->fk_user_creat);
  564. $conf->cache['user'][$object->fk_user_creat] = $user_temp;
  565. }
  566. print $user_temp->getNomUrl(-1);
  567. }
  568. } elseif ($key == 'fk_user_modif') {
  569. if ($object->fk_user_modif > 0) {
  570. if (isset($conf->cache['user'][$object->fk_user_modif])) {
  571. $user_temp = $conf->cache['user'][$object->fk_user_modif];
  572. } else {
  573. $user_temp = new User($db);
  574. $user_temp->fetch($object->fk_user_modif);
  575. $conf->cache['user'][$object->fk_user_modif] = $user_temp;
  576. }
  577. print $user_temp->getNomUrl(-1);
  578. }
  579. } elseif ($key == 'fk_user_valid') {
  580. if ($object->fk_user_valid > 0) {
  581. if (isset($conf->cache['user'][$object->fk_user_valid])) {
  582. $user_temp = $conf->cache['user'][$object->fk_user_valid];
  583. } else {
  584. $user_temp = new User($db);
  585. $user_temp->fetch($object->fk_user_valid);
  586. $conf->cache['user'][$object->fk_user_valid] = $user_temp;
  587. }
  588. print $user_temp->getNomUrl(-1);
  589. }
  590. } elseif ($key == 'lang') {
  591. $labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
  592. print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
  593. print $labellang;
  594. } else {
  595. print $object->showOutputField($val, $key, $object->$key, '');
  596. }
  597. print '</td>';
  598. if (!$i) {
  599. $totalarray['nbfield']++;
  600. }
  601. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  602. if (!$i) {
  603. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  604. }
  605. if (!isset($totalarray['val'])) {
  606. $totalarray['val'] = array();
  607. }
  608. if (!isset($totalarray['val']['t.'.$key])) {
  609. $totalarray['val']['t.'.$key] = 0;
  610. }
  611. $totalarray['val']['t.'.$key] += $object->$key;
  612. }
  613. }
  614. }
  615. // Extra fields
  616. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  617. // Fields from hook
  618. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  619. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  620. print $hookmanager->resPrint;
  621. // Action column
  622. print '<td class="nowrap center">';
  623. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  624. $selected = 0;
  625. if (in_array($object->id, $arrayofselected)) {
  626. $selected = 1;
  627. }
  628. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  629. }
  630. print '</td>';
  631. if (!$i) {
  632. $totalarray['nbfield']++;
  633. }
  634. print '</tr>'."\n";
  635. $i++;
  636. }
  637. // Show total line
  638. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  639. // If no record found
  640. if ($num == 0) {
  641. $colspan = 1;
  642. foreach ($arrayfields as $key => $val) {
  643. if (!empty($val['checked'])) {
  644. $colspan++;
  645. }
  646. }
  647. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  648. }
  649. $db->free($resql);
  650. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  651. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  652. print $hookmanager->resPrint;
  653. print '</table>'."\n";
  654. print '</div>'."\n";
  655. print '</form>'."\n";
  656. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  657. $hidegeneratedfilelistifempty = 1;
  658. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  659. $hidegeneratedfilelistifempty = 0;
  660. }
  661. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  662. $formfile = new FormFile($db);
  663. // Show list of available documents
  664. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  665. $urlsource .= str_replace('&amp;', '&', $param);
  666. $filedir = $diroutputmassaction;
  667. $genallowed = $permissiontoread;
  668. $delallowed = $permissiontoadd;
  669. print $formfile->showdocuments('massfilesarea_knowledgemanagement', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  670. }
  671. // End of page
  672. llxFooter();
  673. $db->close();