target_list.php 32 KB

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