<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Process extends CI_Model{
	function __construct()
	{
		parent::__construct();
	}
	function loginauth($username,$password)
	{
		$pass = MD5($password);
		$query = $this->db->query("select * from tbl_admin where user_name = '".$username."' and password = '".$pass."'");
		if($query->num_rows() == 1)
		{
			return $query->row_array(); 
		}
		else
		{
			return false;
		}
	}
	function logoutupdate($adminid)
	{
		date_default_timezone_set('Asia/Calcutta');
		$date = date("Y-m-d");
		$time = date("H:i:s");
		$query = $this->db->query("update tbl_admin set last_login='".$date."', login_time='".$time."' where admin_id='".$adminid."'");
		return $query ;		
		
	}
	function ChangePassword($adminid)
	{
		$oldpass = MD5($this->input->post('oldpass'));
		$newpass = MD5($this->input->post('newpass'));
		$query = $this->db->query("select * from tbl_admin where admin_id='".$adminid."'");
		if($query->num_rows() == 1)
		{
			return $query->row_array(); 
		}
		else
		{
			return false;
		}
		
	}
	function UploadHandheldData()
	{
		if($_FILES['datafile']['name']!="")
		{
			if(($handle = fopen($_FILES['datafile']['tmp_name'], "r")) !== FALSE) 
			{
				while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
				{
					$tag_id = $data[0];
					$time_in = $data[1];
					
					$date = $time_in;
					$currentDate = strtotime($date);
					$futureDate = $currentDate+(60*5);
					$time_out = date("Y-m-d H:i:s", $futureDate);
					
					$insertsql="insert into log (tag_id, time_in ,time_out) values('".$tag_id."', '".$time_in."', '".$time_out."')";
					$insertquery = $this->db->query($insertsql);
				}
				fclose($handle);
			}
			return $insertquery;
		}
	}
}