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

class AuthModel extends CI_Model {

    public function __construct(){
		parent::__construct();
		$this->load->database();
    }
    
    var $auth_key = "simplerestapi";

	public function get_row($where)
    {
		$sql = "select * from admin_tb".$where;
		$query = $this->db->query($sql);
		return $query->row_array();
	}
	
	public function qr_guest_row($where)
	{
		$sql = "select * from guest_tb".$where;
		$query = $this->db->query($sql);
		return $query->row_array();
	}

    public function get_bucketlist($site_url)
    {
        $sql = "select country_id,site_id,location_id from kiosk_tb where link ='".$site_url."'";
        $query = $this->db->query($sql);
        $countryid =  $query ->row_array()["country_id"];
        $siteid = $query->row_array()["site_id"];
        $locationid = $query->row_array()["location_id"];
        $sql = "select title from country_tb where id = ".$countryid;
        $query = $this->db->query($sql);
        $country = $query->row_array()["title"];
        if($locationid!=0)
        {
            $sql = "select title from location_tb where id = ".$locationid;
            $query = $this->db->query($sql);
            $data['location'] = $query->row_array()["title"];
        }
        else{
            $data['location'] = $query->row_array()["title"]="";
        }
        $sql = "select title from site_tb where id = ".$siteid;
        $query = $this->db->query($sql);
        $site = $query->row_array()["title"];
        $data['country'] = $country;
        $data['site'] = $site;
        $data['key'] = "ap-northeast-1:cefce7b8-4f7e-4da9-b130-e218ad97c1c8";
        return $data;
    }

	public function update_row($update_data, $id)
	{
		$this->db->update('admin_tb', $update_data, $id);
	}	

	public function get_guest_row($where)
    {
		$sql = "select * from guest_tb".$where;
		$query = $this->db->query($sql);
		return $query->row_array();
	}

	public function insert_guest_row($insert_data)
	{
		$this->db->insert('guest_tb', $insert_data);
	}

	public function update_guest_row($update_data, $id)
	{
		$this->db->update('guest_tb', $update_data, $id);
	}	
}