<?
	//error_reporting(E_ERROR | E_WARNING | E_PARSE);
	error_reporting(E_ALL);
	ini_set('display_errors', '1');
	
	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header ("Cache-Control: nocache, must-revalidate");
	header ("Pragma: nocache");
	
		
	function u_dan($date_time = 0, $brojcano = 0, $lang = 0){
		if($date_time == 0){
			$date_time = "now";
		}
  	$l_timestamp = strtotime($date_time);
  	if($brojcano){
    	$izl =  date("w", $l_timestamp);
      return $izl;
    }
		switch(date("w", $l_timestamp)){
    	case 0:
      	$izl = "Nedjelja";
				if($lang == 1){
					$izl = "Sunday";
				}
				if($lang == 2){
					$izl = "Nedelja";
				}
        break;
    	case 1:
      	$izl = "Ponedjeljak";
				if($lang == 1){
					$izl = "Monday";
				}
				if($lang == 2){
					$izl = "Ponedeljak";
				}
        break;
    	case 2:
      	$izl = "Utorak";
				if($lang == 1){
					$izl = "Tuesday";
				}
				if($lang == 2){
					$izl = "Utorak";
				}
        break;
    	case 3:
      	$izl = "Srijeda";
				if($lang == 1){
					$izl = "Wednesday";
				}
				if($lang == 2){
					$izl = "Sreda";
				}
        break;
    	case 4:
      	$izl = "Četvrtak";
				if($lang == 1){
					$izl = "Thursday";
				}
				if($lang == 2){
					$izl = "Četvrtak";
				}
        break;
    	case 5:
      	$izl = "Petak";
				if($lang == 1){
					$izl = "Friday";
				}
				if($lang == 2){
					$izl = "Petak";
				}
        break;
    	case 6:
      	$izl = "Subota";
				if($lang == 1){
					$izl = "Saturday";
				}
				if($lang == 2){
					$izl = "Subota";
				}
        break;
    }
    return $izl;
  }

	function u_datum($date_time = 0, $pocetna_nula = 0){
		if($date_time == 0){
			$date_time = "now";
		}
  	$l_timestamp = strtotime($date_time);
    if($pocetna_nula){
			$izl = date("d", $l_timestamp);
    }else{
			$izl = date("j", $l_timestamp);
    }
    return $izl;
  }

	function u_mjesec($date_time = 0, $brojcano = 0, $lang = 0){
		if($date_time == 0){
			$date_time = "now";
		}
  	$l_timestamp = strtotime($date_time);
  	if($brojcano){
    	$izl = date("m", $l_timestamp);
      return $izl;
    }
		global $pis;
		if($pis == "cir"){
			switch(date("n", $l_timestamp)){
				case 1:
					$izl = "januara";
					break;
				case 2:
					$izl = "februara";
					break;
				case 3:
					$izl = "marta";
					break;
				case 4:
					$izl = "aprila";
					break;
				case 5:
					$izl = "maja";
					break;
				case 6:
					$izl = "juna";
					break;
				case 7:
					$izl = "jula";
					break;
				case 8:
					$izl = "augusta";
					break;
				case 9:
					$izl = "septembra";
					break;
				case 10:
					$izl = "oktobra";
					break;
				case 11:
					$izl = "novembra";
						break;
				case 12:
					$izl = "decembra";
					break;
			}
		}else{
			switch(date("n", $l_timestamp)){
				case 1:
					$izl = "siječnja";
					if($lang){
						$izl = "January";
					}
					break;
				case 2:
					$izl = "veljače";
					if($lang){
						$izl = "February";
					}
					break;
				case 3:
					$izl = "ožujka";
					if($lang){
						$izl = "March";
					}
					break;
				case 4:
					$izl = "travnja";
					if($lang){
						$izl = "April";
					}
					break;
				case 5:
					$izl = "svibnja";
					if($lang){
						$izl = "May";
					}
					break;
				case 6:
					$izl = "lipnja";
					if($lang){
						$izl = "June";
					}
					break;
				case 7:
					$izl = "srpnja";
					if($lang){
						$izl = "July";
					}
					break;
				case 8:
					$izl = "kolovoza";
					if($lang){
						$izl = "August";
					}
					break;
				case 9:
					$izl = "rujna";
					if($lang){
						$izl = "September";
					}
					break;
				case 10:
					$izl = "listopada";
					if($lang){
						$izl = "October";
					}
					break;
				case 11:
					$izl = "studenog";
					if($lang){
						$izl = "November";
					}
					break;
				case 12:
					$izl = "prosinca";
					if($lang){
						$izl = "December";
					}
					break;
			}
		}
    return $izl;
  }

	function u_godina($date_time = 0, $skraceno = 0){
		if($date_time == 0){
			$date_time = "now";
		}
  	$l_timestamp = strtotime($date_time);
		if($skraceno){
			return date('y', $l_timestamp);
		}else{
			return date('Y', $l_timestamp);
		}
  }

	function u_godina_current($date_time = 0, $skraceno = 0){
		return u_godina($date_time);/*REPLACE YEAR INTO OLD YEAR*/
  }

	function u_sat($date_time = "now"){
  	$l_timestamp = strtotime($date_time);
		return date('H', $l_timestamp);
  }

	function u_minuta($date_time = "now"){
  	$l_timestamp = strtotime($date_time);
		return date('i', $l_timestamp);
  }

	function u_sekunda($date_time = "now"){
  	$l_timestamp = strtotime($date_time);
		return date('s', $l_timestamp);
  }

	function get_item($sql, $db_res = "", $test_mode = 0){
		
		if($db_res){
			$rez = mysql_query($sql, $db_res);
		}else{
			$rez = mysql_query($sql);
		}
		
		// ova funkcija uvijek mora vratiti samo nula ili jedan redak
		$l_br_redaka = mysql_num_rows($rez);
		switch($l_br_redaka){
			case 0:
				$result = "";
				break;
			case 1:
				$row = mysql_fetch_array ($rez);
				$result = trim($row[0]);
				break;
			default:
				if($test_mode == 1){
					die("Funkcija <i>get_item()</i> vratila je više od jednog retka iako je dozvoljeno vraćanje samo jednog".
						"<br><br> &nbsp; :::=>> <b>".$sql."</b>");
				}
		}
		
		return $result;
	}
	
	
	function get_data($sql, $force_array = 0, $db_res = ""){
		$la_polje = array();
		
		if($db_res){
			$rez = mysql_query($sql, $db_res);
		}else{
			$rez = mysql_query($sql);
		}
		//echo $sql."\n<br><br>";
		//echo mysql_errno() . ": " . mysql_error() . "\n<br><br>";
		

		$l_br_polja = mysql_num_fields($rez);
		for($i = 0; $i < $l_br_polja; $i++){
			array_push($la_polje, mysql_field_name($rez, $i));
		}
		
		$l_br_redaka = mysql_num_rows($rez);
		if($force_array && $l_br_redaka == 1){
			// uvijek vrati array
			$l_br_redaka = -1;
		}
		switch($l_br_redaka){
			case 0:
				$result = array("");
				break;
			case 1:
				$row = mysql_fetch_array ($rez);
				for($i = 0; $i < $l_br_polja; $i++){
					$result[$la_polje[$i]] = $row[$i];
				}
				break;
			default:
				for($i = 0; $i < $l_br_polja; $i++){
					$result[$la_polje[$i]] = array();
				}
				while ($row = mysql_fetch_array ($rez)){
					for($i = 0; $i < $l_br_polja; $i++){
						array_push($result[$la_polje[$i]], $row[$i]);
					}
				}
		}
		return $result;
	}
	
	
	function sql_exe($sql, $last_id = false, $db_res = ""){
		$db_res == "" ? $result = mysql_query($sql) : $result = mysql_query($sql, $db_res);
		if($last_id && $result){
			$result = mysql_insert_id();
		}
		return $result;
	}
	
	function execInBackground($cmd){
		if(substr(php_uname(), 0, 7) == "Windows"){
			pclose(popen('start /B '.$cmd, 'r'));
		}else{
			exec($cmd.' > /dev/null &');
		}
	}
?>