Project

General

Profile

1 1289 kweitzel
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18
19
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
20
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
21
22
// Find out if the user was view advanced options or not
23
if($_POST['advanced'] == 'yes' ? $advanced = '?advanced=yes' : $advanced = '');
24
25
// Print admin header
26
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28
if($advanced == '') {
29
	$admin = new admin('Settings', 'settings_basic');
30
	$_POST['database_password'] = DB_PASSWORD;
31
} else {
32
	$admin = new admin('Settings', 'settings_advanced');
33
}
34
35
// Create a javascript back link
36
$js_back = "javascript: history.go(-1);";
37
38
// Ensure that the specified default email is formally valid
39
if(isset($_POST['server_email']))
40
{
41
	$_POST['server_email'] = strip_tags($_POST['server_email']);
42
	if(!eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['server_email'])) {
43
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'].
44
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
45
	}
46
}
47
48
// Work-out file mode
49
if($advanced == '')
50
{
51
	// Check if should be set to 777 or left alone
52
	if(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true')
53
    {
54
		$file_mode = '0777';
55
		$dir_mode = '0777';
56
	} else {
57
		$file_mode = STRING_FILE_MODE;
58
		$dir_mode = STRING_DIR_MODE;
59
	}
60
} else {
61
	// Work-out the octal value for file mode
62
	$u = 0;
63
	if(isset($_POST['file_u_r']) AND $_POST['file_u_r'] == 'true') {
64
		$u = $u+4;
65
	}
66
	if(isset($_POST['file_u_w']) AND $_POST['file_u_w'] == 'true') {
67
		$u = $u+2;
68
	}
69
	if(isset($_POST['file_u_e']) AND $_POST['file_u_e'] == 'true') {
70
		$u = $u+1;
71
	}
72
	$g = 0;
73
	if(isset($_POST['file_g_r']) AND $_POST['file_g_r'] == 'true') {
74
		$g = $g+4;
75
	}
76
	if(isset($_POST['file_g_w']) AND $_POST['file_g_w'] == 'true') {
77
		$g = $g+2;
78
	}
79
	if(isset($_POST['file_g_e']) AND $_POST['file_g_e'] == 'true') {
80
		$g = $g+1;
81
	}
82
	$o = 0;
83
	if(isset($_POST['file_o_r']) AND $_POST['file_o_r'] == 'true') {
84
		$o = $o+4;
85
	}
86
	if(isset($_POST['file_o_w']) AND $_POST['file_o_w'] == 'true') {
87
		$o = $o+2;
88
	}
89
	if(isset($_POST['file_o_e']) AND $_POST['file_o_e'] == 'true') {
90
		$o = $o+1;
91
	}
92
	$file_mode = "0".$u.$g.$o;
93
	// Work-out the octal value for dir mode
94
	$u = 0;
95
	if(isset($_POST['dir_u_r']) AND $_POST['dir_u_r'] == 'true') {
96
		$u = $u+4;
97
	}
98
	if(isset($_POST['dir_u_w']) AND $_POST['dir_u_w'] == 'true') {
99
		$u = $u+2;
100
	}
101
	if(isset($_POST['dir_u_e']) AND $_POST['dir_u_e'] == 'true') {
102
		$u = $u+1;
103
	}
104
	$g = 0;
105
	if(isset($_POST['dir_g_r']) AND $_POST['dir_g_r'] == 'true') {
106
		$g = $g+4;
107
	}
108
	if(isset($_POST['dir_g_w']) AND $_POST['dir_g_w'] == 'true') {
109
		$g = $g+2;
110
	}
111
	if(isset($_POST['dir_g_e']) AND $_POST['dir_g_e'] == 'true') {
112
		$g = $g+1;
113
	}
114
	$o = 0;
115
	if(isset($_POST['dir_o_r']) AND $_POST['dir_o_r'] == 'true') {
116
		$o = $o+4;
117
	}
118
	if(isset($_POST['dir_o_w']) AND $_POST['dir_o_w'] == 'true') {
119
		$o = $o+2;
120
	}
121
	if(isset($_POST['dir_o_e']) AND $_POST['dir_o_e'] == 'true') {
122
		$o = $o+1;
123
	}
124
	$dir_mode = "0".$u.$g.$o;
125
}
126
127
// Create new database object
128
/*$database = new database(); */
129
130
// Query current settings in the db, then loop through them and update the db with the new value
131
$query = "SELECT name FROM ".TABLE_PREFIX."settings";
132
$results = $database->query($query);
133
while($setting = $results->fetchRow())
134
{
135
	$setting_name = $setting['name'];
136
	$value = $admin->get_post($setting_name);
137
	if ($setting_name!='wb_version')
138
    {
139
		$allow_tags_in_fields = array('website_header', 'website_footer','wbmailer_smtp_password');
140
		if(!in_array($setting_name, $allow_tags_in_fields)) {
141
			$value = strip_tags($value);
142
		}
143
		switch ($setting_name) {
144
			case 'default_timezone':
145
				$value=$value*60*60;
146
				break;
147
			case 'string_dir_mode':
148
				$value=$dir_mode;
149
				break;
150
			case 'string_file_mode':
151
				$value=$file_mode;
152
				break;
153
			case 'pages_directory':
154
				if(trim($value)=='/') $value='';
155
				break;
156
		}
157
		$value = $admin->add_slashes($value);
158
		$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
159
	}
160
}
161
162
// Query current search settings in the db, then loop through them and update the db with the new value
163
$query = "SELECT name, value FROM ".TABLE_PREFIX."search WHERE extra = ''";
164
$results = $database->query($query);
165
while($search_setting = $results->fetchRow())
166
{
167
	$old_value = $search_setting['value'];
168
	$setting_name = $search_setting['name'];
169
	$post_name = 'search_'.$search_setting['name'];
170
    // hold old value if post is empty
171
    // check search template
172
    $value = ( ($admin->get_post($post_name) == '') AND ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
173
174
	$value = $admin->add_slashes($value);
175
	$database->query("UPDATE ".TABLE_PREFIX."search SET value = '$value' WHERE name = '$setting_name'");
176
}
177
178
// Check if there was an error updating the db
179
if($database->is_error()) {
180
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
181
	$admin->print_footer();
182
	exit();
183
}
184
185
$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
186
$admin->print_footer();
187
188
?>