<?php
/**
* @version		3.0.0
* @package		JomLand TicketCenter
* @copyright	Copyright (C) 2010 JomLand.com. All rights reserved.
* @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

defined('_JEXEC') or die();

class JLTicketCenterCart{
	public  $event_id;
	public  $add_time;
	public  $ticket_type;
	public  $ticket_price;
	public  $quantity;
	public  $event_obj;
	
	function fixObject(&$object){
	  if (!is_object ($object) && gettype ($object) == 'object')
	    return ($object = unserialize (serialize ($object)));
	  return $object;
	} //EOF fixObject
	
	function getCartData(){
		$session = JFactory::getSession();
		$seesion_id = $session->getId();
		
		if ($session->get('jlticketcenter_cart')){
			//var_dump($session->get('jlticketcenter_cart'));
			foreach ($session->get('jlticketcenter_cart')as $k=>$v ){
				$new_v = JLTicketCenterCart::fixObject($v);
				$cart[$k] =$new_v;
			}
		}
		
		
		
		//var_dump($cart);
		return $cart;
	}//EOF getCartData()
	
	function cleanCart(){
		$session = JFactory::getSession();
		$seesion_id = $session->getId();
		
		$session->clear('jlticketcenter_cart');
		
		return;
	}//EOF cleanCart()
	
	
	public static function quantityDropdown($value=0,$id='qty',$class='',$ticket=null){
		
		 $pparams = new JLTicketCenterHelperSetup;
		 $default = $pparams->get('def_qty',2);
		 if ($value>0){
		 	$default=$value; 
		 }

		if (isset($ticket->in_cart)){
			$in_cart =$ticket->in_cart; 
		}else{
			$in_cart =0;
		}
		 
		 $avail_qty = $ticket->tickets-$ticket->tickets_sold-$ticket->tickets_ordered - $in_cart;
		 
		 if ($pparams->get('qty_max',1)<$avail_qty){
		 	$avail_qty = $pparams->get('qty_max',1);
		 }
			
		  $qty_array = array();
		  for ($i=1;$i<=$avail_qty ;$i++){
		  	$qty_array[$i]=$i;
		  } 
		  
		  $options = array();
		  foreach($qty_array  as $key=>$value) :
		  		$options[] = JHTML::_('select.option', $key, $value);
		  endforeach;
		 
		  $dropdown = JHTML::_('select.genericlist', $options, $id, 'class="inputbox jltc_qty_select'.$class.'"', 'value', 'text', $default);
		  
		  return $dropdown;
	}//EOF quantityDropdown
}