Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 883 2008-11-27 21:58:49Z thorn $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, 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
@include_once('config.php');
27

    
28
// this function checks the basic configurations of an existing WB intallation
29
function status_msg($message, $class='check', $element='span') {
30
	// returns a status message
31
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
32
}
33

    
34

    
35
?>
36
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
37
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
38
<head>
39
<title>Upgrade script</title>
40
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
41
<style type="text/css">
42
body {
43
	margin:0;
44
	padding:0;
45
	border:0;
46
	background: #EBF7FC;
47
	color:#000;
48
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
49
	font-size: small;
50
	height:101%;
51
}
52

    
53
#container {
54
	width:85%;
55
	background: #A8BCCB url(<?php echo ADMIN_URL;?>/interface/background.png) repeat-x;
56
	border:1px solid #000;
57
	color:#000;
58
	margin:2em auto;
59
	padding:0 15px;
60
	min-height: 500px;
61
	text-align:left;
62
}
63

    
64
p { line-height:1.5em; }
65

    
66
h1,h2,h3,h4,h5,h6 {
67
	font-family: Verdana, Arial, Helvetica, sans-serif;
68
	color: #369;
69
	margin-top: 1.0em;
70
	margin-bottom: 0.1em;
71
}
72

    
73
h1 { font-size:150%; }
74
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
75
h3 { font-size: 120%; }
76

    
77
.ok, .error { font-weight:bold; }
78
.ok { color:green; }
79
.error { color:red; }
80
.check { color:#555; }
81

    
82
.warning {
83
	width: 98%;
84
	background:#FFDBDB;
85
	padding:0.2em;
86
	margin-top:0.5em;
87
	border: 1px solid black;
88
}
89
</style>
90
</head>
91
<body>
92
<div id="container">
93
<img src="<?php echo ADMIN_URL;?>/interface/logo.png" alt="Website Baker Logo" />
94

    
95
<h1>Website Baker Upgrade</h1>
96

    
97
<?php
98

    
99
require_once('config.php');
100
require_once(WB_PATH.'/framework/functions.php');
101

    
102
$OK   = '<span class="ok">OK</span>';
103
$FAIL = '<span class="error">FAILED</span>';
104

    
105
// function to add a var/value-pair into settings-table
106
function db_add_key_value($key, $value) {
107
	global $database; global $OK; global $FAIL;
108
	$table = TABLE_PREFIX.'settings';
109
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
110
	if($query->numRows() > 0) {
111
		echo "$key: allready there. $OK.<br />";
112
		return true;
113
	} else {
114
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
115
		echo (mysql_error()?mysql_error().'<br />':'');
116
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
117
		if($query->numRows() > 0) {
118
			echo "$key: $OK.<br />";
119
			return true;
120
		} else {
121
			echo "$key: $FAIL!<br />";
122
			return false;
123
		}
124
	}
125
}
126

    
127
// function to add a new field into a table
128
function db_add_field($field, $table, $desc) {
129
	global $database; global $OK; global $FAIL;
130
	echo "<u>Adding field '$field' to table '$table'</u><br />";
131
	$table = TABLE_PREFIX.$table;
132
	$query = $database->query("DESCRIBE $table '$field'");
133
	if($query->numRows() == 0) { // add field
134
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
135
		echo (mysql_error()?mysql_error().'<br />':'');
136
		$query = $database->query("DESCRIBE $table '$field'");
137
		echo (mysql_error()?mysql_error().'<br />':'');
138
		if($query->numRows() > 0) {
139
			echo "'$field' added. $OK.<br />";
140
		} else {
141
			echo "adding '$field' $FAIL!<br />";
142
		}
143
	} else {
144
		echo "'$field' allready there. $OK.<br />";
145
	}
146
}
147

    
148

    
149
/**********************************************************
150
 *  - Adding field sec_anchor to settings table
151
 */
152
echo "<br />Adding key sec_anchor to settings table<br />";
153
$cfg = array(
154
	'sec_anchor' => 'wb_'
155
);
156
foreach($cfg as $key=>$value) {
157
	db_add_key_value($key, $value);
158
}
159

    
160

    
161
/**********************************************************
162
 *  - Add field "redirect_type" to table "mod_menu_link"
163
 */
164
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
165
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
166

    
167

    
168
/**********************************************************
169
 *  - End of upgrade script
170
 */
171
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
172
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
173
// show buttons to go to the backend or frontend
174
echo '<br />';
175
if(defined('WB_URL')) {
176
	echo '<form action="'.WB_URL.'" target="_self">';
177
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
178
	echo '</form>';
179
}
180
if(defined('ADMIN_URL')) {
181
	echo '<form action="'.ADMIN_URL.'" target="_self">';
182
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
183
	echo '</form>';
184
}
185
echo '<p>&nbsp;</p>';
186

    
187
?>
188
	
189
</div>
190
</body>
191
</html>
(4-4/4)