<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Web_style extends CI_Controller
{


    function __construct()
    {
        parent::__construct();
        $this->load->model(array('Web_style_model', 'Ion_auth_model'));
        $this->load->database();
        $this->load->library(array('ion_auth', 'form_validation'));
        $this->load->helper(array('url', 'language'));

        $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));

        $this->lang->load('auth');
    }

    public function index()
    {
        $web_style = $this->Web_style_model->get_all();

        $data = array(
            'web_style_data' => $web_style
        );

        $row = $this->Web_style_model->get_style();
        $data2 = array(
            'web_meta_color' => $row->meta_color,
            'web_navbar_color' => $row->navbar_color,
            'web_box_color' => $row->box_color,
            'web_box_bottom' => $row->box_bottom,
        );

        $this->template->load('template', 'web_style/web_style_list', $data + $data2);
    }

    public function read($id)
    {
        $row = $this->Web_style_model->get_by_id($id);
        if ($row) {
            $data = array(
                'id_web_style' => $row->id_web_style,
                'name_style' => $row->name_style,
                'meta_color' => $row->meta_color,
                'navbar_color' => $row->navbar_color,
                'box_color' => $row->box_color,
                'box_bottom' => $row->box_bottom,
            );

            $rows = $this->Web_style_model->get_style();
            $data2 = array(
                'web_meta_color' => $rows->meta_color,
                'web_navbar_color' => $rows->navbar_color,
                'web_box_color' => $rows->box_color,
                'web_box_bottom' => $rows->box_bottom,
            );

            $this->template->load('template', 'web_style/web_style_read', $data + $data2);
        } else {
            $this->session->set_flashdata('message', 'Record Not Found');
            redirect(site_url('web_style'));
        }
    }

    public function create()
    {
        $data = array(
            'button' => 'Simpan',
            'action' => site_url('web_style/create_action'),
            'id_web_style' => set_value('id_web_style'),
            'name_style' => set_value('name_style'),
            'meta_color' => set_value('meta_color'),
            'navbar_color' => set_value('navbar_color'),
            'box_color' => set_value('box_color'),
            'box_bottom' => set_value('box_bottom'),
        );

        $row = $this->Web_style_model->get_style();
        $data2 = array(
            'web_meta_color' => $row->meta_color,
            'web_navbar_color' => $row->navbar_color,
            'web_box_color' => $row->box_color,
            'web_box_bottom' => $row->box_bottom,
        );

        $this->template->load('template', 'web_style/web_style_form', $data + $data2);
    }

    public function create_action()
    {
        $this->_rules();

        if ($this->form_validation->run() == FALSE) {
            $this->create();
        } else {
            $data = array(
                'name_style' => $this->input->post('name_style', TRUE),
                'meta_color' => $this->input->post('meta_color', TRUE),
                'navbar_color' => $this->input->post('navbar_color', TRUE),
                'box_color' => $this->input->post('box_color', TRUE),
                'box_bottom' => $this->input->post('box_bottom', TRUE),
            );

            $this->Web_style_model->insert($data);
            $this->session->set_flashdata('message', 'Create Record Success');
            redirect(site_url('web_style'));
        }
    }

    public function update($id)
    {
        $row = $this->Web_style_model->get_by_id($id);

        if ($row) {
            $data = array(
                'button' => 'Update',
                'action' => site_url('web_style/update_action'),
                'id_web_style' => set_value('id_web_style', $row->id_web_style),
                'name_style' => set_value('name_style', $row->name_style),
                'meta_color' => set_value('meta_color', $row->meta_color),
                'navbar_color' => set_value('navbar_color', $row->navbar_color),
                'box_color' => set_value('box_color', $row->box_color),
                'box_bottom' => set_value('box_bottom', $row->box_bottom),
            );

            $rows = $this->Web_style_model->get_style();
            $data2 = array(
                'web_meta_color' => $rows->meta_color,
                'web_navbar_color' => $rows->navbar_color,
                'web_box_color' => $rows->box_color,
                'web_box_bottom' => $rows->box_bottom,
            );

            $this->template->load('template', 'web_style/web_style_form', $data + $data2);
        } else {
            $this->session->set_flashdata('message', 'Record Not Found');
            redirect(site_url('web_style'));
        }
    }

    public function update_action()
    {
        $this->_rules();

        if ($this->form_validation->run() == FALSE) {
            $this->update($this->input->post('id_web_style', TRUE));
        } else {
            $data = array(
                'name_style' => $this->input->post('name_style', TRUE),
                'meta_color' => $this->input->post('meta_color', TRUE),
                'navbar_color' => $this->input->post('navbar_color', TRUE),
                'box_color' => $this->input->post('box_color', TRUE),
                'box_bottom' => $this->input->post('box_bottom', TRUE),
            );

            $this->Web_style_model->update($this->input->post('id_web_style', TRUE), $data);
            $this->session->set_flashdata('message', 'Update Record Success');
            redirect(site_url('web_style'));
        }
    }

    public function delete($id)
    {
        $row = $this->Web_style_model->get_by_id($id);

        if ($row) {
            $this->Web_style_model->delete($id);
            $this->session->set_flashdata('message', 'Delete Record Success');
            redirect(site_url('web_style'));
        } else {
            $this->session->set_flashdata('message', 'Record Not Found');
            redirect(site_url('web_style'));
        }
    }

    public function _rules()
    {
        $this->form_validation->set_rules('name_style', 'name style', 'trim|required');
        $this->form_validation->set_rules('meta_color', 'meta color', 'trim|required');
        $this->form_validation->set_rules('navbar_color', 'navbar color', 'trim|required');
        $this->form_validation->set_rules('box_color', 'box color', 'trim|required');
        $this->form_validation->set_rules('box_bottom', 'box bottom', 'trim|required');

        $this->form_validation->set_rules('id_web_style', 'id_web_style', 'trim');
        $this->form_validation->set_error_delimiters('<span class="text-danger">', '</span>');
    }
}

/* End of file Web_style.php */
/* Location: ./application/controllers/Web_style.php */
/* Please DO NOT modify this information : */
/* Generated by IDETech Codeigniter CRUD Generator 2020-06-20 15:33:01 */
/* http://idetech.id */