<?php

class plus_uploadMod extends commonMod
{
    
    // 上传管理
    public function index()
    {
        
        $url = __URL__ . '/index-page-{page}.html'; //分页基准网址
        $page = new Page();
        $listRows = 40; //每页显示记录
        $cur_page = $page->getCurPage($url);
        $limit_start = ($cur_page - 1) * $listRows;
        $limit = $limit_start . ',' . $listRows;

        $list = $this->model->table('upload')->order('id desc')->limit($limit)->select(); //查询替换表所有数据
        $count = $this->model->table('upload')->count(); //总记录数
        $this->assign('list', $list);
        $this->assign('page', $this->page($url, $count, $listRows));
        $this->display();
    }
    
    // 上传删除
    public function del()
    {

        $id = intval($_GET[0]);
        if (empty($id)) {
            $this->jserror('ID传输错误！');
            return;
        }
        

        $info=$this->model->table('upload')->where('id='.$id)->find();

        if (!@unlink($_SERVER['DOCUMENT_ROOT'].$info['file']))
        {
        $this->jserror('文件删除失败！');
        }

        $condition['id'] = $id;
        $this->model->table('upload')->where($condition)->delete();

        $this->jssuccess('文件删除成功！');
    }
    
    // 批量删除
    public function del_all()
    {
        $mode = intval($_POST['mode']);
        $checkbox = $_POST['id'];
        if (empty($checkbox)) {
            $this->error('未选择文件！');
            exit;
        }
        $in = implode(',', $checkbox);
        $condition = "id in($in)";
        $ary = explode(",", $in);
            foreach ($ary as $val) {
                $info=$this->model->table('upload')->field('id,file')->where('id='.$val)->find();
                @unlink($_SERVER['DOCUMENT_ROOT'].$info['file']);
                $condition2['id'] = $val;
                $this->model->table('upload')->where($condition2)->delete();
            }
        $this->success('批量删除完毕！');
        
    }
}

?>