forked from Graphite-Tattle/Tattle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscription.php
91 lines (78 loc) · 3.26 KB
/
subscription.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
<?
include dirname(__FILE__) . '/inc/init.php';
fAuthorization::requireLoggedIn();
$breadcrumbs[] = array('name' => 'Subscription', 'url' => Subscription::makeURL('list'),'active'=>true);
$action = fRequest::getValid('action',
array('list', 'add', 'edit', 'delete')
);
$sort = fCRUD::getSortColumn(array('name','status','method','state'));
$sort_order = fCRUD::getSortDirection('asc');
$subscription_id = fRequest::get('subscription_id', 'integer');
$check_id = fRequest::get('check_id', 'integer');
$manage_url = $_SERVER['SCRIPT_NAME'];
// --------------------------------- //
if ('delete' == $action) {
try {
$check = new Check($check_id);
$subscription = new Subscription($subscription_id);
if (fRequest::isPost()) {
fRequest::validateCSRFToken(fRequest::get('token'));
$subscription->delete();
fMessaging::create('success', $manage_url,
'The subscription for ' . $check->getName() . ' was successfully deleted');
fURL::redirect($manage_url);
}
} catch (fNotFoundException $e) {
fMessaging::create('error', $manage_url,
'The subscription requested, ' . fHTML::encode($date) . ', could not be found');
fURL::redirect($manage_url);
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/delete_subscription.php';
// --------------------------------- //
} elseif ('edit' == $action) {
try {
$subscription = new Subscription($subscription_id);
$check = new Check($subscription->getCheck_Id());
if (fRequest::isPost()) {
$subscription->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$subscription->store();
fMessaging::create('affected', fURL::get(), $check->getName());
fMessaging::create('success', fURL::get(),
'The subscription to check ' . $check->getName(). ' was successfully updated');
//fURL::redirect($manage_url);
}
} catch (fNotFoundException $e) {
fMessaging::create('error', $manage_url,
'The subscription requested ' . fHTML::encode($check_id) . ' could not be found');
fURL::redirect($manage_url);
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/add_edit_subscription.php';
// --------------------------------- //
} elseif ('add' == $action) {
$subscription = new Subscription();
//Load details of the check we are going to subscribe to
$check = new Check($check_id);
if (fRequest::isPost()) {
try {
$subscription->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$subscription->store();
fMessaging::create('affected',$manage_url , $check->getName());
fMessaging::create('success', $manage_url,
'The subscription to ' . $check->getName() . ' was successfully created');
fURL::redirect($manage_url);
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
}
include VIEW_PATH . '/add_edit_subscription.php';
} else {
$user = new User(fSession::get('user_id'));
$subscriptions = $user->buildSubscriptions();
include VIEW_PATH . '/list_subscriptions.php';
}