OSDN Git Service

Another small bug fix. :P
[idb/iDB.git.git] / inc / admin / sqldumper / sqlite.php
1 <?php
2 /*
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the Revised BSD License.
5
6     This program is distributed in the hope that it will be useful,
7     but WITHOUT ANY WARRANTY; without even the implied warranty of
8     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9     Revised BSD License for more details.
10
11     Copyright 2004-2009 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: sqlite.php - Last Update: 12/15/2009 SVN 408 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="sqlite.php"||$File3Name=="/sqlite.php") {
18         require('index.php');
19         exit(); }
20
21 if($_SESSION['UserGroup']==$Settings['GuestGroup']||$GroupInfo['HasAdminCP']=="no") {
22 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
23 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
24 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
25 if($Settings['sqltype']!="sqlite") {
26 redirect("location",$basedir.url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false));
27 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']);
28 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
29 if(!isset($_GET['outtype'])) { $_GET['outtype'] = "UTF-8"; }
30 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
31 header("Cache-Control: private",false); 
32 header("Content-Description: File Transfer");
33 $fname = str_replace("_","", $Settings['sqltable']);
34 header("Content-Disposition: attachment; filename=".$fname.".sql");
35 header("Content-Type: application/octet-stream");
36 header("Content-Transfer-Encoding: binary");
37 $SQLDumper = "SQL Dumper";
38 function GetAllRows($table) { $rene_j = 0; $trowout = null;
39 global $SQLStat;
40 $tresult = sql_query("SELECT * FROM \"".$table."\"",$SQLStat);
41 while ($trow = sql_fetch_assoc($tresult)) {
42 $trowout[$rene_j] = $trow;
43 ++$rene_j; }
44 sql_free_result($tresult);
45 return $trowout; }
46 $TablePreFix = $Settings['sqltable'];
47 function add_prefix($tarray) {
48 global $TablePreFix;
49 return $TablePreFix.$tarray; }
50 $TableChCk = array("categories", "catpermissions", "events", "forums", "groups", "members", "messenger", "permissions", "posts", "restrictedwords", "sessions", "smileys", "topics", "wordfilter");
51 $TableChCk = array_map("add_prefix",$TableChCk);
52 if(!isset($_GET['outtype'])||$_GET['outtype']=="UTF-8") {
53 header("Content-Type: text/plain; charset=UTF-8"); }
54 if($_GET['outtype']=="latin1") {
55 header("Content-Type: text/plain; charset=ISO-8859-15"); }
56 if($_GET['outtype']=="latin15") {
57 header("Content-Type: text/plain; charset=ISO-8859-15"); }
58 $sli = 0; $slnum = count($TableChCk);
59 while ($sli < $slnum) {
60 /*
61 $FullTable[$sli] = "CREATE TABLE \"".$TableChCk[$sli]."\" (\n";
62 */
63 $tabsta = sql_query("SELECT * FROM sqlite_master WHERE type=\"table\" and tbl_name=\"".$TableChCk[$sli]."\";",$SQLStat);
64 $tabstats = sql_fetch_array($tabsta);
65 $FullTable[$sli] = $tabstats['sql'].";\n";
66 /*
67 $zli = 0;
68 $tabsta = sql_query("PRAGMA table_info(\"".$TableChCk[$sli]."\");",$SQLStat);
69 while ($tabstats = sql_fetch_array($tabsta)) {
70 var_dump($tabstats);
71 if($zli>0) { $FullTable[$sli] .= ",\n"; }
72 $SQLDefault = null; $PrimeKey = " ";
73 if($tabstats['dflt_value']!==null) {
74 $SQLDefault = " default '".$tabstats['dflt_value']."'"; }
75 if($tabstats['dflt_value']===null) {
76 $SQLDefault = ""; }
77 if($tabstats['pk']=="1") {
78 $PrimeKey = " PRIMARY KEY "; }
79 $FullTable[$sli] .= "  \"".$tabstats['name']."\" ".$tabstats['type'].$PrimeKey."NOT NULL".$SQLDefault;
80 ++$zli; }
81 $FullTable[$sli] .= "\n);\n";
82 */
83 ++$sli; }
84 $TableNames = $TableChCk;
85 $num = count($TableNames); $renee_s = 0;
86 echo "-- ".$OrgName." ".$SQLDumper."\n";
87 echo "-- version ".$VerInfo['iDB_Ver_SVN']."\n";
88 echo "-- ".$iDBHome."support/\n";
89 echo "--\n";
90 echo "-- Generation Time: ".GMTimeGet('F d, Y \a\t h:i A',$_SESSION['UserTimeZone'],0,$_SESSION['UserDST'])."\n";
91 echo "-- SQLite Server version: ".sql_server_info($SQLStat)."\n";
92 echo "-- PHP Version: ".phpversion()."\n\n";
93 echo "--\n";
94 echo "-- Database: \"".$Settings['sqldb']."\"\n";
95 echo "--\n\n";
96 echo "-- --------------------------------------------------------\n\n";
97 while ($renee_s < $num) { $tnum = $num - 1;
98 $trow = GetAllRows($TableNames[$renee_s]);
99 $numz = count($trow); $kazuki_p = 0;
100 echo "--\n";
101 echo "-- Table structure for table \"".$TableNames[$renee_s]."\"\n";
102 echo "--\n\n";
103 echo $FullTable[$renee_s]."\n";
104 while ($kazuki_p < $numz) { $tnumz = $numz - 1;
105 $srow = null; $srowvalue = null;
106 $trownew = $trow[$kazuki_p];
107 $trowname = array_keys($trownew);
108 $nums = count($trownew); $il = 0;
109 while ($il < $nums) { $tnums = $nums - 1;
110 $trowrname = sql_escape_string($trowname[$il],$SQLStat);
111 $trowrvalue = sql_escape_string($trownew[$trowrname],$SQLStat);
112 if($_GET['outtype']=="UTF-8"&&$Settings['charset']!="UTF-8") {
113 $trowrvalue = utf8_encode($trowrvalue); }
114 $trowrvalue = str_replace( array("\n", "\r"), array('\n', '\r'), $trowrvalue);
115 if($il===0) { $srow = "INSERT INTO \"".$TableNames[$renee_s]."\" ("; }
116 if($il<$tnums&&$il!=$tnums) { $srow .= "\"".$trowrname."\", "; }
117 if($il==$tnums) { $srow .= "\"".$trowrname."\") VALUES"; }
118 if($il===0) { $srowvalue = "("; }
119 if(!is_numeric($trowrvalue)) { $trowrvalue = "'".$trowrvalue."'"; }
120 if($il<$tnums) { $srowvalue .= $trowrvalue.", "; }
121 if($il==$tnums) { $srowvalue .= $trowrvalue;
122 if($kazuki_p<$tnumz) { $srowvalue .= ");"; }
123 if($kazuki_p==$tnumz) { $srowvalue .= ");"; } }
124 ++$il; }
125 if($kazuki_p===0) {
126 echo "--\n";
127 echo "-- Dumping data for table \"".$TableNames[$renee_s]."\"\n";
128 echo "--\n\n"; }
129 echo $srow."\n";
130 echo $srowvalue."\n";
131 if($kazuki_p==$tnumz&&$renee_s<$tnum) {
132 echo "\n-- --------------------------------------------------------\n"; }
133 ++$kazuki_p; }
134 if($numz===0) {
135 echo "--\n";
136 echo "-- Dumping data for table \"".$TableNames[$renee_s]."\"\n";
137 echo "--\n\n";
138 echo "\n-- --------------------------------------------------------\n"; }
139 echo "\n";
140 ++$renee_s; }
141 fix_amp($Settings['use_gzip'],$GZipEncode['Type']);
142 ?>