hotel_list.php 31 KB

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