<?php
$pass3 = $_POST["pass3"];
$action = $_POST["action"];
$r_name2 = $_POST["r_name2"];
$field = $_POST["field2"];
$newtext = $_POST["newtext"];
$image_name = $_POST["image_name"];
$MAX_FILE_SIZE = $_POST["MAX_FILE_SIZE"];
//$imgfile = $_FILE['imgfile'];
$t24 = $_FILES['imgfile']['tmp_name'];
?>

<html>

<head>
<title>Image Manager</title>

<style>
.field 
{
	font-family: Tahoma,Verdana;font-size:10pt;border: 2px double #EEEEEE;
}
.field2 
{
	font-family: Tahoma,Verdana;font-size:10pt;border: 2px outset #000000; font-weight:bold;color:white;background-color:#880000;
}
body
{
	SCROLLBAR-FACE-COLOR: #FFFFFF; 
	SCROLLBAR-HIGHLIGHT-COLOR: #CCCCCC; 
	SCROLLBAR-SHADOW-COLOR: #CCCCCC; 
	SCROLLBAR-3DLIGHT-COLOR: #EFEFEF; 
	SCROLLBAR-ARROW-COLOR: #B9BCA4; 
	SCROLLBAR-TRACK-COLOR: #F5F5F3; 
	SCROLLBAR-DARKSHADOW-COLOR: #F5F5F3;
	BACKGROUND-COLOR: #FFFFFF;
}
a:link.f1 {color:black;TEXT-DECORATION: none;font-family:Tahoma;font-size:8pt;}
a:hover.f1 {color:blue;TEXT-DECORATION: underline;font-family:Tahoma;font-size:8pt;}
a:active.f1 {color:red;TEXT-DECORATION: none;font-family:Tahoma;font-size:8pt;}
a:visited.f1 {color:#777777;TEXT-DECORATION: none;font-family:Tahoma;font-size:8pt;}
</style>

</head>

<body>

<script>
function deleter(image_name)
{
	if(document.form1.pass3.value=="")
	{
		alert("Enter password");
	}
	else
	{
		var agree=confirm("Delete this file ?");
		if(agree)
		{
			document.form1.image_name.value = image_name;
			document.form1.action.value = "image_delete";
			document.form1.submit();
		}
		else
		{
		
		}
	}
// End -->
}

//
function deleteNews()
{
	if(document.form1.pass3.value=="")
	{
		alert("Enter password");
	}
	else
	{
		document.form1.action.value = "news_delete";
		document.form1.submit();
	}
}

function uploadImage()
{
	var message = "";

	if(document.form1.pass3.value=="")
	{
		message = message + "Enter password \n";
	}
	if(document.form1.imgfile.value=="")
	{
		message = message + "Select image file\n";
	}
	if(message)
	{
		alert(" - Message - \n\n" + message);
	}
	else
	{
		document.form1.action.value = "upload_image";
		document.form1.submit();
	}
}


</script>

<form name="form1" action="<?=$SCRIPT_NAME?>" method="post" enctype="multipart/form-data">
<INPUT type=button value="Text Manager" onClick="document.location.href='../admin.php'" class="field2" style="cursor:hand;" title="Text Manager">
<INPUT type=button value="Upload Photo" onClick="document.location.href='index.php'" class="field2" style="cursor:hand;" title="Upload Photo">
<INPUT type=button value="View Photo" onClick="document.location.href='view.php'" class="field2" style="cursor:hand;" title="View Photo">
<INPUT type=password value="<?=@$pass3?>" name="pass3" class="field" size="3"> <font face="Tahoma,Verdana,Arial" size="1"><b>- Pass 3</b></font>
<INPUT type=hidden value="" name="action" class="field">
<INPUT type=hidden value="" name="image_name" class="field">
<!--<INPUT type=button value="Delete News" onClick="deleteNews();" class="field2" style="cursor:hand;" title="Delete News File">-->
</form>

<?

include("../setting.php");
$msg="";

if ($action == "image_delete")
{
	if($password3 == $pass3)
	{
		if(file_exists($image_name))
		{
			unlink($image_name);
			$msg = $msg." Image [".$image_name."] is deleted <br> ";
		}
		else
		{
			$msg = $msg." Dont find [".$image_name."] image <br> ";
		}

	}
	else
	{

		$msg = $msg." Incorrect password <br> ";
	}
}

//// view images

$imgurl = "../icon/";
$imgDir=".";
$d=opendir($imgDir);
$cis = 0;
$fil = 0;
$fol = 0;
while(($e = readdir($d))!==false)
{
	$path = "$imgDir/$e";
	$tim = filemtime($path);
	$siz = filesize($path);
	$sizk = $siz / 1;
	$sizk = $sizk / 1024;
	settype($sizk,"integer");
	$ltim = date("d.m.y H:i",$tim); 

	if(!ereg("([[:alnum:]]+)\\.([[:alnum:]]+)$",$e,$poster))
	{

	}
	else
	{
		if($e!="index.php" && $e!="Thumbs.db" && $e!="view.php")
		{

			echo('<font  size="1" face="Tahoma" style="background-color:white;color:green;font-weight:normal;"><img src="../icon/delete.gif" border="0" hspace="3" alt="Delete Image - '.$e.'" style="cursor:hand;" onclick="deleter(\''.$e.'\');">&nbsp;<a href='.str_replace(' ','%20',$e).' class="f1" target="_blank"><img src="'.$imgurl.$poster[2].'.gif" border="0" hspace="3" alt="Preview Image"></a></font>&nbsp;<font face="Tahoma,Vardana" size="1">'.$e.'</font><font  face="Tahoma" size="1" color="green"> - '.$sizk.' Kb.</font><font face="Tahoma" size="1" color="#0A4BA5"> -  '.$ltim.'</font><br><img src="'.str_replace(' ','%20',$e).'" border="1"><br><br>');
			$fil++;
		}
	}
	$cis++;
}
$cis=$cis-3;

echo ('<br><font face="Tahoma" size="1" color="#0A4BA5"><b></font><font face="Tahoma" size="1" color="#880000">'.$fil.' - images</b></font>');
?>
</body>
</html>
