<?php

class Status extends MY_Controller{
    
    public function __construct(){
        parent::__construct();
        $this->load->model('manage/status_model');
    }
    public function index(){
        $_data ['button']=$this->navButton('Manage');
        $_data ['url'] = $this->url;
        $this->load->view('manage/status',$_data); 
    }
    
     public function add_status(){

             $_data ["status_name"]=$this->input->post('status_name');           
             if($_data ["status_name"]){
                 $_row = $this->status_model->get_status_name($_data ["status_name"]);
                 if($_row){
                     echo'{"success":false,"message":"添加失败,状态名已经存在！"}';exit;
                 }
             }else{
                     echo'{"success":false,"message":"非法访问"}';exit;
             }
             if($this->status_model->add_status($_data)){
                 echo'{"success":true,"message":"添加成功"}';
             }else{
                 echo'{"success":false,"message":"添加失败"}';
             }

     }     
    
     public function update_status(){
         $_id=$this->input->post('status_id');
         if(isset($_id)){
             $_data ["status_name"]=$this->input->post('status_name');
             if($this->status_model->update_status($_id,$_data)){
                 echo'{"success":true,"message":"修改成功"}';
             }else{
                 echo'{"success":false,"message":"修改失败"}';
             }
         }else{
             echo'{"success":false,"message":"非法访问"}';
         }        
     }
   
    
    public function get_status(){
       $_row = $this->status_model->get_status();
       $_row=array_values($_row);
       $_str='['.substr(json_encode($_row),1,-1).']';
       echo $_str;
    }

    
    
    public function get_one_status(){
            $_id=$this->input->post('id');
        if(isset($_id)){
            if($this->status_model->get_one_status($_id)){
                $_row = $this->status_model->get_one_status($_id);
                $_row = json_encode($_row);
                echo '['.$_row.']';
            }else{
                echo'{"success":false,"message":"状态不存在"}';
            }
        }else{
            echo'{"success":false,"message":"非法访问"}';
        }
     
     }
     
}