availabilities_list.php 34 KB

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