<?php
defined('IN_TS') or die('Access Denied.');

$userid = aac('user')->isLogin();

switch($ts){
	case "":
		$albumid=intval($_GET['albumid']);
		include template("upload");
		break;
	case "add":
		$albumid=intval($_GET['albumid']);
		include template("add");
		break;
	case "do":
		$albumid = intval($_POST['albumid']);


		$strAlbum = $new['attach']->find('attach_album',array(
			'albumid'=>$albumid,
		));

		if($strAlbum!=''){
	         if($strAlbum['userid']!=$userid){
	            getJson('非法操作3！');
	            
	        }           
        }


        
		if($_FILES['file']==''){ts404();}
			//上传
		$attachid = $new['attach']->create('attach',array(
			'userid'=>$userid,
			'albumid'=>$albumid,
			'locationid'=>aac('user')->getLocationId($userid),
			'addtime'	=> date('Y-m-d H:i:s',time()),
		));
		//上传
		$arrUpload = tsUpload($_FILES['file'],$attachid,'attach',array('zip','rar','doc','txt','ppt','pdf','docx','mp4'));
		
		if($arrUpload && $arrUpload['path'] && $arrUpload['url']){
			$new['attach']->update('attach',array(
				'attachid'=>$attachid,
			),array(
				'attachname'=>$arrUpload['name'],
				'attachtype'=>$arrUpload['type'],
				'path'=>$arrUpload['path'],
				'attachurl'=>$arrUpload['url'],
				'attachsize'=>$arrUpload['size'],
			));
		}
		
		
            $count_attach = $new['attach']->findCount('attach',array(
                'albumid'=>$albumid,
            ));

            $new['attach']->update('attach_album',array(
                'albumid'=>$albumid,
            ),array(
                'count_attach'=>$count_attach
            ));
            
            
		break;

}