<?php

/*======================================================================*\
|| #################################################################### ||
|| # Drag'nDrop Shop 1.8                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright 2014 JAKWEB All Rights Reserved.                       # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| #   ----------- Drag'nDrop Shop IS NOT FREE SOFTWARE -----------   # ||
|| #                      http://www.jakweb.ch                        # ||
|| #################################################################### ||
\*======================================================================*/

class JAK_rewrite
{

	private $url_seg;
	private $data = array();
	
	// This constructor can be used for all classes:
	
	public function __construct($url){
			
			$this->url = $url;
	}
	
	public function jakGetseg($var)
	{
	
		if (JAK_USE_APACHE) {
		
			$url = str_replace(_APP_MAIN_DIR, '', $this->url);
			$_tmp = explode('?', $url);
			$url = $_tmp[0];
			
			if ($url = explode('/', $url)) {
			    foreach ($url as $d) {
			        if ($d) {
			            $data[] = $d;
			        }
			    }
			}
			
			$url_seg = $data[$var];
		
		} else {
	
			// get the url and parse it
			$parseurl = parse_url($this->url);
			
			// get only the query
			$parameters = $parseurl["query"];
			parse_str($parameters, $data);
			
			// Now we have to set the array to basic keys
			foreach($data as $d)
			{
				$data[] = $d;
			}
		
			$url_seg = $data[$var];
			
		}
		
		return $url_seg;
	}
	
	public function jakGetsegAdmin($var)
	{
	
			// get the url and parse it
			$parseurl = parse_url($this->url);
			
			// get only the query
			$parameters = $parseurl["query"];
			parse_str($parameters, $data);
			
			// Now we have to set the array to basic keys
			foreach($data as $d)
			{
				$data[] = $d;
			}
		
			$url_seg = $data[$var];
		
		return $url_seg;
	}
	
	public static function jakParseurl($var, $var1, $var2, $var3, $var4)
	{
	
		if (!JAK_USE_APACHE) {
		
			// Set v to zero
			$v = '';
			$v1 = '';
			$v2 = '';
				
			if ($var1) {
				$v = '&amp;w='.$var1;
			}
			if ($var2) {
				$v1 = '&amp;id='.$var2;
			}
			if ($var3) {
				$v2 = '&amp;s='.$var3;
			}
			
			if ($var4) {
				$v3 = '&amp;b='.$var4;
			}
			
			
			$var = 'p='.$var;
			
			// Now se the var for none apache
			$varname = 'index.php?'.$var.$v.$v1.$v2.$v3;
			
		} else {
		
			// Set v to zero
				$v = '';
				$v1 = '';
				$v2 = '';
			
				// if apache add some stuff to the url
				$var = $var;
					
				if ($var1) {
					$v = '/'.$var1;
				}
				if ($var2) {
					$v1 = '/'.$var2;
				}
				if ($var3) {
					$v2 = '/'.$var3;
				}
				if ($var4) {
					$v3 = '/'.$var4;
				}
				
			// Now se the var for none apache
			$varname = (_APP_MAIN_DIR ? _APP_MAIN_DIR.'/' : '/').$var.$v.$v1.$v2.$v3;
				
		}
		
		return $varname;
		
	}
	
	public static function jakParseurlpaginate($var)
	{
		
		// Check if is/not apache and create url
		if (!JAK_USE_APACHE && $var) {
			
			// Now se the var for none apache
			$varname = '&amp;page='.$var;
		
		} elseif (JAK_PAGINATE_ADMIN) {
			
			// Now se the var for none apache
			$varname = '&amp;page='.$var;
			
		} else {
				
			// Now se the var for none apache
			$varname = '/'.$var;
				
		}
		
		return $varname;
	
	}
	
	public function jakRealrequest()
	{
		$r = str_replace(_APP_MAIN_DIR, '', $this->url);
		
		return $r;
	}
}
?>