<?php

class frontAction  extends MyTpl{
	private $data;
	function __construct(){
			parent::__construct();
			$this->data = new data($this);
			$this->channel=new channelModel();
		}

    function run(){
			$act=isset($_GET["a"])?$_GET["a"]:"index";
			if(method_exists($this,$act)){
				eval('$this->'.$act.'();');
			}else{
				echo '功能正在开发当中...';
				exit;
			}
		}

	function index(){
			$this->data->index();
			$this->display(APP_STYLE."/index.html");
		}

	function channel(){
			$channel = $this->channel->getChannelList("where ishidden=0");
			foreach($channel as $key => $val){

				if($val['id']==$_REQUEST['channelid']){
					if(!empty($val['isexternal'])){
					Header("Location:$val[link]");
					}
					$html=$this->data->channel($val);

				}

			}
			if(empty($html))exit;//这里可以处理不存在的栏目
			$this->display(APP_STYLE."/".$html);
	}


	function imagecode(){
			$code = new validationcode(76,22,4);
			$code->showImage();
			$_SESSION['checkcode']=$code->getCheckCode();
		}


	function leavemsg(){
				if(isset($_POST['verifycode']) && !empty($_POST['verifycode'])){
					if($_POST['verifycode']==$_SESSION['checkcode']){
						$object = new guestbookModel();
						$_POST['ip']=Common::getRealIpAddr();
						$_POST['message']=Common::HTMLEncode($_POST['message']);
						$_POST['publish']=time();
							if($object->add($_POST)){
								echo "<script>alert('留言成功！');location.href='".$_POST[url]."';</script>";

							}else{
								echo "<script>alert('留言失败！');location.href='".$_POST[url]."';</script>";
							}
					}else{
						echo "<script>alert('验证码不正确！');location.href='".$_POST[url]."';</script>";
					}


				}else{
					echo "<script>alert('请填写正确验证码！');location.href='".$_POST[url]."';</script>";
				}
		}


}
?>
