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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
<?php
# Lifter007: TEST
/**
* siteinfo - display information about Stud.IP
*
* @author Ansgar Bockstiegel
* @copyright 2008 Ansgar Bockstiegel
* @license GPL2 or any later version
*/
class SiteinfoController extends StudipController
{
protected $with_session = true;
private $si;
/**
* common tasks for all actions
*/
public function before_filter (&$action, &$args)
{
parent::before_filter($action, $args);
// Siteinfo-Class is defined in models/siteinfo.php
$this->si = new Siteinfo();
$this->populate_ids($args);
$this->add_navigation($action);
if (is_object($GLOBALS['perm']) && $GLOBALS['perm']->have_perm('root')) {
$this->setupSidebar();
} else {
$action = 'show';
}
PageLayout::setTitle(_('Impressum'));
PageLayout::setTabNavigation('/footer/siteinfo');
}
//the first element of the unconsumed trails-path determines the rubric
//the second element defines the page(detail)
//if they are missing the first detail/rubric is the fallback
protected function populate_ids($args)
{
if (isset($args[0]) && is_numeric($args[0])) {
$this->currentrubric = $args[0];
if (isset($args[1]) && is_numeric($args[1])) {
$this->currentdetail = $args[1];
} else {
$this->currentdetail = $this->si->first_detail_id($args[0]);
}
} else {
$this->currentrubric = $this->si->first_rubric_id();
$this->currentdetail = $this->si->first_detail_id();
}
}
protected function add_navigation($action)
{
foreach ($this->si->get_all_rubrics() as $rubric) {
$rubric[1] = language_filter($rubric[1]);
if ($rubric[1] == '') {
$rubric[1] = _('unbenannt');
}
Navigation::addItem('/footer/siteinfo/'.$rubric[0],
new Navigation($rubric[1], $this->url_for('siteinfo/show/'.$rubric[0])));
}
foreach ($this->si->get_all_details() as $detail) {
$detail[2] = language_filter($detail[2]);
if ($detail[2] == '') {
$detail[2] = _('unbenannt');
}
Navigation::addItem('/footer/siteinfo/'.$detail[1].'/'.$detail[0],
new Navigation($detail[2], $this->url_for('siteinfo/show/'.$detail[1].'/'.$detail[0])));
}
if ($action != 'new') {
if ($this->currentdetail > 0) {
Navigation::activateItem('/footer/siteinfo/'.$this->currentrubric.'/'.$this->currentdetail);
} else {
Navigation::activateItem('/footer/siteinfo/'.$this->currentrubric);
}
}
}
protected function setupSidebar()
{
$sidebar = Sidebar::get();
if (!$GLOBALS['rubrics_empty']) {
$actions = new ActionsWidget();
$actions->setTitle(_('Seiten-Aktionen'));
if ($this->currentrubric) {
$actions->addLink(_('Neue Seite anlegen'),
$this->url_for('siteinfo/new/' . $this->currentrubric), Icon::create('add', 'clickable'));
}
if ($this->currentdetail) {
$actions->addLink(_('Seite bearbeiten'),
$this->url_for('siteinfo/edit/' . $this->currentrubric . '/' . $this->currentdetail), Icon::create('edit', 'clickable'));
$actions->addLink(_('Seite löschen'),
$this->url_for('siteinfo/delete/' . $this->currentrubric . '/' . $this->currentdetail), Icon::create('trash', 'clickable'));
}
$sidebar->addWidget($actions);
}
$actions = new ActionsWidget();
$actions->setTitle(_('Rubrik-Aktionen'));
$actions->addLink(_('Neue Rubrik anlegen'),
$this->url_for('siteinfo/new'), Icon::create('add', 'clickable'));
if ($this->currentrubric) {
$actions->addLink(_('Rubrik bearbeiten'),
$this->url_for('siteinfo/edit/' . $this->currentrubric), Icon::create('edit', 'clickable'));
$actions->addLink(_('Rubrik löschen'),
$this->url_for('siteinfo/delete/' . $this->currentrubric), Icon::create('trash', 'clickable'));
}
$sidebar->addWidget($actions);
}
/**
* Display the siteinfo
*/
public function show_action()
{
$this->output = $this->si->get_detail_content_processed($this->currentdetail);
}
public function new_action($givenrubric = null)
{
if ($givenrubric === null) {
Navigation::addItem('/footer/siteinfo/rubric_new',
new AutoNavigation(_('Neue Rubrik'),
$this->url_for('siteinfo/new')));
$this->edit_rubric = true;
} else {
Navigation::addItem('/footer/siteinfo/' . $this->currentrubric . '/detail_new',
new AutoNavigation(_('Neue Seite'),
$this->url_for('siteinfo/new/' . $this->currentrubric)));
$this->rubrics = $this->si->get_all_rubrics();
}
}
public function edit_action($givenrubric = null, $givendetail = null)
{
if (is_numeric($givendetail)) {
$this->rubrics = $this->si->get_all_rubrics();
$this->rubric_id = $this->si->rubric_for_detail($this->currentdetail);
$this->detail_name = $this->si->get_detail_name($this->currentdetail);
$this->content = $this->si->get_detail_content($this->currentdetail);
} else {
$this->edit_rubric = true;
$this->rubric_id = $this->currentrubric;
}
$this->rubric_name = $this->si->rubric_name($this->currentrubric);
}
public function save_action()
{
$detail_name = Request::get('detail_name');
$rubric_name = Request::get('rubric_name');
$content = Request::get('content');
$rubric_id = Request::int('rubric_id');
$detail_id = Request::int('detail_id');
if ($rubric_id) {
if ($detail_id) {
list($rubric, $detail) = $this->si->save('update_detail', compact('rubric_id', 'detail_name', 'content', 'detail_id'));
} else {
if ($content) {
list($rubric, $detail) = $this->si->save('insert_detail', compact('rubric_id', 'detail_name','content'));
} else {
list($rubric, $detail) = $this->si->save('update_rubric', compact('rubric_id', 'rubric_name'));
}
}
} else {
list($rubric, $detail) = $this->si->save('insert_rubric', compact('rubric_name'));
}
$this->redirect('siteinfo/show/' . $rubric . '/' . $detail);
}
public function delete_action($givenrubric = null, $givendetail = null, $execute = false)
{
if ($execute) {
if ($givendetail === 'all') {
$this->si->delete('rubric', $this->currentrubric);
$this->redirect('siteinfo/show/');
} else {
$this->si->delete('detail', $this->currentdetail);
$this->redirect('siteinfo/show/' . $this->currentrubric);
}
} else {
if (is_numeric($givendetail)) {
$this->detail = true;
}
$this->output = $this->si->get_detail_content_processed($this->currentdetail);
}
}
}
|