forked from artursudnik/webpagetest-monitor
/
updateAlert.php
60 lines (58 loc) · 1.89 KB
/
updateAlert.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
<?php
require("login/login.php");
include 'monitor.inc';
$folderId = $_REQUEST['folderId'];
// $user_id=getCurrentUserId();
$user_id=getUserIdForFolder('Alert',$folderId);
$id = $_REQUEST['id'];
if ( !$active = $_REQUEST['active'] ){
$active = 0;
};
$label = $_REQUEST['label'];
$description = $_REQUEST['description'];
$emailaddresses= $_REQUEST['emailaddresses'];
$alerton = $_REQUEST['alerton'];
$alertontype = $_REQUEST['alertOnType'];
$alertoncomparator = $_REQUEST['alertOnComparator'];
$alertonvalue = $_REQUEST['alertOnValue'];
$alertthreshold = $_REQUEST['alertThreshold'];
if ( $alertontype == "Response Code"){
$alerton = $_REQUEST['alertOnResponseCode'];
} else if ( $alertontype == "Response Time"){
$alerton = $_REQUEST['alertOnResponseTime'];
} else if ( $alertontype == "Validation Code"){
$alerton = $_REQUEST['alertOnValidationCode'];
}
try
{
if ( $id ){
$alertTable = Doctrine_Core::getTable('Alert');
$result = $alertTable->find($id);
if ( $result ){
echo "Found alert ".$result['Id'];
$alert = $result;
$alert['Active']=$active;
} else {
//TODO: Passed in an Id, but didn't find it. Add error here.
}
}else {
$alert = new Alert();
$alert['Active']= 0;
}
$alert['AlertFolderId'] = $folderId;
$alert['UserId'] = $user_id;
$alert['Label'] = $label;
$alert['Description'] = $description;
$alert['EmailAddresses'] = $emailaddresses;
$alert['AlertOn'] = $alerton;
$alert['AlertOnType']=$alertontype;
$alert['AlertOnComparator']=$alertoncomparator;
$alert['AlertOnValue']=$alertonvalue;
$alert['AlertThreshold']=$alertthreshold;
$alert->save();
} catch (Exception $e) {
error_log("[WPTMonitor] Failed while updating alert: for ".$user_id. " message: " . $e->getMessage());
}
header("Location: listAlerts.php");
exit;
?>