| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class News extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_user','user');		$this->load->_model('Model_news','news');	}    public function _remap($arg,$arg_array)    {		if($arg == 'add')        {             $this->_add();        }		else if($arg == 'edit')        {             $this->_edit($arg_array);        }		else if($arg == 'del')        {             $this->_del();        }		else if($arg == 'rows')        {             $this->_rows();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$title = $this->input->post('title',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1 ";            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($title)            {				$where  .= " and title like '%$title%'";            }			if($timetk && $timetj)            {                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";            }            //取得信息列表            $info_list = $this->news->find_all($where,'id,title,addtime',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$info_list[$key]['addtime'] = date('Y-m-d H:i',$value['addtime']);            }		    $total = $this->news->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));		    echo json_encode($rows);exit;		}		$this->_Template('news',$this->data);	}	//添加	public function _add()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			$post['title'] = $this->input->post('title',true);			$post['content'] = $this->input->post('content',true);			$post['addtime'] = time();			if($this->news->insert($post))        	{         		echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$this->_Template('news_add',$this->data);	}	//修改	public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			$post['title'] = $this->input->post('title',true);			$post['content'] = $this->input->post('content',true);			if($this->news->save($post,$id))        	{         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		$arg_array = $arg_array[0];		$news = $this->news->read($arg_array);		$this->data['news'] = $news;		$this->_Template('news_edit',$this->data);	}	//删除	public function _del()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{            $id_arr = $this->input->post('s');            $id_arr =  explode(',',$id_arr);            if(!$id_arr)            {                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;            }            //循环删除记录            foreach ($id_arr as $v) 		    {                $this->news->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }}
 |