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

class SiteDataModel extends CI_Model { 

    public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	public function insert_row($guest_id = '', $clicks = '', $description = 'Page')
	{
		if(!empty($clicks))
		{
			date_default_timezone_set('Asia/Singapore');
    
			if(!empty($this->session->userdata('makeabl2020')))
			{
				$userdata = $this->session->userdata('makeabl2020');
				$guest_id = !empty($userdata["id"]) ? $userdata["id"] : '';
			}

			$site_url_site_data = $_SERVER['HTTP_HOST'];
			$site_row_site_data = $this->SiteModel->get_row_from_url($site_url_site_data);
			$site_data_site_id = !empty($site_row_site_data['id']) ? $site_row_site_data['id'] : '19';
			
			if($clicks == 'Download')
			{
				if(!empty($guest_id))
				{
					$arraySiteData = array(
						'guest_id' => $guest_id,
						'site_id' => $site_data_site_id,
						'ip_address' => $_SERVER['REMOTE_ADDR'],
						'browser' =>  $_SERVER['HTTP_USER_AGENT'],
						'url' =>  current_url(),
						'clicks' => $clicks,
						'description' => $description,
						'created_at' => date('Y-m-d H:i:s'),
						'created_date' => time(),
						'only_date' => date('Y-m-d')
					);

					$inserDataSite = $this->db->insert('site_data', $arraySiteData);
				}
				
				return true;
			}
			else
			{
				$arraySiteData = array(
					'guest_id' => $guest_id,
					'site_id' => $site_data_site_id,
					'ip_address' => $_SERVER['REMOTE_ADDR'],
					'browser' =>  $_SERVER['HTTP_USER_AGENT'],
					'url' =>  current_url(),
					'clicks' => $clicks,
					'description' => $description,
					'created_at' => date('Y-m-d H:i:s'),
					'created_date' => time(),
					'only_date' => date('Y-m-d')
				);

				$inserDataSite = $this->db->insert('site_data', $arraySiteData);
				return true;
			}
			
		}

	   
	}

}