Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 109 2005-09-15 19:56:01Z 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
//print_r($_POST);
40

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

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

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