Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 532 2008-01-13 08:25:24Z doc $
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
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
27
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die("Cannot access this file directly");  
28

    
29
// Find out if the user was view advanced options or not
30
if($_POST['advanced'] == 'yes' ? $advanced = '?advanced=yes' : $advanced = '');
31

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

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

    
119
// Create new database object
120
$database = new database();
121

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

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

    
156
// Check if there was an error updating the db
157
if($database->is_error()) {
158
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
159
	$admin->print_footer();
160
	exit();
161
}
162

    
163
$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
164
$admin->print_footer();
165

    
166
?>
(2-2/3)