myobject_list.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/myobject_list.php
  20. * \ingroup mymodule
  21. * \brief List page for myobject
  22. */
  23. // General defined Options
  24. //if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  25. //if (! defined('MAIN_AUTHENTICATION_MODE')) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
  26. //if (! defined('MAIN_LANG_DEFAULT')) define('MAIN_LANG_DEFAULT', 'auto'); // Force LANG (language) to a particular value
  27. //if (! defined('MAIN_SECURITY_FORCECSP')) define('MAIN_SECURITY_FORCECSP', 'none'); // Disable all Content Security Policies
  28. //if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
  29. //if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  30. //if (! defined('NOLOGIN')) define('NOLOGIN', '1'); // Do not use login - if this page is public (can be called outside logged session). This includes the NOIPCHECK too.
  31. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  32. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
  33. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // Do not load html.form.class.php
  34. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // Do not load and show top and left menu
  35. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
  36. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
  37. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
  38. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
  39. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
  40. //if (! defined('NOSESSION')) define('NOSESSION', '1'); // On CLI mode, no need to use web sessions
  41. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
  42. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  43. // Load Dolibarr environment
  44. $res = 0;
  45. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  46. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  47. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  48. }
  49. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  50. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  51. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  52. $i--;
  53. $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 module libraries
  78. require_once __DIR__.'/class/myobject.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("mymodule@mymodule", "other"));
  83. // Get parameters
  84. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
  85. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  86. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  87. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  88. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  89. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  90. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  91. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  92. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  93. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  94. $id = GETPOST('id', 'int');
  95. $ref = GETPOST('ref', 'alpha');
  96. // Load variable for pagination
  97. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  98. $sortfield = GETPOST('sortfield', 'aZ09comma');
  99. $sortorder = GETPOST('sortorder', 'aZ09comma');
  100. $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
  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 MyObject($db);
  110. $extrafields = new ExtraFields($db);
  111. $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  112. $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
  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 = trim(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. $fieldstosearchall = array();
  138. // List of fields to search into when doing a "search in all"
  139. // foreach ($object->fields as $key => $val) {
  140. // if (!empty($val['searchall'])) {
  141. // $fieldstosearchall['t.'.$key] = $val['label'];
  142. // }
  143. // }
  144. // $parameters = array('fieldstosearchall'=>$fieldstosearchall);
  145. // $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  146. // if ($reshook > 0) {
  147. // $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
  148. // } elseif ($reshook == 0) {
  149. // $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
  150. // }
  151. // Definition of array of fields for columns
  152. $arrayfields = array();
  153. foreach ($object->fields as $key => $val) {
  154. // If $val['visible']==0, then we never show the field
  155. if (!empty($val['visible'])) {
  156. $visible = (int) dol_eval($val['visible'], 1);
  157. $arrayfields['t.'.$key] = array(
  158. 'label'=>$val['label'],
  159. 'checked'=>(($visible < 0) ? 0 : 1),
  160. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  161. 'position'=>$val['position'],
  162. 'help'=> isset($val['help']) ? $val['help'] : ''
  163. );
  164. }
  165. }
  166. // Extra fields
  167. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  168. $object->fields = dol_sort_array($object->fields, 'position');
  169. //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
  170. $arrayfields = dol_sort_array($arrayfields, 'position');
  171. // There is several ways to check permission.
  172. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  173. $enablepermissioncheck = 0;
  174. if ($enablepermissioncheck) {
  175. $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read');
  176. $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write');
  177. $permissiontodelete = $user->hasRight('mymodule', 'myobject', 'delete');
  178. } else {
  179. $permissiontoread = 1;
  180. $permissiontoadd = 1;
  181. $permissiontodelete = 1;
  182. }
  183. // Security check (enable the most restrictive one)
  184. if ($user->socid > 0) {
  185. accessforbidden();
  186. }
  187. //if ($user->socid > 0) accessforbidden();
  188. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  189. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  190. //restrictedArea($user, $object->module, 0, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
  191. if (!isModEnabled("mymodule")) {
  192. accessforbidden('Module mymodule not enabled');
  193. }
  194. if (!$permissiontoread) {
  195. accessforbidden();
  196. }
  197. /*
  198. * Actions
  199. */
  200. if (GETPOST('cancel', 'alpha')) {
  201. $action = 'list';
  202. $massaction = '';
  203. }
  204. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  205. $massaction = '';
  206. }
  207. $parameters = array();
  208. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  209. if ($reshook < 0) {
  210. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  211. }
  212. if (empty($reshook)) {
  213. // Selection of new fields
  214. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  215. // Purge search criteria
  216. 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
  217. foreach ($object->fields as $key => $val) {
  218. $search[$key] = '';
  219. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  220. $search[$key.'_dtstart'] = '';
  221. $search[$key.'_dtend'] = '';
  222. }
  223. }
  224. $toselect = array();
  225. $search_array_options = array();
  226. }
  227. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  228. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  229. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  230. }
  231. // Mass actions
  232. $objectclass = 'MyObject';
  233. $objectlabel = 'MyObject';
  234. $uploaddir = $conf->mymodule->dir_output;
  235. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  236. // You can add more action here
  237. // if ($action == 'xxx' && $permissiontoxxx) ...
  238. }
  239. /*
  240. * View
  241. */
  242. $form = new Form($db);
  243. $now = dol_now();
  244. $title = $langs->trans("MyObjects");
  245. //$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  246. $help_url = '';
  247. $morejs = array();
  248. $morecss = array();
  249. // Build and execute select
  250. // --------------------------------------------------------------------
  251. $sql = 'SELECT ';
  252. $sql .= $object->getFieldList('t');
  253. // Add fields from extrafields
  254. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  255. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  256. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  257. }
  258. }
  259. // Add fields from hooks
  260. $parameters = array();
  261. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  262. $sql .= $hookmanager->resPrint;
  263. $sql = preg_replace('/,\s*$/', '', $sql);
  264. $sqlfields = $sql; // $sql fields to remove for count total
  265. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  266. //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
  267. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  268. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  269. }
  270. // Add table from hooks
  271. $parameters = array();
  272. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  273. $sql .= $hookmanager->resPrint;
  274. if ($object->ismultientitymanaged == 1) {
  275. $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOST('search_current_entity', 'int') ? 0 : 1)).")";
  276. } else {
  277. $sql .= " WHERE 1 = 1";
  278. }
  279. foreach ($search as $key => $val) {
  280. if (array_key_exists($key, $object->fields)) {
  281. if ($key == 'status' && $search[$key] == -1) {
  282. continue;
  283. }
  284. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  285. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  286. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  287. $search[$key] = '';
  288. }
  289. $mode_search = 2;
  290. }
  291. if ($search[$key] != '') {
  292. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  293. }
  294. } else {
  295. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  296. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  297. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  298. if (preg_match('/_dtstart$/', $key)) {
  299. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  300. }
  301. if (preg_match('/_dtend$/', $key)) {
  302. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  303. }
  304. }
  305. }
  306. }
  307. }
  308. if ($search_all) {
  309. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  310. }
  311. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  312. // Add where from extra fields
  313. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  314. // Add where from hooks
  315. $parameters = array();
  316. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  317. $sql .= $hookmanager->resPrint;
  318. /* If a group by is required
  319. $sql .= " GROUP BY ";
  320. foreach($object->fields as $key => $val) {
  321. $sql .= "t.".$db->escape($key).", ";
  322. }
  323. // Add fields from extrafields
  324. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  325. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  326. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  327. }
  328. }
  329. // Add groupby from hooks
  330. $parameters = array();
  331. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  332. $sql .= $hookmanager->resPrint;
  333. $sql = preg_replace('/,\s*$/', '', $sql);
  334. */
  335. // Add HAVING from hooks
  336. /*
  337. $parameters = array();
  338. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  339. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  340. */
  341. // Count total nb of records
  342. $nbtotalofrecords = '';
  343. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  344. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  345. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  346. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  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 resultset is smaller than the paging size (filtering), 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 && getDolGlobalInt('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('/mymodule/myobject_card.php', 1).'?id='.((int) $id));
  376. exit;
  377. }
  378. // Output page
  379. // --------------------------------------------------------------------
  380. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-mymodule page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
  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. $arrayofselected = is_array($toselect) ? $toselect : array();
  396. $param = '';
  397. if (!empty($mode)) {
  398. $param .= '&mode='.urlencode($mode);
  399. }
  400. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  401. $param .= '&contextpage='.urlencode($contextpage);
  402. }
  403. if ($limit > 0 && $limit != $conf->liste_limit) {
  404. $param .= '&limit='.((int) $limit);
  405. }
  406. if ($optioncss != '') {
  407. $param .= '&optioncss='.urlencode($optioncss);
  408. }
  409. foreach ($search as $key => $val) {
  410. if (is_array($search[$key])) {
  411. foreach ($search[$key] as $skey) {
  412. if ($skey != '') {
  413. $param .= '&search_'.$key.'[]='.urlencode($skey);
  414. }
  415. }
  416. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  417. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  418. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  419. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  420. } elseif ($search[$key] != '') {
  421. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  422. }
  423. }
  424. // Add $param from extra fields
  425. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  426. // Add $param from hooks
  427. $parameters = array();
  428. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  429. $param .= $hookmanager->resPrint;
  430. // List of mass actions available
  431. $arrayofmassactions = array(
  432. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  433. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  434. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  435. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  436. );
  437. if (!empty($permissiontodelete)) {
  438. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  439. }
  440. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  441. $arrayofmassactions = array();
  442. }
  443. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  444. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  445. if ($optioncss != '') {
  446. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  447. }
  448. print '<input type="hidden" name="token" value="'.newToken().'">';
  449. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  450. print '<input type="hidden" name="action" value="list">';
  451. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  452. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  453. print '<input type="hidden" name="page" value="'.$page.'">';
  454. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  455. print '<input type="hidden" name="page_y" value="">';
  456. print '<input type="hidden" name="mode" value="'.$mode.'">';
  457. $newcardbutton = '';
  458. $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'));
  459. $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'));
  460. $newcardbutton .= dolGetButtonTitleSeparator();
  461. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  462. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  463. // Add code for pre mass action (confirmation or email presend form)
  464. $topicmail = "SendMyObjectRef";
  465. $modelmail = "myobject";
  466. $objecttmp = new MyObject($db);
  467. $trackid = 'xxxx'.$object->id;
  468. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  469. if ($search_all) {
  470. $setupstring = '';
  471. foreach ($fieldstosearchall as $key => $val) {
  472. $fieldstosearchall[$key] = $langs->trans($val);
  473. $setupstring .= $key."=".$val.";";
  474. }
  475. print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  476. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  477. }
  478. $moreforfilter = '';
  479. /*$moreforfilter.='<div class="divsearchfield">';
  480. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  481. $moreforfilter.= '</div>';*/
  482. $parameters = array();
  483. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  484. if (empty($reshook)) {
  485. $moreforfilter .= $hookmanager->resPrint;
  486. } else {
  487. $moreforfilter = $hookmanager->resPrint;
  488. }
  489. if (!empty($moreforfilter)) {
  490. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  491. print $moreforfilter;
  492. $parameters = array();
  493. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  494. print $hookmanager->resPrint;
  495. print '</div>';
  496. }
  497. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  498. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  499. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  500. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  501. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  502. // Fields title search
  503. // --------------------------------------------------------------------
  504. print '<tr class="liste_titre_filter">';
  505. // Action column
  506. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  507. print '<td class="liste_titre center maxwidthsearch">';
  508. $searchpicto = $form->showFilterButtons('left');
  509. print $searchpicto;
  510. print '</td>';
  511. }
  512. foreach ($object->fields as $key => $val) {
  513. $searchkey = empty($search[$key]) ? '' : $search[$key];
  514. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  515. if ($key == 'status') {
  516. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  517. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  518. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  519. } elseif (in_array($val['type'], array('timestamp'))) {
  520. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  521. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  522. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  523. }
  524. if (!empty($arrayfields['t.'.$key]['checked'])) {
  525. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
  526. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  527. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
  528. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  529. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  530. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  531. print '<div class="nowrap">';
  532. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  533. print '</div>';
  534. print '<div class="nowrap">';
  535. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  536. print '</div>';
  537. } elseif ($key == 'lang') {
  538. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  539. $formadmin = new FormAdmin($db);
  540. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  541. } else {
  542. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  543. }
  544. print '</td>';
  545. }
  546. }
  547. // Extra fields
  548. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  549. // Fields from hook
  550. $parameters = array('arrayfields'=>$arrayfields);
  551. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  552. print $hookmanager->resPrint;
  553. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  554. print '<td class="liste_titre"></td>';
  555. }*/
  556. // Action column
  557. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  558. print '<td class="liste_titre center maxwidthsearch">';
  559. $searchpicto = $form->showFilterButtons();
  560. print $searchpicto;
  561. print '</td>';
  562. }
  563. print '</tr>'."\n";
  564. $totalarray = array();
  565. $totalarray['nbfield'] = 0;
  566. // Fields title label
  567. // --------------------------------------------------------------------
  568. print '<tr class="liste_titre">';
  569. // Action column
  570. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  571. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  572. $totalarray['nbfield']++;
  573. }
  574. foreach ($object->fields as $key => $val) {
  575. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  576. if ($key == 'status') {
  577. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  578. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  579. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  580. } elseif (in_array($val['type'], array('timestamp'))) {
  581. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  582. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  583. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  584. }
  585. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  586. if (!empty($arrayfields['t.'.$key]['checked'])) {
  587. 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";
  588. $totalarray['nbfield']++;
  589. }
  590. }
  591. // Extra fields
  592. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  593. // Hook fields
  594. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  595. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  596. print $hookmanager->resPrint;
  597. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  598. print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
  599. $totalarray['nbfield']++;
  600. }*/
  601. // Action column
  602. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  603. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  604. $totalarray['nbfield']++;
  605. }
  606. print '</tr>'."\n";
  607. // Detect if we need a fetch on each output line
  608. $needToFetchEachLine = 0;
  609. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  610. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  611. if (!is_null($val) && preg_match('/\$object/', $val)) {
  612. $needToFetchEachLine++; // There is at least one compute field that use $object
  613. }
  614. }
  615. }
  616. // Loop on record
  617. // --------------------------------------------------------------------
  618. $i = 0;
  619. $savnbfield = $totalarray['nbfield'];
  620. $totalarray = array();
  621. $totalarray['nbfield'] = 0;
  622. $imaxinloop = ($limit ? min($num, $limit) : $num);
  623. while ($i < $imaxinloop) {
  624. $obj = $db->fetch_object($resql);
  625. if (empty($obj)) {
  626. break; // Should not happen
  627. }
  628. // Store properties in $object
  629. $object->setVarsFromFetchObj($obj);
  630. /*
  631. $object->thirdparty = null;
  632. if ($obj->fk_soc > 0) {
  633. if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
  634. $companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
  635. } else {
  636. $companyobj = new Societe($db);
  637. $companyobj->fetch($obj->fk_soc);
  638. $conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
  639. }
  640. $object->thirdparty = $companyobj;
  641. }*/
  642. if ($mode == 'kanban') {
  643. if ($i == 0) {
  644. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  645. print '<div class="box-flex-container kanban">';
  646. }
  647. // Output Kanban
  648. $selected = -1;
  649. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  650. $selected = 0;
  651. if (in_array($object->id, $arrayofselected)) {
  652. $selected = 1;
  653. }
  654. }
  655. //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
  656. print $object->getKanbanView('', array('selected' => $selected));
  657. if ($i == ($imaxinloop - 1)) {
  658. print '</div>';
  659. print '</td></tr>';
  660. }
  661. } else {
  662. // Show line of result
  663. $j = 0;
  664. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  665. // Action column
  666. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  667. print '<td class="nowrap center">';
  668. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  669. $selected = 0;
  670. if (in_array($object->id, $arrayofselected)) {
  671. $selected = 1;
  672. }
  673. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  674. }
  675. print '</td>';
  676. if (!$i) {
  677. $totalarray['nbfield']++;
  678. }
  679. }
  680. foreach ($object->fields as $key => $val) {
  681. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  682. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  683. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  684. } elseif ($key == 'status') {
  685. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  686. }
  687. if (in_array($val['type'], array('timestamp'))) {
  688. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  689. } elseif ($key == 'ref') {
  690. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  691. }
  692. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
  693. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  694. }
  695. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  696. if (!empty($arrayfields['t.'.$key]['checked'])) {
  697. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  698. if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
  699. print ' title="'.dol_escape_htmltag($object->$key).'"';
  700. }
  701. print '>';
  702. if ($key == 'status') {
  703. print $object->getLibStatut(5);
  704. } elseif ($key == 'rowid') {
  705. print $object->showOutputField($val, $key, $object->id, '');
  706. } else {
  707. print $object->showOutputField($val, $key, $object->$key, '');
  708. }
  709. print '</td>';
  710. if (!$i) {
  711. $totalarray['nbfield']++;
  712. }
  713. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  714. if (!$i) {
  715. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  716. }
  717. if (!isset($totalarray['val'])) {
  718. $totalarray['val'] = array();
  719. }
  720. if (!isset($totalarray['val']['t.'.$key])) {
  721. $totalarray['val']['t.'.$key] = 0;
  722. }
  723. $totalarray['val']['t.'.$key] += $object->$key;
  724. }
  725. }
  726. }
  727. // Extra fields
  728. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  729. // Fields from hook
  730. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  731. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  732. print $hookmanager->resPrint;
  733. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  734. print '<td class="right">'.$obj->anotherfield.'</td>';
  735. }*/
  736. // Action column
  737. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  738. print '<td class="nowrap center">';
  739. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  740. $selected = 0;
  741. if (in_array($object->id, $arrayofselected)) {
  742. $selected = 1;
  743. }
  744. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  745. }
  746. print '</td>';
  747. if (!$i) {
  748. $totalarray['nbfield']++;
  749. }
  750. }
  751. print '</tr>'."\n";
  752. }
  753. $i++;
  754. }
  755. // Show total line
  756. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  757. // If no record found
  758. if ($num == 0) {
  759. $colspan = 1;
  760. foreach ($arrayfields as $key => $val) {
  761. if (!empty($val['checked'])) {
  762. $colspan++;
  763. }
  764. }
  765. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  766. }
  767. $db->free($resql);
  768. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  769. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  770. print $hookmanager->resPrint;
  771. print '</table>'."\n";
  772. print '</div>'."\n";
  773. print '</form>'."\n";
  774. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  775. $hidegeneratedfilelistifempty = 1;
  776. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  777. $hidegeneratedfilelistifempty = 0;
  778. }
  779. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  780. $formfile = new FormFile($db);
  781. // Show list of available documents
  782. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  783. $urlsource .= str_replace('&amp;', '&', $param);
  784. $filedir = $diroutputmassaction;
  785. $genallowed = $permissiontoread;
  786. $delallowed = $permissiontoadd;
  787. print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  788. }
  789. // End of page
  790. llxFooter();
  791. $db->close();