<?php

	$uhash='098f6bcd4621d373cade4e832627b4f6';
//	$uhash='5f9c54546db75cc28e7c873ff542eb17';
	
	function fnWriteLoginForm()
	{
		echo "<div align=center>\n
				<form name=login_form action=index.php?action=login method=POST>\n
					<input type=password name=login size=20 class=login_field maxlength=20>&nbsp;
					<input type=submit name=Submit value=OK class=login_button>
				<form>";
	}
	
//--------------------------------------------------------------------------------------------------------------------

	function fnGetRowsNum($table)
	{
		global $link;
		
		$query="SELECT count(ID) as pocet FROM $table";
		$result=mysql_query($query, $link);
		if($result)
		{
			$row=mysql_fetch_array($result);
			$count=$row["pocet"];
			mysql_free_result($result);
			return $count;
		}
		else 
		{
			return false;
		}
	}
	
//--------------------------------------------------------------------------------------------------------------------

	function fnGetMaxID($table)
	{
		global $link;
		
		$query="SELECT ID FROM $table ORDER BY ID DESC";
		$result=mysql_query($query);
		if($result)
		{
			$row=mysql_fetch_array($result);
			$maxid=$row["ID"];
			mysql_free_result($result);
			return $maxid;
		}
		else 
		{
			return false;
		}
	}
	
//--------------------------------------------------------------------------------------------------------------------
	
	function fnGetLimit($i, $nastranu)
	{		
		return ($i-1)*$nastranu;	
	}

//--------------------------------------------------------------------------------------------------------------------		

	function fnGetPages($num, $nastranu)
	{
		$stranok=floor($num/$nastranu);
		if($num%$nastranu!=0) $stranok+=1;
		return $stranok;
	}


//--------------------------------------------------------------------------------------------------------------------

	function fnIDexists($id, $table)
	{
		global $link;
		$query="SELECT ID FROM $table WHERE ID=$id";
		$result=mysql_query($query, $link);
		if($result)
		{
			$num=mysql_num_rows($result);
			if($num==1) return true;
			else return false;
		}
		else return false;
	}


//--------------------------------------------------------------------------------------------------------------------

	function fnGetPage($table, $id, $nastranu)
	{
		global $link;

		$i=0;
		$query="SELECT ID FROM $table ORDER BY ID ASC";
		$result=mysql_query($query);
		while($row=mysql_fetch_array($result))
		{
			$i++;
			if($id==$row['ID'])
			{
				$poradie=$i;
				break;
			}
		}

		$page=floor($poradie/$nastranu);
		if($poradie%$nastranu<>0) $page+=1;
		return $page;
	}


