workstation_list.php 36 KB

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