<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Fav extends CI_Controller {

	function __construct(){
		parent::__construct();
        	$this->load->helper('url');
                $this->load->library('session'); //加载session
		$this->load->model('CsdjDB');
		$this->load->model('CsdjAdmin');
		$this->load->model('CsdjSkins');
                $this->db->cache_off();
	        $this->CsdjAdmin->Admin_Login();
	}

	public function index()
	{
 	    $sid = $this->input->get('sid');
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

            if($sid){
	           $sql_string = "SELECT * FROM ".CS_SqlPrefix."fav where cs_sid=".$sid." order by CS_ID desc";
            }else{
	           $sql_string = "SELECT * FROM ".CS_SqlPrefix."fav order by CS_ID desc";
            }
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/down/index/')."?sid=".$sid;
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['fav'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/fav',$data);
        }

	public function pldel()
	{
            $this->CsdjAdmin->Admin_Qx('45');
	    $ids=$this->input->post('CS_ID');
            if(empty($ids)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');
            $id=implode(',', $ids);
            $this->db->query("delete from ".CS_SqlPrefix."fav where CS_ID in (".$id.")");
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',$_SERVER['HTTP_REFERER'],'ok');
        }
}

