Project

General

Profile

1 1348 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7 1716 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1348 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1348 Luisehahne
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
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 1767 Luisehahne
require_once(WB_PATH.'/framework/functions.php');
28 1348 Luisehahne
29 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
30 1348 Luisehahne
if($advanced == '')
31
{
32 1457 Luisehahne
	$admin = new admin('Settings', 'settings_basic',false);
33 1348 Luisehahne
} else {
34 1457 Luisehahne
	$admin = new admin('Settings', 'settings_advanced',false);
35 1348 Luisehahne
}
36
37 1425 Luisehahne
// Create a javascript back link
38
$js_back = ADMIN_URL.'/settings/index.php'.$advanced;
39 1355 FrankH
if( !$admin->checkFTAN() )
40
{
41 1457 Luisehahne
	$admin->print_header();
42 1425 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$js_back );
43 1355 FrankH
}
44 1457 Luisehahne
// After check print the header
45
$admin->print_header();
46 1355 FrankH
47 1348 Luisehahne
// Ensure that the specified default email is formally valid
48
if(isset($_POST['server_email']))
49
{
50
	$_POST['server_email'] = strip_tags($_POST['server_email']);
51 1716 Luisehahne
//    // $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';
52
//    $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}))$/';
53
//    if(false == preg_match($pattern, $_POST['server_email']))
54
	if(!$admin->validate_email($_POST['server_email']))
55 1348 Luisehahne
    {
56 1572 Luisehahne
		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'].
57 1348 Luisehahne
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
58
	}
59
}
60
61 1777 Luisehahne
if($admin->StripCodeFromText($admin->get_post('wbmailer_routine'))=='smtp') {
62 1572 Luisehahne
63 1777 Luisehahne
	$checkSmtpHost = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_host'))=='') ? false : true);
64
//	$checkSmtpHost = (isset($_POST['wbmailer_smtp_host']) && ($_POST['wbmailer_smtp_host']=='') ? false : true);
65
	$checkSmtpUser = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_username'))=='') ? false : true);
66
//	$checkSmtpUser = (isset($_POST['wbmailer_smtp_username']) && ($_POST['wbmailer_smtp_username']=='') ? false : true);
67
	$checkSmtpPassword = (($admin->StripCodeFromText($admin->get_post('wbmailer_smtp_password'))=='') ? false : true);
68
//	$checkSmtpPassword = (isset($_POST['wbmailer_smtp_password']) && ($_POST['wbmailer_smtp_password']=='') ? false : true);
69
70 1572 Luisehahne
	if(!$checkSmtpHost || !$checkSmtpUser || !$checkSmtpPassword) {
71
		$admin->print_error($TEXT['REQUIRED'].' '.$TEXT['WBMAILER_SMTP_AUTH'].
72
			'<br /><strong>'.$MESSAGE['GENERIC_FILL_IN_ALL'].'</strong>', $js_back);
73
	}
74
75
}
76
77 1348 Luisehahne
// Work-out file mode
78
if($advanced == '')
79
{
80 1777 Luisehahne
	$file_mode = STRING_FILE_MODE;
81
	$dir_mode = STRING_DIR_MODE;
82 1348 Luisehahne
	// Check if should be set to 777 or left alone
83 1777 Luisehahne
//	if(isset($_POST['world_writeable']) && $_POST['world_writeable'] == 'true')
84
//    {
85
//		$file_mode = '0777';
86
//		$dir_mode = '0777';
87
//	} else {
88
//		$file_mode = STRING_FILE_MODE;
89
//		$dir_mode = STRING_DIR_MODE;
90
//	}
91 1348 Luisehahne
} else {
92 1577 Luisehahne
	$file_mode = STRING_FILE_MODE;
93
	$dir_mode = STRING_DIR_MODE;
94
	if($admin->get_user_id()=='1')
95
	{
96
		// Work-out the octal value for file mode
97
		$u = 0;
98
		if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
99
			$u = $u+4;
100
		}
101
		if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
102
			$u = $u+2;
103
		}
104
		if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
105
			$u = $u+1;
106
		}
107
		$g = 0;
108
		if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
109
			$g = $g+4;
110
		}
