Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 95 2005-09-12 23:08:46Z stefan $
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
// Find out if the user was view advanced options or not
27
if($_POST['advanced'] == 'yes' ? $advanced = '?advanced=yes' : $advanced = '');
28

    
29
// Print admin header
30
require('../../config.php');
31
require_once(WB_PATH.'/framework/class.admin.php');
32
if($advanced == '') {
33
	$admin = new admin('Settings', 'settings_basic');
34
	$_POST['database_password'] = DB_PASSWORD;
35
} else {
36
	$admin = new admin('Settings', 'settings_advanced');
37
}
38

    
39
// Create new database object
40
$database = new database();
41

    
42
// Query current settings in the db, then loop through them and update the db with the new value
43
$query = "SELECT name FROM ".TABLE_PREFIX."settings";
44
$results = $database->query($query);
45
while($setting = $results->fetchRow()) {
46
	$setting_name = $setting['name'];
47
	$value = $admin->get_post($setting_name);
48
	$value = $admin->add_slashes($value);
49
	$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
50
}
51

    
52
// Query current search settings in the db, then loop through them and update the db with the new value
53
$query = "SELECT name FROM ".TABLE_PREFIX."search WHERE extra = ''";
54
$results = $database->query($query);
55
while($search_setting = $results->fetchRow()) {
56
	$setting_name = $search_setting['name'];
57
	$post_name = 'search_'.$search_setting['name'];
58
	$value = $admin->get_post($post_name);
59
	$value = $admin->add_slashes($value);
60
	$database->query("UPDATE ".TABLE_PREFIX."search SET value = '$value' WHERE name = '$setting_name'");
61
}
62

    
63
// Check if there was an error updating the db
64
if($database->is_error()) {
65
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
66
} else {
67
	// Get timezone offset
68
	$timezone_offset = $_POST['timezone']*60*60;
69
	// Work out what code to put in for error reporting
70
	if($_POST['er_level'] == '') {
71
		$er_level = '';
72
		$er_level_code = '';
73
	} else {
74
		$er_level = $_POST['er_level'];
75
		$er_level_code = "error_reporting('".$_POST['er_level']."');\n";
76
	}
77
	// Work-out database type, and whether or not to use PEAR
78
	$database_type = $admin->get_post('database_type');
79
	
80
	// Work-out file mode
81
	if($advanced == '') {
82
		// Check if should be set to 777 or left alone
83
		if(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
84
			$file_mode = '0777';
85
			$dir_mode = '0777';
86
		} else {
87
			$file_mode = STRING_FILE_MODE;
88
			$dir_mode = STRING_DIR_MODE;
89
		}
90
	} else {
91
		// Work-out the octal value for file mode
92
		$u = 0;
93
		if(isset($_POST['file_u_r']) AND $_POST['file_u_r'] == 'true') {
94
			$u = $u+4;
95
		}
96
		if(isset($_POST['file_u_w']) AND $_POST['file_u_w'] == 'true') {
97
			$u = $u+2;
98
		}
99
		if(isset($_POST['file_u_e']) AND $_POST['file_u_e'] == 'true') {
100
			$u = $u+1;
101
		}
102
		$g = 0;
103
		if(isset($_POST['file_g_r']) AND $_POST['file_g_r'] == 'true') {
104
			$g = $g+4;
105
		}
106
		if(isset($_POST['file_g_w']) AND $_POST['file_g_w'] == 'true') {
107
			$g = $g+2;
108
		}
109
		if(isset($_POST['file_g_e']) AND $_POST['file_g_e'] == 'true') {
110
			$g = $g+1;
111
		}
112
		$o = 0;
113
		if(isset($_POST['file_o_r']) AND $_POST['file_o_r'] == 'true') {
114
			$o = $o+4;
115
		}
116
		if(isset($_POST['file_o_w']) AND $_POST['file_o_w'] == 'true') {
117
			$o = $o+2;
118
		}
119
		if(isset($_POST['file_o_e']) AND $_POST['file_o_e'] == 'true') {
120
			$o = $o+1;
121
		}
122
		$file_mode = "0".$u.$g.$o;
123
		// Work-out the octal value for dir mode
124
		$u = 0;
125
		if(isset($_POST['dir_u_r']) AND $_POST['dir_u_r'] == 'true') {
126
			$u = $u+4;
127
		}
128
		if(isset($_POST['dir_u_w']) AND $_POST['dir_u_w'] == 'true') {
129
			$u = $u+2;
130
		}
131
		if(isset($_POST['dir_u_e']) AND $_POST['dir_u_e'] == 'true') {
132
			$u = $u+1;
133
		}
134
		$g = 0;
135
		if(isset($_POST['dir_g_r']) AND $_POST['dir_g_r'] == 'true') {
136
			$g = $g+4;
137
		}
138
		if(isset($_POST['dir_g_w']) AND $_POST['dir_g_w'] == 'true') {
139
			$g = $g+2;
140
		}
141
		if(isset($_POST['dir_g_e']) AND $_POST['dir_g_e'] == 'true') {
142
			$g = $g+1;
143
		}
144
		$o = 0;
145
		if(isset($_POST['dir_o_r']) AND $_POST['dir_o_r'] == 'true') {
146
			$o = $o+4;
147
		}
148
		if(isset($_POST['dir_o_w']) AND $_POST['dir_o_w'] == 'true') {
149
			$o = $o+2;
150
		}
151
		if(isset($_POST['dir_o_e']) AND $_POST['dir_o_e'] == 'true') {
152
			$o = $o+1;
153
		}
154
		$dir_mode = "0".$u.$g.$o;
155
	}
156
	
157
	// Rewrite WB_PATH and ADMIN_PATH if on Windows
158
	if($_POST['operating_system']=='windows') {
159
		$WB_PATH = str_replace('/','\\', WB_PATH);
160
		$WB_PATH = str_replace('\\','\\\\', $WB_PATH);
161
		$ADMIN_PATH = str_replace('/','\\', ADMIN_PATH);
162
		$ADMIN_PATH = str_replace('\\','\\\\', $ADMIN_PATH);
163
	} else {
164
		$WB_PATH = WB_PATH;
165
		$ADMIN_PATH = ADMIN_PATH;
166
	}
167
	// Write the remaining settings to the config file
168
	$config_filename = $WB_PATH.'/config.php';
169
	$config_content = "" .
170
	"<?php \n".
171
	"define('DB_TYPE', '".DB_TYPE."');\n".
172
	"define('DB_HOST', '".DB_HOST."');\n".
173
	"define('DB_USERNAME', '".DB_USERNAME."');\n".
174
	"define('DB_PASSWORD', '".DB_PASSWORD."');\n".
175
	"define('DB_NAME', '".DB_NAME."');\n".
176
	"define('TABLE_PREFIX', '".TABLE_PREFIX."');\n".
177
	"\n".
178
	"define('WB_PATH', '".$WB_PATH."');\n".
179
	"define('WB_URL', '".WB_URL."');\n".
180
	"define('ADMIN_PATH', '".$ADMIN_PATH."');\n".
181
	"define('ADMIN_URL', '".ADMIN_URL."');\n".
182
	"\n".
183
	"?>";
184
	
185
	// Check if file is writable first
186
	if(!is_writable($config_filename)) {
187
		$admin->print_error($MESSAGE['SETTINGS']['UNABLE_WRITE_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);
188
	} else {
189
		// Try and open the config file
190
		if (!$handle = fopen($config_filename, 'w')) {
191
			$admin->print_error($MESSAGE['SETTINGS']['UNABLE_OPEN_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);	
192
		} else {
193
			// Try and write to the config file
194
			if (fwrite($handle, $config_content) === FALSE) {
195
				$admin->print_error($MESSAGE['SETTINGS']['UNABLE_WRITE_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);
196
			} else {
197
				$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
198
			}
199
		}
200
	}
201
	
202
}
203

    
204
$admin->print_footer();
205

    
206
?>
(2-2/3)