<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DeleteAction extends BbsAction
{
    public function run()
    {
        $this->getController()->isLogin();
        $aid = intval(S::gp('aid','G'));
        $attachModel = Attachment::single();
        $attachDownModel = AttachDownload::single();
        $permissions = Members::single()->getPermissions($this->uid());
        try
        {
            $attachment = $attachModel->getOne($aid);
        }
        catch (AttachmentNotExistsException $exce)
        {
            throw new iSystemException($exce->getMessage());
        }
        
        if ($attachment['uid'] != $this->uid() && !$permissions['isdelatt'])
        {
            $this->NoPermission();
        }
        
        if (!$_GET['confirm'])
        {
            $message[] = '确定要删除吗？删除后将不可恢复！';
            $message[] = $this->getController()->link('确定删除',$this->getController()->url('system',array('s'=>'bbs','c'=>'attachment','a'=>'delete','aid'=>$aid,'confirm'=>1))).'.'.$this->getController()->link('取消返回',$this->getController()->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$attachment['tid'])));
            $this->showMessage($message);
        }
        $attachModel->deleteOne($aid, $attachment['tid']);
        iforward($this->getController()->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$attachment['tid'])));
    }
}