emailcollector_list.php 30 KB

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