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 1745 2012-09-08 13:06:55Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-09-08 15:06:55 +0200 (Sat, 08 Sep 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
	if(!$admin->validate_email($_POST['server_email']))
54
    {
55
		$admin->print_error($MESSAGE['USERS_INVALID_EMAIL'].
56
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
57
	}
58
}
59

    
60
if(isset($_POST['wbmailer_routine']) && ($_POST['wbmailer_routine']=='smtp')) {
61

    
62
	$checkSmtpHost = (isset($_POST['wbmailer_smtp_host']) && ($_POST['wbmailer_smtp_host']=='') ? false : true);
63
	$checkSmtpUser = (isset($_POST['wbmailer_smtp_username']) && ($_POST['wbmailer_smtp_username']=='') ? false : true);
64
	$checkSmtpPassword = (isset($_POST['wbmailer_smtp_password']) && ($_POST['wbmailer_smtp_password']=='') ? false : true);
65
	if(!$checkSmtpHost || !$checkSmtpUser || !$checkSmtpPassword) {
66
		$admin->print_error($TEXT['REQUIRED'].' '.$TEXT['WBMAILER_SMTP_AUTH'].
67
			'<br /><strong>'.$MESSAGE['GENERIC_FILL_IN_ALL'].'</strong>', $js_back);
68
	}
69

    
70
}
71

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

    
156
$allow_tags_in_fields = array('website_header', 'website_footer','website_signature');
157
$allow_empty_values = array('website_header','website_footer','pages_directory','page_spacer','website_signature,page_icon_dir');
158
$disallow_in_fields = array('pages_directory', 'media_directory','wb_version');
159

    
160
// Query current settings in the db, then loop through them and update the db with the new value
161
$settings = array();
162
$old_settings = array();
163
// Query current settings in the db, then loop through them to get old values
164
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
165
$sql .= 'ORDER BY `name`';
166

    
167
if($res_settings = $database->query($sql)) {
168
	$passed = false;
169
	while($setting = $res_settings->fetchRow())
170
	{
171
		$old_settings[$setting['name']] = $setting['value'];
172
		$setting_name = $setting['name'];
173
		$value = $admin->get_post($setting_name);
174
		$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
175
		switch ($setting_name) {
176
			case 'default_timezone':
177
				$value=$value*60*60;
178
				$passed = true;
179
				break;
180
			case 'string_dir_mode':
181
				$value=$dir_mode;
182
				$passed = true;
183
				break;
184
			case 'string_file_mode':
185
				$value=$file_mode;
186
	 			$passed = true;
187
			break;
188
			case 'sec_anchor':
189
				$value=(($value=='') ? 'section_' : $value);
190
	 			$passed = true;
191
			case 'pages_directory':
192
				break;
193
			case 'wbmailer_smtp_auth':
194
				// $value = isset($_POST[$setting_name]) ? $_POST[$setting_name] : '' ;
195
				$value = true ;
196
	 			$passed = true;
197
				break;
198
			default :
199
			    $passed = in_array($setting_name, $allow_empty_values);
200
				break;
201
		}
202

    
203
	    if (!in_array($setting_name, $allow_tags_in_fields))
204
	    {
205
	        $value = strip_tags($value);
206
	    }
207

    
208
	    if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
209
	    {
210
	        $value = trim($admin->add_slashes($value));
211
	        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
212
	        $sql .= 'SET `value` = \''.$value.'\' ';
213
	        $sql .= 'WHERE `name` != \'wb_version\' ';
214
	        $sql .= 'AND `name` = \''.$setting_name.'\' ';
215

    
216
	        if (!$database->query($sql))
217
	        {
218
				if($database->is_error()) {
219
					$admin->print_error($database->get_error, $js_back );
220
				}
221
	        }
222
		}
223
	}
224
}
225

    
226
// Query current search settings in the db, then loop through them and update the db with the new value
227
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
228
$sql .= 'WHERE `extra` = ""';
229
$res_search = $database->query($sql);
230

    
231
if($database->is_error()) {
232
	$admin->print_error($database->is_error(), $js_back );
233
}
234

    
235
while($search_setting = $res_search->fetchRow())
236
{
237
	$old_value = $search_setting['value'];
238
	$setting_name = $search_setting['name'];
239
	$post_name = 'search_'.$search_setting['name'];
240

    
241
    // hold old value if post is empty
242
    // check search template
243
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
244
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
245
    if(isset($value))
246
	{
247
		$value = $admin->add_slashes($value);
248
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
249
        $sql .= 'SET `value` = "'.$value.'" ';
250
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
251
        $sql .= 'AND `extra` = ""';
252
		if($database->query($sql)) {
253
		}
254
		$sql_info = mysql_info($database->db_handle);
255
    }
256
}
257

    
258
// Check if there was an error updating the db
259
if($database->is_error()) {
260
	$admin->print_error($database->get_error, $js_back );
261
} else {
262
	$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
263
}
264
$admin->print_footer();
(2-2/3)