workstation_list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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('workstation', '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('ListOf', $langs->transnoentitiesnoconv("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 .= preg_replace('/^,/', '', $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 (empty($conf->global->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='.urlencode($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); // 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. foreach ($object->fields as $key => $val) {
  410. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  411. if ($key == 'status') {
  412. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  413. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  414. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  415. } elseif (in_array($val['type'], array('timestamp'))) {
  416. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  417. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  418. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  419. }
  420. if (!empty($arrayfields['t.'.$key]['checked'])) {
  421. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  422. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  423. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  424. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  425. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  426. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  427. print '<div class="nowrap">';
  428. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  429. print '</div>';
  430. print '<div class="nowrap">';
  431. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  432. print '</div>';
  433. } elseif ($key == 'lang') {
  434. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  435. $formadmin = new FormAdmin($db);
  436. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  437. } else {
  438. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  439. }
  440. print '</td>';
  441. }
  442. }
  443. // usergroups
  444. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  445. print '<td class="liste_titre">';
  446. print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $conf->entity, true);
  447. print '</td>';
  448. }
  449. // resources
  450. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  451. print '<td class="liste_titre">';
  452. print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $conf->entity, true, 0, '', true);
  453. print '</td>';
  454. }
  455. // Extra fields
  456. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  457. // Fields from hook
  458. $parameters = array('arrayfields'=>$arrayfields);
  459. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  460. print $hookmanager->resPrint;
  461. // Action column
  462. print '<td class="liste_titre maxwidthsearch">';
  463. $searchpicto = $form->showFilterButtons();
  464. print $searchpicto;
  465. print '</td>';
  466. print '</tr>'."\n";
  467. $totalarray = array();
  468. $totalarray['nbfield'] = 0;
  469. // Fields title label
  470. // --------------------------------------------------------------------
  471. print '<tr class="liste_titre">';
  472. foreach ($object->fields as $key => $val) {
  473. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  474. if ($key == 'status') {
  475. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  476. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  477. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  478. } elseif (in_array($val['type'], array('timestamp'))) {
  479. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  480. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  481. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  482. }
  483. if (!empty($arrayfields['t.'.$key]['checked'])) {
  484. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  485. $totalarray['nbfield']++;
  486. }
  487. }
  488. // usergroups
  489. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  490. print getTitleFieldOfList($arrayfields['wug.fk_usergroup']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
  491. }
  492. // resources
  493. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  494. print getTitleFieldOfList($arrayfields['wr.fk_resource']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
  495. }
  496. // Extra fields
  497. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  498. // Hook fields
  499. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  500. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  501. print $hookmanager->resPrint;
  502. // Action column
  503. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  504. $totalarray['nbfield']++;
  505. print '</tr>'."\n";
  506. // Detect if we need a fetch on each output line
  507. $needToFetchEachLine = 0;
  508. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  509. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  510. if (preg_match('/\$object/', $val)) {
  511. $needToFetchEachLine++; // There is at least one compute field that use $object
  512. }
  513. }
  514. }
  515. // Loop on record
  516. // --------------------------------------------------------------------
  517. $i = 0;
  518. $savnbfield = $totalarray['nbfield'];
  519. $totalarray['nbfield'] = 0;
  520. $imaxinloop = ($limit ? min($num, $limit) : $num);
  521. while ($i < $imaxinloop) {
  522. $obj = $db->fetch_object($resql);
  523. if (empty($obj)) {
  524. break; // Should not happen
  525. }
  526. // Store properties in $object
  527. $object->setVarsFromFetchObj($obj);
  528. $object->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($obj->rowid);
  529. $object->resources = WorkstationResource::getAllResourcesOfWorkstation($obj->rowid);
  530. if ($mode == 'kanban') {
  531. if ($i == 0) {
  532. print '<tr><td colspan="'.$savnbfield.'">';
  533. print '<div class="box-flex-container">';
  534. }
  535. // Output Kanban
  536. print $object->getKanbanView('');
  537. if ($i == ($imaxinloop - 1)) {
  538. print '</div>';
  539. print '</td></tr>';
  540. }
  541. } else {
  542. // Show here line of result
  543. $j = 0;
  544. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  545. foreach ($object->fields as $key => $val) {
  546. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  547. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  548. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  549. } elseif ($key == 'status') {
  550. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  551. }
  552. if (in_array($val['type'], array('timestamp'))) {
  553. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  554. } elseif ($key == 'ref') {
  555. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  556. }
  557. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  558. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  559. }
  560. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  561. if (!empty($arrayfields['t.'.$key]['checked'])) {
  562. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  563. if ($key == 'status') {
  564. print $object->getLibStatut(5);
  565. } elseif ($key == 'rowid') {
  566. print $object->showOutputField($val, $key, $object->id, '');
  567. } else {
  568. print $object->showOutputField($val, $key, $object->$key, '');
  569. }
  570. print '</td>';
  571. if (!$i) {
  572. $totalarray['nbfield']++;
  573. }
  574. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  575. if (!$i) {
  576. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  577. }
  578. if (!isset($totalarray['val'])) {
  579. $totalarray['val'] = array();
  580. }
  581. if (!isset($totalarray['val']['t.'.$key])) {
  582. $totalarray['val']['t.'.$key] = 0;
  583. }
  584. $totalarray['val']['t.'.$key] += $object->$key;
  585. }
  586. }
  587. }
  588. if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
  589. $toprint = array();
  590. $cssforli = '';
  591. if (count($object->usergroups) >= 4) {
  592. $cssforli = 'tdoverflowmax60';
  593. } elseif (count($object->usergroups) >= 2) {
  594. $cssforli = 'tdoverflowmax80';
  595. }
  596. foreach ($object->usergroups as $id_group) {
  597. $g = new UserGroup($db);
  598. $g->fetch($id_group);
  599. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
  600. }
  601. print '<td>';
  602. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  603. print '</td>';
  604. }
  605. if (!empty($arrayfields['wr.fk_resource']['checked'])) {
  606. $toprint = array();
  607. $cssforli = '';
  608. if (count($object->resources) >= 4) {
  609. $cssforli = 'tdoverflowmax60';
  610. } elseif (count($object->resources) >= 2) {
  611. $cssforli = 'tdoverflowmax80';
  612. }
  613. foreach ($object->resources as $id_resource) {
  614. $r = new Dolresource($db);
  615. $r->fetch($id_resource);
  616. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
  617. }
  618. print '<td>';
  619. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  620. print '</td>';
  621. }
  622. // Extra fields
  623. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  624. // Fields from hook
  625. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  626. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  627. print $hookmanager->resPrint;
  628. // Action column
  629. print '<td class="nowrap center">';
  630. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  631. $selected = 0;
  632. if (in_array($object->id, $arrayofselected)) {
  633. $selected = 1;
  634. }
  635. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  636. }
  637. print '</td>';
  638. if (!$i) {
  639. $totalarray['nbfield']++;
  640. }
  641. print '</tr>'."\n";
  642. }
  643. $i++;
  644. }
  645. // Show total line
  646. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  647. // If no record found
  648. if ($num == 0) {
  649. $colspan = 1;
  650. foreach ($arrayfields as $key => $val) {
  651. if (!empty($val['checked'])) {
  652. $colspan++;
  653. }
  654. }
  655. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  656. }
  657. $db->free($resql);
  658. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  659. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  660. print $hookmanager->resPrint;
  661. print '</table>'."\n";
  662. print '</div>'."\n";
  663. print '</form>'."\n";
  664. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  665. $hidegeneratedfilelistifempty = 1;
  666. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  667. $hidegeneratedfilelistifempty = 0;
  668. }
  669. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  670. $formfile = new FormFile($db);
  671. // Show list of available documents
  672. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  673. $urlsource .= str_replace('&amp;', '&', $param);
  674. $filedir = $diroutputmassaction;
  675. $genallowed = $permissiontoread;
  676. $delallowed = $permissiontoadd;
  677. print $formfile->showdocuments('massfilesarea_workstation', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  678. }
  679. // End of page
  680. llxFooter();
  681. $db->close();