-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrem.php
266 lines (251 loc) · 8.51 KB
/
rem.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
<?php
/* ListMail (c) 2005 Dean Wiebe <[email protected]>
You may not modify or distribute the program without express permission from the author.
Files are overwritten when updates are released, so it's not a good idea anyway. */
include("./config.php");
include("./admin.php");
// set up variables
$delete = $dodel; // backwards compat for new varname. 03-11-2005
$error = '';
// reserve $u $c and $x for future custom custom fields
if ($u) {
$x = '';
$email = '';
if (strpos($u, ',') > 0) {
list($c, $u) = explode(',', $u);
} else {
$u = addslashes($u);
$c = addslashes($c);
}
$cmd = "uid = '$u' and (cnf = '1' OR cnf = '0')";
}
if ($x) {
if (strpos($x, ',') > 0) {
list($c, $list, $email) = explode(',', $x);
$c = addslashes($c);
$list = addslashes($list);
$email = addslashes($email);
} else {
$c = addslashes($x);
$list = addslashes($l);
$email = addslashes($e);
}
$cmd = "list = '$list' and email like '$email' and (cnf = '1' OR cnf = '0')"; //Safe?
//$cmd = "list = '$list' and email = '$email' and (cnf = '1' OR cnf = '0')"; //exact match email
}
if ($r) {
if (strpos($r, ';') > 0 && !$email) {
list($r, $ru) = explode(';', $r);
if (strpos($ru, ',') > 0)
list($ru) = explode(',', $ru);
list($email) = mysql_fetch_row(mysql_query("select email from $utable where uid = '" . addslashes($ru) . "';"));
} elseif (!$email) {
exit('error, no email');
}
$cmd = '(';
$lists = explode(',', $r);
while (list($k, $v) = each($lists)) {
if ($k > 0)
$cmd .= ' or ';
$cmd .= "list = '$v'";
}
reset($lists);
$email = addslashes($email);
$cmd .= ") and email like '$email' and (cnf = '1' OR cnf = '0');";
}
if (!$u && !$x && !$r) {
$email = addslashes($email);
$list = addslashes($list);
$cmd = "list = '$list' and email like '$email' and (cnf = '1' OR cnf = '0')";
}
if ($lists && !$list)
$list = addslashes($lists[0]);
if (($c && !is_numeric($c)) || ($list && !is_numeric($list)))
$error = 'data_bad';
// echo "email=$email list=$list<br>";
if (!$u && !$email)
$error = 'email_req';
if ($email && !valid_email(strtolower($email)))
$error = 'email_bad';
// error check
if (!$error) {
$ucmd = "select id,list,email from $utable where $cmd";
//Check if list is remote
$lcmd = "select title,remote,remotedb,remoteuser,remotepwd,remotehost from $ltable where listnum = '$list'";
$lrow = @mysql_query($lcmd, $link) or die('admin-6-' . mysql_error());
list($ltitle, $remote, $remotedb, $remoteuser, $remotepwd, $remotehost) = @mysql_fetch_row($lrow);
if ($remote) {
if (!$dbh) {
try {
$pdo_db = 'mysql:dbname=' . $remotedb . ';host=' . $remotehost;
$dbh = new PDO($pdo_db, $remoteuser, $remotepwd);
} catch (PDOException $e) {
die('rem-1-' . $e->getMessage());
}
}
$dbh_query = $dbh->query($ucmd);
if ($dbh_query->rowCount() > 0) {
list($cid, $list, $email) = $dbh_query->fetch();
} else {
$error = 'rem_nf';
}
} else {
$rows = mysql_query($ucmd) or die(mysql_error());
if (@mysql_num_rows($rows) > 0) {
list($cid, $list, $email) = @mysql_fetch_row($rows);
} else {
$error = 'rem_nf';
}
}
}
// echo "ORIGvars: \$c = $c, \$list = $list, \$email = $email, \$u = $u<br>";
// echo "FINALvars: \$cid = $cid, \$list = $list, \$email = $email<br>";
$chid = listopts('chtmlid', $list);
$eid = listopts('errorid', $list);
if (!$eid)
$eid = '1';
if (!$chid)
$chid = '1';
if (!$error) {
if ($c) {
// echo "checking \$c: ";
$drow = mysql_query("select data3,data4 from $dtable where id = '" . addslashes($c) . "';");
if (@mysql_num_rows($drow) > 0) {
list($data3, $data4) = mysql_fetch_row($drow);
if ($data3 == '1')
$delete = 1;
if ($data4) {
// multi list
if (strpos(' ' . $data4, '*') > 0) {
// put all lists in array
$rows = mysql_query("select listnum from $ltable where 1 order by listnum");
while (list($ln) = mysql_fetch_row($rows)) {
if ($ln <> $list)
$lists[] = $ln;
}
} else {
// get lists from string
$lists = explode(',', $data4);
}
}
}
} else {
// !$c, single list only
// no options: no one-click, no multi list
}
$lists[] = $list;
// print_r($lists);
// loop code, if dodel delete, if not, confirm.
// provide ability to output listnames with !code in chtml?
// create sql query
$cmd = "select id,uid,list,fname from $utable where email like '$email' and (cnf = '1' OR cnf = '0') and (";
while (list($k, $l) = each($lists)) {
if ($k > 0)
$cmd .= ' or ';
$cmd .= "list = '$l'";
}
$cmd .= ')';
if ($remote) {
if(!$dbh){
try {
$pdo_db = 'mysql:dbname=' . $remotedb . ';host=' . $remotehost;
$dbh = new PDO($pdo_db, $remoteuser, $remotepwd);
} catch (PDOException $e) {
die('rem-2-' . $e->getMessage());
}
}
$dbh_query = $dbh->prepare($cmd);
$dbh_query->execute();
if ($dbh_query->rowCount() > 0) {
$rows = $dbh_query->fetchAll();
} else {
$error = 'rem_nf';
}
} else {
$temprows = mysql_query($cmd);
$rows = array();
while ($temprow = mysql_fetch_array($temprows)) {
$rows[] = $temprow; //echo $temprow['id'].'<br>';
}
}
$delcmd = array();
$x = 0;
if ($r)
$r .= ';';
foreach ($rows as $row) {
list($id,$uniqid,$ln,$fname) = $row;
if ($delete) {
$narr = getnotifs($ln);
if ($narr[1] == '1')
sendnotif('remove', $id);
$lrow = mysql_query("select listopts from $ltable where listnum = '$ln'");
list($listopts) = mysql_fetch_row($lrow);
$listopts = explode(';', $listopts);
if ($listopts[4] == '1')
remlists($email, $ln, 4);
if ($listopts[5] == '1')
addlists($email, $ln, 5);
if ($listopts[1] == 1) {
$cmd = "update $utable set cnf = '2' where id = '$id';";
if ($remote) {
if (!$dbh) {
try {
$pdo_db = 'mysql:dbname=' . $remotedb . ';host=' . $remotehost;
$dbh = new PDO($pdo_db, $remoteuser, $remotepwd);
} catch (PDOException $e) {
die('rem-2-' . $e->getMessage());
}
}
$dbh_query = $dbh->prepare($cmd);
$dbh_query->execute();
} else {
mysql_query($cmd);
}
} else {
$delcmd[] = "delete from $utable where id = '$id';";
}
}
}
// if multi list rem, add uid
if ($r) {
if ($x > 0)
$r .= ',';
$r .= $uniqid;
}
$x++;
}
if ($error) {
$errmsg = emsg($error, $eid) . '<br>';
$data = chtml('remerror', $chid);
$data = str_replace('!data', $errmsg, $data);
if (strpos(' ' . $data, 'URL:') == '1')
header('Location: ' . str_replace('URL:', '', $data));
else
echo $data;
exit;
} else {
// echo "no error, show page";
if ($delete) {
// remove xtra
if (file_exists('./remove-xtra.php')) {
include('./remove-xtra.php');
mysql_select_db($sqldb, $link);
}
// success!
$data = chtml('remsuccess', $chid);
list($data) = processmsg($cid, $data, '', '', '1');
} else {
// confirm
$data = chtml('remove', $chid);
list($data) = processmsg2($id, $uniqid, $ln, $fname, '', $email, '', '', '', '', '', '', '', '', '', '', '', '', $data, '', '', '0', '', $c, $r);
}
}
if ($delcmd)
while (list($k, $v) = each($delcmd))
mysql_query($v);
if (strpos(' ' . $data, 'URL:') == '1')
header('Location: ' . str_replace('URL:', '', $data));
else
echo $data;
exit;
?>