2012-08-22 23:27:53 +02:00
< ? php
2006-10-29 20:09:49 +01:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-05-06 11:22:58 +02:00
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ uers . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ inodbox . com >
2014-05-29 14:26:27 +02:00
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - concept . pro >
2005-01-05 16:26:05 +01: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-01-05 16:26:05 +01: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-01-05 16:26:05 +01:00
*/
2005-04-07 01:23:01 +02:00
/**
2009-01-25 23:04:55 +01:00
* \file htdocs / comm / mailing / cibles . php
* \ingroup mailing
2010-12-01 22:16:28 +01:00
* \brief Page to define emailing targets
2009-01-25 23:04:55 +01:00
*/
2005-01-14 20:24:00 +01: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 . '/core/modules/mailings/modules_mailings.php' ;
require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/mailing.class.php' ;
2014-05-29 14:26:27 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmailing.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/emailing.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2005-01-05 16:26:05 +01:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
2005-01-14 20:24:00 +01:00
$langs -> load ( " mails " );
2009-07-29 20:41:39 +02:00
// Security check
2012-01-26 23:05:59 +01:00
if ( ! $user -> rights -> mailing -> lire || $user -> societe_id > 0 ) accessforbidden ();
2008-12-07 20:19:32 +01:00
2008-05-15 19:59:37 +02:00
2016-11-11 14:03:57 +01:00
// Load variable for pagination
2017-06-08 14:55:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2016-11-11 14:03:57 +01:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-02-12 13:58:24 +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 ( ! $sortfield ) $sortfield = " email " ;
2016-11-11 14:03:57 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
2005-02-15 22:33:36 +01:00
2012-06-14 09:12:52 +02:00
$id = GETPOST ( 'id' , 'int' );
$rowid = GETPOST ( 'rowid' , 'int' );
2017-05-16 13:27:32 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2013-02-23 15:26:39 +01:00
$search_lastname = GETPOST ( " search_lastname " );
$search_firstname = GETPOST ( " search_firstname " );
2012-01-26 23:05:59 +01:00
$search_email = GETPOST ( " search_email " );
2017-08-25 19:26:48 +02:00
$search_other = GETPOST ( " search_other " );
2014-05-29 14:26:27 +02:00
$search_dest_status = GETPOST ( 'search_dest_status' );
2012-01-26 23:05:59 +01:00
// Search modules dirs
2012-05-09 16:40:54 +02:00
$modulesdir = dolGetModulesDirs ( '/mailings' );
2012-01-26 23:05:59 +01:00
2012-06-13 21:45:47 +02:00
$object = new Mailing ( $db );
2005-02-15 22:18:35 +01:00
2005-02-12 00:41:42 +01:00
/*
* Actions
*/
2009-08-12 14:59:14 +02:00
2012-01-26 23:05:59 +01:00
if ( $action == 'add' )
2005-01-05 16:26:05 +01:00
{
2018-12-11 10:15:13 +01:00
$module = GETPOST ( " module " , 'alpha' );
2012-01-26 23:05:59 +01:00
$result =- 1 ;
2009-01-26 22:57:14 +01:00
2012-01-26 23:05:59 +01:00
foreach ( $modulesdir as $dir )
2009-01-26 22:57:14 +01:00
{
2012-01-26 23:05:59 +01:00
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog ( " Scan directory " . $dir . " for modules " );
2009-01-26 22:57:14 +01:00
2015-11-06 09:46:18 +01:00
// Loading Class
2012-01-26 23:05:59 +01:00
$file = $dir . " / " . $module . " .modules.php " ;
$classname = " mailing_ " . $module ;
2009-01-26 22:57:14 +01:00
2012-01-26 23:05:59 +01:00
if ( file_exists ( $file ))
{
2012-08-22 23:11:24 +02:00
require_once $file ;
2009-01-26 22:57:14 +01:00
2012-01-26 23:05:59 +01:00
// Add targets into database
$obj = new $classname ( $db );
2016-02-10 23:48:18 +01:00
dol_syslog ( " Call add_to_target on class " . $classname );
2018-12-11 10:15:13 +01:00
$result = $obj -> add_to_target ( $id );
2009-01-26 22:57:14 +01:00
}
}
if ( $result > 0 )
{
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " XTargetsAdded " , $result ), null , 'mesgs' );
2014-08-25 19:32:36 +02:00
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2009-01-26 22:57:14 +01:00
exit ;
}
if ( $result == 0 )
{
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " WarningNoEMailsAdded " ), null , 'warnings' );
2009-01-26 22:57:14 +01:00
}
if ( $result < 0 )
{
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " Error " ) . ( $obj -> error ? ' ' . $obj -> error : '' ), null , 'errors' );
2009-01-26 22:57:14 +01:00
}
2005-01-05 16:26:05 +01:00
}
2013-05-27 16:03:10 +02:00
if ( GETPOST ( 'clearlist' ))
2005-02-12 18:41:13 +01:00
{
2015-11-06 09:36:16 +01:00
// Loading Class
2015-02-10 11:38:13 +01:00
$obj = new MailingTargets ( $db );
2012-01-26 23:05:59 +01:00
$obj -> clear_target ( $id );
2016-06-19 11:59:55 +02:00
/* Avoid this to allow reposition
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2009-01-26 22:57:14 +01:00
exit ;
2016-06-19 11:59:55 +02:00
*/
2005-02-12 18:41:13 +01:00
}
2012-01-26 23:05:59 +01:00
if ( $action == 'delete' )
2005-04-20 20:47:41 +02:00
{
2009-01-26 22:57:14 +01:00
// Ici, rowid indique le destinataire et id le mailing
2012-06-14 09:12:52 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " mailing_cibles WHERE rowid= " . $rowid ;
2009-01-26 22:57:14 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
2012-06-14 09:12:52 +02:00
{
2012-05-21 16:16:24 +02:00
if ( ! empty ( $id ))
{
2015-02-10 11:38:13 +01:00
$obj = new MailingTargets ( $db );
2012-06-15 11:20:09 +02:00
$obj -> update_nb ( $id );
2012-11-17 00:58:43 +01:00
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
2012-06-14 09:43:05 +02:00
exit ;
2012-05-21 16:16:24 +02:00
}
else
{
2014-09-18 20:33:37 +02:00
header ( " Location: list.php " );
2012-05-21 16:16:24 +02:00
exit ;
}
2009-01-26 22:57:14 +01:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-01-26 22:57:14 +01:00
}
2005-04-20 20:47:41 +02:00
}
2005-01-14 20:24:00 +01:00
2017-08-25 21:12:22 +02:00
// 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
2008-04-04 13:31:52 +02:00
{
2013-02-23 15:26:39 +01:00
$search_lastname = '' ;
$search_firstname = '' ;
2008-04-04 13:31:52 +02:00
$search_email = '' ;
2017-08-25 21:12:22 +02:00
$search_other = '' ;
2017-05-04 13:41:37 +02:00
$search_dest_status = '' ;
2008-04-04 13:31:52 +02:00
}
2005-02-12 00:41:42 +01:00
2008-08-01 22:59:33 +02:00
2005-01-05 16:26:05 +01:00
/*
2009-08-12 14:59:14 +02:00
* View
2005-01-05 16:26:05 +01:00
*/
2018-01-29 12:58:33 +01:00
2009-08-12 14:59:14 +02:00
llxHeader ( '' , $langs -> trans ( " Mailing " ), 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing' );
2005-01-05 16:26:05 +01:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2014-05-29 14:26:27 +02:00
$formmailing = new FormMailing ( $db );
2009-07-29 20:41:39 +02:00
2012-06-13 21:45:47 +02:00
if ( $object -> fetch ( $id ) >= 0 )
2005-01-05 16:26:05 +01:00
{
2012-06-13 21:45:47 +02:00
$head = emailing_prepare_head ( $object );
2009-01-25 23:04:55 +01:00
2017-04-17 13:02:40 +02:00
dol_fiche_head ( $head , 'targets' , $langs -> trans ( " Mailing " ), - 1 , 'email' );
2009-01-25 23:04:55 +01:00
2014-09-18 20:33:37 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/list.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2012-07-28 21:49:47 +02:00
2016-11-11 01:55:53 +01:00
$morehtmlright = '' ;
2018-01-29 12:46:07 +01:00
$nbtry = $nbok = 0 ;
if ( $object -> statut == 2 || $object -> statut == 3 )
{
$nbtry = $object -> countNbOfTargets ( 'alreadysent' );
$nbko = $object -> countNbOfTargets ( 'alreadysentko' );
$morehtmlright .= ' (' . $nbtry . '/' . $object -> nbemail ;
if ( $nbko ) $morehtmlright .= ' - ' . $nbko . ' ' . $langs -> trans ( " Error " );
$morehtmlright .= ') ' ;
}
2017-08-02 13:31:53 +02:00
2016-11-11 01:55:53 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , '' , '' , 0 , '' , $morehtmlright );
2017-04-17 13:02:40 +02:00
print '<div class="fichecenter">' ;
2016-11-11 01:55:53 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-08-02 13:31:53 +02:00
2016-11-11 01:55:53 +01:00
print '<table class="border" width="100%">' ;
2017-04-17 13:02:40 +02:00
2016-11-11 01:55:53 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " MailTitle " ) . '</td><td colspan="3">' . $object -> titre . '</td></tr>' ;
2009-07-29 20:41:39 +02:00
2016-07-06 22:28:13 +02:00
print '<tr><td>' . $langs -> trans ( " MailFrom " ) . '</td><td colspan="3">' . dol_print_email ( $object -> email_from , 0 , 0 , 0 , 0 , 1 ) . '</td></tr>' ;
2009-07-29 20:41:39 +02:00
// Errors to
2016-07-06 22:28:13 +02:00
print '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td colspan="3">' . dol_print_email ( $object -> email_errorsto , 0 , 0 , 0 , 0 , 1 );
2009-07-29 20:41:39 +02:00
print '</td></tr>' ;
// Nb of distinct emails
2016-07-06 22:28:13 +02:00
print '<tr><td>' ;
2009-08-26 11:50:00 +02:00
print $langs -> trans ( " TotalNbOfDistinctRecipients " );
print '</td><td colspan="3">' ;
2018-01-26 15:12:40 +01:00
$nbemail = ( $object -> nbemail ? $object -> nbemail : 0 );
if ( is_numeric ( $nbemail ))
2009-08-26 11:50:00 +02:00
{
2018-01-26 15:12:40 +01:00
$text = '' ;
2018-01-29 12:46:07 +01:00
if (( ! empty ( $conf -> global -> MAILING_LIMIT_SENDBYWEB ) && $conf -> global -> MAILING_LIMIT_SENDBYWEB < $nbemail ) && ( $object -> statut == 1 || ( $object -> statut == 2 && $nbtry < $nbemail )))
2018-01-26 15:12:40 +01:00
{
if ( $conf -> global -> MAILING_LIMIT_SENDBYWEB > 0 )
{
$text .= $langs -> trans ( 'LimitSendingEmailing' , $conf -> global -> MAILING_LIMIT_SENDBYWEB );
}
else
{
$text .= $langs -> trans ( 'SendingFromWebInterfaceIsNotAllowed' );
}
}
if ( empty ( $nbemail )) $nbemail .= ' ' . img_warning ( '' ) . ' <font class="warning">' . $langs -> trans ( " NoTargetYet " ) . '</font>' ;
if ( $text )
{
print $form -> textwithpicto ( $nbemail , $text , 1 , 'warning' );
}
else
{
print $nbemail ;
}
2009-08-26 11:50:00 +02:00
}
print '</td></tr>' ;
2009-07-29 20:41:39 +02:00
2009-01-26 22:57:14 +01:00
print '</table>' ;
print " </div> " ;
2017-04-17 13:02:40 +02:00
dol_fiche_end ();
2017-08-02 13:31:53 +02:00
2017-11-03 16:29:23 +01:00
print '<br>' ;
2009-01-26 22:57:14 +01:00
2017-01-29 15:31:22 +01:00
$allowaddtarget = ( $object -> statut == 0 );
2013-06-12 22:12:06 +02:00
2010-12-13 19:40:04 +01:00
// Show email selectors
2013-06-12 22:12:06 +02:00
if ( $allowaddtarget && $user -> rights -> mailing -> creer )
2009-01-26 22:57:14 +01:00
{
2016-05-06 12:15:44 +02:00
print load_fiche_titre ( $langs -> trans ( " ToAddRecipientsChooseHere " ), ( $user -> admin ? info_admin ( $langs -> trans ( " YouCanAddYourOwnPredefindedListHere " ), 1 ) : '' ), 'title_generic' );
2009-07-29 20:41:39 +02:00
2016-11-26 12:21:50 +01:00
//print '<table class="noborder" width="100%">';
2018-03-02 11:18:29 +01:00
print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">' ;
2017-08-02 13:31:53 +02:00
2016-11-26 12:21:50 +01:00
//print '<tr class="liste_titre">';
print '<div class="tagtr liste_titre">' ;
//print '<td class="liste_titre">'.$langs->trans("RecipientSelectionModules").'</td>';
print '<div class="tagtd">' . $langs -> trans ( " RecipientSelectionModules " ) . '</div>' ;
//print '<td class="liste_titre" align="center">'.$langs->trans("NbOfUniqueEMails").'</td>';
print '<div class="tagtd" align="center">' . $langs -> trans ( " NbOfUniqueEMails " ) . '</div>' ;
//print '<td class="liste_titre" align="left">'.$langs->trans("Filter").'</td>';
print '<div class="tagtd" align="left">' . $langs -> trans ( " Filter " ) . '</div>' ;
//print '<td class="liste_titre" align="center"> </td>';
print '<div class="tagtd"> </div>' ;
//print "</tr>\n";
print '</div>' ;
2017-08-02 13:31:53 +02:00
2009-01-26 22:57:14 +01:00
clearstatcache ();
2008-12-07 20:19:32 +01:00
2012-01-26 23:05:59 +01:00
foreach ( $modulesdir as $dir )
2009-01-26 22:57:14 +01:00
{
2012-01-26 23:05:59 +01:00
$modulenames = array ();
2009-01-25 23:04:55 +01:00
2012-01-26 23:05:59 +01:00
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog ( " Scan directory " . $dir . " for modules " );
$handle =@ opendir ( $dir );
if ( is_resource ( $handle ))
2009-01-26 22:57:14 +01:00
{
2012-01-26 23:05:59 +01:00
while (( $file = readdir ( $handle )) !== false )
2009-01-25 23:04:55 +01:00
{
2012-01-26 23:05:59 +01:00
if ( substr ( $file , 0 , 1 ) <> '.' && substr ( $file , 0 , 3 ) <> 'CVS' )
2009-01-26 22:57:14 +01:00
{
2012-01-26 23:05:59 +01:00
if ( preg_match ( " /(.*) \ .modules \ .php $ /i " , $file , $reg ))
2009-01-26 22:57:14 +01:00
{
2012-01-26 23:05:59 +01:00
if ( $reg [ 1 ] == 'example' ) continue ;
$modulenames [] = $reg [ 1 ];
2009-01-26 22:57:14 +01:00
}
}
2012-01-26 23:05:59 +01:00
}
closedir ( $handle );
}
// Sort $modulenames
2012-01-26 23:08:20 +01:00
sort ( $modulenames );
2012-01-26 23:05:59 +01:00
2018-08-29 11:57:43 +02:00
$var = true ;
2012-01-26 23:05:59 +01:00
// Loop on each submodule
2018-08-29 11:57:43 +02:00
foreach ( $modulenames as $modulename )
{
2015-11-06 09:46:18 +01:00
// Loading Class
2012-01-26 23:05:59 +01:00
$file = $dir . $modulename . " .modules.php " ;
$classname = " mailing_ " . $modulename ;
2012-08-22 23:11:24 +02:00
require_once $file ;
2012-01-26 23:05:59 +01:00
$obj = new $classname ( $db );
2014-11-29 12:40:45 +01:00
// Check dependencies
$qualified = ( isset ( $obj -> enabled ) ? $obj -> enabled : 1 );
2012-01-26 23:05:59 +01:00
foreach ( $obj -> require_module as $key )
{
if ( ! $conf -> $key -> enabled || ( ! $user -> admin && $obj -> require_admin ))
{
$qualified = 0 ;
//print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
break ;
}
}
// Si le module mailing est qualifie
2018-08-29 10:40:30 +02:00
if ( $qualified )
{
2018-12-11 09:52:00 +01:00
$var = ! $var ;
2013-06-12 22:12:06 +02:00
if ( $allowaddtarget )
2012-01-26 23:05:59 +01:00
{
2018-12-11 09:52:00 +01:00
print '<form ' . $bctag [ $var ] . ' name="' . $modulename . '" action="' . $_SERVER [ 'PHP_SELF' ] . '?action=add&id=' . $object -> id . '&module=' . $modulename . '" method="POST" enctype="multipart/form-data">' ;
2012-01-26 23:05:59 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
}
2016-11-26 12:21:50 +01:00
else
{
2018-12-11 09:52:00 +01:00
print '<div ' . $bctag [ $var ] . '>' ;
2016-11-26 12:21:50 +01:00
}
2012-01-26 23:05:59 +01:00
2016-11-26 12:21:50 +01:00
print '<div class="tagtd">' ;
2012-11-17 00:58:43 +01:00
if ( empty ( $obj -> picto )) $obj -> picto = 'generic' ;
2017-08-25 21:12:22 +02:00
print img_object ( $langs -> trans ( " EmailingTargetSelector " ) . ': ' . get_class ( $obj ), $obj -> picto );
2016-11-26 12:21:50 +01:00
print ' ' ;
print $obj -> getDesc ();
print '</div>' ;
2017-08-02 13:31:53 +02:00
2014-08-25 19:32:36 +02:00
try {
$nbofrecipient = $obj -> getNbOfRecipients ( '' );
}
catch ( Exception $e )
{
dol_syslog ( $e -> getMessage (), LOG_ERR );
}
2016-11-26 12:21:50 +01:00
print '<div class="tagtd center">' ;
2012-01-26 23:05:59 +01:00
if ( $nbofrecipient >= 0 )
{
print $nbofrecipient ;
}
else
{
print $langs -> trans ( " Error " ) . ' ' . img_error ( $obj -> error );
}
2016-11-26 12:21:50 +01:00
print '</div>' ;
2017-08-02 13:31:53 +02:00
2016-11-26 12:21:50 +01:00
print '<div class="tagtd" align="left">' ;
if ( $allowaddtarget )
2014-08-25 19:32:36 +02:00
{
2016-11-26 12:21:50 +01:00
try {
$filter = $obj -> formFilter ();
}
catch ( Exception $e )
{
dol_syslog ( $e -> getMessage (), LOG_ERR );
}
if ( $filter ) print $filter ;
else print $langs -> trans ( " None " );
2014-08-25 19:32:36 +02:00
}
2016-11-26 12:21:50 +01:00
print '</div>' ;
2017-08-02 13:31:53 +02:00
2016-11-26 12:21:50 +01:00
print '<div class="tagtd" align="right">' ;
2013-06-12 22:12:06 +02:00
if ( $allowaddtarget )
2012-01-26 23:05:59 +01:00
{
2016-11-26 12:21:50 +01:00
print '<input type="submit" class="button" name="button_' . $modulename . '" value="' . $langs -> trans ( " Add " ) . '">' ;
2012-01-26 23:05:59 +01:00
}
else
{
2016-11-26 12:21:50 +01:00
print '<input type="submit" class="button disabled" disabled="disabled" name="button_' . $modulename . '" value="' . $langs -> trans ( " Add " ) . '">' ;
2012-01-26 23:05:59 +01:00
//print $langs->trans("MailNoChangePossible");
print " " ;
}
2016-11-26 12:21:50 +01:00
print '</div>' ;
2017-08-02 13:31:53 +02:00
2013-06-12 22:12:06 +02:00
if ( $allowaddtarget ) print '</form>' ;
2016-11-26 12:21:50 +01:00
else print '</div>' ;
2008-12-04 18:52:32 +01:00
}
2009-01-26 22:57:14 +01:00
}
} // End foreach dir
2009-01-25 23:04:55 +01:00
2016-11-26 12:21:50 +01:00
print '</div>' ;
2017-08-02 13:31:53 +02:00
2016-11-26 12:21:50 +01:00
print '<br><br>' ;
2009-01-26 22:57:14 +01:00
}
2009-01-25 23:04:55 +01:00
2009-01-26 22:57:14 +01:00
// List of selected targets
2016-11-11 14:03:57 +01:00
$sql = " SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type, mc.error_text " ;
2009-01-26 22:57:14 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing_cibles as mc " ;
2012-06-13 21:45:47 +02:00
$sql .= " WHERE mc.fk_mailing= " . $object -> id ;
2017-08-25 19:26:48 +02:00
if ( $search_lastname ) $sql .= natural_search ( " mc.lastname " , $search_lastname );
if ( $search_firstname ) $sql .= natural_search ( " mc.firstname " , $search_firstname );
if ( $search_email ) $sql .= natural_search ( " mc.email " , $search_email );
if ( $search_other ) $sql .= natural_search ( " mc.other " , $search_other );
2017-05-04 13:41:37 +02:00
if ( $search_dest_status != '' && $search_dest_status >= - 1 ) $sql .= " AND mc.statut= " . $db -> escape ( $search_dest_status ) . " " ;
2010-03-13 00:40:39 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2016-02-12 13:58:24 +01:00
2016-02-12 14:21:44 +01:00
// Count total nb of records
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2016-02-12 14:21:44 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2018-04-24 11:37:57 +02:00
if (( $page * $limit ) > $nbtotalofrecords ) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
$page = 0 ;
$offset = 0 ;
}
2016-02-12 14:21:44 +01:00
}
2018-04-24 11:37:57 +02:00
2016-02-12 14:21:44 +01:00
//$nbtotalofrecords=$object->nbemail; // nbemail is a denormalized field storing nb of targets
2016-02-12 13:58:24 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2017-08-02 13:31:53 +02:00
2009-01-26 22:57:14 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2017-08-02 13:31:53 +02:00
2009-01-26 22:57:14 +01:00
$num = $db -> num_rows ( $resql );
2013-04-10 18:34:19 +02:00
$param = " &id= " . $object -> id ;
2018-01-26 15:37:23 +01:00
//if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . urlencode ( $limit );
2013-04-10 18:34:19 +02:00
if ( $search_lastname ) $param .= " &search_lastname= " . urlencode ( $search_lastname );
if ( $search_firstname ) $param .= " &search_firstname= " . urlencode ( $search_firstname );
if ( $search_email ) $param .= " &search_email= " . urlencode ( $search_email );
2017-08-25 19:26:48 +02:00
if ( $search_other ) $param .= " &search_other= " . urlencode ( $search_other );
2013-04-10 18:34:19 +02:00
2013-06-12 22:12:06 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
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 . '">' ;
2013-06-12 22:12:06 +02:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2016-05-06 11:22:58 +02:00
$cleartext = '' ;
2014-05-29 14:26:27 +02:00
if ( $allowaddtarget ) {
2016-06-19 11:59:55 +02:00
$cleartext = $langs -> trans ( " ToClearAllRecipientsClickHere " ) . ' ' . '<a href="' . $_SERVER [ " PHP_SELF " ] . '?clearlist=1&id=' . $object -> id . '" class="button reposition">' . $langs -> trans ( " TargetsReset " ) . '</a>' ;
2014-05-29 14:26:27 +02:00
}
2017-09-16 13:28:13 +02:00
print_barre_liste ( $langs -> trans ( " MailSelectedRecipients " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $cleartext , $num , $nbtotalofrecords , 'title_generic' , 0 , '' , '' , $limit );
2017-08-02 13:31:53 +02:00
2013-06-12 22:12:06 +02:00
print '</form>' ;
2013-06-12 22:36:30 +02:00
print " \n <!-- Liste destinataires selectionnes --> \n " ;
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
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 . '">' ;
2013-06-12 22:36:30 +02:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2016-02-12 13:58:24 +01:00
print '<input type="hidden" name="limit" value="' . $limit . '">' ;
2017-08-02 13:31:53 +02:00
2013-06-12 22:12:06 +02:00
2017-05-04 13:41:37 +02:00
if ( $page ) $param .= " &page= " . $page ;
2017-08-02 13:31:53 +02:00
2018-01-12 14:41:57 +01:00
print '<div class="div-table-responsive">' ;
2009-01-26 22:57:14 +01:00
print '<table class="noborder" width="100%">' ;
2017-08-02 13:31:53 +02:00
2009-01-26 22:57:14 +01:00
// Ligne des champs de filtres
2017-05-04 13:41:37 +02:00
print '<tr class="liste_titre_filter">' ;
2009-01-26 22:57:14 +01:00
// EMail
print '<td class="liste_titre">' ;
2016-11-11 01:15:41 +01:00
print '<input class="flat maxwidth100" type="text" name="search_email" value="' . dol_escape_htmltag ( $search_email ) . '">' ;
2009-01-26 22:57:14 +01:00
print '</td>' ;
// Name
print '<td class="liste_titre">' ;
2016-11-11 14:03:57 +01:00
print '<input class="flat maxwidth100" type="text" name="search_lastname" value="' . dol_escape_htmltag ( $search_lastname ) . '">' ;
2009-01-26 22:57:14 +01:00
print '</td>' ;
// Firstname
print '<td class="liste_titre">' ;
2016-11-11 14:03:57 +01:00
print '<input class="flat maxwidth100" type="text" name="search_firstname" value="' . dol_escape_htmltag ( $search_firstname ) . '">' ;
2009-01-26 22:57:14 +01:00
print '</td>' ;
// Other
print '<td class="liste_titre">' ;
2017-08-25 19:26:48 +02:00
print '<input class="flat maxwidth100" type="text" name="search_other" value="' . dol_escape_htmltag ( $search_other ) . '">' ;
2009-01-26 22:57:14 +01:00
print '</td>' ;
2010-12-28 03:04:41 +01:00
// Source
2014-05-29 14:26:27 +02:00
print '<td class="liste_titre">' ;
print ' ' ;
print '</td>' ;
2017-08-02 13:31:53 +02:00
2014-05-29 14:26:27 +02:00
// Date sending
print '<td class="liste_titre">' ;
print ' ' ;
print '</td>' ;
//Statut
print '<td class="liste_titre" align="right">' ;
2014-05-30 12:01:26 +02:00
print $formmailing -> selectDestinariesStatus ( $search_dest_status , 'search_dest_status' , 1 );
2014-05-29 14:26:27 +02:00
print '</td>' ;
2016-11-11 14:03:57 +01:00
// Action column
2014-05-29 14:26:27 +02:00
print '<td class="liste_titre" align="right">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( $massactionbutton ? 1 : 0 , 'checkforselect' , 1 );
print $searchpicto ;
2009-01-26 22:57:14 +01:00
print '</td>' ;
2006-10-29 20:09:49 +01:00
print '</tr>' ;
2017-08-02 13:31:53 +02:00
2017-05-04 13:41:37 +02:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " EMail " , $_SERVER [ " PHP_SELF " ], " mc.email " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Lastname " , $_SERVER [ " PHP_SELF " ], " mc.lastname " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Firstname " , $_SERVER [ " PHP_SELF " ], " mc.firstname " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( " OtherInformations " , $_SERVER [ " PHP_SELF " ], " " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Source " , $_SERVER [ " PHP_SELF " ], " " , $param , " " , 'align="center"' , $sortfield , $sortorder );
2017-05-04 13:41:37 +02:00
// Date sending
if ( $object -> statut < 2 )
{
print_liste_field_titre ( '' );
}
else
{
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " DateSending " , $_SERVER [ " PHP_SELF " ], " mc.date_envoi " , $param , '' , 'align="center"' , $sortfield , $sortorder );
2017-05-04 13:41:37 +02:00
}
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Status " , $_SERVER [ " PHP_SELF " ], " mc.statut " , $param , '' , 'align="right"' , $sortfield , $sortorder );
2017-05-04 13:41:37 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
print '</tr>' ;
2009-01-25 23:04:55 +01:00
2009-01-26 22:57:14 +01:00
$i = 0 ;
if ( $num )
{
2016-11-11 14:03:57 +01:00
while ( $i < min ( $num , $limit ))
2009-01-26 22:57:14 +01:00
{
$obj = $db -> fetch_object ( $resql );
2016-11-11 14:03:57 +01:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-01-26 22:57:14 +01:00
print '<td>' . $obj -> email . '</td>' ;
2013-02-23 15:26:39 +01:00
print '<td>' . $obj -> lastname . '</td>' ;
print '<td>' . $obj -> firstname . '</td>' ;
2009-01-26 22:57:14 +01:00
print '<td>' . $obj -> other . '</td>' ;
2010-12-28 03:04:41 +01:00
print '<td align="center">' ;
if ( empty ( $obj -> source_id ) || empty ( $obj -> source_type ))
{
2017-01-29 18:29:37 +01:00
print empty ( $obj -> source_url ) ? '' : $obj -> source_url ; // For backward compatibility
2010-12-28 03:04:41 +01:00
}
else
{
if ( $obj -> source_type == 'member' )
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
2016-01-22 13:20:21 +01:00
$objectstatic = new Adherent ( $db );
$objectstatic -> fetch ( $obj -> source_id );
2018-05-21 10:58:16 +02:00
print $objectstatic -> getNomUrl ( 1 );
2010-12-28 03:04:41 +01:00
}
else if ( $obj -> source_type == 'user' )
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2016-01-22 13:20:21 +01:00
$objectstatic = new User ( $db );
$objectstatic -> fetch ( $obj -> source_id );
$objectstatic -> id = $obj -> source_id ;
2018-05-21 10:58:16 +02:00
print $objectstatic -> getNomUrl ( 1 );
2010-12-28 03:04:41 +01:00
}
else if ( $obj -> source_type == 'thirdparty' )
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2016-01-22 13:20:21 +01:00
$objectstatic = new Societe ( $db );
$objectstatic -> fetch ( $obj -> source_id );
2018-05-21 10:58:16 +02:00
print $objectstatic -> getNomUrl ( 1 );
}
else if ( $obj -> source_type == 'contact' )
{
include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
$objectstatic = new Contact ( $db );
$objectstatic -> fetch ( $obj -> source_id );
print $objectstatic -> getNomUrl ( 1 );
2010-12-28 03:04:41 +01:00
}
else
{
print $obj -> source_url ;
}
}
print '</td>' ;
2009-01-26 22:57:14 +01:00
2018-01-29 12:58:33 +01:00
// Status of recipient sending email (Warning != status of emailing)
2009-01-26 22:57:14 +01:00
if ( $obj -> statut == 0 )
{
print '<td align="center"> </td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . $langs -> trans ( " MailingStatusNotSent " );
2012-06-13 11:44:17 +02:00
print '</td>' ;
2009-01-26 22:57:14 +01:00
}
else
{
print '<td align="center">' . $obj -> date_envoi . '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2018-01-29 12:58:33 +01:00
print $object :: libStatutDest ( $obj -> statut , 2 , $obj -> error_text );
2009-01-26 22:57:14 +01:00
print '</td>' ;
}
2014-08-25 19:32:36 +02:00
2016-05-05 23:44:44 +02:00
// Search Icon
2015-07-04 03:28:52 +02:00
print '<td align="right">' ;
2018-01-29 12:58:33 +01:00
if ( $obj -> statut == 0 ) // Not sent yet
2015-07-04 03:28:52 +02:00
{
if ( $user -> rights -> mailing -> creer && $allowaddtarget ) {
2018-01-29 12:58:33 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&rowid=' . $obj -> rowid . $param . '">' . img_delete ( $langs -> trans ( " RemoveRecipient " )) . '</a>' ;
2015-07-04 03:28:52 +02:00
}
}
2018-01-29 12:58:33 +01:00
/* if ( $obj -> statut == - 1 ) // Sent with error
{
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=retry&rowid=' . $obj -> rowid . $param . '">' . $langs -> trans ( " Retry " ) . '</a>' ;
} */
2015-07-04 03:28:52 +02:00
print '</td>' ;
2009-01-26 22:57:14 +01:00
print '</tr>' ;
$i ++ ;
}
}
else
{
2017-08-02 13:31:53 +02:00
if ( $object -> statut < 2 )
2016-02-12 14:21:44 +01:00
{
2017-04-17 13:02:40 +02:00
print '<tr><td colspan="8" class="opacitymedium">' ;
2016-02-12 14:21:44 +01:00
print $langs -> trans ( " NoTargetYet " );
print '</td></tr>' ;
}
2009-01-26 22:57:14 +01:00
}
print " </table><br> " ;
2018-01-12 14:41:57 +01:00
print '</div>' ;
2009-01-26 22:57:14 +01:00
2013-06-12 22:36:30 +02:00
print '</form>' ;
2013-06-12 22:12:06 +02:00
2009-01-26 22:57:14 +01:00
$db -> free ( $resql );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2009-01-26 22:57:14 +01:00
}
2006-10-29 20:09:49 +01:00
print " \n <!-- Fin liste destinataires selectionnes --> \n " ;
2005-01-05 16:26:05 +01:00
}
2009-01-25 23:04:55 +01:00
2018-07-29 17:17:29 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-01-26 23:05:59 +01:00
$db -> close ();