-
Notifications
You must be signed in to change notification settings - Fork 28
/
reports.php
187 lines (178 loc) · 6.91 KB
/
reports.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
<?php include('includes/header.php');?>
<?php include('includes/login/auth.php');?>
<?php include('includes/dashboard/main.php');?>
<?php
if(get_app_info('is_sub_user'))
{
if(get_app_info('app')!=get_app_info('restricted_to_app'))
{
echo '<script type="text/javascript">window.location="'.get_app_info('path').'/reports?i='.get_app_info('restricted_to_app').'"</script>';
exit;
}
}
?>
<div class="row-fluid">
<div class="span2">
<?php include('includes/sidebar.php');?>
</div>
<div class="span10">
<div>
<p class="lead"><?php echo get_app_data('app_name');?></p>
</div>
<h2><?php echo _('Reports');?></h2><br/>
<table class="table table-striped responsive">
<thead>
<tr>
<th><?php echo _('Campaign title');?></th>
<th><?php echo _('Recipients');?></th>
<th><?php echo _('Sent');?></th>
<th><?php echo _('Unique Opens');?></th>
<th><?php echo _('Unique Clicks');?></th>
<th><?php echo _('Delete');?></th>
</tr>
</thead>
<tbody>
<?php
$limit = 10;
$total_subs = totals($_GET['i'], 'reports');
$total_pages = ceil($total_subs/$limit);
$p = isset($_GET['p']) ? $_GET['p'] : null;
$offset = $p!=null ? ($p-1) * $limit : 0;
$q = 'SELECT * FROM campaigns WHERE userID = '.get_app_info('main_userID').' AND app='.get_app_info('app').' AND sent != "" ORDER BY id DESC LIMIT '.$offset.','.$limit;
$r = mysqli_query($mysqli, $q);
if ($r && mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r))
{
$id = stripslashes($row['id']);
$title = stripslashes(htmlentities($row['title'],ENT_QUOTES,"UTF-8"));
$recipients = stripslashes($row['recipients']);
$sent = stripslashes($row['sent']);
$opens = stripslashes($row['opens']);
$from_email = stripslashes($row['from_email']);
$error_stack = stripslashes($row['errors']);
$error_stack_array = explode(',', $error_stack);
$no_of_errors = count($error_stack_array);
if($opens=='')
{
$percentage_opened = 0;
$opens_unique = 0;
}
else
{
$opens_array = explode(',', $opens);
$opens_unique = count(array_unique($opens_array));
$percentage_opened = round($opens_unique/$recipients * 100, 2);
}
$percentage_clicked = round(get_click_percentage($id)/$recipients *100, 2);
//tags for subject
preg_match_all('/\[([a-zA-Z0-9!#%^&*()+=$@._-|\/?<>~`"\'\s]+),\s*fallback=/i', $title, $matches_var, PREG_PATTERN_ORDER);
preg_match_all('/,\s*fallback=([a-zA-Z0-9!,#%^&*()+=$@._-|\/?<>~`"\'\s]*)\]/i', $title, $matches_val, PREG_PATTERN_ORDER);
preg_match_all('/(\[[a-zA-Z0-9!#%^&*()+=$@._-|\/?<>~`"\'\s]+,\s*fallback=[a-zA-Z0-9!,#%^&*()+=$@._-|\/?<>~`"\'\s]*\])/i', $title, $matches_all, PREG_PATTERN_ORDER);
$matches_var = $matches_var[1];
$matches_val = $matches_val[1];
$matches_all = $matches_all[1];
for($i=0;$i<count($matches_var);$i++)
{
$field = $matches_var[$i];
$fallback = $matches_val[$i];
$tag = $matches_all[$i];
//for each match, replace tag with fallback
$title = str_replace($tag, $fallback, $title);
}
$title = str_replace('[Email]', $from_email, $title);
if($sent==NULL)
{
echo '
<tr id="'.$id.'">
<td><span class="label">Draft</span> <a href="'.get_app_info('path').'/send-to?i='.get_app_info('app').'&c='.$id.'" title="'._('Define recipients & send').'">'.$title.'</a> | <a href="'.get_app_info('path').'/edit?i='.get_app_info('app').'&c='.$id.'" title="'._('Edit this campaign').'"> Edit</a></td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td><a href="javascript:void(0)" title="Delete '.$title.'?" id="delete-btn-'.$id.'" class="delete-campaign"><i class="icon icon-trash"></i></a></td>
<script type="text/javascript">
$("#delete-btn-'.$id.'").click(function(e){
e.preventDefault();
c = confirm("'._('Confirm delete').' '.$title.'?");
if(c)
{
$.post("includes/campaigns/delete.php", { campaign_id: '.$id.' },
function(data) {
if(data)
{
$("#'.$id.'").fadeOut();
}
else
{
alert("'._('Sorry, unable to delete. Please try again later!').'");
}
}
);
}
});
</script>
</tr>
';
}
else
{
if($error_stack != '')
$download_errors = ' | <a href="'.get_app_info('path').'/includes/app/download-errors-csv.php?c='.$id.'" title="'._('Download CSV of emails that were not delivered to even after retrying').'">'.$no_of_errors.' '._('not delivered').'</a>';
else
$download_errors = '';
echo '
<tr id="'.$id.'">
<td></a> <a href="'.get_app_info('path').'/report?i='.get_app_info('app').'&c='.$id.'" title="">'.$title.'</a>'.$download_errors.'</td>
<td>'.number_format($recipients).'</td>
<td>'.parse_date($sent, 'long', true).'</td>
<td><span class="label">'.$percentage_opened.'%</span> '.number_format($opens_unique).' '._('opened').'</td>
<td><span class="label">'.$percentage_clicked.'%</span> '.number_format(get_click_percentage($id)).' '._('clicked').'</td>
<td><a href="javascript:void(0)" title="Delete '.$title.'?" id="delete-btn-'.$id.'" class="delete-campaign"><i class="icon icon-trash"></i></a></td>
<script type="text/javascript">
$("#delete-btn-'.$id.'").click(function(e){
e.preventDefault();
c = confirm("'._('Confirm delete').' '.$title.'?");
if(c)
{
$.post("includes/campaigns/delete.php", { campaign_id: '.$id.' },
function(data) {
if(data)
{
$("#'.$id.'").fadeOut();
}
else
{
alert("'._('Sorry, unable to delete. Please try again later!').'");
}
}
);
}
});
</script>
</tr>
';
$download_errors = '';
}
}
}
else
{
echo '
<tr>
<td>'._('There are no reports yet.').' <a href="'.get_app_info('path').'/create?i='.get_app_info('app').'" title="">'._('Create your first campaign').'</a>!</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
';
}
?>
</tbody>
</table>
<?php pagination($limit, 'reports'); ?>
</div>
</div>
<?php include('includes/footer.php');?>