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

class Profile extends CI_Controller {

	function __construct() {
		error_reporting(0);
		parent::__construct();
		$this->load->model('CommonModel');
		$this->load->helper('Security');

	}


	public function ChangeDetails()
	{
		if(check_login())
		{
			$data['content'] = 'Profile/Edit';
			$this->load->view('layout_home', $data);
		}
	}
	public function ChangePassword()
	{
		if(check_login())
		{
			$data['content'] = 'Profile/PassEdit';
			$this->load->view('layout_home', $data);
		}
	}

	public function Hod()
	{
		if(isHod())
		{
			$data['content'] = 'Change/hod';
			$this->load->view('layout_hod', $data);
		}
	}

	public function Controller()
	{
		if(isController())
		{
			$data['content'] = 'Change/controller';
			$this->load->view('layout_controller', $data);
		}
	}

	public function check()
	{

		if(check_login())
		{

			$data = $this->input->post();

			$data = $this->security->xss_clean($data);

	        $md5_convert_data = md5($this->db->escape_like_str($data['old']));
	        $salt_key = get_encript_id($this->db->escape_like_str($data['old']));
	        $password = $md5_convert_data . $salt_key;

	        $user_exsist = $this->db->select('*')->where('email', $this->session->userdata('admin_user_id'))->where('password', $password)->get('admin')->result_array();

	        if (!empty($user_exsist) && count($user_exsist) > 0) {
	            echo 'true';
	        } else {
	        	echo 'false';
	        }

		}

	}


	public function change_pass()
	{

		if(check_login())
		{


			$data = $this->input->post();
			$old_md5_convert_data = md5($data['old_password']);
			$old_salt_key = get_encript_id($data['old_password']);
			$oldpass = $old_md5_convert_data . $old_salt_key;
			$user_exsist = $this->db->select('*')->where('admin_id', $this->session->userdata('admin_id'))->where('password', $oldpass)->get('admin')->result_array();
			if(!$user_exsist){
				echo "failed";
			}
			else{
			$md5_convert_data = md5($data['new_pass']);
			$salt_key = get_encript_id($data['new_pass']);
			$password = $md5_convert_data . $salt_key;

			$sql_upd=" UPDATE `admin` SET `password`='".$password."' WHERE `admin_id`='".$this->session->userdata('admin_id')."' ";
			$this->db->query($sql_upd);
			$this->session->set_userdata('password_change', 1);
			echo "success";
			
		}
		}

	}

	public function update_details()
	{

		if(check_login())
		{


			$data = $this->input->post();

			
			
			// $this->CommonModel->edit_data('admin', 'admin_id', $this->session->userdata('admin_id'), $upd);
			$sql_upd=" UPDATE `admin` SET `fullname`='".$data['fullname']."',`email`='".$data['email']."',`mobile_no`='".$data['mobile_no']."' WHERE `admin_id`='".$this->session->userdata('admin_id')."' ";
			$this->db->query($sql_upd);
			$this->session->set_userdata('password_change', 1);
			echo "success";
			
		
		}

	}

}
