dolibarr/htdocs/comm/mailing/list.php

342 lines
11 KiB
PHP
Raw Normal View History

2005-08-25 18:55:11 +02:00
<?php
2016-11-05 03:27:56 +01:00
/* Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
2005-08-25 18:55:11 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2005-08-25 18:55:11 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2005-08-25 18:55:11 +02:00
*/
/**
* \file htdocs/comm/mailing/list.php
2009-08-12 14:59:14 +02:00
* \ingroup mailing
* \brief Liste des mailings
*/
2005-08-25 18:55:11 +02:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
2005-08-25 18:55:11 +02:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
2011-05-25 21:21:34 +02:00
$langs->load("mails");
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
2020-04-12 18:13:43 +02:00
$optioncss = GETPOST('optioncss', 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-23 18:59:19 +01:00
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
$offset = $limit * $page;
2010-11-20 14:08:44 +01:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-23 18:59:19 +01:00
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "m.date_creat";
}
2005-08-25 18:55:11 +02:00
$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
$filteremail = GETPOST('filteremail', 'alpha');
2018-11-07 12:49:17 +01:00
$object = new Mailing($db);
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2016-08-24 19:38:34 +02:00
$hookmanager->initHooks(array('mailinglist'));
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
2019-09-28 10:55:09 +02:00
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
2016-08-24 19:38:34 +02:00
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
'm.titre'=>'Ref',
2016-08-24 19:38:34 +02:00
);
2021-03-29 22:43:39 +02:00
// Security check
if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
accessforbidden();
}
//$result = restrictedArea($user, 'mailing');
2018-09-23 16:09:25 +02:00
/*
* Actions
*/
2021-02-23 18:59:19 +01:00
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
2018-09-23 16:09:25 +02:00
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2021-02-23 18:59:19 +01:00
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
2018-09-23 16:09:25 +02:00
2021-02-23 18:59:19 +01:00
if (empty($reshook)) {
2018-09-23 16:09:25 +02:00
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
2021-02-23 18:59:19 +01:00
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
2018-09-23 16:09:25 +02:00
/*foreach($object->fields as $key => $val)
{
$search[$key]='';
}*/
$search_ref = '';
$search_all = '';
$toselect = '';
$search_array_options = array();
2018-09-23 16:09:25 +02:00
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
2021-02-23 18:59:19 +01:00
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
2018-09-23 16:09:25 +02:00
}
// Mass actions
/*$objectclass='MyObject';
$objectlabel='MyObject';
$permissiontoread = $user->rights->mymodule->read;
$permissiontodelete = $user->rights->mymodule->delete;
2018-09-23 16:09:25 +02:00
$uploaddir = $conf->mymodule->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
*/
}
2005-08-25 18:55:11 +02:00
/*
* View
*/
llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
2005-08-25 18:55:11 +02:00
$form = new Form($db);
2005-08-25 18:55:11 +02:00
2021-01-28 09:25:58 +01:00
if ($filteremail) {
$sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
$sql .= " mc.statut as sendstatut";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
$sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
$sql .= " AND mc.email = '".$db->escape($filteremail)."'";
2021-02-23 18:59:19 +01:00
if ($search_ref) {
$sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
}
if ($search_all) {
$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)."%')";
}
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "m.rowid";
}
2020-05-21 15:05:19 +02:00
} else {
2021-01-28 09:25:58 +01:00
$sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
$sql .= " WHERE m.entity = ".$conf->entity;
2021-02-23 18:59:19 +01:00
if ($search_ref) {
$sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
}
if ($search_all) {
$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)."%')";
}
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "m.rowid";
}
}
2005-08-25 18:55:11 +02:00
2020-04-12 18:13:43 +02:00
$sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
2021-02-23 18:59:19 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2020-04-12 18:13:43 +02:00
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
2021-02-23 18:59:19 +01:00
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-04-12 18:13:43 +02:00
$page = 0;
$offset = 0;
}
}
$sql .= $db->plimit($limit + 1, $offset);
//print $sql;
2020-04-12 18:13:43 +02:00
dol_syslog("comm/mailing/list.php", LOG_DEBUG);
$resql = $db->query($sql);
2021-02-23 18:59:19 +01:00
if ($resql) {
2020-04-12 18:13:43 +02:00
$num = $db->num_rows($resql);
$title = $langs->trans("ListOfEMailings");
2021-02-23 18:59:19 +01:00
if ($filteremail) {
$title .= ' ('.$langs->trans("SentTo", $filteremail).')';
}
$newcardbutton = '';
2021-02-23 18:59:19 +01:00
if ($user->rights->mailing->creer) {
$newcardbutton .= dolGetButtonTitle($langs->trans('NewMailing'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/mailing/card.php?action=create');
2018-04-15 17:37:49 +02:00
}
$i = 0;
2018-09-23 16:09:25 +02:00
$param = "&search_all=".urlencode($search_all);
2021-02-23 18:59:19 +01:00
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($filteremail) {
$param .= '&filteremail='.urlencode($filteremail);
}
2020-04-12 18:13:43 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
2021-02-23 18:59:19 +01:00
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2020-05-11 19:00:27 +02:00
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_email', 0, $newcardbutton, '', $limit, 0, 0, 1);
2018-04-07 16:17:40 +02:00
$moreforfilter = '';
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre_filter">';
print '<td class="liste_titre">';
2018-09-23 16:09:25 +02:00
print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
// Title
print '<td class="liste_titre">';
2018-09-23 16:09:25 +02:00
print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
print '</td>';
print '<td class="liste_titre">&nbsp;</td>';
2021-02-23 18:59:19 +01:00
if (!$filteremail) {
print '<td class="liste_titre">&nbsp;</td>';
}
print '<td class="liste_titre">&nbsp;</td>';
2016-08-24 19:38:34 +02:00
print '<td class="liste_titre">&nbsp;</td>';
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
2017-05-14 21:06:33 +02:00
print $searchpicto;
2016-08-24 19:38:34 +02:00
print '</td>';
print "</tr>\n";
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder);
2021-02-23 18:59:19 +01:00
if (!$filteremail) {
print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder);
}
if (!$filteremail) {
print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
} else {
print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
}
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], ($filteremail ? "mc.statut" : "m.statut"), $param, "", 'class="right"', $sortfield, $sortorder);
2019-02-04 10:27:26 +01:00
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', 'class="right"', $sortfield, $sortorder, 'maxwidthsearch ');
2017-03-30 16:00:53 +02:00
print "</tr>\n";
$email = new Mailing($db);
2021-02-23 18:59:19 +01:00
while ($i < min($num, $limit)) {
2020-04-12 18:13:43 +02:00
$obj = $db->fetch_object($resql);
2018-09-23 15:58:33 +02:00
$email->id = $obj->rowid;
$email->ref = $obj->rowid;
2020-04-12 18:13:43 +02:00
print '<tr class="oddeven">';
2018-09-23 15:58:33 +02:00
print '<td>';
print $email->getNomUrl(1);
print '</td>';
2021-01-28 09:25:58 +01:00
// Title
print '<td>'.$obj->title.'</td>';
2018-09-23 15:58:33 +02:00
2021-01-28 09:25:58 +01:00
// Date creation
2019-12-12 10:31:08 +01:00
print '<td class="center">';
print dol_print_date($db->jdate($obj->datec), 'day');
print '</td>';
2018-09-23 15:58:33 +02:00
// Nb of email
2021-02-23 18:59:19 +01:00
if (!$filteremail) {
2019-12-12 10:31:08 +01:00
print '<td class="center">';
$nbemail = $obj->nbemail;
2017-01-29 20:33:08 +01:00
/*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
{
$text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
print $form->textwithpicto($nbemail,$text,1,'warning');
}
else
{
print $nbemail;
2017-01-29 20:33:08 +01:00
}*/
print $nbemail;
print '</td>';
}
2018-09-23 15:58:33 +02:00
// Last send
print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi), 'day').'</td>';
print '</td>';
2018-09-23 15:58:33 +02:00
// Status
2019-02-04 10:27:26 +01:00
print '<td class="nowrap right">';
2021-02-23 18:59:19 +01:00
if ($filteremail) {
print $email::libStatutDest($obj->sendstatut, 2);
2020-05-21 15:05:19 +02:00
} else {
print $email->LibStatut($obj->statut, 5);
}
print '</td>';
2018-09-23 15:58:33 +02:00
2016-08-24 19:38:34 +02:00
print '<td></td>';
2018-09-23 15:58:33 +02:00
print "</tr>\n";
$i++;
}
2019-11-20 12:45:15 +01:00
if (empty($num)) {
$colspan = 6;
2021-02-23 18:59:19 +01:00
if (!$filteremail) {
$colspan++;
}
2019-11-20 12:45:15 +01:00
print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
print '</table>';
print '</div>';
print '</form>';
2020-04-12 18:13:43 +02:00
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2005-08-25 18:55:11 +02:00
}
2018-07-29 17:17:29 +02:00
// End of page
llxFooter();
2012-05-09 18:16:09 +02:00
$db->close();