array(
'mail_target_id' => array(
'title' => LAN_MAILOUT_143,
'thclass' => 'center',
'forced' => TRUE
),
'mail_recipient_id' => array(
'title' => LAN_MAILOUT_142,
'thclass' => 'center'
),
'mail_recipient_name' => array(
'title' => LAN_MAILOUT_141,
'forced' => TRUE
),
'mail_recipient_email' => array(
'title' => LAN_MAILOUT_140,
'thclass' => 'left',
'forced' => TRUE
),
'mail_status' => array(
'title' => LAN_MAILOUT_138,
'thclass' => 'center',
'proc' => 'contentstatus'
),
'mail_detail_id' => array('title' => LAN_MAILOUT_137),
'mail_send_date' => array(
'title' => LAN_MAILOUT_139,
'proc' => 'sdatetime'
),
'mail_target_info' => array(
'title' => LAN_MAILOUT_148,
'proc' => 'array'
),
'options' => array(
'title' => LAN_OPTIONS,
'forced' => TRUE
)
),
'mail_content' => array(
'mail_source_id' => array(
'title' => LAN_MAILOUT_137,
'thclass' => 'center',
'forced' => TRUE
),
'mail_title' => array(
'title' => LAN_TITLE,
'forced' => TRUE
),
'mail_subject' => array(
'title' => LAN_MAILOUT_06,
'forced' => TRUE
),
'mail_content_status' => array(
'title' => LAN_MAILOUT_136,
'thclass' => 'center',
'proc' => 'contentstatus'
),
'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(
'title' => LAN_MAILOUT_131,
'proc' => 'sdatetime'
),
'mail_end_send' => array(
'title' => LAN_MAILOUT_132,
'proc' => 'sdatetime'
),
'mail_create_date' => array(
'title' => LAN_MAILOUT_130,
'proc' => 'sdatetime'
),
'mail_creator' => array(
'title' => LAN_MAILOUT_85,
'proc' => 'username'
),
'mail_create_app' => array('title' => LAN_MAILOUT_133),
'mail_e107_priority' => array('title' => LAN_MAILOUT_134),
'mail_notify_complete' => array(
'title' => LAN_MAILOUT_243,
'nolist' => 'TRUE'
),
'mail_last_date' => array(
'title' => LAN_MAILOUT_129,
'proc' => 'sdatetime'
),
'mail_body' => array(
'title' => LAN_MAILOUT_100,
'proc' => 'trunc200'
),
'mail_body_templated' => array(
'title' => LAN_MAILOUT_257,
'proc' => 'chars'
),
// 'mail_other' = array('title' => LAN_MAILOUT_84),
'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',
'nolist' => 'TRUE'
),
'mail_include_images' => array(
'title' => LAN_MAILOUT_224,
'proc' => 'yesno'
),
'options' => array(
'title' => LAN_OPTIONS,
'forced' => TRUE
)
)
);
// List of fields to be hidden for each action ('nolist' attribute true)
protected $hideFields = array(
'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',
// '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',
'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',
'recipients' => 'mail_detail_id'
);
// Array of info associated with each task we might do
protected $tasks = array(
'makemail' => array(
'title' => LAN_MAILOUT_190,
'defaultSort' => '',
'defaultTable' => ''
),
'saved' => array(
'title' => LAN_MAILOUT_191,
'defaultSort' => 'mail_source_id',
'defaultTable' => 'mail_content'
),
'marksend' => array(
'title' => 'Internal: marksend',
'defaultSort' => 'mail_source_id',
'defaultTable' => 'mail_content'
),
'sent' => array(
'title' => LAN_MAILOUT_192,
'defaultSort' => 'mail_source_id',
'defaultTable' => 'mail_content'
),
'pending' => array(
'title' => LAN_MAILOUT_193,
'defaultSort' => 'mail_source_id',
'defaultTable' => 'mail_content'
),
'held' => array(
'title' => LAN_MAILOUT_194,
'defaultSort' => 'mail_source_id',
'defaultTable' => 'mail_content'
),
'recipients' => array(
'title' => LAN_MAILOUT_173,
'defaultSort' => 'mail_recipient_email',
'defaultTable' => 'mail_recipients'
),
'mailtargets' => array(
'title' => LAN_MAILOUT_173,
'defaultSort' => 'mail_recipient_email',
'defaultTable' => 'mail_recipients'
),
'prefs' => array(
'title' => ADLAN_40,
'defaultSort' => '',
'defaultTable' => ''
),
'maint' => array(
'title' => ADLAN_40,
'defaultSort' => '',
'defaultTable' => ''
)
);
// Options for mail listing dropdown - actions apertaining to a stored email
protected $modeOptions = array(
'saved' => array(
'mailedit' => LAN_MAILOUT_163,
'maildelete' => LAN_DELETE,
'mailshowtemplate' => LAN_MAILOUT_254
),
'pending' => array(
'mailsendimmediately' => "Send Immediately",
'mailhold' => LAN_MAILOUT_159,
'mailcancel' => LAN_MAILOUT_160,
'mailtargets' => LAN_MAILOUT_181
),
'held' => array(
'mailsendnow' => LAN_MAILOUT_158,
'mailcancel' => LAN_MAILOUT_160,
'mailtargets' => LAN_MAILOUT_181
),
'sent' => array(
'mailcopy' => LAN_MAILOUT_251,
'maildelete' => LAN_DELETE,
'mailtargets' => LAN_MAILOUT_181
),
'recipients' => array('mailonedelete' => LAN_DELETE)
);
// List of fields to be included in email display for various options
protected $mailDetailDisplay = array(
'basic' => array(
'mail_source_id' => 1,
'mail_title' => 1,
'mail_subject' => 1,
'mail_body' => 200
),
'send' => array(
'mail_source_id' => 1,
'mail_title' => 1,
'mail_subject' => 1,
'mail_body' => 500,
'mail_send_style' => 1
),
'template' => array(
'mail_source_id' => 1,
'mail_title' => 1,
'mail_subject' => 1,
'mail_body' => 200,
'mail_body_templated' => 'chars'
),
);
/**
* Constructor
*
*
* @return void
*/
public function __construct($mode = '')
{
parent::__construct();
$dbTable = '';
if(isset($this->tasks[$mode]))
{
$dbTable = $this->tasks[$mode]['defaultTable'];
}
if(isset($_GET['frm']))
{
$temp = intval($_GET['frm']);
if($temp < 0)
$temp = 0;
$this->showFrom = $temp;
}
if(isset($_GET['count']))
{
$temp = min(intval($_GET['count']), 50);
// Limit to 50 per page
$temp = max($temp, 5);
// ...and minimum 5 per page
$this->showCount = $temp;
}
if(isset($_GET['fld']))
{
$temp = e107::getParser()->toDB($_GET['fld']);
if(is_array($this->fields[$dbTable][$temp]))
{
$this->sortField = $temp;
}
}
if(isset($_GET['asc']))
{
$temp = strtolower(e107::getParser()->toDB($_GET['asc']));
if(($temp == 'asc') || ($temp == 'desc'))
{
$this->sortOrder = $temp;
}
}
$this->newMode($mode);
}
/**
* Set up new mode
*
* @param $mode - display mode
* @return none
*/
public function newMode($mode = '')
{
global $user_pref;
$this->mode = $mode;
$curTable = $this->tasks[$this->mode]['defaultTable'];
if($curTable)
{
if(isset($user_pref['admin_mailout_columns'][$mode]) && is_array($user_pref['admin_mailout_columns'][$mode]))
{
// Use saved list of fields to view if it exists
$this->fieldPref = $user_pref['admin_mailout_columns'][$mode];
}
else
{
// Default list is minimal fields only
$this->fieldPref = array();
foreach($this->fields[$curTable] as $f => $v)
{
if(vartrue($v['forced']))
{
$this->fieldPref[] = $f;
}
}
}
}
// Possibly the sort field needs changing
if(!isset($this->fields[$curTable][$this->sortField]))
{
$this->sortField = $this->tasks[$mode]['defaultSort'];
}
// Now hide any fields that need to be for this mode
if(isset($this->hideFields[$mode]))
{
$hideList = array_flip(explode(',', $this->hideFields[$mode]));
foreach($this->fields[$curTable] as $f => $v)
{
$this->fields[$curTable][$f]['nolist'] = isset($hideList[$f]);
}
foreach($this->fieldPref as $k => $v)// Remove from list of active fields
// (shouldn't often do anything)
{
if(isset($hideList[$v]))
{
unset($this->fieldPref[$k]);
}
}
}
}
/**
* Calculate the list of fields (columns) to be displayed for a given mode
*
* @param string $mode - display mode
* @param boolean $noOptions - set TRUE to suppress inclusion of any 'options'
* column. FALSE to include 'options' (default)
* @return array of field definitions
*/
protected function calcFieldSpec($mode, $noOptions = FALSE)
{
if(!isset($this->tasks[$mode]))
{
echo "CalcfieldSpec({$mode}) - programming bungle ";
return FALSE;
}
$ret = array();
$curTable = $this->tasks[$this->mode]['defaultTable'];
foreach($this->fields[$curTable] as $f => $v)
{
if((vartrue($v['forced']) && !vartrue($v['nolist'])) || in_array($f, $this->fieldPref))
{
if(($f != 'options') || ($noOptions === FALSE))
{
$ret[] = $f;
}
}
}
return $ret;
}
/**
* Save the column visibility prefs for this mode
*
* @param $target - display mode
* @return none
*/
/*
public function mailbodySaveColumnPref($target)
{
global $user_pref;
if (!$target) return;
if (!isset($this->tasks[$target]))
{
echo "Invalid prefs target: {$target} ";
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];
}
}
*/
/**
* Get the user name associated with a user ID.
* The result is cached in case required again
*
* @param int $uid - User ID
*
* @return string with user name and user login name (UID if user not found)
*/
protected function getUserName($uid)
{
if(!isset($this->userCache[$uid]))
{
// Look up user
$this->checkDB(2);
// Make sure DB object created
if($this->db2->select('user', 'user_name, user_loginname', 'user_id=' . intval($uid)))
{
$row = $this->db2->fetch();
$this->userCache[$uid] = $row['user_name'] . ' (' . $row['user_loginname'] . ')';
}
else
{
$this->userCache[$uid] = 'UID: ' . $uid;
}
}
return $this->userCache[$uid];
}
/**
* Generate the HTML for displaying actions box for emails
*
* Options given depend on $mode (saved|sent|pending|held), and also values in
* the email data.
*
* @param array $mailData - array of email-related info
* @return string HTML for display
*/
public function makeMailOptions($mode, $mailData)
{
if(!is_numeric($mailData['mail_source_id']) || ($mailData['mail_source_id'] == 0))
{
echo "makeMailOptions ({$mode}): Programming bungle!";
print_a($mailData);
return 'Error';
}
$text = "\n";
return $text;
}
/**
* Generate the HTML for displaying actions box for emails
*
* Options given depend on $mode, and also values in the email data.
*
* @param $mailData - array of email-related info
* @return HTML for display
*/
public function makeTargetOptions($mode, $targetData)
{
if(!is_numeric($targetData['mail_target_id']) || ($targetData['mail_target_id'] == 0))
{
echo "makeTargetOptions ({$mode}): Programming bungle!";
print_a($targetData);
return 'Error';
}
$text = "\n";
return $text;
}
/**
* Generate the HTML for displaying email selection fields
*
* @param $options - comma-separate string of handlers to load
* 'core' - core handler
* plugin name - obvious!
* 'all' - obvious!
* @return Number of handlers loaded
*/
public function loadMailHandlers($options = 'all')
{
$pref = e107::getPref();
$pref['mailout_enabled'] = str_replace('core','user',$pref['mailout_enabled']); // BC fix.
$ret = 0;
$toLoad = explode(',', $options);
$active_mailers = explode(',', varset($pref['mailout_enabled'], 'user'));
if((in_array('core', $toLoad) || ($options == 'all')) && in_array('core', $active_mailers))
{
// require_once (e_HANDLER . 'mailout_class.php');
// $this->mailHandlers['core'] = new core_mailout; // Start by loading the core mailout class
// $ret++;
}
if(empty($pref['e_mailout_list']))
{
return $ret;
}
// Load additional configured handlers e_mailout.php from plugins.
foreach($pref['e_mailout_list'] as $mailer => $v)
{
if(isset($pref['plug_installed'][$mailer]) && in_array($mailer, $active_mailers) && (($options == 'all') || in_array($mailer, $toLoad)))
{
// Could potentially use this handler - its installed and enabled
if(!is_readable(e_PLUGIN . $mailer . '/e_mailout.php'))
{
echo 'Invalid mailer selected: ' . $mailer . ' ';
exit ;
}
require_once (e_PLUGIN . $mailer . '/e_mailout.php');
if(varset($mailerIncludeWithDefault, TRUE))
{
// Definitely need this plugin
$mailClass = $mailer . '_mailout';
$temp = new $mailClass;
// $temp = e107::getSingleton($mailClass);
if($temp->mailerEnabled)
{
$this->mailHandlers[$mailer] = $temp;
$ret++;
if(varset($mailerExcludeDefault, FALSE) && isset($this->mailHandlers['core']))
{
$this->mailHandlers['core']->mailerEnabled = FALSE;
// Don't need default (core) handler
$ret--;
}
}
else
{
unset($temp);
}
}
}
}
return $ret;
}
/**
* Generate the HTML for displaying email selection fields
*
* @param $options - comma-separated string of areas to display:
* 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 text for display
*/
public function emailSelector($options = 'all', $selectorInfo = FALSE)
{
$tabs = array();
foreach($this->mailHandlers as $key => $m)
{
if($m->mailerEnabled)
{
$content = $m->showSelect(TRUE, varset($selectorInfo[$key], FALSE));
if(is_array($content))
{
$text = "
";
foreach($content as $var)
{
$text .= "
" . $var['caption'] . "
" . $var['html'] . "
";
}
$text .= "
";
}
else
{
$text = $content; //BC (0.8 only) but should be deprecated
}
$tabs[$key] = array('caption'=>$m->mailerName, 'text'=>$text);
}
}
if(count($tabs) < 2) // no tabs if there's only 1 category.
{
return $text;
}
return e107::getForm()->tabs($tabs);
}
/**
* Get the selector details from each mail plugin (to add to mail data)
*
* @return array of selectors - key is the plugin name, value is the selector
* data (often itself an array)
*/
public function getAllSelectors()
{
$ret = array();
foreach($this->mailHandlers as $key => $m)
{
if($m->mailerEnabled)
{
$ret[$key] = $m->returnSelectors();
}
}
return $ret;
}
/**
* Creates a 'select' dropdown of userclasses, including the number of members in
* each class.
*
* @param string $name - name for