<?php
!defined("MONKEYMAO") && die("Accessed Defined!");
	$set = array();
	$query = $db -> query("SELECT * FROM {$tablepre}settings");
	while($sett = $db -> fetch_array($query)){
		$set[$sett['variable']] = $sett['value'];
	}
if(cpchecksubmit('upset')){
/*
	ksort($settings);
	foreach($settings AS $key => $set){
		$db -> query("INSERT INTO {$tablepre}settings  (variable, value) VALUES ('$key', '$set') ");
	}
*/
	$settings['timeformat'] = $settings['timeformat'] == 24 ? 'H:i' : 'h:i';
	$settings['dateformat'] = str_replace('mm', 'n', $settings['dateformat']);
	$settings['dateformat'] = str_replace('dd', 'j', $settings['dateformat']);
		$settings['dateformat'] = str_replace('yyyy', 'Y', $settings['dateformat']);
	$settings['dateformat'] = str_replace('yy', 'y', $settings['dateformat']);

	foreach($settings AS $key => $value){
		if($set[$key] != $settings[$key]){		
			$db -> query("UPDATE {$tablepre}settings SET value='$value' WHERE variable='$key'");
		}
	}
	$updfiles =  uploadfile('wartermark');
	if($updfiles){
		@unlink(MODEPATH.'./'.$attachdir.'/'.$set['wartermark']);	
		$wartermark=$updfiles[0]['attachment'];
		$db -> query("UPDATE {$tablepre}settings SET value='$wartermark' WHERE variable='wartermark'");
	}
	cache('settings');
	cache();
	
	cpmsg('succeeded', 'index.php?action=settings');
}else{

	$set['timeformat'] = $set['timeformat'] == 'H:i' ? 24 : 12;
	$set['dateformat'] = str_replace('n', 'mm', $set['dateformat']);
	$set['dateformat'] = str_replace('j', 'dd', $set['dateformat']);
	$set['dateformat'] = str_replace('y', 'yy', $set['dateformat']);
	$set['dateformat'] = str_replace('Y', 'yyyy', $set['dateformat']);
	
	include theme('settings', 'themes/admin', 'admin');

}

?>