-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathe_mailout.php
210 lines (177 loc) · 6.69 KB
/
e_mailout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Event calendar - mailout function
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/e_mailout.php,v $
* $Revision$
* $Date$
* $Author$
*
*/
/**
* e107 Event calendar plugin
*
* Event calendar - mailout function
*
* @package e107_plugins
* @subpackage event_calendar
* @version $Id$;
*/
if (!defined('e107_INIT')) { exit(); }
include_lan(e_PLUGIN.'/calendar_menu/languages/'.e_LANGUAGE.'_mailer.php');
/*
Class for event calendar mailout function
Allows admins to send mail to those subscribed to calendar events
*/
// These variables determine the circumstances under which this class is loaded (only used during loading, and may be overwritten later)
$mailerIncludeWithDefault = TRUE; // Mandatory - if false, show only when mailout for this specific plugin is enabled
$mailerExcludeDefault = FALSE; // Mandatory - if TRUE, when this plugin's mailout is active, the default (core) isn't loaded
class calendar_menu_mailout
{
protected $mailCount = 0;
protected $mailRead = 0;
//public $mailerSource = 'calendar_menu'; //FIXME should be auto-detected // Plugin name (core mailer is special case) Must be directory for this file
public $mailerName = LAN_EC_MAIL_01; // Text to identify the source of selector (displayed on left of admin page)
public $mailerEnabled = TRUE; // Mandatory - set to FALSE to disable this plugin (e.g. due to permissions restrictions)
private $selectorActive = FALSE; // Set TRUE if we've got a valid selector to start returning entries
// Constructor
public function __construct()
{
}
/**
* Return data representing the user's selection criteria as entered in the $_POST array.
*
* This is stored in the DB with a saved email. (Just return an empty string or array if this is undesirable)
* The returned value is passed back to selectInit() and showSelect when needed.
*
* @return string Selection data - comma-separated list of category IDs
*/
public function returnSelectors()
{
$res = array();
if (is_array($_POST['ec_category_sel']))
{
foreach ($_POST['ec_category_sel'] as $k => $v)
{
$res[] = intval($v);
}
}
return implode(',',$res);
}
/**
* Called to initialise data selection routine.
* Needs to save any queries or other information into internal variables, do initial DB queries as appropriate.
* Could in principle read all addresses and buffer them for later routines, if this is more convenient
*
* @param string $selectVals - array of selection criteria as returned by returnSelectors()
*
* @return integer Return number of records available (or 1 if unknown) on success, FALSE on failure
*/
public function selectInit($selectVals = FALSE)
{
$sql = e107::getDb();
if (($selectVals === FALSE) || ($selectVals == ''))
{
return 0; // No valid selector - so no valid records
}
$where = array();
$qry = 'SELECT u.user_id, u.user_name, u.user_email, u.user_loginname, u.user_sess, u.user_lastvisit FROM `#event_subs` AS es';
$qry .= ' LEFT JOIN `#user` AS u ON es.`event_subid` = u.`user_id` WHERE es.`event_cat` IN (\''.$selectVals.'\') AND u.`user_id` IS NOT NULL';
$qry .= ' GROUP BY u.`user_id`';
// echo "Selector query: ".$qry.'<br />';
if (!( $this->mail_count = $sql->db_Select_gen($qry))) return FALSE;
$this->selectorActive = TRUE;
$this->mail_read = 0;
return $this->mail_count;
}
/**
* Return an email address to add to the recipients list. Return FALSE if no more addresses to add
*
* @return array|boolean FALSE if no more addresses available; else an array:
* 'mail_recipient_id' - non-zero if a registered user, zero if a non-registered user. (Always non-zero from this class)
* 'mail_recipient_name' - user name
* 'mail_recipient_email' - email address to use
* 'mail_target_info' - array of info which might be substituted into email, usually using the codes defined by the editor.
* Array key is the code within '|...|', value is the string for substitution
*/
public function selectAdd()
{
$sql = e107::getDb();
if (!$this->selectorActive) return FALSE;
if (!($row = $sql->db_Fetch(MYSQL_ASSOC))) return FALSE;
$ret = array('mail_recipient_id' => $row['user_id'],
'mail_recipient_name' => $row['user_name'], // Should this use realname?
'mail_recipient_email' => $row['user_email'],
'mail_target_info' => array(
'USERID' => $row['user_id'],
'DISPLAYNAME' => $row['user_name'],
'SIGNUP_LINK' => $row['user_sess'],
'USERNAME' => $row['user_loginname'],
'USERLASTVISIT' => $row['user_lastvisit']
)
);
$this->mail_read++;
return $ret;
}
/**
* Called once all email addresses read, to do any housekeeping needed
*
* @return none
*/
public function select_close()
{
// Nothing to do here
}
/**
* Called to show current selection criteria, and optionally allow edit
*
* @param boolean $allow_edit is TRUE to allow user to change the selection; FALSE to just display current settings
* @param string $selectVals is the current selection information - in the same format as returned by returnSelectors()
*
* @return array Returns array which is displayed in a table cell.
*/
public function showSelect($allow_edit = FALSE, $selectVals = FALSE)
{
$sql = e107::getDb();
$frm = e107::getForm();
$var = array();
// $ret = "<table style='width:95%'>";
$selects = array_flip(explode(',', $selectVals));
if ($sql->db_Select('event_cat', 'event_cat_id, event_cat_name', "event_cat_name != 'Default'"))
{
$c=0;
while ($row = $sql->db_Fetch(MYSQL_ASSOC))
{
$checked = (isset($selects[$row['event_cat_id']])) ? " checked='checked'" : '';
if ($allow_edit)
{
$var[$c]['caption'] = $row['event_cat_name'];
$var[$c]['html'] = $frm->checkbox('ec_category_sel[]',$row['event_cat_id'],$checked);
/*$ret .= "<tr><td><input type='checkbox' name='ec_category_sel[]' value='{$row['event_cat_id']}' {$checked}/></td><td>
".$row['event_cat_name']."</td></tr>";*/
}
elseif($checked)
{
$var[$c]['html'] = $row['event_cat_name'];
$var[$c]['caption'] = LAN_EC_MAIL_03;
/*$ret .= "<tr><td>".LAN_EC_MAIL_03."</td><td>
".$row['event_cat_name']."</td></tr>";*/
}
$c++;
}
}
else
{
$var[0]['caption'] = LAN_EC_MAIL_02;
$var[0]['html'] = '';
}
return $var;
}
}
?>