availabilities_list.php 33 KB

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