1 |
182
|
ryan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2005, Ryan Djurovich
|
9 |
|
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Check if user clicked on the backup button
|
27 |
|
|
if(!isset($_POST['backup'])){ header('Location: ../'); }
|
28 |
|
|
|
29 |
187
|
ryan
|
// Include config
|
30 |
|
|
require_once('../../config.php');
|
31 |
182
|
ryan
|
|
32 |
187
|
ryan
|
// Create new admin object
|
33 |
|
|
require(WB_PATH.'/framework/class.admin.php');
|
34 |
|
|
$admin = new admin('Settings', 'settings_advanced', false);
|
35 |
|
|
|
36 |
|
|
// Begin output var
|
37 |
189
|
ryan
|
$output = "".
|
38 |
188
|
ryan
|
"#\n".
|
39 |
189
|
ryan
|
"# Website Baker ".WB_VERSION." Database Backup\n".
|
40 |
|
|
"# ".WB_URL."\n".
|
41 |
|
|
"# ".gmdate(DATE_FORMAT, mktime()+TIMEZONE)." ".gmdate(TIME_FORMAT, mktime()+TIMEZONE)."\n".
|
42 |
187
|
ryan
|
"#".
|
43 |
|
|
"\n";
|
44 |
|
|
|
45 |
182
|
ryan
|
// Get table names
|
46 |
|
|
$result = $database->query("SHOW TABLE STATUS");
|
47 |
|
|
|
48 |
|
|
// Loop through tables
|
49 |
190
|
ryan
|
while($row = $result->fetchRow()) {
|
50 |
|
|
//show sql query to rebuild the query
|
51 |
|
|
$sql = 'SHOW CREATE TABLE '.$row['Name'].'';
|
52 |
|
|
$query2 = $database->query($sql);
|
53 |
182
|
ryan
|
// Start creating sql-backup
|
54 |
190
|
ryan
|
$sql_backup ="\r\n# Create table ".$row['Name']."\r\n\r\n";
|
55 |
|
|
$out = $query2->fetchRow();
|
56 |
|
|
$sql_backup.=$out['Create Table'].";\r\n\r\n";
|
57 |
|
|
$sql_backup.="# Dump data for ".$row['Name']."\r\n\r\n";
|
58 |
|
|
// Select everything
|
59 |
|
|
$out = $database->query('SELECT * FROM '.$row['Name']);
|
60 |
182
|
ryan
|
$sql_code = '';
|
61 |
190
|
ryan
|
// Loop through all collumns
|
62 |
|
|
while($code = $out->fetchRow()) {
|
63 |
|
|
$sql_code .= "INSERT INTO ".$row['Name']." SET ";
|
64 |
182
|
ryan
|
$numeral = 0;
|
65 |
190
|
ryan
|
foreach($code as $insert => $value) {
|
66 |
|
|
// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't?
|
67 |
182
|
ryan
|
if($numeral==1) {
|
68 |
190
|
ryan
|
$sql_code.=$insert ."='".addslashes($value)."',";
|
69 |
182
|
ryan
|
}
|
70 |
|
|
$numeral = 1 - $numeral;
|
71 |
|
|
}
|
72 |
|
|
$sql_code = substr($sql_code, 0, -1);
|
73 |
|
|
$sql_code.= ";\r\n";
|
74 |
|
|
}
|
75 |
190
|
ryan
|
$output .= $sql_backup.$sql_code;
|
76 |
182
|
ryan
|
}
|
77 |
|
|
|
78 |
|
|
// Output file
|
79 |
|
|
header('Content-Type: application/octet-stream');
|
80 |
187
|
ryan
|
header('Content-Disposition: attachment');
|
81 |
|
|
header('Filename: "'.str_replace(WB_PATH.'/temp', '', $temp_file).'"');
|
82 |
|
|
echo $output;
|
83 |
182
|
ryan
|
|
84 |
|
|
?>
|