<html>
<head>
<title>Insert/Update Image</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
}
.style2 {font-size: 10px}
.style3 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
-->
</style>
</head>

<body bgcolor="#E4E4E4">
<?php
if(isset($_GET['action']))
{
$filedel = $_GET['file'];
unlink($filedel);
}


if(isset($_POST['Submit']))
{
$fileErr="";

 $file_tmp  = $_FILES['file']['tmp_name'];
 $file_type = $_FILES['file']['type'];
 $file_name = $_FILES['file']['name'];
 $emsg ="";
 echo $file_tmp;
 echo $file_type;
 echo $file_name;

 $dest_dir = "../images";
 $dest = $dest_dir . "/" . $file_name;
 
    if (!is_uploaded_file ($file_tmp))
	{
     $fileErr = "Error: No file uploaded";
    }
	if (!file_exists ($dest_dir))
	{
    $fileErr = "Error: Destination directory does not exist";
    }
	if (!is_dir ($dest_dir))
	{
    $fileErr= "Error: Destination directory is not a directory";
	}
	if (file_exists ($dest))
	{
    $fileErr = "Error: File already exists!";
	}

	copy($file_tmp,$dest);
	unlink($file_tmp); 
	

 
}

?>
<table width="75%" border="0" cellspacing="0">
  <tr>
    <td colspan="2" valign="top"><strong>d<?php if(isset($fileErr))echo $fileErr;?></strong></td>
  </tr>
  <tr>
    <td width="49%" valign="top"> 
      <table width="63%" border="0" cellspacing="0">
        <tr>
		<td align=center style="BORDER-TOP: #336699 1px solid;BORDER-LEFT: #336699 1px solid;BORDER-RIGHT: #336699 1px solid;BORDER-BOTTOM: #336699 1px solid;" bgcolor=White>
				<div id="divImg" style="overflow:auto;width:150;height:170"></div>
		</td>  
        </tr>
      </table></td>
    <td width="51%" valign="top"><table width="100%" border="0" cellspacing="0">
        <tr> 
          <td bgcolor="#000099"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>File 
            Name:</strong></font></td>
        </tr>
        <tr> 
          <td width="100%">
		  
		  
        <?php 
          $strHTML="";
		  $dir="../images";
			if ($handle = opendir($dir))
			{
     		$strHTML = $strHTML . "<table border=0 cellpadding=3 cellspacing=0 width=100% >";
			while (false !== ($file = readdir($handle))) { 
			//$strHTML = "";
			//$strHTML=$file . "\n";
			if(strlen($file) > 3)
			{
			$strHTML = $strHTML . "<tr bgcolor=Gainsboro>";
		
			$strHTML = $strHTML . "<td valign=top whidth=100%><font face=verdana size=1>  " . $file . "</font></td>";
			
			$dest_dir = 'images/' . $file;
			
            $strHTML = $strHTML . "<td valign=top style=cursor:hand; onClick=\"selectImage('$dest_dir')\"><u><font color=blue face=verdana size=1>select</font></u></td>";
	        $strHTML = $strHTML . "<td valign=top style=cursor:hand; onClick=\"deleteImage('$dest_dir')\"><u><font color=blue face=verdana size=1>del</font></u></td></tr>";
			}
          //echo($strHTML);
             }
		    $strHTML = $strHTML . "</table>";
		}
		?>
			<div style="overflow:auto;height:120;width:100%;BORDER-LEFT: #316AC5 1px solid;BORDER-RIGHT: LightSteelblue 1px solid;BORDER-BOTTOM: LightSteelblue 1px solid;">
			<?php echo($strHTML);?>
	      </div>
		  
	  	  </td>
        </tr>
        <tr>
          <td><form action="default_image.php" method="post" enctype="multipart/form-data" name="form1">
              <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Upload 
              Image: 
              <input name="file" type="file" id="file">
              <br>
              <input type="submit" name="Submit" value="Upload">
              <br>
              </font> 
            </form></td>
        </tr>
      </table></td>
  </tr>
