<?php

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

class Web_management extends CI_Controller
{


    function __construct()
    {
        parent::__construct();
        $this->load->model(array('Web_management_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()
    {
        $row = $this->Web_management_model->get_by_id();

        if ($row) {
            $data = array(
                'button' => 'Set Web',
                'action' => site_url('web_management/set_action'),
                'id' => set_value('id', $row->id),
                'nama_web' => set_value('nama_web', $row->nama_web),
                'deskripsi' => set_value('deskripsi', $row->deskripsi),
                'style_web' => set_value('style_web', $row->style_web),
            );

            $rows = $this->Web_management_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_management_form', $data + $data2);
        } else {
            $this->session->set_flashdata('message', 'Record Not Found');
            redirect(site_url('web_management'));
        }
    }

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

        if ($this->form_validation->run() == FALSE) {
            $this->index($this->input->post('id', TRUE));
        } else {
            $data = array(
                'nama_web' => $this->input->post('nama_web', TRUE),
                'deskripsi' => $this->input->post('deskripsi', TRUE),
                'style_web' => $this->input->post('style_web', TRUE),
            );

            $this->Web_management_model->update($this->input->post('id', TRUE), $data);
            $this->session->set_flashdata('message', 'Update Record Success');
            redirect(site_url('web_management'));
        }
    }

    public function _rules()
    {
        $this->form_validation->set_rules('nama_web', 'nama web', 'trim|required');
        $this->form_validation->set_rules('deskripsi', 'deskripsi', 'trim|required');
        $this->form_validation->set_rules('style_web', 'style web', 'trim|required');

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

/* End of file Web_management.php */
/* Location: ./application/controllers/Web_management.php */
/* Please DO NOT modify this information : */
/* Generated by IDETech Codeigniter CRUD Generator 2020-03-29 18:02:17 */
/* http://idetech.id */