target_list.php 31 KB

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