<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
@header("Cache-Control: no-cache, must-revalidate"); 
@header("Pragma: no-cache");
if(@!eregi($_SERVER['SERVER_NAME'],$_SERVER['HTTP_REFERER'])){exit('QQ:848769359');}
class Ding extends CI_Controller {

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

        //列表
	public function lists()
	{
                $data='';
                $id = intval($this->uri->segment(3));   //ID
		$row=$this->CsdjDB->get_select ('dance','CS_ID','CS_Dhits,CS_Chits',''.$id.'');
		if(!$row){
			show_404();
		}
		$DHits=$row[0]->CS_Dhits;
		$CHits=$row[0]->CS_Chits;
		$nCount=$row[0]->CS_Dhits+$row[0]->CS_Chits;
		if($DHits==$CHits){
			$DuHits="50";
			$CuHits="50";
		}else{
			$DuHits=intval($DHits/$nCount*100);
			$CuHits=intval($CHits/$nCount*100);
		}

                $TempImg = Web_Path.'skins/'.Skins_dir.'/';
                $TempImg = str_replace('//','/',$TempImg);
                $TempImg = substr(substr($TempImg,0,strlen($TempImg)-1),0,strrpos(substr($TempImg,0,strlen($TempImg)-1),'/')+1);

                $this->load->get_templates();
		$Mark_Text=$this->load->view('cs-ding.html',$data,true);

		$Mark_Text=str_replace("[dance:dhits]",$DHits,$Mark_Text);
		$Mark_Text=str_replace("[dance:chits]",$CHits,$Mark_Text);
		$Mark_Text=str_replace("[dance:duhits]",$DuHits,$Mark_Text);
		$Mark_Text=str_replace("[dance:cuhits]",$CuHits,$Mark_Text);
		$Mark_Text=str_replace("[dance:id]",$id,$Mark_Text);
		$Mark_Text=str_replace("{cscms:path}",Web_Path,$Mark_Text);
		$Mark_Text=str_replace("{cscms:tempurl}",$TempImg,$Mark_Text);
                echo $Mark_Text;
        }

        //顶踩
	public function go()
	{
                $type = $this->uri->segment(3);   //方式
                $id = intval($this->uri->segment(4));   //ID

		$row=$this->CsdjDB->get_select ('dance','CS_ID','CS_Dhits,CS_Chits',''.$id.'');
		if(!$row){
			exit();
		}
                $sessionid='adddingtime_'.$id;
  
                if($type=='ding'){
	            $updata['CS_Dhits']=$row[0]->CS_Dhits+1;
                }else{
	            $updata['CS_Chits']=$row[0]->CS_Chits+1;
                }

		if($this->session->userdata($sessionid)){
			exit("Err_110"); //24小时已经顶过
		}else{
		     $dingdata = array(
                                        ''.$sessionid.''  => date("Y-m-d H:i:s"),
                                   );
                     $this->session->set_userdata($dingdata);
                     $edit=$this->CsdjDB->get_update ('dance',$id,$updata);
                     echo 'Err_111';
		}

        }
}

