calendar_list.php 37 KB

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