forked from gkrid/dokuwiki-plugin-approve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
165 lines (145 loc) · 5.51 KB
/
admin.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
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
<?php
/**
* DokuWiki Plugin watchcycle (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Szymon Olewniczak <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
class admin_plugin_approve extends DokuWiki_Admin_Plugin
{
/**
* @return int sort number in admin menu
*/
public function getMenuSort()
{
return 1;
}
/**
* Should carry out any processing required by the plugin.
*/
public function handle()
{
global $ID;
/* @var Input */
global $INPUT;
try {
/** @var \helper_plugin_approve_db $db_helper */
$db_helper = plugin_load('helper', 'approve_db');
$sqlite = $db_helper->getDB();
} catch (Exception $e) {
msg($e->getMessage(), -1);
return;
}
/** @var helper_plugin_approve $helper */
$helper = plugin_load('helper', 'approve');
if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) {
$assignment = $INPUT->arr('assignment');
//insert empty string as NULL
if ($INPUT->str('action') === 'delete') {
$sqlite->query('DELETE FROM maintainer WHERE id=?', $assignment['id']);
$helper->updatePagesAssignments($sqlite);
} else if ($INPUT->str('action') === 'add' && !blank($assignment['assign'])) {
$data = [
'namespace' => $assignment['assign']
];
if (!blank($assignment['approver'])) {
$data['approver'] = $assignment['approver'];
} else if (!blank($assignment['approver_fb'])) {
$data['approver'] = $assignment['approver_fb'];
}
$sqlite->storeEntry('maintainer', $data);
$helper->updatePagesAssignments($sqlite);
}
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'approve'), true, '&'));
}
}
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html()
{
global $ID;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;
try {
/** @var \helper_plugin_approve_db $db_helper */
$db_helper = plugin_load('helper', 'approve_db');
$sqlite = $db_helper->getDB();
} catch (Exception $e) {
msg($e->getMessage(), -1);
return;
}
$res = $sqlite->query('SELECT * FROM maintainer ORDER BY namespace');
$assignments = $sqlite->res2arr($res);
echo $this->locale_xhtml('assignments_intro');
echo '<form action="' . wl($ID) . '" action="post">';
echo '<input type="hidden" name="do" value="admin" />';
echo '<input type="hidden" name="page" value="approve" />';
echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
echo '<table class="inline">';
// header
echo '<tr>';
echo '<th>'.$this->getLang('admin h_assignment_namespace').'</th>';
echo '<th>'.$this->getLang('admin h_assignment_approver').'</th>';
echo '<th></th>';
echo '</tr>';
// existing assignments
foreach($assignments as $assignment) {
$id = $assignment['id'];
$namespace = $assignment['namespace'];
$approver = $assignment['approver'] ? $assignment['approver'] : '---';
$link = wl(
$ID, array(
'do' => 'admin',
'page' => 'approve',
'action' => 'delete',
'sectok' => getSecurityToken(),
'assignment[id]' => $id
)
);
echo '<tr>';
echo '<td>' . hsc($namespace) . '</td>';
$user = $auth->getUserData($approver);
if ($user) {
echo '<td>' . hsc($user['name']) . '</td>';
} else {
echo '<td>' . hsc($approver) . '</td>';
}
echo '<td><a href="' . $link . '">'.$this->getLang('admin btn_delete').'</a></td>';
echo '</tr>';
}
// new assignment form
echo '<tr>';
echo '<td><input type="text" name="assignment[assign]" /></td>';
echo '<td>';
if ($auth->canDo('getUsers')) {
echo '<select name="assignment[approver]">';
echo '<option value="">---</option>';
if ($auth->canDo('getGroups')) {
foreach($auth->retrieveGroups() as $group) {
echo '<option value="@' . hsc($group) . '">' . '@' . hsc($group) . '</option>';
}
}
foreach($auth->retrieveUsers() as $login => $data) {
echo '<option value="' . hsc($login) . '">' . hsc($data['name']) . '</option>';
}
echo '</select>';
// in case your auth plugin can do groups, but not list them (like the default one),
// leave a text field as backup
if (!$auth->canDo('getGroups')) {
echo '<input name="assignment[approver_fb]" id="plugin__approve_group_input">';
}
} else {
echo '<input name="assignment[approver]">';
}
echo '</td>';
echo '<td><button type="submit" name="action" value="add">'.$this->getLang('admin btn_add').'</button></td>';
echo '</tr>';
echo '</table>';
}
}
// vim:ts=4:sw=4:et: