workstation_list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.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 htdocs/workstation/workstation_list.php
  20. * \ingroup workstation
  21. * \brief List page for workstation
  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/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('mrp', 'other'));
  32. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  33. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  34. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  35. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  36. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  37. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  38. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'workstationlist'; // To manage different context of search
  39. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  40. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  41. $mode = GETPOST('mode', 'aZ');
  42. $id = GETPOST('id', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  49. // If $page is not defined, or '' or -1 or if we click on clear filters
  50. $page = 0;
  51. }
  52. $offset = $limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. // Initialize technical objects
  56. $object = new Workstation($db);
  57. $extrafields = new ExtraFields($db);
  58. $diroutputmassaction = $conf->workstation->dir_output.'/temp/massgeneration/'.$user->id;
  59. $hookmanager->initHooks(array('workstationlist')); // Note that conf->hooks_modules contains array
  60. // Fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  63. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  64. // Default sort order (if not yet defined by previous GETPOST)
  65. if (!$sortfield) {
  66. reset($object->fields); // Reset is required to avoid key() to return null.
  67. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "ASC";
  71. }
  72. // Initialize array of search criterias
  73. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  74. $search = array();
  75. foreach ($object->fields as $key => $val) {
  76. if (GETPOST('search_'.$key, 'alpha') !== '') {
  77. $search[$key] = GETPOST('search_'.$key, 'alpha');
  78. }
  79. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  80. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  81. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  82. }
  83. }
  84. $groups = GETPOST('groups', 'array:int');
  85. $resources = GETPOST('resources', 'array:int');
  86. // List of fields to search into when doing a "search in all"
  87. $fieldstosearchall = array();
  88. foreach ($object->fields as $key => $val) {
  89. if (!empty($val['searchall'])) {
  90. $fieldstosearchall['t.'.$key] = $val['label'];
  91. }
  92. }
  93. // Definition of array of fields for columns
  94. $arrayfields = array();
  95. foreach ($object->fields as $key => $val) {
  96. // If $val['visible']==0, then we never show the field
  97. if (!empty($val['visible'])) {
  98. $visible = (int) dol_eval($val['visible'], 1);
  99. $arrayfields['t.'.$key] = array(
  100. 'label'=>$val['label'],
  101. 'checked'=>(($visible < 0) ? 0 : 1),
  102. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  103. 'position'=>$val['position'],
  104. 'help'=> isset($val['help']) ? $val['help'] : ''
  105. );
  106. }
  107. }
  108. $arrayfields['wug.fk_usergroup'] = array(
  109. 'label'=>$langs->trans('UserGroups'),
  110. 'checked'=>(($visible < 0) ? 0 : 1),
  111. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  112. 'position'=>1000,
  113. 'help' => empty($val['help']) ? '' : $val['help']
  114. );
  115. /* disabled because adding resources to workstation seems not yet available in GUI
  116. $arrayfields['wr.fk_resource'] = array(
  117. 'label'=>$langs->trans('Resources'),
  118. 'checked'=>(($visible < 0) ? 0 : 1),
  119. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  120. 'position'=>1001,
  121. 'help' => empty($val['help']) ? '' : $val['help']
  122. );
  123. */
  124. // Extra fields
  125. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  126. $object->fields = dol_sort_array($object->fields, 'position');
  127. $arrayfields = dol_sort_array($arrayfields, 'position');
  128. $permissiontoread = $user->rights->workstation->workstation->read;
  129. $permissiontoadd = $user->rights->workstation->workstation->write;
  130. $permissiontodelete = $user->rights->workstation->workstation->delete;
  131. // Security check
  132. restrictedArea($user, $object->element, 0, $object->table_element, 'workstation');
  133. /*
  134. * Actions
  135. */
  136. if (GETPOST('cancel', 'alpha')) {
  137. $action = 'list';
  138. $massaction = '';
  139. }
  140. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  141. $massaction = '';
  142. }
  143. $parameters = array();
  144. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  145. if ($reshook < 0) {
  146. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  147. }
  148. if (empty($reshook)) {
  149. // Selection of new fields
  150. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  151. // Purge search criteria
  152. 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
  153. foreach ($object->fields as $key => $val) {
  154. $search[$key] = '';
  155. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  156. $search[$key.'_dtstart'] = '';
  157. $search[$key.'_dtend'] = '';
  158. }
  159. }
  160. $groups = $resources=array();
  161. $toselect = array();
  162. $search_array_options = array();
  163. }
  164. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  165. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  166. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  167. }
  168. // Mass actions
  169. $objectclass = 'Workstation';
  170. $objectlabel = 'Workstation';
  171. $uploaddir = $conf->workstation->dir_output;
  172. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  173. }
  174. /*
  175. * View
  176. */
  177. $form = new Form($db);
  178. $formresource = new FormResource($db);
  179. $now = dol_now();
  180. $help_url = 'EN:Module_Workstation';
  181. $title = $langs->trans("Workstations");
  182. $morejs = array();
  183. $morecss = array();
  184. // Build and execute select
  185. // --------------------------------------------------------------------
  186. $sql = 'SELECT ';
  187. $sql .= $object->getFieldList('t');
  188. // Add fields from extrafields
  189. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  190. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  191. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  192. }
  193. }
  194. // Add fields from hooks
  195. $parameters = array();
  196. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  197. $sql .= $hookmanager->resPrint;
  198. $sql = preg_replace('/,\s*$/', '', $sql);
  199. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  200. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  201. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  202. }
  203. if (!empty($groups)) {
  204. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'workstation_workstation_usergroup wug ON (wug.fk_workstation = t.rowid)';
  205. }
  206. if (!empty($resources)) {
  207. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'workstation_workstation_resource wr ON (wr.fk_workstation = t.rowid)';
  208. }
  209. // Add table from hooks
  210. $parameters = array();
  211. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  212. $sql .= $hookmanager->resPrint;
  213. if ($object->ismultientitymanaged == 1) {
  214. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  215. } else {
  216. $sql .= " WHERE 1 = 1";
  217. }
  218. foreach ($search as $key => $val) {
  219. if (array_key_exists($key, $object->fields)) {
  220. if ($key == 'status' && $search[$key] == -1) {
  221. continue;
  222. }
  223. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  224. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  225. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  226. $search[$key] = '';
  227. }
  228. $mode_search = 2;
  229. }
  230. if ($search[$key] != '') {
  231. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  232. }
  233. } else {
  234. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  235. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  236. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  237. if (preg_match('/_dtstart$/', $key)) {
  238. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  239. }
  240. if (preg_match('/_dtend$/', $key)) {
  241. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  242. }
  243. }
  244. }
  245. }
  246. }
  247. if ($search_all) {
  248. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  249. }
  250. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  251. // Add where from extra fields
  252. // usergroups
  253. if (!empty($groups)) {
  254. $sql.= ' AND wug.fk_usergroup IN('.$db->sanitize(implode(',', $groups)).')';
  255. }
  256. // resources
  257. if (!empty($resources)) {
  258. $sql.= ' AND wr.fk_resource IN('.$db->sanitize(implode(',', $resources)).')';
  259. }
  260. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  261. // Add where from hooks
  262. $parameters = array();
  263. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  264. $sql .= $hookmanager->resPrint;
  265. $sql.= " GROUP BY ";
  266. foreach ($object->fields as $key => $val) {
  267. $sql .= "t.".$db->escape($key).", ";
  268. }
  269. // Add fields from extrafields
  270. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  271. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  272. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  273. }
  274. }
  275. // Add where from hooks
  276. $parameters = array();
  277. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  278. $sql .= $hookmanager->resPrint;
  279. $sql = preg_replace('/,\s*$/', '', $sql);
  280. // Count total nb of records
  281. $nbtotalofrecords = '';
  282. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  283. /* This old and fast method to get and count full list returns all record so use a high amount of memory. */
  284. $resql = $db->query($sql);
  285. $nbtotalofrecords = $db->num_rows($resql);
  286. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  287. $page = 0;
  288. $offset = 0;
  289. }
  290. $db->free($resql);
  291. }
  292. // Complete request and execute it with limit
  293. $sql .= $db->order($sortfield, $sortorder);
  294. if ($limit) {
  295. $sql .= $db->plimit($limit + 1, $offset);
  296. }
  297. $resql = $db->query($sql);
  298. if (!$resql) {
  299. dol_print_error($db);
  300. exit;
  301. }
  302. $num = $db->num_rows($resql);
  303. // Direct jump if only one record found
  304. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  305. $obj = $db->fetch_object($resql);
  306. $id = $obj->rowid;
  307. header("Location: ".DOL_URL_ROOT.'/workstation/workstation_card.php?id='.$id);
  308. exit;
  309. }
  310. // Output page
  311. // --------------------------------------------------------------------
  312. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  313. $arrayofselected = is_array($toselect) ? $toselect : array();
  314. $param = '';
  315. if (!empty($mode)) {
  316. $param .= '&mode='.urlencode($mode);
  317. }
  318. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  319. $param .= '&contextpage='.urlencode($contextpage);
  320. }
  321. if ($limit > 0 && $limit != $conf->liste_limit) {
  322. $param .= '&limit='.((int) $limit);
  323. }
  324. foreach ($search as $key => $val) {
  325. if (is_array($search[$key]) && count($search[$key])) {
  326. foreach ($search[$key] as $skey) {
  327. if ($skey != '') {
  328. $param .= '&search_'.$key.'[]='.urlencode($skey);
  329. }
  330. }
  331. } elseif ($search[$key] != '') {
  332. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  333. }
  334. }
  335. if ($optioncss != '') {
  336. $param .= '&optioncss='.urlencode($optioncss);
  337. }
  338. // Add $param from extra fields
  339. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  340. // Add $param from hooks
  341. $parameters = array();
  342. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  343. $param .= $hookmanager->resPrint;
  344. // List of mass actions available
  345. $arrayofmassactions = array(
  346. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  347. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  348. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  349. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  350. );
  351. if ($permissiontodelete) {
  352. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  353. }
  354. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  355. $arrayofmassactions = array();
  356. }
  357. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  358. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  359. if ($optioncss != '') {
  360. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  361. }
  362. print '<input type="hidden" name="token" value="'.newToken().'">';
  363. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  364. print '<input type="hidden" name="action" value="list">';
  365. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  366. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  367. print '<input type="hidden" name="page" value="'.$page.'">';
  368. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  369. print '<input type="hidden" name="mode" value="'.$mode.'">';
  370. $newcardbutton = '';
  371. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/workstation/workstation_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  372. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  373. // Add code for pre mass action (confirmation or email presend form)
  374. $topicmail = "SendWorkstationRef";
  375. $modelmail = "workstation";
  376. $objecttmp = new Workstation($db);
  377. $trackid = 'xxxx'.$object->id;
  378. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  379. if ($search_all) {
  380. foreach ($fieldstosearchall as $key => $val) {
  381. $fieldstosearchall[$key] = $langs->trans($val);
  382. }
  383. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  384. }
  385. $moreforfilter = '';
  386. /*$moreforfilter.='<div class="divsearchfield">';
  387. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  388. $moreforfilter.= '</div>';*/
  389. $parameters = array();
  390. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  391. if (empty($reshook)) {
  392. $moreforfilter .= $hookmanager->resPrint;
  393. } else {
  394. $moreforfilter = $hookmanager->resPrint;
  395. }
  396. if (!empty($moreforfilter)) {
  397. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  398. print $moreforfilter;
  399. print '</div>';
  400. }
  401. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  402. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  403. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  404. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  405. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  406. // Fields title search
  407. // --------------------------------------------------------------------
  408. print '<tr class="liste_titre">';
  409. // Action column
  410. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  411. print '<td class="liste_titre maxwidthsearch">';
  412. $searchpicto = $form->showFilterButtons('left');
  413. print $searchpicto;
  414. print '</td>';
  415. }
  416. foreach ($object->fields as $key => $val) {
  417. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  418. if ($key == 'status') {
  419. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  420. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  421. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  422. } elseif (in_array($val['type'], array('timestamp'))) {
  423. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  424. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  425. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  426. }
  427. if (!empty($arrayfields['t.'.$key]['checked'])) {
  428. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  429. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  430. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  431. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  432. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  433. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  434. print '<div class="nowrap">';
  435. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  436. print '</div>';
  437. print '<div class="nowrap">';
  438. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  439. print '</div>';
  440. } elseif ($key == 'lang') {
  441. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  442. $formadmin = new FormAdmin($db);
  443. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  444. } else {
  445. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  446. }
  447. print '</td>';
  448. }
  449. }
  450. // usergroups
  451. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  452. print '<td class="liste_titre">';
  453. print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $conf->entity, true);
  454. print '</td>';
  455. }
  456. // resources
  457. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  458. print '<td class="liste_titre">';
  459. print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $conf->entity, true, 0, '', true);
  460. print '</td>';
  461. }
  462. // Extra fields
  463. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  464. // Fields from hook
  465. $parameters = array('arrayfields'=>$arrayfields);
  466. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  467. print $hookmanager->resPrint;
  468. // Action column
  469. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  470. print '<td class="liste_titre maxwidthsearch">';
  471. $searchpicto = $form->showFilterButtons();
  472. print $searchpicto;
  473. print '</td>';
  474. }
  475. print '</tr>'."\n";
  476. $totalarray = array();
  477. $totalarray['nbfield'] = 0;
  478. // Fields title label
  479. // --------------------------------------------------------------------
  480. print '<tr class="liste_titre">';
  481. // Action column
  482. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  483. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  484. $totalarray['nbfield']++;
  485. }
  486. foreach ($object->fields as $key => $val) {
  487. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  488. if ($key == 'status') {
  489. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  490. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  491. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  492. } elseif (in_array($val['type'], array('timestamp'))) {
  493. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  494. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  495. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  496. }
  497. if (!empty($arrayfields['t.'.$key]['checked'])) {
  498. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  499. $totalarray['nbfield']++;
  500. }
  501. }
  502. // usergroups
  503. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  504. print getTitleFieldOfList($arrayfields['wug.fk_usergroup']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
  505. }
  506. // resources
  507. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  508. print getTitleFieldOfList($arrayfields['wr.fk_resource']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
  509. }
  510. // Extra fields
  511. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  512. // Hook fields
  513. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  514. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  515. print $hookmanager->resPrint;
  516. // Action column
  517. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  518. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  519. $totalaray['nbfield']++;
  520. }
  521. print '</tr>'."\n";
  522. // Detect if we need a fetch on each output line
  523. $needToFetchEachLine = 0;
  524. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  525. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  526. if (preg_match('/\$object/', $val)) {
  527. $needToFetchEachLine++; // There is at least one compute field that use $object
  528. }
  529. }
  530. }
  531. // Loop on record
  532. // --------------------------------------------------------------------
  533. $i = 0;
  534. $savnbfield = $totalarray['nbfield'];
  535. $totalarray['nbfield'] = 0;
  536. $imaxinloop = ($limit ? min($num, $limit) : $num);
  537. while ($i < $imaxinloop) {
  538. $obj = $db->fetch_object($resql);
  539. if (empty($obj)) {
  540. break; // Should not happen
  541. }
  542. // Store properties in $object
  543. $object->setVarsFromFetchObj($obj);
  544. $object->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($obj->rowid);
  545. $object->resources = WorkstationResource::getAllResourcesOfWorkstation($obj->rowid);
  546. if ($mode == 'kanban') {
  547. if ($i == 0) {
  548. print '<tr><td colspan="'.$savnbfield.'">';
  549. print '<div class="box-flex-container kanban">';
  550. }
  551. // Output Kanban
  552. print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  553. if ($i == ($imaxinloop - 1)) {
  554. print '</div>';
  555. print '</td></tr>';
  556. }
  557. } else {
  558. // Show here line of result
  559. $j = 0;
  560. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  561. // Action column
  562. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  563. print '<td class="nowrap center">';
  564. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  565. $selected = 0;
  566. if (in_array($object->id, $arrayofselected)) {
  567. $selected = 1;
  568. }
  569. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  570. }
  571. print '</td>';
  572. if (!$i) {
  573. $totalarray['nbfield']++;
  574. }
  575. }
  576. foreach ($object->fields as $key => $val) {
  577. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  578. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  579. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  580. } elseif ($key == 'status') {
  581. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  582. }
  583. if (in_array($val['type'], array('timestamp'))) {
  584. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  585. } elseif ($key == 'ref') {
  586. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  587. }
  588. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  589. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  590. }
  591. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  592. if (!empty($arrayfields['t.'.$key]['checked'])) {
  593. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  594. if ($key == 'status') {
  595. print $object->getLibStatut(5);
  596. } elseif ($key == 'rowid') {
  597. print $object->showOutputField($val, $key, $object->id, '');
  598. } else {
  599. print $object->showOutputField($val, $key, $object->$key, '');
  600. }
  601. print '</td>';
  602. if (!$i) {
  603. $totalarray['nbfield']++;
  604. }
  605. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  606. if (!$i) {
  607. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  608. }
  609. if (!isset($totalarray['val'])) {
  610. $totalarray['val'] = array();
  611. }
  612. if (!isset($totalarray['val']['t.'.$key])) {
  613. $totalarray['val']['t.'.$key] = 0;
  614. }
  615. $totalarray['val']['t.'.$key] += $object->$key;
  616. }
  617. }
  618. }
  619. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  620. $toprint = array();
  621. $cssforli = '';
  622. if (count($object->usergroups) >= 4) {
  623. $cssforli = 'tdoverflowmax60';
  624. } elseif (count($object->usergroups) >= 2) {
  625. $cssforli = 'tdoverflowmax80';
  626. }
  627. foreach ($object->usergroups as $id_group) {
  628. $g = new UserGroup($db);
  629. $g->fetch($id_group);
  630. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
  631. }
  632. print '<td>';
  633. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  634. print '</td>';
  635. }
  636. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  637. $toprint = array();
  638. $cssforli = '';
  639. if (count($object->resources) >= 4) {
  640. $cssforli = 'tdoverflowmax60';
  641. } elseif (count($object->resources) >= 2) {
  642. $cssforli = 'tdoverflowmax80';
  643. }
  644. foreach ($object->resources as $id_resource) {
  645. $r = new Dolresource($db);
  646. $r->fetch($id_resource);
  647. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
  648. }
  649. print '<td>';
  650. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  651. print '</td>';
  652. }
  653. // Extra fields
  654. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  655. // Fields from hook
  656. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  657. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  658. print $hookmanager->resPrint;
  659. // Action column
  660. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  661. print '<td class="nowrap center">';
  662. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  663. $selected = 0;
  664. if (in_array($object->id, $arrayofselected)) {
  665. $selected = 1;
  666. }
  667. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  668. }
  669. print '</td>';
  670. if (!$i) {
  671. $totalarray['nbfield']++;
  672. }
  673. }
  674. print '</tr>'."\n";
  675. }
  676. $i++;
  677. }
  678. // Show total line
  679. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  680. // If no record found
  681. if ($num == 0) {
  682. $colspan = 1;
  683. foreach ($arrayfields as $key => $val) {
  684. if (!empty($val['checked'])) {
  685. $colspan++;
  686. }
  687. }
  688. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  689. }
  690. $db->free($resql);
  691. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  692. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  693. print $hookmanager->resPrint;
  694. print '</table>'."\n";
  695. print '</div>'."\n";
  696. print '</form>'."\n";
  697. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  698. $hidegeneratedfilelistifempty = 1;
  699. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  700. $hidegeneratedfilelistifempty = 0;
  701. }
  702. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  703. $formfile = new FormFile($db);
  704. // Show list of available documents
  705. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  706. $urlsource .= str_replace('&amp;', '&', $param);
  707. $filedir = $diroutputmassaction;
  708. $genallowed = $permissiontoread;
  709. $delallowed = $permissiontoadd;
  710. print $formfile->showdocuments('massfilesarea_workstation', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  711. }
  712. // End of page
  713. llxFooter();
  714. $db->close();