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

class Checkout extends Front_Controller
{
	public function __construct()
	{
		parent::__construct();
		// $this->checkUserLoginSession();
	}
	
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://www.janbasktraining.com/payment
	 *	- or -
	 * 		http://www.janbasktraining.com/Payment/index
	 */
	public function index()
	{
		$this->checkUserLoginSession();
		$user_id = $this->session->userdata("user_id");
		$data['cart_items'] = $this->PM->fetchCartDetails($user_id);
		$this->load->view($this->_checkout,$data);
	}
	
	public function enrollUser()
	{
		// $this->checkUserLoginSession();
		if(isset($_POST['batch_id']) && !empty($_POST['batch_id']))
		{
			// if($this->session->userdata("user_id"))
			// {
				$user_id = $this->session->userdata("user_id");
				if($user_id == "") {
					$user_id = $this->input->post('user_id');
					$admin_user = $this->input->post('admin_user');
					$this->session->set_userdata(array("user_id"=>$user_id,"admin_user"=>$admin_user));
				}
				
				$batch_id = $this->input->post('batch_id');
				$course_id = $this->input->post('course_id');
				$cart_data = array('user_id'=>$user_id,'batch_id'=>$batch_id,'course_id'=>$course_id);
				$check_cart = $this->PM->checkExistingCart($cart_data);
				$response = array('loged_in_user'=>'1','item_added'=>'1','redirect'=>'checkout');
			// }
			// else
			// {
				// $response = array('loged_in_user'=>'0','item_added'=>'0','redirect'=>'login');
			// }
			echo json_encode($response);
		}
		else
		{
			redirect(site_url());
		}
	}
	
