list.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. /* Copyright (C) 2005-2023 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/comm/mailing/list.php
  20. * \ingroup mailing
  21. * \brief Liste des mailings
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  26. // Load translation files required by the page
  27. $langs->load('mails');
  28. // Get Parameters
  29. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
  30. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  31. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  32. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  33. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  34. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  35. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  36. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  37. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  38. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  39. // Load variable for pagination
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  45. // If $page is not defined, or '' or -1 or if we click on clear filters
  46. $page = 0;
  47. }
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. // Search Fields
  52. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  53. $search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
  54. $filteremail = GETPOST('filteremail', 'alpha');
  55. // Initialize technical objects
  56. $object = new Mailing($db);
  57. $extrafields = new ExtraFields($db);
  58. $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
  59. // Fetch optionals attributes and labels
  60. $extrafields->fetch_name_optionals_label($object->table_element);
  61. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  62. // Default sort order (if not yet defined by previous GETPOST)
  63. if (!$sortorder) {
  64. $sortorder = "DESC";
  65. }
  66. if (!$sortfield) {
  67. $sortfield = "m.date_creat";
  68. }
  69. // List of fields to search into when doing a "search in all"
  70. $fieldstosearchall = array(
  71. 'm.titre'=>'Ref',
  72. );
  73. $permissiontoread = $user->hasRight('mailing', 'lire');
  74. $permissiontoadd = $user->hasRight('mailing', 'creer');
  75. $permissiontodelete = $user->hasRight('mailing', 'delete');
  76. // Security check
  77. if (!$user->hasRight('mailing', 'lire') || (!getDolGlobalString('EXTERNAL_USERS_ARE_AUTHORIZED') && $user->socid > 0)) {
  78. accessforbidden();
  79. }
  80. //$result = restrictedArea($user, 'mailing');
  81. /*
  82. * Actions
  83. */
  84. if (GETPOST('cancel', 'alpha')) {
  85. $action = 'list';
  86. $massaction = '';
  87. }
  88. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  89. $massaction = '';
  90. }
  91. $parameters = array();
  92. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  93. if ($reshook < 0) {
  94. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  95. }
  96. if (empty($reshook)) {
  97. // Selection of new fields
  98. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  99. // Purge search criteria
  100. 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
  101. /*foreach($object->fields as $key => $val)
  102. {
  103. $search[$key]='';
  104. }*/
  105. $search_ref = '';
  106. $search_all = '';
  107. $toselect = array();
  108. $search_array_options = array();
  109. }
  110. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  111. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  112. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  113. }
  114. // Mass actions
  115. $objectclass = 'Mailing';
  116. $objectlabel = 'Mailing';
  117. $uploaddir = $conf->mailing->dir_output;
  118. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  119. }
  120. /*
  121. * View
  122. */
  123. $form = new Form($db);
  124. $now = dol_now();
  125. $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
  126. $title = $langs->trans("Mailing");
  127. $morejs = array();
  128. $morecss = array();
  129. // Build and execute select
  130. // --------------------------------------------------------------------
  131. if ($filteremail) {
  132. $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
  133. $sql .= " mc.statut as sendstatut";
  134. $sqlfields = $sql; // $sql fields to remove for count total
  135. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
  136. $sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
  137. $sql .= " AND mc.email = '".$db->escape($filteremail)."'";
  138. if ($search_ref) {
  139. $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
  140. }
  141. if ($search_all) {
  142. $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
  143. }
  144. if (!$sortorder) {
  145. $sortorder = "ASC";
  146. }
  147. if (!$sortfield) {
  148. $sortfield = "m.rowid";
  149. }
  150. } else {
  151. $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
  152. $sqlfields = $sql; // $sql fields to remove for count total
  153. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  154. $sql .= " WHERE m.entity = ".$conf->entity;
  155. if ($search_ref) {
  156. $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
  157. }
  158. if ($search_all) {
  159. $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
  160. }
  161. if (!$sortorder) {
  162. $sortorder = "ASC";
  163. }
  164. if (!$sortfield) {
  165. $sortfield = "m.rowid";
  166. }
  167. }
  168. if ($search_all) {
  169. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  170. }
  171. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  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, $action); // Note that $action and $object may have been modified by hook
  177. $sql .= $hookmanager->resPrint;
  178. // Count total nb of records
  179. $nbtotalofrecords = '';
  180. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  181. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  182. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  183. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  184. $resql = $db->query($sqlforcount);
  185. if ($resql) {
  186. $objforcount = $db->fetch_object($resql);
  187. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  188. } else {
  189. dol_print_error($db);
  190. }
  191. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  192. $page = 0;
  193. $offset = 0;
  194. }
  195. $db->free($resql);
  196. }
  197. // Complete request and execute it with limit
  198. $sql .= $db->order($sortfield, $sortorder);
  199. if ($limit) {
  200. $sql .= $db->plimit($limit + 1, $offset);
  201. }
  202. $resql = $db->query($sql);
  203. if (!$resql) {
  204. dol_print_error($db);
  205. exit;
  206. }
  207. $num = $db->num_rows($resql);
  208. // Direct jump if only one record found
  209. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  210. $obj = $db->fetch_object($resql);
  211. $id = $obj->rowid;
  212. header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
  213. exit;
  214. }
  215. // Output page
  216. // --------------------------------------------------------------------
  217. $title = $langs->trans("EMailings");
  218. if ($filteremail) {
  219. $title .= ' ('.$langs->trans("SentTo", $filteremail).')';
  220. }
  221. llxHeader('', $title, $help_url);
  222. $arrayofselected = is_array($toselect) ? $toselect : array();
  223. $param = "&search_all=".urlencode($search_all);
  224. if (!empty($mode)) {
  225. $param .= '&mode='.urlencode($mode);
  226. }
  227. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  228. $param .= '&contextpage='.urlencode($contextpage);
  229. }
  230. if ($limit > 0 && $limit != $conf->liste_limit) {
  231. $param .= '&limit='.((int) $limit);
  232. }
  233. if ($optioncss != '') {
  234. $param .= '&optioncss='.urlencode($optioncss);
  235. }
  236. if ($filteremail) {
  237. $param .= '&filteremail='.urlencode($filteremail);
  238. }
  239. // Add $param from extra fields
  240. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  241. // Add $param from hooks
  242. $parameters = array();
  243. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  244. $param .= $hookmanager->resPrint;
  245. // List of mass actions available
  246. $arrayofmassactions = array(
  247. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  248. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  249. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  250. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  251. );
  252. if (!empty($permissiontodelete)) {
  253. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  254. }
  255. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  256. $arrayofmassactions = array();
  257. }
  258. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  259. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  260. if ($optioncss != '') {
  261. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  262. }
  263. print '<input type="hidden" name="token" value="'.newToken().'">';
  264. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  265. print '<input type="hidden" name="action" value="list">';
  266. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  267. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  268. print '<input type="hidden" name="page" value="'.$page.'">';
  269. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  270. print '<input type="hidden" name="page_y" value="">';
  271. print '<input type="hidden" name="mode" value="'.$mode.'">';
  272. $newcardbutton = '';
  273. if ($user->hasRight('mailing', 'creer')) {
  274. $newcardbutton .= dolGetButtonTitle($langs->trans('NewMailing'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/mailing/card.php?action=create');
  275. }
  276. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_email', 0, $newcardbutton, '', $limit, 0, 0, 1);
  277. // Add code for pre mass action (confirmation or email presend form)
  278. $topicmail = "SendMailingRef";
  279. $modelmail = "mailing";
  280. $objecttmp = new Mailing($db);
  281. $trackid = 'mailing'.$object->id;
  282. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  283. if ($search_all) {
  284. $setupstring = '';
  285. foreach ($fieldstosearchall as $key => $val) {
  286. $fieldstosearchall[$key] = $langs->trans($val);
  287. $setupstring .= $key."=".$val.";";
  288. }
  289. print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  290. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  291. }
  292. $moreforfilter = '';
  293. $parameters = array();
  294. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  295. if (empty($reshook)) {
  296. $moreforfilter .= $hookmanager->resPrint;
  297. } else {
  298. $moreforfilter = $hookmanager->resPrint;
  299. }
  300. if (!empty($moreforfilter)) {
  301. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  302. print $moreforfilter;
  303. $parameters = array('type'=>$type);
  304. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  305. print $hookmanager->resPrint;
  306. print '</div>';
  307. }
  308. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  309. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  310. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  311. print '<div class="div-table-responsive">';
  312. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  313. // Fields title search
  314. // --------------------------------------------------------------------
  315. print '<tr class="liste_titre_filter">';
  316. // Action column
  317. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  318. print '<td class="liste_titre maxwidthsearch center">';
  319. $searchpicto = $form->showFilterButtons('left');
  320. print $searchpicto;
  321. print '</td>';
  322. }
  323. print '<td class="liste_titre">';
  324. print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  325. print '</td>';
  326. // Title
  327. print '<td class="liste_titre">';
  328. print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
  329. print '</td>';
  330. print '<td class="liste_titre">&nbsp;</td>';
  331. if (!$filteremail) {
  332. print '<td class="liste_titre">&nbsp;</td>';
  333. }
  334. print '<td class="liste_titre">&nbsp;</td>';
  335. print '<td class="liste_titre">&nbsp;</td>';
  336. // Extra fields
  337. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  338. // Fields from hook
  339. $parameters = array('arrayfields'=>$arrayfields);
  340. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  341. print $hookmanager->resPrint;
  342. // Action column
  343. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  344. print '<td class="liste_titre center maxwidthsearch">';
  345. $searchpicto = $form->showFilterButtons();
  346. print $searchpicto;
  347. print '</td>';
  348. }
  349. print '</tr>'."\n";
  350. $totalarray = array();
  351. $totalarray['nbfield'] = 0;
  352. // Fields title label
  353. // --------------------------------------------------------------------
  354. print '<tr class="liste_titre">';
  355. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  356. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  357. $totalarray['nbfield']++;
  358. }
  359. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder);
  360. $totalarray['nbfield']++;
  361. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
  362. $totalarray['nbfield']++;
  363. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder);
  364. $totalarray['nbfield']++;
  365. if (!$filteremail) {
  366. print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder);
  367. $totalarray['nbfield']++;
  368. }
  369. if (!$filteremail) {
  370. print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
  371. $totalarray['nbfield']++;
  372. } else {
  373. print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
  374. $totalarray['nbfield']++;
  375. }
  376. // Extra fields
  377. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  378. // Hook fields
  379. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  380. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  381. print $hookmanager->resPrint;
  382. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], ($filteremail ? "mc.statut" : "m.statut"), $param, "", '', $sortfield, $sortorder, 'center ');
  383. $totalarray['nbfield']++;
  384. // Action column
  385. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  386. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  387. $totalarray['nbfield']++;
  388. }
  389. print '</tr>'."\n";
  390. $totalarray = array();
  391. $totalarray['nbfield'] = 0;
  392. // Loop on record
  393. // --------------------------------------------------------------------
  394. $i = 0;
  395. $savnbfield = $totalarray['nbfield'];
  396. $totalarray = array();
  397. $totalarray['nbfield'] = 0;
  398. $imaxinloop = ($limit ? min($num, $limit) : $num);
  399. while ($i < $imaxinloop) {
  400. $obj = $db->fetch_object($resql);
  401. if (empty($obj)) {
  402. break; // Should not happen
  403. }
  404. $object->id = $obj->rowid;
  405. $object->ref = $obj->rowid;
  406. // Show here line of result
  407. $j = 0;
  408. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  409. // Action column
  410. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  411. print '<td class="nowrap center">';
  412. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  413. $selected = 0;
  414. if (in_array($object->id, $arrayofselected)) {
  415. $selected = 1;
  416. }
  417. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  418. }
  419. print '</td>';
  420. if (!$i) {
  421. $totalarray['nbfield']++;
  422. }
  423. }
  424. print '<td>';
  425. print $object->getNomUrl(1);
  426. print '</td>';
  427. // Title
  428. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
  429. // Date creation
  430. print '<td class="center">';
  431. print dol_print_date($db->jdate($obj->datec), 'day');
  432. print '</td>';
  433. // Nb of email
  434. if (!$filteremail) {
  435. print '<td class="center nowraponall">';
  436. $nbemail = $obj->nbemail;
  437. /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
  438. {
  439. $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  440. print $form->textwithpicto($nbemail,$text,1,'warning');
  441. }
  442. else
  443. {
  444. print $nbemail;
  445. }*/
  446. print $nbemail;
  447. print '</td>';
  448. }
  449. // Last send
  450. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi), 'day').'</td>';
  451. print '</td>';
  452. // Status
  453. print '<td class="nowrap center">';
  454. if ($filteremail) {
  455. print $object::libStatutDest($obj->sendstatut, 2);
  456. } else {
  457. print $object->LibStatut($obj->statut, 5);
  458. }
  459. print '</td>';
  460. // Action column
  461. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  462. print '<td class="nowrap center">';
  463. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  464. $selected = 0;
  465. if (in_array($object->id, $arrayofselected)) {
  466. $selected = 1;
  467. }
  468. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  469. }
  470. print '</td>';
  471. if (!$i) {
  472. $totalarray['nbfield']++;
  473. }
  474. }
  475. print '</tr>'."\n";
  476. $i++;
  477. }
  478. // Show total line
  479. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  480. // If no record found
  481. if (empty($num)) {
  482. $colspan = 6;
  483. if (!$filteremail) {
  484. $colspan++;
  485. }
  486. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  487. }
  488. $db->free($resql);
  489. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  490. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  491. print $hookmanager->resPrint;
  492. print '</table>'."\n";
  493. print '</div>'."\n";
  494. print '</form>'."\n";
  495. // End of page
  496. llxFooter();
  497. $db->close();