emailcollector_list.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. $id = GETPOST('id', 'int');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  48. $page = 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. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. //if (! $sortfield) $sortfield="p.date_fin";
  54. //if (! $sortorder) $sortorder="DESC";
  55. // Initialize technical objects
  56. $object = new EmailCollector($db);
  57. $extrafields = new ExtraFields($db);
  58. $diroutputmassaction = $conf->emailcollector->dir_output.'/temp/massgeneration/'.$user->id;
  59. $hookmanager->initHooks(array('emailcollectorlist')); // Note that conf->hooks_modules contains array
  60. // Fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  63. // Default sort order (if not yet defined by previous GETPOST)
  64. if (!$sortfield) {
  65. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  66. }
  67. if (!$sortorder) {
  68. $sortorder = "ASC";
  69. }
  70. // Security check
  71. $socid = 0;
  72. if ($user->socid > 0) { // Protection if external user
  73. //$socid = $user->socid;
  74. accessforbidden();
  75. }
  76. //$result = restrictedArea($user, 'emailcollector', $id, '');
  77. // Initialize array of search criterias
  78. $search_all = GETPOST("search_all", 'alphanohtml');
  79. $search = array();
  80. foreach ($object->fields as $key => $val) {
  81. if (GETPOST('search_'.$key, 'alpha') !== '') {
  82. $search[$key] = GETPOST('search_'.$key, 'alpha');
  83. }
  84. }
  85. // List of fields to search into when doing a "search in all"
  86. $fieldstosearchall = array();
  87. foreach ($object->fields as $key => $val) {
  88. if (!empty($val['searchall'])) {
  89. $fieldstosearchall['t.'.$key] = $val['label'];
  90. }
  91. }
  92. // Definition of array of fields for columns
  93. $arrayfields = array();
  94. foreach ($object->fields as $key => $val) {
  95. // If $val['visible']==0, then we never show the field
  96. if (!empty($val['visible'])) {
  97. $visible = dol_eval($val['visible'], 1, 1, '1');
  98. $arrayfields['t.'.$key] = array(
  99. 'label'=>$val['label'],
  100. 'checked'=>(($visible < 0) ? 0 : 1),
  101. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  102. 'position'=>$val['position']
  103. );
  104. }
  105. }
  106. // Extra fields
  107. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
  108. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  109. if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
  110. $arrayfields["ef.".$key] = array(
  111. 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
  112. 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
  113. 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
  114. 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]),
  115. 'langfile'=>$extrafields->attributes[$object->table_element]['langfile'][$key]
  116. );
  117. }
  118. }
  119. }
  120. $object->fields = dol_sort_array($object->fields, 'position');
  121. $arrayfields = dol_sort_array($arrayfields, 'position');
  122. /*$permissiontoread = $user->rights->emailcollector->read;
  123. $permissiontoadd = $user->rights->emailcollector->write;
  124. $permissiontodelete = $user->rights->emailcollector->delete;*/
  125. $permissiontoread = $user->admin;
  126. $permissiontoadd = $user->admin;
  127. $permissiontodelete = $user->admin;
  128. if (!$user->admin) {
  129. accessforbidden();
  130. }
  131. if (empty($conf->emailcollector->enabled)) {
  132. accessforbidden('Module not enabled');
  133. }
  134. /*
  135. * Actions
  136. */
  137. if (GETPOST('cancel', 'alpha')) {
  138. $action = 'list'; $massaction = '';
  139. }
  140. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  141. $massaction = '';
  142. }
  143. $parameters = array();
  144. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  145. if ($reshook < 0) {
  146. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  147. }
  148. if (empty($reshook)) {
  149. // Selection of new fields
  150. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  151. // Purge search criteria
  152. 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
  153. foreach ($object->fields as $key => $val) {
  154. $search[$key] = '';
  155. }
  156. $toselect = '';
  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. $help_url = "EN:Module_EMail_Collector|FR:Module_Collecteur_de_courrier_électronique|ES:Module_EMail_Collector";
  174. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("EmailCollector"));
  175. // Build and execute select
  176. // --------------------------------------------------------------------
  177. $sql = 'SELECT ';
  178. foreach ($object->fields as $key => $val) {
  179. $sql .= "t.".$key.", ";
  180. }
  181. // Add fields from extrafields
  182. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  183. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  184. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  185. }
  186. }
  187. // Add fields from hooks
  188. $parameters = array();
  189. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  190. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  191. $sql = preg_replace('/,\s*$/', '', $sql);
  192. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  193. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  194. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  195. }
  196. if ($object->ismultientitymanaged == 1) {
  197. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  198. } else {
  199. $sql .= " WHERE 1 = 1";
  200. }
  201. foreach ($search as $key => $val) {
  202. if ($key == 'status' && $search[$key] == -1) {
  203. continue;
  204. }
  205. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  206. if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
  207. if ($search[$key] == '-1') {
  208. $search[$key] = '';
  209. }
  210. $mode_search = 2;
  211. }
  212. if ($search[$key] != '') {
  213. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  214. }
  215. }
  216. if ($search_all) {
  217. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  218. }
  219. // Add where from extra fields
  220. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  221. // Add where from hooks
  222. $parameters = array();
  223. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  224. $sql .= $hookmanager->resPrint;
  225. /* If a group by is required
  226. $sql.= " GROUP BY ";
  227. foreach ($object->fields as $key => $val)
  228. {
  229. $sql .= "t.".$key.", ";
  230. }
  231. // Add fields from extrafields
  232. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  233. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  234. }
  235. // Add where from hooks
  236. $parameters=array();
  237. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  238. $sql.=$hookmanager->resPrint;
  239. $sql=preg_replace('/, $/','', $sql);
  240. */
  241. $sql .= $db->order($sortfield, $sortorder);
  242. // Count total nb of records
  243. $nbtotalofrecords = '';
  244. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  245. $resql = $db->query($sql);
  246. $nbtotalofrecords = $db->num_rows($resql);
  247. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  248. $page = 0;
  249. $offset = 0;
  250. }
  251. }
  252. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  253. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  254. $num = $nbtotalofrecords;
  255. } else {
  256. if ($limit) {
  257. $sql .= $db->plimit($limit + 1, $offset);
  258. }
  259. $resql = $db->query($sql);
  260. if (!$resql) {
  261. dol_print_error($db);
  262. exit;
  263. }
  264. $num = $db->num_rows($resql);
  265. }
  266. // Direct jump if only one record found
  267. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  268. $obj = $db->fetch_object($resql);
  269. $id = $obj->rowid;
  270. header("Location: ".DOL_URL_ROOT.'/emailcollector/emailcollector_card.php?id='.$id);
  271. exit;
  272. }
  273. // Output page
  274. // --------------------------------------------------------------------
  275. llxHeader('', $title, $help_url);
  276. $arrayofselected = is_array($toselect) ? $toselect : array();
  277. $param = '';
  278. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  279. $param .= '&contextpage='.urlencode($contextpage);
  280. }
  281. if ($limit > 0 && $limit != $conf->liste_limit) {
  282. $param .= '&limit='.urlencode($limit);
  283. }
  284. foreach ($search as $key => $val) {
  285. if (is_array($search[$key]) && count($search[$key])) {
  286. foreach ($search[$key] as $skey) {
  287. $param .= '&search_'.$key.'[]='.urlencode($skey);
  288. }
  289. } else {
  290. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  291. }
  292. }
  293. if ($optioncss != '') {
  294. $param .= '&optioncss='.urlencode($optioncss);
  295. }
  296. // Add $param from extra fields
  297. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  298. // List of mass actions available
  299. $arrayofmassactions = array(
  300. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  301. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  302. );
  303. if ($permissiontodelete) {
  304. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  305. }
  306. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  307. $arrayofmassactions = array();
  308. }
  309. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  310. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  311. if ($optioncss != '') {
  312. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  313. }
  314. print '<input type="hidden" name="token" value="'.newToken().'">';
  315. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  316. print '<input type="hidden" name="action" value="list">';
  317. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  318. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  319. print '<input type="hidden" name="page" value="'.$page.'">';
  320. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  321. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  322. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', 'emailcollector_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  323. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'email', 0, $newcardbutton.' '.$linkback, '', $limit, 0, 0, 1);
  324. // Add code for pre mass action (confirmation or email presend form)
  325. /*$topicmail="";
  326. $modelmail="";
  327. $objecttmp=new EmailCollector($db);
  328. $trackid='xxxx'.$object->id;*/
  329. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  330. $moreforfilter = '';
  331. /*$moreforfilter.='<div class="divsearchfield">';
  332. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  333. $moreforfilter.= '</div>';*/
  334. $parameters = array();
  335. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  336. if (empty($reshook)) {
  337. $moreforfilter .= $hookmanager->resPrint;
  338. } else {
  339. $moreforfilter = $hookmanager->resPrint;
  340. }
  341. if (!empty($moreforfilter)) {
  342. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  343. print $moreforfilter;
  344. print '</div>';
  345. }
  346. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  347. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  348. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  349. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  350. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  351. // Fields title search
  352. // --------------------------------------------------------------------
  353. print '<tr class="liste_titre">';
  354. foreach ($object->fields as $key => $val) {
  355. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  356. if ($key == 'status') {
  357. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  358. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  359. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  360. } elseif (in_array($val['type'], array('timestamp'))) {
  361. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  362. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  363. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  364. }
  365. if (!empty($arrayfields['t.'.$key]['checked'])) {
  366. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  367. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  368. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  369. } elseif (strpos($val['type'], 'integer:') === 0) {
  370. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  371. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  372. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
  373. }
  374. print '</td>';
  375. }
  376. }
  377. // Extra fields
  378. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  379. // Fields from hook
  380. $parameters = array('arrayfields'=>$arrayfields);
  381. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  382. print $hookmanager->resPrint;
  383. // Action column
  384. print '<td class="liste_titre maxwidthsearch">';
  385. $searchpicto = $form->showFilterButtons();
  386. print $searchpicto;
  387. print '</td>';
  388. print '</tr>'."\n";
  389. // Fields title label
  390. // --------------------------------------------------------------------
  391. print '<tr class="liste_titre">';
  392. foreach ($object->fields as $key => $val) {
  393. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  394. if ($key == 'status') {
  395. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  396. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  397. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  398. } elseif (in_array($val['type'], array('timestamp'))) {
  399. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  400. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  401. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  402. }
  403. if (!empty($arrayfields['t.'.$key]['checked'])) {
  404. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  405. }
  406. }
  407. // Extra fields
  408. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  409. // Hook fields
  410. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  411. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  412. print $hookmanager->resPrint;
  413. // Action column
  414. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  415. print '</tr>'."\n";
  416. // Detect if we need a fetch on each output line
  417. $needToFetchEachLine = 0;
  418. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  419. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  420. if (preg_match('/\$object/', $val)) {
  421. $needToFetchEachLine++; // There is at least one compute field that use $object
  422. }
  423. }
  424. }
  425. // Loop on record
  426. // --------------------------------------------------------------------
  427. $i = 0;
  428. $totalarray = array();
  429. while ($i < ($limit ? min($num, $limit) : $num)) {
  430. $obj = $db->fetch_object($resql);
  431. if (empty($obj)) {
  432. break; // Should not happen
  433. }
  434. // Store properties in $object
  435. $object->setVarsFromFetchObj($obj);
  436. // Show here line of result
  437. print '<tr class="oddeven">';
  438. foreach ($object->fields as $key => $val) {
  439. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  440. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  441. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  442. } elseif ($key == 'status') {
  443. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  444. }
  445. if (in_array($val['type'], array('timestamp'))) {
  446. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  447. } elseif ($key == 'ref') {
  448. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  449. }
  450. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status'))) {
  451. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  452. }
  453. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  454. if (!empty($arrayfields['t.'.$key]['checked'])) {
  455. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  456. if ($key == 'status') {
  457. print $object->getLibStatut(5);
  458. } else {
  459. print $object->showOutputField($val, $key, $object->$key, '');
  460. }
  461. print '</td>';
  462. if (!$i) {
  463. $totalarray['nbfield']++;
  464. }
  465. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  466. if (!$i) {
  467. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  468. }
  469. if (!isset($totalarray['val'])) {
  470. $totalarray['val'] = array();
  471. }
  472. if (!isset($totalarray['val']['t.'.$key])) {
  473. $totalarray['val']['t.'.$key] = 0;
  474. }
  475. $totalarray['val']['t.'.$key] += $object->$key;
  476. }
  477. }
  478. }
  479. // Extra fields
  480. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  481. // Fields from hook
  482. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  483. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  484. print $hookmanager->resPrint;
  485. // Action column
  486. print '<td class="nowrap center">';
  487. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  488. $selected = 0;
  489. if (in_array($object->id, $arrayofselected)) {
  490. $selected = 1;
  491. }
  492. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  493. }
  494. print '</td>';
  495. if (!$i) {
  496. $totalarray['nbfield']++;
  497. }
  498. print '</tr>'."\n";
  499. $i++;
  500. }
  501. // Show total line
  502. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  503. // If no record found
  504. if ($num == 0) {
  505. $colspan = 1;
  506. foreach ($arrayfields as $key => $val) {
  507. if (!empty($val['checked'])) {
  508. $colspan++;
  509. }
  510. }
  511. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  512. }
  513. $db->free($resql);
  514. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  515. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  516. print $hookmanager->resPrint;
  517. print '</table>'."\n";
  518. print '</div>'."\n";
  519. print '</form>'."\n";
  520. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  521. $hidegeneratedfilelistifempty = 1;
  522. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  523. $hidegeneratedfilelistifempty = 0;
  524. }
  525. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  526. $formfile = new FormFile($db);
  527. // Show list of available documents
  528. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  529. $urlsource .= str_replace('&amp;', '&', $param);
  530. $filedir = $diroutputmassaction;
  531. $genallowed = $permissiontoread;
  532. $delallowed = $permissiontoadd;
  533. print $formfile->showdocuments('massfilesarea_emailcollector', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  534. }
  535. // End of page
  536. llxFooter();
  537. $db->close();