<?php

/* 
 * Author       : Jai K
 * Purpose      : Controller for Kiosk Admin Settings
 * Created On   : 2016-12-21 18:43
 */

/*
 * 
Advertisements
-----------------

* image
* Status

Events:
------------
* event_name
* event_slug
* event_start_date
* event_end_date
 
 * 
 */


class Billing_Settings extends REF_Controller {
    public $controller;
    
    function __construct() {
        parent::__construct();
        
        $segments = $this->uri->segments;
        $this->controller = $segments[1];
         
        
        $this->load->model('billing/bill_settings_model');
    }
    
    function index( $id='' ) {
        $post = $this->input->post();
        $session_data = $this->session->userdata(TBL_PREFIX . 'user_logged_in');
        $token = $this->session->userdata( 'rtoken-'.$session_data['user_id'] ); 
        
        $data = array(
            'title'          => 'Settings',
            'controller'     => $this->controller,
            'form_action'       => base_url() . $this->controller .'/',
            
        );
        
        $data['token'] = $this->auto_generation_code( rand( 999, 9999 ) );
        $this->session->set_userdata( 'rtoken-'.$session_data['user_id'], $data['token'] );
        
        if( !empty( $post['submit'] ) ) :// && $post['token'] == $token ) :
            // Update
            $this->bill_settings_model->manipulate();
            $data['success'] = "Information is updated successfully";
        endif;
        
        $results = $this->bill_settings_model->get(TBL_BILL_SETT, array('where' => array( 'status !=' => 2, 'slug !=' => 'event' ) , 'select' => 'id, name, slug, value, status, created_on, updated_on', 'order_by' => 'updated_on'));
        
		foreach($results as $k => $result) :
            $data[$result['slug']][] = $result;
        endforeach;		
        
        // Load Views
        $this->render( $data, 'billing/settings/index' );
    }
    
    function ajax(){
        echo json_encode( $this->bill_settings_model->ajax() );
    }
}