/
subscribers.php
400 lines (344 loc) · 11.7 KB
/
subscribers.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/**
* This file has the base subscriber functions in it. Each subprocess is handled separately.
*
* @version $Id: subscribers.php,v 1.37 2007/12/28 03:56:01 hendri Exp $
* @author Chris <chris@interspire.com>
*
* @package SendStudio
* @subpackage SendStudio_Functions
*/
/**
* Include the base sendstudio functions.
*/
require_once(dirname(__FILE__) . '/sendstudio_functions.php');
/**
* Base class for subscribers processing. This simply hands the processing to subareas (eg adding, banning, exporting and so on).
*
* @package SendStudio
* @subpackage SendStudio_Functions
*/
class Subscribers extends SendStudio_Functions
{
/**
* PopupWindows
* A list of popup windows for subscribers. This is overridden from the main sendstudio_functions file.
*
* @var Array
*/
var $PopupWindows = array('import', 'importiframe', 'export', 'exportiframe', 'view_report', 'viewtutorial');
/**
* SuppressHeader
* A list of action that need to have the header string suppressed
*
* @var Array
*/
var $SuppressHeader = array('import', 'export','eventadd','eventlist','eventsave','eventupdate','eventdelete','eventtable');
/**
* Constructor
* Loads the language file.
*
* @return Void Doesn't return anything
*/
function Subscribers()
{
$this->LoadLanguageFile('Subscribers');
}
/**
* Process
* This does base processing only. Prints the headers, handles paging, then passes off the functionality to the appropriate subarea.
*
* @see Subscribers_Add
* @see Subscribers_Banned
* @see Subscribers_Edit
* @see Subscribers_Export
* @see Subscribers_Import
* @see Subscribers_Manage
* @see Subscribers_Remove
*/
function Process()
{
$GLOBALS['Message'] = '';
$action = (isset($_GET['Action'])) ? strtolower($_GET['Action']) : null;
$user = GetUser();
$permission_action = $action;
if ($action == 'remove') {
$permission_action = 'delete';
}
if ($action == 'view') {
$permission_action = 'manage';
}
$subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : null;
if ($action == 'event') {
$permission_action = $subaction;
if ($permission_action == 'eventlist' || $permission_action == 'eventtable') {
$permission_action = 'manage';
}
}
$access = $user->HasAccess('Subscribers', $permission_action);
$popup = (in_array($subaction, $this->PopupWindows)) ? true : false;
$this->PrintHeader($popup, true, (!in_array($subaction, $this->SuppressHeader)));
if (!$access) {
$this->DenyAccess();
return;
}
switch ($action) {
case 'add':
require_once(dirname(__FILE__) . '/subscribers_add.php');
$AddSubscribers = new Subscribers_Add();
$AddSubscribers->Process($subaction);
break;
case 'remove':
require_once(dirname(__FILE__) . '/subscribers_remove.php');
$RemoveSubscribers = new Subscribers_Remove();
$RemoveSubscribers->Process($subaction);
break;
case 'edit':
require_once(dirname(__FILE__) . '/subscribers_edit.php');
$EditSubscriber = new Subscribers_Edit();
$EditSubscriber->Process($subaction);
break;
case 'view':
require_once(dirname(__FILE__) . '/subscribers_view.php');
$EditSubscriber = new Subscribers_View();
$EditSubscriber->Process();
break;
case 'import':
require_once(dirname(__FILE__) . '/subscribers_import.php');
$ImportSubscribers = new Subscribers_Import();
$ImportSubscribers->Process($subaction);
break;
case 'export':
require_once(dirname(__FILE__) . '/subscribers_export.php');
$ExportSubscribers = new Subscribers_Export();
$ExportSubscribers->Process($subaction);
break;
case 'banned':
require_once(dirname(__FILE__) . '/subscribers_banned.php');
$ExportSubscribers = new Subscribers_Banned();
$ExportSubscribers->Process($subaction);
break;
case 'search':
require_once(dirname(__FILE__) . '/subscribers_search.php');
$SearchSubscribers = new Subscribers_Search();
$SearchSubscribers->Process($subaction);
break;
case 'event':
require_once(dirname(__FILE__) . '/subscribers_event.php');
$EventSubscribers = new Subscribers_Event();
$EventSubscribers->Process($subaction);
break;
case 'delete':
case 'manage':
default:
require_once(dirname(__FILE__) . '/subscribers_manage.php');
$ManageSubscribers = new Subscribers_Manage();
$ManageSubscribers->Process($subaction);
break;
}
$this->PrintFooter($popup);
}
/**
* ChooseList
* This prints out the select box which makes you choose a list (to start any subscriber process).
* If there is only one list, it will automatically redirect you to that particular list (depending on which area you're looking for).
* Otherwise, it prints out the appropriate template for the area you're working with.
*
* @param String $action The area you're working with. This can be manage, export, import, banned and so on.
* @param String $subaction Which step you're up to in the process.
*
* @see User_API::GetLists
* @see User_API::CanCreateList
*
* @return Void Prints out the appropriate template, doesn't return anything.
*/
function ChooseList($action='Manage', $subaction=null)
{
$action = strtolower($action);
$user = GetUser();
$lists = $user->GetLists();
$listids = array_keys($lists);
if (sizeof($listids) < 1) {
switch ($action) {
case 'banned':
if ($subaction == 'add') {
$extra_message = GetLang('Banned_Add_NoList_Message');
} else {
$extra_message = GetLang('Banned_Manage_NoList_Message');
}
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
break;
case 'import':
$extra_message = GetLang('Import_Add_NoList_Message');
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
break;
case 'export':
$extra_message = GetLang('Export_Add_NoList_Message');
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
break;
case 'remove':
$extra_message = GetLang('Remove_NoList_Message');
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
break;
case 'add':
$extra_message = GetLang('Add_NoList_Message');
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
break;
default:
$extra_message = GetLang('View_NoList_Message');
$GLOBALS['Intro_Help'] = GetLang('Help_SubscribersManage');
}
$GLOBALS['Intro'] = GetLang('Subscribers_' . ucwords($action));
$GLOBALS['Lists_AddButton'] = '';
if ($user->CanCreateList() === true) {
$GLOBALS['Message'] = $this->PrintSuccess('Subscriber_NoLists', $extra_message, GetLang('ListCreate'));
$GLOBALS['Lists_AddButton'] = $this->ParseTemplate('List_Create_Button', true, false);
} else {
$GLOBALS['Message'] = $this->PrintSuccess('Subscriber_NoLists', $extra_message, GetLang('ListAssign'));
}
$this->ParseTemplate('Subscribers_No_Lists');
return;
}
if ($listname = IEM::sessionGet('AddSubscriberMessage')) {
$GLOBALS['Message'] = $this->PrintSuccess('SubscriberAddSuccessfulList', htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET));
IEM::sessionRemove('AddSubscriberMessage');
}
if ($emptybannedmsg = IEM::sessionGet('EmptyBannedSubscriberMessage')) {
$GLOBALS['Message'] = $this->PrintSuccess('SubscriberBanListEmpty', htmlspecialchars($emptybannedmsg, ENT_QUOTES, SENDSTUDIO_CHARSET));
IEM::sessionRemove('EmptyBannedSubscriberMessage');
}
if ($bannedmsg = IEM::sessionGet('DeleteBannedSubscriberMessage')) {
$GLOBALS['Message'] = $bannedmsg;
IEM::sessionRemove('DeleteBannedSubscriberMessage');
}
$sortedlist = array();
if ($action == 'banned') {
$banned_list = $user->GetBannedLists($listids);
$banned_listids = array_keys($banned_list);
if ($user->HasAccess('Lists', 'Global')) {
$sortedlist['global'] = array('name' => GetLang('Subscribers_GlobalBan'));
}
$sortedlist += $lists;
foreach ($sortedlist as $name => $details) {
$check_name = $name;
if ($name == 'global') {
$check_name = 'g';
}
$sortedlist[$name]['bancount'] = 0;
if (in_array($check_name, $banned_listids)) {
$sortedlist[$name]['bancount'] = $banned_list[$check_name];
}
}
}
if ($action != 'banned') {
if ($action == 'manage' || $action == 'export') {
$sortedlist = array('any' => array('name' => GetLang('AnyList')));
}
$sortedlist += $lists;
}
$selectlist = '';
foreach ($sortedlist as $listid => $listdetails) {
$subscriber_count = '';
if (isset($listdetails['bancount'])) {
if ($listdetails['bancount'] == 1) {
$subscriber_count = GetLang('Ban_Count_One');
} else {
$subscriber_count = sprintf(GetLang('Ban_Count_Many'), $this->FormatNumber($listdetails['bancount']));
}
} else {
if (isset($listdetails['subscribecount'])) {
if ($listdetails['subscribecount'] == 1) {
$subscriber_count = GetLang('Subscriber_Count_One');
} else {
$subscriber_count = sprintf(GetLang('Subscriber_Count_Many'), $this->FormatNumber($listdetails['subscribecount']));
}
}
}
if ($listid == 'any') {
$sel = 'selected';
} else {
$sel = '';
}
$selectlist .= '<option ' . $sel . ' value="' . $listid . '">' . htmlspecialchars($listdetails['name'], ENT_QUOTES, SENDSTUDIO_CHARSET) . $subscriber_count . '</option>';
}
$GLOBALS['SelectList'] = $selectlist;
$tempCount = count($sortedlist);
if ($tempCount <= 10) {
if ($tempCount < 3) {
$tempCount = 3;
}
$GLOBALS['SelectListStyle'] = 'height: ' . ($tempCount * 25) . 'px;';
}
$GLOBALS['DisplaySegmentOption'] = 'none';
if (in_array($action, array('manage', 'send')) && $user->HasAccess('Segments', 'View')) {
$selectSegment = '';
$segments = $user->GetSegmentList();
$segmentAPI = $this->GetApi('Segment');
foreach ($segments as $segmentid => $segmentdetails) {
$tempCount = $segmentAPI->GetSubscribersCount($segmentdetails['segmentid']);
if ($tempCount == 1) {
$tempCount = GetLang('Subscriber_Count_One');
} else {
$tempCount = sprintf(GetLang('Subscriber_Count_Many'), $this->FormatNumber($tempCount));
}
$selectSegment .= '<option value="' . $segmentid . '">'
. htmlspecialchars($segmentdetails['segmentname'], ENT_QUOTES, SENDSTUDIO_CHARSET)
. $tempCount
. '</option>';
}
$GLOBALS['SelectSegment'] = $selectSegment;
$GLOBALS['DisplaySegmentOption'] = '';
}
switch ($action) {
case 'search':
$this->ParseTemplate('Subscriber_Search_Step1');
break;
case 'manage':
$this->ParseTemplate('Subscriber_Manage_Step1');
break;
case 'add':
$this->ParseTemplate('Subscribers_Add_Step1');
break;
case 'remove':
$this->ParseTemplate('Subscribers_Remove_Step1');
break;
case 'import':
$this->ParseTemplate('Subscribers_Import_Step1');
break;
case 'export':
$this->ParseTemplate('Subscribers_Export_Step1');
break;
case 'banned':
$this->ParseTemplate('Subscribers_Banned_Step1');
break;
}
}
/**
* SetupGoogleCalendar
* Sets the variables used for Google Calendar integration
*
* @see Subscribers_View::ViewSubscriber
* @see Subscribers_Edit::EditSubscriber
* @see Subscribers_Manage::ManageSubscribers_Step3
*
* @return Void Returns nothing
*/
function SetupGoogleCalendar()
{
$user = GetUser();
$eventGoogleUse = IEM::sessionGet('eventGoogleUse');
if (strlen($user->googlecalendarusername) && strlen($user->googlecalendarpassword)) {
$GLOBALS['GoogleCalendarLink'] = SENDSTUDIO_APPLICATION_URL . "/admin/index.php?" . $_SERVER['QUERY_STRING'];
$GLOBALS['GoogleCalendarIntroText'] = GetLang('GoogleCalendarIntro');
$GLOBALS['eventGoogleDisplay'] = '';
if ($eventGoogleUse !== 'no') {
$GLOBALS['eventGoogleUse'] = 'true';
} else {
$GLOBALS['eventGoogleUse'] = 'false';
}
} else {
$GLOBALS['eventGoogleUse'] = 'false';
$GLOBALS['eventGoogleDisplay'] = 'display: none;';
}
}
}