-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_subscriber.php
231 lines (214 loc) · 9.61 KB
/
move_subscriber.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
<?php
# ---------------------------------------------------------
# Set the valid responder numbers
$responder_list = array();
$responder_list[1] = "1";
$responder_list[2] = "2";
$responder_list[3] = "3";
$responder_list[4] = "4";
$responder_list[5] = "5";
$responder_list[6] = "6";
$responder_list[7] = "7";
$responder_list[8] = "8";
$responder_list[9] = "9";
$responder_list[10] = "10";
$responder_list[11] = "11";
$responder_list[12] = "12";
$responder_list[13] = "13";
$responder_list[14] = "14";
$responder_list[15] = "15";
$responder_list[16] = "16";
$responder_list[17] = "17";
$responder_list[18] = "18";
$responder_list[19] = "19";
$responder_list[20] = "20";
# ---------------------------------------------------------
# Set stuff up
if ($config_init != TRUE) {
$config_init = TRUE;
include('config.php');
}
# ---------------------------------------------------------
# Grab and check the move_to variable
if (empty($passed['MOVE_TO'])) {
$passed['MOVE_TO'] = $_REQUEST['MOVE_TO'];
}
$move_to_checked = FALSE;
foreach ($responder_list as $key => $value) {
if ($passed['MOVE_TO'] == $value) {
$move_to_checked = TRUE;
}
}
if ($move_to_checked != TRUE) {
die("Invalid responder number!<br>\n");
}
# Get the other passed data
if (empty($passed['NAME'])) {
$passed['NAME'] = $_REQUEST['NAME'];
}
if (empty($passed['EMAIL'])) {
$passed['EMAIL'] = $_REQUEST['EMAIL'];
}
if (empty($passed['FIRST'])) {
$passed['FIRST'] = $_REQUEST['FIRST'];
}
if (empty($passed['LAST'])) {
$passed['LAST'] = $_REQUEST['LAST'];
}
if (empty($passed['IP'])) {
$passed['IP'] = $_REQUEST['IP'];
}
if (empty($passed['DEL'])) {
$passed['DEL'] = $_REQUEST['DEL'];
}
if ((empty($passed['DEL'])) || ($passed['DEL'] == "") || ($passed['DEL'] == 0) || ($passed['DEL'] == FALSE)) {
$passed['DEL'] = FALSE;
}
else {
$passed['DEL'] = TRUE;
}
if ($passed['ONLYDEL'] == "YES") {
$passed['ONLYDEL'] = TRUE;
}
else {
$passed['ONLYDEL'] = FALSE;
}
if ((empty($passed['EMAIL'])) OR ($passed['EMAIL'] == "") OR ($passed['EMAIL'] == NULL)) {
die("Nobody was passed for me to move!<br>\n");
}
if ((empty($passed['FIRST'])) || (empty($passed['LAST']))) {
if (!(empty($passed['NAME']))) {
$Space_List=explode(' ',trim($passed['NAME']));
$Space_MaxIndex = sizeof($Space_List);
if (empty($passed['LAST'])) {
$passed['LAST'] = $Space_List[$Space_MaxIndex-1];
}
if (empty($passed['FIRST'])) {
$passed['FIRST'] = '';
for ($k=0; $k<=$Space_MaxIndex-2; $k++) {
$passed['FIRST'] = $passed['FIRST'] . ' ' . $Space_List[$k];
}
$passed['FIRST'] = trim($passed['FIRST']);
}
}
}
# Create the safe data array
foreach ($passed as $key => $value) {
$safe[$key] = MakeSafe($value);
}
if (!(isInBlacklist($safe['EMAIL']))) {
# Get old responder info
$got_custom_fields = FALSE;
$user_data = array();
$custom_fields = array();
$resp_list = "";
foreach ($responder_list as $idx => $resp_num) {
$resp_list = $resp_list . "'" . $resp_num . "',";
}
$resp_list = trim($resp_list,",");
$query = "SELECT * FROM InfResp_subscribers WHERE (EmailAddress = '" . $safe['EMAIL'] . "') AND ResponderID IN (". $resp_list .")";
# echo $query . "<br>\n";
$result = mysql_query($query) OR die("Invalid query: " . mysql_error());
if (mysql_num_rows($result) > 0) {
# Get current data
$user_data = mysql_fetch_assoc($result);
# Get the relevant responder ID
$attached_responder_id = $user_data['ResponderID'];
# Update array based on any provided data
if ((!(empty($safe['FIRST']))) && ($safe['FIRST'] != "")) {
$user_data['FirstName'] = $safe['FIRST'];
}
if ((!(empty($safe['LAST']))) && ($safe['LAST'] != "")) {
$user_data['LastName'] = $safe['LAST'];
}
if ((!(empty($safe['IP']))) && ($safe['IP'] != "")) {
$user_data['IP_Addy'] = $safe['IP'];
}
# Is there any custom data?
$query = "SELECT * FROM InfResp_customfields WHERE (email_attached= '" . $safe['EMAIL'] . "') AND resp_attached IN (". $resp_list .")";
# echo $query . "<br>\n";
$custom_result = mysql_query($query) OR die("Invalid query: " . mysql_error());
if (mysql_num_rows($custom_result) > 0) {
# Yep, get it.
$custom_fields = mysql_fetch_assoc($custom_result);
$got_custom_fields = TRUE;
# Delete the current custom fields?
if ($passed['DEL'] == TRUE) {
if ($passed['ONLYDEL'] == TRUE) {
$query = "DELETE FROM InfResp_customfields WHERE (email_attached= '" . $safe['EMAIL'] . "') AND resp_attached IN (". $resp_list .")";
# echo $query . "<br>\n";
}
else {
$query = "DELETE FROM InfResp_customfields WHERE email_attached = '" . $safe['EMAIL'] . "' AND resp_attached = '" . $attached_responder_id . "'";
# echo $query . "<br>\n";
}
$custom_delete = mysql_query($query) OR die("Invalid query: " . mysql_error());
}
}
# Delete old responder info?
if ($passed['DEL'] == TRUE) {
if ($passed['ONLYDEL'] == TRUE) {
$query = "DELETE FROM InfResp_subscribers WHERE (EmailAddress = '" . $safe['EMAIL'] . "') AND ResponderID IN (". $resp_list .")";
}
else {
$query = "DELETE FROM InfResp_subscribers WHERE EmailAddress = '" . $safe['EMAIL'] . "' AND ResponderID = '" . $attached_responder_id . "'";
}
$delete_result = mysql_query($query) OR die("Invalid query: " . mysql_error());
}
}
else {
# Make the data array
$user_data['SentMsgs'] = '';
$user_data['EmailAddress'] = $safe['EMAIL'];
$user_data['TimeJoined'] = time();
$user_data['Real_TimeJoined'] = time();
$user_data['CanReceiveHTML'] = '1';
$user_data['LastActivity'] = time();
$user_data['FirstName'] = $safe['FIRST'];
$user_data['LastName'] = $safe['LAST'];
$user_data['IP_Addy'] = $safe['IP'];
$user_data['ReferralSource'] = 'Added w/ Move Subscriber';
$user_data['UniqueCode'] = generate_unique_code();
$user_data['Confirmed'] = '1';
}
# Check for existance in new responder.
$query = "SELECT * FROM InfResp_subscribers WHERE EmailAddress = '" . $safe['EMAIL'] . "' AND ResponderID = '" . $passed['MOVE_TO'] . "'";
# echo $query . "<br>\n";
$result = mysql_query($query) OR die("Invalid query: " . mysql_error());
if (mysql_num_rows($result) > 0) {
# Update existing data
$query = "UPDATE InfResp_subscribers SET SentMsgs = '', TimeJoined = '" . $user_data['TimeJoined'] . "', Real_TimeJoined = '" . $user_data['Real_TimeJoined'] . "', LastActivity = '" . $user_data['LastActivity'] . "', FirstName = '" . $user_data['FirstName'] . "', LastName = '" . $user_data['LastName'] . "', IP_Addy = '" . $user_data['IP_Addy'] . "', ReferralSource = '" . $user_data['ReferralSource'] . "', Confirmed = '" . $user_data['Confirmed'] . "' WHERE EmailAddress = '" . $safe['EMAIL'] . "' AND ResponderID = '" . $passed['MOVE_TO'] . "'";
# echo $query . "<br>\n";
$result = mysql_query($query) OR die("Invalid query: " . mysql_error());
}
else {
# Make a new entry?
if ($passed['ONLYDEL'] != TRUE) {
$insert_values = "'".$passed['MOVE_TO']."','".$user_data['SentMsgs']."','".$user_data['EmailAddress']."','".$user_data['TimeJoined']."','".$user_data['Real_TimeJoined']."','".$user_data['CanReceiveHTML']."','".$user_data['LastActivity']."','".$user_data['FirstName']."','".$user_data['LastName']."','".$user_data['IP_Addy']."','".$user_data['ReferralSource']."','".$user_data['UniqueCode']."','".$user_data['Confirmed']."'";
$query = "INSERT INTO InfResp_subscribers (ResponderID,SentMsgs,EmailAddress,TimeJoined,Real_TimeJoined,CanReceiveHTML,LastActivity,FirstName,LastName,IP_Addy,ReferralSource,UniqueCode,Confirmed) VALUES ($insert_values)";
# echo $query . "<br>\n";
$result = mysql_query($query) OR die("Invalid query: " . mysql_error());
$subscriber_id = mysql_insert_id();
# Insert any custom field data
if (($got_custom_fields == TRUE) && ($subscriber_id) && ($subscriber_id != NULL) && ($subscriber_id != "") && ($subscriber_id != 0)) {
$fieldstr = "";
$valuestr = "";
$custom_fields['user_attached'] = $subscriber_id;
$custom_fields['resp_attached'] = $passed['MOVE_TO'];
foreach ($custom_fields as $key => $value) {
if ($key != "fieldID") {
$fieldstr .= $key.",";
$valuestr .= "'".$value."',";
}
}
$fieldstr = trim((trim($fieldstr)), ",");
$valuestr = trim((trim($valuestr)), ",");
$query = "INSERT INTO InfResp_customfields ($fieldstr) VALUES($valuestr)";
# echo $query . "<br>\n";
$custom_result = mysql_query($query) or die("Invalid query: " . mysql_error());
}
}
}
}
DB_disconnect();
?>