This repository has been archived by the owner on Dec 28, 2024. It is now read-only.
forked from cosmocode/sqlite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.php
144 lines (116 loc) · 4.92 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
<?php
/**
* DokuWiki Plugin sqlite (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'admin.php');
class admin_plugin_sqlite extends DokuWiki_Admin_Plugin {
function getInfo() {
return confToHash(dirname(__FILE__).'plugin.info.txt');
}
function getMenuSort() { return 500; }
function forAdminOnly() { return true; }
function handle() {
}
function html() {
global $ID;
echo $this->locale_xhtml('intro');
if($_REQUEST['db'] && checkSecurityToken()){
echo '<h2>'.$this->getLang('db').' '.hsc($_REQUEST['db']).'</h2>';
echo '<div class="level2">';
echo '<ul>';
echo '<li><div class="li"><a href="'.
wl($ID,array('do' => 'admin',
'page' => 'sqlite',
'db' => $_REQUEST['db'],
'sql' => 'SELECT name,sql FROM sqlite_master WHERE type=\'table\' ORDER BY name',
'sectok' => getSecurityToken())).
'">'.$this->getLang('table').'</a></div></li>';
echo '<li><div class="li"><a href="'.
wl($ID,array('do' => 'admin',
'page' => 'sqlite',
'db' => $_REQUEST['db'],
'sql' => 'SELECT name,sql FROM sqlite_master WHERE type=\'index\' ORDER BY name',
'sectok' => getSecurityToken())).
'">'.$this->getLang('index').'</a></div></li>';
echo '</ul>';
$form = new Doku_Form(array('class'=>'sqliteplugin'));
$form->startFieldset('SQL Command');
$form->addHidden('id',$ID);
$form->addHidden('do','admin');
$form->addHidden('page','sqlite');
$form->addHidden('db',$_REQUEST['db']);
$form->addElement('<textarea name="sql" class="edit">'.hsc($_REQUEST['sql']).'</textarea>');
$form->addElement('<input type="submit" class="button" />');
$form->endFieldset();
$form->printForm();
if($_REQUEST['sql']){
$DBI =& plugin_load('helper', 'sqlite');
if(!$DBI->init($_REQUEST['db'],'')) return;
$sql = explode(";",$_REQUEST['sql']);
foreach($sql as $s){
$s = preg_replace('!^\s*--.*$!m', '', $s);
$s = trim($s);
if(!$s) continue;
$res = $DBI->query("$s;");
if ($res === false) continue;
msg($DBI->res2count($res).' affected rows',1);
$result = $DBI->res2arr($res);
if(!count($result)) continue;
echo '<p>';
$ths = array_keys($result[0]);
echo '<table class="inline">';
echo '<tr>';
foreach($ths as $th){
echo '<th>'.hsc($th).'</th>';
}
echo '</tr>';
foreach($result as $row){
echo '<tr>';
$tds = array_values($row);
foreach($tds as $td){
echo '<td>'.hsc($td).'</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</p>';
}
}
echo '</div>';
}
}
function getTOC(){
global $conf;
global $ID;
$toc = array();
$fileextensions = array('sqlite2'=>'.sqlite','sqlite3'=>'.sqlite3');
foreach($fileextensions as $dbformat => $fileextension){
$toc[] = array(
'link' => '',
'title' => $dbformat.':',
'level' => 1,
'type' => 'ul',
);
$dbfiles = glob($conf['metadir'].'/*'.$fileextension);
if(is_array($dbfiles)) foreach($dbfiles as $file){
$db = basename($file,$fileextension);
$toc[] = array(
'link' => wl($ID,array('do'=>'admin','page'=>'sqlite','db'=>$db,'sectok'=>getSecurityToken())),
'title' => $this->getLang('db').' '.$db,
'level' => 2,
'type' => 'ul',
);
}
}
return $toc;
}
}
// vim:ts=4:sw=4:et: