-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
bouncerule.php
99 lines (90 loc) · 4.27 KB
/
bouncerule.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
<?php
require_once dirname(__FILE__).'/accesscheck.php';
if (isset($_GET['id'])) {
$hash = '#'.sprintf('%d', $_GET['id']);
$id = sprintf('%d', $_GET['id']);
} else {
$hash = '';
$id = 0;
}
if (isset($_GET['action']) && $_GET['action'] == 'next') {
if (isset($_GET['del'])) {
Sql_Query(sprintf('delete from %s where id = %d', $GLOBALS['tables']['bounceregex'], $_GET['del']));
} elseif (isset($_GET['activate'])) {
Sql_Query(sprintf('update %s set status = "active" where id = %d', $GLOBALS['tables']['bounceregex'],
$_GET['activate']));
} else {
Redirect('bouncerules');
}
$next = Sql_Fetch_Row_Query(sprintf('select id from %s where status = "candidate"',
$GLOBALS['tables']['bounceregex']));
if (!empty($next[0])) {
Redirect('bouncerule&id='.$next[0]);
} else {
$_SESSION['action_result'] = s('No more candidate rules');
Redirect('bouncerules');
}
}
if (isset($_POST['save']) && $_POST['save']) {
Sql_Query(sprintf('update %s set regex = "%s", regexhash = "%s", action="%s", comment="%s",status = "%s" where id= %d',
$GLOBALS['tables']['bounceregex'], trim($_POST['regex']), md5(trim($_POST['regex'])), sql_escape($_POST['action']),
sql_escape($_POST['comment']), sql_escape($_POST['status']), $_GET['id']), 1);
$num = Sql_Affected_Rows();
if ($num < 0) {
echo $GLOBALS['I18N']->get('Updating the regular expression of this rule caused an Sql conflict<br/>This is probably because there is already a rule like that. Do you want to delete this rule instead?');
echo '<p>'.PageLink2('bouncerules&del='.$id, $GLOBALS['I18N']->get('Yes')).' ';
echo PageLink2('bouncerules', $GLOBALS['I18N']->get('No')).'</p>';
return;
}
Redirect('bouncerules'.$hash);
}
echo '<p>'.PageLinkButton('bouncerules'.$hash, $GLOBALS['I18N']->get('back to list of bounce rules')).'</p>';
$data = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',
$GLOBALS['tables']['bounceregex'], $id));
echo '<div class="actions">';
echo PageLinkButton('bouncerule', s('delete and next'), 'del='.$id.'&action=next', '',
s('delete this rule and go to the next candidate'));
echo PageLinkButton('bouncerule', s('activate and next'), 'activate='.$id.'&action=next', '',
s('activate this rule and go to the next candidate'));
echo '</div>';
echo formStart();
echo '<table>';
printf('<tr><td colspan="2">%s</td></tr><tr><td colspan="2"><input type=text name="regex" size=60 value="%s"></td></tr>',
$GLOBALS['I18N']->get('Regular Expression'), htmlspecialchars($data['regex']));
printf('<tr><td>%s</td><td>%s</td></tr>',
$GLOBALS['I18N']->get('Created By'), adminName($data['admin']));
printf('<tr><td>%s</td><td><select name="action">', $GLOBALS['I18N']->get('Action'));
foreach ($GLOBALS['bounceruleactions'] as $action => $desc) {
printf('<option value="%s" %s>%s</option>', $action, $data['action'] == $action ? 'selected' : '', $desc);
}
echo '</select></td></tr>';
printf('<tr><td>%s</td><td><select name="status">', $GLOBALS['I18N']->get('Status'));
printf('<option value="none">[%s]</option>', $GLOBALS['I18N']->get('Select Status'));
foreach (array('active', 'candidate') as $type) {
printf('<option value="%s" %s>%s</option>', $type, $data['status'] == $type ? 'selected' : '',
$GLOBALS['I18N']->get($type));
}
echo '</select></td></tr>';
printf('<tr><td colspan=2>%s</td></tr><tr><td colspan=2>
<textarea name="comment" rows=10 cols=65>%s</textarea></td></tr>',
$GLOBALS['I18N']->get('Memo for this rule'), htmlspecialchars($data['comment']));
echo '<tr><td colspan=2><input type=submit name="save" value="'.$GLOBALS['I18N']->get('Save Changes').'"></td></tr>';
echo '</table></form>';
$req = Sql_Query(sprintf('select * from %s where regex = %d', $GLOBALS['tables']['bounceregex_bounce'], $_GET['id']));
$num = Sql_affected_Rows();
if ($num) {
echo '<p>'.$GLOBALS['I18N']->get('related bounces').'</p><p>';
} else {
echo '<p>'.$GLOBALS['I18N']->get('no related bounces found').'</p>';
}
$c = 0;
while ($row = Sql_Fetch_Array($req)) {
echo PageLink2('bounce&id='.$row['bounce'], $row['bounce']).' ';
++$c;
if ($c > 100) {
break;
}
}
if ($c < $num) {
printf(' '.$GLOBALS['I18N']->get('and more, %d in total'), $num);
}