<?php
!function_exists('adminmsg') && exit('Forbidden');

@include_once(D_P.'data/bbscache/o_config.php');

if (empty($action)) {

	if (empty($_POST['step'])) {

		ifcheck($db_dopen,'dopen');
		$uploadsize = unserialize($o_uploadsize);
		$attachdir_ck[(int)$o_attachdir] = 'selected';
		require_once PrintMode('diary');

	} else {

		InitGP(array('config','dopen'),'GP',2);
		InitGP(array('uploadsize'),'P',2);
		
		require_once(R_P.'admin/cache.php');
		$db->pw_update(
			"SELECT db_name FROM pw_config WHERE db_name='db_dopen'",
			"UPDATE pw_config SET db_value=".pwEscape($dopen)."WHERE db_name='db_dopen'",
			"INSERT INTO pw_config SET db_name='db_dopen',db_value=".pwEscape($dopen)
		);
		updatecache_c();

		$uploadsize = addslashes(serialize($uploadsize));
		$updatecache = false;
		foreach ($config as $key => $value) {
			if (${'o_'.$key} != $value) {
				$db->pw_update(
					'SELECT hk_name FROM pw_hack WHERE hk_name=' . pwEscape("o_$key"),
					'UPDATE pw_hack SET ' . pwSqlSingle(array('hk_value' => $value, 'vtype' => 'string')) . ' WHERE hk_name=' . pwEscape("o_$key"),
					'INSERT INTO pw_hack SET ' . pwSqlSingle(array('hk_name' => "o_$key", 'vtype' => 'string', 'hk_value' => $value))
				);
				$updatecache = true;
			}
		}
		if ($uploadsize) {
			$db->pw_update(
				'SELECT hk_name FROM pw_hack WHERE hk_name=' . pwEscape("o_uploadsize"),
				'UPDATE pw_hack SET ' . pwSqlSingle(array('hk_value' => $uploadsize, 'vtype' => 'string')) . ' WHERE hk_name=' . pwEscape("o_uploadsize"),
				'INSERT INTO pw_hack SET ' . pwSqlSingle(array('hk_name' => "o_uploadsize", 'vtype' => 'string', 'hk_value' => $uploadsize))
			);
			$updatecache = true;
		}
		$updatecache && updatecache_conf('o',true);
		adminmsg('operate_success');
	}
}
?>