forked from Graphite-Tattle/Tattle
-
Notifications
You must be signed in to change notification settings - Fork 2
/
groups.php
90 lines (78 loc) · 3.06 KB
/
groups.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
<?php
include 'inc/init.php';
fAuthorization::requireLoggedIn();
fRequest::overrideAction();
$action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete'));
$breadcrumbs[] = array('name' => 'Groups', 'url' => Group::makeURL('list'),'active'=> true);
$group_id = fRequest::get('group_id', 'integer');
if ('delete' == $action) {
if ($group_id == $GLOBALS['DEFAULT_GROUP_ID']) {
fURL::redirect(Group::makeUrl('list'));
} else {
$class_name = 'Group';
try {
$obj = new Group($group_id);
$delete_text = 'Are you sure you want to delete the group : <strong>' . $obj->getName() . '</strong>?';
if (fRequest::isPost()) {
fRequest::validateCSRFToken(fRequest::get('token'));
$obj->delete();
fMessaging::create('success', "/".Group::makeUrl('list'),
'The group "' . $obj->getName() . '" was successfully deleted');
fURL::redirect(Group::makeUrl('list'));
}
} catch (fNotFoundException $e) {
fMessaging::create('error', "/".Group::makeUrl('list'),
'The group requested could not be found');
fURL::redirect(Group::makeUrl('list'));
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/delete.php';
}
// --------------------------------- //
} elseif ('edit' == $action) {
if ($group_id == $GLOBALS['DEFAULT_GROUP_ID']) {
fURL::redirect(Group::makeUrl('list'));
} else {
try {
$group = new Group($group_id);
if (fRequest::isPost()) {
$group->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$group->store();
fMessaging::create('success', "/".Group::makeURL("list"),
'The Group ' . $group->getName(). ' was successfully updated');
fURL::redirect(Group::makeUrl('list'));
}
} catch (fNotFoundException $e) {
fMessaging::create('error', "/".Group::makeUrl('list'),
'The Group requested, ' . fHTML::encode($group_id) . ', could not be found');
fURL::redirect(Group::makeUrl('list'));
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/add_edit_group.php';
}
// --------------------------------- //
} elseif ('add' == $action) {
$group = new Group();
if (fRequest::isPost()) {
try {
$group->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$group->store();
$group_url = fURL::redirect(Group::makeUrl('list'));
fMessaging::create('affected', "/".$group_url, $group->getName());
fMessaging::create('success', "/".$group_url,
'The Group ' . $group->getName() . ' was successfully created');
fURL::redirect($group_url);
echo "";
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
}
include VIEW_PATH . '/add_edit_group.php';
} else {
$groups = Group::findAll();
include VIEW_PATH . '/list_groups.php';
}