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

class MerchandiseController extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('GuestModel');
		$this->load->model('CountryModel');
		$this->load->model('SiteModel');
		$this->load->model('CartModel');
		$this->load->model('LocationModel');
		$this->load->model('SouvenirModel');
		$this->load->model('GalleryModel');
		$this->load->model('AuthModel');
		$this->load->model('NotificationModel');
	}

	public function index()
	{
		$userdata = $this->session->userdata('makeabl2020');
		if (empty($userdata) || !isset($userdata["id"]))
			redirect('login', 'refresh');
        
        $site_row = $this->SiteModel->get_row($userdata['site_id']);
        
		$data['title'] = 'Purchase Merchandise | MAKEABL';
		$data['userdata'] = $userdata;
		$data['guest_detail'] = $this->GuestModel->get_row($userdata['id']);
		$data['merchandise_list'] = $this->SouvenirModel->get_rows(" and souvenir_size_tb.price <> 0 and site_tb.id = '".$userdata['site_id']."' group by souvenir_tb.id order by souvenir_tb.id desc");
		$data['notification_list'] = $this->NotificationModel->get_rows(" where id > 0 and isDeleted = 0 and guest_id = '".$userdata["id"]."' order by id desc");
		$data['new_notification_count'] = $this->NotificationModel->get_count(" where id > 0 and isDeleted = 0 and guest_id = '".$userdata["id"]."' and isShow = 0");
		$data['site_logo'] = 'http://d1z6a3vjnfowyr.cloudfront.net/'.$site_row['logo'];
		$data['is_single_gallery'] = $site_row['is_single_gallery'];
		
		$this->load->view('template/header', $data);
		$this->load->view('template/sidebar', $data);
		$this->load->view('merchandise', $data);
		$this->load->view('template/footer', $data);
	}

	public function detail()
	{
		$userdata = $this->session->userdata('makeabl2020');
		if (empty($userdata) || !isset($userdata["id"]))
			redirect('login', 'refresh');
		
		$id = $this->uri->segment(2);
		$site_row = $this->SiteModel->get_row($userdata['site_id']);
		$detail = $this->SouvenirModel->get_row($id);
		
		$getsiteResult = $this->SiteModel->get_site_row($detail['site_id']);
		
		$data['title'] = 'Merchandise Detail | MAKEABL';
		$data['userdata'] = $userdata;
		$data['detail'] = $detail;
		$data['guest_detail'] = $this->GuestModel->get_row($userdata['id']);
		$data['cart_list'] = $this->CartModel->get_rows(" where cart_tb.site_id =  '".$userdata['site_id']."' and  cart_tb.user_id='".$userdata['id']."'");
		$data['detail_size'] = $this->SouvenirModel->get_size_rows(" where souvenir_size_tb.id > 0 and souvenir_size_tb.isDeleted = 0 and souvenir_size_tb.souvenir_id = '".$id."'");
		$data['notification_list'] = $this->NotificationModel->get_rows(" where id > 0 and isDeleted = 0 and guest_id = '".$userdata["id"]."' order by id desc");
		$data['new_notification_count'] = $this->NotificationModel->get_count(" where id > 0 and isDeleted = 0 and guest_id = '".$userdata["id"]."' and isShow = 0");
		$data['site_logo'] = 'http://d1z6a3vjnfowyr.cloudfront.net/'.$site_row['logo'];
		$data['is_single_gallery'] = $site_row['is_single_gallery'];
		
		$this->load->view('template/header', $data);		
		$this->load->view('template/sidebar', $data);		
		$this->load->view('merchandise-detail', $data);
		$this->load->view('template/footer', $data);		
	}
}