list.php 12 KB

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