Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        modules
33
 * @package         backup
34
 * @author          WebsiteBaker Project
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41
 * @version         $Id: backup-sql.php 1271 2010-01-23 02:30:24Z Luisehahne $
42
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/backup/backup-sql.php $
43
 * @lastmodified    $Date: 2010-01-23 03:30:24 +0100 (Sat, 23 Jan 2010) $
44
 *
45
*/
46

    
47
// Filename to use
48
$filename = $_SERVER['HTTP_HOST'].'-backup-'.gmdate('Y-m-d', time()+TIMEZONE).'.sql';
49

    
50
// Check if user clicked on the backup button
51
if(!isset($_POST['backup'])){
52
	header('Location: ../');
53
	exit(0);
54
}
55

    
56
// Include config
57
require_once('../../config.php');
58

    
59
// Begin output var
60
$output = "".
61
"#\n".
62
"# Website Baker ".WB_VERSION." Database Backup\n".
63
"# ".WB_URL."\n".
64
"# ".gmdate(DATE_FORMAT, time()+TIMEZONE).", ".gmdate(TIME_FORMAT, time()+TIMEZONE)."\n".
65
"#".
66
"\n";
67

    
68
// Get table names
69
// Use this one for ALL tables in DB
70
$query  = "SHOW TABLES";
71

    
72
if ($_POST['tables']=='WB') {
73
	// Or use this to get ONLY wb tables
74
	$prefix=str_replace('_','\_',TABLE_PREFIX);
75
	$query = "SHOW TABLES LIKE '".$prefix."%'";
76
}
77

    
78
$result = $database->query($query);
79

    
80
// Loop through tables
81
while($row = $result->fetchRow()) {
82
	//show sql query to rebuild the query
83
	$sql = 'SHOW CREATE TABLE '.$row[0].''; 
84
	$query2 = $database->query($sql); 
85
	// Start creating sql-backup
86
	$sql_backup ="\r\n# Create table ".$row[0]."\r\n\r\n";
87
	$out = $query2->fetchRow();
88
	$sql_backup.=$out['Create Table'].";\r\n\r\n"; 
89
	$sql_backup.="# Dump data for ".$row[0]."\r\n\r\n";
90
	// Select everything
91
	$out = $database->query('SELECT * FROM '.$row[0]); 
92
	$sql_code = '';
93
	// Loop through all collumns
94
	while($code = $out->fetchRow()) { 
95
		$sql_code .= "INSERT INTO ".$row[0]." SET "; 
96
		$numeral = 0;
97
		foreach($code as $insert => $value) {
98
			// Loosing the numerals in array -> mysql_fetch_array($result, MYSQL_ASSOC) WB hasn't? 
99
			if($numeral==1) {
100
				$sql_code.=$insert ."='".addslashes($value)."',";
101
			}
102
			$numeral = 1 - $numeral;
103
		}
104
		$sql_code = substr($sql_code, 0, -1);
105
		$sql_code.= ";\r\n";
106
	}
107
	$output .= $sql_backup.$sql_code; 
108
}
109

    
110
// Output file
111
header('Content-Type: text/html');
112
header('Content-Disposition: attachment; filename='.$filename);
113
echo $output;
114

    
115
?>
(1-1/4)