emailcollector_list.php 29 KB

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