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 1572 2012-01-14 20:53:04Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-01-14 21:53:04 +0100 (Sat, 14 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
	// Work-out the octal value for file mode
85
	$u = 0;
86
	if(isset($_POST['file_u_r']) && $_POST['file_u_r'] == 'true') {
87
		$u = $u+4;
88
	}
89
	if(isset($_POST['file_u_w']) && $_POST['file_u_w'] == 'true') {
90
		$u = $u+2;
91
	}
92
	if(isset($_POST['file_u_e']) && $_POST['file_u_e'] == 'true') {
93
		$u = $u+1;
94
	}
95
	$g = 0;
96
	if(isset($_POST['file_g_r']) && $_POST['file_g_r'] == 'true') {
97
		$g = $g+4;
98
	}
99
	if(isset($_POST['file_g_w']) && $_POST['file_g_w'] == 'true') {
100
		$g = $g+2;
101
	}
102
	if(isset($_POST['file_g_e']) && $_POST['file_g_e'] == 'true') {
103
		$g = $g+1;
104
	}
105
	$o = 0;
106
	if(isset($_POST['file_o_r']) && $_POST['file_o_r'] == 'true') {
107
		$o = $o+4;
108
	}
109
	if(isset($_POST['file_o_w']) && $_POST['file_o_w'] == 'true') {
110
		$o = $o+2;
111
	}
112
	if(isset($_POST['file_o_e']) && $_POST['file_o_e'] == 'true') {
113
		$o = $o+1;
114
	}
115
	$file_mode = "0".$u.$g.$o;
116
	// Work-out the octal value for dir mode
117
	$u = 0;
118
	if(isset($_POST['dir_u_r']) && $_POST['dir_u_r'] == 'true') {
119
		$u = $u+4;
120
	}
121
	if(isset($_POST['dir_u_w']) && $_POST['dir_u_w'] == 'true') {
122
		$u = $u+2;
123
	}
124
	if(isset($_POST['dir_u_e']) && $_POST['dir_u_e'] == 'true') {
125
		$u = $u+1;
126
	}
127
	$g = 0;
128
	if(isset($_POST['dir_g_r']) && $_POST['dir_g_r'] == 'true') {
129
		$g = $g+4;
130
	}
131
	if(isset($_POST['dir_g_w']) && $_POST['dir_g_w'] == 'true') {
132
		$g = $g+2;
133
	}
134
	if(isset($_POST['dir_g_e']) && $_POST['dir_g_e'] == 'true') {
135
		$g = $g+1;
136
	}
137
	$o = 0;
138
	if(isset($_POST['dir_o_r']) && $_POST['dir_o_r'] == 'true') {
139
		$o = $o+4;
140
	}
141
	if(isset($_POST['dir_o_w']) && $_POST['dir_o_w'] == 'true') {
142
		$o = $o+2;
143
	}
144
	if(isset($_POST['dir_o_e']) && $_POST['dir_o_e'] == 'true') {
145
		$o = $o+1;
146
	}
147
	$dir_mode = "0".$u.$g.$o;
148
}
149

    
150
$allow_tags_in_fields = array('website_header', 'website_footer');
151
$allow_empty_values = array('website_header','website_footer','sec_anchor','pages_directory','page_spacer');
152
$disallow_in_fields = array('pages_directory', 'media_directory','wb_version');
153

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

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

    
194
	    if (!in_array($setting_name, $allow_tags_in_fields))
195
	    {
196
	        $value = strip_tags($value);
197
	    }
198

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

    
207
	        if (!$database->query($sql))
208
	        {
209
				if($database->is_error()) {
210
					$admin->print_error($database->get_error, $js_back );
211
				}
212
	        }
213
		}
214
	}
215
}
216

    
217
// Query current search settings in the db, then loop through them and update the db with the new value
218
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
219
$sql .= 'WHERE `extra` = ""';
220
$res_search = $database->query($sql);
221

    
222
if($database->is_error()) {
223
	$admin->print_error($database->is_error(), $js_back );
224
}
225

    
226
while($search_setting = $res_search->fetchRow())
227
{
228
	$old_value = $search_setting['value'];
229
	$setting_name = $search_setting['name'];
230
	$post_name = 'search_'.$search_setting['name'];
231

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

    
249
// Check if there was an error updating the db
250
if($database->is_error()) {
251
	$admin->print_error($database->get_error, $js_back );
252
} else {
253
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], $js_back );
254
}
255
$admin->print_footer();
(2-2/3)