<?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="hidden" name="MAX_FILE_SIZE" value="1024000"> 
<input type="file" name="imgfile" size="19" value="" style="cursor: hand;" class="field">
<input type="button" value="Upload Image" class="field2" style="cursor:hand;" title="upload Image"  onClick="uploadImage();">
<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>

<?php

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> ";
	}
}

// delete news
/*
if ($REQUEST_METHOD == "POST" && $action == "news_delete")
{
	if($password3 == $pass3)
	{
		$filedata = "../data.html";
		if(file_exists($filedata))
		{
			$opnefile = fopen($filedata,'a',1);
			ftruncate($opnefile, '0');
			fclose($opnefile);
			$msg = $msg." News data is empty <br> ";
		}
		else
		{
			$msg = $msg." Dont find data file <br> ";
		}

	}
	else
	{

		$msg = $msg." Incorrect password <br> ";
	}
}
*/
$today = date("H:i:s");                           
echo('<br><font style="color: #BB0000; font-size: 8pt; font-weight: bold; font-family: Tahoma;">');
echo($today."<br>");
echo($msg);
echo('</font><br>');

// copy file
//echo($action);

if($action == "upload_image")  
{ 	
	//echo("1");
	$uploaddir = "."; 
	$msg2 = "";
	/*
    $pext = getFileExtension($imgfile_name); 
    $pext = strtolower($pext);
	$imgsize = GetImageSize($imgfile); 

    if(($pext != "jpg")  && ($pext != "jpeg") && ($pext != "gif")) 
    { 
		$msg2 = $msg2." Image extension unknown.<br>Please upload only a jpeg image with the extension: .jpg , .jpeg or gif only.<br>The file you uploaded had the following extension: .".$pext."<br> ";
    } 
	if(($pext=="jpg") || ($pext=="jpeg") || ($pext=="gif"))
	{
		if(($imgsize[0] > $imgwidthset) || ($imgsize[1] > $imgheightset))  
		{
	    	$msg2 = $msg2." No correct image resize: ".$imgsize[3]." pixel.<br>Please upload only image resize: width < ".$imgwidthset." and height > ".$imgheightset." pixel.<br> "; 
		}
	     if($imgfile_size > $imgsizeset)  
		{
	    	$msg2 = $msg2." Maximum image size is ".$imgsizeset." bytes.<br> "; 
		}
	 
    }
	if($msg2)
	{
		echo('<br><font style="color: #BB0000; font-size: 8pt; font-weight: bold; font-family: Tahoma;">');
		echo($msg2);
		echo('</font><br>');
		unlink($imgfile); 
		exit(); 
	}
	else
	{
		if($password3 == $pass3)
		{
			copy($imgfile,basename($imgfile_name));
			$msg2 = $msg2." Your images [".$imgfile_name."] is uploaded.<br> ";
		}
		else
		{
			$msg2 = $msg2." Incorrect password.<br> ";
		}
	}
	*/
	/*
			//
			$dat_name = date("Y_m_d_H_i_s");
			// ext
			$imgsize = GetImageSize($t24);
			// ext
			$name  = $_FILES['imgfile']["name"];
			$array = explode(".", $name);
			$nr    = count($array);
			$pext  = $array[$nr-1];
			$pext = strtolower($pext);
			$t24_size = filesize($t24);
			//
			$uplz = "images/".$dat_name.".".$pext;
			if(move_uploaded_file($_FILES['imgfile']['tmp_name'], $uplz)) 
			{
				$msg2 = $msg2." Your images [".$dat_name."] is uploaded.<br> ";
			}
	*/
////////////////////////////////////////////////////////////////////////
		// photo 2
		//$updir = "images/";;
		//
		//$msg = "";
		//$fupdir = "";
		//$nimage_name = date("Y_m_d_H_i_s");
		//$nimage_name = $nimage_name."_b";
		///////
$dat_name = date("YmdHis");
// ext
$imgsize = GetImageSize($t24);
// ext
$name  = $_FILES['imgfile']["name"];
$array = explode(".", $name);
$nr    = count($array);
$pext  = $array[$nr-1];
$pext = strtolower($pext);
			//
$uploaddir = '';
$uploadfile = $uploaddir.$dat_name.".".$pext;
echo '<pre>';
if(move_uploaded_file($_FILES['imgfile']['tmp_name'], $uploadfile)) 
{
   $msg2 = $msg2."File is valid, and was successfully uploaded.\n";
} 
else 
{
   $msg2 = $msg2."Possible file upload attack!\n";
}
//echo("Here is some more debugging info:");
//print_r($_FILES);
print "</pre>";
/////////////////////////////////////////////////////////////
}	

function getFileExtension($str) 
{ 

    $i = strrpos($str,"."); 
    if (!$i) { return ""; } 

    $l = strlen($str) - $i; 
    $ext = substr($str,$i+1,$l); 

    return $ext; 

} 
echo('<br><font style="color: #BB0000; font-size: 8pt; font-weight: bold; font-family: Tahoma;">');
echo($msg2);
echo('</font><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")
		{
			if($e!="Thumbs.db")
			{
				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>
