-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaverule.php
92 lines (85 loc) · 3.05 KB
/
saverule.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
<?php
###############################################################################
# $Id$
# Creates or modifies a emaillist rule in the 3m database
###############################################################################
require_once dirname(__FILE__).'/common.php';
$redirect_wait = 1; // Number of seconds to wait before redirecting if no error
$isupdate = isset($_POST[ruleid]);
$ruleid = $_POST[ruleid];
// First validate the form
$optionalVals = array("addlist", "notificationlist");
foreach($optionalVals as $reqval){
if(isset($_POST[$reqval])) {
$$reqval = $_POST[$reqval];
} else {
$$reqval = "";
}
}
if(!(isset($_POST["dept"]) && formatYear($_POST["position"]))) {
fatal("Need to specify dept and specify and position!");
} else {
$dept = $_POST["dept"];
$position = $_POST["position"];
}
if (isset($_POST["delete"])) {
// Performing delete.
error_log("Deleting emailrule " . $ruleid);
$sql = "DELETE FROM emailrules ";
$sql .= "WHERE ruleid=" . ((int)$ruleid);
$res =& $mdb2->exec($sql);
if(PEAR::isError($res)) {
error_log($res->getDebugInfo());
fatal("ERROR: Could not delete emailrule: ".$res->getMessage());
}
}
// Validation complete. If this is an update, perform update!
else if ($isupdate) {
error_log("Updating emailrule " . $_POST["ruleid"]);
$sql = "UPDATE emailrules SET dept=" . $mdb2->quote($dept) . ",";
$sql .= " position=" . $mdb2->quote($position) . ",";
$sql .= " addlist=" . $mdb2->quote($addlist) . ",";
$sql .= " notificationlist=" . $mdb2->quote($notificationlist);
$sql .= " WHERE ruleid=" . ((int)$ruleid);
$res =& $mdb2->exec($sql);
if(PEAR::isError($res)) {
error_log($res->getDebugInfo());
fatal("Could not update emailrule: ".$res->getMessage());
}
} else {
error_log("Creating new emailrule.");
$sql = "INSERT INTO emailrules (dept, position, addlist, notificationlist) VALUES (";
$sql .= $mdb2->quote($dept) . ", ";
$sql .= $mdb2->quote($position) . ", ";
$sql .= $mdb2->quote($addlist) . ", ";
$sql .= $mdb2->quote($notificationlist) . ")";
$res =& $mdb2->exec($sql);
if(PEAR::isError($res)) {
error_log($res->getDebugInfo());
fatal("Could not add emailrule: ".$res->getMessage());
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="<?=$redirect_wait?>; url=rules.php">
</head>
<body onload="updateCounter();">
You have successfully modified the email rule. If, instead, you have fucked
it up, e-mail <a href="mailto:[email protected]">[email protected]</a>.<br>
<a href="."> Click here to go back to 3M</a>. <span id="note"></span>
</body>
<script type="text/javascript" language="javascript">
var time =<?=$redirect_wait?>;
var text = "You will automatically be redirected in ";
function updateCounter() {
var s = "second";
if(time != 1) { s += "s"; }
if(time < 0 ) { window.location = "rules.php"; return; }
document.getElementById("note").innerHTML = text + time + " " + s;
time--;
setTimeout("updateCounter()", 1000);
}
</script>
</html>