Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker 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 1777 2012-10-01 16:16:26Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-10-01 18:16:26 +0200 (Mon, 01 Oct 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
require_once(WB_PATH.'/framework/functions.php');
28

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

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

    
47
// 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
//    // $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
    {
56
		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'].
57
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
58
	}
59
}
60

    
61
if($admin->StripCodeFromText($admin->get_post('wbmailer_routine'))=='smtp') {
62

    
63
	$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
	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
// Work-out file mode
78
if($advanced == '')
79
{
80
	$file_mode = STRING_FILE_MODE;
81
	$dir_mode = STRING_DIR_MODE;
82
	// Check if should be set to 777 or left alone
83
//	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
} else {
92
	$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
	}
161
}
162

    
163
$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

    
204
$bRebuildAccessFiles = ( (isset( $_POST['rebuild_access_files']) && ( $_POST['rebuild_access_files'] == true )) ? true : false ) ;
205

    
206
// Query current settings in the db, then loop through them and update the db with the new value
207
$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
if($res_settings = $database->query($sql)) {
214
	$passed = false;
215
	while($setting = $res_settings->fetchRow())
216
	{
217
		$setting_name = $setting['name'];
218
		$old_settings[$setting_name] = $setting['value'];
219
		$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
    			break;
234
			case 'sec_anchor':
235
                $value = $admin->StripCodeFromText($value);
236
				$value=(($value=='') ? 'section_' : $value);
237
	 			$passed = true;
238
				break;
239
			case 'pages_directory':
240
                $value = $admin->StripCodeFromText($value);
241
                $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
				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
                $passed = in_array($setting_name, $allow_empty_values);
257
                if(in_array($setting_name, $StripCodeFromInput) ) {
258
                    $value = $admin->StripCodeFromText($value);
259
                }
260
				break;
261
		}
262

    
263
	    if (!in_array($setting_name, $allow_tags_in_fields))
264
	    {
265
	        $value = strip_tags($value);
266
	    }
267

    
268
	    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
	        $sql .= 'SET `value` = \''.($value).'\' '; // mysql_escape_string
273
	        $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
	}
283

    
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
}
291
$StripCodeFromISearch = array(
292
    'search_module_order',
293
    'search_max_excerpt',
294
    'search_time_limit',
295
    );
296

    
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
	$admin->print_error($database->is_error(), $js_back );
304
}
305

    
306
while($search_setting = $res_search->fetchRow())
307
{
308
	$old_value = $search_setting['value'];
309
	$setting_name = $search_setting['name'];
310
	$post_name = 'search_'.$setting_name;
311

    
312
    // hold old value if post is empty
313
    // check search template
314
    $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
    // $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
	$admin->print_error($database->get_error, $js_back );
336
} else {
337
	$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
338
}
339
$admin->print_footer();
(3-3/4)