/**
  * 查看相册
  */
 public function action_list()
 {
     if (ORM::factory('user')->check_space($this->auth['uid'])) {
     } else {
         $this->checkSpace();
         //空间验证
     }
     $this->_add_script('scripts/copy.js');
     $this->_add_script('scripts/wal8/menu.js');
     $this->template->pageTitle = '查看相册';
     ORM::factory('user')->upcache($this->auth['uid']);
     $this->template->num = $num = $this->getQuery('num', 20);
     $select = DB::select('cate.cate_id', 'cate.cate_name', 'cate.index_img', 'cate.img_num', 'cate.is_share', 'cate.type', 'cate.index_img_id')->from(array('img_categories', 'cate'))->where('uid', '=', (int) $this->auth['uid']);
     $select2 = DB::select('i.id', 'i.cate_id', 'i.picname', 'i.custom_name', 'i.disk_id', 'i.userid', 'i.click', 'i.is_share', 'i.disk_name', array('i.disk_id', 'disk_domain'))->from(array('imgs', 'i'))->where('i.userid', '=', (int) $this->auth['uid']);
     $this->template->order_by = $order_by = trim($this->getQuery('order_by'));
     if (!empty($order_by)) {
         $select2->order_by('i.id', $order_by);
     }
     $this->template->cate_id = $cate_id = (int) $this->getQuery('cate_id');
     $this->template->recycle = $recycle = (int) $this->getQuery('recycle');
     $this->template->keyword = $keyword = trim($this->getQuery('keyword'));
     $this->template->type = $type = trim($this->getQuery('search_type'));
     if ($cate_id > 0) {
         $select->where('cate.parent_id', '=', $cate_id);
         $select2->where('i.cate_id', '=', (int) $cate_id)->where('i.recycle', '=', 0);
     } else {
         if ($recycle) {
             $select2->where('i.recycle', '=', '1');
             $select->where('cate.cate_name', '=', null);
         } else {
             $select2->where('i.recycle', '=', 0);
             if (empty($keyword)) {
                 $select2->where('i.cate_id', '=', 0);
             }
             $select->where('cate.parent_id', '=', 0);
         }
     }
     if (!empty($keyword)) {
         if ($type == 1) {
             $select->where('cate.cate_name', 'like', "%{$keyword}%");
             if ($cate_id <= 0) {
                 $select2->where('i.cate_id', '=', (int) $keyword);
             }
         } else {
             $select->where('cate.cate_name', '=', null);
             $select2->where('i.custom_name', 'like', "%{$keyword}%");
         }
     }
     $this->template->order_by = $order_by = trim($this->getQuery('order_by', 'DESC'));
     if (!empty($order_by)) {
         $select->order_by('cate.cate_id', $order_by);
         $select2->order_by('i.id', $order_by);
     }
     $this->template->pic_num = $pic_num = $select2->count_all();
     $this->template->cate_num = $cate_num = $select->count_all();
     $pageNum = $pic_num + $cate_num;
     // 显示分页链接(图片+分类的)
     $this->template->pagination = $pagination = Pagination::factory(array('total_items' => $pageNum, 'items_per_page' => $num));
     // 分类结果
     $this->template->results = $results = $select->limit($pagination->items_per_page)->offset($pagination->offset)->execute();
     //需要显示多少张图片, 每页显示数-当前显示目录数
     $piclimit = $pagination->items_per_page - count($results->as_array());
     if ($piclimit > 0) {
         //图片从几条数据取起
         $offset = $pagination->offset - $cate_num;
         if ($offset < 0) {
             $offset = 0;
         }
         $select2 = $select2->limit($piclimit)->offset($offset);
         $this->template->rootresults = $select2->execute();
     }
     // 图片分类列表
     $this->template->cate_list = $cate_list = DB::select('cate_name', 'cate_id', 'path')->from('img_categories')->where('uid', '=', $this->auth['uid'])->fetch_all();
     $arr = array();
     if ($cate_id > 0) {
         $cate = new Category();
         $path = $cate->getPath($cate_id);
         $path = explode(';', $path);
         foreach ($path as $value) {
             if (!empty($value)) {
                 $info = $cate->infoSql($value)->execute()->current();
                 $arr[$value] = $info['cate_name'];
             }
         }
         $this->template->cateInfo = $cateInfo = $cate->infoSql($cate_id)->execute()->current();
     }
     $this->template->arr = $arr;
 }