<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*  Author  : Dhidhik /Tanggal : 20 Januari 2016
 *  Desc    : Untuk Keperluan Short key Event	
 *  Revisi  : 
 */

class Shortkey extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        //$this->default_value_isKeys();
    }	
    
    public function default_value_isKeys() { 
        //$this->load->library('session');
        $data = $this->session->userdata('keydata');
        $data = json_decode($data);
        if(!isset($data)){
            $data_array = array();
            $keydata = "keydata";
            for($exm=0;$exm<=255;$exm++){
                $data_value[$exm]=false;
            }                 
            $this->session->set_userdata('keydata',  json_encode($data_value));             
        }
    }
    
    public function reset_value_isKeys() { 
        $keydata = "keydata";
        for($exm=0;$exm<=255;$exm++){
            $data_value[$exm]=false;
        }                 
        $this->session->set_userdata('keydata',  json_encode($data_value));   
        echo json_encode($data_value);
    }
    
    public function get_value_isKeys() {  
        //$this->load->library('session');
        $data = $this->session->userdata('keydata');
        $data = json_decode($data);
        //echo "data = ".$data;
        if(!isset($data)){
            $data_array = array();
            $keydata = "keydata";
            for($exm=0;$exm<=255;$exm++){
                $data_value[$exm]=false;
            }     
            
            $this->session->set_userdata('keydata',  json_encode($data_value)); 
            $data = json_encode($data_value);
            
        }else{
            $data = json_encode($data);
        }
        echo ($data);
    }
    public function set_value_isKeys() {   
        //$this->default_value_isKeys();
        //$this->load->library('session');
        
        $varIndex   = $this->uri->segment(4) *1; 
        $value      = $this->uri->segment(5); 
        $value=="true"?$value=true:$value=false;
        
        $data               = $this->session->userdata('keydata');
        //echo "data = ".$data;
        $data               = json_decode($data);
        $data[$varIndex]    = $value;        
        $data               = json_encode($data);
        $this->session->set_userdata('keydata',  $data); 
        
        echo ($data);
    }
}
?>