forked from e107inc/e107
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailout_admin_class.php
2322 lines (2029 loc) · 63 KB
/
mailout_admin_class.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2017 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Mailout - admin-related functions
*
*/
/**
* Various admin-related mailout functions, mostly to do with creating and
* handling forms.
*
* @package e107
* @subpackage e107_handlers
*/
/*
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
*/
if (!defined('e107_INIT'))
{
exit;
}
define('MAIL_ADMIN_DEBUG', true);
require_once(e_HANDLER . 'mail_manager_class.php');
/**
*
*/
class mailoutAdminClass extends e107MailManager
{
public $_cal = array();
protected $mode;
// So we know what the current task is
protected $mailHandlers = array();
protected $showFrom = 0;
protected $showCount = 10;
protected $sortField = 'mail_source_id';
protected $sortOrder = 'asc';
protected $fieldPref = array();
protected $userCache = array();
// Definitions associated with each column which might be displayed. (Compatible
// with forms-based display)
// Fields are displayed in the order listed.
// Can also have: width
// type
// thclass
protected $fields = array(
'mail_recipients' => 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_SOURCE),
'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 void
*/
public function newMode($mode = '')
{
global $user_pref;
$this->mode = $mode;
$curTable = varset($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 = varset($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|false of field definitions
*/
protected function calcFieldSpec($mode, $noOptions = false)
{
if (!isset($this->tasks[$mode]))
{
echo "CalcfieldSpec({$mode}) - programming bungle<br />";
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}<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];
}
}
*/
/**
* 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 = "<select name='mailaction[{$mailData['mail_source_id']}]' onchange='this.form.submit()' class='tbox form-control' style='width:90%'>\n
<option selected='selected' value=''> </option>\n";
foreach ($this->modeOptions[$mode] as $key => $val)
{
$text .= "<option value='{$key}'>{$val}</option>\n";
}
$text .= "</select>\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 string $mode
* @param $targetData - array of email-related info
* @return string 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 = "<select name='targetaction[{$targetData['mail_target_id']}]' onchange='this.form.submit()' class='tbox form-control' style='width:90%'>\n
<option selected='selected' value=''> </option>\n";
foreach ($this->modeOptions[$mode] as $key => $val)
{
$text .= "<option value='{$key}'>{$val}</option>\n";
}
$text .= "</select>\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', varset($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 . '<br />';
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 string html for display
*/
public function emailSelector($options = 'all', $selectorInfo = false)
{
$tabs = array();
// Check for selected email address sources
if (!$this->mailHandlers)
{
$text = "<span class='label label-warning'>" . LAN_MAILOUT_259 . "</span>";
}
foreach ($this->mailHandlers as $key => $m)
{
if ($m->mailerEnabled)
{
$content = $m->showSelect(true, varset($selectorInfo[$key], false));
if (is_array($content))
{
$text = "<table class='table table-bordered table-striped ' style='margin-bottom:0;margin-left:0; margin-top:10px'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
foreach ($content as $var)
{
$text .= "
<tr>
<td>" . $var['caption'] . "</td>
<td class='form-inline'>" . $var['html'] . "</td>
</tr>";
}
$text .= "</table>";
}
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 <select>
* @param string $curSel - current select value
* @return string for display
*
* @TODO: Doesn't give correct count for core classes where no data initialised
*/
public function userClassesTotals($name, $curSel)
{
$fixedClasses = array(
'self' => LAN_MAILOUT_54,
'all' => LAN_MAILOUT_12,
'unverified' => LAN_MAILOUT_13,
'admin' => LAN_MAILOUT_53
);
$ret = '';
$this->checkDB(2);
// Make sure DB object created
$ret .= "<select class='tbox form-control' name='{$name}' >
<option value=''> </option>\n";
foreach ($fixedClasses as $k => $v)
{
$sel = ($k == $curSel) ? " selected='selected'" : '';
$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,'(,|$)')
WHERE NOT uc.userclass_id IN (" . e_UC_PUBLIC . ',' . e_UC_NOBODY . ',' . e_UC_READONLY . ',' . e_UC_BOTS . ")
GROUP BY uc.userclass_id
";
$this->db2->gen($query);
while ($row = $this->db2->fetch())
{
$public = ($row['userclass_editclass'] == e_UC_PUBLIC) ? "(" . LAN_MAILOUT_10 . ")" : "";
$selected = ($row['userclass_id'] == $curSel) ? " selected='selected'" : '';
$ret .= "<option value='{$row['userclass_id']}'{$selected} >" . LAN_MAILOUT_55 . " - {$row['userclass_name']} {$public} [{$row['members']}]</option>\n";
}
$ret .= " </select>\n";
return $ret;
}
/**
* Creates a 'select' dropdown of non-system user fields
*
* @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
* @return false|string for display if any extended fields defined; FALSE if none
* available
*/
public function ret_extended_field_list($list_name, $curval = '', $add_blank = false)
{
$ue = e107::getUserExt();
// Get the extended field handler
if (count($ue->fieldDefinitions) == 0)
{
return false;
}
$ret = "<select name='{$list_name}' class='tbox form-control'>\n";
if ($add_blank)
{
$ret .= "<option value=''> </option>\n";
}
foreach ($ue->fieldDefinitions as $fd)
{
if ($fd['user_extended_struct_text'] != '_system_')
{
$value = 'ue.user_' . $fd['user_extended_struct_name'];
$selected = ($value == $curval) ? " selected='selected'" : '';
$ret .= "<option value='" . $value . "' {$selected}>" . ucfirst($fd['user_extended_struct_name']) . "</option>\n";
}
}
$ret .= "</select>\n";
return $ret;
}
/**
* Creates an array of data from standard $_POST fields
*
* @param $newMail - set TRUE for initial creation, FALSE when updating
* @return array of data
*/
public function parseEmailPost($newMail = true)
{
$tp = e107::getParser();
$ret = array(
'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)
);
$ret = $tp->toDB($ret);
// recursive
if (isset($_POST['mail_source_id']))
{
$ret['mail_source_id'] = intval($_POST['mail_source_id']);
}
if ($newMail)
{
$ret['mail_creator'] = USERID;
$ret['mail_create_date'] = time();
}
return $ret;
}
/**
* Does some basic checking on email data.
*
* @param $email - array of data in parseEmailPost() format
* @param $fullCheck - TRUE to check all fields that are required (immediately
* prior to sending); FALSE to just check a few basics (prior to save)
* @return TRUE if OK. Array of error messages if any errors found
*/
public function checkEmailPost(&$email, $fullCheck = false)
{
$errList = array();
if (count($email) < 3)
{
$errList[] = LAN_MAILOUT_201;
return $errList;
}
if (!trim($email['mail_subject']))
{
$errList[] = LAN_MAILOUT_200;
}
if (!trim($email['mail_body']))
{
$errList[] = LAN_MAILOUT_202;
}
if (!trim($email['mail_sender_name']))
{
$errList[] = LAN_MAILOUT_203;
}
if (!trim($email['mail_sender_email']))
{
$errList[] = LAN_MAILOUT_204;
}
if (strlen($email['mail_send_style']) == 0)
{
// Can be a template name now
$errList[] = LAN_MAILOUT_205;
// break;
}
else
{
// Get template data, override email settings as appropriate
require_once(e_HANDLER . 'mail_template_class.php');
$ourTemplate = new e107MailTemplate();
$templateName = $email['mail_send_style'];
if (!$ourTemplate->setNewTemplate($templateName))
{
$errList[] = LAN_MAILOUT_207 . ':' . $templateName;
print_a($ourTemplate);
// Probably template not found if error
}
if (!$ourTemplate->makeEmailBody($email['mail_body'], $email['mail_include_images']))
{
$errList[] = LAN_MAILOUT_205 . ':' . $templateName;
print_a($ourTemplate);
}
else
{
$email['mail_body_templated'] = $ourTemplate->mainBodyText;
$email['mail_body_alt'] = $ourTemplate->altBodyText;
if (count($ourTemplate->lastTemplateData['email_overrides']))
{
$email['mail_overrides'] = $ourTemplate->lastTemplateData['email_overrides'];
}
}
}
if (count($errList) == 0)
{
return true;
}
return $errList;
}
/**
* Generate a table which shows some information about an email.
* Intended to be part of a 2-column table - includes the row detail, but not the
* surrounding table definitions
*
* @param $mailSource - array of mail information
* @param $options - controls how much information is displayed
* @return string for display
*/
public function showMailDetail(&$mailSource, $options = 'basic')
{
$tp = e107::getParser();
if (!isset($this->mailDetailDisplay[$options]))
{
return "<tr><td colspan='2'>Programming bungle - invalid option value: {$options}</td></tr>";
}
$text = '';
foreach ($this->mailDetailDisplay[$options] as $k => $v)
{
$text .= '<tr><td>' . $this->fields['mail_content'][$k]['title'] . '</td><td>';
$val = $mailSource[$k];
if ($k == 'mail_body')
{
// $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>";
continue;
}
if (is_numeric($v))
{
$text .= ($v > 1) ? $tp->text_truncate($val, $v, '...') : $val;
}
else
{
switch ($v)
{
case 'username':
$text .= $this->getUserName($val);
break;
case 'sdatetime':
$text .= $tp->toDate($val, 'short');
break;
case 'trunc200':
$text .= e107::getParser()->text_truncate($val, 200, '...');
break;
case 'chars':
// Show generated html as is
$text .= htmlspecialchars($val, ENT_COMPAT, 'UTF-8');
break;
case 'contentstatus':
$text .= $this->statusToText($val);
break;
case 'selectors':
$text .= 'cannot display';
break;
case 'yesno':
$text .= $val ? LAN_YES : LAN_NO;
break;
case 'default':
default:
$text .= $val;
}
}
$text .= '</td></tr>' . "\n";
}
return $text;
}