-
Notifications
You must be signed in to change notification settings - Fork 7
/
autoresponders-list.php
381 lines (343 loc) · 15.3 KB
/
autoresponders-list.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
<?php include('includes/header.php');?>
<?php include('includes/login/auth.php');?>
<?php include('includes/subscribers/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').'/autoresponders-list?i='.get_app_info('restricted_to_app').'&l='.$_GET['l'].'"</script>';
exit;
}
}
if(isset($_GET['e'])) $err = $_GET['e'];
else $err = '';
?>
<script type="text/javascript" src="<?php echo get_app_info('path');?>/js/validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
<?php
$q = 'SELECT id, name, type, custom_field FROM ares WHERE list = '.mysqli_real_escape_string($mysqli, $_GET['l']);
if(mysqli_num_rows(mysqli_query($mysqli, $q))==0):
?>
$("#autoresponder-form").show();
$("#new-autoresponder-btn").hide();
<?php else:?>
$("#autoresponder-form").hide();
<?php endif;?>
<?php if($err==1):?>
$("#autoresponder-form").show();
$("#new-autoresponder-btn").hide();
<?php endif;?>
$("#new-autoresponder-btn").click(function(){
$("#autoresponder-form").slideDown();
$(this).slideUp();
});
$("#cancel-btn").click(function(){
$("#autoresponder-form").slideUp();
$("#new-autoresponder-btn").slideDown();
});
//Validation
$("#add-autoresponder-form").validate({
rules: {
autoresponder_name: {
required: true
}
},
messages: {
autoresponder_name: "<?php echo addslashes(_('Autoresponder name is required'));?>"
}
});
});
</script>
<div class="row-fluid">
<div class="span2">
<?php include('includes/sidebar.php');?>
</div>
<div class="span10">
<div class="row-fluid">
<div class="span12">
<div>
<p class="lead"><?php echo get_app_data('app_name');?></p>
</div>
<h2><?php echo _('Autoresponders');?></h2>
<br/>
<p class="well"><?php echo _('List');?>: <a href="<?php echo get_app_info('path');?>/subscribers?i=<?php echo get_app_info('app');?>&l=<?php echo $_GET['l'];?>" title=""><span class="label label-info"><?php echo get_lists_data('name', $_GET['l']);?></span></a> | <a href="<?php echo get_app_info('path')?>/list?i=<?php echo get_app_info('app');?>" title=""><?php echo _('Back to lists');?></a>
</p><br/>
</div>
</div>
<?php if($err==1):?>
<div class="alert alert-danger"><?php echo _('You can\'t create an autoresponder based on a custom field already in use by another autoresponder.');?></div>
<?php endif;?>
<?php
//check if drip campaign has been created
$all_used = 0;
$q = 'SELECT type FROM ares WHERE list = '.mysqli_real_escape_string($mysqli, $_GET['l']).' AND type = 1';
if(mysqli_num_rows(mysqli_query($mysqli, $q)) > 0)
$all_used++;
//check if custom fields has been used up
$inuse = 0;
$total_dates = 0;
$q = 'SELECT custom_fields FROM lists WHERE id = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r = mysqli_query($mysqli, $q);
if (mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r)) $list_custom_fields = stripslashes($row['custom_fields']);
$list_custom_fields_array = explode('%s%', $list_custom_fields);
foreach($list_custom_fields_array as $cf)
{
$cf_array = explode(':', $cf);
if($cf_array[1]=='Date')
{
$total_dates++;
//check if custom field has been used in any autoresponders before
$q2 = 'SELECT custom_field FROM ares WHERE custom_field = "'.$cf_array[0].'" AND list = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r2 = mysqli_query($mysqli, $q2);
if (mysqli_num_rows($r2) > 0)
$inuse++;
}
}
}
//if all custom fields has been used up
if($inuse == $total_dates)
$all_used++;
?>
<?php if($all_used != 2): //if not all autoresponders have been created ?>
<p><a href="javascript:void(0)" id="new-autoresponder-btn" class="btn btn-inverse btn-large"><i class="icon-plus icon-white"></i> <?php echo _('Create a new autoresponder');?></a></p>
<?php else: ?>
<div class="alert alert-info"><?php echo _('All autoresponders have been created.');?></div>
<?php endif;?>
<div class="row-fluid" id="autoresponder-form">
<div class="span12 well">
<form method="POST" action="<?php echo get_app_info('path');?>/includes/ares/add-autoresponder.php" id="add-autoresponder-form">
<h3><i class="icon icon-plus" style="margin-top: 4px;"></i> <?php echo _('Create a new autoresponder');?></h3><hr/>
<?php if($all_used != 2): //if not all autoresponders have been created ?>
<div class="row-fluid">
<div class="span3">
<label for="autoresponder_name"><?php echo _('Autoresponder name');?></label>
<input type="text" name="autoresponder_name" id="autoresponder_name" placeholder="Name" style="width: 98%;">
<br/><br/>
</div>
<div class="span9">
<p><?php echo _('Autoresponder type');?></p>
<?php
$drip_created = false;
$q = 'SELECT type FROM ares WHERE list = '.mysqli_real_escape_string($mysqli, $_GET['l']).' AND type = 1';
if(mysqli_num_rows(mysqli_query($mysqli, $q)) == 0):
?>
<label class="radio">
<input type="radio" name="autoresponder_type" id="autoresponder_type1" value="1" checked>
<strong><?php echo _('Drip campaign');?></strong><br/>
<?php echo _('Create a sequence of emails that automatically sends to subscribers after they sign up.');?>
</label><br/>
<?php else:
$drip_created = true;
?>
<div class="alert alert-info"><?php echo _('A drip campaign autoresponder has already been created. You cannot create another drip campaign but you can add more emails to the sequence.');?></div>
<?php endif;?>
<?php
$inuse = 0;
$total_dates = 0;
$q = 'SELECT custom_fields FROM lists WHERE id = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r = mysqli_query($mysqli, $q);
if (mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r)) $list_custom_fields = stripslashes($row['custom_fields']);
$list_custom_fields_array = explode('%s%', $list_custom_fields);
foreach($list_custom_fields_array as $cf)
{
$cf_array = explode(':', $cf);
if($cf_array[1]=='Date')
{
$total_dates++;
//check if custom field has been used in any autoresponders before
$q2 = 'SELECT custom_field FROM ares WHERE custom_field = "'.$cf_array[0].'" AND list = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r2 = mysqli_query($mysqli, $q2);
if (mysqli_num_rows($r2) > 0)
$inuse++;
}
}
}
//if all custom fields has been used up
if($inuse == $total_dates):
?>
<div class="alert alert-info"><?php echo _('There are no available \'date based custom fields\' to create anniversary or date based autoresponders.');?></div>
<?php else:?>
<?php
$q = 'SELECT custom_fields FROM lists WHERE id = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r = mysqli_query($mysqli, $q);
if (mysqli_num_rows($r) > 0):
while($row = mysqli_fetch_array($r)) $list_custom_fields = stripslashes($row['custom_fields']);
if($list_custom_fields!=''):
?>
<label class="radio" id="ares_type2">
<input type="radio" name="autoresponder_type" id="autoresponder_type2" value="2" <?php if($drip_created) echo 'checked'; ?>>
<strong><?php echo _('Send annually');?></strong><br/>
<?php echo _('Create emails that automatically sends annually to subscribers, eg. anniversaries or birthdays.');?>
<br/><br/>
<?php echo _('Based on this date');?>:<br/>
<select id="type2_custom_fields" name="type2_custom_fields">
<?php
$list_custom_fields_array = explode('%s%', $list_custom_fields);
foreach($list_custom_fields_array as $cf)
{
$cf_array = explode(':', $cf);
if($cf_array[1]=='Date')
{
//check if custom field has been used in any autoresponders before
$q2 = 'SELECT custom_field FROM ares WHERE custom_field = "'.$cf_array[0].'" AND list = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r2 = mysqli_query($mysqli, $q2);
if (mysqli_num_rows($r2) > 0)
echo '<option value="'.$cf_array[0].'%s%inuse">'.$cf_array[0].' (in use)</option>';
else
echo '<option value="'.$cf_array[0].'">'.$cf_array[0].'</option>';
}
}
?>
</select>
<br/>
</label>
<?php endif; endif; ?>
<?php
$q = 'SELECT custom_fields FROM lists WHERE id = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r = mysqli_query($mysqli, $q);
if (mysqli_num_rows($r) > 0):
while($row = mysqli_fetch_array($r)) $list_custom_fields = stripslashes($row['custom_fields']);
if($list_custom_fields!=''):
?>
<label class="radio" id="ares_type3" style="margin-top: 18px;">
<input type="radio" name="autoresponder_type" id="autoresponder_type3" value="3">
<strong><?php echo _('Send on date');?></strong><br/>
<?php echo _('Create one off emails that sends automatically on a specific date. eg. one off reminders.');?>
<br/><br/>
<?php echo _('Based on this date');?>:<br/>
<select id="type3_custom_fields" name="type3_custom_fields">
<?php
$list_custom_fields_array = explode('%s%', $list_custom_fields);
foreach($list_custom_fields_array as $cf)
{
$cf_array = explode(':', $cf);
if($cf_array[1]=='Date')
{
//check if custom field has been used in any autoresponders before
$q2 = 'SELECT custom_field FROM ares WHERE custom_field = "'.$cf_array[0].'" AND list = '.mysqli_real_escape_string($mysqli, $_GET['l']);
$r2 = mysqli_query($mysqli, $q2);
if (mysqli_num_rows($r2) > 0)
echo '<option value="'.$cf_array[0].'%s%inuse">'.$cf_array[0].' (in use)</option>';
else
echo '<option value="'.$cf_array[0].'">'.$cf_array[0].'</option>';
}
}
?>
</select>
<br/>
</label>
<?php endif; endif; ?>
<?php endif; ?>
<br/>
<input type="hidden" name="id" value="<?php echo $_GET['i'];?>"></input>
<input type="hidden" name="list" value="<?php echo $_GET['l'];?>"></input>
<button class="btn btn-inverse" type="submit"><?php echo _('Save & next');?></button> <?php echo _('or');?> <a href="javascript:void(0)" id="cancel-btn"><?php echo _('cancel');?></a>
</div>
</div>
<?php endif;?>
</form>
</div>
</div>
<br/><br/>
<div class="row-fluid">
<div class="span12">
<h3><?php echo _('Existing autoresponders');?></h3><hr/>
<table class="table table-striped responsive">
<thead>
<tr>
<th><?php echo _('Autoresponder');?></th>
<th><?php echo _('Type');?></th>
<th><?php echo _('Emails sent');?></th>
<th><?php echo _('Delete');?></th>
</tr>
</thead>
<tbody>
<?php
$q = 'SELECT id, name, type, custom_field FROM ares WHERE list = '.mysqli_real_escape_string($mysqli, $_GET['l']).' ORDER BY type ASC';
$r = mysqli_query($mysqli, $q);
if ($r && mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r))
{
$ares_id = $row['id'];
$ares_name = $row['name'];
$ares_type = $row['type'];
$ares_custom_field = $row['custom_field'];
$q2 = 'SELECT recipients FROM ares_emails WHERE ares_id = '.$ares_id;
$r2 = mysqli_query($mysqli, $q2);
if ($r2 && mysqli_num_rows($r2) > 0)
{
$recipients = 0;
while($row = mysqli_fetch_array($r2))
{
$recipients += $row['recipients'];
}
}
else $recipients = _('No emails have been set up');
switch($ares_type)
{
case '1':
$ares_type_name = _('Drip campaign');
break;
case '2':
$ares_type_name = _('Send annually').' ('.$ares_custom_field.')';
break;
case '3':
$ares_type_name = _('Send on date').' ('.$ares_custom_field.')';
break;
}
echo '
<tr id="ares-'.$ares_id.'">
<td><a href="'.get_app_info('path').'/autoresponders-emails?i='.get_app_info('app').'&a='.$ares_id.'">'.$ares_name.'</a></td>
<td>'.$ares_type_name.'</td>
<td>'.$recipients.'</td>
<td><a href="javascript:void(0)" title="" id="delete-'.$ares_id.'" data-id="'.$ares_id.'"><i class="icon-trash"></i></a></td>
<script type="text/javascript">
$("#delete-'.$ares_id.'").click(function(e){
e.preventDefault();
c = confirm("'._('All associated autoresponder emails will be permanently deleted.').' '._('Confirm delete').' \''.$ares_name.'\'?");
if(c)
{
$.post("'.get_app_info('path').'/includes/ares/delete-ares.php", { id: $(this).data("id") },
function(data) {
if(data)
{
$("#ares-'.$ares_id.'").fadeOut(function(){
window.location = "'.get_app_info('path').'/autoresponders-list?i='.get_app_info('app').'&l='.$_GET['l'].'";
});
}
else
{
alert("'._('Sorry, unable to delete. Please try again later!').'");
}
}
);
}
});
</script>
</tr>
';
}
}
else
{
echo '
<tr>
<td colspan="4">'._('No autoresponders').'</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include('includes/footer.php');?>