emailcollector_list.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. if (!$user->admin) accessforbidden();
  31. if (empty($conf->emailcollector->enabled)) accessforbidden();
  32. // Load traductions files required by page
  33. $langs->loadLangs(array("admin", "other"));
  34. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  35. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  36. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  37. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  38. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'emailcollectorlist'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. $id = GETPOST('id', 'int');
  44. // Load variable for pagination
  45. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  46. $sortfield = GETPOST('sortfield', 'alpha');
  47. $sortorder = GETPOST('sortorder', 'alpha');
  48. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  49. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // 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) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  65. if (!$sortorder) $sortorder = "ASC";
  66. // Security check
  67. $socid = 0;
  68. if ($user->socid > 0) // Protection if external user
  69. {
  70. //$socid = $user->socid;
  71. accessforbidden();
  72. }
  73. //$result = restrictedArea($user, 'emailcollector', $id, '');
  74. // Initialize array of search criterias
  75. $search_all = trim(GETPOST("search_all", 'alpha'));
  76. $search = array();
  77. foreach ($object->fields as $key => $val)
  78. {
  79. if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  80. }
  81. // List of fields to search into when doing a "search in all"
  82. $fieldstosearchall = array();
  83. foreach ($object->fields as $key => $val)
  84. {
  85. if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  86. }
  87. // Definition of fields for list
  88. $arrayfields = array();
  89. foreach ($object->fields as $key => $val)
  90. {
  91. // If $val['visible']==0, then we never show the field
  92. if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
  93. }
  94. // Extra fields
  95. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
  96. {
  97. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
  98. {
  99. if (!empty($extrafields->attributes[$object->table_element]['list'][$key]))
  100. $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
  101. }
  102. }
  103. $object->fields = dol_sort_array($object->fields, 'position');
  104. $arrayfields = dol_sort_array($arrayfields, 'position');
  105. /*
  106. * Actions
  107. */
  108. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  109. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
  110. $parameters = array();
  111. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  112. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  113. if (empty($reshook))
  114. {
  115. // Selection of new fields
  116. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  117. // Purge search criteria
  118. 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
  119. {
  120. foreach ($object->fields as $key => $val)
  121. {
  122. $search[$key] = '';
  123. }
  124. $toselect = '';
  125. $search_array_options = array();
  126. }
  127. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  128. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
  129. {
  130. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  131. }
  132. // Mass actions
  133. $objectclass = 'EmailCollector';
  134. $objectlabel = 'EmailCollector';
  135. $permissiontoread = $user->rights->emailcollector->read;
  136. $permissiontodelete = $user->rights->emailcollector->delete;
  137. $uploaddir = $conf->emailcollector->dir_output;
  138. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  139. }
  140. /*
  141. * View
  142. */
  143. $form = new Form($db);
  144. $help_url = "EN:Module_EMail_Collector|FR:Module_Collecteur_de_courrier_électronique|ES:Module_EMail_Collector";
  145. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("EmailCollector"));
  146. // Build and execute select
  147. // --------------------------------------------------------------------
  148. $sql = 'SELECT ';
  149. foreach ($object->fields as $key => $val)
  150. {
  151. $sql .= 't.'.$key.', ';
  152. }
  153. // Add fields from extrafields
  154. if (!empty($extrafields->attributes[$object->table_element]['label']))
  155. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
  156. // Add fields from hooks
  157. $parameters = array();
  158. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  159. $sql .= $hookmanager->resPrint;
  160. $sql = preg_replace('/, $/', '', $sql);
  161. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  162. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  163. if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  164. else $sql .= " WHERE 1 = 1";
  165. foreach ($search as $key => $val)
  166. {
  167. if ($key == 'status' && $search[$key] == -1) continue;
  168. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  169. if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  170. }
  171. if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  172. // Add where from extra fields
  173. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  174. // Add where from hooks
  175. $parameters = array();
  176. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  177. $sql .= $hookmanager->resPrint;
  178. /* If a group by is required
  179. $sql.= " GROUP BY "
  180. foreach($object->fields as $key => $val)
  181. {
  182. $sql.='t.'.$key.', ';
  183. }
  184. // Add fields from extrafields
  185. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  186. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  187. // Add where from hooks
  188. $parameters=array();
  189. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  190. $sql.=$hookmanager->resPrint;
  191. $sql=preg_replace('/, $/','', $sql);
  192. */
  193. $sql .= $db->order($sortfield, $sortorder);
  194. // Count total nb of records
  195. $nbtotalofrecords = '';
  196. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  197. {
  198. $resql = $db->query($sql);
  199. $nbtotalofrecords = $db->num_rows($resql);
  200. if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
  201. {
  202. $page = 0;
  203. $offset = 0;
  204. }
  205. }
  206. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  207. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
  208. {
  209. $num = $nbtotalofrecords;
  210. }
  211. else
  212. {
  213. $sql .= $db->plimit($limit + 1, $offset);
  214. $resql = $db->query($sql);
  215. if (!$resql)
  216. {
  217. dol_print_error($db);
  218. exit;
  219. }
  220. $num = $db->num_rows($resql);
  221. }
  222. // Direct jump if only one record found
  223. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
  224. {
  225. $obj = $db->fetch_object($resql);
  226. $id = $obj->rowid;
  227. header("Location: ".DOL_URL_ROOT.'/emailcollector/emailcollector_card.php?id='.$id);
  228. exit;
  229. }
  230. // Output page
  231. // --------------------------------------------------------------------
  232. llxHeader('', $title, $help_url);
  233. // Example : Adding jquery code
  234. print '<script type="text/javascript" language="javascript">
  235. jQuery(document).ready(function() {
  236. function init_myfunc()
  237. {
  238. jQuery("#myid").removeAttr(\'disabled\');
  239. jQuery("#myid").attr(\'disabled\',\'disabled\');
  240. }
  241. init_myfunc();
  242. jQuery("#mybutton").click(function() {
  243. init_myfunc();
  244. });
  245. });
  246. </script>';
  247. $arrayofselected = is_array($toselect) ? $toselect : array();
  248. $param = '';
  249. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  250. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  251. foreach ($search as $key => $val)
  252. {
  253. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  254. }
  255. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  256. // Add $param from extra fields
  257. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  258. // List of mass actions available
  259. $arrayofmassactions = array(
  260. //'presend'=>$langs->trans("SendByMail"),
  261. //'builddoc'=>$langs->trans("PDFMerge"),
  262. );
  263. if ($user->rights->emailcollector->delete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  264. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  265. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  266. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  267. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  268. print '<input type="hidden" name="token" value="'.newToken().'">';
  269. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  270. print '<input type="hidden" name="action" value="list">';
  271. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  272. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  273. print '<input type="hidden" name="page" value="'.$page.'">';
  274. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  275. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  276. $newcardbutton = '';
  277. //if ($user->rights->emailcollector->creer)
  278. //{
  279. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', 'emailcollector_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']));
  280. //}
  281. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton.' '.$linkback, '', $limit);
  282. // Add code for pre mass action (confirmation or email presend form)
  283. /*$topicmail="";
  284. $modelmail="";
  285. $objecttmp=new EmailCollector($db);
  286. $trackid='xxxx'.$object->id;*/
  287. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  288. if ($sall)
  289. {
  290. foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
  291. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  292. }
  293. $moreforfilter = '';
  294. /*$moreforfilter.='<div class="divsearchfield">';
  295. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  296. $moreforfilter.= '</div>';*/
  297. $parameters = array();
  298. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  299. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  300. else $moreforfilter = $hookmanager->resPrint;
  301. if (!empty($moreforfilter))
  302. {
  303. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  304. print $moreforfilter;
  305. print '</div>';
  306. }
  307. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  308. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  309. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  310. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  311. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  312. // Fields title search
  313. // --------------------------------------------------------------------
  314. print '<tr class="liste_titre">';
  315. foreach ($object->fields as $key => $val)
  316. {
  317. $cssforfield = '';
  318. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  319. if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  320. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  321. if (!empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
  322. }
  323. // Extra fields
  324. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  325. // Fields from hook
  326. $parameters = array('arrayfields'=>$arrayfields);
  327. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  328. print $hookmanager->resPrint;
  329. // Action column
  330. print '<td class="liste_titre maxwidthsearch">';
  331. $searchpicto = $form->showFilterButtons();
  332. print $searchpicto;
  333. print '</td>';
  334. print '</tr>'."\n";
  335. // Fields title label
  336. // --------------------------------------------------------------------
  337. print '<tr class="liste_titre">';
  338. foreach ($object->fields as $key => $val)
  339. {
  340. $cssforfield = '';
  341. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  342. if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  343. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  344. if (!empty($arrayfields['t.'.$key]['checked']))
  345. {
  346. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  347. }
  348. }
  349. // Extra fields
  350. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  351. // Hook fields
  352. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  353. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  354. print $hookmanager->resPrint;
  355. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  356. print '</tr>'."\n";
  357. // Detect if we need a fetch on each output line
  358. $needToFetchEachLine = 0;
  359. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
  360. {
  361. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
  362. {
  363. if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
  364. }
  365. }
  366. // Loop on record
  367. // --------------------------------------------------------------------
  368. $i = 0;
  369. $totalarray = array();
  370. while ($i < min($num, $limit))
  371. {
  372. $obj = $db->fetch_object($resql);
  373. if (empty($obj)) break; // Should not happen
  374. // Store properties in $object
  375. $object->id = $obj->rowid;
  376. foreach ($object->fields as $key => $val)
  377. {
  378. if (property_exists($obj, $key)) $object->$key = $obj->$key;
  379. }
  380. // Show here line of result
  381. print '<tr class="oddeven">';
  382. foreach ($object->fields as $key => $val)
  383. {
  384. $cssforfield = '';
  385. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  386. elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  387. if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  388. elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  389. if (!empty($arrayfields['t.'.$key]['checked']))
  390. {
  391. print '<td';
  392. if ($cssforfield || $val['css']) print ' class="';
  393. print $cssforfield;
  394. if ($cssforfield && $val['css']) print ' ';
  395. print $val['css'];
  396. if ($cssforfield || $val['css']) print '"';
  397. print '>';
  398. print $object->showOutputField($val, $key, $obj->$key, '');
  399. print '</td>';
  400. if (!$i) $totalarray['nbfield']++;
  401. if (!empty($val['isameasure']))
  402. {
  403. if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  404. $totalarray['val']['t.'.$key] += $obj->$key;
  405. }
  406. }
  407. }
  408. // Extra fields
  409. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  410. // Fields from hook
  411. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  412. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  413. print $hookmanager->resPrint;
  414. // Action column
  415. print '<td class="nowrap center">';
  416. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  417. {
  418. $selected = 0;
  419. if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
  420. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  421. }
  422. print '</td>';
  423. if (!$i) $totalarray['nbfield']++;
  424. print '</tr>';
  425. $i++;
  426. }
  427. // Show total line
  428. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  429. // If no record found
  430. if ($num == 0)
  431. {
  432. $colspan = 1;
  433. foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
  434. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  435. }
  436. $db->free($resql);
  437. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  438. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  439. print $hookmanager->resPrint;
  440. print '</table>'."\n";
  441. print '</div>'."\n";
  442. print '</form>'."\n";
  443. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
  444. {
  445. $hidegeneratedfilelistifempty = 1;
  446. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
  447. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  448. $formfile = new FormFile($db);
  449. // Show list of available documents
  450. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  451. $urlsource .= str_replace('&amp;', '&', $param);
  452. $filedir = $diroutputmassaction;
  453. $genallowed = $user->rights->emailcollector->read;
  454. $delallowed = $user->rights->emailcollector->create;
  455. print $formfile->showdocuments('massfilesarea_emailcollector', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  456. }
  457. // End of page
  458. llxFooter();
  459. $db->close();