list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /* Copyright (C) 2005-2016 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. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
  25. // Load translation files required by the page
  26. $langs->load("mails");
  27. $sortfield = GETPOST('sortfield', 'aZ09comma');
  28. $sortorder = GETPOST('sortorder', 'aZ09comma');
  29. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  30. $optioncss = GETPOST('optioncss', 'alpha');
  31. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  32. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  33. $page = 0;
  34. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  35. $offset = $limit * $page;
  36. $pageprev = $page - 1;
  37. $pagenext = $page + 1;
  38. if (!$sortorder) {
  39. $sortorder = "DESC";
  40. }
  41. if (!$sortfield) {
  42. $sortfield = "m.date_creat";
  43. }
  44. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  45. $search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
  46. $filteremail = GETPOST('filteremail', 'alpha');
  47. $object = new Mailing($db);
  48. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  49. $hookmanager->initHooks(array('mailinglist'));
  50. $extrafields = new ExtraFields($db);
  51. // fetch optionals attributes and labels
  52. $extrafields->fetch_name_optionals_label($object->table_element);
  53. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  54. // List of fields to search into when doing a "search in all"
  55. $fieldstosearchall = array(
  56. 'm.titre'=>'Ref',
  57. );
  58. // Security check
  59. if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
  60. accessforbidden();
  61. }
  62. //$result = restrictedArea($user, 'mailing');
  63. /*
  64. * Actions
  65. */
  66. if (GETPOST('cancel', 'alpha')) {
  67. $action = 'list'; $massaction = '';
  68. }
  69. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  70. $massaction = '';
  71. }
  72. $parameters = array();
  73. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  74. if ($reshook < 0) {
  75. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  76. }
  77. if (empty($reshook)) {
  78. // Selection of new fields
  79. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  80. // Purge search criteria
  81. 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
  82. /*foreach($object->fields as $key => $val)
  83. {
  84. $search[$key]='';
  85. }*/
  86. $search_ref = '';
  87. $search_all = '';
  88. $toselect = '';
  89. $search_array_options = array();
  90. }
  91. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  92. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  93. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  94. }
  95. // Mass actions
  96. /*$objectclass='MyObject';
  97. $objectlabel='MyObject';
  98. $permissiontoread = $user->rights->mymodule->read;
  99. $permissiontodelete = $user->rights->mymodule->delete;
  100. $uploaddir = $conf->mymodule->dir_output;
  101. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  102. */
  103. }
  104. /*
  105. * View
  106. */
  107. llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
  108. $form = new Form($db);
  109. if ($filteremail) {
  110. $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
  111. $sql .= " mc.statut as sendstatut";
  112. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
  113. $sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
  114. $sql .= " AND mc.email = '".$db->escape($filteremail)."'";
  115. if ($search_ref) {
  116. $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
  117. }
  118. if ($search_all) {
  119. $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)."%')";
  120. }
  121. if (!$sortorder) {
  122. $sortorder = "ASC";
  123. }
  124. if (!$sortfield) {
  125. $sortfield = "m.rowid";
  126. }
  127. } else {
  128. $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
  129. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  130. $sql .= " WHERE m.entity = ".$conf->entity;
  131. if ($search_ref) {
  132. $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
  133. }
  134. if ($search_all) {
  135. $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)."%')";
  136. }
  137. if (!$sortorder) {
  138. $sortorder = "ASC";
  139. }
  140. if (!$sortfield) {
  141. $sortfield = "m.rowid";
  142. }
  143. }
  144. $sql .= $db->order($sortfield, $sortorder);
  145. $nbtotalofrecords = '';
  146. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  147. $resql = $db->query($sql);
  148. $nbtotalofrecords = $db->num_rows($resql);
  149. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  150. $page = 0;
  151. $offset = 0;
  152. }
  153. }
  154. $sql .= $db->plimit($limit + 1, $offset);
  155. //print $sql;
  156. dol_syslog("comm/mailing/list.php", LOG_DEBUG);
  157. $resql = $db->query($sql);
  158. if ($resql) {
  159. $num = $db->num_rows($resql);
  160. $title = $langs->trans("ListOfEMailings");
  161. if ($filteremail) {
  162. $title .= ' ('.$langs->trans("SentTo", $filteremail).')';
  163. }
  164. $newcardbutton = '';
  165. if ($user->rights->mailing->creer) {
  166. $newcardbutton .= dolGetButtonTitle($langs->trans('NewMailing'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/mailing/card.php?action=create');
  167. }
  168. $i = 0;
  169. $param = "&search_all=".urlencode($search_all);
  170. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  171. $param .= '&contextpage='.urlencode($contextpage);
  172. }
  173. if ($limit > 0 && $limit != $conf->liste_limit) {
  174. $param .= '&limit='.urlencode($limit);
  175. }
  176. if ($filteremail) {
  177. $param .= '&filteremail='.urlencode($filteremail);
  178. }
  179. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  180. if ($optioncss != '') {
  181. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  182. }
  183. print '<input type="hidden" name="token" value="'.newToken().'">';
  184. print '<input type="hidden" name="action" value="list">';
  185. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  186. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  187. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_email', 0, $newcardbutton, '', $limit, 0, 0, 1);
  188. $moreforfilter = '';
  189. print '<div class="div-table-responsive">';
  190. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  191. print '<tr class="liste_titre_filter">';
  192. print '<td class="liste_titre">';
  193. print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  194. print '</td>';
  195. // Title
  196. print '<td class="liste_titre">';
  197. print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
  198. print '</td>';
  199. print '<td class="liste_titre">&nbsp;</td>';
  200. if (!$filteremail) {
  201. print '<td class="liste_titre">&nbsp;</td>';
  202. }
  203. print '<td class="liste_titre">&nbsp;</td>';
  204. print '<td class="liste_titre">&nbsp;</td>';
  205. print '<td class="liste_titre maxwidthsearch">';
  206. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  207. print $searchpicto;
  208. print '</td>';
  209. print "</tr>\n";
  210. print '<tr class="liste_titre">';
  211. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder);
  212. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
  213. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder);
  214. if (!$filteremail) {
  215. print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder);
  216. }
  217. if (!$filteremail) {
  218. print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
  219. } else {
  220. print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
  221. }
  222. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], ($filteremail ? "mc.statut" : "m.statut"), $param, "", 'class="right"', $sortfield, $sortorder);
  223. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', 'class="right"', $sortfield, $sortorder, 'maxwidthsearch ');
  224. print "</tr>\n";
  225. $email = new Mailing($db);
  226. while ($i < min($num, $limit)) {
  227. $obj = $db->fetch_object($resql);
  228. $email->id = $obj->rowid;
  229. $email->ref = $obj->rowid;
  230. print '<tr class="oddeven">';
  231. print '<td>';
  232. print $email->getNomUrl(1);
  233. print '</td>';
  234. // Title
  235. print '<td>'.$obj->title.'</td>';
  236. // Date creation
  237. print '<td class="center">';
  238. print dol_print_date($db->jdate($obj->datec), 'day');
  239. print '</td>';
  240. // Nb of email
  241. if (!$filteremail) {
  242. print '<td class="center">';
  243. $nbemail = $obj->nbemail;
  244. /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
  245. {
  246. $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  247. print $form->textwithpicto($nbemail,$text,1,'warning');
  248. }
  249. else
  250. {
  251. print $nbemail;
  252. }*/
  253. print $nbemail;
  254. print '</td>';
  255. }
  256. // Last send
  257. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi), 'day').'</td>';
  258. print '</td>';
  259. // Status
  260. print '<td class="nowrap right">';
  261. if ($filteremail) {
  262. print $email::libStatutDest($obj->sendstatut, 2);
  263. } else {
  264. print $email->LibStatut($obj->statut, 5);
  265. }
  266. print '</td>';
  267. print '<td></td>';
  268. print "</tr>\n";
  269. $i++;
  270. }
  271. if (empty($num)) {
  272. $colspan = 6;
  273. if (!$filteremail) {
  274. $colspan++;
  275. }
  276. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  277. }
  278. print '</table>';
  279. print '</div>';
  280. print '</form>';
  281. $db->free($resql);
  282. } else {
  283. dol_print_error($db);
  284. }
  285. // End of page
  286. llxFooter();
  287. $db->close();