111
		if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
112
			$g = $g+2;
113
		}
114
		if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
115
			$g = $g+1;
116
		}
117
		$o = 0;
118
		if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
119
			$o = $o+4;
120
		}
121
		if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
122
			$o = $o+2;
123
		}
124
		if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
125
			$o = $o+1;
126
		}
127
		$file_mode = "0".$u.$g.$o;
128
		// Work-out the octal value for dir mode
129
		$u = 0;
130
		if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
131
			$u = $u+4;
132
		}
133
		if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
134
			$u = $u+2;
135
		}
136
		if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
137
			$u = $u+1;
138
		}
139
		$g = 0;
140
		if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
141
			$g = $g+4;
142
		}
143
		if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
144
			$g = $g+2;
145
		}
146
		if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
147
			$g = $g+1;
148
		}
149
		$o = 0;
150
		if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
151
			$o = $o+4;
152
		}
153
		if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
154
			$o = $o+2;
155
		}
156
		if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
157
			$o = $o+1;
158
		}
159
		$dir_mode = "0".$u.$g.$o;
160 1348 Luisehahne
	}
161
}
162
163 1777 Luisehahne
$allow_tags_in_fields = array(
164
    'website_header',
165
    'website_footer',
166
    'website_signature'
167
    );
168
$allow_empty_values = array(
169
    'website_header',
170
    'website_footer',
171
    'website_signature',
172
    'wysiwyg_style',
173
    'pages_directory',
174
    'page_icon_dir',
175
    'rename_files_on_upload',
176
    'page_spacer',
177
    'website_signature',
178
    'page_icon_dir',
179
    'modules_upgrade_list'
180
    );
181
$disallow_in_fields = array(
182
    'pages_directory',
183
    'media_directory',
184
    'wb_version'
185
    );
186
$StripCodeFromInput = array(
187
    'website_title',
188
    'website_description',
189
    'website_keywords',
190
    'wysiwyg_style',
191
    'search_module_order',
192
    'search_max_excerpt',
193
    'search_time_limit',
194
    'pages_directory',
195
    'page_icon_dir',
196
    'media_directory',
197
    'page_extension',
198
    'rename_files_on_upload',
199
    'page_spacer',
200
    'page_icon_dir',
201
    'modules_upgrade_list'
202
    );
