<?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['selectedimage'] != "") {
    $filename = $_POST['selectedimage'];
    copy("../usergallery/$userid/images/" . $filename, $urllocation . $filename);
    chmod($urllocation . $filename, 0777);
    if ($_SESSION['session_published'] != "yes")
        watermarkimage($urllocation . $filename);
    echo "<script>returnValue = new Object(); returnValue.url=\"./images/" . $filename . "\"; window.close();</script>";
} 
$currentloc = "../";
include "../includes/applicationheader.php";

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

  function selectthisimags(id){
    document.getElementById("selectedimage").value=id;
    document.frmImageUpload.submit();
  }	
</SCRIPT>
</head>
<body>
<table width="100%" cellpadding=2 cellpadding=2 align=center>
 <tr>
   
    <td class=errormessage align=center>
	<?php
	 if(!validateSizePerUser($_SESSION["session_userid"],$size_per_user,$allowed_space)) {
           echo "The space taken by you has exceeded the allowed limit.<br>(Space taken by you: " . human_read($size_per_user) . " <br>Allowed space: " . human_read($allowed_space) . ")<br>Delete 
		   unused images or any/all of the sites created by you to proceed further.<br>&nbsp;<br>";
		   exit;
     }
	?>
	</td>
   </tr>
    <tr>
     <td align=center><a class="editorlinks" href="#" onclick="canceltblpro();">Cancel without selecting image</a></td></td>
   </tr>
   <tr>
      <td>
	                  <FIELDSET>
					      <legend class=maintextbold>Select Image from your gallery</legend>
						  <form method="post"   name="frmImageUpload" target="targ">
						  <table border=0 width="70%" align=center>
						       <?php
								        $dirpath="../usergallery/$userid/images/";
								        $handle = opendir($dirpath);
								        $i=0;
								        while( false !== ($file = readdir($handle))){
										  if ($file != "." && $file != ".." && $file !="Thumbs.db" && $file!="thumbimages" ) {
														if($i==0) {
															echo "<tr>";
														}
														if($i==4) {
														     $i=0;
														 	 echo "</tr><tr>";
														}
											
										
							 ?>
							              
												  <td>
												     <FIELDSET>
												      <TABLE>
													     <tr>
														   <td> <img id="<?php echo $file?>" src="<?php echo $dirpath?><?php echo $file?>" width=100 height=100 onclick="selectthisimags(this.id)"></td>
														 </tr>
													  </TABLE>
													  </fieldset>
										              
										         </td>
										   
										    
								     
							             
							 <?php	
								                     $i++;
													
								   		}
										
										
								   }
								   if($i<=3){
									  echo "<td colspan='3'>&nbsp;</td></tr>";
								  }else if($i==4){
									  echo "</tr>";
							   	  }
							?>
								 <input type=hidden name=selectedimage id=selectedimage value="">
								  </form>
							  </table>
						  
						  
					  </FIELDSET>
	  </td>
	</tr>
</table>	  				  	  

<?php
  include "./includes/editorfooter.php";
?> 
