eventproduct_list.php 39 KB

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