203 1348 Luisehahne
204 1767 Luisehahne
$bRebuildAccessFiles = ( (isset( $_POST['rebuild_access_files']) && ( $_POST['rebuild_access_files'] == true )) ? true : false ) ;
205
206 1348 Luisehahne
// Query current settings in the db, then loop through them and update the db with the new value
207 1354 Luisehahne
$settings = array();
208
$old_settings = array();
209
// Query current settings in the db, then loop through them to get old values
210
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
211
$sql .= 'ORDER BY `name`';
212
213 1572 Luisehahne
if($res_settings = $database->query($sql)) {
214
	$passed = false;
215
	while($setting = $res_settings->fetchRow())
216
	{
217
		$setting_name = $setting['name'];
218 1767 Luisehahne
		$old_settings[$setting_name] = $setting['value'];
219 1572 Luisehahne
		$value = $admin->get_post($setting_name);
220
		$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
221
		switch ($setting_name) {
222
			case 'default_timezone':
223
				$value=$value*60*60;
224
				$passed = true;
225
				break;
226
			case 'string_dir_mode':
227
				$value=$dir_mode;
228
				$passed = true;
229
				break;
230
			case 'string_file_mode':
231
				$value=$file_mode;
232
	 			$passed = true;
233 1767 Luisehahne
    			break;
234 1745 Luisehahne
			case 'sec_anchor':
235 1777 Luisehahne
                $value = $admin->StripCodeFromText($value);
236 1745 Luisehahne
				$value=(($value=='') ? 'section_' : $value);
237
	 			$passed = true;
238 1767 Luisehahne
				break;
239 1572 Luisehahne
			case 'pages_directory':
240 1777 Luisehahne
                $value = $admin->StripCodeFromText($value);
241 1767 Luisehahne
                $bNewPageFile = ( ( $value!= $old_settings['pages_directory'] ) ? true :  false );
242
	 			$passed = $bNewPageFile;
243
                $sGetId = '&amp;id='.$bNewPageFile;
244
//                if(!is_dir(WB_PATH.$value) && is_writable(WB_PATH)) {
245
//                    $passed = make_dir(WB_PATH.$value);
246
//                }
247
                $value  = (($passed == true) ? $value : $old_settings['pages_directory']);
248
                $sPageDirectory = $value;
249 1572 Luisehahne
				break;
250
			case 'wbmailer_smtp_auth':
251
				// $value = isset($_POST[$setting_name]) ? $_POST[$setting_name] : '' ;
252
				$value = true ;
253
	 			$passed = true;
254
				break;
255
			default :
256 1777 Luisehahne
                $passed = in_array($setting_name, $allow_empty_values);
257
                if(in_array($setting_name, $StripCodeFromInput) ) {
258
                    $value = $admin->StripCodeFromText($value);
259
                }
260 1572 Luisehahne
				break;
261
		}
262 1348 Luisehahne
263 1572 Luisehahne
	    if (!in_array($setting_name, $allow_tags_in_fields))
264
	    {
265
	        $value = strip_tags($value);
266
	    }
267 1348 Luisehahne
268 1572 Luisehahne
	    if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
269
	    {
270
	        $value = trim($admin->add_slashes($value));
271
	        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
272 1777 Luisehahne
	        $sql .= 'SET `value` = \''.($value).'\' '; // mysql_escape_string
273 1572 Luisehahne
	        $sql .= 'WHERE `name` != \'wb_version\' ';
274
	        $sql .= 'AND `name` = \''.$setting_name.'\' ';
275
	        if (!$database->query($sql))
276
	        {
277
				if($database->is_error()) {
278
					$admin->print_error($database->get_error, $js_back );
279
				}
280
	        }
281
		}
282 1348 Luisehahne
	}
283 1767 Luisehahne
284
    if(($bRebuildAccessFiles==true) && ($_POST['modules_upgrade_list']!='') && ($sPageDirectory==$old_settings['pages_directory']) ) {
285
        rebuild_all_accessfiles();
286
        $aModuleList = ( explode(',', $_POST['modules_upgrade_list']));
287
        upgrade_modules($aModuleList);
288
    }
289
290 1348 Luisehahne
}
291 1777 Luisehahne
$StripCodeFromISearch = array(
292
    'search_module_order',
293
    'search_max_excerpt',
294
    'search_time_limit',
295
    );
296 1348 Luisehahne
297
// Query current search settings in the db, then loop through them and update the db with the new value
298
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
299
$sql .= 'WHERE `extra` = ""';
300
$res_search = $database->query($sql);
301
302
if($database->is_error()) {
303 1425 Luisehahne
	$admin->print_error($database->is_error(), $js_back );
304 1348 Luisehahne
}
305
306
while($search_setting = $res_search->fetchRow())
307
{
308
	$old_value = $search_setting['value'];
309
	$setting_name = $search_setting['name'];
310 1777 Luisehahne
	$post_name = 'search_'.$setting_name;
311 1348 Luisehahne
312
    // hold old value if post is empty
313
    // check search template
314 1777 Luisehahne
    $value = ($admin->get_post($post_name));
315
    if(in_array($post_name, $StripCodeFromISearch) ) {
316
        $value = $admin->StripCodeFromText($value);
317
    }
318
    $value = ( ($value == '') && ($setting_name != 'template') ) ? $old_value : $value;
319 1348 Luisehahne
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
320
    if(isset($value))
321
	{
322
		$value = $admin->add_slashes($value);
323
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
324
        $sql .= 'SET `value` = "'.$value.'" ';
325
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
326
        $sql .= 'AND `extra` = ""';
327
		if($database->query($sql)) {
328
		}
329
		$sql_info = mysql_info($database->db_handle);
330
    }
331
}
332
333
// Check if there was an error updating the db
334
if($database->is_error()) {
335 1425 Luisehahne
	$admin->print_error($database->get_error, $js_back );
336 1348 Luisehahne
} else {
337 1731 Luisehahne
	$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
338 1348 Luisehahne
}
339
$admin->print_footer();