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 1577 2012-01-16 18:05:33Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-01-16 19:05:33 +0100 (Mon, 16 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
if(isset($_POST['wbmailer_routine']) && ($_POST['wbmailer_routine']=='smtp')) {
60

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

    
69
}
70

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

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

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

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

    
199
	    if (!in_array($setting_name, $allow_tags_in_fields))
200
	    {
201
	        $value = strip_tags($value);
202
	    }
203

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

    
212
	        if (!$database->query($sql))
213
	        {
214
				if($database->is_error()) {
215
					$admin->print_error($database->get_error, $js_back );
216
				}
217
	        }
218
		}
219
	}
220
}
221

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

    
227
if($database->is_error()) {
228
	$admin->print_error($database->is_error(), $js_back );
229
}
230

    
231
while($search_setting = $res_search->fetchRow())
232
{
233
	$old_value = $search_setting['value'];
234
	$setting_name = $search_setting['name'];
235
	$post_name = 'search_'.$search_setting['name'];
236

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

    
254
// Check if there was an error updating the db
255
if($database->is_error()) {
256
	$admin->print_error($database->get_error, $js_back );
257
} else {
258
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], $js_back );
259
}
260
$admin->print_footer();
(2-2/3)