//--------------------------------------------------------------------------------------------------------------------

	function fnWriteTableImages($result)
	{
		global $link;
		global $u;
		
		echo "<form name=images action=images_action.php?u=$u&action=delete_checked method=POST>";
		echo "<div align=center><img name=image src='../images/games/na.jpg' align=top><br><br></div>";
		echo "<table width=80% cellpadding=1 cellspacing=1 align=center border=0>\n";
		echo "<tr>\n";
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=3><input type=submit name=Submit value=\"Zmazať označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=3><form name=nap_id action=images_action.php?u=$u&action=delete method=POST>Zmazať pozadie s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaž class=button></form></td>\n";
		echo "<td class=image_table colspan=3><form name=edit_id action=image_edit.php?u=$u&action=edit method=POST>Editovať pozadie s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=4><form name=go_id action=images_action.php?u=$u&action=go method=POST>Ísť na pozadie s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</tr>";
		echo "<td class=image_table_header width=10>&nbsp;</td>\n";
		echo "<td class=image_table_header>ID</td>\n";
		echo "<td class=image_table_header>File</td>\n";
		echo "<td class=image_table_header>Res</td>\n";
		echo "<td class=image_table_header>Cat</td>\n";
		echo "<td class=image_table_header>Hlasov</td>\n";
		echo "<td class=image_table_header>Priemer</td>\n";
		echo "<td class=image_table_header>Download</td>\n";
		echo "<td class=image_table_header>Pridal</td>\n";
		echo "<td class=image_table_header>Šírka</td>\n";
		echo "<td class=image_table_header>Výška</td>\n";
		echo "<td class=image_table_header>Edit</td>\n";
		echo "<td class=image_table_header>Delete</td>\n";
		echo "</tr>";
		
		$j=0;
		
		while($row=mysql_fetch_array($result))
		{
			$j+=1;
			echo "<tr class='image_row";
			if($row['ID']==$_GET['img_id']) echo "_red";
			echo "' onMouseOver='moveon(this);' onMouseOut='moveoff(this);'>";
			if($row["ID"]>4922){$path='pozadia2/';}
			if($row["ID"]<4922){$path='pozadia/';}
			if($row['ID']>0) list($width, $height) = getimagesize('../'.$path.$row["file"]);
			echo "<td class=image_table width=10><input type=checkbox name=image$j value=".$row['ID']."></td>\n";
			echo "<td class=image_table><a onClick=\"image.src='../".$path.$row['file']."'\" class=image_table_link style=\"cursor: hand;\">".$row["ID"]."</a></td>\n";
			echo "<td class=image_table><a onClick=\"image.src='../".$path.$row['file']."'\" class=image_table_link style=\"cursor: hand;\">".$row["file"]."</a></td>\n";
			echo "<td class=image_table>".$row["res"]."</td>\n";
			echo "<td class=image_table>".$row["cat"]."</td>\n";
			echo "<td class=image_table>".$row["hlasov"]."</td>\n";
			echo "<td class=image_table>".$row["priemer"]."</td>\n";
			echo "<td class=image_table>".$row["dload"]."</td>\n";
			echo "<td class=image_table>".$row["pridal_user"]."</td>\n";
			echo "<td class=image_table>".$width."</td>\n";
			echo "<td class=image_table>".$height."</td>\n";
			echo "<td class=image_table><a href=image_edit.php?u=$u&action=edit&id=".$row['ID']." class=image_table_link>edit</a></td>\n";
			echo "<td class=image_table><a href=images_action.php?u=$u&action=delete&id=".$row['ID']." class=image_table_link>delete</a></td>\n";
			echo "</tr>\n";
		}	
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=3><input type=submit name=Submit value=\"Zmazať označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=3><form name=nap_id action=images_action.php?u=$u&action=delete method=POST>Zmazať pozadie s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaž class=button></form></td>\n";
		echo "<td class=image_table colspan=3><form name=edit_id action=image_edit.php?u=$u&action=edit method=POST>Editovať pozadie s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=4><form name=go_id action=images_action.php?u=$u&action=go method=POST>Ísť na pozadie s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</tr>";
		echo "</table>";
	} 
	
//--------------------------------------------------------------------------------------------------------------------

	function fnWriteNav($params)
	{
		global $u;
		$page=$params['page'];
		$i=$params['i'];
		$stranok=$params['stranok'];
		
		echo "<table width=80% border=0 cellspacing=0 cellpadding=0 class=text align=center style=\"background:#111111\">\n";
  		echo "<tr><td width=20 align=left valign=top style=\"padding-left:3px; padding-bottom:3px\">\n"; 
  		echo "<a href=$page.php?u=$u&i=1 class=image_navi title=Začiatok>|<<</a></td>\n";
  		echo "<td width=60 align=right valign=top><a href=$page.php?u=$u&i=";
		if($i>10) $x=$i-10; else $x=1;
		echo "$x class=image_navi title=\"O 10 dozadu\"><<</a></td>";
		echo "<td width=60 align=right valign=top><a href=$page.php?u=$u&i=";
		if($i>1) $x=$i-1; else $x=1;
		echo "$x class=image_navi title=\"O 1 dozadu\"><</a></td>";
    	echo "<td align=center class=image_navi>$i/$stranok</td>";
    	echo "<td width=60 align=left valign=top><a href=$page.php?u=$u&i=";
		if($i<$stranok) $x=$i+1; else $x=$stranok;
		echo "$x class=image_navi title=\"O 1 dopredu\">></a></td>";
  		echo "<td width=60 align=left valign=top><a href=$page.php?u=$u&i=";
		if($i<=$stranok-10) $x=$i+10; else $x=$stranok;
		echo "$x class=image_navi title=\"O 10 dopredu\">>></a></td>";
		echo "<td width=20 align=right valign=top style=\"padding-left:3px; padding-bottom:3px\">\n"; 
  		echo "<a href=$page.php?u=$u&i=$stranok class=image_navi title=Koniec>>>|</a></td></tr></table><br><br>\n";
	}

