/
stats.php
5425 lines (4251 loc) · 190 KB
/
stats.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
/**
* This file has the base subscriber functions in it. Each subprocess is handled separately.
*
* @version $Id: stats.php,v 1.98 2008/03/03 03:17:04 chris 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 Stats extends SendStudio_Functions
{
/**
* Default sort.
*
* @var _DefaultSort
*/
var $_DefaultSort = 'finishtime';
/**
* Default direction for sorting.
*
* @var _DefaultDirection
*/
var $_DefaultDirection = 'down';
/**
* @var CalendarRestrictions Store the calendar restrictions in the class - easy reference.
*
* @see CalculateCalendarRestrictions
*/
var $CalendarRestrictions = array (
'opens' => '',
'clicks' => '',
'forwards' => '',
'bounces' => '',
'unsubscribes' => '',
'subscribers' => array('subscribes' => '', 'unsubscribes' => '', 'bounces' => ''),
'recipients' => ''
);
/**
* Constructor
* Loads the language file.
*
* @return Void Doesn't return anything.
*/
function Stats()
{
$this->LoadLanguageFile();
}
/**
* Process
* Standard process function. Works out what you're trying to do and passes action off to other functions.
*
* @return Void Doesn't return anything. Hands control off to other functions.
*/
function Process()
{
$action = (isset($_GET['Action'])) ? strtolower($_GET['Action']) : null;
$user = IEM::userGetCurrent();
$access = $user->HasAccess('Statistics');
$subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : null;
$popup = ($action == 'print') ? true : false;
$GLOBALS['Loading_Indicator'] = $this->ParseTemplate('Loading_Indicator', true);
$this->PrintHeader($popup);
// Print the loading indicator for the charts
$GLOBALS['TableType'] = 'chart';
$this->ParseTemplate('Loading_Indicator', false);
if (!$access) {
$this->DenyAccess();
}
foreach (array('lc', 'uc', 'oc', 'bc', 'fc', 'rc', '') as $k => $area) {
if ($action == 'processpaging' . $area) {
$page = null;
if ($area) {
$page = 'stats_processpaging' . $area;
}
if (isset($_GET['PerPageDisplay' . $area])) {
$this->SetPerPage($_GET['PerPageDisplay' . $area], $page);
}
$action = $subaction;
if (isset($_GET['NextAction'])) {
$subaction = strtolower($_GET['NextAction']);
}
break;
}
}
if ($action == 'processcalendar') {
if (isset($_POST['Calendar'])) {
$calendar_settings = $_POST['Calendar'];
$user->SetSettings('Calendar', $calendar_settings);
$this->CalculateCalendarRestrictions($calendar_settings);
$user->SetSettings('CalendarDates', $this->CalendarRestrictions);
$user->SaveSettings();
}
$action = $subaction;
if (isset($_GET['NextAction'])) {
$subaction = strtolower($_GET['NextAction']);
}
}
$this->CalculateCalendarRestrictions();
switch ($action) {
case 'list':
if (!$user->HasAccess('statistics', 'list')) {
$this->DenyAccess();
}
switch ($subaction) {
case 'step2':
case 'viewsummary':
$listid = 0;
if (isset($_GET['list'])) {
$listid = (int)$_GET['list'];
}
$this->PrintListStats_Step2($listid);
break;
default:
// if they have changed paging, we'll have a 'default' action but the userid will still be in the url.
if (isset($_GET['list'])) {
$this->PrintListStats_Step2($_GET['list']);
break;
}
IEM::sessionRemove('ListStatistics');
$this->PrintListStats_Step1();
}
break;
case 'triggeremails':
$this->TriggerEmailsStats($subaction);
break;
case 'user':
if (!$user->HasAccess('statistics', 'user')) {
$this->DenyAccess();
}
IEM::sessionRemove('ListStatistics');
switch ($subaction) {
case 'step2':
$userid = 0;
if (isset($_GET['user'])) {
$userid = (int)$_GET['user'];
}
$this->PrintUserStats_Step2($userid);
break;
default:
// if they have changed paging, we'll have a 'default' action but the userid will still be in the url.
if (isset($_GET['user'])) {
$this->PrintUserStats_Step2($_GET['user']);
break;
}
$this->PrintUserStats_Step1();
}
break;
case 'autoresponders':
if (!$user->HasAccess('statistics', 'autoresponder')) {
$this->DenyAccess();
}
IEM::sessionRemove('ListStatistics');
$this->LoadLanguageFile('Autoresponders');
switch ($subaction) {
case 'doselect':
switch (strtolower($_REQUEST['SelectAction'])) {
case 'delete':
$stats_api = $this->GetApi('Stats');
$stats_to_delete = array();
if (isset($_POST['stats']) && !empty($_POST['stats'])) {
foreach ($_POST['stats'] as $statid) {
$autoresponderid = $statid;
$summary = $stats_api->GetAutoresponderSummary($autoresponderid, true, 0);
$stats_to_delete[] = $summary['statid'];
}
}
if (isset($_GET['id'])) {
$stats_to_delete[] = (int)$_GET['id'];
}
if (empty($stats_to_delete)) {
$this->PrintAutoresponderStats_Step1();
break;
}
$success = 0;
$failure = 0;
$cant_delete = 0;
foreach ($stats_to_delete as $p => $statid) {
// bail if they're trying to delete things they're not allowed to
if (!$this->CanAccessStats($statid, 'a')) {
$this->DenyAccess();
}
if (!$statid) {
$cant_delete++;
continue;
}
$delete = $stats_api->HideStats($statid, 'autoresponder', $user->Get('userid'));
if ($delete) {
$success++;
} else {
$failure++;
}
}
$msg = '';
if ($failure > 0) {
if ($failure == 1) {
$GLOBALS['Error'] = GetLang('StatisticsDeleteFail_One');
} else {
$GLOBALS['Error'] = sprintf(GetLang('StatisticsDeleteFail_One'), $this->FormatNumber($failure));
}
$msg .= $this->ParseTemplate('ErrorMsg', true, false);
}
if ($success > 0) {
if ($success == 1) {
$msg .= $this->PrintSuccess('StatisticsDeleteSuccess_One');
} else {
$msg .= $this->PrintSuccess('StatisticsDeleteSuccess_Many', $this->FormatNumber($success));
}
}
if ($cant_delete > 0) {
if ($cant_delete == 1) {
$msg .= $this->PrintSuccess('StatisticsDeleteNoStatistics_One');
} else {
$msg .= $this->PrintSuccess('StatisticsDeleteNoStatistics_Many', $this->FormatNumber($cant_delete));
}
}
$GLOBALS['Message'] = $msg;
$this->PrintAutoresponderStats_Step1($msg);
break; // delete
}
break; // doselect
case 'step2':
case 'viewsummary':
$autoid = 0;
if (isset($_GET['auto'])) {
$autoid = (int)$_GET['auto'];
}
if (!$this->CanAccessAutoresponder($autoid)) {
$this->DenyAccess();
}
$this->PrintAutoresponderStats_Step2($autoid);
break;
default:
$this->PrintAutoresponderStats_Step1();
} // switch ($subaction)
break;
default:
if (!$user->HasAccess('statistics', 'newsletter')) {
$this->DenyAccess();
}
IEM::sessionRemove('ListStatistics');
switch (strtolower($subaction)) {
case 'doselect':
$selectAction = IEM::ifsetor($_REQUEST['SelectAction'], 'strtolower');
switch (strtolower($selectAction)) {
case 'export':
$newsletterapi = $this->GetApi('Newsletters');
$statsapi = $this->GetApi('Stats');
$name = '';
if (count($_REQUEST['stats']) == 1) {
// When exporting for just one campaign, use the campaign name in the file name
$f = $statsapi->FetchStats($_REQUEST['stats'][0],'newsletter');
$newsletterapi->Load($f['newsletterid']);
if (!$this->IsOwner($newsletterapi->ownerid)) {
$this->DenyAccess();
}
$name = preg_replace('/[^a-z0-9]/i','_',$newsletterapi->name) . "_";
}
$name .= "stats_" . $this->PrintDate(time(),'dmy');
while (is_file(TEMP_DIRECTORY . "/{$name}.csv")) {
$name .= "_" . rand(10,99);
}
$name .= ".csv";
$local = TEMP_DIRECTORY . "/$name";
$http = SENDSTUDIO_TEMP_URL . "/$name";
if (is_writable(TEMP_DIRECTORY)) {
$fh = fopen($local,'wb');
$header = array(
GetLang('Stats_Export_Header_Subject'),
GetLang('Stats_Export_Header_Date'),
GetLang('Stats_Export_Header_Time'),
GetLang('Stats_Export_Header_Duration'),
GetLang('Stats_Export_Header_Recipients'),
GetLang('Stats_Export_Header_Send_Rate'),
GetLang('Stats_Export_Header_Unique_Opened'),
GetLang('Stats_Export_Header_Total_Opened'),
GetLang('Stats_Export_Header_Percent_Opened'),
GetLang('Stats_Export_Header_Recipients_who_Clicked_Links'),
GetLang('Stats_Export_Header_Percent_Recipients_who_Clicked'),
GetLang('Stats_Export_Header_Total_Links_Clicked'),
GetLang('Stats_Export_Header_Hard_Bounced'),
GetLang('Stats_Export_Header_Soft_Bounced'),
GetLang('Stats_Export_Header_Total_Bounced'),
GetLang('Stats_Export_Header_Percent_Bounced'),
GetLang('Stats_Export_Header_Unsubscribed'),
GetLang('Stats_Export_Header_Percent_Unsubscribed'),
GetLang('Stats_Export_Header_Forwarded'),
GetLang('Stats_Export_Header_Recipients_who_Forwarded'),
GetLang('Stats_Export_Header_Percent_Recipients_who_Forwarded')
);
$header = '"' . implode('","',$header) . '"';
fwrite($fh,"$header\r\n");
foreach ($_REQUEST['stats'] as $statid) {
$f = $statsapi->FetchStats($statid,'newsletter');
$row = array();
$newsletterapi->Load($f['newsletterid']);
if (!$this->IsOwner($newsletterapi->ownerid)) {
$this->DenyAccess();
}
$duration = $f['finishtime'] - $f['starttime'];
$recipients = $f['sendsize'];
$bounces = $f['bouncecount_hard'] + $f['bouncecount_soft'];
$unique_clicks = (int)$statsapi->GetUniqueClickRecipients($statid);
$unique_forwards = (int)$statsapi->GetForwardsRecipients($statid);
if ($duration == 0) {
$send_rate = $recipients;
} else {
$send_rate = round($recipients / ($duration / 60),2);
}
if ($recipients == 0) {
$open_percent = $click_percent = $bounce_percent =
$unsub_percent = $forward_percent = 0;
} else {
$open_percent = round($f['emailopens_unique'] / $recipients * 100,2);
$click_percent = round($unique_clicks / $recipients * 100,2);
$bounce_percent = round($bounces / $recipients * 100,2);
$unsub_percent = round($f['unsubscribecount'] / $recipients * 100,2);
$forward_percent = round($unique_forwards / $recipients * 100,2);
}
$row = array(
str_replace('"','_',$newsletterapi->subject),
$this->PrintDate($f['starttime'],'d/m/y'),
$this->PrintDate($f['starttime'],'H:i'),
round($duration / 60,2),
$recipients,
$send_rate,
$f['emailopens_unique'],
$f['emailopens'],
$open_percent,
$unique_clicks,
$click_percent,
$f['linkclicks'],
$f['bouncecount_hard'],
$f['bouncecount_soft'],
$bounces,
$bounce_percent,
$f['unsubscribecount'],
$unsub_percent,
$f['emailforwards'],
$unique_forwards,
$forward_percent
);
$entry = '"' . implode('","',$row) . '"';
fwrite($fh,"$entry\r\n");
}
fclose($fh);
$GLOBALS['Message'] = $this->PrintSuccess('Export_Newsletter_Statistics',$http);
} else {
$GLOBALS['Message'] = $this->PrintWarning('Export_Not_Writable',TEMP_DIRECTORY);
}
break; // export
case 'delete':
$stats_to_delete = array();
if (isset($_POST['stats']) && !empty($_POST['stats'])) {
$stats_to_delete = $_POST['stats'];
}
if (isset($_GET['id'])) {
$stats_to_delete[] = (int)$_GET['id'];
}
if (empty($stats_to_delete)) {
$this->PrintNewsletterStats_Step1();
}
$stats_api = $this->GetApi('Stats');
$success = 0;
$failure = 0;
$cant_delete = 0;
foreach ($stats_to_delete as $p => $statid) {
if (!$this->CanAccessStats($statid, 'n')) {
// bail if they're trying to delete things they're not allowed to
$this->DenyAccess();
}
$finished = $stats_api->IsFinished($statid, 'newsletter');
if (!$finished) {
$cant_delete++;
continue;
}
$delete = $stats_api->HideStats($statid, 'newsletter', $user->Get('userid'));
if ($delete) {
$success++;
} else {
$failure++;
}
}
$msg = '';
if ($failure > 0) {
if ($failure == 1) {
$GLOBALS['Error'] = GetLang('StatisticsDeleteFail_One');
} else {
$GLOBALS['Error'] = sprintf(GetLang('StatisticsDeleteFail_One'), $this->FormatNumber($failure));
}
$msg .= $this->ParseTemplate('ErrorMsg', true, false);
}
if ($success > 0) {
if ($success == 1) {
$msg .= $this->PrintSuccess('StatisticsDeleteSuccess_One');
} else {
$msg .= $this->PrintSuccess('StatisticsDeleteSuccess_Many', $this->FormatNumber($success));
}
}
if ($cant_delete > 0) {
if ($cant_delete == 1) {
$msg .= $this->PrintSuccess('StatisticsDeleteNotFinished_One');
} else {
$msg .= $this->PrintSuccess('StatisticsDeleteNotFinished_Many', $this->FormatNumber($cant_delete));
}
}
$GLOBALS['Message'] = $msg;
break; // delete
}
$this->PrintNewsletterStats_Step1();
break; // doselect
case 'viewsummary':
$statid = IEM::requestGetGET('id', 0, 'intval');
if (!$this->CanAccessStats($statid, 'n')) {
$this->DenyAccess();
}
$this->PrintNewsletterStats_Step2($statid);
break;
default:
$this->PrintNewsletterStats_Step1();
break;
}
}
$this->PrintFooter($popup);
}
/**
* PrintNewsletterStats_Step1
* This will show a list of newsletters that have been sent out according to which lists the user has access to.
*
* @see User_API::GetLists
* @see Stats_API::GetNewsletterStats
*
* @return Void Doesn't return anything. Prints out a list of the newsletters sent to the lists that the user has access to.
*/
function PrintNewsletterStats_Step1()
{
$user = IEM::userGetCurrent();
$statsapi = $this->GetApi();
$this->LoadLanguageFile('Newsletters');
$perpage = $this->GetPerPage();
$DisplayPage = $this->GetCurrentPage();
$start = 0;
if ($perpage != 'all') {
$start = ($DisplayPage - 1) * $perpage;
}
$sortinfo = $this->GetSortDetails();
$lists = $user->GetLists();
$listids = array_keys($lists);
$NumberOfStats = $statsapi->GetNewsletterStats($listids, $sortinfo, true, 0, 0);
if (!isset($GLOBALS['Message'])) {
$GLOBALS['Message'] = '';
}
if ($NumberOfStats == 0) {
$GLOBALS['Message'] .= $this->PrintSuccess('NoNewslettersHaveBeenSent');
if ($user->HasAccess('Newsletters', 'Send')) {
$GLOBALS['Newsletters_SendButton'] = $this->ParseTemplate('Newsletter_Send_Button', true, false);
}
$this->ParseTemplate('Stats_Newsletters_Empty');
return;
}
$mystats = $statsapi->GetNewsletterStats($listids, $sortinfo, false, $start, $perpage);
$this->LoadLanguageFile('Lists');
$GLOBALS['FormAction'] = 'Action=ProcessPaging&SubAction=Newsletters&NextAction=Step1';
$GLOBALS['PAGE'] = 'Stats&Action=Newsletters&SubAction=Step1';
$this->SetupPaging($NumberOfStats, $DisplayPage, $perpage);
$paging = $this->ParseTemplate('Paging', true, false);
$stats_manage = $this->ParseTemplate('Stats_Newsletter_Manage', true, false);
$statsdisplay = '';
foreach ($mystats as $pos => $statsdetails) {
$GLOBALS['StatID'] = $statsdetails['statid'];
$GLOBALS['Newsletter'] = htmlspecialchars($statsdetails['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET);
$full_list_name = htmlspecialchars($statsdetails['listname'], ENT_QUOTES, SENDSTUDIO_CHARSET);
$GLOBALS['MailingList_Full'] = $full_list_name;
$GLOBALS['MailingList'] = $this->TruncateName($full_list_name, 60);
$GLOBALS['StartDate'] = $this->PrintTime($statsdetails['starttime'], true);
$GLOBALS['StatsAction'] = '<a href="index.php?Page=Stats&Action=Newsletters&SubAction=ViewSummary&id=' . $statsdetails['statid'] . '">' . GetLang('ViewSummary') . '</a> ';
$GLOBALS['StatsAction'] .= '<a href="index.php?Page=Stats&Action=Newsletters&SubAction=DoSelect&SelectAction=export&stats%5B%5D=' . $statsdetails['statid'] . '">' . GetLang('Export_Stats_Selected') . '</a> ';
$GLOBALS['StatsAction'] .= '<a href="remote_stats.php?height=420&width=420&overflow=none&statstype=n&Action=print&stats%5B%5D=' . $statsdetails['statid'] . '" class="thickbox" title="' . GetLang('PrintEmailCampaignStatistics') . '">' . GetLang('Print_Stats_Selected') . '</a> ';
$finishtime = $statsdetails['finishtime'];
if ($finishtime > 0) {
$GLOBALS['StatsAction'] .= '<a href="javascript:ConfirmDelete(' . $statsdetails['statid'] . ');">' . GetLang('Delete') . '</a>';
$GLOBALS['FinishDate'] = $this->PrintTime($finishtime, true);
} else {
$GLOBALS['StatsAction'] .= '<span class="disabled" title="' . GetLang('StatsDeleteDisabled') . '">' . GetLang('Delete') . '</a>';
$GLOBALS['FinishDate'] = GetLang('NotFinishedSending');
}
$bounce_count = $statsdetails['bouncecount_soft'] + $statsdetails['bouncecount_hard'] + $statsdetails['bouncecount_unknown'];
$GLOBALS['TotalRecipients'] = $this->FormatNumber($statsdetails['sendsize']);
$GLOBALS['BounceCount'] = $this->FormatNumber($bounce_count);
$GLOBALS['UnsubscribeCount'] = $this->FormatNumber($statsdetails['unsubscribecount']);
$statsdisplay .= $this->ParseTemplate('Stats_Newsletter_Manage_Row', true, false);
}
$stats_manage = str_replace('%%TPL_Stats_Newsletter_Manage_Row%%', $statsdisplay, $stats_manage);
$stats_manage = str_replace('%%TPL_Paging%%', $paging, $stats_manage);
$stats_manage = str_replace('%%TPL_Paging_Bottom%%', $GLOBALS['PagingBottom'], $stats_manage);
echo $stats_manage;
}
/**
* PrintNewsletterStats_Step2
* This displays summary information for a newsletter based on the statid passed in. This sets up the other tabs (opens, bounces, links and so on) as well but this particular function mainly sets up the summary page.
*
* @param Int $statid The statid to get information for.
*
* @see Stats_API::GetNewsletterSummary
* @see DisplayNewsletterOpens
* @see DisplayNewsletterLinks
* @see DisplayNewsletterBounces
* @see DisplayNewsletterUnsubscribes
* @see DisplayNewsletterForwards
*
* @return Void Doesn't return anything - just prints out the summary information.
*/
function PrintNewsletterStats_Step2($statid=0)
{
include_once(dirname(__FILE__) . '/amcharts/amcharts.php');
$perpage = $this->GetPerPage();
$statsapi = $this->GetApi('Stats');
$summary = $statsapi->GetNewsletterSummary($statid, true, $perpage);
// Log this to "User Activity Log"
IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/chart_bar.gif', $summary['newslettername']);
$GLOBALS['NewsletterID'] = $summary['newsletterid'];
$sent_when = $GLOBALS['StartSending'] = $this->PrintTime($summary['starttime'], true);
if ($summary['finishtime'] > 0) {
$GLOBALS['FinishSending'] = $this->PrintTime($summary['finishtime'], true);
$GLOBALS['SendingTime'] = $this->TimeDifference($summary['finishtime'] - $summary['starttime']);
} else {
$GLOBALS['FinishSending'] = GetLang('NotFinishedSending');
$GLOBALS['SendingTime'] = GetLang('NotFinishedSending');
}
$sent_to = $summary['htmlrecipients'] + $summary['textrecipients'] + $summary['multipartrecipients'];
$sent_size = $summary['sendsize'];
$GLOBALS['SentToDetails'] = sprintf(GetLang('NewsletterStatistics_Snapshot_SendSize'), $this->FormatNumber($sent_to), $this->FormatNumber($sent_size));
$test_mode_info = '';
if ($summary['sendtestmode'] == 1) {
$test_mode_info = GetLang('NewsletterStatistics_Send_TestMode_Enabled');
}
$GLOBALS['SummaryIntro'] = sprintf(GetLang('NewsletterStatistics_Snapshot_Summary'), htmlspecialchars($summary['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET), $sent_when, $test_mode_info);
$GLOBALS['NewsletterName'] = htmlspecialchars($summary['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET);
$GLOBALS['NewsletterSubject'] = htmlspecialchars($summary['newslettersubject'], ENT_QUOTES, SENDSTUDIO_CHARSET);
$GLOBALS['UserEmail'] = htmlspecialchars($summary['emailaddress'], ENT_QUOTES, SENDSTUDIO_CHARSET);
$sent_by = $summary['username'];
if ($summary['fullname']) {
$sent_by = $summary['fullname'];
}
$GLOBALS['SentBy'] = htmlspecialchars($sent_by, ENT_QUOTES, SENDSTUDIO_CHARSET);
if (sizeof($summary['lists']) > 1) {
$GLOBALS['SentToLists'] = GetLang('SentToLists');
$GLOBALS['MailingLists'] = '';
$break_up = 4;
$c = 1;
foreach ($summary['lists'] as $listid => $listname) {
if ($c % $break_up == 0) {
$GLOBALS['MailingLists'] .= '<br/>';
$c = 0;
}
$GLOBALS['MailingLists'] .= htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET) . ',';
$c++;
}
if (($c - 1) % $break_up != 0) {
$GLOBALS['MailingLists'] = substr($GLOBALS['MailingLists'], 0, -1);
}
} else {
$GLOBALS['SentToLists'] = GetLang('SentToList');
$listname = current($summary['lists']);
$GLOBALS['MailingLists'] = htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET);
}
$GLOBALS['UniqueOpens'] = sprintf(GetLang('EmailOpens_Unique'), $this->FormatNumber($summary['emailopens_unique']));
$GLOBALS['TotalOpens'] = sprintf(GetLang('EmailOpens_Total'), $this->FormatNumber($summary['emailopens']));
if ($sent_to != 0) {
$GLOBALS['OpenRate'] = $this->FormatNumber($summary['emailopens_unique'] / $sent_to * 100,2) . "%" ;
} else {
$GLOBALS['OpenRate'] = '0%';
}
$clicks = $statsapi->GetUniqueClickRecipients($statid,'','a');
if ($sent_to == 0) {
$GLOBALS['ClickThroughRate'] = "0%";
} else {
$GLOBALS['ClickThroughRate'] = $this->FormatNumber($clicks / $sent_to * 100,2) . '%';
}
$total_bounces = $summary['bouncecount_unknown'] + $summary['bouncecount_hard'] + $summary['bouncecount_soft'];
$GLOBALS['TotalBounces'] = $this->FormatNumber($total_bounces);
// now for the opens page.
// by default this is for all opens, not unique opens.
$only_unique = false;
if (isset($_GET['Unique'])) {
$only_unique = true;
}
if (!isset($_GET['Unique'])) {
$GLOBALS['OpensURL'] = 'javascript: void(0);" onclick="ShowTab(2);';
$GLOBALS['UniqueOpensURL'] = 'index.php?Page=Stats&Action=Newsletters&SubAction=ViewSummary&id=' . $statid . '&tab=2&Unique';
} else {
$GLOBALS['UniqueOpensURL'] = 'javascript: void(0);" onclick="ShowTab(2);';
$GLOBALS['OpensURL'] = 'index.php?Page=Stats&Action=Newsletters&SubAction=ViewSummary&id=' . $statid . '&tab=2';
}
$chosen_link = 'a';
if (isset($_GET['link'])) {
if (is_numeric($_GET['link'])) {
$chosen_link = $_GET['link'];
}
}
$chosen_bounce_type = '';
if (isset($_GET['bouncetype'])) {
$chosen_bounce_type = $_GET['bouncetype'];
}
// we need to process the opens page first because it sets the number of opens used in a calculation for the links page.
$GLOBALS['OpensPage'] = $this->DisplayNewsletterOpens($statid, $summary, $only_unique);
$GLOBALS['LinksPage'] = $this->DisplayNewsletterLinks($statid, $summary, $chosen_link);
$GLOBALS['BouncesPage'] = $this->DisplayNewsletterBounces($statid, $summary, $chosen_bounce_type);
$GLOBALS['UnsubscribesPage'] = $this->DisplayNewsletterUnsubscribes($statid, $summary);
$GLOBALS['ForwardsPage'] = $this->DisplayNewsletterForwards($statid, $summary);
$unopened = $sent_size - $summary['emailopens_unique'] - $total_bounces;
if ($unopened < 0) {
$unopened = 0;
}
// explicitly pass the sessionid across to the chart
// since it's not the browser but the server making this request, it may get a different session id if we don't, which then means it can't load the data properly.
// especially applies to windows servers.
$data_url = 'stats_chart.php?Opens='. $summary['emailopens_unique'] . '&Unopened=' . $unopened . '&Bounced=' . $total_bounces . '&' . IEM::SESSION_NAME . '=' . IEM::sessionID();
// Newsletter Summary Chart
$GLOBALS['SummaryChart'] = InsertChart('pie', $data_url, array('graph_title' => GetLang("NewsletterSummaryChart")));
// finally put it all together.
$page = $this->ParseTemplate('Stats_Newsletters_Step3', true, false);
if (isset($_GET['tab'])) {
$page .= '
<script>
ShowTab(' . $_GET['tab'] . ');
</script>
';
}
echo $page;
}
/**
* DisplayNewsletterOpens
* This displays the page of newsletter open information based on the details passed in.
* It will work out the calendar information, graph, paging and so on.
*
* @param Int $statid The statid to get information for.
* @param Array $summary The basic information - start time and total number of opens.
* @param Boolean $unique_only Whether to only show unique opens or not. By default this will show all open information, not just unique opens.
*
* @see Stats_API::GetOpens
* @see Stats_API::GetMostOpens
* @see DisplayChart
*
* @return Void Doesn't return anything - just prints out the tab of information.
*/
function DisplayNewsletterOpens($statid, $summary=array(), $unique_only=false)
{
$sent_when = $this->PrintTime($summary['starttime'], true);
$GLOBALS['DisplayOpensIntro'] = sprintf(GetLang('NewsletterStatistics_Snapshot_OpenHeading'), htmlspecialchars($summary['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET), $sent_when);
if ($unique_only) {
$GLOBALS['DisplayOpensIntro'] = sprintf(GetLang('NewsletterStatistics_Snapshot_OpenHeading_Unique'), htmlspecialchars($summary['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET), $sent_when);
}
$statsapi = $this->GetApi('Stats');
$GLOBALS['PPDisplayName'] = 'oc';
$base_action = $GLOBALS['PPDisplayName'].'&SubAction=Newsletters&NextAction=ViewSummary&id=' . $statid . '&tab=2';
if ($unique_only) {
$base_action .= '&Unique';
}
$calendar_restrictions = $this->CalendarRestrictions['opens'];
$GLOBALS['TabID'] = '2';
$this->SetupCalendar('Action=ProcessCalendar&' . $base_action);
$perpage = $this->GetPerPage();
$DisplayPage = (isset($_GET['DisplayPage'])) ? (int)$_GET['DisplayPage'] : 1;
$start = 0;
if ($perpage != 'all') {
$start = ($DisplayPage - 1) * $perpage;
}
// make sure unique opens are > 0 - if they aren't, something isn't tracking right anyway so no point trying anything else.
if ($summary['emailopens_unique'] > 0) {
$opens = $statsapi->GetOpens($statid, $start, $perpage, $unique_only, $calendar_restrictions);
}
/*
* we can't rely on the counter in the summary table -
* because you could delete subscribers.
* and we don't want that to affect the summary table because it distorts statistics.
*
* So we do an actual count here for paging.
*/
$opencount = $statsapi->GetOpens($statid, 0, 0, $unique_only, $calendar_restrictions, true);
// if we still don't have any opens, not sure how! but we display an error.
if (empty($opens)) {
if ($summary['trackopens']) {
if ($summary['emailopens_unique'] > 0) {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenOpened_CalendarProblem');
} else {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenOpened');
}
} else {
$GLOBALS['Error'] = GetLang('NewsletterWasNotOpenTracked');
}
$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
return $this->ParseTemplate('Stats_Step3_Opens_Empty', true, false);
}
$total_emails = $summary['htmlrecipients'] + $summary['textrecipients'] + $summary['multipartrecipients'];
$GLOBALS['TotalEmails'] = $this->FormatNumber($total_emails);
$GLOBALS['TotalOpens'] = $this->FormatNumber($summary['emailopens']);
$GLOBALS['TotalUniqueOpens'] = $this->FormatNumber($summary['emailopens_unique']);
$most_opens = $statsapi->GetMostOpens($statid, $calendar_restrictions);
$now = getdate();
if (isset($most_opens['mth'])) {
$GLOBALS['MostOpens'] = $this->Months[$most_opens['mth']] . ' ' . $most_opens['yr'];
}
if (isset($most_opens['hr'])) {
$GLOBALS['MostOpens'] = date(GetLang('Daily_Time_Display'),mktime($most_opens['hr'], 1, 1, 1, 1, $now['year']));
}
if (isset($most_opens['dow'])) {
$pos = array_search($most_opens['dow'], array_keys($this->days_of_week));
$GLOBALS['MostOpens'] = date(GetLang('Date_Display_Display'), strtotime("last " . $this->days_of_week[$pos]));
}
if (isset($most_opens['dom'])) {
$month = $now['mon'];
// if the day-of-month is after "today", it's going to be for "last month" so adjust the month accordingly.
if ($most_opens['dom'] > $now['mday']) {
$month = $now['mon'] - 1;
}
$GLOBALS['MostOpens'] = date(GetLang('Date_Display_Display'),mktime(0, 0, 1, $month, $most_opens['dom'], $now['year']));
}
$avg_opens = 0;
if ($total_emails > 0) {
$avg_opens = $summary['emailopens'] / $total_emails;
}
$GLOBALS['AverageOpens'] = $this->FormatNumber($avg_opens, 1);
$GLOBALS['FormAction'] = 'Action=ProcessPaging' . $base_action;
$GLOBALS['PAGE'] = 'Stats&Action=Newsletters&SubAction=ViewSummary&id=' . $statid . '&tab=2';
if ($unique_only) {
$GLOBALS['PAGE'] .= '&Unique';
}
$this->DisplayChart('OpenChart', 'newsletter', $statid,'column',array('graph_title' => GetLang("OpensChart")));
$token = "stats" . md5(uniqid('_'));
IEM::sessionSet($token, array(
'statid' => $statid,
'unique_only' => $unique_only,
'calendar_restrictions' => $calendar_restrictions,
'summary' => $summary
));
$GLOBALS['TableType'] = 'newsletter_opens';
$GLOBALS['TableToken'] = $token;
$GLOBALS['Loading_Indicator'] = $this->ParseTemplate('Loading_Indicator',true);
$GLOBALS['NewsletterOpenCount'] = $opencount;
return $this->ParseTemplate('Stats_Step3_Opens', true, false);
}
/**
* DisplayNewsletterLinks
* This displays the page of newsletter link information based on the details passed in.
* It will work out the calendar information, graph, paging and so on.
*
* @param Int $statid The statid to get information for.
* @param Array $summary The basic information - start time and total number of link clicks.
* @param String $chosen_link If this is present, we are showing information for a specific link. If it's not present, combine all links into one.
*
* @see Stats_API::GetClicks
* @see Stats_API::GetUniqueLinks
* @see DisplayChart
*
* @return Void Doesn't return anything - just prints out the tab of information.
*/
function DisplayNewsletterLinks($statid, $summary=array(), $chosen_link='a')
{
$sent_when = $this->PrintTime($summary['starttime'], true);
$GLOBALS['StatID'] = (int)$statid;
$GLOBALS['LinkAction'] = 'Newsletter';
if (!is_numeric($chosen_link)) {
$chosen_link = 'a';
}
$GLOBALS['DisplayLinksIntro'] = sprintf(GetLang('NewsletterStatistics_Snapshot_LinkHeading'), htmlspecialchars($summary['newslettername'], ENT_QUOTES, SENDSTUDIO_CHARSET), $sent_when);
$statsapi = $this->GetApi('Stats');
$GLOBALS['PPDisplayName'] = 'lc';
$base_action = $GLOBALS['PPDisplayName'].'&SubAction=Newsletters&NextAction=ViewSummary&id=' . $statid . '&tab=3&link=' . $chosen_link;
$GLOBALS['FormAction'] = 'Action=ProcessPaging' . $base_action;
$GLOBALS['PAGE'] = 'Stats&Action=Newsletters&SubAction=ViewSummary&id=' . $statid . '&tab=3&link=' . $chosen_link;
$calendar_restrictions = $this->CalendarRestrictions['clicks'];
$GLOBALS['TabID'] = '3';
$this->SetupCalendar('Action=ProcessCalendar&' . $base_action);
/*
* we can't rely on the counter in the summary table -
* because you could delete subscribers.
* and we don't want that to affect the summary table because it distorts statistics.
*
* So we do an actual count here for paging.
*/
$summary['linkclicks'] = $statsapi->GetClicks($statid, 0, 0, $chosen_link, $calendar_restrictions, true);
$links = array();
if ($summary['linkclicks'] > 0) {
$links = $statsapi->GetClicks($statid, 0, 10, $chosen_link, $calendar_restrictions, false);
}
if (empty($links)) {
if ($summary['tracklinks']) {
if (empty($all_links)) {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenClicked_NoLinksFound');
} else {
if ($summary['linkclicks'] > 0) {
if (is_numeric($chosen_link)) {
if ($calendar_restrictions != '') {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenClicked_CalendarLinkProblem');
} else {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenClicked_LinkProblem');
}
} else {
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenClicked_CalendarProblem');
}
} else {
$GLOBALS['DisplayStatsLinkList'] = 'none';
$GLOBALS['Error'] = GetLang('NewsletterHasNotBeenClicked');
}
}
} else {
$GLOBALS['Error'] = GetLang('NewsletterWasNotTracked_Links');
}
$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);