2 /*****************************
3 * SQLite database tool *
6 *****************************/
8 // This library is GPL.
10 include('../../../config.php');
12 include($DIR_LIBS . 'PLUGINADMIN.php');
14 // create the admin area page
15 $pa = new PluginAdmin('SQLite');
18 $pluginUrl=$p->getAdminURL();
21 // check if superadmin is logged in
22 if (!($member->isLoggedIn() && $member->isAdmin()))
24 echo '<p>' . _ERROR_DISALLOWED . '</p>';
30 if (requestVar('SQLiteCommand') && (!$manager->checkTicket())){
31 echo '<p>' . _ERROR_BADTICKET . '</p>';
35 $ticket=$manager->addTicketToUrl('');
36 $ticket=substr($ticket,strpos($ticket,'ticket=')+7);
38 ?><script type="text/javascript">
41 return document.getElementById(id);
47 echo '<h2>'.$p->translated('SQLite management')."</h2>\n";
50 switch(requestVar('SQLiteCommand')){
52 nucleus_mysql_query('VACUUM');
53 $infostr='VACUUM was done.';
55 case 'integrity_check':
56 $res=nucleus_mysql_query('PRAGMA integrity_check');
57 $infostr='Integrity check result:'."<br />\n";
58 while ($a=nucleus_mysql_fetch_array($res)) $infostr.=$a[0]."<br />\n";
61 $pluginfile=requestVar('plugin');
62 $query='SELECT COUNT(*) as result FROM `'.sql_table('plugin').'` WHERE pfile="'.addslashes($pluginfile).'"';
63 if (!quickQuery($query)) {
64 $infostr="No such plugin!";
67 if ($p->modify_plugin($pluginfile)) {
68 $infostr=$p->translated('The plugin, ').$pluginfile.$p->translated(' was checked and modified (if modification required)');
72 // Modification failed. Show the lines that must be modified
74 array_push($phpfiles,$DIR_PLUGINS.$pluginfile.'.php');
75 $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3));
76 $p->seekPhpFiles($admindir,$phpfiles);
77 $infostr=$p->translated('Please modify the PHP files').": <br />\n";
78 foreach ($phpfiles as $file) $infostr.=$p->show_Lines($file);
81 $infostr='<table><tr><th>'.'Query'.
82 ' (-><a href="javascript:Copy this query" onclick="
83 var t=$(\'QueryShown\').innerHTML+\'\';
84 $(\'ExecQuery\').value=t.replace(/^\s+|\s+$/g,\'\');
87 "</th></td><tr><td id=\"QueryShown\">\n".htmlspecialchars($query=requestVar('query'))."</td></tr></table><br />\n";
88 if (requestVar('confirm')!='confirmed'){
89 $infostr=$p->translated('Please check the "I am sure." checkbox to execute query').$infostr;
93 $res=nucleus_mysql_query($query);
94 $errorstr=ob_get_contents();
97 $infostr.=nucleus_mysql_error()."<br />\n";
98 if (preg_match('/sqlite_query\(\):([^<]*)in <b>/i',$errorstr,$matches)) $infostr.=$matches[1];
101 if (preg_match('/ OFFSET ([0-9]+)$/i',$query,$matches)) $offset=$matches[1];
104 // Get resut into an array
105 $resulttable=array();
108 while ($a=nucleus_mysql_fetch_array($res,SQLITE_ASSOC)) {
109 if ($columnnum<count($a)) {
111 foreach ($a as $key=>$value) $columnname[$i++]=$key;
112 $columnnum=count($a);
115 foreach ($a as $key=>$value) $templine[$key]=$value;
116 array_push($resulttable,$templine);
119 // Create table HTML from the array
120 $infostr.="<table><tr>";
121 for ($i=0;$i<$columnnum;$i++) $infostr.="<th>".$columnname[$i]."</th>";
123 foreach ($resulttable as $templine) {
125 for ($i=0;$i<$columnnum;$i++) {
126 $value=(string)$templine[$columnname[$i]];
127 if (50<strlen($value)) {
128 $value='<span id="sqliteobj'.$idnum.'"><a href="" title="'.'Click this to show all'.'" onclick="'.
129 '$(\'sqliteobj'.$idnum.'\').innerHTML='.
130 '$(\'sqliteobj'.$idnum.'-2\').innerHTML;'.
131 'return false;">'.htmlspecialchars(substr($value,0,50)).".....</a></span>\n".
132 '<span style="DISPLAY:none;" id="sqliteobj'.$idnum.'-2">'.htmlspecialchars($value)."</span>\n";
134 } else $value=htmlspecialchars($value);
135 switch(requestVar('option')){
136 case 'showalltables':
137 if ($columnname[$i]!='name') break;
138 $query="SELECT * FROM '$value' LIMIT 10";
139 $value='<a href="'.htmlspecialchars($pluginUrl).
140 '?SQLiteCommand=QUERY&confirm=confirmed&option=showtable&ticket='.$ticket.
141 '&query='.htmlspecialchars($query).'">'.
146 $value=preg_replace('/\\n$/','',$value);
147 $value=str_replace("\n","<br />\n",$value);
148 $infostr.="<td>".$value."</td>";
153 $infostr.="</table>\n";
154 switch(requestVar('option')){
156 $query=requestVar('query');
157 $offset=(int)$offset;
158 $query=preg_replace('/ OFFSET ([0-9]+)$/i','',$query)." OFFSET $offset";
159 $res=nucleus_mysql_query($query);
160 if (!nucleus_mysql_fetch_array($res)) break;
162 <form method="POST" action="'.htmlspecialchars($pluginUrl).'">
163 <input type="hidden" name="SQLiteCommand" value="QUERY">
164 <input type="hidden" name="confirm" value="confirmed">
165 <input type="hidden" name="ticket" value="'.$ticket.'">
166 <input type="hidden" name="query" value="'.htmlspecialchars($query).'">
167 <input type="hidden" name="option" value="showtable">
168 <input type="submit" value="More">
177 echo $p->translated('PHP version: ').phpversion()."<br />\n";
178 if ($res = nucleus_mysql_query('SELECT sqlite_version();')) $ret = nucleus_mysql_fetch_array($res);
179 if (!$ret) $SQLiteVersion='?.?.?';
180 else if (!($SQLiteVersion=$ret[0])) $SQLiteVersion='?.?.?';
181 echo $p->translated('SQLite DB version: ').$SQLiteVersion."<br />\n";;
182 echo $p->translated('SQLite wrapper version: ').$SQLITECONF['VERSION']."<br />\n";
183 echo $p->translated('SQLite DB file size: ').filesize($SQLITECONF['DBFILENAME'])." bytes<br />\n";
186 ?><table><tr><th><?php echo $p->translated('Tools'); ?></th><th><?php echo $p->translated('Execute SQL Query'); ?></th></tr>
188 <form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
189 <input type="hidden" name="SQLiteCommand" value="VACUUM">
190 <input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
191 <input type="submit" value="<?php echo $p->translated('VACUUM'); ?>">
193 <form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
194 <input type="hidden" name="SQLiteCommand" value="integrity_check">
195 <input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
196 <input type="submit" value="<?php echo $p->translated('Integrity Check'); ?>">
198 <form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
199 <select name="plugin">
201 $res=nucleus_mysql_query('SELECT pfile FROM `'.sql_table('plugin').'`');
202 while($result=nucleus_mysql_fetch_row($res)) {
203 if (requestVar('plugin')==$result[0]) echo '<option selected value="'.$result[0].'">'.$result[0]."</option>\n";
204 else echo '<option value="'.$result[0].'">'.$result[0]."</option>\n";
208 <input type="hidden" name="SQLiteCommand" value="plugin_check">
209 <input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
210 <input type="submit" value="<?php echo $p->translated('Check plugin'); ?>">
213 if ('yes'==$p->getOption('allowsql')) {
214 ?><form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
215 <input type="hidden" name="SQLiteCommand" value="QUERY">
216 <input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
217 <input type="hidden" name="confirm" value="confirmed">
218 <input type="hidden" name="query" value="SELECT name, sqlite_table_structure(name) as table_structure FROM sqlite_master WHERE type='table'">
219 <input type="hidden" name="option" value="showalltables">
220 <input type="submit" value="<?php echo $p->translated('Show all tables'); ?>">
225 if ('yes'!=$p->getOption('allowsql')) echo $p->translated('Query not allowed. To use it, change the plugin option.');
227 ?><form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
228 <input type="hidden" name="SQLiteCommand" value="QUERY">
229 <input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
230 <textarea name="query" id="ExecQuery" cols="50" rows="10"></textarea><br />
231 <input type="submit" value="<?php echo $p->translated('Execute'); ?>">
232 <input type="checkbox" name="confirm" value="confirmed"><?php echo $p->translated('I am sure.'); ?>
239 if ($infostr) echo "<hr />\n".$infostr;