//--------------------------------------------------------------------------------------------------------------------


	function fnWriteTableMelodies($result)
	{
		global $link;
		global $u;
			
		echo "<form name=melody action=melody_action.php?u=$u&action=delete_checked method=POST style='padding-bottom:0px;'>";
		echo "<table width=80% cellpadding=1 cellspacing=1 align=center border=0>\n";
		echo "<tr>\n";
		echo "<td class=image_table_header width=10>&nbsp;</td>\n";
		echo "<td class=image_table_header>ID</td>\n";
		echo "<td class=image_table_header>Interpret</td>\n";
		echo "<td class=image_table_header>Názov</td>\n";
		echo "<td class=image_table_header>File</td>\n";
		echo "<td class=image_table_header>Hlasy</td>\n";
		echo "<td class=image_table_header>Poznámka</td>\n";
		echo "<td class=image_table_header>Edit</td>\n";
		echo "<td class=image_table_header>Delete</td>\n";
		echo "<td class=image_table_header>NEW</td>\n";
		echo "</tr>";
		
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=3><input type=submit name=Submit value=\"Zmazať označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=1><form name=nap_id action=melody_action.php?u=$u&action=delete method=POST>Zmazať melódiu s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaž class=button></form></td>\n";
		echo "<td class=image_table colspan=2><form name=edit_id action=melody_edit.php?u=$u&action=edit method=POST>Editovať melódiu s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=4><form name=go_id action=melody_action.php?u=$u&action=go method=POST>Ísť na melódiu s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</tr>";
		
		$j=0;
		
		$na = array
		(
			0 => 'nie',
			1 => 'Áno'
		);
		
		while($row=mysql_fetch_array($result))
		{
			$j+=1;
			echo "<tr name='row$j' class='image_row";
			if($row['ID']==$_GET['mel_id']) echo "_red";
			echo "' onMouseOver='moveon(this);' onMouseOut='moveoff(this);'>";
			echo "<td class=image_table width=10><input type=checkbox name=melody$j value=".$row['ID']."></td>\n";
			echo "<td class=image_table width=20>".$row["ID"]."</a></td>\n";
			echo "<td class=image_table>".$row["interpret"]."</a></td>\n";
			echo "<td class=image_table>".$row["nazov"]."</td>\n";
			echo "<td class=image_table>".$row["file"]."</td>\n";
			echo "<td class=image_table>".$row["hlasy"]."</td>\n";
			echo "<td class=image_table>".$row["poznamka"]."</td>\n";
			echo "<td class=image_table><a href=melody_edit.php?u=$u&action=edit&id=".$row['ID']." class=image_table_link>edit</a></td>\n";
			echo "<td class=image_table width=30><a href=melody_action.php?u=$u&action=delete&id=".$row['ID']." class=image_table_link>delete</a></td>\n";
			echo "<td class=image_table width=20>"; if($row["new"]==1) echo'<span class=red>'.$na[$row["new"]].'</span>'; else echo $na[$row["new"]];  echo"</td>\n";
			echo "</tr>\n";
		}	
		
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=3><input type=submit name=Submit value=\"Zmazať označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=1><form name=nap_id action=melody_action.php?u=$u&action=delete method=POST>Zmazaďż˝ melďż˝diu s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaďż˝ class=button></form></td>\n";
		echo "<td class=image_table colspan=2><form name=edit_id action=melody_edit.php?u=$u&action=edit method=POST>Editovaďż˝ melďż˝diu s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=4><form name=go_id action=melody_action.php?u=$u&action=go method=POST>ďż˝sďż˝ na melďż˝diu s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</tr></table>";
	} 
	
//--------------------------------------------------------------------------------------------------------------------

	function fnWriteTableGames($result)
	{
		global $link;
		global $u;
		global $typy;
		
		echo "<form name=game action=game_action.php?u=$u&action=delete_checked method=POST style='padding-bottom:0px;'>";
		echo "<table width=80% cellpadding=1 cellspacing=1 align=center border=0>\n";
		echo "<tr>\n";
		echo "<td class=image_table_header width=10>&nbsp;</td>\n";
		echo "<td class=image_table_header>ID</td>\n";
		echo "<td class=image_table_header>Nďż˝zov</td>\n";
		echo "<td class=image_table_header width='180'>File</td>\n";
		echo "<td class=image_table_header>Obrďż˝zok</td>\n";
		echo "<td class=image_table_header>Poznďż˝mka</td>\n";
		echo "<td class=image_table_header>Typ</td>\n";
		echo "<td class=image_table_header>Edit</td>\n";
		echo "<td class=image_table_header>Delete</td>\n";
		echo "</tr>";
		
		$j=0;
		
		while($row=mysql_fetch_array($result))
		{
			$j+=1;
			echo "<tr name='row$j' class='image_row";
			if($row['ID']==$_GET['game_id']) echo "_red";
			echo "' onMouseOver='moveon(this);' onMouseOut='moveoff(this);'>";
			echo "<td class=image_table width=10><input type=checkbox name=game$j value=".$row['ID']."></td>\n";
			echo "<td class=image_table width=20>".$row["ID"]."</a></td>\n";
			echo "<td class=image_table>".$row["nazov"]."</td>\n";
			echo "<td class=image_table>".$row["file"]."</td>\n";
			echo "<td class=image_table>".$row["image"]."</td>\n";
			echo "<td class=image_table>".$row["poznamka"]."</td>\n";
			echo "<td class=image_table>".$typy[$row["typ"]]['type']."</td>\n";
			echo "<td class=image_table><a href=game_edit.php?u=$u&action=edit&id=".$row['ID']." class=image_table_link>edit</a></td>\n";
			echo "<td class=image_table width=30><a href=game_action.php?u=$u&action=delete&id=".$row['ID']." class=image_table_link>delete</a></td>\n";
			echo "</tr>\n";
		}	
		
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=3><input type=submit name=Submit value=\"Zmazaďż˝ označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=1><form name=nap_id action=game_action.php?u=$u&action=delete method=POST>Zmazaďż˝ hru s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaďż˝ class=button></form></td>\n";
		echo "<td class=image_table colspan=2><form name=edit_id action=game_edit.php?u=$u&action=edit method=POST>Editovaďż˝ hru s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=3><form name=go_id action=game_action.php?u=$u&action=go method=POST>ďż˝sďż˝ na hru s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</table>";
		var_dump($typy);
	} 
	
