2013-02-20 21:11:17 +00:00
< ? php
/*
* e107 website system
*
2017-02-10 22:34:17 +00:00
* Copyright ( C ) 2008 - 2017 e107 Inc ( e107 . org )
2013-02-20 21:11:17 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Mailout - admin - related functions
*
*/
/**
2020-12-18 19:55:12 -08:00
* Various admin - related mailout functions , mostly to do with creating and
2014-10-11 12:54:16 -07:00
* handling forms .
*
2020-12-18 19:55:12 -08:00
* @ package e107
* @ subpackage e107_handlers
2014-10-11 12:54:16 -07:00
*/
2013-02-20 21:11:17 +00:00
/*
2014-10-11 12:54:16 -07:00
TODO :
1. Use API to downloads plugin to get available files ( when available )
2. Fuller checking prior to send
3. May want more control over date display format
4. Use new date picker
*/
2013-02-20 21:11:17 +00:00
2020-12-18 19:55:12 -08:00
if ( ! defined ( 'e107_INIT' ))
2014-10-11 12:54:16 -07:00
{
2020-12-18 19:55:12 -08:00
exit ;
2014-10-11 12:54:16 -07:00
}
2013-02-20 21:11:17 +00:00
2020-12-18 19:55:12 -08:00
define ( 'MAIL_ADMIN_DEBUG' , true );
require_once ( e_HANDLER . 'mail_manager_class.php' );
2013-02-20 21:11:17 +00:00
class mailoutAdminClass extends e107MailManager
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
public $_cal = array ();
protected $mode ;
// So we know what the current task is
2013-02-20 21:11:17 +00:00
protected $mailHandlers = array ();
protected $showFrom = 0 ;
protected $showCount = 10 ;
protected $sortField = 'mail_source_id' ;
protected $sortOrder = 'asc' ;
protected $fieldPref = array ();
protected $userCache = array ();
2014-10-11 12:54:16 -07:00
// Definitions associated with each column which might be displayed. (Compatible
// with forms-based display)
2013-02-20 21:11:17 +00:00
// Fields are displayed in the order listed.
// Can also have: width
// type
// thclass
protected $fields = array (
2014-10-11 12:54:16 -07:00
'mail_recipients' => array (
2020-12-18 19:55:12 -08:00
'mail_target_id' => array (
'title' => LAN_MAILOUT_143 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'center' ,
2020-12-18 19:55:12 -08:00
'forced' => true
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_recipient_id' => array (
'title' => LAN_MAILOUT_142 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'center'
),
2020-12-18 19:55:12 -08:00
'mail_recipient_name' => array (
'title' => LAN_MAILOUT_141 ,
'forced' => true
2014-10-11 12:54:16 -07:00
),
'mail_recipient_email' => array (
2020-12-18 19:55:12 -08:00
'title' => LAN_MAILOUT_140 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'left' ,
2020-12-18 19:55:12 -08:00
'forced' => true
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_status' => array (
'title' => LAN_MAILOUT_138 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'center' ,
2020-12-18 19:55:12 -08:00
'proc' => 'contentstatus'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_detail_id' => array ( 'title' => LAN_MAILOUT_137 ),
'mail_send_date' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_139 ,
2020-12-18 19:55:12 -08:00
'proc' => 'sdatetime'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_target_info' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_148 ,
2020-12-18 19:55:12 -08:00
'proc' => 'array'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'options' => array (
'title' => LAN_OPTIONS ,
'forced' => true
2014-10-11 12:54:16 -07:00
)
2013-02-20 21:11:17 +00:00
),
2020-12-18 19:55:12 -08:00
'mail_content' => array (
'mail_source_id' => array (
'title' => LAN_MAILOUT_137 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'center' ,
2020-12-18 19:55:12 -08:00
'forced' => true
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_title' => array (
'title' => LAN_TITLE ,
'forced' => true
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_subject' => array (
'title' => LAN_MAILOUT_06 ,
'forced' => true
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_content_status' => array (
'title' => LAN_MAILOUT_136 ,
2014-10-11 12:54:16 -07:00
'thclass' => 'center' ,
2020-12-18 19:55:12 -08:00
'proc' => 'contentstatus'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_togo_count' => array ( 'title' => LAN_MAILOUT_83 ),
'mail_sent_count' => array ( 'title' => LAN_MAILOUT_82 ),
'mail_fail_count' => array ( 'title' => LAN_MAILOUT_128 ),
'mail_bounce_count' => array ( 'title' => LAN_MAILOUT_144 ),
'mail_start_send' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_131 ,
2020-12-18 19:55:12 -08:00
'proc' => 'sdatetime'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_end_send' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_132 ,
2020-12-18 19:55:12 -08:00
'proc' => 'sdatetime'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_create_date' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_130 ,
2020-12-18 19:55:12 -08:00
'proc' => 'sdatetime'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_creator' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_85 ,
2020-12-18 19:55:12 -08:00
'proc' => 'username'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_create_app' => array ( 'title' => LAN_SOURCE ),
'mail_e107_priority' => array ( 'title' => LAN_MAILOUT_134 ),
2014-10-11 12:54:16 -07:00
'mail_notify_complete' => array (
2020-12-18 19:55:12 -08:00
'title' => LAN_MAILOUT_243 ,
2014-10-11 12:54:16 -07:00
'nolist' => 'TRUE'
),
2020-12-18 19:55:12 -08:00
'mail_last_date' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_129 ,
2020-12-18 19:55:12 -08:00
'proc' => 'sdatetime'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_body' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_100 ,
2020-12-18 19:55:12 -08:00
'proc' => 'trunc200'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'mail_body_templated' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_257 ,
2020-12-18 19:55:12 -08:00
'proc' => 'chars'
2014-10-11 12:54:16 -07:00
),
// 'mail_other' = array('title' => LAN_MAILOUT_84),
2020-12-18 19:55:12 -08:00
'mail_sender_email' => array ( 'title' => LAN_MAILOUT_149 ),
'mail_sender_name' => array ( 'title' => LAN_MAILOUT_150 ),
'mail_copy_to' => array ( 'title' => LAN_MAILOUT_151 ),
'mail_bcopy_to' => array ( 'title' => LAN_MAILOUT_152 ),
'mail_attach' => array ( 'title' => LAN_MAILOUT_153 ),
'mail_send_style' => array ( 'title' => LAN_MAILOUT_154 ),
'mail_selectors' => array (
'title' => LAN_MAILOUT_155 ,
'proc' => 'selectors' ,
2014-10-11 12:54:16 -07:00
'nolist' => 'TRUE'
),
2020-12-18 19:55:12 -08:00
'mail_include_images' => array (
2014-10-11 12:54:16 -07:00
'title' => LAN_MAILOUT_224 ,
2020-12-18 19:55:12 -08:00
'proc' => 'yesno'
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'options' => array (
'title' => LAN_OPTIONS ,
'forced' => true
2014-10-11 12:54:16 -07:00
)
2013-02-20 21:11:17 +00:00
)
);
// List of fields to be hidden for each action ('nolist' attribute true)
protected $hideFields = array (
2020-12-18 19:55:12 -08:00
'orphans' => array (),
'saved' => 'mail_content_status,mail_togo_count,mail_sent_count,mail_fail_count,mail_bounce_count,mail_start_send,mail_end_send,mail_e107_priority,mail_notify_complete,mail_last_date,mail_selectors' ,
'sent' => 'mail_togo_count,mail_last_date,mail_selectors,mail_notify_complete' ,
2014-10-11 12:54:16 -07:00
// 'pending' =>
// 'mail_togo_count,mail_sent_count,mail_fail_count,mail_bounce_count,mail_start_send,mail_end_send,mail_e107_priority,mail_last_date,mail_selectors',
2020-12-18 19:55:12 -08:00
'pending' => 'mail_start_send,mail_end_send,mail_e107_priority,mail_notify_complete,mail_last_date,mail_selectors' ,
'held' => 'mail_sent_count,mail_fail_count,mail_bounce_count,mail_start_send,mail_end_send,mail_e107_priority,mail_notify_complete,mail_last_date,mail_selectors' ,
'resend' => 'mail_Selectors,mail_notify_complete' ,
2013-02-20 21:11:17 +00:00
'recipients' => 'mail_detail_id'
2014-10-11 12:54:16 -07:00
);
2013-02-20 21:11:17 +00:00
// Array of info associated with each task we might do
protected $tasks = array (
2020-12-18 19:55:12 -08:00
'makemail' => array (
'title' => LAN_MAILOUT_190 ,
'defaultSort' => '' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => ''
),
2020-12-18 19:55:12 -08:00
'saved' => array (
'title' => LAN_MAILOUT_191 ,
'defaultSort' => 'mail_source_id' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_content'
),
2020-12-18 19:55:12 -08:00
'marksend' => array (
'title' => 'Internal: marksend' ,
'defaultSort' => 'mail_source_id' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_content'
),
2020-12-18 19:55:12 -08:00
'sent' => array (
'title' => LAN_MAILOUT_192 ,
'defaultSort' => 'mail_source_id' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_content'
),
2020-12-18 19:55:12 -08:00
'pending' => array (
'title' => LAN_MAILOUT_193 ,
'defaultSort' => 'mail_source_id' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_content'
),
2020-12-18 19:55:12 -08:00
'held' => array (
'title' => LAN_MAILOUT_194 ,
'defaultSort' => 'mail_source_id' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_content'
),
2020-12-18 19:55:12 -08:00
'recipients' => array (
'title' => LAN_MAILOUT_173 ,
'defaultSort' => 'mail_recipient_email' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_recipients'
),
'mailtargets' => array (
2020-12-18 19:55:12 -08:00
'title' => LAN_MAILOUT_173 ,
'defaultSort' => 'mail_recipient_email' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => 'mail_recipients'
),
2020-12-18 19:55:12 -08:00
'prefs' => array (
'title' => ADLAN_40 ,
'defaultSort' => '' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => ''
),
2020-12-18 19:55:12 -08:00
'maint' => array (
'title' => ADLAN_40 ,
'defaultSort' => '' ,
2014-10-11 12:54:16 -07:00
'defaultTable' => ''
)
);
2013-02-20 21:11:17 +00:00
// Options for mail listing dropdown - actions apertaining to a stored email
protected $modeOptions = array (
2020-12-18 19:55:12 -08:00
'saved' => array (
'mailedit' => LAN_MAILOUT_163 ,
'maildelete' => LAN_DELETE ,
2013-02-20 21:11:17 +00:00
'mailshowtemplate' => LAN_MAILOUT_254
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'pending' => array (
2013-02-20 21:11:17 +00:00
'mailsendimmediately' => " Send Immediately " ,
2020-12-18 19:55:12 -08:00
'mailhold' => LAN_MAILOUT_159 ,
'mailcancel' => LAN_MAILOUT_160 ,
'mailtargets' => LAN_MAILOUT_181
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'held' => array (
2014-10-11 12:54:16 -07:00
'mailsendnow' => LAN_MAILOUT_158 ,
2020-12-18 19:55:12 -08:00
'mailcancel' => LAN_MAILOUT_160 ,
2014-10-11 12:54:16 -07:00
'mailtargets' => LAN_MAILOUT_181
),
2020-12-18 19:55:12 -08:00
'sent' => array (
'mailcopy' => LAN_MAILOUT_251 ,
'maildelete' => LAN_DELETE ,
2014-10-11 12:54:16 -07:00
'mailtargets' => LAN_MAILOUT_181
),
'recipients' => array ( 'mailonedelete' => LAN_DELETE )
2013-02-20 21:11:17 +00:00
);
// List of fields to be included in email display for various options
protected $mailDetailDisplay = array (
2020-12-18 19:55:12 -08:00
'basic' => array (
2014-10-11 12:54:16 -07:00
'mail_source_id' => 1 ,
2020-12-18 19:55:12 -08:00
'mail_title' => 1 ,
'mail_subject' => 1 ,
'mail_body' => 200
2014-10-11 12:54:16 -07:00
),
2020-12-18 19:55:12 -08:00
'send' => array (
'mail_source_id' => 1 ,
'mail_title' => 1 ,
'mail_subject' => 1 ,
'mail_body' => 500 ,
2014-10-11 12:54:16 -07:00
'mail_send_style' => 1
),
'template' => array (
2020-12-18 19:55:12 -08:00
'mail_source_id' => 1 ,
'mail_title' => 1 ,
'mail_subject' => 1 ,
'mail_body' => 200 ,
2014-10-11 12:54:16 -07:00
'mail_body_templated' => 'chars'
),
2013-02-20 21:11:17 +00:00
);
/**
* Constructor
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
*
* @ return void
*/
public function __construct ( $mode = '' )
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
parent :: __construct ();
$dbTable = '' ;
2020-12-18 19:55:12 -08:00
if ( isset ( $this -> tasks [ $mode ]))
2013-02-20 21:11:17 +00:00
{
$dbTable = $this -> tasks [ $mode ][ 'defaultTable' ];
}
2020-12-18 19:55:12 -08:00
if ( isset ( $_GET [ 'frm' ]))
2013-02-20 21:11:17 +00:00
{
$temp = intval ( $_GET [ 'frm' ]);
2020-12-18 19:55:12 -08:00
if ( $temp < 0 )
{
2014-10-11 12:54:16 -07:00
$temp = 0 ;
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
$this -> showFrom = $temp ;
}
2020-12-18 19:55:12 -08:00
if ( isset ( $_GET [ 'count' ]))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$temp = min ( intval ( $_GET [ 'count' ]), 50 );
// Limit to 50 per page
$temp = max ( $temp , 5 );
// ...and minimum 5 per page
2013-02-20 21:11:17 +00:00
$this -> showCount = $temp ;
}
2020-12-18 19:55:12 -08:00
if ( isset ( $_GET [ 'fld' ]))
2013-02-20 21:11:17 +00:00
{
2013-03-26 12:16:55 +01:00
$temp = e107 :: getParser () -> toDB ( $_GET [ 'fld' ]);
2020-12-18 19:55:12 -08:00
if ( is_array ( $this -> fields [ $dbTable ][ $temp ]))
2013-02-20 21:11:17 +00:00
{
$this -> sortField = $temp ;
}
}
2020-12-18 19:55:12 -08:00
if ( isset ( $_GET [ 'asc' ]))
2013-02-20 21:11:17 +00:00
{
2013-03-26 12:16:55 +01:00
$temp = strtolower ( e107 :: getParser () -> toDB ( $_GET [ 'asc' ]));
2020-12-18 19:55:12 -08:00
if (( $temp == 'asc' ) || ( $temp == 'desc' ))
2013-02-20 21:11:17 +00:00
{
$this -> sortOrder = $temp ;
}
}
$this -> newMode ( $mode );
}
/**
* Set up new mode
*
* @ param $mode - display mode
2021-12-03 14:58:33 -08:00
* @ return void
2013-02-20 21:11:17 +00:00
*/
public function newMode ( $mode = '' )
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
global $user_pref ;
$this -> mode = $mode ;
2021-01-16 13:32:35 -08:00
$curTable = varset ( $this -> tasks [ $this -> mode ][ 'defaultTable' ]);
2020-12-18 19:55:12 -08:00
if ( $curTable )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( isset ( $user_pref [ 'admin_mailout_columns' ][ $mode ]) && is_array ( $user_pref [ 'admin_mailout_columns' ][ $mode ]))
2014-10-11 12:54:16 -07:00
{
// Use saved list of fields to view if it exists
2013-02-20 21:11:17 +00:00
$this -> fieldPref = $user_pref [ 'admin_mailout_columns' ][ $mode ];
}
else
2014-10-11 12:54:16 -07:00
{
// Default list is minimal fields only
2013-02-20 21:11:17 +00:00
$this -> fieldPref = array ();
2020-12-18 19:55:12 -08:00
foreach ( $this -> fields [ $curTable ] as $f => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( vartrue ( $v [ 'forced' ]))
2013-02-20 21:11:17 +00:00
{
$this -> fieldPref [] = $f ;
}
}
}
}
// Possibly the sort field needs changing
2020-12-18 19:55:12 -08:00
if ( ! isset ( $this -> fields [ $curTable ][ $this -> sortField ]))
2013-02-20 21:11:17 +00:00
{
2021-01-16 13:32:35 -08:00
$this -> sortField = varset ( $this -> tasks [ $mode ][ 'defaultSort' ]);
2013-02-20 21:11:17 +00:00
}
2014-10-11 12:54:16 -07:00
2013-02-20 21:11:17 +00:00
// Now hide any fields that need to be for this mode
2020-12-18 19:55:12 -08:00
if ( isset ( $this -> hideFields [ $mode ]))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$hideList = array_flip ( explode ( ',' , $this -> hideFields [ $mode ]));
2020-12-18 19:55:12 -08:00
foreach ( $this -> fields [ $curTable ] as $f => $v )
2013-02-20 21:11:17 +00:00
{
$this -> fields [ $curTable ][ $f ][ 'nolist' ] = isset ( $hideList [ $f ]);
}
2020-12-18 19:55:12 -08:00
foreach ( $this -> fieldPref as $k => $v ) // Remove from list of active fields
// (shouldn't often do anything)
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( isset ( $hideList [ $v ]))
2013-02-20 21:11:17 +00:00
{
unset ( $this -> fieldPref [ $k ]);
}
}
}
}
/**
* Calculate the list of fields ( columns ) to be displayed for a given mode
*
* @ param string $mode - display mode
2014-10-11 12:54:16 -07:00
* @ param boolean $noOptions - set TRUE to suppress inclusion of any 'options'
* column . FALSE to include 'options' ( default )
2020-12-18 19:55:12 -08:00
* @ return array | false of field definitions
2013-02-20 21:11:17 +00:00
*/
2020-12-18 19:55:12 -08:00
protected function calcFieldSpec ( $mode , $noOptions = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( ! isset ( $this -> tasks [ $mode ]))
2013-02-20 21:11:17 +00:00
{
echo " CalcfieldSpec( { $mode } ) - programming bungle<br /> " ;
2020-12-18 19:55:12 -08:00
return false ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$ret = array ();
$curTable = $this -> tasks [ $this -> mode ][ 'defaultTable' ];
2020-12-18 19:55:12 -08:00
foreach ( $this -> fields [ $curTable ] as $f => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if (( vartrue ( $v [ 'forced' ]) && ! vartrue ( $v [ 'nolist' ])) || in_array ( $f , $this -> fieldPref ))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if (( $f != 'options' ) || ( $noOptions === false ))
2013-02-20 21:11:17 +00:00
{
$ret [] = $f ;
}
}
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $ret ;
}
/**
* Save the column visibility prefs for this mode
*
* @ param $target - display mode
* @ return none
*/
2014-10-11 12:54:16 -07:00
/*
public function mailbodySaveColumnPref ( $target )
{
global $user_pref ;
if ( ! $target ) return ;
if ( ! isset ( $this -> tasks [ $target ]))
{
echo " Invalid prefs target: { $target } <br /> " ;
return ;
}
if ( isset ( $_POST [ 'etrigger_ecolumns' ]))
{
$user_pref [ 'admin_mailout_columns' ][ $target ] = $_POST [ 'e-columns' ];
save_prefs ( 'user' );
$this -> fieldPref = $user_pref [ 'admin_mailout_columns' ][ $target ];
}
}
*/
2013-02-20 21:11:17 +00:00
/**
2020-12-18 19:55:12 -08:00
* Get the user name associated with a user ID .
* The result is cached in case required again
2013-02-20 21:11:17 +00:00
*
2020-12-18 19:55:12 -08:00
* @ param int $uid - User ID
2013-02-20 21:11:17 +00:00
*
2020-12-18 19:55:12 -08:00
* @ return string with user name and user login name ( UID if user not found )
2013-02-20 21:11:17 +00:00
*/
protected function getUserName ( $uid )
{
2020-12-18 19:55:12 -08:00
if ( ! isset ( $this -> userCache [ $uid ]))
2013-02-20 21:11:17 +00:00
{
// Look up user
2014-10-11 12:54:16 -07:00
$this -> checkDB ( 2 );
// Make sure DB object created
2020-12-18 19:55:12 -08:00
if ( $this -> db2 -> select ( 'user' , 'user_name, user_loginname' , 'user_id=' . intval ( $uid )))
2013-02-20 21:11:17 +00:00
{
2016-02-14 12:15:55 -08:00
$row = $this -> db2 -> fetch ();
2014-10-11 12:54:16 -07:00
$this -> userCache [ $uid ] = $row [ 'user_name' ] . ' (' . $row [ 'user_loginname' ] . ')' ;
2013-02-20 21:11:17 +00:00
}
else
{
2014-10-11 12:54:16 -07:00
$this -> userCache [ $uid ] = 'UID: ' . $uid ;
2013-02-20 21:11:17 +00:00
}
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $this -> userCache [ $uid ];
}
/**
* Generate the HTML for displaying actions box for emails
2014-10-11 12:54:16 -07:00
*
* Options given depend on $mode ( saved | sent | pending | held ), and also values in
* the email data .
2013-02-20 21:11:17 +00:00
*
* @ param array $mailData - array of email - related info
* @ return string HTML for display
*/
2014-10-11 12:54:16 -07:00
public function makeMailOptions ( $mode , $mailData )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( ! is_numeric ( $mailData [ 'mail_source_id' ]) || ( $mailData [ 'mail_source_id' ] == 0 ))
2013-02-20 21:11:17 +00:00
{
echo " makeMailOptions ( { $mode } ): Programming bungle! " ;
print_a ( $mailData );
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return 'Error' ;
}
2021-10-19 07:41:33 -07:00
$text = " <select name='mailaction[ { $mailData [ 'mail_source_id' ] } ]' onchange='this.form.submit()' class='tbox form-control' style='width:90%'> \n
2013-02-20 21:11:17 +00:00
< option selected = 'selected' value = '' >& nbsp ; </ option > \n " ;
2020-12-18 19:55:12 -08:00
foreach ( $this -> modeOptions [ $mode ] as $key => $val )
2013-02-20 21:11:17 +00:00
{
$text .= " <option value=' { $key } '> { $val } </option> \n " ;
}
$text .= " </select> \n " ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $text ;
}
/**
* Generate the HTML for displaying actions box for emails
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* Options given depend on $mode , and also values in the email data .
*
* @ param $mailData - array of email - related info
2020-12-18 19:55:12 -08:00
* @ return string HTML for display
2013-02-20 21:11:17 +00:00
*/
2014-10-11 12:54:16 -07:00
public function makeTargetOptions ( $mode , $targetData )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( ! is_numeric ( $targetData [ 'mail_target_id' ]) || ( $targetData [ 'mail_target_id' ] == 0 ))
2013-02-20 21:11:17 +00:00
{
echo " makeTargetOptions ( { $mode } ): Programming bungle! " ;
print_a ( $targetData );
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return 'Error' ;
}
2021-10-19 07:41:33 -07:00
$text = " <select name='targetaction[ { $targetData [ 'mail_target_id' ] } ]' onchange='this.form.submit()' class='tbox form-control' style='width:90%'> \n
2013-02-20 21:11:17 +00:00
< option selected = 'selected' value = '' >& nbsp ; </ option > \n " ;
2020-12-18 19:55:12 -08:00
foreach ( $this -> modeOptions [ $mode ] as $key => $val )
2013-02-20 21:11:17 +00:00
{
$text .= " <option value=' { $key } '> { $val } </option> \n " ;
}
$text .= " </select> \n " ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $text ;
}
/**
* Generate the HTML for displaying email selection fields
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $options - comma - separate string of handlers to load
2020-12-18 19:55:12 -08:00
* 'core' - core handler
* plugin name - obvious !
* 'all' - obvious !
2013-02-20 21:11:17 +00:00
* @ return Number of handlers loaded
*/
public function loadMailHandlers ( $options = 'all' )
{
2020-12-18 19:55:12 -08:00
2013-02-25 21:28:26 +01:00
$pref = e107 :: getPref ();
2013-02-20 21:11:17 +00:00
2021-01-16 13:32:35 -08:00
$pref [ 'mailout_enabled' ] = str_replace ( 'core' , 'user' , varset ( $pref [ 'mailout_enabled' ])); // BC fix.
2016-04-11 18:39:19 -07:00
2013-02-20 21:11:17 +00:00
$ret = 0 ;
$toLoad = explode ( ',' , $options );
2020-12-18 19:55:12 -08:00
2016-04-11 18:39:19 -07:00
$active_mailers = explode ( ',' , varset ( $pref [ 'mailout_enabled' ], 'user' ));
2020-12-18 19:55:12 -08:00
//if((in_array('core', $toLoad) || ($options == 'all')) && in_array('core', $active_mailers))
// {
2016-04-11 18:39:19 -07:00
// require_once (e_HANDLER . 'mailout_class.php');
// $this->mailHandlers['core'] = new core_mailout; // Start by loading the core mailout class
// $ret++;
2020-12-18 19:55:12 -08:00
// }
if ( empty ( $pref [ 'e_mailout_list' ]))
2014-11-15 13:29:37 -08:00
{
return $ret ;
}
2020-12-18 19:55:12 -08:00
2014-10-16 19:04:24 -07:00
// Load additional configured handlers e_mailout.php from plugins.
2020-12-18 19:55:12 -08:00
foreach ( $pref [ 'e_mailout_list' ] as $mailer => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( isset ( $pref [ 'plug_installed' ][ $mailer ]) && in_array ( $mailer , $active_mailers ) && (( $options == 'all' ) || in_array ( $mailer , $toLoad )))
2014-10-11 12:54:16 -07:00
{
// Could potentially use this handler - its installed and enabled
2020-12-18 19:55:12 -08:00
if ( ! is_readable ( e_PLUGIN . $mailer . '/e_mailout.php' ))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
echo 'Invalid mailer selected: ' . $mailer . '<br />' ;
2020-12-18 19:55:12 -08:00
exit ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
require_once ( e_PLUGIN . $mailer . '/e_mailout.php' );
if ( varset ( $mailerIncludeWithDefault , true ))
2014-10-11 12:54:16 -07:00
{
// Definitely need this plugin
$mailClass = $mailer . '_mailout' ;
2013-02-20 21:11:17 +00:00
$temp = new $mailClass ;
2020-12-18 19:55:12 -08:00
// $temp = e107::getSingleton($mailClass);
if ( $temp -> mailerEnabled )
2013-02-20 21:11:17 +00:00
{
$this -> mailHandlers [ $mailer ] = $temp ;
$ret ++ ;
2020-12-18 19:55:12 -08:00
if ( varset ( $mailerExcludeDefault , false ) && isset ( $this -> mailHandlers [ 'core' ]))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$this -> mailHandlers [ 'core' ] -> mailerEnabled = false ;
2014-10-11 12:54:16 -07:00
// Don't need default (core) handler
2013-02-20 21:11:17 +00:00
$ret -- ;
}
}
else
{
unset ( $temp );
}
}
}
}
return $ret ;
}
/**
* Generate the HTML for displaying email selection fields
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $options - comma - separated string of areas to display :
2020-12-18 19:55:12 -08:00
* plugins - selectors from any available plugins
* cc - field for 'cc' options
* bcc - field for 'bcc' options
* src = plugname - selector from the specified plugin
* 'all' - all available fields
* @ return string html for display
2013-02-20 21:11:17 +00:00
*/
2020-12-18 19:55:12 -08:00
public function emailSelector ( $options = 'all' , $selectorInfo = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2014-10-16 19:04:24 -07:00
$tabs = array ();
2014-10-11 12:54:16 -07:00
2019-10-24 14:33:23 +02:00
// Check for selected email address sources
2020-12-18 19:55:12 -08:00
if ( ! $this -> mailHandlers )
2019-10-24 14:33:23 +02:00
{
2020-12-18 19:55:12 -08:00
$text = " <span class='label label-warning'> " . LAN_MAILOUT_259 . " </span> " ;
2019-10-24 14:33:23 +02:00
}
2020-12-18 19:55:12 -08:00
foreach ( $this -> mailHandlers as $key => $m )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $m -> mailerEnabled )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
$content = $m -> showSelect ( true , varset ( $selectorInfo [ $key ], false ));
if ( is_array ( $content ))
2013-02-20 21:11:17 +00:00
{
2016-04-11 18:39:19 -07:00
$text = " <table class='table table-bordered table-striped ' style='margin-bottom:0;margin-left:0; margin-top:10px'>
2013-02-20 21:11:17 +00:00
< colgroup span = '2' >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
" ;
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
foreach ( $content as $var )
2013-02-20 21:11:17 +00:00
{
2014-10-16 19:04:24 -07:00
$text .= "
< tr >
2016-04-11 18:39:19 -07:00
< td > " . $var['caption'] . " </ td >
2014-10-16 19:04:24 -07:00
< td class = 'form-inline' > " . $var['html'] . " </ td >
</ tr > " ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
2014-10-16 19:04:24 -07:00
$text .= " </table> " ;
2013-02-20 21:11:17 +00:00
}
else
{
2014-10-16 19:04:24 -07:00
$text = $content ; //BC (0.8 only) but should be deprecated
2013-02-20 21:11:17 +00:00
}
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
$tabs [ $key ] = array ( 'caption' => $m -> mailerName , 'text' => $text );
2014-10-16 19:04:24 -07:00
2013-02-20 21:11:17 +00:00
}
}
2020-12-18 19:55:12 -08:00
if ( count ( $tabs ) < 2 ) // no tabs if there's only 1 category.
2014-10-16 19:04:24 -07:00
{
2020-12-18 19:55:12 -08:00
return $text ;
2014-10-16 19:04:24 -07:00
}
2020-12-18 19:55:12 -08:00
2014-10-16 19:04:24 -07:00
return e107 :: getForm () -> tabs ( $tabs );
}
2013-02-25 21:28:26 +01:00
2013-02-20 21:11:17 +00:00
/**
* Get the selector details from each mail plugin ( to add to mail data )
2014-10-11 12:54:16 -07:00
*
* @ return array of selectors - key is the plugin name , value is the selector
* data ( often itself an array )
2013-02-20 21:11:17 +00:00
*/
public function getAllSelectors ()
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$ret = array ();
2020-12-18 19:55:12 -08:00
foreach ( $this -> mailHandlers as $key => $m )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $m -> mailerEnabled )
2013-02-20 21:11:17 +00:00
{
$ret [ $key ] = $m -> returnSelectors ();
}
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $ret ;
}
/**
2014-10-11 12:54:16 -07:00
* Creates a 'select' dropdown of userclasses , including the number of members in
* each class .
*
2013-02-20 21:11:17 +00:00
* @ param string $name - name for < select >
* @ param string $curSel - current select value
2021-12-03 14:58:33 -08:00
* @ return string for display
2013-02-20 21:11:17 +00:00
*
2020-12-18 19:55:12 -08:00
* @ TODO : Doesn ' t give correct count for core classes where no data initialised
2013-02-20 21:11:17 +00:00
*/
2014-10-11 12:54:16 -07:00
public function userClassesTotals ( $name , $curSel )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
$fixedClasses = array (
2020-12-18 19:55:12 -08:00
'self' => LAN_MAILOUT_54 ,
'all' => LAN_MAILOUT_12 ,
2014-10-11 12:54:16 -07:00
'unverified' => LAN_MAILOUT_13 ,
2020-12-18 19:55:12 -08:00
'admin' => LAN_MAILOUT_53
2014-10-11 12:54:16 -07:00
);
2013-02-20 21:11:17 +00:00
$ret = '' ;
2014-10-11 12:54:16 -07:00
$this -> checkDB ( 2 );
// Make sure DB object created
2021-10-19 07:41:33 -07:00
$ret .= " <select class='tbox form-control' name=' { $name } ' >
2013-02-20 21:11:17 +00:00
< option value = '' >& nbsp ; </ option > \n " ;
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
foreach ( $fixedClasses as $k => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$sel = ( $k == $curSel ) ? " selected='selected' " : '' ;
2013-02-20 21:11:17 +00:00
$ret .= " <option value=' { $k } ' { $sel } > { $v } </option> \n " ;
}
$query = " SELECT uc.*, count(u.user_id) AS members
FROM #userclass_classes AS uc
LEFT JOIN #user AS u ON u.user_class REGEXP concat('(^|,)',uc.userclass_id,'(,|$)')
2014-10-11 12:54:16 -07:00
WHERE NOT uc . userclass_id IN ( " . e_UC_PUBLIC . ',' . e_UC_NOBODY . ',' . e_UC_READONLY . ',' . e_UC_BOTS . " )
2013-02-20 21:11:17 +00:00
GROUP BY uc . userclass_id
" ;
2013-03-26 12:16:55 +01:00
$this -> db2 -> gen ( $query );
2020-12-18 19:55:12 -08:00
while ( $row = $this -> db2 -> fetch ())
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$public = ( $row [ 'userclass_editclass' ] == e_UC_PUBLIC ) ? " ( " . LAN_MAILOUT_10 . " ) " : " " ;
$selected = ( $row [ 'userclass_id' ] == $curSel ) ? " selected='selected' " : '' ;
2014-10-11 12:54:16 -07:00
$ret .= " <option value=' { $row [ 'userclass_id' ] } ' { $selected } > " . LAN_MAILOUT_55 . " - { $row [ 'userclass_name' ] } { $public } [ { $row [ 'members' ] } ]</option> \n " ;
2013-02-20 21:11:17 +00:00
}
$ret .= " </select> \n " ;
return $ret ;
}
/**
* Creates a 'select' dropdown of non - system user fields
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param string $list_name - name for < select >
* @ param string $curval - current select value
* @ param boolean $add_blank - add a blank line before the options if TRUE
2021-12-03 14:58:33 -08:00
* @ return false | string for display if any extended fields defined ; FALSE if none
2014-10-11 12:54:16 -07:00
* available
2013-02-20 21:11:17 +00:00
*/
2020-12-18 19:55:12 -08:00
public function ret_extended_field_list ( $list_name , $curval = '' , $add_blank = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
$ue = e107 :: getUserExt ();
// Get the extended field handler
2020-12-18 19:55:12 -08:00
if ( count ( $ue -> fieldDefinitions ) == 0 )
{
return false ;
}
2021-10-19 07:41:33 -07:00
$ret = " <select name=' { $list_name } ' class='tbox form-control'> \n " ;
2020-12-18 19:55:12 -08:00
if ( $add_blank )
{
2014-10-11 12:54:16 -07:00
$ret .= " <option value=''> </option> \n " ;
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
2020-12-18 19:55:12 -08:00
foreach ( $ue -> fieldDefinitions as $fd )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $fd [ 'user_extended_struct_text' ] != '_system_' )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$value = 'ue.user_' . $fd [ 'user_extended_struct_name' ];
2020-12-18 19:55:12 -08:00
$selected = ( $value == $curval ) ? " selected='selected' " : '' ;
2014-10-11 12:54:16 -07:00
$ret .= " <option value=' " . $value . " ' { $selected } > " . ucfirst ( $fd [ 'user_extended_struct_name' ]) . " </option> \n " ;
2013-02-20 21:11:17 +00:00
}
}
$ret .= " </select> \n " ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $ret ;
}
/**
* Creates an array of data from standard $_POST fields
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $newMail - set TRUE for initial creation , FALSE when updating
* @ return array of data
*/
2020-12-18 19:55:12 -08:00
public function parseEmailPost ( $newMail = true )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$tp = e107 :: getParser ();
2014-10-11 12:54:16 -07:00
$ret = array (
2020-12-18 19:55:12 -08:00
'mail_title' => $_POST [ 'email_title' ],
'mail_subject' => $_POST [ 'email_subject' ],
'mail_body' => $_POST [ 'email_body' ],
'mail_sender_email' => $_POST [ 'email_from_email' ],
'mail_sender_name' => $_POST [ 'email_from_name' ],
'mail_copy_to' => $_POST [ 'email_cc' ],
'mail_bcopy_to' => $_POST [ 'email_bcc' ],
'mail_attach' => trim ( $_POST [ 'email_attachment' ]),
'mail_send_style' => varset ( $_POST [ 'email_send_style' ], 'textonly' ),
'mail_include_images' => ( isset ( $_POST [ 'email_include_images' ]) ? 1 : 0 )
2014-10-11 12:54:16 -07:00
);
$ret = $tp -> toDB ( $ret );
// recursive
2020-12-18 19:55:12 -08:00
if ( isset ( $_POST [ 'mail_source_id' ]))
2013-02-20 21:11:17 +00:00
{
$ret [ 'mail_source_id' ] = intval ( $_POST [ 'mail_source_id' ]);
}
2020-12-18 19:55:12 -08:00
if ( $newMail )
2013-02-20 21:11:17 +00:00
{
$ret [ 'mail_creator' ] = USERID ;
$ret [ 'mail_create_date' ] = time ();
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $ret ;
}
/**
* Does some basic checking on email data .
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $email - array of data in parseEmailPost () format
2014-10-11 12:54:16 -07:00
* @ param $fullCheck - TRUE to check all fields that are required ( immediately
* prior to sending ); FALSE to just check a few basics ( prior to save )
2013-02-20 21:11:17 +00:00
* @ return TRUE if OK . Array of error messages if any errors found
*/
2020-12-18 19:55:12 -08:00
public function checkEmailPost ( & $email , $fullCheck = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$errList = array ();
2020-12-18 19:55:12 -08:00
if ( count ( $email ) < 3 )
2013-02-20 21:11:17 +00:00
{
$errList [] = LAN_MAILOUT_201 ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $errList ;
}
2020-12-18 19:55:12 -08:00
if ( ! trim ( $email [ 'mail_subject' ]))
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_200 ;
2020-12-18 19:55:12 -08:00
}
if ( ! trim ( $email [ 'mail_body' ]))
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_202 ;
2020-12-18 19:55:12 -08:00
}
if ( ! trim ( $email [ 'mail_sender_name' ]))
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_203 ;
2020-12-18 19:55:12 -08:00
}
if ( ! trim ( $email [ 'mail_sender_email' ]))
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_204 ;
2020-12-18 19:55:12 -08:00
}
if ( strlen ( $email [ 'mail_send_style' ]) == 0 )
2014-10-11 12:54:16 -07:00
{
// Can be a template name now
2013-02-20 21:11:17 +00:00
$errList [] = LAN_MAILOUT_205 ;
2020-12-18 19:55:12 -08:00
// break;
2013-02-20 21:11:17 +00:00
}
else
{
// Get template data, override email settings as appropriate
2020-12-18 19:55:12 -08:00
require_once ( e_HANDLER . 'mail_template_class.php' );
2013-02-20 21:11:17 +00:00
$ourTemplate = new e107MailTemplate ();
$templateName = $email [ 'mail_send_style' ];
2020-12-18 19:55:12 -08:00
if ( ! $ourTemplate -> setNewTemplate ( $templateName ))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_207 . ':' . $templateName ;
print_a ( $ourTemplate );
// Probably template not found if error
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
if ( ! $ourTemplate -> makeEmailBody ( $email [ 'mail_body' ], $email [ 'mail_include_images' ]))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$errList [] = LAN_MAILOUT_205 . ':' . $templateName ;
2013-02-20 21:11:17 +00:00
print_a ( $ourTemplate );
}
else
{
$email [ 'mail_body_templated' ] = $ourTemplate -> mainBodyText ;
$email [ 'mail_body_alt' ] = $ourTemplate -> altBodyText ;
2020-12-18 19:55:12 -08:00
if ( count ( $ourTemplate -> lastTemplateData [ 'email_overrides' ]))
2013-02-20 21:11:17 +00:00
{
$email [ 'mail_overrides' ] = $ourTemplate -> lastTemplateData [ 'email_overrides' ];
}
}
}
2020-12-18 19:55:12 -08:00
if ( count ( $errList ) == 0 )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
return true ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $errList ;
}
/**
* Generate a table which shows some information about an email .
2014-10-11 12:54:16 -07:00
* Intended to be part of a 2 - column table - includes the row detail , but not the
* surrounding table definitions
*
2013-02-20 21:11:17 +00:00
* @ param $mailSource - array of mail information
* @ param $options - controls how much information is displayed
2021-12-03 14:58:33 -08:00
* @ return string for display
2013-02-20 21:11:17 +00:00
*/
2014-10-11 12:54:16 -07:00
public function showMailDetail ( & $mailSource , $options = 'basic' )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$tp = e107 :: getParser ();
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
if ( ! isset ( $this -> mailDetailDisplay [ $options ]))
2013-02-20 21:11:17 +00:00
{
return " <tr><td colspan='2'>Programming bungle - invalid option value: { $options } </td></tr> " ;
}
$text = '' ;
2020-12-18 19:55:12 -08:00
foreach ( $this -> mailDetailDisplay [ $options ] as $k => $v )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= '<tr><td>' . $this -> fields [ 'mail_content' ][ $k ][ 'title' ] . '</td><td>' ;
2013-02-20 21:11:17 +00:00
$val = $mailSource [ $k ];
2020-12-18 19:55:12 -08:00
if ( $k == 'mail_body' )
2014-10-12 18:01:19 -07:00
{
2020-12-18 19:55:12 -08:00
// $text .= print_a($mailSource,true);
// $text .= $tp->toHTML($val,true);
$text .= " <iframe src=' " . e_ADMIN . " mailout.php?mode=main&action=preview&id= " . $mailSource [ 'mail_source_id' ] . " ' width='100%' height='350'>Loading...</iframe> " ;
2014-10-12 18:01:19 -07:00
continue ;
}
2020-12-18 19:55:12 -08:00
if ( is_numeric ( $v ))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$text .= ( $v > 1 ) ? $tp -> text_truncate ( $val , $v , '...' ) : $val ;
2013-02-20 21:11:17 +00:00
}
else
{
switch ( $v )
{
2014-10-11 12:54:16 -07:00
case 'username' :
2013-02-20 21:11:17 +00:00
$text .= $this -> getUserName ( $val );
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'sdatetime' :
2015-05-13 02:03:36 -07:00
$text .= $tp -> toDate ( $val , 'short' );
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'trunc200' :
2020-12-18 19:55:12 -08:00
2013-03-26 12:16:55 +01:00
$text .= e107 :: getParser () -> text_truncate ( $val , 200 , '...' );
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'chars' :
// Show generated html as is
2013-02-20 21:11:17 +00:00
$text .= htmlspecialchars ( $val , ENT_COMPAT , 'UTF-8' );
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'contentstatus' :
2013-02-20 21:11:17 +00:00
$text .= $this -> statusToText ( $val );
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'selectors' :
2013-02-20 21:11:17 +00:00
$text .= 'cannot display' ;
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'yesno' :
2020-12-18 19:55:12 -08:00
$text .= $val ? LAN_YES : LAN_NO ;
break ;
2014-10-11 12:54:16 -07:00
case 'default' :
default :
2013-02-20 21:11:17 +00:00
$text .= $val ;
}
}
2014-10-11 12:54:16 -07:00
$text .= '</td></tr>' . " \n " ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $text ;
}
/**
* Generate the HTML for dropdown to select mail sending style ( text / HTML / styled
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $curval - current value
* @ param $name name of item
2021-12-03 14:58:33 -08:00
* @ return string for display
2013-02-20 21:11:17 +00:00
*/
2020-12-18 19:55:12 -08:00
public function sendStyleSelect ( $curval = '' , $name = 'email_send_style' , $incTemplates = true )
2013-02-20 21:11:17 +00:00
{
$emFormat = array (
2020-12-18 19:55:12 -08:00
'textonly' => LAN_MAILOUT_125 ,
'texthtml' => LAN_MAILOUT_126 ,
2013-02-20 21:11:17 +00:00
'texttheme' => LAN_MAILOUT_127
);
2020-12-18 19:55:12 -08:00
if ( $incTemplates )
2013-02-20 21:11:17 +00:00
{
$tList = self :: getEmailTemplateNames ( 'user' );
2020-12-18 19:55:12 -08:00
foreach ( $tList as $key => $val )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$emFormat [ $key ] = LAN_TEMPLATE . " : " . $val ;
}
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
if ( empty ( $curval ))
2014-10-22 17:58:20 -07:00
{
$curval = e107 :: getConfig () -> get ( 'mail_sendstyle' );
2020-12-18 19:55:12 -08:00
2014-10-22 17:58:20 -07:00
}
2020-12-18 19:55:12 -08:00
return e107 :: getForm () -> select ( $name , $emFormat , $curval , 'required=1&size=xxlarge' );
2014-10-22 17:58:20 -07:00
2013-02-20 21:11:17 +00:00
}
/**
* Generate the HTML to show the mailout form . Used for both sending and editing
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $mailSource - array of mail information
* @ return text for display
*/
2014-10-11 12:54:16 -07:00
/*
function show_mailform ( & $mailSource )
{
global $HANDLERS_DIRECTORY ;
global $mailAdmin ;
$sql = e107 :: getDb ();
$ns = e107 :: getRender ();
$tp = e107 :: getParser ();
$frm = e107 :: getForm ();
$mes = e107 :: getMessage ();
$pref = e107 :: getPref ();
if ( ! is_array ( $mailSource ))
{
$mes -> addError ( 'Coding error - mail not array (521)' );
//$ns->tablerender('ERROR!!', );
//exit;
}
$email_subject = varset ( $mailSource [ 'mail_subject' ], '' );
$email_body = $tp -> toForm ( varset ( $mailSource [ 'mail_body' ], '' ));
$email_id = varset ( $mailSource [ 'mail_source_id' ], '' );
$text = '' ;
if ( strpos ( $_SERVER [ 'SERVER_SOFTWARE' ], 'mod_gzip' ) &&
! is_readable ( e_HANDLER . 'phpmailer/.htaccess' ))
{
$warning = LAN_MAILOUT_40 . ' ' . $HANDLERS_DIRECTORY . 'phpmailer/ ' . LAN_MAILOUT_41 ;
$ns -> tablerender ( LAN_MAILOUT_42 , $mes -> render () . $warning );
}
$debug = ( e_MENU == " debug " ) ? " ?[debug] " : " " ;
$text .= " <div>
< form method = 'post' action = '".e_SELF."?mode=makemail' id = 'mailout_form' > " ;
$text .= $this -> emailSelector ( 'all' , varset ( $mailSource [ 'mail_selectors' ],
FALSE ));
$text .= " <table class='table'>
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tr >
< td > " .LAN_MAILOUT_111. " : </ td >
< td > " . $frm->text ('email_title',varset( $mailSource['mail_title'] ,'')). " </ td >
</ tr >
< tr >
< td > " .LAN_MAILOUT_01. " : </ td >
< td > " . $frm->text ('email_from_name',varset( $mailSource['mail_from_name'] ,USERNAME)). " </ td >
</ tr >
< tr >
< td > " .LAN_MAILOUT_02. " : </ td >
< td
> " . $frm->text ('email_from_email',varset( $mailSource['mail_from_email'] ,USEREMAIL)). " </ td >
</ tr > " ;
// Add in the core and any plugin selectors here
*/
/* $text .= "
2013-02-20 21:11:17 +00:00
2014-10-11 12:54:16 -07:00
< tr >
< td > " .LAN_MAILOUT_03. " : </ td >
< td > " . $this->emailSelector ('all', varset( $mailSource['mail_selectors'] ,
FALSE )) . " </td>
</ tr > " ;*/
/*
$text .= "
< tr >
< td > " .LAN_MAILOUT_04. " : </ td >
< td > " . $frm->text ('email_cc',varset( $mailSource['mail_cc'] ,'')). " </ td >
</ tr >
< tr >
< td > " .LAN_MAILOUT_05. " : </ td >
< td > " . $frm->text ('email_bcc',varset( $mailSource['mail_bcc'] ,'')). " </ td >
</ tr >
< tr >
< td > " .LAN_MAILOUT_51. " : </ td >
< td > " . $frm->text ('email_subject',varset( $email_subject ,''),255,'required=1&size=xxlarge'). " </ td >
</ tr > " ;
// Attachment.
if ( e107 :: isInstalled ( 'download' ))
{
// TODO - use download plugin API
if ( $sql -> select ( " download " , " download_url,download_name " , " download_id !=''
ORDER BY download_name " ))
{
$text .= " <tr>
< td > " .LAN_MAILOUT_07. " : </ td >
< td > " ;
$text .= " <select class='tbox' name='email_attachment' >
< option value = '' >& nbsp ; </ option > \n " ;
while ( $row = $sql -> fetch ())
{
$selected = ( $mailSource [ 'mail_attach' ] == $row [ 'download_url' ]) ?
" selected='selected' " : '' ;
// $text .= "<option value='".urlencode($row['download_url'])."'
// {$selected}>".htmlspecialchars($row['download_name'])."</option>\n";
$text .= " <option value=' " . $row [ 'download_url' ] . " '
{ $selected } > " .htmlspecialchars( $row['download_name'] ). " </ option > \n " ;
}
$text .= " </select> " ;
$text .= " </td>
</ tr > " ;
}
}
// TODO File-Picker from Media-Manager.
$text .= "
< tr >
< td > " .LAN_MAILOUT_09. " : </ td >
< td > \n " ;
global $eplug_bb ;
$eplug_bb [] = array (
'name' => 'shortcode' ,
'onclick' => 'expandit' ,
'onclick_var' => 'sc_selector' ,
'icon' => e_IMAGE . 'generic/bbcode/shortcode.png' ,
'helptext' => LAN_MAILOUT_11 ,
'function' => array ( $this , 'sc_Select' ),
'function_var' => 'sc_selector'
);
$text .= $this -> sendStyleSelect ( varset ( $mailSource [ 'mail_send_style' ], '' ));
$checked = ( isset ( $mailSource [ 'mail_include_images' ]) &&
$mailSource [ 'mail_include_images' ]) ? " checked='checked' " : '' ;
$text .= " <input type='checkbox' name='email_include_images'
value = '1' { $checked } /> " .LAN_MAILOUT_225;
$text .= "
</ td ></ tr > \n
< tr >
< td
colspan = '2' > " . $frm->bbarea ('email_body', $email_body ,'mailout','helpb'). " </ td >
</ tr > " ;
$text .= "
< tr >
< td colspan = '2' >
< div > " ;
// $text .= display_help('helpb','mailout');
$text .= "
</ div ></ td >
</ tr >
</ table > " ;
$text .= " <div class='buttons-bar center'> " ;
if ( $email_id )
{
$text .= $frm -> hidden ( 'mail_source_id' , $email_id );
$text .= $frm -> admin_button ( 'update_email' , LAN_UPDATE );
//$text .= "<input type='hidden' name='mail_source_id' value='".$email_id."'
// />";
//$text .= "<input type='submit' name='update_email' value=\"".LAN_UPDATE."\"
// />";
}
else
{
$text .= $frm -> admin_button ( 'save_email' , LAN_SAVE , 'other' );
}
$text .= $frm -> admin_button ( 'send_email' , LAN_MAILOUT_08 ); //
$text .= " </div>
</ form >
</ div > " ;
return $text ;
// $ns->tablerender(ADLAN_136.SEP.LAN_MAILOUT_15, $mes->render(). $text); //
// Render the complete form
}
*/
2013-02-20 21:11:17 +00:00
/**
2020-12-18 19:55:12 -08:00
* Helper function manages the shortcodes which can be inserted
2013-02-20 21:11:17 +00:00
*/
2014-10-11 12:54:16 -07:00
function sc_Select ( $container = 'sc_selector' )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
$text = "
2013-02-20 21:11:17 +00:00
<!-- Start of Shortcode selector --> \n
< div style = 'margin-left:0px;margin-right:0px; position:relative;z-index:1000;float:right;display:none' id = '{$container}' >
< div style = 'position:absolute; bottom:30px; right:125px' >
< table class = 'fborder' style = 'background-color: #fff' >
< tr >< td >
2021-10-19 07:41:33 -07:00
< select class = 'tbox form-control' name = 'sc_sel' onchange = \ " addtext(this.value); this.selectedIndex= 0; expandit(' { $container } ') \" >
2013-02-20 21:11:17 +00:00
< option value = '' > -- </ option > \n " ;
2014-10-11 12:54:16 -07:00
$sc = array (
2020-12-18 19:55:12 -08:00
'|DISPLAYNAME|' => LAN_MAILOUT_14 ,
'|USERNAME|' => LAN_MAILOUT_16 ,
'|SIGNUP_LINK|' => LAN_MAILOUT_17 ,
'|USERID|' => LAN_MAILOUT_18 ,
2014-10-11 12:54:16 -07:00
'|USERLASTVISIT|' => LAN_MAILOUT_178
);
2013-02-20 21:11:17 +00:00
2020-12-18 19:55:12 -08:00
foreach ( $sc as $key => $val )
2014-10-11 12:54:16 -07:00
{
$text .= " <option value=' " . $key . " '> " . $val . " </option> \n " ;
}
$text .= "
2013-02-20 21:11:17 +00:00
</ select ></ td ></ tr > \n </ table ></ div >
</ div >
\n <!-- End of SC selector -->
" ;
return $text ;
}
/**
* Return dropdown for arithmetic comparisons
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $name string name of select structure
* @ param $curval string current value
2021-12-03 14:58:33 -08:00
* @ return string for display
2013-02-20 21:11:17 +00:00
*/
public function comparisonSelect ( $name , $curval = '' )
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
$compVals = array (
' ' => ' ' ,
'<' => LAN_MAILOUT_175 ,
'=' => LAN_MAILOUT_176 ,
'>' => LAN_MAILOUT_177
);
2021-10-19 07:41:33 -07:00
$ret = " <select name=' { $name } ' class='tbox form-control'> \n " ;
2020-12-18 19:55:12 -08:00
foreach ( $compVals as $k => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$selected = ( $k == $curval ) ? " selected='selected' " : '' ;
2014-10-11 12:54:16 -07:00
$ret .= " <option value=' " . $k . " ' { $selected } > " . $v . " </option> \n " ;
2013-02-20 21:11:17 +00:00
}
$ret .= " </select> \n " ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $ret ;
}
/**
2020-12-18 19:55:12 -08:00
* Show the generated template of a saved email
2013-02-20 21:11:17 +00:00
*/
public function showEmailTemplate ( $mailId )
{
2020-12-18 19:55:12 -08:00
2014-10-11 12:54:16 -07:00
$mes = e107 :: getMessage ();
$ns = e107 :: getRender ();
2015-05-13 02:03:36 -07:00
$frm = e107 :: getForm ();
2013-02-25 21:28:26 +01:00
2013-02-20 21:11:17 +00:00
$mailData = $this -> retrieveEmail ( $mailId );
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
if ( $mailData === false )
2013-02-20 21:11:17 +00:00
{
2013-02-25 21:28:26 +01:00
$mes -> addInfo ( LAN_MAILOUT_79 );
2021-01-16 13:32:35 -08:00
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_171 , $mes -> render () );
2020-12-18 19:55:12 -08:00
exit ;
2013-02-20 21:11:17 +00:00
}
2015-05-13 02:03:36 -07:00
$text = "
2014-10-11 12:54:16 -07:00
< form action = '" . e_SELF . "?mode=saved' id = 'email_show_template' method = 'post' >
2013-02-20 21:11:17 +00:00
< fieldset id = 'email-show-template' >
< table class = 'table adminlist' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody > " ;
$text .= $this -> showMailDetail ( $mailData , 'template' );
2021-01-16 13:32:35 -08:00
$text .= '<tr><td>' . LAN_MAILOUT_172 . '</td><td>' . $this -> statusToText ( $mailData [ 'mail_content_status' ]) . " <input type='hidden' name='mailIDConf' value=' " . $mailId . " ' /></td></tr> " ;
2013-02-20 21:11:17 +00:00
$text .= " </tbody></table> \n </fieldset> " ;
$text .= " <div class='buttons-bar center'>
2014-10-11 12:54:16 -07:00
" . $frm->admin_button ('email_delete', LAN_MAILOUT_256, 'other') . "
2013-02-25 21:28:26 +01:00
</ div > " ;
2013-02-20 21:11:17 +00:00
2013-02-25 21:28:26 +01:00
$text .= " </form> " ;
2014-10-11 12:54:16 -07:00
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_255 . $mailId , $text );
2013-02-20 21:11:17 +00:00
}
/**
* Show a screen to confirm deletion of an email
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $mailid - number of email
* @ param $nextPage - 'mode' specification for page to return to following delete
2021-12-03 14:58:33 -08:00
* @ return void for display
2013-02-20 21:11:17 +00:00
*/
2021-02-13 07:58:24 -08:00
2014-10-11 12:54:16 -07:00
public function showDeleteConfirm ( $mailID , $nextPage = 'saved' )
{
$mailData = $this -> retrieveEmail ( $mailID );
$frm = e107 :: getForm ();
$ns = e107 :: getRender ();
$mes = e107 :: getMessage ();
if ( $mailData === FALSE )
{
$mes -> addInfo ( LAN_MAILOUT_79 );
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_171 , $mes -> render () . $text );
exit ;
}
$text .= "
< form
action = '".e_SELF.' ? mode = maildeleteconfirm & amp ; m = '.$mailID.' & amp ; savepage = '.$nextPage."'
id = 'email_delete' method = 'post' >
< fieldset id = 'email-delete' >
< table class = 'table adminlist' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody > " ;
$text .= $this -> showMailDetail ( $mailData , 'basic' );
$text .=
'<tr><td>' . LAN_MAILOUT_172 . '</td><td>' . $this -> statusToText ( $mailData [ 'mail_content_status' ]) . " <input
type = 'hidden' name = 'mailIDConf' value = '{$mailID}' /></ td ></ tr > " ;
if ( $mailData [ 'mail_content_status' ] != MAIL_STATUS_SAVED )
{
$text .= '<tr><td>' . LAN_MAILOUT_173 . '</td><td>' . ( $mailData [ 'mail_togo_count' ] +
$mailData [ 'mail_sent_count' ] + $mailData [ 'mail_fail_count' ]) . '</td></tr>' ;
}
$text .= " </tbody></table> \n </fieldset> " ;
$text .= " <div class='buttons-bar center'>
" . $frm->admin_button ('email_delete', LAN_DELETE, 'delete'). "
" . $frm->admin_button ('email_cancel', LAN_CANCEL, 'cancel'). "
</ div >
</ form > " ;
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_171 , $text );
}
2021-02-13 07:58:24 -08:00
2013-02-20 21:11:17 +00:00
/**
2014-10-11 12:54:16 -07:00
* Generate the HTML to show a list of emails of a particular type , in tabular
* form
*
2013-02-20 21:11:17 +00:00
* @ param $type - type of email to display ( saved | sent | pending | held )
* @ param $from - offset into table of candidates
* @ param $amount - number to return
* @ return text for display
*/
2014-10-10 22:58:47 -07:00
/*
2014-10-11 12:54:16 -07:00
public function showEmailList ( $type , $from = 0 , $amount = 10 )
{
// Need to select main email entries; count number of addresses attached to each
$gen = new convert ;
$frm = e107 :: getForm ();
$ns = e107 :: getRender ();
$mes = e107 :: getMessage ();
$tp = e107 :: getParser ();
switch ( $type )
{
case 'sent' :
$searchType = 'allcomplete' ;
break ;
default :
$searchType = $type ;
}
if ( $from < 0 ) { $from = $this -> showFrom ; }
if ( $amount < 0 ) { $amount = $this -> showCount ; }
// in $_GET, so = sort order, sf = sort field
$count = $this -> selectEmailStatus ( $from , $amount , '*' , $searchType ,
$this -> sortField , $this -> sortOrder );
$totalCount = $this -> getEmailCount ();
$emails_found = array (); // Log ID and count for later
if ( ! $count )
{
$mes -> addInfo ( LAN_MAILOUT_79 );
$ns -> tablerender ( $this -> tasks [ $type ][ 'title' ], $mes -> render () . $text );
return ;
}
$text = "
< form action = '".e_SELF.' ? '.e_QUERY."' id = 'email_list' method = 'post' >
< fieldset id = 'emails-list' >
< table class = 'table adminlist' > " ;
$fieldPrefs = $this -> calcFieldSpec ( $type , TRUE ); // Get columns to display
// Must use '&' rather than '&' in query pattern
$text .=
$frm -> colGroup ( $this -> fields [ 'mail_content' ], $this -> fieldPref ) . $frm -> thead ( $this -> fields [ 'mail_content' ], $this -> fieldPref , 'mode=' . $type . " &fld=[FIELD]&asc=[ASC]&frm=[FROM] " ) . " <tbody> " ;
while ( $row = $this -> getNextEmailStatus ( FALSE ))
{
//print_a($row);
$text .= '<tr>' ;
foreach ( $fieldPrefs as $fieldName )
{ // Output column data value
$text .= '<td>' ;
if ( isset ( $row [ $fieldName ]))
{
$proctype = varset ( $this -> fields [ 'mail_content' ][ $fieldName ][ 'proc' ],
'default' );
switch ( $proctype )
{
case 'username' :
$text .= $this -> getUserName ( $row [ $fieldName ]);
break ;
case 'sdatetime' :
$text .= $gen -> convert_date ( $row [ $fieldName ], 'short' );
break ;
case 'trunc200' :
$text .= $tp -> text_truncate ( $row [ $fieldName ], 200 , '...' );
break ;
case 'chars' : // Show generated html as is
$text .= htmlspecialchars ( $row [ $fieldName ], ENT_COMPAT , 'UTF-8' );
break ;
case 'contentstatus' :
$text .= $this -> statusToText ( $row [ $fieldName ]);
break ;
case 'selectors' :
$text .= 'cannot display' ;
break ;
case 'yesno' :
$text .= $row [ $fieldName ] ? LAN_YES : LAN_NO ;
break ;
case 'default' :
default :
$text .= $row [ $fieldName ];
}
}
else
{ // Special stuff
}
$text .= '</td>' ;
}
// Add in options here
$text .= '<td>' . $this -> makeMailOptions ( $type , $row ) . '</td>' ;
$text .= '</tr>' ;
}
$text .= " </tbody></table><br /><br /> \n " ;
if ( $totalCount > $count )
{
$parms =
" { $totalCount } , { $amount } , { $from } , " . e_SELF . " ?mode= { $type } &count= { $amount } &frm=[FROM]&fld= { $this -> sortField } &asc= { $this -> sortOrder } " ;
$text .= $tp -> parseTemplate ( " { NEXTPREV= { $parms } } " );
}
$text .= '</fieldset></form>' ;
$ns -> tablerender ( ADLAN_136 . SEP . $this -> tasks [ $type ][ 'title' ], $text );
}
*/
2013-02-20 21:11:17 +00:00
/**
* Generate a list of emails to send
* Returns various information to display in a confirmation screen
*
2014-10-11 12:54:16 -07:00
* The email and its recipients are stored in the DB with a tag of
* 'MAIL_STATUS_TEMP' if its a new email ( no change if already on hold )
*
2013-02-20 21:11:17 +00:00
* @ param array $mailData - Details of the email , selection criteria etc
2014-10-11 12:54:16 -07:00
* @ param boolean $fromHold - FALSE if this is a 'new' email to send , TRUE if its
* already been put on hold ( selects processing path )
2021-12-03 14:58:33 -08:00
* @ return false | string for display
2013-02-20 21:11:17 +00:00
*/
2020-12-18 19:55:12 -08:00
public function sendEmailCircular ( $mailData , $fromHold = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
$frm = e107 :: getForm ();
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
if ( $fromHold )
2014-10-11 12:54:16 -07:00
{
// Email data already generated
2013-02-20 21:11:17 +00:00
$mailMainID = $mailData [ 'mail_source_id' ];
2020-12-18 19:55:12 -08:00
if ( $mailMainID == 0 )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
return false ;
}
if ( false === ( $mailData = $this -> retrieveEmail ( $mailMainID ))) // Get the new data
{
return false ;
2013-02-20 21:11:17 +00:00
}
2014-10-11 12:54:16 -07:00
$counters [ 'add' ] = $mailData [ 'mail_togo_count' ];
// Set up the counters
2013-02-20 21:11:17 +00:00
$counters [ 'dups' ] = 0 ;
}
else
{
// Start by saving the email
2014-10-12 02:37:43 -07:00
/*
2013-02-20 21:11:17 +00:00
$mailData [ 'mail_content_status' ] = MAIL_STATUS_TEMP ;
$mailData [ 'mail_create_app' ] = 'core' ;
$result = $this -> saveEmail ( $mailData , TRUE );
2014-10-11 12:54:16 -07:00
// $result = $this->saveEmail($mailData, false); // false = update, not insert.
if ( is_numeric ( $result ))
2013-02-20 21:11:17 +00:00
{
$mailMainID = $mailData [ 'mail_source_id' ] = $result ;
}
else
{
2014-10-11 12:54:16 -07:00
e107 :: getMessage () -> addDebug ( " Couldn't save email. ( " . __FILE__ . " Line: " . __LINE__ . " ) " );
2013-02-20 21:11:17 +00:00
}
2014-10-12 02:37:43 -07:00
*/
2020-12-18 19:55:12 -08:00
2014-10-12 02:37:43 -07:00
$mailMainID = $mailData [ 'mail_source_id' ];
2013-02-20 21:11:17 +00:00
2014-10-12 02:37:43 -07:00
$this -> mailInitCounters ( $mailMainID ); // Initialise counters for emails added
2020-12-18 19:55:12 -08:00
foreach ( $this -> mailHandlers as $key => $m )
2014-10-11 12:54:16 -07:00
{
// Get email addresses from each handler in turn. Do them one at a time, so that
// all can use the $sql data object
2020-12-18 19:55:12 -08:00
if ( $m -> mailerEnabled && isset ( $mailData [ 'mail_selectors' ][ $key ]))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2014-10-12 02:37:43 -07:00
$mailerCount = $m -> selectInit ( $mailData [ 'mail_selectors' ][ $key ]); // Initialise
2016-05-11 12:14:58 -07:00
2020-12-18 19:55:12 -08:00
if ( ! empty ( $mailerCount ))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
while ( $row = $m -> selectAdd ()) // Get email addresses - add to list, strip duplicates
{
2014-10-12 02:37:43 -07:00
$result = $this -> mailAddNoDup ( $mailMainID , $row , MAIL_STATUS_TEMP ); // Add email addresses to the database ready for sending (the body is never saved // in the DB - it gets passed as a $_POST value)
2020-12-18 19:55:12 -08:00
if ( $result === false )
2013-02-20 21:11:17 +00:00
{
// Error
2020-12-18 19:55:12 -08:00
e107 :: getMessage () -> addDebug ( " Couldn't add receipients ( " . __FILE__ . " Line: " . __LINE__ . " ) " );
2013-02-20 21:11:17 +00:00
}
}
}
2016-05-11 12:14:58 -07:00
else
{
2020-12-18 19:55:12 -08:00
e107 :: getMessage () -> addWarning ( $key . " : no matching recipients " );
2016-05-11 12:14:58 -07:00
}
2014-10-11 12:54:16 -07:00
$m -> select_close ();
// Close
2013-02-20 21:11:17 +00:00
// Update the stats after each handler
$this -> mailUpdateCounters ( $mailMainID );
}
}
$counters = $this -> mailRetrieveCounters ( $mailMainID );
2020-12-18 09:39:02 -08:00
// $this->e107->admin_log->add('MAIL_02','ID: '.$mailMainID.'
2014-10-11 12:54:16 -07:00
// '.$counters['add'].'[!br!]'.$_POST['email_from_name']."
// <".$_POST['email_from_email'],E_LOG_INFORMATIVE,'');
2013-02-20 21:11:17 +00:00
}
// We've got all the email addresses here - display a confirmation form
// Include start/end dates for send
2014-10-11 12:54:16 -07:00
// $text = "<form action='".e_SELF.'?mode=marksend&m='.$mailMainID."'
// id='email_send' method='post'>";
2013-02-25 21:28:26 +01:00
$text = "
2014-10-11 12:54:16 -07:00
< form action = '" . e_SELF . "' id = 'email_send' method = 'post' >
2013-02-20 21:11:17 +00:00
< fieldset id = 'email-send' >
2013-02-25 21:28:26 +01:00
< table class = 'table adminlist' >
2013-02-20 21:11:17 +00:00
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody > " ;
$text .= $this -> showMailDetail ( $mailData , 'send' );
2014-10-12 18:01:19 -07:00
$text .= '<tr><td>' . LAN_MAILOUT_03 . '</td><td>' ; // TO
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
// Add in core and any plugin selectors here
2020-12-18 19:55:12 -08:00
foreach ( $this -> mailHandlers as $key => $m )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $m -> mailerEnabled && ( $contentArray = $m -> showSelect ( false , $mailData [ 'mail_selectors' ][ $key ])))
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
$text .= $m -> mailerName . ':<ul>' ;
foreach ( $contentArray as $val )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= " <li> " . $val [ 'caption' ] . " : " . $val [ 'html' ] . " </li> " ;
2013-02-20 21:11:17 +00:00
}
2014-10-12 18:01:19 -07:00
$text .= '</ul>' ;
2013-02-20 21:11:17 +00:00
}
}
2014-10-12 18:01:19 -07:00
$text .= '</td></tr>' ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
// Figures - number of emails to send, number of duplicates stripped
2016-05-11 12:14:58 -07:00
$totalRecipients = ! empty ( $mailData [ 'mail_togo_count' ]) ? $mailData [ 'mail_togo_count' ] : $counters [ 'add' ];
$text .= '<tr><td>' . LAN_MAILOUT_173 . '</td><td>' . $totalRecipients . " <input type='hidden' name='mailIDConf' value=' { $mailMainID } ' /></td></tr> " ;
2014-10-11 12:54:16 -07:00
$text .= '<tr><td>' . LAN_MAILOUT_71 . '</td><td> ' . $counters [ 'add' ] . ' ' . LAN_MAILOUT_69 . $counters [ 'dups' ] . LAN_MAILOUT_70 . '</td></tr>' ;
2013-02-20 21:11:17 +00:00
$text .= " </tbody></table> \n </fieldset> " ;
2020-12-18 19:55:12 -08:00
$this -> updateCounter ( $mailMainID , 'total' , $counters [ 'add' ]);
$text .= $this -> makeAdvancedOptions ( true );
2014-10-11 12:54:16 -07:00
// Show the table of advanced options
2013-02-20 21:11:17 +00:00
$text .= " <div class='buttons-bar center'> " ;
2020-12-18 19:55:12 -08:00
$text .= " <a href=' " . e_SELF . " ?mode=main&action=sendnow&id= " . $mailMainID . " ' class='btn btn-primary'> " . LAN_MAILOUT_158 . " </a> " ;
// $text .= $frm->admin_button('email_sendnow', "Send Now", 'primary');
2017-02-13 08:18:33 +01:00
$text .= $frm -> admin_button ( 'email_send' , LAN_MAILOUT_269 );
2014-10-11 12:54:16 -07:00
2014-02-07 07:33:33 -08:00
// $text .= "<input type='submit' name='email_send' value=\"".LAN_SEND."\" />";
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
if ( ! $fromHold )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= $frm -> admin_button ( 'email_hold' , LAN_HOLD , 'warning' );
$text .= $frm -> admin_button ( 'email_cancel' , LAN_CANCEL , 'delete' );
// $text .= " <input type='submit' name='email_hold' value=\"".LAN_HOLD."\"
// />";
// $text .= " <input type='submit' name='email_cancel'
// value=\"".LAN_CANCEL."\" />";
2013-02-20 21:11:17 +00:00
}
2014-10-11 12:54:16 -07:00
$text .= $frm -> hidden ( 'email_id' , $mailMainID );
2013-02-20 21:11:17 +00:00
$text .= " </div>
</ form >
</ div > " ;
2014-10-11 12:54:16 -07:00
return $text ;
// e107::getRender()->tablerender(ADLAN_136.SEP.LAN_MAILOUT_179, $mes->render().
// $text);
} // End of previewed email
2013-02-20 21:11:17 +00:00
/**
*
*/
2020-12-18 19:55:12 -08:00
protected function makeAdvancedOptions ( $initHide = false )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
// Separate table for advanced mailout options
// mail_notify_complete field
$text = "
2014-10-11 12:54:16 -07:00
< legend > " . LAN_MAILOUT_242 . " </ legend >
2013-02-20 21:11:17 +00:00
< fieldset id = 'email-send-options' >
2013-02-25 21:28:26 +01:00
< table class = 'table adminlist' >
2013-02-20 21:11:17 +00:00
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody > " ;
2014-10-11 12:54:16 -07:00
$text .= " <tr><td> " . LAN_MAILOUT_238 . " </td><td> " . $this -> makeCalendar ( 'mail_earliest_time' , '' , CORE_DATE_ORDER ) . " </td></tr> " ;
$text .= " <tr><td> " . LAN_MAILOUT_239 . " </td><td> " . $this -> makeCalendar ( 'mail_latest_time' , '' , CORE_DATE_ORDER ) . " </td></tr> " ;
// Can comment the two lines above, uncomment two lines below, and default
// time/date is shown. May or may not be preferable
// $text .=
// "<tr><td>".LAN_MAILOUT_238."</td><td>".$this->makeCalendar('mail_earliest_time',
// time(), CORE_DATE_ORDER)."</td></tr>";
// $text .=
// "<tr><td>".LAN_MAILOUT_239."</td><td>".$this->makeCalendar('mail_latest_time',
// time()+86400, CORE_DATE_ORDER)."</td></tr>";
$text .= " <tr><td> " . LAN_MAILOUT_240 . " </td><td><input type='checkbox' value='1' name='mail_notify_complete' /> " . LAN_MAILOUT_241 . " </td></tr> " ;
2013-02-20 21:11:17 +00:00
$text .= " </tbody></table> \n </fieldset> " ;
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $text ;
}
/**
*
*/
public function makeCalendar ( $calName , $calVal = '' , $dateOrder = 'dmy' )
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
// Determine formatting strings this way, to give sensible default
switch ( $dateOrder )
{
2014-10-11 12:54:16 -07:00
case 'mdy' :
2013-02-20 21:11:17 +00:00
$dFormat = '%m/%d/%y' ;
$tFormat = '%H:%M' ;
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'ymd' :
2013-02-20 21:11:17 +00:00
$dFormat = '%Y/%m/%d' ;
$tFormat = ' %H:%M' ;
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case 'dmy' :
default :
2013-02-20 21:11:17 +00:00
$dFormat = '%d/%m/%Y' ;
$tFormat = ' %H:%M' ;
}
$options = array (
2020-12-18 19:55:12 -08:00
'type' => 'datetime' ,
'format' => $dFormat . " " . $tFormat ,
2014-10-11 12:54:16 -07:00
// 'timeformat' => $tFormat,
'firstDay' => 1 , // 0 = Sunday.
2020-12-18 19:55:12 -08:00
'size' => 12
2014-10-11 12:54:16 -07:00
);
// $options['dateFormat'] = $dformat;
// $options['timeFormat'] = $tformat;
2013-02-20 21:11:17 +00:00
2014-10-11 12:54:16 -07:00
return e107 :: getForm () -> datepicker ( $calName , $calVal , $options );
}
2013-02-20 21:11:17 +00:00
2014-10-12 02:37:43 -07:00
2013-02-20 21:11:17 +00:00
/**
* Show recipients of an email
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ param $mailid - number of email
* @ param $nextPage - 'mode' specification for page to return to following delete
* @ return text for display
*/
2014-10-12 02:37:43 -07:00
/*
2013-02-20 21:11:17 +00:00
public function showmailRecipients ( $mailID , $nextPage = 'saved' )
{
$gen = new convert ;
$frm = e107 :: getForm ();
2013-02-25 21:28:26 +01:00
$mes = e107 :: getMessage ();
2013-03-26 12:16:55 +01:00
$tp = e107 :: getParser ();
$ns = e107 :: getRender ();
2013-02-20 21:11:17 +00:00
$mailData = $this -> retrieveEmail ( $mailID );
2014-10-11 12:54:16 -07:00
if ( $mailData === FALSE )
2013-02-20 21:11:17 +00:00
{
2013-02-25 21:28:26 +01:00
$mes -> addInfo ( LAN_MAILOUT_79 );
2014-10-11 12:54:16 -07:00
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_171 , $mes -> render () . $text );
exit ;
2013-02-20 21:11:17 +00:00
}
$text .= "
2014-10-11 12:54:16 -07:00
< form action = '" . e_SELF . ' ? ' . e_QUERY . "' id = 'email_recip_header' method = 'post' >
2013-02-20 21:11:17 +00:00
< fieldset id = 'email-recip_header' >
2013-02-25 21:28:26 +01:00
< table class = 'table adminlist' >
2013-02-20 21:11:17 +00:00
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody > " ;
$text .= $this -> showMailDetail ( $mailData , 'basic' );
2014-10-11 12:54:16 -07:00
$text .= '<tr><td>' . LAN_MAILOUT_172 . '</td><td>' . $this -> statusToText ( $mailData [ 'mail_content_status' ]) . " <input type='hidden' name='mailIDConf' value=' { $mailID } ' /></td></tr> " ;
if ( $mailData [ 'mail_content_status' ] != MAIL_STATUS_SAVED )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= '<tr><td>' . LAN_MAILOUT_173 . '</td><td>' . ( $mailData [ 'mail_togo_count' ] + $mailData [ 'mail_sent_count' ] + $mailData [ 'mail_fail_count' ]) . '</td></tr>' ;
2013-02-20 21:11:17 +00:00
}
$text .= " </tbody></table> \n </fieldset></form> " ;
// List of recipients
// in $_GET, asc = sort order, fld = sort field
$count = $this -> selectTargetStatus ( $mailID , $this -> showFrom , $this -> showCount , '*' , FALSE , $this -> sortField , $this -> sortOrder );
$totalCount = $this -> getTargetCount ();
2014-10-11 12:54:16 -07:00
if ( $count == 0 )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= " <span class='required'> " . LAN_MAILOUT_253 . '</span>' ;
2013-02-20 21:11:17 +00:00
}
else
{
$text .= "
2014-10-11 12:54:16 -07:00
< form action = '" . e_SELF . "?mode=recipients&m={$mailID}&count={$count}&frm={$this->showFrom}&fld={$this->sortField}&asc={$this->sortOrder}&savepage={$nextPage}' id = 'email_recip_body' method = 'post' >
2013-02-20 21:11:17 +00:00
< fieldset id = 'email-recip_body' >
2013-02-25 21:28:26 +01:00
< table class = 'table adminlist' > " ;
2013-02-20 21:11:17 +00:00
2014-10-11 12:54:16 -07:00
$fieldPrefs = $this -> calcFieldSpec ( 'recipients' , TRUE );
// Get columns to display
2013-02-20 21:11:17 +00:00
// Must use '&' rather than '&' in query pattern
2014-10-11 12:54:16 -07:00
$text .= $frm -> colGroup ( $this -> fields [ 'mail_recipients' ], $this -> fieldPref ) . $frm -> thead ( $this -> fields [ 'mail_recipients' ], $this -> fieldPref , 'mode=' . 'recipients&m=' . $mailID . " &fld=[FIELD]&asc=[ASC]&frm=[FROM] " ) . " <tbody> " ;
2013-02-20 21:11:17 +00:00
2014-10-11 12:54:16 -07:00
while ( $row = $this -> getNextTargetStatus ( FALSE ))
2013-02-20 21:11:17 +00:00
{
// print_a($row);
$text .= '<tr>' ;
2014-10-11 12:54:16 -07:00
foreach ( $fieldPrefs as $fieldName )
{
// Output column data value
2013-02-20 21:11:17 +00:00
$text .= '<td>' ;
2014-10-11 12:54:16 -07:00
if ( isset ( $row [ $fieldName ]))
2013-02-20 21:11:17 +00:00
{
$proctype = varset ( $this -> fields [ 'mail_recipients' ][ $fieldName ][ 'proc' ], 'default' );
switch ( $proctype )
{
2014-10-11 12:54:16 -07:00
case 'username' :
2013-02-20 21:11:17 +00:00
$text .= $this -> getUserName ( $row [ $fieldName ]);
2014-10-11 12:54:16 -07:00
break ;
case 'sdatetime' :
2013-02-20 21:11:17 +00:00
$text .= $gen -> convert_date ( $row [ $fieldName ], 'short' );
2014-10-11 12:54:16 -07:00
break ;
case 'trunc200' :
2013-03-26 12:16:55 +01:00
$text .= $tp -> text_truncate ( $row [ $fieldName ], 200 , '...' );
2014-10-11 12:54:16 -07:00
break ;
case 'chars' :
// Show generated html as is
2013-02-20 21:11:17 +00:00
$text .= htmlspecialchars ( $row [ $fieldName ], ENT_COMPAT , 'UTF-8' );
2014-10-11 12:54:16 -07:00
break ;
case 'contentstatus' :
2013-02-20 21:11:17 +00:00
$text .= $this -> statusToText ( $row [ $fieldName ]);
2014-10-11 12:54:16 -07:00
break ;
case 'selectors' :
2013-02-20 21:11:17 +00:00
$text .= 'cannot display' ;
2014-10-11 12:54:16 -07:00
break ;
case 'array' :
if ( is_array ( $row [ $fieldName ]))
2013-02-20 21:11:17 +00:00
{
$nl = '' ;
2014-10-11 12:54:16 -07:00
foreach ( $row [ $fieldName ] as $k => $v )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
if ( $v )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$text .= $nl . $k . ' => ' . $v ;
2013-02-20 21:11:17 +00:00
$nl = '<br />' ;
}
}
}
else
{
$text .= 'bad data: ' ;
}
2014-10-11 12:54:16 -07:00
break ;
case 'default' :
default :
2013-02-20 21:11:17 +00:00
$text .= $row [ $fieldName ];
}
}
else
2014-10-11 12:54:16 -07:00
{
// Special stuff
2013-02-20 21:11:17 +00:00
$text .= 'special' ;
}
$text .= '</td>' ;
}
// Add in options here
2014-10-11 12:54:16 -07:00
$text .= '<td>' . $this -> makeTargetOptions ( 'recipients' , $row ) . '</td>' ;
2013-02-20 21:11:17 +00:00
$text .= '</tr>' ;
}
$text .= " </tbody></table> \n </fieldset></form><br /><br /> " ;
2014-10-11 12:54:16 -07:00
if ( $totalCount > $count )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$parms = " { $totalCount } , { $this -> showCount } , { $this -> showFrom } , " . e_SELF . " ?mode=recipients&m= { $mailID } &count= { $this -> showCount } &frm=[FROM]&fld= { $this -> sortField } &asc= { $this -> sortOrder } &savepage= { $nextPage } " ;
2013-02-25 21:28:26 +01:00
$text .= $tp -> parseTemplate ( " { NEXTPREV= { $parms } } " );
2013-02-20 21:11:17 +00:00
}
}
2014-10-11 12:54:16 -07:00
$ns -> tablerender ( ADLAN_136 . SEP . LAN_MAILOUT_181 , $mes -> render () . $text );
2013-02-20 21:11:17 +00:00
}
2014-10-12 02:37:43 -07:00
*/
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
/**
* Clean up mailout DB
* Dump array of results to admin log
2014-10-11 12:54:16 -07:00
*
2013-02-20 21:11:17 +00:00
* @ return boolean TRUE if no errors , FALSE if errors
*/
public function dbTidy ()
{
2020-12-18 19:55:12 -08:00
$noError = true ;
2013-02-20 21:11:17 +00:00
$results = array ();
2014-10-11 12:54:16 -07:00
$this -> checkDB ( 2 );
// Make sure DB object created
2013-02-20 21:11:17 +00:00
// First thing, delete temporary records from both tables
2020-12-18 19:55:12 -08:00
if (( $res = $this -> db2 -> db_Delete ( 'mail_content' , '`mail_content_status` = ' . MAIL_STATUS_TEMP )) === false )
2013-02-20 21:11:17 +00:00
{
2020-03-01 13:16:36 -08:00
$results [] = 'Error ' . $this -> db2 -> getLastErrorNumber () . ':' . $this -> db2 -> getLastErrorText () . ' deleting temporary records from mail_content' ;
2020-12-18 19:55:12 -08:00
$noError = false ;
2013-02-20 21:11:17 +00:00
}
else
{
2020-12-18 19:55:12 -08:00
if ( $res )
{
2014-10-11 12:54:16 -07:00
$results [] = str_replace ( array (
2017-11-06 13:48:08 -08:00
'[x]' ,
2017-11-06 14:15:58 -08:00
'[y]'
2014-10-11 12:54:16 -07:00
), array (
$res ,
'mail_content'
), LAN_MAILOUT_227 );
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
if (( $res = $this -> db2 -> delete ( 'mail_recipients' , '`mail_status` = ' . MAIL_STATUS_TEMP )) === false )
2013-02-20 21:11:17 +00:00
{
2020-03-01 13:16:36 -08:00
$results [] = 'Error ' . $this -> db2 -> getLastErrorNumber () . ':' . $this -> db2 -> getLastErrorText () . ' deleting temporary records from mail_recipients' ;
2020-12-18 19:55:12 -08:00
$noError = false ;
2013-02-20 21:11:17 +00:00
}
else
{
2020-12-18 19:55:12 -08:00
if ( $res )
{
2014-10-11 12:54:16 -07:00
$results [] = str_replace ( array (
2017-11-06 13:48:08 -08:00
'[x]' ,
2017-11-06 14:15:58 -08:00
'[y]'
2014-10-11 12:54:16 -07:00
), array (
$res ,
'mail_recipients'
), LAN_MAILOUT_227 );
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
}
// Now look for 'orphaned' recipient records
2020-12-18 19:55:12 -08:00
if (( $res = $this -> db2 -> gen ( " DELETE `#mail_recipients` FROM `#mail_recipients`
2013-02-20 21:11:17 +00:00
LEFT JOIN `#mail_content` ON `#mail_recipients` . `mail_detail_id` = `#mail_content` . `mail_source_id`
2020-12-18 19:55:12 -08:00
WHERE `#mail_content` . `mail_source_id` IS NULL " )) === false)
2013-02-20 21:11:17 +00:00
{
2020-03-01 13:16:36 -08:00
$results [] = 'Error ' . $this -> db2 -> getLastErrorNumber () . ':' . $this -> db2 -> getLastErrorText () . ' deleting orphaned records from mail_recipients' ;
2020-12-18 19:55:12 -08:00
$noError = false ;
2013-02-20 21:11:17 +00:00
}
2020-12-18 19:55:12 -08:00
elseif ( $res )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $res )
{
2017-11-06 13:48:08 -08:00
$results [] = str_replace ( '[x]' , $res , LAN_MAILOUT_226 );
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
}
// Scan content table for anomalies, out of time records
2020-12-18 19:55:12 -08:00
if (( $res = $this -> db2 -> gen ( " SELECT * FROM `#mail_content`
2014-10-11 12:54:16 -07:00
WHERE ( `mail_content_status` > " . MAIL_STATUS_FAILED . " ) AND ( `mail_content_status` <= " . MAIL_STATUS_MAX_ACTIVE . " )
2020-12-18 19:55:12 -08:00
AND (( `mail_togo_count` = 0 ) OR ( ( `mail_last_date` != 0 ) AND ( `mail_last_date` < " . time() . " ))) " )) === false)
2013-02-20 21:11:17 +00:00
{
2020-03-01 13:16:36 -08:00
$results [] = 'Error ' . $this -> db2 -> getLastErrorNumber () . ':' . $this -> db2 -> getLastErrorText () . ' checking bad status in mail_content' ;
2020-12-18 19:55:12 -08:00
$noError = false ;
2013-02-20 21:11:17 +00:00
}
else
{
2014-10-11 12:54:16 -07:00
$items = array ();
// Store record number of any content record that needs to be changed
2020-12-18 19:55:12 -08:00
while ( $row = $this -> db2 -> fetch ())
2013-02-20 21:11:17 +00:00
{
$items [] = $row [ 'mail_source_id' ];
2020-12-18 19:55:12 -08:00
if ( $row [ 'mail_source_id' ])
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( false == $this -> cancelEmail ( $row [ 'mail_source_id' ]))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$results [] = 'Error cancelling email ref: ' . $row [ 'mail_source_id' ];
2013-02-20 21:11:17 +00:00
}
else
{
2014-10-11 12:54:16 -07:00
$results [] = 'Email cancelled: ' . $row [ 'mail_source_id' ];
2013-02-20 21:11:17 +00:00
}
}
}
2020-12-18 19:55:12 -08:00
if ( count ( $items ))
{
2014-10-11 12:54:16 -07:00
$results [] = str_replace ( array (
2017-11-06 13:48:08 -08:00
'[x]' ,
'[y]'
2014-10-11 12:54:16 -07:00
), array (
count ( $items ),
implode ( ', ' , $items )
), LAN_MAILOUT_228 );
2020-12-18 19:55:12 -08:00
}
2014-10-11 12:54:16 -07:00
}
//Finally - check for inconsistent recipient and content status records -
// basically verify counts
2020-12-18 19:55:12 -08:00
if (( $res = $this -> db2 -> gen ( " SELECT COUNT(mr.`mail_status`) AS mr_count, mr.`mail_status`,
2013-02-20 21:11:17 +00:00
mc . `mail_source_id` , mc . `mail_togo_count` , mc . `mail_sent_count` , mc . `mail_fail_count` , mc . `mail_bounce_count` , mc . `mail_source_id` FROM `#mail_recipients` AS mr
LEFT JOIN `#mail_content` AS mc ON mr . `mail_detail_id` = mc . `mail_source_id`
2014-10-11 12:54:16 -07:00
WHERE mc . `mail_content_status` <= " . MAIL_STATUS_MAX_ACTIVE . "
2013-02-20 21:11:17 +00:00
GROUP BY mr . `mail_status` , mc . `mail_source_id` ORDER BY mc . `mail_source_id`
2020-12-18 19:55:12 -08:00
" )) === false)
2013-02-20 21:11:17 +00:00
{
2020-03-01 13:16:36 -08:00
$results [] = 'Error ' . $this -> db2 -> getLastErrorNumber () . ':' . $this -> db2 -> getLastErrorText () . ' assembling email counts' ;
2020-12-18 19:55:12 -08:00
$noError = false ;
2013-02-20 21:11:17 +00:00
}
else
{
2014-10-11 12:54:16 -07:00
$lastMail = 0 ;
// May get several rows per mail
2020-12-18 19:55:12 -08:00
$notLast = true ;
2014-10-11 12:54:16 -07:00
// This forces one more loop, so we can clean up for last record read
2013-02-20 21:11:17 +00:00
$changeCount = 0 ;
$saveRow = array ();
2020-12-18 19:55:12 -08:00
while (( $row = $this -> db2 -> fetch ()) || $notLast )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if (( $lastMail > 0 && $row === false ) || ( $lastMail != $row [ 'mail_source_id' ]))
2014-10-11 12:54:16 -07:00
{
// Change of mail ID here - handle any accumulated info
2020-12-18 19:55:12 -08:00
if ( $lastMail > 0 )
2014-10-11 12:54:16 -07:00
{
// Need to verify counts for mail just read
2013-02-20 21:11:17 +00:00
$changes = array ();
2020-12-18 19:55:12 -08:00
foreach ( $counters as $k => $v )
2013-02-20 21:11:17 +00:00
{
2020-12-18 19:55:12 -08:00
if ( $saveRow [ $k ] != $v )
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$changes [ $k ] = $v ;
// Assume the counters have got it right
2013-02-20 21:11:17 +00:00
}
}
2020-12-18 19:55:12 -08:00
if ( count ( $changes ))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
// *************** Update mail record here *********************
2013-02-20 21:11:17 +00:00
$this -> checkDB ( 1 );
2014-10-11 12:54:16 -07:00
$this -> db -> update ( 'mail_content' , array (
2020-12-18 19:55:12 -08:00
'data' => $changes ,
'WHERE' => '`mail_source_id` = ' . $lastMail ,
2014-10-11 12:54:16 -07:00
'_FIELDS' => $this -> dbTypes [ 'mail_content' ]
));
2013-02-20 21:11:17 +00:00
$line = " Count update for { $saveRow [ 'mail_source_id' ] } - { $saveRow [ 'mail_togo_count' ] } , { $saveRow [ 'mail_sent_count' ] } , { $saveRow [ 'mail_fail_count' ] } , { $saveRow [ 'mail_bounce_count' ] } => " ;
2014-10-11 12:54:16 -07:00
$line .= implode ( ', ' , $counters );
2013-02-20 21:11:17 +00:00
$results [] = $line ;
$changeCount ++ ;
//echo $line.'<br />';
}
}
2014-10-11 12:54:16 -07:00
2013-02-20 21:11:17 +00:00
// Now reset for current mail
$lastMail = $row [ 'mail_source_id' ];
2014-10-11 12:54:16 -07:00
$counters = array (
2020-12-18 19:55:12 -08:00
'mail_togo_count' => 0 ,
'mail_sent_count' => 0 ,
'mail_fail_count' => 0 ,
2014-10-11 12:54:16 -07:00
'mail_bounce_count' => 0
);
2013-02-20 21:11:17 +00:00
$saveRow = $row ;
}
2020-12-18 19:55:12 -08:00
if ( $row === false )
{
$notLast = false ;
}
2014-10-11 12:54:16 -07:00
// We get one record for each mail_status value for a given email - use them to
// update counts
2020-12-18 19:55:12 -08:00
if ( $notLast )
2013-02-20 21:11:17 +00:00
{
switch ( $row [ 'mail_status' ])
{
2014-10-11 12:54:16 -07:00
case MAIL_STATUS_SENT :
// Mail sent. Email handler happy, but may have bounced (or may be yet to bounce)
2013-02-20 21:11:17 +00:00
$counters [ 'mail_sent_count' ] += $row [ 'mr_count' ];
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case MAIL_STATUS_BOUNCED :
$counters [ 'mail_sent_count' ] += $row [ 'mr_count' ];
// It was sent, so increment that counter
$counters [ 'mail_bounce_count' ] += $row [ 'mr_count' ];
//...but bounced, so extra status
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case MAIL_STATUS_CANCELLED :
2020-12-18 19:55:12 -08:00
// Cancelled email - treat as a failure
2014-10-11 12:54:16 -07:00
case MAIL_STATUS_FAILED :
$counters [ 'mail_fail_count' ] += $row [ 'mr_count' ];
// Never sent at all
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
case MAIL_STATUS_PARTIAL :
// Shouldn't get this on individual emails - ignore if we do
2020-12-18 19:55:12 -08:00
break ;
2014-10-11 12:54:16 -07:00
default :
2020-12-18 19:55:12 -08:00
if (( $row [ 'mail_status' ] >= MAIL_STATUS_PENDING ) && ( $row [ 'mail_status' ] <= MAIL_STATUS_MAX_ACTIVE ))
2013-02-20 21:11:17 +00:00
{
2014-10-11 12:54:16 -07:00
$counters [ 'mail_togo_count' ] += $row [ 'mr_count' ];
// Still in the queue
2013-02-20 21:11:17 +00:00
}
}
}
}
2020-12-18 19:55:12 -08:00
if ( $changeCount )
{
2017-11-06 13:48:08 -08:00
$results [] = str_replace ( '[x]' , $changeCount , LAN_MAILOUT_237 );
2020-12-18 19:55:12 -08:00
}
2013-02-20 21:11:17 +00:00
}
2014-10-23 11:07:18 -07:00
e107 :: getLog () -> add ( 'MAIL_05' , implode ( '[!br!]' , $results ), E_LOG_INFORMATIVE , '' );
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
return $noError ;
}
/**
2020-12-18 19:55:12 -08:00
* Get a list of all the available email templates , by name and variable name
2013-02-20 21:11:17 +00:00
*
2020-12-18 19:55:12 -08:00
* @ param string $sel - currently ( all | system | user ) - selects template type
2013-02-20 21:11:17 +00:00
*
2020-12-18 19:55:12 -08:00
* @ return array - key is the variable name of the template , value is the stored
2014-10-11 12:54:16 -07:00
* template name
2013-02-20 21:11:17 +00:00
*/
public function getEmailTemplateNames ( $sel = 'all' )
{
2020-12-18 19:55:12 -08:00
2013-02-20 21:11:17 +00:00
$ret = array ();
2014-10-11 12:54:16 -07:00
2014-10-16 23:50:47 -07:00
$templates = e107 :: getCoreTemplate ( 'email' , false , 'front' , false );
2014-10-11 12:54:16 -07:00
2020-12-18 19:55:12 -08:00
foreach ( $templates as $key => $layout )
2014-10-10 20:16:11 -07:00
{
2020-12-18 19:55:12 -08:00
if ( vartrue ( $layout [ 'name' ]))
2014-10-10 20:16:11 -07:00
{
2014-10-11 12:54:16 -07:00
$ret [ $key ] = $layout [ 'name' ];
2014-10-10 20:16:11 -07:00
}
2014-10-11 12:54:16 -07:00
2014-10-10 20:16:11 -07:00
}
return $ret ;
/*
2014-10-11 12:54:16 -07:00
foreach ( array ( e_CORE . 'templates/email_template.php' ,
THEME . 'templates/email_template.php' ) as $templateFileName ) // Override file
then defaults
if ( is_readable ( $templateFileName ))
{
require ( $templateFileName );
$tVars = get_defined_vars ();
if ( isset ( $tVars [ 'GLOBALS' ])) unset ( $tVars [ 'GLOBALS' ]);
foreach ( $tVars as $tKey => $tData )
{
if ( is_array ( $tData ) && isset ( $tData [ 'template_name' ]))
{
if ( ! isset ( $tData [ 'template_type' ]) || ( $tData [ 'template_type' ] == 'all' ) ||
( $tData [ 'template_type' ] == $sel ))
{
$ret [ $tKey ] = $tData [ 'template_name' ];
}
}
if ( $tKey != 'ret' )
{
unset ( $tVars [ $tKey ]);
}
}
}
print_a ( $ret );
return $ret ;
2014-10-10 20:16:11 -07:00
*/
2013-02-20 21:11:17 +00:00
}
2016-04-08 09:01:10 -07:00
2020-12-18 19:55:12 -08:00
public static function mailerPrefsTable ( $pref , $id = 'mailer' )
2016-04-08 09:01:10 -07:00
{
$frm = e107 :: getForm ();
2020-12-18 19:55:12 -08:00
$mailers = array ( 'php' => 'php' , 'smtp' => 'smtp' , 'sendmail' => 'sendmail' );
2016-04-08 09:01:10 -07:00
2020-12-18 19:55:12 -08:00
$smtp_opts = explode ( ',' , varset ( $pref [ 'smtp_options' ], '' ));
2016-04-14 14:48:02 -07:00
$smtpdisp = ( $pref [ $id ] != 'smtp' ) ? " style='display:none;' " : '' ;
2016-04-08 09:01:10 -07:00
2020-12-18 19:55:12 -08:00
$text = $frm -> select ( $id , $mailers , $pref [ $id ]) . "
< span class = 'field-help' > " . LAN_MAILOUT_116 . " </ span > " ;
2016-04-08 09:01:10 -07:00
$text .= " <div id='smtp' { $smtpdisp } >
< table class = 'table table-bordered adminlist' style = 'margin-top:10px;width:auto;margin-right:auto;margin-left:0' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
" ;
2020-12-18 19:55:12 -08:00
$ports = array ( 25 => '25 (' . LAN_DEFAULT . " ) " , 26 => '26' , 465 => '465 (SSL)' , 587 => '587' , 2465 => '2465' , 2525 => '2525' , 2587 => '2587' );
2016-04-08 09:01:10 -07:00
$text .= "
< tr >
2020-12-18 19:55:12 -08:00
< td > " . LAN_MAILOUT_87 . " :& nbsp ; & nbsp ; </ td >
< td > " . $frm->text ('smtp_server', $pref['smtp_server'] , 128, array('size' => 'xxlarge')) . " </ td >
2016-04-08 09:01:10 -07:00
</ tr >
< tr >
2020-12-18 19:55:12 -08:00
< td > " . LAN_MAILOUT_88 . " :</ td >
< td style = 'width:50%;' > " . $frm->text ('smtp_username', $pref['smtp_username'] , 128, array('size' => 'xxlarge', 'placeholder' => " ( " . LAN_OPTIONAL . " ) " )) . " </ td >
2016-04-08 09:01:10 -07:00
</ tr >
< tr >
2020-12-18 19:55:12 -08:00
< td > " . LAN_MAILOUT_89 . " :</ td >
< td > " . $frm->password ('smtp_password', $pref['smtp_password'] , 128, array('size' => 'xxlarge', 'required' => false, 'pattern' => '. { 4,}', 'placeholder' => " ( " . LAN_OPTIONAL . " ) " , 'autocomplete' => 'new-password')) . "
2016-04-08 09:01:10 -07:00
</ td >
</ tr >
< tr >
2020-12-18 19:55:12 -08:00
< td > " . LAN_MAILOUT_261 . " </ td >
< td > " . $frm->select ('smtp_port', $ports , $pref['smtp_port'] ) . "
2016-04-08 09:01:10 -07:00
</ td >
</ tr >
< tr >
2020-12-18 19:55:12 -08:00
< td > " . LAN_MAILOUT_90 . " </ td >< td >
2021-10-19 07:41:33 -07:00
< select class = 'tbox form-control' name = 'smtp_options' > \n
2016-04-08 09:01:10 -07:00
2020-12-18 19:55:12 -08:00
< option value = '' > " . LAN_NONE . " </ option > \n " ;
$selected = ( in_array ( 'secure=SSL' , $smtp_opts ) ? " selected='selected' " : '' );
$text .= " <option value='smtp_ssl' { $selected } > " . LAN_MAILOUT_92 . " </option> \n " ;
$selected = ( in_array ( 'secure=TLS' , $smtp_opts ) ? " selected='selected' " : '' );
$text .= " <option value='smtp_tls' { $selected } > " . LAN_MAILOUT_93 . " </option> \n " ;
$selected = ( in_array ( 'pop3auth' , $smtp_opts ) ? " selected='selected' " : '' );
$text .= " <option value='smtp_pop3auth' { $selected } > " . LAN_MAILOUT_91 . " </option> \n " ;
2016-04-08 09:01:10 -07:00
$text .= " </select></td></tr> " ;
$text .= " <tr>
2020-12-18 19:55:12 -08:00
< td >< label for = 'smtp_keepalive' > " . LAN_MAILOUT_57 . " </ label ></ td >< td > \n " ;
2016-04-08 09:01:10 -07:00
2020-12-29 08:04:52 -08:00
$text .= $frm -> radio_switch ( 'smtp_keepalive' , varset ( $pref [ 'smtp_keepalive' ])) . "
2016-04-08 09:01:10 -07:00
</ td >
</ tr > " ;
$text .= " <tr>
2020-12-18 19:55:12 -08:00
< td >< label for = 'smtp_useVERP' > " . LAN_MAILOUT_95 . " </ label ></ td >< td > " . $frm->radio_switch ('smtp_useVERP', (in_array('useVERP', $smtp_opts ))) . "
2016-04-08 09:01:10 -07:00
</ td >
</ tr >
</ table ></ div > " ;
/* FIXME - posting SENDMAIL path triggers Mod - Security rules . use define () in e107_config . php instead .
// Sendmail. -------------->
$text .= " <div id='sendmail' { $senddisp } ><table style='margin-right:0px;margin-left:auto;border:0px'> " ;
$text .= "
< tr >
< td > " .LAN_MAILOUT_20. " :& nbsp ; & nbsp ; </ td >
< td >
< input class = 'tbox' type = 'text' name = 'sendmail' size = '60' value = \ " " . ( ! $pref [ 'sendmail' ] ? " /usr/sbin/sendmail -t -i -r " . $pref [ 'siteadminemail' ] : $pref [ 'sendmail' ]) . " \" maxlength='80' />
</ td >
</ tr >
</ table ></ div > " ;
*/
e107 :: js ( 'footer-inline' , "
2020-12-18 19:55:12 -08:00
$ ( '#" . $id . "' ) . on ( 'change' , function () {
2016-04-08 09:01:10 -07:00
var type = $ ( this ) . val ();
if ( type == 'smtp' )
{
$ ( '#smtp' ) . show ( 'slow' );
$ ( '#sendmail' ) . hide ( 'slow' );
return ;
}
if ( type == 'sendmail' )
{
$ ( '#smtp' ) . hide ( 'slow' );
$ ( '#sendmail' ) . show ( 'slow' );
return ;
}
$ ( '#smtp' ) . hide ( 'slow' );
$ ( '#sendmail' ) . hide ( 'slow' );
});
" );
return $text ;
}
2014-10-11 12:54:16 -07:00
}
2020-06-05 11:34:17 -07:00