<?
	header("Content-Type: text/html; charset=utf-8");
	
	//$g_path = '../../my/';
	$la_tmp = explode('/app/', $_SERVER['SCRIPT_FILENAME']);
	
	$l_path_minus = $la_tmp[0].'/app/webroot/iso/';
	$g_path = $la_tmp[0].'/app/webroot/iso/my/';
	
	include $g_path."u_globals.php";
	include $g_path."html/f.php";
	include $g_path."u_spoj_na_bazu.php";
	
	$can_live_alone = 1;
	include $g_path."u_headers.php";
	include $g_path."u_log.php";
	
	include $l_path_minus.'_all_reports.php';
	
	$result = 0;
	
	
	$l_do_it = mailer_check_date();
	
	switch($_GET['report_id']){
		case 1:
		case 8:
			if($l_do_it){
				$la_file = all_dnevni_promet($_GET['p1'], $_GET['p2'], $_GET['p3']);
			}else{
				$la_file = all_dnevni_promet('01-01-2000', '', '');
			}
			break;
			
		case 2:
			if($l_do_it){
				$la_file = all_pregled_prodaje_po_normativu($_GET['p1'], $_GET['p2'], $_GET['p3']);
			}else{
				$la_file = all_pregled_prodaje_po_normativu('01-01-2000', '31-01-2000', '');
			}
			break;
			
		case 3:
			if($l_do_it){
				$la_file = all_pregled_prodaje_po_nacinu_placanja($_GET['p1'], $_GET['p2'], $_GET['p3']);
			}else{
				$la_file = all_pregled_prodaje_po_nacinu_placanja('01-01-2000', '31-01-2000', '');
			}
			break;
			
		case 4:
		case 11:
			if($l_do_it){
				$la_file = all_rekapitulacija_prometa($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_rekapitulacija_prometa('01-01-2000', '31-01-2000');
			}
			break;
			
		case 5:
			if($l_do_it){
				$la_file = all_pregled_prodaje_po_artiklu($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
			}else{
				$la_file = all_pregled_prodaje_po_artiklu('01-01-2000', '31-01-2000', 'DA', 0);
			}
			break;
			
		case 6:
			if($l_do_it){
				$la_file = all_porez_na_potrosnju($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_porez_na_potrosnju('01-01-2000', '31-01-2000');
			}
			break;
			
		case 7:
		case 10:
			if($l_do_it){
				$la_file = all_stanje_skladista($_GET['p1'], $_GET['p2'], $_GET['p3']);
			}else{
				$la_file = all_stanje_skladista('31-01-2000', '23:59', '');
			}
			break;
			
		case 12:
		case 13:
			if($l_do_it){
				$la_file = all_kartica_artikla($_GET['p1'], (isset($_GET['p2']) && $_GET['p2'] == 1) ? 1 : 0);
			}else{
				$la_file = all_kartica_artikla(-1);
			}
			break;
			
		case 9:
			if($l_do_it){
				$la_file = all_prodani_artikli($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4'], $_GET['p5']);
			}else{
				$la_file = all_prodani_artikli('01-01-2000', '01-01-2000', 0, 0, 0);
			}
			break;
			
		case 14:
			if($l_do_it){
				$la_file = all_kolicina_materijala_po_stolovima();
			}else{
				$la_file = all_kolicina_materijala_po_stolovima();
			}
			break;
			
		case 15:
			if($l_do_it){
				$la_file = all_keub($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_keub($_GET['p1'], $_GET['p2']);
			}
			break;
			
		case 16:
			if($l_do_it){
				$la_file = all_rekapitproizvmedjus($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
			}else{
				$la_file = all_rekapitproizvmedjus($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
			}
			break;
			
		case 17:
			if($l_do_it){
				$la_file = all_rekapitreceivings($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
			}else{
				$la_file = all_rekapitreceivings($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
			}
			break;
			
		case 18:
			if($l_do_it){
				$la_file = all_ispis_normativa($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_ispis_normativa('01-01-2000', '31-01-2000');
			}
			break;
			
		case 19:
		case 20:
			if($l_do_it){
				$la_file = all_rekapitulacija_po_danima($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_rekapitulacija_po_danima('01-01-2000', '31-01-2000');
			}
			break;
			
		case 21:
			if($l_do_it){
				$la_file = all_ispis_cjenika($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_ispis_cjenika(null, 1);
			}
			break;
			
		case 22:
			if($l_do_it){
				$la_file = all_rekapitulacija_dobavljaca($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_rekapitulacija_dobavljaca('01-01-2000', '31-01-2000');
			}
			break;
			
		case 23:
			if($l_do_it){
				$la_file = all_pregled_nabave_materijalno($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_pregled_nabave_materijalno('01-01-2000', '31-01-2000');
			}
			break;
			
		case 24:
		case 25:
			if($l_do_it){
				$la_file = all_stanje_skladista_iz_artikala($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_stanje_skladista_iz_artikala('31-01-2000', '23:59');
			}
			break;
		case 26:
			if($l_do_it){
				$la_file = all_pregled_napojnice($_GET['p1'], $_GET['p2']);
			}else{
				$la_file = all_pregled_napojnice('01-01-2000', '31-01-2000');
			}
			break;
		
		case 100:
			// Generiranje PDF ponude
			if(isset($_GET['p1']) && $_GET['p1'] > 0){
				$la_file = all_print_offer($_GET['p1']);
			}
			break;
			
	}
	
	if(is_file($la_file['path'].$la_file['name'])){
		$result = 1;
	}
	
	$la_data = array();
	$la_data['result'] = $result;
	
	$la_json = json_encode($la_data);
	print $la_json;
	exit;
?>
