forked from nodesman/wp-autoresponder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_autoresponder.php
202 lines (180 loc) · 6.13 KB
/
manage_autoresponder.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
<?php
include "autoresponder.messages.lib.php";
function wpr_manage_responder()
{
switch ($_GET['mact'])
{
case 'create':
_wpr_manage_responder_create();
break;
case 'edit':
_wpr_manage_responder_edit();
break;
case 'delete':
_wpr_manage_responder_delete();
break;
default:
_wpr_manage_responder_list();
}
}
function _wpr_manage_responder_delete()
{
global $wpdb;
$id = $_GET['id'];
$message = _wpr_get_autoresponder_message($id);
if ($_GET['confirm'] == "true")
{
$query = "DELETE FROM ".$wpdb->prefix."wpr_autoresponder_messages where id=".$id;
$wpdb->query($query);
?>
<script>window.location='admin.php?page=wpresponder/autoresponder.php&action=manage&aid=<?php echo $_GET['aid'] ?>';</script>
<?php
}
else
{
?>
<div class="wrap"><h2>Confirm Deletion Of '<?php echo $message->subject ?>'</h2></div>
<div class="updated fade">Are you sure you want to delete this message? </div>
<a href="<?php echo $_SERVER['REQUEST_URI'] ?>&confirm=true" class="button">Yes</a> <a href="admin.php?page=wpresponder/autoresponder.php&aid=<?php echo $_GET['aid']; ?>&action=manage" class="button">Cancel</a>
<?php
}
}
function _wpr_manage_responder_create()
{
global $wpdb;
$wpr_autoresponder_messages = $wpdb->prefix."wpr_autoresponder_messages";
$parameters->htmlenabled=1;
if (isset($_POST['subject']))
{
$subject = $_POST['subject'];
$textbody = $_POST['body'];
$aid = $_GET['aid'];
$htmlenabled = (isset($_POST['htmlenabled']))?1:0;
$attachimages = ($_POST['attachimages']=="1");
$htmlbody = $_POST['htmlbody'];
$sequence = intval($_POST['sequence']);
$whetherAMessageExistsOnSaidDay = $wpdb->prepare("SELECT COUNT(*) num FROM $wpr_autoresponder_messages WHERE `aid`=$aid AND `sequence`=$sequence");
$results = $wpdb->get_results($whetherAMessageExistsOnSaidDay);
if ($results[0]->num != 0)
{
$error = "An autoresponder follow-up message has already been added for that day. Set this e-mail to go out another day.";
}
else
{
if (!($subject && $textbody))
{
$error = "Subject and Text Body are required";
}
else
{
if ($htmlenabled && !$htmlbody)
{
$error = "You have enabled HTML E-Mail but not entered any content for the HTML E-mail.";
}
else
{
$sequence = (int) $sequence;
$query = "INSERT INTO ".$wpdb->prefix."wpr_autoresponder_messages (aid, subject,htmlenabled,textbody,htmlbody,attachimages,sequence) values ('$aid','$subject','".((int) $htmlenabled)."','$textbody','$htmlbody','$attachimages',$sequence)";
$wpdb->query($query);
?>
<div class="wrap"><h2>Message Added</h2></div>
<a href="admin.php?page=wpresponder/autoresponder.php&action=manage&aid=<?php echo $_GET['aid'] ?>" class="button">OK</a>
</a>
<?php
return;
}
}
}
$parameters->subject = $subject;
$parameters->textbody = $textbody;
$parameters->htmlenabled = ($htmlenabled)?1:0;
$parameters->htmlbody = $htmlbody;
$parameters->textbody = $textbody;
$parameters->sequence = $sequence;
}
$parameters->buttontext = "Create Message";
$parameters->formtitle = "Create Folllow Up Mail";
wpr_mail_form($parameters,"autoresponder",$error);
}
function _wpr_manage_responder_list()
{
global $wpdb;
$id = $_GET['aid'];
$responder = _wpr_autoresponder_get($id);
$query = "SELECT * FROM ".$wpdb->prefix."wpr_autoresponder_messages where aid=".$id." order by sequence";
$messages = $wpdb->get_results($query);
?>
<div class="wrap"> <h2>'<?php echo $responder->name ?>' Follow Up Messages</h2></div>
<table class="widefat">
<thead>
<tr>
<th>Subject</th>
<th>Sequence</th>
<th>Action</th>
</tr>
</thead>
<?php
foreach ($messages as $message)
{?>
<tr>
<td><?php echo htmlspecialchars($message->subject) ?></td>
<td><?php echo htmlspecialchars($message->sequence) ?></td>
<td><a href="admin.php?page=wpresponder/autoresponder.php&action=manage&mact=edit&aid=<?php echo $_GET['aid'] ?>&id=<?php echo $message->id ?>" class="button">Edit</a> <a href="admin.php?page=wpresponder/autoresponder.php&action=manage&mact=delete&aid=<?php echo $_GET['aid'] ?>&id=<?php echo $message->id ?>" class="button">Delete</a></td>
</tr>
<?php
}
?>
</table>
<a href="admin.php?page=wpresponder/autoresponder.php" class="button">« Back To Autoresponders</a> <input type="button" value="Add Message" onclick="window.location='admin.php?page=wpresponder/autoresponder.php&action=manage&mact=create&aid=<?php echo $_GET['aid'] ?>'" class="button" />
<?php
}
function _wpr_manage_responder_edit()
{
global $wpdb;
$error="";
if (isset($_POST['subject']))
{
$subject = $_POST['subject'];
$textbody = $_POST['body'];
$aid = $_GET['aid'];
$id = $_GET['id'];
$htmlenabled = ($_POST['htmlenabled'] == "on");
$htmlbody = $_POST['htmlbody'];
$sequence = $_POST['sequence'];
if (!($subject && $textbody))
{
$error = "Subject and Text Body are required";
}
else
{
if ($htmlenabled && !$htmlbody)
{
$error = "You have enabled HTML E-Mail but not entered any content for the HTML E-mail.";
}
else
{
$sequence = (int) $sequence;
$query = "UPDATE ".$wpdb->prefix."wpr_autoresponder_messages set subject='$subject',textbody='$textbody',htmlbody='$htmlbody',htmlenabled='".((int)$htmlenabled)."',sequence=$sequence where id=$id";
$wpdb->query($query);
?>
<script>
window.location='admin.php?page=wpresponder/autoresponder.php&action=manage&aid=<?php echo $_GET['aid']; ?>';
</script>
<?php
return;
}
}
$parameters->subject = $subject;
$parameters->textbody = $textbody;
$parameters->htmlbody = $htmlbody;
$parameters->sequence = $sequence;
}
if (empty($parameters))
{
$id = $_GET['id'];
$parameters = _wpr_get_autoresponder_message($id);
}
$parameters->formtitle = "Edit Follow Up Mail";
$parameters->buttontext = "Save Message";
wpr_mail_form($parameters,"autoresponder",$error);
}