Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 96 2005-09-13 07:14:08Z 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
// Work-out file mode
40
if($advanced == '') {
41
	// Check if should be set to 777 or left alone
42
	if(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
43
		$file_mode = '0777';
44
		$dir_mode = '0777';
45
	} else {
46
		$file_mode = STRING_FILE_MODE;
47
		$dir_mode = STRING_DIR_MODE;
48
	}
49
} else {
50
	// Work-out the octal value for file mode
51
	$u = 0;
52
	if(isset($_POST['file_u_r']) AND $_POST['file_u_r'] == 'true') {
53
		$u = $u+4;
54
	}
55
	if(isset($_POST['file_u_w']) AND $_POST['file_u_w'] == 'true') {
56
		$u = $u+2;
57
	}
58
	if(isset($_POST['file_u_e']) AND $_POST['file_u_e'] == 'true') {
59
		$u = $u+1;
60
	}
61
	$g = 0;
62
	if(isset($_POST['file_g_r']) AND $_POST['file_g_r'] == 'true') {
63
		$g = $g+4;
64
	}
65
	if(isset($_POST['file_g_w']) AND $_POST['file_g_w'] == 'true') {
66
		$g = $g+2;
67
	}
68
	if(isset($_POST['file_g_e']) AND $_POST['file_g_e'] == 'true') {
69
		$g = $g+1;
70
	}
71
	$o = 0;
72
	if(isset($_POST['file_o_r']) AND $_POST['file_o_r'] == 'true') {
73
		$o = $o+4;
74
	}
75
	if(isset($_POST['file_o_w']) AND $_POST['file_o_w'] == 'true') {
76
		$o = $o+2;
77
	}
78
	if(isset($_POST['file_o_e']) AND $_POST['file_o_e'] == 'true') {
79
		$o = $o+1;
80
	}
81
	$file_mode = "0".$u.$g.$o;
82
	// Work-out the octal value for dir mode
83
	$u = 0;
84
	if(isset($_POST['dir_u_r']) AND $_POST['dir_u_r'] == 'true') {
85
		$u = $u+4;
86
	}
87
	if(isset($_POST['dir_u_w']) AND $_POST['dir_u_w'] == 'true') {
88
		$u = $u+2;
89
	}
90
	if(isset($_POST['dir_u_e']) AND $_POST['dir_u_e'] == 'true') {
91
		$u = $u+1;
92
	}
93
	$g = 0;
94
	if(isset($_POST['dir_g_r']) AND $_POST['dir_g_r'] == 'true') {
95
		$g = $g+4;
96
	}
97
	if(isset($_POST['dir_g_w']) AND $_POST['dir_g_w'] == 'true') {
98
		$g = $g+2;
99
	}
100
	if(isset($_POST['dir_g_e']) AND $_POST['dir_g_e'] == 'true') {
101
		$g = $g+1;
102
	}
103
	$o = 0;
104
	if(isset($_POST['dir_o_r']) AND $_POST['dir_o_r'] == 'true') {
105
		$o = $o+4;
106
	}
107
	if(isset($_POST['dir_o_w']) AND $_POST['dir_o_w'] == 'true') {
108
		$o = $o+2;
109
	}
110
	if(isset($_POST['dir_o_e']) AND $_POST['dir_o_e'] == 'true') {
111
		$o = $o+1;
112
	}
113
	$dir_mode = "0".$u.$g.$o;
114
}
115

    
116
// Create new database object
117
$database = new database();
118

    
119
// Query current settings in the db, then loop through them and update the db with the new value
120
$query = "SELECT name FROM ".TABLE_PREFIX."settings";
121
$results = $database->query($query);
122
while($setting = $results->fetchRow()) {
123
	$setting_name = $setting['name'];
124
	$value = $admin->get_post($setting_name);
125
	$value = $admin->add_slashes($value);
126
	switch ($setting_name) {
127
		case 'default_timezone':
128
			$value=$value*60*60;
129
			break;
130
		case 'string_dir_mode':
131
			$value=$dir_mode;
132
			break;
133
		case 'string_file_mode':
134
			$value=$file_mode;
135
			break;
136
	}
137
	$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
138
}
139

    
140
// Query current search settings in the db, then loop through them and update the db with the new value
141
$query = "SELECT name FROM ".TABLE_PREFIX."search WHERE extra = ''";
142
$results = $database->query($query);
143
while($search_setting = $results->fetchRow()) {
144
	$setting_name = $search_setting['name'];
145
	$post_name = 'search_'.$search_setting['name'];
146
	$value = $admin->get_post($post_name);
147
	$value = $admin->add_slashes($value);
148
	$database->query("UPDATE ".TABLE_PREFIX."search SET value = '$value' WHERE name = '$setting_name'");
149
}
150

    
151
// Check if there was an error updating the db
152
if($database->is_error()) {
153
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
154
	$admin->print_footer();
155
	exit();
156
}
157

    
158
// Get timezone offset
159
$timezone_offset = $_POST['timezone']*60*60;
160
// Work out what code to put in for error reporting
161
if($_POST['er_level'] == '') {
162
	$er_level = '';
163
	$er_level_code = '';
164
} else {
165
	$er_level = $_POST['er_level'];
166
	$er_level_code = "error_reporting('".$_POST['er_level']."');\n";
167
}
168
// Work-out database type, and whether or not to use PEAR
169
$database_type = $admin->get_post('database_type');
170

    
171
// Rewrite WB_PATH and ADMIN_PATH if on Windows
172
if($_POST['operating_system']=='windows') {
173
	$WB_PATH = str_replace('/','\\', WB_PATH);
174
	$WB_PATH = str_replace('\\','\\\\', $WB_PATH);
175
	$ADMIN_PATH = str_replace('/','\\', ADMIN_PATH);
176
	$ADMIN_PATH = str_replace('\\','\\\\', $ADMIN_PATH);
177
} else {
178
	$WB_PATH = WB_PATH;
179
	$ADMIN_PATH = ADMIN_PATH;
180
}
181
// Write the remaining settings to the config file
182
$config_filename = $WB_PATH.'/config.php';
183
$config_content = "" .
184
"<?php \n".
185
"define('DB_TYPE', '".DB_TYPE."');\n".
186
"define('DB_HOST', '".DB_HOST."');\n".
187
"define('DB_USERNAME', '".DB_USERNAME."');\n".
188
"define('DB_PASSWORD', '".DB_PASSWORD."');\n".
189
"define('DB_NAME', '".DB_NAME."');\n".
190
"define('TABLE_PREFIX', '".TABLE_PREFIX."');\n".
191
"\n".
192
"define('WB_PATH', '".$WB_PATH."');\n".
193
"define('WB_URL', '".WB_URL."');\n".
194
"define('ADMIN_PATH', '".$ADMIN_PATH."');\n".
195
"define('ADMIN_URL', '".ADMIN_URL."');\n".
196
"\n".
197
"?>";
198

    
199
// Check if file is writable first
200
if(!is_writable($config_filename)) {
201
	$admin->print_error($MESSAGE['SETTINGS']['UNABLE_WRITE_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);
202
} else {
203
	// Try and open the config file
204
	if (!$handle = fopen($config_filename, 'w')) {
205
		$admin->print_error($MESSAGE['SETTINGS']['UNABLE_OPEN_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);	
206
	} else {
207
		// Try and write to the config file
208
		if (fwrite($handle, $config_content) === FALSE) {
209
			$admin->print_error($MESSAGE['SETTINGS']['UNABLE_WRITE_CONFIG'], ADMIN_URL.'/settings/index.php'.$advanced);
210
		} else {
211
			$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
212
		}
213
	}
214
}
215

    
216
$admin->print_footer();
217

    
218
?>
(2-2/3)