<?php

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

class Copy_Location extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->common_model->checkAdminLogin();
        $this->load->model($this->config->item('adminFolder') . '/copy_location_model', 'copy_location');
        $this->load->model($this->config->item('adminFolder').'/country_model', 'country');
        $this->load->model($this->config->item('adminFolder').'/province_model', 'province');
        $this->load->library('form_validation');       
    }

    public function index() { 

        if (!empty($_POST)) {          
               //  pr($_POST);die;
            $this->form_validation->set_rules('country_id', 'Country', 'trim|required');
            $this->form_validation->set_rules('province_id', 'Province', 'trim|required');
            $this->form_validation->set_rules('country_id1', 'Country', 'trim|required');
            $this->form_validation->set_rules('province_id1', 'Province', 'trim|required');
            $this->form_validation->set_rules('table_name', 'Table Name', 'trim|required');

            if ($this->form_validation->run()) {
                $data['output'] = $output = $this->copy_location->getSelectedTableData();              
                $this->copy_location->copyData($output);
                $this->session->set_flashdata('LocationSuccess', 'Copy of data from one location to another has been done Successfully');
                redirect($this->config->item('adminFolder') . '/copy-location');
                exit;
            }else{
                    $data['country_id']  = $this->input->post('country_id');              
                    $data['province_id'] = $this->input->post('province_id');                  
                    $data['country_id1'] = $this->input->post('country_id1');                  
                    $data['province_id1'] = $this->input->post('province_id1');
                    $data['table_name'] = $this->input->post('table_name');
            }
        }
            
            $data['breadcum'] = 'Copy Location';
            $data['country_list'] = $this->country->getCountryList();
           
        $this->load->view($this->config->item('adminFolder') . '/header', $data);        
        $this->load->view($this->config->item('adminFolder') . '/copy_location/copy_location_form');
        $this->load->view($this->config->item('adminFolder') . '/footer');
    }
}