<?php

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

class Website extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->common_model->checkAdminLogin();
        $this->load->model($this->config->item('adminFolder') . '/website_model', 'website');
        $this->load->library('form_validation');
    }

    public function index() {
        $data['lists'] = $lists = $this->website->website_list();
        $data['id'] = $settingId = $lists[0]['id'];
        $data['site_email'] = $lists[0]['site_email'];
        $data['contact_address'] = $lists[0]['contact_address'];
        $data['contact_no'] = $lists[0]['contact_no'];
        $data['siteon'] = $lists[0]['siteon'];
        $data['facebook'] = $lists[0]['facebook'];
        $data['twitter'] = $lists[0]['twitter'];
        $data['google'] = $lists[0]['google'];
        $data['youtube'] = $lists[0]['youtube'];
        $data['linkedin'] = $lists[0]['linkedin'];
        $data['delivery_note'] = $lists[0]['delivery_note'];
            $data['delivery_charges'] = $lists[0]['delivery_charges'];
            $data['minimum_order_amount'] = $lists[0]['minimum_order_amount'];
        $data['site_title'] = $lists[0]['site_title'];
        $data['meta_keywords'] = $lists[0]['meta_keywords'];
        $data['meta_description'] = $lists[0]['meta_description'];
        $data['google_code'] = $lists[0]['google_code'];
        $data['google_indexing'] = $lists[0]['google_indexing'];
        $data['google_analytic_code'] = $lists[0]['google_analytic_code'];
        $data['logo'] = $lists[0]['logo'];



        if (!empty($_POST)) {
            $data['site_email'] = $this->input->post('site_email');
            $data['paypal_email'] = $this->input->post('paypal_email');
            $data['contact_address'] = $this->input->post('contact_address');
            $data['facebook'] = $this->input->post('facebook');
            $data['twitter'] = $this->input->post('twitter');
            $data['google'] = $this->input->post('google');
            $data['youtube'] = $this->input->post('youtube');
            $data['linkedin'] = $this->input->post('linkedin');
            $data['site_title'] = $this->input->post('site_title');
             $data['delivery_note'] = $this->input->post('delivery_note');
            $data['delivery_charges'] = $this->input->post('delivery_charges');
            $data['minimum_order_amount'] = $this->input->post('minimum_order_amount');
            $data['meta_keywords'] = $this->input->post('meta_keywords');
            $data['meta_description'] = $this->input->post('meta_description');
            $data['google_code'] = $this->input->post('google_code');
            $data['google_indexing'] = $this->input->post('google_indexing');
            $data['google_analytic_code'] = $this->input->post('google_analytic_code');
            $data['logo'] = $this->input->post('logo');


            if ($_FILES["logo"]['name']) {
                $config['upload_path'] = './assets/uploads/site_images';
                $config['allowed_types'] = 'jpg|png|jpeg|gif';
                $this->load->library('upload', $config);
                if (!$this->upload->do_upload('logo')) {
                    $error_msg = $this->upload->display_errors();
                } else {
                    $detail = array('upload_data' => $this->upload->data());
                }
            }

//            if ($_FILES["favicon"]['name']) {
//                $config['upload_path'] = './assets/uploads/site_images';
//                $config['allowed_types'] = 'jpg|png|jpeg|gif';
//                $this->load->library('upload', $config);
//                if (!$this->upload->do_upload('favicon')) {
//                    $error_msg = $this->upload->display_errors();
//                } else {
//                    $detail = array('favicon_data' => $this->upload->data());
//                }
//            }

            $this->website->update($settingId, $detail['upload_data']['file_name']);
            $this->session->set_userdata('websiteSettingsUpdate', show_message('Website Setting Detail Has Been Update Successfully', 'success'));
            redirect($this->config->item('adminFolder') . '/website-links');
            exit;
        }
        $data['page_name'] = 'websiteSetting';
        $data['breadcum'] = 'Manage Website Setting';
        $this->load->view($this->config->item('adminFolder') . "/header", $data);
        $this->load->view($this->config->item('adminFolder') . '/website/website_form');
        $this->load->view($this->config->item('adminFolder') . '/footer');
    }

}