<?php
/**
 * @package BILLETS
 * @link 	http://www.dioscouri.com
 * @license GNU/GPLv2
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
* 	BilletsBuildRoute
*/
// ************************************************************************
function BilletsBuildRoute(&$query)
{
	$segments = array();
	
	if(isset($query['controller']))
	{
		$segments[] = $query['controller'];
		unset($query['controller']);
	}
	
	if(isset($query['task'])) 
	{
		$segments[] = $query['task'];
		unset($query['task']);
	};
		
	if(isset($query['view'])) 
	{
		$segments[] = $query['view'];
		unset($query['view']);
	};

	if(isset($query['id']))
	{
		$segments[] = $query['id'];
		unset($query['id']);
	};

	return $segments;
}

/**
* 	BilletsParseRoute
*/
// ************************************************************************
function BilletsParseRoute($segments)
{
       $vars = array();
       switch($segments[0])
       {
		   case 'billets':
				   $vars['view'] = 'default';
				   break;
		   case 'ticket':
			   switch($segments[1])
			   {
				   case 'view':
				   		   $vars['controller'] = 'ticket';
						   $vars['task'] = 'view';
						   $vars['view'] = 'default';
						   $id = explode( ':', $segments[2] );
						   $vars['id'] = (int) $id[0];				   
						   break;
				   case 'new':
				   		   $vars['controller'] = 'ticket';
						   $vars['task'] = 'new';
						   $vars['view'] = 'form';
						   break;
				}
       }
	   
       return $vars;
}