<?
	header("Content-Type: text/html; charset=utf-8");
	
	$g_path = '../my/';
	
	include $g_path."u_globals.php";
	include $g_path."html/f.php";
	include $g_path."u_spoj_na_bazu.php";
	
	include $g_path."u_headers.php";
	
	if(!$_SESSION['__id']){
		//exit;
	}
	
	if($_POST){
		if(strstr($_SERVER['HTTP_REFERER'], $g_path_sl.'res/dist_list_copy.php')){
			
			$x = get_data('select * from distribucijska_lista where guid = "'.$_GET['id'].'" ', 0);
			$l_id = get_item('select guid from zaposlenik where rbr_users_outer_db = '.$_SESSION['__id']);
			
			$l_new_guid = get_item('SELECT UUID() as uuid');
			$l_sql = 'insert into distribucijska_lista values("'.$l_new_guid.'", "'.addslashes($x['Naziv'].' (Copy)').'", now(), "'.$l_id.'")';
			sql_exe($l_sql, true);
			
			$x = get_data('select primatelj_guid from distribucijska_lista_primatelji where distribucijska_lista_guid = "'.$_GET['id'].'" ', 1);
			for($i = 0; $i < sizeof($x['primatelj_guid']); $i++){
				$l_sql = 'insert into distribucijska_lista_primatelji values("'.addslashes(get_item('SELECT UUID() as uuid')).'", "'.$l_new_guid.'", "'.$x['primatelj_guid'][$i].'")';
				sql_exe($l_sql);
			}
			
			
			/*
			$x = get_data('select DocumentName, DocumentVersion from document where guid = "'.$_POST['docGuid'].'" ', 0);
			$l_list_name = get_item('select Naziv from distribucijska_lista where guid = "'.$_POST['distListSelect'].'" ');
			
			$la_tmp = explode('-', $_POST['distListProcitatiDo']);
			$l_datum = $la_tmp[2].'-'.$la_tmp[1].'-'.$la_tmp[0];
			
			$y = get_data('select guid from distribucijska_lista_primatelji where distribucijska_lista_guid = "'.$_POST['distListSelect'].'" ', 1);
			for($i = 0; $i < sizeof($y['guid']); $i++){
				$uuid = get_item('SELECT UUID() as uuid');
				$l_sql = 'insert into distribucijska_lista_log values("'.$uuid.'", "'.$y['guid'][$i].'", now(), '.
					'"'.$_POST['docGuid'].'", "'.$x['DocumentName'].'", "'.$x['DocumentVersion'].'", 0, NULL, "'.$l_list_name.'", "'.$l_datum.'")';
				sql_exe($l_sql);
			}
			*/
			
			header('location:dist_list_copy.php?edit=done&id='.$_GET['id'].'&rbr='.$_GET['rbr']);
			exit;
		}
	}
?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
	<html>
	<head>
		<link rel='stylesheet' type='text/css' href="css/dist-list-do-1.css">
		<script type="text/javascript" src="<?=$g_path_sl?>res/js/f-dist-list-do-1.js"></script>
		<script type="text/javascript" src="<?=$g_path_sl_res?>js/datetimepicker_css.js"></script>
	</head>
	<body>
<?
		$result = '';
		
		if($_GET['edit'] == 'done'){
			$result .= 'Distribucijska lista uspješno je kopirana<br><br>';
			
			$result .= '<a href="#" onclick="parent.location.reload(); close_layer(\'copyDistList_'.$_GET['rbr'].'\'); return false;" class="distListDoButtonOK">Ok</a>';
		}else{
			
			
			$x = get_data('select Naziv from distribucijska_lista where guid = "'.$_GET['id'].'" ', 0);
			
			$result .= '<b>Distribucijska lista:</b> '.$x['Naziv'].'<br><br>';
			
			
			
			$result .= '<form name="formaDistListDo" class="formaDistListDo" method="post" action="dist_list_copy.php?id='.$_GET['id'].'&rbr='.$_GET['rbr'].'">';
			
			$result .= '<input type="hidden" name="test_field" value="1">';
							
			
			$result .= '<a href="#" onclick="close_layer(\'copyDistList_'.$_GET['rbr'].'\'); return false;" class="distListDoButtonCancel">Odustani</a>';
			$result .= '<a href="#" onclick="document.formaDistListDo.submit();" class="distListDoButtonOK">Kopiraj listu</a>';
		}
		
		
		
		$result .= '</form>';
		
		print $result;
?>
	</body>
	</html>