</table>
<table width="75%" border="0" cellspacing="0">
  <tr>
		<td colspan=2>
				
				<hr>	
				<table border=0 width=340 cellpadding=0 cellspacing=1>
				<tr>
						<td width="90"><span class="style1"><span class="style2">Image source</span> : </span></td>
						<td colspan=3>
						<INPUT type="text" id="inpImgURL" name=inpImgURL size=39>
						<!--<font color=red>(you can type your own image path here)</font>-->
						</td>		
				</tr>					
				<tr>
						<td><span class="style3">Alternate text :</span> </td>
						<td colspan=3><INPUT type="text" id="inpImgAlt" name=inpImgAlt size=39></td>		
				</tr>				
				<tr>
						<td><span class="style3">Alignment : </span></td>
						<td width="93">
						<select ID="inpImgAlign" NAME="inpImgAlign">
								<option value="" selected>&lt;Not Set&gt;</option>
								<option value="absBottom">absBottom</option>
								<option value="absMiddle">absMiddle</option>
								<option value="baseline">baseline</option>
								<option value="bottom">bottom</option>
								<option value="left">left</option>
								<option value="middle">middle</option>
								<option value="right">right</option>
								<option value="textTop">textTop</option>
								<option value="top">top</option>						
						</select>
						</td>
						<td width="102"><span class="style3">Image border :</span></td>
						<td width="50"><select id=inpImgBorder name=inpImgBorder>
							<option value=0>0</option>
							<option value=1>1</option>
							<option value=2>2</option>
							<option value=3>3</option>
							<option value=4>4</option>
							<option value=5>5</option>
						</select>
						</td>					
				</tr>
				<tr>
						<td><span class="style3">Width :</span></td>
						<td><INPUT type="text" ID="inpImgWidth" NAME="inpImgWidth" size=2></td>
						<td><span class="style3">Horizontal Spacing :</span></td>
						<td><INPUT type="text" ID="inpHSpace" NAME="inpHSpace" size=2></td>
				</tr>				
				<tr>
						<td><span class="style3">Height :</span></td>
						<td><INPUT type="text" ID="inpImgHeight" NAME="inpImgHeight" size=2></td>
						<td><span class="style3">Vertical Spacing :</span></td>
						<td><INPUT type="text" ID="inpVSpace" NAME="inpVSpace" size=2></td>
				</tr>
				</table>

		</td>
  </tr>
  <tr> 
    <td colspan="2"><div align="center">
        <INPUT type="button" value="Cancel" onclick="self.close();" style="height: 22px;font:8pt verdana,arial,sans-serif" ID="Button1" NAME="Button1">
        <INPUT type="button" value="Insert" onclick="InsertImage();self.close();" style="height: 22px;font:8pt verdana,arial,sans-serif" ID="Button2" NAME="Button2">
        </span><span id="btnImgUpdate" style="display:none">
        <INPUT type="button" value="Update" onclick="UpdateImage();self.close();" style="height: 22px;font:8pt verdana,arial,sans-serif" ID="Button3" NAME="Button3">
        </span> </div></td>
  </tr>
  <script language="javascript">
function deleteImage(sURL)
	{
	if (confirm("Delete this document ?") == true) 
		{
		//window.navigate("default_Image.php?action=del&file="+sURL+"&catid="+form1.catid.value);
		window.navigate("default_image.php?action=del&file="+sURL);
		}
	}
		
function selectImage(sURL)
	{

SETPath="http://user4/php/toprecruitpuntingandkicking/manager/";


Path=SETPath+"jscripts/tiny_mce/themes/";



	inpImgURL.value =Path+sURL;
	sURL="../"+sURL;
	divImg.style.visibility = "hidden"
	divImg.innerHTML = "<img id='idImg' src='" + sURL + "'>";
	

	var width = idImg.width
	var height = idImg.height 
	var resizedWidth = 150;
	var resizedHeight = 170;

	var Ratio1 = resizedWidth/resizedHeight;
	var Ratio2 = width/height;

	if(Ratio2 > Ratio1)
		{
		if(width*1>resizedWidth*1)
			idImg.width=resizedWidth;
		else
			idImg.width=width;
		}
	else
		{
		if(height*1>resizedHeight*1)
			idImg.height=resizedHeight;
		else
			idImg.height=height;
		}
	
	divImg.style.visibility = "visible"
	}

function InsertImag1ehh()
	{
	oName=window.opener.oUtil.oName

	eval("window.opener."+oName).InsertImage(inpImgURL.value,inpImgAlt.value,inpImgAlign.value,inpImgBorder.value,inpImgWidth.value,inpImgHeight.value,inpHSpace.value,inpVSpace.value);
	}	
function InsertImage()
{
window.opener.document.forms[0].src.value=inpImgURL.value ;

window.opener.document.forms[0].width.value=inpImgWidth.value ;
window.opener.document.forms[0].height.value=inpImgHeight.value ;
window.opener.document.forms[0].vspace.value=inpVSpace.value ;
window.opener.document.forms[0].hspace.value=inpHSpace.value ;


}

</script>

</table>
</body>
</html>