		/**Function to add order data to table and redirect to payment gateway**/
	public function processOrder()
	{
		$this->checkUserLoginSession();
		if(isset($_POST['cart_id']) && !empty($_POST['cart_id']))
		{
			$user_id = $this->session->userdata("user_id");
			$cart_id = $this->input->post('cart_id');
			$amount_paid = $this->input->post('amount');
			$currency = 'USD';
			$order_date = date("Y-m-d");
			$checkOrder=$this->PM->checkUserOrder($user_id);
			
				/*Check if user is enrolled from admin*/
			$enrolled_by_admin = "";
			if($this->session->userdata("admin_user")){
				$enrolled_by_admin = $this->session->userdata("admin_user");
			}
				
			if($checkOrder)
			{
				
				$orderData=$this->PM->checkUserOrderExistsId($user_id);
				$orderId = $orderData[0]->id;
				$order_data = array("user_id"=>$user_id,"cart_id"=>$cart_id,"amount_paid"=>$amount_paid,"currency"=>$currency,"order_date"=>$order_date,"is_order_complete"=>"0","payment_status"=>'1',"enrolled_by_admin"=>$enrolled_by_admin);
				$response = $this->PM->updateOrder($order_data,$orderId);
				$response = array('order_created'=>'1');
			}
			else
			{
				$order_data = array("user_id"=>$user_id,"cart_id"=>$cart_id,"amount_paid"=>$amount_paid,"currency"=>$currency,"order_date"=>$order_date,"is_order_complete"=>"0","payment_status"=>'1',"enrolled_by_admin"=>$enrolled_by_admin);
				$response = $this->PM->createOrder($order_data);
			}
			
			$this->session->unset_userdata('admin_user');
				/*Enroll Admin user directly to course without payment*/
			if($user_id=="3") {
				$admin_order_data = $this->PM->getOrderData($user_id);
				$order_id = $admin_order_data[0]->id;
				$cart_id = $admin_order_data[0]->cart_id;
				$this->PM->updateOrderStatus($order_id,$cart_id);
				$cart_items = $this->PM->fetchCartData($cart_id);
				foreach($cart_items as $cart_item) {
					$enrolled_batch_data = array('course_id'=>$cart_item->course_id,'batch_id'=>$cart_item->batch_id,'user_id'=>$user_id);
					$this->PM->insertUserEnrolledBatch($enrolled_batch_data);
				} 
				$this->load->view($this->_payment_status);
			}
			
			echo json_encode($response);
			die();
			
		}
		else
		{
			redirect(site_url());
		}
	}
	<commit_msg>changes made for processing payment baseed on user<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Checkout extends Front_Controller
{
	public function __construct()
	{
		parent::__construct();
		// $this->checkUserLoginSession();
	}
	
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://www.janbasktraining.com/payment
	 *	- or -
	 * 		http://www.janbasktraining.com/Payment/index
	 */
	public function index()
	{
		$this->checkUserLoginSession();
		$user_id = $this->session->userdata("user_id");
		$data['cart_items'] = $this->PM->fetchCartDetails($user_id);
		$this->load->view($this->_checkout,$data);
	}
	
	public function enrollUser()
	{
		// $this->checkUserLoginSession();
		if(isset($_POST['batch_id']) && !empty($_POST['batch_id']))
		{
			// if($this->session->userdata("user_id"))
			// {
				$user_id = $this->session->userdata("user_id");
				if($user_id == "") {
					$user_id = $this->input->post('user_id');
					$admin_user = $this->input->post('admin_user');
					$this->session->set_userdata(array("user_id"=>$user_id,"admin_user"=>$admin_user));
				}
				
				$batch_id = $this->input->post('batch_id');
				$course_id = $this->input->post('course_id');
				$cart_data = array('user_id'=>$user_id,'batch_id'=>$batch_id,'course_id'=>$course_id);
				$check_cart = $this->PM->checkExistingCart($cart_data);
				$response = array('loged_in_user'=>'1','item_added'=>'1','redirect'=>'checkout');
			// }
			// else
			// {
				// $response = array('loged_in_user'=>'0','item_added'=>'0','redirect'=>'login');
			// }
			echo json_encode($response);
		}
		else
		{
			redirect(site_url());
		}
	}
	
		/**Function to add order data to table and redirect to payment gateway**/
	public function processOrder()
	{
		$this->checkUserLoginSession();
		if(isset($_POST['cart_id']) && !empty($_POST['cart_id']))
		{
			$user_id = $this->session->userdata("user_id");
			$cart_id = $this->input->post('cart_id');
			$amount_paid = $this->input->post('amount');
			$currency = 'USD';
			$order_date = date("Y-m-d");
			$checkOrder=$this->PM->checkUserOrder($user_id);
			
				/*Check if user is enrolled from admin*/
			$enrolled_by_admin = "";
			if($this->session->userdata("admin_user")){
				$enrolled_by_admin = $this->session->userdata("admin_user");
			}
				
			
			if($checkOrder)
			{
				
				$orderData=$this->PM->checkUserOrderExistsId($user_id);
				$orderId = $orderData[0]->id;
				$order_data = array("user_id"=>$user_id,"cart_id"=>$cart_id,"amount_paid"=>$amount_paid,"currency"=>$currency,"order_date"=>$order_date,"is_order_complete"=>"0","payment_status"=>'1',"enrolled_by_admin"=>$enrolled_by_admin);
				$response = $this->PM->updateOrder($order_data,$orderId);
				$response = array('order_created'=>'1',"redirect"=>"payment");
			}
			else
			{
				$order_data = array("user_id"=>$user_id,"cart_id"=>$cart_id,"amount_paid"=>$amount_paid,"currency"=>$currency,"order_date"=>$order_date,"is_order_complete"=>"0","payment_status"=>'1',"enrolled_by_admin"=>$enrolled_by_admin);
				$response = $this->PM->createOrder($order_data);
				$response["redirect"] = "payment";
			}
			
			$this->session->unset_userdata('admin_user');
				/*Enroll Admin user directly to course without payment*/
			if($user_id=="3") {
				$admin_order_data = $this->PM->getOrderData($user_id);
				$order_id = $admin_order_data[0]->id;
				$cart_id = $admin_order_data[0]->cart_id;
				$this->PM->updateOrderStatus($order_id,$cart_id);
				$cart_items = $this->PM->fetchCartData($cart_id);
				foreach($cart_items as $cart_item) {
					$enrolled_batch_data = array('course_id'=>$cart_item->course_id,'batch_id'=>$cart_item->batch_id,'user_id'=>$user_id);
					$this->PM->insertUserEnrolledBatch($enrolled_batch_data);
				} 
				$response = array('order_created'=>'1',"redirect"=>"payment-status");
			}
			
			echo json_encode($response);
			die();
			
		}
		else
		{
			redirect(site_url());
		}
	}
	
{'fraction_non_alphanumeric': 0.20558602219104705, 'fraction_numerical': 0.003443438336946818, 'mean_word_length': 4.686729514140682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 191, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3730334', 'n_tokens_mistral': 3217, 'n_tokens_neox': 2782, 'n_words': 324}