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

class userProfile extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('company/company_info_model');
        // $this->load->model('Useraccess');
        // $query = $this->Useraccess->useraccess_id_module2('9', 'transaction');
        // if(!$query){
        // 	echo '<script>alert("Not authorised..");
        // 		window.location.replace("'.base_url().'Error");
        /* 		</script>';*/
        // }
        // $this->load->model('menu');
    }

    public function index()
    {

    }

    public function Usermaster()
    {

        $this->load->model('Usermaster');
        if ($this->input->post('mysubmit')) {

            $this->load->model('Gallery_user');
            if ($this->input->post('fldid') == NULL) {
                $newusermaster = array(
                    'fldid' => $this->input->post('fldid'),
                    'userid' => $this->input->post('userid'),
                    'password' => $this->input->post('password'),
                    'username' => $this->input->post('username'),
                    'position' => $this->input->post('position'),
                    'email' => $this->input->post('email'),
                    'phone_off' => $this->input->post('phone_off'),
                    'Phone_mobile' => $this->input->post('phone_mobile'),
                    'department' => $this->input->post('department'),
                    'section' => $this->input->post('section'),
                    'language' => $this->input->post('language'),
                    'imageFile' => $this->input->post('userfile'),
                    'create_dt' => $this->input->post('order_time'),
                    'create_user' => element('userid', $this->session->userdata('logged_in'))
                );


                $insert_user = $this->Usermaster->usermaster_insert($newusermaster);
                if ($insert_user) {
                    $this->Gallery_user->do_upload($insert_user);
                    echo '<script>alert("Insert Data Success..");
				window.location.replace("usermasterlist");
				</script>';
                } else {
                    echo '<script>alert("Insert Data Failed.");
				history.go(-1);</script>';
                }
            } else {
                $fldid = $this->input->post('fldid');

                $image_name = $this->Gallery_user->do_upload($fldid);

                $editusermaster = array(
                    'userid' => $this->input->post('userid'),
                    'password' => $this->input->post('password'),
                    'username' => $this->input->post('username'),
                    'position' => $this->input->post('position'),
                    'email' => $this->input->post('email'),
                    'phone_off' => $this->input->post('phone_off'),
                    'Phone_mobile' => $this->input->post('phone_mobile'),
                    'department' => $this->input->post('department'),
                    'section' => $this->input->post('section'),
                    'language' => $this->input->post('language'),
                    'imageFile' => $image_name,
                    'modified_dt' => $this->input->post('order_time'),
                    'modified_user' => element('userid', $this->session->userdata('logged_in'))
                );

                $insert_user = $this->Usermaster->usermaster_edit($editusermaster, $fldid);
                if ($insert_user) {

                    $this->Gallery_user->do_upload($fldid);

                    echo '<script>alert("Update Success..");
					window.location = "' . base_url() . '";
					</script>';
                } else {
                    echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
                }
            }
        } else {
            $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : "";
            $this->load->library('layouts');
            $this->lang->load("usermaster", $this->session->userdata('language'));
            $this->load->model('Department');
            $data['deptrec'] = $this->Department->department_all();
            $this->load->model('Section');
            $data['secrec']  = $this->Section->section_all();
            $dataum          = $this->Usermaster->usermaster_id(element('role', $this->session->userdata('logged_in')));
            $data['umaster'] = $dataum[0];
            $this->load->model('Language');
            $data['language'] = $this->Language->language_all();
            $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')->add_includes('js/validationengine/jquery.validationEngine.js');
            $this->layouts->view('admin/userProfileEdit', array(
                'latest' => 'sidebar/latest'
            ), $data);

        }
    }


    public function userOnlineStatus()
    {
        $this->load->model('Usermaster');
        echo json_encode($this->Usermaster->userOnlineStatus());
    }

    public function poke()
    {
        $this->load->model('Usermaster');
        echo json_encode($this->Usermaster->poke());
    }

    public function getPoke()
    {
        $this->load->model('Usermaster');
        echo $this->Usermaster->getPoke();
    }


}


/* End of file admin.php */
/* Location: ./application/controller/admin.php */
