<?php

class Button extends MY_Controller{
    
    public function __construct(){
        parent::__construct();
        $this->load->model('base/button_model');
    }
    public function index(){
        $_data ['button']=$this->navButton('Base');
        $_data ['url'] = $this->url;
        $this->load->view('base/button',$_data); 
    }
    
    public function get_button(){
       $_row = $this->button_model->get_button();
       $_row=array_values($_row);
       $_str='['.substr(json_encode($_row),1,-1).']';
       echo $_str;
    }  
    
    public function get_one_button(){
        $_id=$this->input->post('id');
        if(isset($_id)){
            if($this->button_model->get_one_button($_id)){
                $_row = $this->button_model->get_one_button($_id);
                $_row = json_encode($_row);
                echo '['.$_row.']';;
            }else{
                echo'{"success":false,"message":"按钮不存在"}';
            }
        }else{
            echo'{"success":false,"message":"非法访问"}';
        }       
     }
     
     public function add_button(){

             $_data ["button_name"]=$this->input->post('button_name');
             $_data ["button_icon"]=$this->input->post('button_icon');
             $_data ["button_level"]=$this->input->post('button_level');
             $_data ["button_way"]=$this->input->post('button_way');
              
             if($this->button_model->add_button($_data)){
                 echo'{"success":true,"message":"添加成功"}';
             }else{
                 echo'{"success":false,"message":"添加失败"}';
             }

     }     
     
     public function update_button(){
         $_id=$this->input->post('button_id');
         if(isset($_id)){
             $_data ["button_icon"]=$this->input->post('button_icon');
             $_data ["button_level"]=$this->input->post('button_level');
             $_data ["button_way"]=$this->input->post('button_way');
             
             if($this->button_model->update_button($_id,$_data)){
                 echo'{"success":true,"message":"修改成功"}';
             }else{
                 echo'{"success":false,"message":"修改失败"}';
             }
         }else{
             echo'{"success":false,"message":"非法访问"}';
         }        
     }
}