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
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// 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 " );
2013-01-02 18:43:59 +01:00
// Security check
$result = restrictedArea ( $user , 'mailing' );
2005-08-25 18:55:11 +02:00
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2018-04-21 12:16:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2010-11-20 14:08:44 +01:00
$page = GETPOST ( " page " , 'int' );
2018-09-23 16:09:25 +02: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 ;
2009-01-25 23:04:55 +01:00
if ( ! $sortorder ) $sortorder = " DESC " ;
if ( ! $sortfield ) $sortfield = " m.date_creat " ;
2005-08-25 18:55:11 +02:00
2018-09-23 16:09:25 +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 " );
2015-09-03 09:56:33 +02:00
$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
$extralabels = $extrafields -> fetch_name_optionals_label ( 'mailing' );
2018-11-07 12:49:17 +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 (
'm.titre' => 'Ref' ,
);
2018-09-23 16:09:25 +02:00
/*
* Actions
*/
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
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
{
/* foreach ( $object -> fields as $key => $val )
{
$search [ $key ] = '' ;
} */
$search_ref = '' ;
$search_all = '' ;
$toselect = '' ;
$search_array_options = array ();
}
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
|| 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
}
// Mass actions
/* $objectclass = 'MyObject' ;
$objectlabel = 'MyObject' ;
$permtoread = $user -> rights -> mymodule -> read ;
$permtodelete = $user -> rights -> mymodule -> delete ;
$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
*/
2009-08-12 14:59:14 +02: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
2010-02-21 22:21:12 +01:00
if ( $filteremail )
{
$sql = " SELECT m.rowid, m.titre, 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 ;
2011-02-24 19:22:24 +01:00
$sql .= " AND mc.email = ' " . $db -> escape ( $filteremail ) . " ' " ;
2018-09-23 16:09:25 +02: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 ) . " %') " ;
2010-02-21 22:21:12 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " m.rowid " ;
2010-03-13 00:40:39 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2010-02-21 22:21:12 +01:00
}
else
{
$sql = " SELECT m.rowid, m.titre, 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 ;
2018-09-23 16:09:25 +02: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 ) . " %') " ;
2010-02-21 22:21:12 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " m.rowid " ;
2010-03-13 00:40:39 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2010-02-21 22:21:12 +01:00
}
2005-08-25 18:55:11 +02:00
2010-02-21 22:21:12 +01:00
//print $sql;
2005-08-25 18:55:11 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
2010-02-21 22:21:12 +01:00
$num = $db -> num_rows ( $result );
$title = $langs -> trans ( " ListOfEMailings " );
if ( $filteremail ) $title .= ' (' . $langs -> trans ( " SentTo " , $filteremail ) . ')' ;
2018-04-03 15:28:12 +02:00
2018-04-15 17:37:49 +02:00
$newcardbutton = '' ;
if ( $user -> rights -> mailing -> creer )
{
2018-06-13 22:57:41 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/comm/mailing/card.php?action=create"><span class="valignmiddle">' . $langs -> trans ( 'NewMailing' ) . '</span>' ;
2018-04-18 03:26:15 +02:00
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
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 );
2018-04-07 16:17:40 +02:00
if ( $filteremail ) $param .= '&filteremail=' . urlencode ( $filteremail );
2017-08-02 13:31:53 +02:00
2015-08-15 15:30:12 +02:00
print '<form method="GET" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2016-11-27 13:49:46 +01:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ '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 . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-08-02 13:31:53 +02:00
2018-04-07 16:17:40 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , '' , $num , '' , 'title_generic.png' , 0 , $newcardbutton );
$moreforfilter = '' ;
2017-08-02 13:31:53 +02:00
2016-11-27 13:49:46 +01:00
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">' ;
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>' ;
if ( ! $filteremail ) print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
2016-08-24 19:38:34 +02:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre" align="right">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
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">' ;
2017-08-02 13:31:53 +02: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 );
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 , " " , 'align="right"' , $sortfield , $sortorder );
2017-03-30 16:00:53 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , 'align="right"' , $sortfield , $sortorder , 'maxwidthsearch ' );
print " </tr> \n " ;
2017-08-02 13:31:53 +02:00
2010-02-21 22:21:12 +01:00
$email = new Mailing ( $db );
2016-11-05 03:27:56 +01:00
while ( $i < min ( $num , $limit ))
2010-02-21 22:21:12 +01:00
{
$obj = $db -> fetch_object ( $result );
2018-09-23 15:58:33 +02:00
$email -> id = $obj -> rowid ;
$email -> ref = $obj -> rowid ;
2010-02-21 22:21:12 +01:00
2017-03-30 16:00:53 +02:00
print " <tr> " ;
2018-09-23 15:58:33 +02:00
print '<td>' ;
print $email -> getNomUrl ( 1 );
print '</td>' ;
2010-02-21 22:21:12 +01:00
print '<td>' . $obj -> titre . '</td>' ;
// Date creation
2018-09-23 15:58:33 +02:00
2010-02-21 22:21:12 +01:00
print '<td align="center">' ;
print dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' );
print '</td>' ;
2018-09-23 15:58:33 +02:00
2010-02-21 22:21:12 +01:00
// Nb of email
if ( ! $filteremail )
{
print '<td align="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 )
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
2013-04-25 01:13:13 +02: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
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2010-02-21 22:21:12 +01:00
if ( $filteremail )
{
2015-10-01 16:09:04 +02:00
print $email :: libStatutDest ( $obj -> sendstatut , 2 );
2010-02-21 22:21:12 +01: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
2010-02-21 22:21:12 +01:00
print " </tr> \n " ;
$i ++ ;
}
2016-11-27 13:49:46 +01:00
print '</table>' ;
print '</div>' ;
print '</form>' ;
2010-02-21 22:21:12 +01:00
$db -> free ( $result );
2005-08-25 18:55:11 +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 ();