<?php

	session_start();
	require_once("mysqlconnect.php");
	require_once('../conf/definitions.php');
	require_once('../conf/objs.php');
	require_once('../conf/functions.php');
	
	
	$u=$_GET['u'];
	
//	if(!$_SESSION["mobile_admin_logged_in"] || $u<>$uhash) header('location: index.php');
	
	$action=$_GET["action"];
	
	if($action=='add_file')
	{
		$nazov=$_POST["nazov"];
		$nazov=eregi_replace(' ', '', $nazov);	
	}
	
	$typy = $theme_types;
		
	if($action=='add_file' && $_FILES['the_file']['name']<>'' && $nazov<>'' && $_POST['type']<>'')
	{
		$file=$_FILES['the_file']['name'];
		$file_tmp=$_FILES['the_file']['tmp_name'];
		
		$image=$_FILES['the_image']['name'];
		$img_tmp=$_FILES['the_image']['tmp_name'];
		
		$check_size=false;
		if(file_exists($file_tmp)) $size=round(filesize($file_tmp)/1024,2);
		if($size<=1000 && $size>0) $check_size=true;
		$err='';
		if(!$check_size) $err.='Neplatná veľkosť témy<br>';
		if($check_size)
		{
			$uploaddir = "/home/clients/peterpech.com/peterpech.com/4mobile/themes/";
			$uploadfile = $uploaddir . $_FILES['the_file']['name']; 
			move_uploaded_file($file_tmp, $uploadfile);
			
//			if($_FILES['the_file2']['name']<>'')
//			{
//				$uploadfile = $uploaddir . $_FILES['the_file2']['name']; 
//				move_uploaded_file($file_tmp2, $uploadfile);
//			}

			if($image<>'')
			{
			$uploaddir = "/home/clients/peterpech.com/peterpech.com/4mobile/images/themes/";
			$uploadfile = $uploaddir . $_FILES['the_image']['name']; 
			move_uploaded_file($img_tmp, $uploadfile);
			}
			
			$nazov=$_POST["nazov"];
			
			$image=$_FILES['the_image']['name'];
			
			$poznamka=htmlspecialchars($_POST["poznamka"]);
			
			if($image=='') $image='na.jpg';
			
			$typ=$_POST['type'];
			$cat=$_POST['category'];
			
			$query="INSERT INTO `mobile_themes` ( `ID` , `nazov` , `file` , `image` , `poznamka` , `typ`, `cat`) VALUES ('', '".$nazov."', '".$file."', '".$image."', '".$poznamka."', '".$typ."', '".$cat."')";
			mysql_query($query, $link); // or die('Chyba pri pridavani temy');
			$_SESSION['dump'] =  mysql_error()."<br />";
			$_SESSION['dump'] .= $query;
			$err='Téma vyhovuje kritériám a bola pridaná';
			header("location: theme_add.php?u=$u&action=form&err=$err");
		}
		else 
		{
			if(!file_exists($file_tmp) && $action=='add_file') $err='Zadaný súbor neexistuje';
		}
	}	
	else 
	{
		if($action=='add_file')
		{
			$err='Nezadal si názov témy alebo si nevybral typ';
	 		header("location: theme_add.php?u=$u&action=form&err=$err");
		}
	}

	?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//SK" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>4mobile - všetko pre Váš mobil</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="book.css">
<script language="JavaScript" src="book.js">
</script>
<style type="text/css">
<!--
.form_name {  font-family: Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; color: #666666; text-decoration: none; text-align: left;}
.form_tlac {  font-family: Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; color: #666666; background-color: #FFFFFF; border: 1px solid #CCCCCC}
.form_text { font-family: Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: normal; color: #666666; text-decoration: none ; text-align: justify; background-color: #FFFFFF; border: #CCCCCC; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
.form_text2 { font-family: Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; color: #666666; text-decoration: none ; text-align: justify }
.msg { font-family: Verdana; font-size: 7pt; color:#999999; }
.field1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #CC0000; background-color: #CCCCCC; border: #000000; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}

-->
</style>
</head>

<body bgcolor="#000000">
<?php 
	include "menu.php"; 
?>
<div align='center'>
<? 
	dump($_SESSION['dump']);
	$action=$_GET["action"];
	if($action=='form')
	{
		echo"<div>
		<form ENCTYPE=\"multipart/form-data\" name=\"q\" action=\"theme_add.php?u=$u&action=add_file\" method=POST>
			<table width=400 border=0 align=center cellspacing=1>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;*Súbor1:</td>
					<td class=form_name style=\" padding-top:3px; padding-bottom:3px;\"><input name=the_file type=file size=29 class=form_text></td>
				</tr>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;*Typ:</td>
					<td class=form_name><select name='type' class='form_text'>
					<option value=''>=> Vyber typ témy <=</option>\n";
					for($i=1; $i<=sizeof($typy); $i++)
					{
						echo "<option value='$i'>".$typy[$i]['type']."</option>";
					}
				echo"</select></td>
				</tr>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;*Kategória:</td>
					<td class=form_name><select name='category' class='form_text'>
					<option value=''>=> Vyber kategóriu <=</option>\n";
					foreach ($theme_categories as $id => $cat)
					{
						echo "<option value='$id'>".$cat."</option>";
					}
				echo"</select></td>
				</tr>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;*Názov:</td>
					<td class=form_name><input type=text name=nazov size=40 class=field1 maxlength=50></td>
				</tr>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;Poznámka:</td>
					<td class=form_name><textarea rows=6 cols=30 name=poznamka style=\"scrolling:auto; scrollbar-face-color: #CCCCCC; scrollbar-shadow-color:#CCCCCC;
	  					scrollbar-highlight-color:#CCCCCC ; 
	  					scrollbar-3dlight-color: #CCCCCC;
	  					scrollbar-darkshadow-color: #CCCCCC; 
	  					scrollbar-track-color: #cccccc;
	  					scrollbar-arrow-color: #CC0000;\" class=field1></textarea></td>
				</tr>
				<tr bgcolor=#222222>
					<td class=form_name>&nbsp;Obrázok:</td>
					<td class=form_name style=\" padding-top:3px; padding-bottom:3px;\"><input name=the_image type=file size=29 class=form_text></td>
				</tr>	
				<tr bgcolor=#222222>
					<td colspan=2 align=center class=msg> Max. veľkosť témy je 300kB. Nie je tam kontrola na typ hry ani na obrázok. Ak chces pridať typ témy ktorý nie je v zozname tak mi napíš a najskôr ho pridám do toho zoznamu, nech v tom neni zmatok keby sa tam dal dočasne iný typ.</td>
				</tr>	
				<tr bgcolor=#222222>
					<td colspan=2 align=center><input type=submit value=OK class=form_tlac style=\"cursor:hand\";>  
          				<input type=reset value=Vymazať class=form_tlac style=\"cursor:hand\";></td>
					
				</tr>
			</table>
		</form></div>";
	}
	echo"<div align=center class=textb>$err</div>";		
			
	
	
	?>

</div>
</body>
</html>
