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

class Review extends CI_Controller 
{
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('Index_model');
	}
	public function review_order()
	{  
		$cart = $this->session->userdata('cart');
		if(empty($cart))
		{
			redirect(base_url());
		}
		else
		{
			$granttotal = 0;
			foreach ($cart as $cartcount => $form) { 
				$mtotal = 0;
				$mptotal = 0;
				$ntotal = 0;
				$nptotal = 0;
				$stotal = 0;
				$data['classform'.$form]=$this->Index_model->returnform($form);

				$classform = $this->Index_model->returnclass($form);

				$this->session->set_userdata('classform'.$form,$data['classform'.$form]);

				/*Member*/

				$member = ($this->session->userdata('member'.$form));

				if (!empty($member) || isset($member['M'])) {
					$i = 1;
					foreach ($member['M'] as $key => $value) {
						$i++;
					}
					$this->session->set_userdata('mcount'.$form,$i-1);
					$mtotal = $classform->class_price_m * ($i-1);
				}

				/*Member End*/

				/*Member 2+*/

				$memplus = ($this->session->userdata('memplus'.$form));

				if (!empty($memplus) || isset($memplus['M2'])) {
					$i = 1;
					foreach ($memplus['M2'] as $key => $value) {
						$i++;
					}
					$this->session->set_userdata('mpluscount'.$form,$i-1);
					$mptotal = $classform->class_price_m2 * ($i-1);
				}

				/*Member 2+ End*/

				/*Non Member*/

				$nonmember = $this->session->userdata('nonmember'.$form);

				if (!empty($nonmember) || isset($nonmember['N'])) {
					$i = 1;
					foreach ($nonmember['N'] as $key => $value) {
						$i++;
					}
					$this->session->set_userdata('ncount'.$form,$i-1);
					$ntotal = $classform->class_price_n * ($i-1);
				}

				/*Non Member End*/

				/*Non Member 2+*/

				$nonplus = $this->session->userdata('nonplus'.$form);

				if (!empty($nonplus) || isset($nonplus['N2'])) {
					$i = 1;
					foreach ($nonplus['N2'] as $key => $value) {
						$i++;
					}
					$this->session->set_userdata('npluscount'.$form,$i-1);
					$nptotal = $classform->class_price_n2 * ($i-1);
				}

				/*Non Member 2+ End*/

				/*Employee*/

				$semember = $this->session->userdata('semember'.$form);

				if (!empty($semember) || isset($semember['S'])) {
					$i = 1;
					foreach ($semember['S'] as $key => $value) {
						$i++;
					}
					$this->session->set_userdata('scount'.$form,$i-1);
					$stotal = $classform->class_price_s * ($i-1);
				}

				/*Employee End*/

				if(isset($mtotal)) { $mtot = $mtotal; } else { $mtot = 0; }
				if(isset($mptotal)) { $mptot = $mptotal; } else { $mptot = 0; }
				if(isset($ntotal)) { $ntot = $ntotal; } else { $ntot = 0; }
				if(isset($nptotal)) { $nptot = $nptotal; } else { $nptot = 0; }
				if(isset($stotal)) { $stot = $stotal; } else { $stot = 0; }
				$classtotal = $mtot + $mptot + $ntot + $nptot + $stot; /*Class Total*/
				$this->session->set_userdata('classtotal'.$form,$classtotal);
				$granttotal+=$classtotal;
			} 
			$this->session->set_userdata('granttotal',$granttotal);
			$this->load->view('front/review');
		}
	}

	public function back()
	{
		$urlcheck = $this->session->userdata('urlcheck');
		if($urlcheck)
		{
			redirect('loc-class/'.$urlcheck);
		}else{
			redirect(base_url());	
		}

	}

}
?>