<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

// 下载
class AttachmentAction extends SunnyiAction{
    public function down(){
    	if(intval($_SESSION['user_id']==0))
    	{
    		$this->assign("jumpUrl",U("User/login"));
    		$this->error(L("PLEASE_LOGIN"));
    	}
		$id = intval($_REQUEST['id']);
		if(D("Attachment")->where('id='.$id)->count()==0)
		{
			$this->error(L("NO_ATTACHMENT"));
		}
		else 
		{
			$attachment_item = D("Attachment")->getById($id);
			if(strtolower(substr($attachment_item['file_path'],0,7))!="http://")
			{
				if(file_exists($this->getRealPath().$attachment_item['file_path']))
				{
					if($this->check_ip_operation(get_client_ip(),"Attachment",1200,$id))
					D("Attachment")->where(array('id'=>$id))->setInc("count");
					header("Location:".__ROOT__.$attachment_item['file_path']);
				}
				else 
				{
					$this->error(L("PATH_INVALID"));
				}
			}
			else 
			{
				if(file_get_contents($attachment_item['file_path']))
				{
					if($this->check_ip_operation(get_client_ip(),"Attachment",1200,$id))
					D("Attachment")->where(array('id'=>$id))->setInc("count");
					header("Location:".$attachment_item['file_path']);
				}
				else 
				{
					$this->error(L("PATH_INVALID"));
				}
			}
		}
    }
}
?>