/
group_sets.php
123 lines (112 loc) · 3.8 KB
/
group_sets.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Users;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\User\Group\GroupSet;
use GroupList;
use Group;
class GroupSets extends DashboardPageController
{
public $category;
public function on_start()
{
parent::on_start();
$this->set('groupSets', GroupSet::getList());
$gl = new GroupList();
$groups = $gl->getResults();
$this->set('groups', $groups);
}
public function add_set()
{
if ($this->token->validate('add_set')) {
$gsName = trim($this->post('gsName'));
if (!$gsName) {
$this->error->add(t("Specify a name for your group set."));
} elseif (preg_match('/[<>{};?"`]/i', $gsName)) {
$this->error->add(t('Invalid characters in group set name.'));
}
if (!$this->error->has()) {
$gs = GroupSet::add($gsName);
if (is_array($_POST['gID'])) {
foreach ($_POST['gID'] as $gID) {
$g = Group::getByID($gID);
if (is_object($g)) {
$gs->addGroup($g);
}
}
}
$this->redirect('dashboard/users/group_sets', 'set_added');
}
} else {
$this->error->add($this->token->getErrorMessage());
}
}
public function set_added()
{
$this->set('success', t('Group set added successfully.'));
}
public function set_deleted()
{
$this->set('success', t('Group set deleted successfully.'));
}
public function set_updated()
{
$this->set('success', t('Group set updated successfully.'));
}
public function update_set()
{
$this->edit($this->post('gsID'));
if ($this->token->validate('update_set')) {
$as = GroupSet::getByID($this->post('gsID'));
if (!is_object($as)) {
$this->error->add(t('Invalid group set.'));
} else {
if (!trim($this->post('gsName'))) {
$this->error->add(t("Specify a name for your group set."));
}
}
$gsName = trim($this->post('gsName'));
if (preg_match('/[<>{};?"`]/i', $gsName)) {
$this->error->add(t('Invalid characters in group set name.'));
}
if (!$this->error->has()) {
$as->updateGroupSetName($gsName);
$as->clearGroups();
if (is_array($this->post('gID'))) {
foreach ($_POST['gID'] as $gID) {
$g = Group::getByID($gID);
if (is_object($g)) {
$as->addGroup($g);
}
}
}
$this->redirect('dashboard/users/group_sets', 'set_updated');
}
} else {
$this->error->add($this->token->getErrorMessage());
}
}
public function delete_set()
{
if ($this->token->validate('delete_set')) {
$gs = GroupSet::getByID($this->post('gsID'));
if (!is_object($gs)) {
$this->error->add(t('Invalid group set.'));
}
if (!$this->error->has()) {
$gs->delete();
$this->redirect('dashboard/users/group_sets', 'set_deleted');
}
} else {
$this->error->add($this->token->getErrorMessage());
}
}
public function edit($gsID = false)
{
$gs = GroupSet::getByID($gsID);
if (is_object($gs)) {
$this->set('set', $gs);
} else {
$this->redirect('/dashboard/users/group_sets');
}
}
}