Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: save.php 1567 2012-01-07 06:14:53Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-01-07 07:14:53 +0100 (Sat, 07 Jan 2012) $
15
 *
16
 */
17

    
18
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
19
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
20

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

    
24
// Print admin header
25
require('../../config.php');
26
require_once(WB_PATH.'/framework/class.admin.php');
27

    
28
// suppress to print the header, so no new FTAN will be set
29
if($advanced == '')
30
{
31
	$admin = new admin('Settings', 'settings_basic',false);
32
} else {
33
	$admin = new admin('Settings', 'settings_advanced',false);
34
}
35

    
36
// Create a javascript back link
37
$js_back = ADMIN_URL.'/settings/index.php'.$advanced;
38
if( !$admin->checkFTAN() )
39
{
40
	$admin->print_header();
41
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back );
42
}
43
// After check print the header
44
$admin->print_header();
45

    
46
// Ensure that the specified default email is formally valid
47
if(isset($_POST['server_email']))
48
{
49
	$_POST['server_email'] = strip_tags($_POST['server_email']);
50
    // $pattern = '/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?\r/im';
51
    $pattern = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,6}))$/';
52
    if(false == preg_match($pattern, $_POST['server_email']))
53
    {
54
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'].
55
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
56
	}
57
}
58

    
59
// Work-out file mode
60
if($advanced == '')
61
{
62
	// Check if should be set to 777 or left alone
63
	if(isset($_POST['world_writeable']) && $_POST['world_writeable'] == 'true')
64
    {
65
		$file_mode = '0777';
66
		$dir_mode = '0777';
67
	} else {
68
		$file_mode = STRING_FILE_MODE;
69
		$dir_mode = STRING_DIR_MODE;
70
	}
71
} else {
72
	// Work-out the octal value for file mode
73
	$u = 0;
74
	if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
75
		$u = $u+4;
76
	}
77
	if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
78
		$u = $u+2;
79
	}
80
	if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
81
		$u = $u+1;
82
	}
83
	$g = 0;
84
	if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
85
		$g = $g+4;
86
	}
87
	if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
88
		$g = $g+2;
89
	}
90
	if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
91
		$g = $g+1;
92
	}
93
	$o = 0;
94
	if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
95
		$o = $o+4;
96
	}
97
	if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
98
		$o = $o+2;
99
	}
100
	if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
101
		$o = $o+1;
102
	}
103
	$file_mode = "0".$u.$g.$o;
104
	// Work-out the octal value for dir mode
105
	$u = 0;
106
	if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
107
		$u = $u+4;
108
	}
109
	if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
110
		$u = $u+2;
111
	}
112
	if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
113
		$u = $u+1;
114
	}
115
	$g = 0;
116
	if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
117
		$g = $g+4;
118
	}
119
	if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
120
		$g = $g+2;
121
	}
122
	if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
123
		$g = $g+1;
124
	}
125
	$o = 0;
126
	if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
127
		$o = $o+4;
128
	}
129
	if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
130
		$o = $o+2;
131
	}
132
	if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
133
		$o = $o+1;
134
	}
135
	$dir_mode = "0".$u.$g.$o;
136
}
137

    
138
$allow_tags_in_fields = array('website_header', 'website_footer');
139
$allow_empty_values = array('website_header','website_footer','sec_anchor','pages_directory','page_spacer');
140
$disallow_in_fields = array('pages_directory', 'media_directory','wb_version');
141
// Create new database object
142
/*$database = new database(); */
143

    
144
// Query current settings in the db, then loop through them and update the db with the new value
145
$settings = array();
146
$old_settings = array();
147
// Query current settings in the db, then loop through them to get old values
148
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
149
$sql .= 'ORDER BY `name`';
150

    
151
$res_settings = $database->query($sql);
152
$passed = false;
153
while($setting = $res_settings->fetchRow())
154
{
155
	$old_settings[$setting['name']] = $setting['value'];
156
	$setting_name = $setting['name'];
157
	$value = $admin->get_post($setting_name);
158
	$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
159
	switch ($setting_name) {
160
		case 'default_timezone':
161
			$value=$value*60*60;
162
			$passed = true;
163
			break;
164
		case 'string_dir_mode':
165
			$value=$dir_mode;
166
			$passed = true;
167
			break;
168
		case 'string_file_mode':
169
			$value=$file_mode;
170
 			$passed = true;
171
		break;
172
		case 'pages_directory':
173
			break;
174
		case 'wbmailer_smtp_auth':
175
			$value = isset($_POST[$setting_name]) ? $_POST[$setting_name] : '' ;
176
 			$passed = true;
177
			break;
178
		default :
179
		    $passed = in_array($setting_name, $allow_empty_values);
180
			break;
181
	}
182
    if (!in_array($setting_name, $allow_tags_in_fields))
183
    {
184
        $value = strip_tags($value);
185
    }
186

    
187

    
188
    if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
189
    {
190
        $value = trim($admin->add_slashes($value));
191
        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
192
        $sql .= 'SET `value` = \''.$value.'\' ';
193
        $sql .= 'WHERE `name` <> \'wb_version\' ';
194
        $sql .= 'AND `name` = \''.$setting_name.'\' ';
195

    
196
        if (!$database->query($sql))
197
        {
198
			if($database->is_error()) {
199
				$admin->print_error($database->get_error, $js_back );
200
			}
201
        }
202
	}
203
}
204

    
205
// Query current search settings in the db, then loop through them and update the db with the new value
206
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
207
$sql .= 'WHERE `extra` = ""';
208
$res_search = $database->query($sql);
209

    
210
if($database->is_error()) {
211
	$admin->print_error($database->is_error(), $js_back );
212
}
213

    
214
while($search_setting = $res_search->fetchRow())
215
{
216
	$old_value = $search_setting['value'];
217
	$setting_name = $search_setting['name'];
218
	$post_name = 'search_'.$search_setting['name'];
219

    
220
    // hold old value if post is empty
221
    // check search template
222
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
223
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
224
    if(isset($value))
225
	{
226
		$value = $admin->add_slashes($value);
227
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
228
        $sql .= 'SET `value` = "'.$value.'" ';
229
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
230
        $sql .= 'AND `extra` = ""';
231
		if($database->query($sql)) {
232
		}
233
		$sql_info = mysql_info($database->db_handle);
234
    }
235
}
236

    
237
// Check if there was an error updating the db
238
if($database->is_error()) {
239
	$admin->print_error($database->get_error, $js_back );
240
} else {
241
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], $js_back );
242
}
243
$admin->print_footer();
(2-2/3)