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 1767 2012-09-22 20:30:37Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
14
 * @lastmodified    $Date: 2012-09-22 22:30:37 +0200 (Sat, 22 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
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(isset($_POST['wbmailer_routine']) && ($_POST['wbmailer_routine']=='smtp')) {
62

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

    
71
}
72

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

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

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

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

    
170
if($res_settings = $database->query($sql)) {
171
	$passed = false;
172
	while($setting = $res_settings->fetchRow())
173
	{
174
		$setting_name = $setting['name'];
175
		$old_settings[$setting_name] = $setting['value'];
176
		$value = $admin->get_post($setting_name);
177
		$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
178
		switch ($setting_name) {
179
			case 'default_timezone':
180
				$value=$value*60*60;
181
				$passed = true;
182
				break;
183
			case 'string_dir_mode':
184
				$value=$dir_mode;
185
				$passed = true;
186
				break;
187
			case 'string_file_mode':
188
				$value=$file_mode;
189
	 			$passed = true;
190
    			break;
191
			case 'sec_anchor':
192
				$value=(($value=='') ? 'section_' : $value);
193
	 			$passed = true;
194
				break;
195
			case 'pages_directory':
196
                $bNewPageFile = ( ( $value!= $old_settings['pages_directory'] ) ? true :  false );
197
	 			$passed = $bNewPageFile;
198
                $sGetId = '&amp;id='.$bNewPageFile;
199
//                if(!is_dir(WB_PATH.$value) && is_writable(WB_PATH)) {
200
//                    $passed = make_dir(WB_PATH.$value);
201
//                }
202
                $value  = (($passed == true) ? $value : $old_settings['pages_directory']);
203
                $sPageDirectory = $value;
204
				break;
205
			case 'wbmailer_smtp_auth':
206
				// $value = isset($_POST[$setting_name]) ? $_POST[$setting_name] : '' ;
207
				$value = true ;
208
	 			$passed = true;
209
				break;
210
			default :
211
			    $passed = in_array($setting_name, $allow_empty_values);
212
				break;
213
		}
214

    
215

    
216
	    if (!in_array($setting_name, $allow_tags_in_fields))
217
	    {
218
	        $value = strip_tags($value);
219
	    }
220

    
221
	    if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
222
	    {
223
	        $value = trim($admin->add_slashes($value));
224
	        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
225
	        $sql .= 'SET `value` = \''.$value.'\' ';
226
	        $sql .= 'WHERE `name` != \'wb_version\' ';
227
	        $sql .= 'AND `name` = \''.$setting_name.'\' ';
228
	        if (!$database->query($sql))
229
	        {
230
				if($database->is_error()) {
231
					$admin->print_error($database->get_error, $js_back );
232
				}
233
	        }
234
		}
235
	}
236

    
237
    if(($bRebuildAccessFiles==true) && ($_POST['modules_upgrade_list']!='') && ($sPageDirectory==$old_settings['pages_directory']) ) {
238
        rebuild_all_accessfiles();
239
        $aModuleList = ( explode(',', $_POST['modules_upgrade_list']));
240
        upgrade_modules($aModuleList);
241
    }
242

    
243
}
244

    
245
// Query current search settings in the db, then loop through them and update the db with the new value
246
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
247
$sql .= 'WHERE `extra` = ""';
248
$res_search = $database->query($sql);
249

    
250
if($database->is_error()) {
251
	$admin->print_error($database->is_error(), $js_back );
252
}
253

    
254
while($search_setting = $res_search->fetchRow())
255
{
256
	$old_value = $search_setting['value'];
257
	$setting_name = $search_setting['name'];
258
	$post_name = 'search_'.$search_setting['name'];
259

    
260
    // hold old value if post is empty
261
    // check search template
262
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
263
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
264
    if(isset($value))
265
	{
266
		$value = $admin->add_slashes($value);
267
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
268
        $sql .= 'SET `value` = "'.$value.'" ';
269
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
270
        $sql .= 'AND `extra` = ""';
271
		if($database->query($sql)) {
272
		}
273
		$sql_info = mysql_info($database->db_handle);
274
    }
275
}
276

    
277
// Check if there was an error updating the db
278
if($database->is_error()) {
279
	$admin->print_error($database->get_error, $js_back );
280
} else {
281
	$admin->print_success($MESSAGE['SETTINGS_SAVED'], $js_back );
282
}
283
$admin->print_footer();
(2-2/3)