| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | // $Id: save.php 239 2005-11-22 11:50:41Z stefan $
 | 
  
    | 4 | 
 | 
  
    | 5 | /*
 | 
  
    | 6 | 
 | 
  
    | 7 |  Website Baker Project <http://www.websitebaker.org/>
 | 
  
    | 8 |  Copyright (C) 2004-2005, Ryan Djurovich
 | 
  
    | 9 | 
 | 
  
    | 10 |  Website Baker is free software; you can redistribute it and/or modify
 | 
  
    | 11 |  it under the terms of the GNU General Public License as published by
 | 
  
    | 12 |  the Free Software Foundation; either version 2 of the License, or
 | 
  
    | 13 |  (at your option) any later version.
 | 
  
    | 14 | 
 | 
  
    | 15 |  Website Baker is distributed in the hope that it will be useful,
 | 
  
    | 16 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
  
    | 17 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
  
    | 18 |  GNU General Public License for more details.
 | 
  
    | 19 | 
 | 
  
    | 20 |  You should have received a copy of the GNU General Public License
 | 
  
    | 21 |  along with Website Baker; if not, write to the Free Software
 | 
  
    | 22 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
  
    | 23 | 
 | 
  
    | 24 | */
 | 
  
    | 25 | 
 | 
  
    | 26 | // Find out if the user was view advanced options or not
 | 
  
    | 27 | if($_POST['advanced'] == 'yes' ? $advanced = '?advanced=yes' : $advanced = '');
 | 
  
    | 28 | 
 | 
  
    | 29 | // Print admin header
 | 
  
    | 30 | require('../../config.php');
 | 
  
    | 31 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 32 | if($advanced == '') {
 | 
  
    | 33 | 	$admin = new admin('Settings', 'settings_basic');
 | 
  
    | 34 | 	$_POST['database_password'] = DB_PASSWORD;
 | 
  
    | 35 | } else {
 | 
  
    | 36 | 	$admin = new admin('Settings', 'settings_advanced');
 | 
  
    | 37 | }
 | 
  
    | 38 | 
 | 
  
    | 39 | // Work-out file mode
 | 
  
    | 40 | if($advanced == '') {
 | 
  
    | 41 | 	// Check if should be set to 777 or left alone
 | 
  
    | 42 | 	if(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
 | 
  
    | 43 | 		$file_mode = '0777';
 | 
  
    | 44 | 		$dir_mode = '0777';
 | 
  
    | 45 | 	} else {
 | 
  
    | 46 | 		$file_mode = STRING_FILE_MODE;
 | 
  
    | 47 | 		$dir_mode = STRING_DIR_MODE;
 | 
  
    | 48 | 	}
 | 
  
    | 49 | } else {
 | 
  
    | 50 | 	// Work-out the octal value for file mode
 | 
  
    | 51 | 	$u = 0;
 | 
  
    | 52 | 	if(isset($_POST['file_u_r']) AND $_POST['file_u_r'] == 'true') {
 | 
  
    | 53 | 		$u = $u+4;
 | 
  
    | 54 | 	}
 | 
  
    | 55 | 	if(isset($_POST['file_u_w']) AND $_POST['file_u_w'] == 'true') {
 | 
  
    | 56 | 		$u = $u+2;
 | 
  
    | 57 | 	}
 | 
  
    | 58 | 	if(isset($_POST['file_u_e']) AND $_POST['file_u_e'] == 'true') {
 | 
  
    | 59 | 		$u = $u+1;
 | 
  
    | 60 | 	}
 | 
  
    | 61 | 	$g = 0;
 | 
  
    | 62 | 	if(isset($_POST['file_g_r']) AND $_POST['file_g_r'] == 'true') {
 | 
  
    | 63 | 		$g = $g+4;
 | 
  
    | 64 | 	}
 | 
  
    | 65 | 	if(isset($_POST['file_g_w']) AND $_POST['file_g_w'] == 'true') {
 | 
  
    | 66 | 		$g = $g+2;
 | 
  
    | 67 | 	}
 | 
  
    | 68 | 	if(isset($_POST['file_g_e']) AND $_POST['file_g_e'] == 'true') {
 | 
  
    | 69 | 		$g = $g+1;
 | 
  
    | 70 | 	}
 | 
  
    | 71 | 	$o = 0;
 | 
  
    | 72 | 	if(isset($_POST['file_o_r']) AND $_POST['file_o_r'] == 'true') {
 | 
  
    | 73 | 		$o = $o+4;
 | 
  
    | 74 | 	}
 | 
  
    | 75 | 	if(isset($_POST['file_o_w']) AND $_POST['file_o_w'] == 'true') {
 | 
  
    | 76 | 		$o = $o+2;
 | 
  
    | 77 | 	}
 | 
  
    | 78 | 	if(isset($_POST['file_o_e']) AND $_POST['file_o_e'] == 'true') {
 | 
  
    | 79 | 		$o = $o+1;
 | 
  
    | 80 | 	}
 | 
  
    | 81 | 	$file_mode = "0".$u.$g.$o;
 | 
  
    | 82 | 	// Work-out the octal value for dir mode
 | 
  
    | 83 | 	$u = 0;
 | 
  
    | 84 | 	if(isset($_POST['dir_u_r']) AND $_POST['dir_u_r'] == 'true') {
 | 
  
    | 85 | 		$u = $u+4;
 | 
  
    | 86 | 	}
 | 
  
    | 87 | 	if(isset($_POST['dir_u_w']) AND $_POST['dir_u_w'] == 'true') {
 | 
  
    | 88 | 		$u = $u+2;
 | 
  
    | 89 | 	}
 | 
  
    | 90 | 	if(isset($_POST['dir_u_e']) AND $_POST['dir_u_e'] == 'true') {
 | 
  
    | 91 | 		$u = $u+1;
 | 
  
    | 92 | 	}
 | 
  
    | 93 | 	$g = 0;
 | 
  
    | 94 | 	if(isset($_POST['dir_g_r']) AND $_POST['dir_g_r'] == 'true') {
 | 
  
    | 95 | 		$g = $g+4;
 | 
  
    | 96 | 	}
 | 
  
    | 97 | 	if(isset($_POST['dir_g_w']) AND $_POST['dir_g_w'] == 'true') {
 | 
  
    | 98 | 		$g = $g+2;
 | 
  
    | 99 | 	}
 | 
  
    | 100 | 	if(isset($_POST['dir_g_e']) AND $_POST['dir_g_e'] == 'true') {
 | 
  
    | 101 | 		$g = $g+1;
 | 
  
    | 102 | 	}
 | 
  
    | 103 | 	$o = 0;
 | 
  
    | 104 | 	if(isset($_POST['dir_o_r']) AND $_POST['dir_o_r'] == 'true') {
 | 
  
    | 105 | 		$o = $o+4;
 | 
  
    | 106 | 	}
 | 
  
    | 107 | 	if(isset($_POST['dir_o_w']) AND $_POST['dir_o_w'] == 'true') {
 | 
  
    | 108 | 		$o = $o+2;
 | 
  
    | 109 | 	}
 | 
  
    | 110 | 	if(isset($_POST['dir_o_e']) AND $_POST['dir_o_e'] == 'true') {
 | 
  
    | 111 | 		$o = $o+1;
 | 
  
    | 112 | 	}
 | 
  
    | 113 | 	$dir_mode = "0".$u.$g.$o;
 | 
  
    | 114 | }
 | 
  
    | 115 | 
 | 
  
    | 116 | // Create new database object
 | 
  
    | 117 | $database = new database();
 | 
  
    | 118 | 
 | 
  
    | 119 | // Query current settings in the db, then loop through them and update the db with the new value
 | 
  
    | 120 | $query = "SELECT name FROM ".TABLE_PREFIX."settings";
 | 
  
    | 121 | $results = $database->query($query);
 | 
  
    | 122 | while($setting = $results->fetchRow()) {
 | 
  
    | 123 | 	$setting_name = $setting['name'];
 | 
  
    | 124 | 	$value = $admin->get_post($setting_name);
 | 
  
    | 125 | 	if ($value!=null || $setting_name=='default_timezone' || $setting_name=='string_dir_mode' || $setting_name=='string_file_mode') {
 | 
  
    | 126 | 		$value = $admin->add_slashes($value);
 | 
  
    | 127 | 		switch ($setting_name) {
 | 
  
    | 128 | 			case 'default_timezone':
 | 
  
    | 129 | 				$value=$value*60*60;
 | 
  
    | 130 | 				break;
 | 
  
    | 131 | 			case 'string_dir_mode':
 | 
  
    | 132 | 				$value=$dir_mode;
 | 
  
    | 133 | 				break;
 | 
  
    | 134 | 			case 'string_file_mode':
 | 
  
    | 135 | 				$value=$file_mode;
 | 
  
    | 136 | 				break;
 | 
  
    | 137 | 		}
 | 
  
    | 138 | 		$database->query("UPDATE ".TABLE_PREFIX."settings SET value = '$value' WHERE name = '$setting_name'");
 | 
  
    | 139 | 	}
 | 
  
    | 140 | }
 | 
  
    | 141 | 
 | 
  
    | 142 | // Query current search settings in the db, then loop through them and update the db with the new value
 | 
  
    | 143 | $query = "SELECT name FROM ".TABLE_PREFIX."search WHERE extra = ''";
 | 
  
    | 144 | $results = $database->query($query);
 | 
  
    | 145 | while($search_setting = $results->fetchRow()) {
 | 
  
    | 146 | 	$setting_name = $search_setting['name'];
 | 
  
    | 147 | 	$post_name = 'search_'.$search_setting['name'];
 | 
  
    | 148 | 	$value = $admin->get_post($post_name);
 | 
  
    | 149 | 	$value = $admin->add_slashes($value);
 | 
  
    | 150 | 	$database->query("UPDATE ".TABLE_PREFIX."search SET value = '$value' WHERE name = '$setting_name'");
 | 
  
    | 151 | }
 | 
  
    | 152 | 
 | 
  
    | 153 | // Check if there was an error updating the db
 | 
  
    | 154 | if($database->is_error()) {
 | 
  
    | 155 | 	$admin->print_error($database->get_error, ADMIN_URL.'/settings/index.php'.$advanced);
 | 
  
    | 156 | 	$admin->print_footer();
 | 
  
    | 157 | 	exit();
 | 
  
    | 158 | }
 | 
  
    | 159 | 
 | 
  
    | 160 | $admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
 | 
  
    | 161 | $admin->print_footer();
 | 
  
    | 162 | 
 | 
  
    | 163 | ?>
 |