-
Notifications
You must be signed in to change notification settings - Fork 7
/
pending-unsubscription-requests.php
211 lines (181 loc) · 6.1 KB
/
pending-unsubscription-requests.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
<?php include('includes/header.php');?>
<?php include('includes/login/auth.php');?>
<?php include('includes/subscribers/main.php');?>
<?php include('includes/helpers/short.php');?>
<?php
//vars
if(isset($_GET['s'])) $s = $_GET['s'];
else $s = '';
?>
<div class="row-fluid">
<div class="span2">
<?php include('includes/sidebar.php');?>
</div>
<div class="span10">
<h2><?php echo _('Pending Unsubscription Requests');?></h2> <br/>
<form class="form-horizontal" id="form2" accept-charset="utf-8" method="GET" action="">
<table class="table table-striped table-condensed responsive">
<tbody>
<tr>
<?php
$q = 'SELECT id, name, email, phone, idstounsubscribe, raw_emails, date_created
FROM unsubscriberequests WHERE status = 0 Limit 200';
$r = mysqli_query($mysqli, $q);
$all_rows = array();
while ($row = mysqli_fetch_assoc($r)) {
$all_rows[] = $row;
}
function printrowheader()
{
?>
<tr>
<th><?php echo _('<input type="checkbox" class="select_all">');?></th>
<th><?php echo _('Id');?></th>
<th><?php echo _('Volunteer Name');?></th>
<th><?php echo _('Volunteer Email');?></th>
<th><?php echo _('Volunteer Phone');?></th>
<th><?php echo _('Emails to Unsubscribe');?></th>
<th><?php echo _('Number of emails');?></th>
<th><?php echo _('Date');?></th>
<th><?php echo _('Status');?></th>
</tr>
<?
}
function printrow($row)
{
$id = $row['id'];
$name = stripslashes($row['name']);
$email = stripslashes($row['email']);
$phone = stripslashes($row['phone']);
$raw_emails = stripslashes($row['raw_emails']);
$idstounsubscribe = stripslashes($row['idstounsubscribe']);
$date_created = date('d/m/y h:i:s A', strtotime($row['date_created']));
$status = '<a href="javascript:void(0)" id="subscription-'.$id.'" class="label">'._('Pending').'</a>';
?>
<tr id="row-<?echo $id;?>" class="record_table">
<td><input type="checkbox" id="" name="rows_to_edit[<?echo $id;?>]" class="multi_checkbox checkall" value="<?echo $idstounsubscribe?>"></td>
<td><?php echo $id;?></td>
<td><?php echo $name;?></td>
<td><?php echo $email;?></td>
<td><?php echo $phone;?></td>
<td <?echo "title='$raw_emails\n--------------------------------\n$idstounsubscribe'"?>> <?php echo strlen($raw_emails)>20?substr($raw_emails,0,20).'...':$raw_emails;?></td>
<td><?php echo substr_count($idstounsubscribe, ",")+1;?></td>
<td><?php echo $date_created;?></td>
<td><?php echo $status;?></td>
</tr>
<?php
}
if(count($all_rows)>0)
{
printrowheader();
foreach ($all_rows as $row) {
printrow($row);
}
?>
<tr>
<td><input type="checkbox" class="select_all" id="checkbox2"></td>
<td colspan="9"><label for="checkbox2">Select All</label></td>
<?
}
else
{
?>
<tr>
<td colspan="8">No pending unsubscription request.</td>
</tr>
<?php
}
?>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary" id="submit1">Unsubscribe selected</button>
<button class="btn btn-info" id="button2">Reject selected requests</button>
</form>
<?php pagination($limit);?>
</div>
</div>
<script>
$(document).ready(function() {
var lastChecked = null;
var $chkboxes = $('.multi_checkbox');
$chkboxes.click(function(e) {
if(!lastChecked) {
lastChecked = this;
return;
}
if(e.shiftKey) {
var start = $chkboxes.index(this);
var end = $chkboxes.index(lastChecked);
$chkboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).attr('checked', lastChecked.checked);
}
lastChecked = this;
});
$('.record_table').click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
});
$('.select_all').click(function(){
$('.multi_checkbox, .select_all').attr('checked',this.checked);
});
$(".multi_checkbox").click(function(){
if($(".multi_checkbox").length == $(".multi_checkbox:checked").length) {
$(".select_all").attr("checked", "checked");
} else {
$(".select_all").removeAttr("checked");
}
});
$("#form2").submit(function(event) {
event.preventDefault();
var data_to_send = {'ids_to_send[]':[],'action':"approve"};
if($(".multi_checkbox:checked").length>0)
{
$(".multi_checkbox:checked").each(function(){
req_id = $(this).parent().parent().prop('id').split('-')[1];
payload = $(this).val();
data_to_send['ids_to_send[]'].push(req_id+"--"+payload);
});
console.log(data_to_send);
$.post("includes/subscribers/manual-unsubscribe.php", data_to_send)
.done(function(data) {
success_ids = data.split(',');
for(var i in success_ids)
{
$('#subscription-'+success_ids[i]).text("Unsubscribed").removeClass("label-important").addClass("label-success");
}
});
}
else
{
alert("select at least one request");
}
});
$("#button2").click(function(event) {
event.preventDefault();
var data_to_send = {'ids_to_send[]':[],'action':"reject"};
if($(".multi_checkbox:checked").length>0)
{
$(".multi_checkbox:checked").each(function(){
req_id = $(this).parent().parent().prop('id').split('-')[1];
payload = $(this).val();
data_to_send['ids_to_send[]'].push(req_id+"--"+payload);
});
console.log(data_to_send);
$.post("includes/subscribers/manual-unsubscribe.php", data_to_send)
.done(function(data) {
success_ids = data.split(',');
for(var i in success_ids)
{
$('#subscription-'+success_ids[i]).text("Rejected").removeClass("label-success").addClass("label-important");
}
});
}
else
{
alert("select at least one request");
}
});
});
</script>
<?php include('includes/footer.php');?>