<?php
define('THIS_SCRIPT', 'cookies');
require_once 'global.php';
switch($action){
	case 'setlistmod':
		set_cookie("indexlist{$id}",$thisvalue,86400 * 7);
		echo '<script language="javascript" type="text/javascript">if(self.name=="hiddenframe1"){parent.location.reload();}else{alert("error!");top.location.href="'.$fsetting['homepage'].'";}</script>';
		break;
	case 'stylemod':
		switch($stype){
			case 'style':
				foreach($_DCACHE['forum_css'] as $key=>$val){
					if ( intval($skinid) == intval($key) ){
						$getTplUrlarr = explode('/',$val[1]);
						set_cookie("tpl_url",$getTplUrlarr[0].'/'.$getTplUrlarr[1].'/',86400 * 7);
						set_cookie("tpl_img_url",$getTplUrlarr[0].'/'.$getTplUrlarr[1].'/images/',86400 * 7);
						set_cookie("css_style_url",$val[1]. '.css',86400 * 7);
						set_cookie("style_{$boardid}",$val[1]. '.css',86400 * 7);
						break;
					}
				}
				break;
			case 'lang':
				foreach($_DCACHE['forum_lang'] as $key=>$val){
					if ( intval($skinid) == intval($key) ){
						$langstr = basename(strtolower($val[1]));
						set_cookie("language",$langstr,86400 * 7);
						break;
					}
				}
				break;
			case 'default':
				set_cookie("style_{$boardid}",'',86400 * 7);
				set_cookie("language",'',86400 * 7);
				break;
		}
		break;
	case 'regroup':
		if ( $userid > 0 && $isgroupselected = 1 && $groupid != '' && is_numeric($groupid) ){
			if ( $groupid == $userinfo['usergroupid'] || strpos('|'.$gp_issetting.'|','|'.$groupid.'|') !== false ){
				$db->query("update {$dv}online set usergroupid='{$groupid}' where userid=$userid");
			}
		}
		break;
	case 'hidden':
		if ( $userid > 0 ){
			$db->query("Update {$dv}online Set userhidden=1 Where userid=$userid");
			$db->query("Update {$dv}user Set userhidden=1 Where userid=$userid");
		}
		break;
	case 'online':
		if ( $userid > 0 ){
			$db->query("Update {$dv}online Set userhidden=2 Where userid=$userid");
			$db->query("Update {$dv}user Set userhidden=2 Where userid=$userid");
		}
		break;
	case 'isleft':
		set_cookie("setleftbar",1,86400 * 7);
		break;
	case 'noleft':
		set_cookie("setleftbar",0,86400 * 7);
		break;
}
if ( $action != 'setlistmod' ){
	if (empty($_SERVER['HTTP_REFERER']) OR (false !== strpos(strtolower($_SERVER['HTTP_REFERER']), 'cookies.php'))) {
		if ( $action == 'isleft' ){
			header("Location:{$fsetting['homepage']}?targeturl={$fsetting['homepage']}");
		}else{
			header("Location:{$fsetting['homepage']}");
		}
	} else {
		if ( $action == 'isleft' ){
			$encodeurl = urlencode($_SERVER['HTTP_REFERER']);
			header("Location:{$fsetting['homepage']}?targeturl={$encodeurl}");
		}else{
			header("Location:{$_SERVER['HTTP_REFERER']}");
		}
	}
}
?>