<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCreate 1.1                 |
// +----------------------------------------------------------------------+
// | Authors: sudheesh<sudheesh@armia.com>        		              	  |
// |          									                          |
// +----------------------------------------------------------------------+
include "../includes/session.php";
include "../includes/config.php";
include "../includes/function.php";
$tmpsiteid = $_SESSION['session_currenttempsiteid'];
$templateid = $_SESSION['session_currenttemplateid'];
$userid = $_SESSION["session_userid"];
$siteid = $_SESSION['session_siteid'];
if ($_SESSION['session_published'] == "yes") {
    $urllocation = "../workarea/sites/$siteid/images/";
} else {
    $urllocation = "../workarea/tempsites/$tmpsiteid/images/";
} 
if ($_POST['btnuploadtype'] == "Upload") {
    // echo "heree";
    $filename = $_FILES['imgfile']['name'];
    $imagewidth_height_type_array = explode(":", ImageType($_FILES['imgfile']['tmp_name']));
    $imagetype = $imagewidth_height_type_array[0];
    $assignedname = "ug_" . $userid . "_" . time() . "." . $imagetype;
    if ($imagetype == "gif" or $imagetype == "png" or $imagetype == "jpg") {
        move_uploaded_file($_FILES['imgfile']['tmp_name'], "../usergallery/$userid/images/" . $assignedname);
        chmod("../usergallery/$userid/images/" . $assignedname, 0777);
        copy("../usergallery/$userid/images/" . $assignedname, $urllocation . $assignedname);
        chmod($urllocation . $assignedname, 0777);
        if ($_SESSION['session_published'] != "yes")
            watermarkimage("../workarea/tempsites/$tmpsiteid/images/" . $assignedname);
        echo "<script>returnValue = new Object(); returnValue.url=\"./images/" . $assignedname . "\"; window.close();</script>";
    } else {
        $errormessage = "file not supportted.please upload only gif,jpg or png images";
    } 
} 
$currentloc = "../";
include "../includes/applicationheader.php";

?>
<SCRIPT>
 window.name="targ";
 function canceltblpro(){
        window.close();
  }
  function savetblpro(){
		document.frmImageUpload.submit();
        //opener.settablervalue(tborder,tborderclr,bgclr,cells,cellp,talign,twidth);
           //window.close();
  }
   function back(){
		document.frmImageUpload.submit();
        //opener.settablervalue(tborder,tborderclr,bgclr,cells,cellp,talign,twidth);
           //window.close();
  }

  
</SCRIPT>
<body>
<table width="100%" cellpadding=2 cellpadding=2 align=center>
   <tr>
      <td>
	                  <FIELDSET>
					      <legend class=maintextbold>Upload Image</legend>
						    <table width="50%">
							      <form  method="post" enctype="multipart/form-data"  name="frmImageUpload" target="targ">
								  <tr>
								     <td class=errormessage colspan=2><?php echo $errormessage?></td>
								  </tr>
							      <tr>
								     <td class=maintext>File</td>
								     <td class=maintext>
									   <input  type=file name=imgfile>
									 </td>
								  </tr>
							      <tr>
								    <td colspan=4 align=center><input id=btnuploadtype  name=btnuploadtype class=button  type=submit value="Upload" >
										<input class=button  type=button value="Cancel" onclick="canceltblpro();">
										
									 </td>	
								    </tr>
								  
								  </form>
							  </table>
						  
						  
					  </FIELDSET>
	  </td>
	</tr>
</table>	  				  	  
<?php
  include "./includes/editorfooter.php";
?> 
