forked from splitbrain/dokuwiki-plugin-data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
112 lines (88 loc) · 3.44 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
<?php
/**
* DokuWiki Plugin data (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <gohr@cosmocode.de>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
require_once(DOKU_PLUGIN.'admin.php');
class admin_plugin_data extends DokuWiki_Admin_Plugin {
/**
* will hold the data helper plugin
*/
var $dthlp = null;
/**
* Constructor. Load helper plugin
*/
function admin_plugin_data(){
$this->dthlp =& plugin_load('helper', 'data');
}
function getMenuSort() { return 501; }
function forAdminOnly() { return true; }
function handle() {
if(!is_array($_REQUEST['d']) || !checkSecurityToken()) return;
$sqlite = $this->dthlp->_getDB();
if(!$sqlite) return false;
$sqlite->query("BEGIN TRANSACTION");
$sqlite->query("DELETE FROM aliases");
foreach($_REQUEST['d'] as $row){
$row = array_map('trim',$row);
$row['name'] = utf8_strtolower($row['name']);
$row['name'] = rtrim($row['name'],'s');
if(!$row['name']) continue;
$sqlite->query("INSERT INTO aliases (name, type, prefix, postfix, enum)
VALUES (?,?,?,?,?)",$row);
}
$sqlite->query("COMMIT TRANSACTION");
}
function html() {
$sqlite = $this->dthlp->_getDB();
if(!$sqlite) return false;
echo $this->locale_xhtml('admin_intro');
$sql = "SELECT * FROM aliases ORDER BY name";
$res = $sqlite->query($sql);
$rows = $sqlite->res2arr($res);
$form = new Doku_Form(array('method'=>'post'));
$form->addHidden('page','data');
$form->addElement(
'<table class="inline">'.
'<tr>'.
'<th>'.$this->getLang('name').'</th>'.
'<th>'.$this->getLang('type').'</th>'.
'<th>'.$this->getLang('prefix').'</th>'.
'<th>'.$this->getLang('postfix').'</th>'.
'<th>'.$this->getLang('enum').'</th>'.
'</tr>'
);
// add empty row for adding a new entry
$rows[] = array('name'=>'','type'=>'','prefix'=>'','postfix'=>'','enum'=>'');
$cur = 0;
foreach($rows as $row){
$form->addElement('<tr>');
$form->addElement('<td>');
$form->addElement(form_makeTextField('d['.$cur.'][name]',$row['name'],''));
$form->addElement('</td>');
$form->addElement('<td>');
$form->addElement(form_makeMenuField('d['.$cur.'][type]',
array('','page','title','mail','url', 'dt'),$row['type'],''));
$form->addElement('</td>');
$form->addElement('<td>');
$form->addElement(form_makeTextField('d['.$cur.'][prefix]',$row['prefix'],''));
$form->addElement('</td>');
$form->addElement('<td>');
$form->addElement(form_makeTextField('d['.$cur.'][postfix]',$row['postfix'],''));
$form->addElement('</td>');
$form->addElement('<td>');
$form->addElement(form_makeTextField('d['.$cur.'][enum]',$row['enum'],''));
$form->addElement('</td>');
$form->addElement('</tr>');
$cur++;
}
$form->addElement('</table>');
$form->addElement(form_makeButton('submit','admin',$this->getLang('submit')));
$form->printForm();
}
}
// vim:ts=4:sw=4:et:enc=utf-8: