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
2013-01-16 15:36:08 +01:00
* 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
*/
/**
2014-09-18 20:33:37 +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
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
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 " );
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2019-11-13 19:35:39 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-04-12 18:13:43 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2020-03-13 13:07:11 +01:00
$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
2015-12-16 19:38:40 +01:00
$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
2019-11-13 19:35:39 +01: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' );
2010-02-21 22:21:12 +01:00
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
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2019-09-28 10:55:09 +02:00
2019-11-13 19:35:39 +01: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 (
2020-10-31 14:32:18 +01:00
'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
2019-11-13 19:35:39 +01: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 = '' ;
2019-11-13 19:35:39 +01:00
$toselect = '' ;
$search_array_options = array ();
2018-09-23 16:09:25 +02:00
}
2019-01-27 11:55:16 +01: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' )) {
2019-11-13 19:35:39 +01:00
$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' ;
2019-11-04 15:33:49 +01:00
$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' ;
*/
}
2010-02-21 22:21:12 +01:00
2005-08-25 18:55:11 +02:00
2009-01-25 23:04:55 +01:00
/*
* View
*/
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " Mailing " ), 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing' );
2005-08-25 18:55:11 +02:00
2011-11-08 10:18:45 +01: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, " ;
2019-11-13 19:35:39 +01:00
$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 " ;
2019-11-13 19:35:39 +01:00
$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 " ;
}
2010-02-21 22:21:12 +01:00
}
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 );
2010-02-21 22:21:12 +01:00
//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 );
2010-02-21 22:21:12 +01:00
2019-11-13 19:35:39 +01:00
$title = $langs -> trans ( " ListOfEMailings " );
2021-02-23 18:59:19 +01:00
if ( $filteremail ) {
$title .= ' (' . $langs -> trans ( " SentTo " , $filteremail ) . ')' ;
}
2018-04-03 15:28:12 +02:00
2019-11-13 19:35:39 +01:00
$newcardbutton = '' ;
2021-02-23 18:59:19 +01:00
if ( $user -> rights -> mailing -> creer ) {
2020-10-31 14:32:18 +01:00
$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
}
2018-04-03 15:28:12 +02:00
2010-02-21 22:21:12 +01: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 );
}
2017-08-02 13:31:53 +02:00
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 . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2016-11-27 13:49:46 +01:00
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2017-08-02 13:31:53 +02:00
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 = '' ;
2017-08-02 13:31:53 +02:00
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2016-11-27 13:49:46 +01:00
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre_filter">' ;
2010-02-21 22:21:12 +01:00
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 ) . '">' ;
2010-02-21 22:21:12 +01:00
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 ) . '">' ;
2010-02-21 22:21:12 +01:00
print '</td>' ;
print '<td class="liste_titre"> </td>' ;
2021-02-23 18:59:19 +01:00
if ( ! $filteremail ) {
print '<td class="liste_titre"> </td>' ;
}
2010-02-21 22:21:12 +01:00
print '<td class="liste_titre"> </td>' ;
2016-08-24 19:38:34 +02:00
print '<td class="liste_titre"> </td>' ;
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2019-11-13 19:35:39 +01:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
2017-05-14 21:06:33 +02:00
print $searchpicto ;
2016-08-24 19:38:34 +02:00
print '</td>' ;
2010-02-21 22:21:12 +01:00
print " </tr> \n " ;
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre">' ;
2019-01-27 11:55:16 +01:00
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 );
}
2019-11-13 19:35:39 +01:00
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 " ;
2017-08-02 13:31:53 +02:00
2019-11-13 19:35:39 +01:00
$email = new Mailing ( $db );
2010-02-21 22:21:12 +01:00
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 );
2010-02-21 22:21:12 +01:00
2018-09-23 15:58:33 +02:00
$email -> id = $obj -> rowid ;
$email -> ref = $obj -> rowid ;
2010-02-21 22:21:12 +01:00
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
2020-10-07 17:41:36 +02:00
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">' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' );
2010-02-21 22:21:12 +01:00
print '</td>' ;
2018-09-23 15:58:33 +02:00
2010-02-21 22:21:12 +01: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">' ;
2010-02-21 22:21:12 +01:00
$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 )
2010-02-21 22:21:12 +01:00
{
$text = $langs -> trans ( 'LimitSendingEmailing' , $conf -> global -> MAILING_LIMIT_SENDBYWEB );
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $nbemail , $text , 1 , 'warning' );
2010-02-21 22:21:12 +01:00
}
else
{
print $nbemail ;
2017-01-29 20:33:08 +01:00
} */
print $nbemail ;
2010-02-21 22:21:12 +01:00
print '</td>' ;
}
2018-09-23 15:58:33 +02:00
2010-02-21 22:21:12 +01:00
// Last send
2019-01-27 11:55:16 +01:00
print '<td align="center" class="nowrap">' . dol_print_date ( $db -> jdate ( $obj -> date_envoi ), 'day' ) . '</td>' ;
2010-02-21 22:21:12 +01:00
print '</td>' ;
2018-09-23 15:58:33 +02:00
2010-02-21 22:21:12 +01: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 ) {
2019-01-27 11:55:16 +01:00
print $email :: libStatutDest ( $obj -> sendstatut , 2 );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print $email -> LibStatut ( $obj -> statut , 5 );
2010-02-21 22:21:12 +01:00
}
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
2010-02-21 22:21:12 +01: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>' ;
}
2016-11-27 13:49:46 +01:00
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 {
2010-02-21 22:21:12 +01:00
dol_print_error ( $db );
2005-08-25 18:55:11 +02:00
}
2018-07-29 17:17:29 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-05-09 18:16:09 +02:00
$db -> close ();