• R/O
  • SSH
  • HTTPS

onesqliteadmin: 提交


Commit MetaInfo

修訂1 (tree)
時間2010-03-02 00:25:09
作者mitsugi

Log Message

一番最初のコミット

Change Summary

差異

--- trunk/0.1/index.php (nonexistent)
+++ trunk/0.1/index.php (revision 1)
@@ -0,0 +1,423 @@
1+<?php
2+/*
3+OneSQLiteManager
4+
5+Copyright (c) 2010 Mitsugi Tsutsumi
6+
7+Permission is hereby granted, free of charge, to any person obtaining a copy
8+of this software and associated documentation files (the "Software"), to deal
9+in the Software without restriction, including without limitation the rights
10+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+copies of the Software, and to permit persons to whom the Software is
12+furnished to do so, subject to the following conditions:
13+
14+The above copyright notice and this permission notice shall be included in
15+all copies or substantial portions of the Software.
16+
17+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+THE SOFTWARE.
24+*/
25+
26+//Auth
27+$config["user"]="admin";
28+$config["password"]="pass";
29+
30+//db
31+$config["db"][]="db_admin.db";
32+$config["db"][]="test.db";
33+
34+//i18n
35+$lang="ja";
36+define("EN","en");
37+define("JA","ja");
38+if(EN==$lang){
39+ $i18n[EN][0]="login";
40+ $i18n[EN][1]="logout";
41+ $i18n[EN][2]="top";
42+}elseif(JA==$lang){
43+ $i18n[JA][0]="ログイン";
44+ $i18n[JA][1]="ログアウト";
45+ $i18n[JA][2]="トップ";
46+}
47+
48+$pagetitle = "/";
49+$page = "index";
50+
51+//session - session
52+session_start();
53+if (isset($_POST["onedbadmin_username"])) { $_SESSION['onedbadmin_username'] = $_POST["onedbadmin_username"]; }
54+if (isset($_POST["onedbadmin_password"])) { $_SESSION['onedbadmin_password'] = $_POST["onedbadmin_password"]; }
55+if ((@$_SESSION['onedbadmin_username'] == $config["user"]) and (@$_SESSION['onedbadmin_password'] == $config["password"])) {
56+ $_SESSION['onedbadmin_valid'] = "1";
57+} else {
58+ $_SESSION['onedbadmin_valid'] = "0";
59+ if ($_GET["p"] !== "login") { header("Location: ".$_SERVER["php_self"]."?p=login"); }
60+}
61+
62+
63+//page - admin
64+if(isset($_GET["p"])) { $page = $_GET["p"]; }
65+if(@$_GET["p"] == "login") {$pagetitle = "Login";}
66+if(@$_GET["p"] == "logout") {$pagetitle = "Logout"; $_SESSION['onedbadmin_valid'] = "0"; session_destroy(); }
67+if(@$_GET["p"] == "table_list") {
68+ $pagetitle = "table list - ".$config["db"][$_GET["tid"]];
69+}
70+if(@$_GET["p"] == "table_info") {
71+ $pagetitle = "table Structure - ".$config["db"][$_GET["tid"]]."-".$_GET["tname"];
72+}
73+if(@$_GET["p"] == "table_value") {
74+ $tbl_dbh = new PDO('sqlite:'.$config["db"][$_GET["tid"]],'','');
75+ $pagetitle = "teble view - ".$config["db"][$_GET["tid"]]." - ".$_GET["tname"];
76+}
77+
78+
79+
80+
81+
82+
83+function get_pagingURL($pageKey){
84+ $other_param = "";
85+ if(is_array($pageKey)){
86+ foreach($_GET as $key => $value){
87+ if(is_array($value)){
88+ foreach($value as $v_key => $v_value){
89+ if (!in_array(sprintf("%s[%s]",$key,$v_key),$pageKey)){
90+ $other_param .= "&amp;".sprintf("%s[%s]",$key,$v_key)."=".urlencode($v_value);
91+ }
92+ }
93+ }else{
94+ if (!in_array($key,$pageKey)){
95+ $other_param .= "&amp;".$key."=".urlencode($value);
96+ }
97+ }
98+ }
99+ }else{
100+ foreach($_GET as $key => $value){
101+ if(is_array($value)){
102+ foreach($value as $v_key => $v_value){
103+ if (sprintf("%s[%s]",$key,$v_key) != $pageKey){
104+ $other_param .= "&amp;".sprintf("%s[%s]",$key,$v_key)."=".urlencode($v_value);
105+ }
106+ }
107+ }else{
108+ if ($key != $pageKey){
109+ $other_param .= "&amp;".$key."=".urlencode($value);
110+ }
111+ }
112+ }
113+ }
114+ return $other_param;
115+}
116+
117+
118+function page_pager($current_num,$countRe,$url,$per_page=6){
119+ // 現在のページ情報を取得
120+ $VIEW_PAGE_MENU_WIDTH = 2;
121+ $PREV_MARK = "&lt;";
122+ $NEXT_MARK = "&gt;";
123+ $startMore="";
124+ $endMore="";
125+ $startPage=1;
126+ $endPage=0;
127+
128+ $now_page =intval($current_num);
129+ $now_page =(empty($now_page))?1:$now_page;
130+ $now_page =(ceil($countRe / $per_page) < $now_page)?ceil($countRe / $per_page):$now_page;
131+
132+ $other_param = get_pagingURL($url);
133+ if($now_page=="") $now_page=1;
134+ $maxPage=ceil($countRe / $per_page);
135+ if( ($maxPage == 1) or ($maxPage < $now_page) ) return false;
136+ if($now_page > 1){
137+ $startMore .= "<a href=\"?$url=".($now_page - 1).$other_param."\" accesskey=\"*\" >".$PREV_MARK."Previous[*] </a> ";
138+ if($now_page > $VIEW_PAGE_MENU_WIDTH + 1){
139+ $startPage = $now_page - $VIEW_PAGE_MENU_WIDTH;
140+ $startMore .= "<a href=\"?$url=1".$other_param."\"><span style=\"font-size:small;\">1</span></a><span style=\"font-size:xx-small;\">...</span>";
141+ }
142+ }else{
143+ $startPage = 1;
144+ }
145+ if($now_page < $maxPage){
146+ if($now_page + $VIEW_PAGE_MENU_WIDTH < $maxPage){
147+ $endPage = $now_page + $VIEW_PAGE_MENU_WIDTH;
148+ $endMore .= "<span style=\"font-size:xx-small;\">...</span><a href=\"?$url=".$maxPage.$other_param."\"><span style=\"font-size:small;\">".$maxPage."</span></a>\n";
149+ }else{
150+ $endPage = $maxPage;
151+ }
152+ $endMore .= " <a href=\"?$url=".($now_page + 1).$other_param."\" accesskey=\"#\">[#]Next".$NEXT_MARK."</a>\n";
153+ }else{
154+ $endPage = $maxPage;
155+ }
156+ $page_footer="";
157+ for($i = $startPage ; $i <= $endPage ; $i++){
158+ $page_footer.= " ".(($now_page==$i)?"<span style=\"font-size:small;\">$i</span>\n":"<span style=\"font-size:small;\"><a href=\"?$url=$i".$other_param."\">$i</a></span>\n");
159+ }
160+ $page_footer = $startMore.$page_footer.$endMore;
161+ return $page_footer;
162+}
163+
164+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
165+<html xmlns="http://www.w3.org/1999/xhtml">
166+<head>
167+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
168+<meta name="robots" content="noindex">
169+<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALAQMAAACTYuVlAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZQTFRFAAAA////pdmf3QAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIFYzLjM2aCbNIQAAACRJREFUCNdjOJDAsH8Bg4MDQ/0BBp8DDKEODCFgEsgGijQoAAC0HAp0htmWJwAAAABJRU5ErkJggg==" />
170+<title> OneSQLiteAdmin - <?php echo $pagetitle; ?></title>
171+<style type="text/css">
172+html, body, div, span, applet, object, iframe, table, caption,
173+tbody, tfoot, thead, tr, th, td, del, dfn, em, font, img, ins,
174+kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,
175+h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr,
176+acronym, address, big, cite, code, dl, dt, dd, ol, ul, li,
177+fieldset, form, label, legend{
178+ vertical-align:baseline;
179+ font-family:inherit;
180+ font-weight:inherit;
181+ font-style:inherit;
182+ font-size:100%;
183+ outline:0;
184+ padding:0;
185+ margin:0;
186+ border:0;
187+}
188+:focus{
189+ outline:0;
190+}
191+body{
192+ background:white;
193+ line-height:1;
194+ color:black;
195+}
196+ol, ul{
197+ list-style:none;
198+}
199+table{
200+ border-collapse:separate;
201+ border-spacing:0;
202+}
203+caption, th, td{
204+ font-weight:normal;
205+ text-align:left;
206+}
207+blockquote:bfore, blockquote:after, q:before, q:after{
208+ content: "";
209+}
210+blockquote, q{
211+ quotes:"" "";
212+}
213+</style>
214+</head>
215+<body class="page_<?php echo $page; ?>">
216+<div class="container">
217+<div class="header">
218+ <h1>
219+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>" class="title">OneSQLiteAdmin</a>
220+ </h1>
221+<?php if ((isset($_SESSION['onedbadmin_valid'])) && ($_SESSION['onedbadmin_valid'] == "1")) { ?>
222+ <div class="nav">
223+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>"><?=$i18n[$lang][2]?></a> |
224+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>?p=logout"><?=$i18n[$lang][1]?></a>
225+ </div>
226+<?php } ?>
227+</div>
228+
229+<?php
230+
231+if($page == "index"){
232+?>
233+ <h2>db list</h2>
234+ <div class="list-db">
235+<?php if(empty($config["db"])){ ?>
236+ non database.
237+<?php }else{ ?>
238+ <ul>
239+<?php foreach($config["db"] as $db_key => $db_name){ ?>
240+ <li><a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?p=table_list&amp;tid=<?=$db_key?>"><?=$db_name?></a></li>
241+<?php } ?>
242+ </ul>
243+<?php } ?>
244+ <div>
245+<?php };
246+
247+if($page == "table_list"){
248+ $tbl_dbh = new PDO('sqlite:'.$config["db"][$_GET["tid"]],'', '');
249+ $table_names = $tbl_dbh->prepare("select name from sqlite_master where type='table' order by name");
250+ $table_names->execute();
251+ $table_names = $table_names->fetchAll(PDO::FETCH_ASSOC);
252+?>
253+ <h2>table list</h2>
254+ <div class="list-table">
255+<?php if(empty($table_names)){ ?>
256+ non table.
257+<?php }else{ ?>
258+ <ul>
259+<?php foreach($table_names as $table_name){ ?>
260+ <li><a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?p=table_info&amp;tid=<?=$_GET["tid"]?>&amp;tname=<?=$table_name["name"]?>"><?=$table_name["name"]?></a></li>
261+<?php } ?>
262+ </ul>
263+<?php } ?>
264+ <div>
265+<?php };
266+
267+
268+if($page == "table_info"){
269+ $tbl_dbh = new PDO('sqlite:'.$config["db"][$_GET["tid"]],'', '');
270+ $table_infoes = $tbl_dbh->prepare("PRAGMA table_info('".$_GET["tname"]."');");
271+ $table_infoes->execute();
272+ $table_infoes = $table_infoes->fetchAll(PDO::FETCH_ASSOC);
273+
274+
275+?>
276+ <h2>table Structure - <?=$_GET["tname"]?></h2>
277+ <p>Structure|<a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?p=table_value&amp;tid=<?=$_GET["tid"]?>&amp;tname=<?=$_GET["tname"]?>">view</a>|sql</p>
278+ <div class="table-info">
279+<?php if(empty($table_infoes)){ ?>
280+ non table info.
281+<?php }else{ ?>
282+ <table style="margin-top: 0.2em;margin-bottom: 1em;width: 570px;border-collapse: collapse;border: solid 1px #999;font-size: 100%;">
283+ <colgroup>
284+ <col width="150px" ></col>
285+ <col width="150px" ></col>
286+ <col width="150px" ></col>
287+ <col width="150px" ></col>
288+ <col width="150px" ></col>
289+ <col width="150px" ></col>
290+ </colgroup>
291+ <tr style="border: solid 1px #999;">
292+<?php foreach($table_infoes[0] as $table_info_c=>$table_info_v){ ?>
293+ <th style="background: #E6E6E6;text-align: center;white-space: nowrap;color: #666;border: solid 1px #999;padding: 4px 6px;">
294+ <?=$table_info_c?>
295+ </th>
296+<?php } ?>
297+ </tr>
298+<?php foreach($table_infoes as $table_info){ ?>
299+ <tr style="border: solid 1px #999;">
300+<?php foreach($table_info as $table_info_i){ ?>
301+ <td style="border: solid 1px #999;">
302+ <?=$table_info_i?>
303+ </td>
304+<?php } ?>
305+ </tr>
306+<?php } ?>
307+ </table>
308+<?php } ?>
309+ <div>
310+<?php };
311+
312+
313+
314+if($page == "table_value"){
315+ $tbl_dbh = new PDO('sqlite:'.$config["db"][$_GET["tid"]] ,'', '');
316+ $tbl_count = $tbl_dbh->prepare("SELECT count(*) as c FROM ".$_GET["tname"]);
317+ $tbl_count->execute();
318+ $tbl_count = $tbl_count->fetchAll();
319+ $rows_count = $tbl_count[0]["c"];
320+
321+ if($rows_count>0){
322+ if(isset($_GET["i"])){
323+ $p = $_GET["i"];
324+ }else{
325+ $p = 1;
326+ }
327+
328+ if(isset($_GET["l"])){
329+ $limit = $_GET["l"];
330+ }
331+ if(empty($limit)){
332+ $limit = 5;
333+ }else{
334+ $limit = intval($limit);
335+ }
336+
337+ if(isset($_GET["sort"])){
338+ $sort = " ORDER BY ".$_GET["sort"]." ".$_GET["jun"];
339+ }else{
340+ $sort = "";
341+ }
342+
343+ $p = (ceil($rows_count / $limit) < $p)?ceil($rows_count / $limit):$p;
344+ $offset = ($p-1)*$limit;
345+
346+ $tbl_data = $tbl_dbh->prepare("SELECT * FROM ".$_GET["tname"]." {$sort} LIMIT {$offset} , {$limit} ");
347+ $tbl_data->execute();
348+ $tbl_data = $tbl_data->fetchAll(PDO::FETCH_ASSOC);
349+ }
350+
351+?>
352+ <h2>table view - <?=$_GET["tname"]?></h2>
353+ <p><a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>?p=table_info&amp;tid=<?=$_GET["tid"]?>&amp;tname=<?=$_GET["tname"]?>">Structure</a>|view|SQL</p>
354+ <div class="table-value">
355+<?php if($rows_count==0){ ?>
356+ non data.
357+<?php }else{ ?>
358+ <div style="width:100%;overflow:auto;text-align:center;">
359+ <table style="margin-top: 0.2em;margin-bottom: 1em;width: 570px;border-collapse: collapse;border: solid 1px #999;font-size: 100%;">
360+ <tr style="border: solid 1px #999;">
361+<?php foreach($tbl_data[0] as $tbl_data_c=>$tbl_data_v){ ?>
362+ <th style="background: #E6E6E6;text-align: center;white-space: nowrap;color: #666;border: solid 1px #999;padding: 4px 6px;">
363+<?php if($tbl_data_c == @$_GET["sort"]){
364+ if($_GET["jun"]=="DESC"){ ?>
365+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>?jun=ASC<?=get_pagingURL("jun")?>"><?=$tbl_data_c?>△</a>
366+<?php }else{ ?>
367+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>?jun=DESC<?=get_pagingURL("jun")?>"><?=$tbl_data_c?>▽</a>
368+<?php } ?>
369+<?php }else{ ?>
370+ <a href="<?=$_SERVER["SCRIPT_NAME"]?>?sort=<?=$tbl_data_c?>&jun=DESC<?=get_pagingURL(array("jun","sort"))?>"><?=$tbl_data_c?></a>
371+<?php } ?>
372+ </th>
373+<?php } ?>
374+ </tr>
375+<?php foreach($tbl_data as $tbl_d){ ?>
376+ <tr style="border: solid 1px #999;">
377+<?php foreach($tbl_d as $tbl_data_v){ ?>
378+ <td style="border: solid 1px #999;">
379+ <?=$tbl_data_v?>
380+ </td>
381+<?php } ?>
382+ </tr>
383+<?php } ?>
384+ </table>
385+ <p style="width:100%;"><?=page_pager($p,$rows_count,"i",$limit)?></p>
386+ </div>
387+<?php } ?>
388+ <div>
389+<?php };
390+
391+
392+
393+//login
394+if ($page == "login") { ?>
395+ <h2><?=$i18n[$lang][0]?></h2>
396+ <form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>">
397+ <p>
398+ <label for="onedbadmin_username">User:</label>
399+ <input type="text" name="onedbadmin_username" id="onedbadmin_username" class="textinput" />
400+ </p>
401+ <p>
402+ <label for="onedbadmin_password">Password:</label>
403+ <input type="password" name="onedbadmin_password" id="onedbadmin_password" class="textinput" />
404+ </p>
405+ <p><input type="submit" class="button" value="Enter" /></p>
406+ </form>
407+<?php };
408+
409+
410+
411+//logout
412+if ($page == "logout") { ?>
413+ <h2><?=$i18n[$lang][1]?></h2>
414+ <p>Logout...</p>
415+<?php };
416+
417+
418+
419+
420+?>
421+</div>
422+</body>
423+</html>
Show on old repository browser