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


class ProductController extends CI_Controller
{

	public function curlApi($url = '')
	{


		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($ch, CURLOPT_HEADER, FALSE);

		$response = curl_exec($ch);
		curl_close($ch);

		return $response;
	}

	public function index()
	{
		chk_login();
		$user_id = $this->session->user_id;
		$data['categories'] = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/category1"));
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;
		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$this->load->view('product/add-product', $data); //4_dynamic
		$this->load->view('templates/5_footer.php');
		$this->load->view('templates/6_script_end.php');
	}

	public function all_Products()
	{
		chk_login();
		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;
		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$this->load->view('product/all-product.php', $data); //4_dynamic
		$this->load->view('templates/5_footer.php');
		$this->load->view('templates/6_script_end.php');
	}

	public function editProduct($id = '')
	{
		chk_login();
		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$edit = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/edit-product/$id/$user_data->own_refer_id"));


		$data['edit_product'] = $edit;


		$sizes = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/sizes"));

		$colors = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/colors"));

		$data['categories'] = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/category1"));

		$data['sub_category'] = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/sub-cat/" . $edit->sub_cat));

		$data['sizes'] = $sizes->sizes;

		$data['colors'] = $colors->colors;

		$data['user'] = $user_data;
		$data['product_id'] = $id;
		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$this->load->view('product/edit-product.php', $data); //4_dynamic
		$this->load->view('templates/5_footer.php');
		$this->load->view('templates/6_script_end.php');
	}

	public function orders()
	{
		chk_login();
		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);

		$orders = json_decode($this->curlApi("https://myadmin.mali-mart.com/api/orders"));

		$data['user'] = $user_data;
		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$this->load->view('product/product-orders.php', $data); //4_dynamic
		$this->load->view('templates/5_footer.php');
		$this->load->view('templates/6_script_end.php');
	}
}
