emailcollector_list.php 22 KB

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