myobject_list.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. //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('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  33. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  34. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  35. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  36. //if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
  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("XFRAMEOPTIONS_ALLOWALL")) define('XFRAMEOPTIONS_ALLOWALL', '1'); // Do not add the HTTP header 'X-Frame-Options: SAMEORIGIN' but 'X-Frame-Options: ALLOWALL'
  41. // Load Dolibarr environment
  42. $res = 0;
  43. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  44. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  45. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  46. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  47. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  48. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  49. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  50. // Try main.inc.php using relative path
  51. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  52. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  53. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  54. if (!$res) die("Include of main fails");
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  56. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  57. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  58. // load mymodule libraries
  59. require_once __DIR__.'/class/myobject.class.php';
  60. // for other modules
  61. //dol_include_once('/othermodule/class/otherobject.class.php');
  62. // Load translation files required by the page
  63. $langs->loadLangs(array("mymodule@mymodule", "other"));
  64. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  65. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  66. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  67. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  68. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  69. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  70. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectlist'; // To manage different context of search
  71. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  72. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  73. $id = GETPOST('id', 'int');
  74. // Load variable for pagination
  75. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  76. $sortfield = GETPOST('sortfield', 'alpha');
  77. $sortorder = GETPOST('sortorder', 'alpha');
  78. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  79. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
  80. $offset = $limit * $page;
  81. $pageprev = $page - 1;
  82. $pagenext = $page + 1;
  83. // Initialize technical objects
  84. $object = new MyObject($db);
  85. $extrafields = new ExtraFields($db);
  86. $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  87. $hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array
  88. // Fetch optionals attributes and labels
  89. $extrafields->fetch_name_optionals_label($object->table_element);
  90. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  91. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  92. // Default sort order (if not yet defined by previous GETPOST)
  93. if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  94. if (!$sortorder) $sortorder = "ASC";
  95. // Initialize array of search criterias
  96. $search_all = trim(GETPOST("search_all", 'alpha'));
  97. $search = array();
  98. foreach ($object->fields as $key => $val)
  99. {
  100. if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
  101. }
  102. // List of fields to search into when doing a "search in all"
  103. $fieldstosearchall = array();
  104. foreach ($object->fields as $key => $val)
  105. {
  106. if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  107. }
  108. // Definition of fields for list
  109. $arrayfields = array();
  110. foreach ($object->fields as $key => $val)
  111. {
  112. // If $val['visible']==0, then we never show the field
  113. if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']);
  114. }
  115. // Extra fields
  116. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
  117. {
  118. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
  119. {
  120. if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
  121. $arrayfields["ef.".$key] = array(
  122. 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
  123. 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
  124. 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
  125. 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])
  126. );
  127. }
  128. }
  129. }
  130. $object->fields = dol_sort_array($object->fields, 'position');
  131. $arrayfields = dol_sort_array($arrayfields, 'position');
  132. $permissiontoread = $user->rights->mymodule->myobject->read;
  133. $permissiontoadd = $user->rights->mymodule->myobject->write;
  134. $permissiontodelete = $user->rights->mymodule->myobject->delete;
  135. // Security check
  136. if (empty($conf->mymodule->enabled)) accessforbidden('Module not enabled');
  137. $socid = 0;
  138. if ($user->socid > 0) // Protection if external user
  139. {
  140. //$socid = $user->socid;
  141. accessforbidden();
  142. }
  143. //$result = restrictedArea($user, 'mymodule', $id, '');
  144. //if (!$permissiontoread) accessforbidden();
  145. /*
  146. * Actions
  147. */
  148. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  149. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
  150. $parameters = array();
  151. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  152. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  153. if (empty($reshook))
  154. {
  155. // Selection of new fields
  156. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  157. // Purge search criteria
  158. 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
  159. {
  160. foreach ($object->fields as $key => $val)
  161. {
  162. $search[$key] = '';
  163. }
  164. $toselect = '';
  165. $search_array_options = array();
  166. }
  167. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  168. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
  169. {
  170. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  171. }
  172. // Mass actions
  173. $objectclass = 'MyObject';
  174. $objectlabel = 'MyObject';
  175. $uploaddir = $conf->mymodule->dir_output;
  176. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  177. }
  178. /*
  179. * View
  180. */
  181. $form = new Form($db);
  182. $now = dol_now();
  183. //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  184. $help_url = '';
  185. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects"));
  186. // Build and execute select
  187. // --------------------------------------------------------------------
  188. $sql = 'SELECT ';
  189. foreach ($object->fields as $key => $val)
  190. {
  191. $sql .= 't.'.$key.', ';
  192. }
  193. // Add fields from extrafields
  194. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  195. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
  196. }
  197. // Add fields from hooks
  198. $parameters = array();
  199. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  200. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  201. $sql = preg_replace('/,\s*$/', '', $sql);
  202. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  203. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  204. if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  205. else $sql .= " WHERE 1 = 1";
  206. foreach ($search as $key => $val)
  207. {
  208. if ($key == 'status' && $search[$key] == -1) continue;
  209. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  210. if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
  211. if ($search[$key] == '-1') $search[$key] = '';
  212. $mode_search = 2;
  213. }
  214. if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  215. }
  216. if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  217. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  218. // Add where from extra fields
  219. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  220. // Add where from hooks
  221. $parameters = array();
  222. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  223. $sql .= $hookmanager->resPrint;
  224. /* If a group by is required
  225. $sql.= " GROUP BY ";
  226. foreach($object->fields as $key => $val)
  227. {
  228. $sql.='t.'.$key.', ';
  229. }
  230. // Add fields from extrafields
  231. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  232. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  233. }
  234. // Add where from hooks
  235. $parameters=array();
  236. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  237. $sql.=$hookmanager->resPrint;
  238. $sql=preg_replace('/,\s*$/','', $sql);
  239. */
  240. $sql .= $db->order($sortfield, $sortorder);
  241. // Count total nb of records
  242. $nbtotalofrecords = '';
  243. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  244. {
  245. $resql = $db->query($sql);
  246. $nbtotalofrecords = $db->num_rows($resql);
  247. if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
  248. {
  249. $page = 0;
  250. $offset = 0;
  251. }
  252. }
  253. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  254. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit)))
  255. {
  256. $num = $nbtotalofrecords;
  257. }
  258. else
  259. {
  260. if ($limit) $sql .= $db->plimit($limit + 1, $offset);
  261. $resql = $db->query($sql);
  262. if (!$resql)
  263. {
  264. dol_print_error($db);
  265. exit;
  266. }
  267. $num = $db->num_rows($resql);
  268. }
  269. // Direct jump if only one record found
  270. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page)
  271. {
  272. $obj = $db->fetch_object($resql);
  273. $id = $obj->rowid;
  274. header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
  275. exit;
  276. }
  277. // Output page
  278. // --------------------------------------------------------------------
  279. llxHeader('', $title, $help_url);
  280. // Example : Adding jquery code
  281. print '<script type="text/javascript" language="javascript">
  282. jQuery(document).ready(function() {
  283. function init_myfunc()
  284. {
  285. jQuery("#myid").removeAttr(\'disabled\');
  286. jQuery("#myid").attr(\'disabled\',\'disabled\');
  287. }
  288. init_myfunc();
  289. jQuery("#mybutton").click(function() {
  290. init_myfunc();
  291. });
  292. });
  293. </script>';
  294. $arrayofselected = is_array($toselect) ? $toselect : array();
  295. $param = '';
  296. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  297. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  298. foreach ($search as $key => $val)
  299. {
  300. if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
  301. else $param .= '&search_'.$key.'='.urlencode($search[$key]);
  302. }
  303. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  304. // Add $param from extra fields
  305. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  306. // List of mass actions available
  307. $arrayofmassactions = array(
  308. //'validate'=>$langs->trans("Validate"),
  309. //'generate_doc'=>$langs->trans("ReGeneratePDF"),
  310. //'builddoc'=>$langs->trans("PDFMerge"),
  311. //'presend'=>$langs->trans("SendByMail"),
  312. );
  313. if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  314. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  315. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  316. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  317. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  318. print '<input type="hidden" name="token" value="'.newToken().'">';
  319. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  320. print '<input type="hidden" name="action" value="list">';
  321. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  322. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  323. //print '<input type="hidden" name="page" value="'.$page.'">';
  324. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  325. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  326. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit, 0, 0, 1);
  327. // Add code for pre mass action (confirmation or email presend form)
  328. $topicmail = "SendMyObjectRef";
  329. $modelmail = "myobject";
  330. $objecttmp = new MyObject($db);
  331. $trackid = 'xxxx'.$object->id;
  332. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  333. if ($search_all)
  334. {
  335. foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
  336. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  337. }
  338. $moreforfilter = '';
  339. /*$moreforfilter.='<div class="divsearchfield">';
  340. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  341. $moreforfilter.= '</div>';*/
  342. $parameters = array();
  343. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  344. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  345. else $moreforfilter = $hookmanager->resPrint;
  346. if (!empty($moreforfilter))
  347. {
  348. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  349. print $moreforfilter;
  350. print '</div>';
  351. }
  352. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  353. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  354. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  355. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  356. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  357. // Fields title search
  358. // --------------------------------------------------------------------
  359. print '<tr class="liste_titre">';
  360. foreach ($object->fields as $key => $val)
  361. {
  362. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  363. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  364. elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  365. elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  366. elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  367. if (!empty($arrayfields['t.'.$key]['checked']))
  368. {
  369. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  370. if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
  371. elseif (strpos($val['type'], 'integer:') === 0) {
  372. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  373. }
  374. elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
  375. print '</td>';
  376. }
  377. }
  378. // Extra fields
  379. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  380. // Fields from hook
  381. $parameters = array('arrayfields'=>$arrayfields);
  382. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  383. print $hookmanager->resPrint;
  384. // Action column
  385. print '<td class="liste_titre maxwidthsearch">';
  386. $searchpicto = $form->showFilterButtons();
  387. print $searchpicto;
  388. print '</td>';
  389. print '</tr>'."\n";
  390. // Fields title label
  391. // --------------------------------------------------------------------
  392. print '<tr class="liste_titre">';
  393. foreach ($object->fields as $key => $val)
  394. {
  395. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  396. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  397. elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  398. elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  399. elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  400. if (!empty($arrayfields['t.'.$key]['checked']))
  401. {
  402. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  403. }
  404. }
  405. // Extra fields
  406. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  407. // Hook fields
  408. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  409. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  410. print $hookmanager->resPrint;
  411. // Action column
  412. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  413. print '</tr>'."\n";
  414. // Detect if we need a fetch on each output line
  415. $needToFetchEachLine = 0;
  416. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
  417. {
  418. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
  419. {
  420. if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
  421. }
  422. }
  423. // Loop on record
  424. // --------------------------------------------------------------------
  425. $i = 0;
  426. $totalarray = array();
  427. while ($i < ($limit ? min($num, $limit) : $num))
  428. {
  429. $obj = $db->fetch_object($resql);
  430. if (empty($obj)) break; // Should not happen
  431. // Store properties in $object
  432. $object->setVarsFromFetchObj($obj);
  433. // Show here line of result
  434. print '<tr class="oddeven">';
  435. foreach ($object->fields as $key => $val)
  436. {
  437. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  438. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  439. elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  440. if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  441. elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  442. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  443. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  444. if (!empty($arrayfields['t.'.$key]['checked']))
  445. {
  446. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  447. if ($key == 'status') print $object->getLibStatut(5);
  448. else print $object->showOutputField($val, $key, $object->$key, '');
  449. print '</td>';
  450. if (!$i) $totalarray['nbfield']++;
  451. if (!empty($val['isameasure']))
  452. {
  453. if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  454. $totalarray['val']['t.'.$key] += $object->$key;
  455. }
  456. }
  457. }
  458. // Extra fields
  459. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  460. // Fields from hook
  461. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  462. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  463. print $hookmanager->resPrint;
  464. // Action column
  465. print '<td class="nowrap center">';
  466. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  467. {
  468. $selected = 0;
  469. if (in_array($object->id, $arrayofselected)) $selected = 1;
  470. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  471. }
  472. print '</td>';
  473. if (!$i) $totalarray['nbfield']++;
  474. print '</tr>'."\n";
  475. $i++;
  476. }
  477. // Show total line
  478. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  479. // If no record found
  480. if ($num == 0)
  481. {
  482. $colspan = 1;
  483. foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
  484. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  485. }
  486. $db->free($resql);
  487. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  488. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  489. print $hookmanager->resPrint;
  490. print '</table>'."\n";
  491. print '</div>'."\n";
  492. print '</form>'."\n";
  493. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
  494. {
  495. $hidegeneratedfilelistifempty = 1;
  496. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
  497. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  498. $formfile = new FormFile($db);
  499. // Show list of available documents
  500. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  501. $urlsource .= str_replace('&amp;', '&', $param);
  502. $filedir = $diroutputmassaction;
  503. $genallowed = $permissiontoread;
  504. $delallowed = $permissiontoadd;
  505. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  506. }
  507. // End of page
  508. llxFooter();
  509. $db->close();