| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class Classid extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_classid','classid');
 
- 	}
 
- 	//定义方法的调用规则 获取URI第二段值
 
-     public function _remap($arg,$arg_array)
 
-     {
 
- 		if($arg == 'add')//添加
 
-         {
 
-              $this->_add($arg_array);
 
-         }
 
- 		else if($arg == 'edit')
 
-         {
 
-              $this->_edit($arg_array);
 
-         }
 
- 		else if($arg == 'del')
 
-         {
 
-              $this->_del();
 
-         }
 
- 		else if($arg == 'px')
 
-         {
 
-              $this->_px();
 
-         }
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['rows']))  
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$title = $this->input->post('title',true);
 
- 			$pp = $this->input->post('pp',true);
 
- 			$order_str = "px asc";
 
- 			$where = "1='1'";
 
- 			if($title)
 
-             {
 
-                 $where  .= " and title like '%$title%'";
 
-             }
 
- 			if($pp)
 
-             {
 
-                 $where  .= " and pp = '$pp'";
 
-             }
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->classid->find_all($where,'*',$order_str);
 
- 		    echo json_encode(array('data'=>$info_list,'power'=>array(),'success'=>true));exit;
 
- 		}
 
- 		$this->_Template('classid',$this->data);
 
- 	}
 
- 	
 
- 	//添加
 
- 	public function _add($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['title']))
 
- 		{
 
- 			$dn = $this->classid->find_count("1=1","*","px asc");
 
- 			$post['px'] = $dn+1;
 
- 			if($this->classid->insert($post))
 
-         	{
 
-          		echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
- 		$this->_Template('classid_add',$this->data);
 
- 	}
 
- 	//修改
 
- 	public function _edit($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['id']))
 
- 		{
 
- 			$id = $this->input->post('id',true);
 
- 			if($this->classid->save($post,$id))
 
-         	{
 
-          		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
 
-        	 	}
 
-        		else
 
-         	{
 
-            		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
 
-         	}
 
- 		}
 
- 		$classid = $this->classid->read($arg_array[0]);
 
- 		$this->data['classid'] = $classid;
 
- 		$this->_Template('classid_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->classid->remove($v);
 
-             }
 
-             echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
 
- 		}
 
-     }
 
- 	
 
- 	public function _px()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['data']))  
 
- 		{
 
- 			//echo json_encode(array('msg'=>'防止误排序,请联系开启!','success'=>false));exit;
 
- 			$data = $this->input->post('data',true);
 
- 			$data = explode('|',trim($data,'|'));
 
- 			$this->db->trans_begin();
 
- 			foreach ($data as $k=>$v)
 
- 		    {
 
- 				$this->classid->save(array('px'=>$k),$v);
 
- 			}
 
- 			if ($this->db->trans_status() === TRUE)
 
-         	{
 
- 				$this->db->trans_commit();
 
- 			}
 
- 			else
 
- 			{
 
- 				$this->db->trans_rollback();
 
- 			}
 
- 		}
 
- 	}
 
- }
 
 
  |