//--------------------------------------------------------------------------------------------------------------------

	function fnWriteTableVideo($result)
	{
		global $link;
		global $u;
		
		echo "<form name=video action=video_action.php?u=$u&action=delete_checked method=POST style='padding-bottom:0px;'>";
		echo "<table width=80% cellpadding=1 cellspacing=1 align=center border=0>\n";
		echo "<tr>\n";
		echo "<td class=image_table_header width=10>&nbsp;</td>\n";
		echo "<td class=image_table_header>ID</td>\n";
		echo "<td class=image_table_header>Nďż˝zov</td>\n";
		echo "<td class=image_table_header width='180'>File</td>\n";
		echo "<td class=image_table_header>Poznďż˝mka</td>\n";
		echo "<td class=image_table_header>Edit</td>\n";
		echo "<td class=image_table_header>Delete</td>\n";
		echo "</tr>";
		
		$j=0;
		
		while($row=mysql_fetch_array($result))
		{
			$j+=1;
			echo "<tr name='row$j' class='image_row";
			if($row['ID']==$_GET['video_id']) echo "_red";
			echo "' onMouseOver='moveon(this);' onMouseOut='moveoff(this);'>";
			echo "<td class=image_table width=10><input type=checkbox name=video$j value=".$row['ID']."></td>\n";
			echo "<td class=image_table width=20>".$row["ID"]."</a></td>\n";
			echo "<td class=image_table>".$row["nazov"]."</td>\n";
			echo "<td class=image_table>".$row["file"]."</td>\n";
			echo "<td class=image_table>".$row["poznamka"]."</td>\n";
			echo "<td class=image_table><a href=video_edit.php?u=$u&action=edit&id=".$row['ID']." class=image_table_link>edit</a></td>\n";
			echo "<td class=image_table width=30><a href=video_action.php?u=$u&action=delete&id=".$row['ID']." class=image_table_link>delete</a></td>\n";
			echo "</tr>\n";
		}	
		
		echo"<tr class='image_row'>\n";
		echo "<td class=image_table colspan=2><input type=submit name=Submit value=\"Zmazaďż˝ označené\" class=button></td></form>\n";
		echo "<td class=image_table colspan=1><form name=nap_id action=video_action.php?u=$u&action=delete method=POST>Zmazaďż˝ video s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Zmaďż˝ class=button></form></td>\n";
		echo "<td class=image_table colspan=1><form name=edit_id action=video_edit.php?u=$u&action=edit method=POST>Editovaďż˝ video s ID:<input type=text name=napisane_id class=field size=5>&nbsp;<input type=submit name=Submit value=Edit class=button></form></td>\n";
		echo "<td class=image_table colspan=3><form name=go_id action=video_action.php?u=$u&action=go method=POST>ďż˝sďż˝ na video s ID:<input type=text name=go_id class=field size=5>&nbsp;<input type=submit name=Submit value=Go class=button></form></td>\n";
		echo "</table>";
		var_dump($typy);
	} 
	
//--------------------------------------------------------------------------------------------------------------------

	function Dump($var)
	{
		global $admins;
		
			echo "<div class='dump'><pre>";
			print_r($var, false);
			echo "</pre></div>";
	}
?>