<?php

class FreelanceController extends CI_Controller
{

	public function index()
	{

		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');


		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;


		$data['job_elements'] = $this->jobElements();

		$this->load->view('freelance/add-freelance.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	public function jobElements()
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/job-elements");
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function postedJob()
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');


		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['jobs'] = $this->postedByMe($user_id);

		$this->load->view('freelance/jobs.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	public function postedByMe($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/job-posted-by-merchant/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function viewJobPost($id)
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');


		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['job'] = $this->singlePostView($id, $user_id);

		$this->load->view('freelance/view-job-post.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	public function singlePostView($id, $user_id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/job-post-view-by-merchant/" . $id . '/' . $user_id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function hire($id)
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');


		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['jobs'] = $this->bidInfo($id);

		$this->load->view('freelance/hire-freelancer.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	/* Single Bid Information Start */

	public function bidInfo($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/job/bid/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}


	/* My Jobs Hired Freelancers start */
	public function myJobsHired()
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');

		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['jobs'] = $this->hiredJobs($user_id);

		$this->load->view('freelance/hire-freelancer.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}
	/* My Jobs Hired Freelancers End */

	public function hiredJobs($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/job/hired/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function newMerchantDeposit()
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');


		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['deposits'] = $this->myDeposits($user_id);


		$this->load->view('freelance/my-deposits.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	/* My All Deposits start */

	public function myDeposits($user_id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/merchant-deposits/" . $user_id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	/* My All Deposits End */

	/* My All Jobs start */
	public function myEarn()
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');

		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;
		$data['jobs'] = $this->meAsAFreelancer($user_id);

		$this->load->view('freelance/my-freelance-jobs.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}
	/* My All Jobs End */


	public function meAsAFreelancer($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/merchant-bid-allowed-jobs/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function JobChat($bid_id)
	{
		$this->load->view('templates/1_head.php');

		$this->load->view('templates/2_nav.php');

		$this->load->view('templates/3_sidebar_menu_left.php');

		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;

		$data['chats'] = $this->bidChat($bid_id);
		$data['bid_id'] = $bid_id;
		$this->load->view('freelance/chat-with-freelancer.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	public function bidChat($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/merchant-job-chats/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}

	public function chatList()
	{
		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;
		$data['chats'] = $this->jobChatFetch($user_id);
		$this->load->view('freelance/chat-lists.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}

	public function jobChatFetch($id)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "https://myadmin.mali-mart.com/api/chat-group-by-job/" . $id);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}


	public function AsHired()
	{

		$this->load->model('Freelance');

		$this->load->view('templates/1_head.php');
		$this->load->view('templates/2_nav.php');
		$this->load->view('templates/3_sidebar_menu_left.php');
		$user_id = $this->session->user_id;
		$user_data = get_user_data($user_id);
		$data['user'] = $user_data;
		$data['jobs'] = $this->Freelance->asIamHired($user_id);

		$this->load->view('freelance/asHired.php', $data); //4_dynamic

		$this->load->view('templates/5_footer.php');

		$this->load->view('templates/6_script_end.php');
	}
}
