Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         settings
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: save.php 1356 2010-12-27 18:19:55Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/settings/save.php $
15
 * @lastmodified    $Date: 2010-12-27 19:19:55 +0100 (Mon, 27 Dec 2010) $
16
 *
17
 */
18

    
19
// prevent this file from being accessed directly in the browser (would set all entries in DB settings table to '')
20
if(!isset($_POST['default_language']) || $_POST['default_language'] == '') die(header('Location: index.php'));
21

    
22
// Find out if the user was view advanced options or not
23
$advanced = ($_POST['advanced'] == 'yes') ? '?advanced=yes' : '';
24

    
25
// Print admin header
26
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28

    
29
if($advanced == '')
30
{
31
	$admin = new admin('Settings', 'settings_basic');
32
} else {
33
	$admin = new admin('Settings', 'settings_advanced');
34
}
35

    
36
if( !$admin->checkFTAN() )
37
{
38
	$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'index.php');
39
	exit();
40
}
41

    
42
// Create a javascript back link
43
$js_back = "javascript: history.go(-1);";
44

    
45
// Ensure that the specified default email is formally valid
46
if(isset($_POST['server_email']))
47
{
48
	$_POST['server_email'] = strip_tags($_POST['server_email']);
49
    // $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';
50
    $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}))$/';
51
    if(false == preg_match($pattern, $_POST['server_email']))
52
    {
53
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'].
54
			'<br /><strong>Email: '.htmlentities($_POST['server_email']).'</strong>', $js_back);
55
	}
56
}
57

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

    
137
$allow_tags_in_fields = array('website_header', 'website_footer');
138
$allow_empty_values = array('website_header','website_footer','sec_anchor','pages_directory','page_spacer');
139
$disallow_in_fields = array('pages_directory', 'media_directory','wb_version');
140
// Create new database object
141
/*$database = new database(); */
142

    
143
// Query current settings in the db, then loop through them and update the db with the new value
144
$settings = array();
145
$old_settings = array();
146
// Query current settings in the db, then loop through them to get old values
147
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
148
$sql .= 'ORDER BY `name`';
149

    
150
$res_settings = $database->query($sql);
151

    
152
while($setting = $res_settings->fetchRow())
153
{
154
	$old_settings[$setting['name']] = $setting['value'];
155
	$setting_name = $setting['name'];
156
	$value = $admin->get_post($setting_name);
157
	$value = isset($_POST[$setting_name]) ? $value : $old_settings[$setting_name] ;
158
	switch ($setting_name) {
159
		case 'default_timezone':
160
			$value=$value*60*60;
161
			break;
162
		case 'string_dir_mode':
163
			$value=$dir_mode;
164
			break;
165
		case 'string_file_mode':
166
			$value=$file_mode;
167
			break;
168
		case 'pages_directory':
169
			break;
170
		default :
171

    
172
			break;
173
	}
174
    if (!in_array($setting_name, $allow_tags_in_fields))
175
    {
176
        $value = strip_tags($value);
177
    }
178

    
179
    $passed = in_array($setting_name, $allow_empty_values);
180

    
181
    if ( !in_array($value, $disallow_in_fields) && (isset($_POST[$setting_name]) || $passed == true) )
182
    {
183
        $value = trim($admin->add_slashes($value));
184
        $sql = 'UPDATE `'.TABLE_PREFIX.'settings` ';
185
        $sql .= 'SET `value` = \''.$value.'\' ';
186
        $sql .= 'WHERE `name` <> \'wb_version\' ';
187
        $sql .= 'AND `name` = \''.$setting_name.'\' ';
188

    
189
        if (!$database->query($sql))
190
        {
191
			if($database->is_error()) {
192
				$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
193
			}
194
        }
195
	}
196
}
197

    
198
// Query current search settings in the db, then loop through them and update the db with the new value
199
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
200
$sql .= 'WHERE `extra` = ""';
201
$res_search = $database->query($sql);
202

    
203
if($database->is_error()) {
204
	$admin->print_error($database->is_error(), ADMIN_URL.'/settings/index.php'.$advanced);
205
}
206

    
207
while($search_setting = $res_search->fetchRow())
208
{
209
	$old_value = $search_setting['value'];
210
	$setting_name = $search_setting['name'];
211
	$post_name = 'search_'.$search_setting['name'];
212

    
213
    // hold old value if post is empty
214
    // check search template
215
    $value = ( ($admin->get_post($post_name) == '') && ($setting_name != 'template') ) ? $old_value : $admin->get_post($post_name);
216
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
217
    if(isset($value))
218
	{
219
		$value = $admin->add_slashes($value);
220
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
221
        $sql .= 'SET `value` = "'.$value.'" ';
222
        $sql .= 'WHERE `name` = "'.$setting_name.'" ';
223
        $sql .= 'AND `extra` = ""';
224
		if($database->query($sql)) {
225
		}
226
		$sql_info = mysql_info($database->db_handle);
227
    }
228
}
229

    
230
// Check if there was an error updating the db
231
if($database->is_error()) {
232
	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
233
} else {
234
	$admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
235
}
236
$admin->print_footer();
237

    
238
?>
(2-2/3)