<?php
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_currenttempsiteid"];
$relativepathtoserver = "../";
/* This file will embed the uploaed image on imageband
*  and save the image in workarea location as 'session_editedimage'
*/
if ($_POST['btnuploadback'] == "Back") {
				header("location:imageeditor.php");
				exit;
} else if ($_POST['btnuploadtype'] == "Upload") {
				if ($_FILES['fileimage']['size'] > 0) {
								list($width, $height, $type, $attr) = @getimagesize($_FILES['fileimage']['tmp_name']);

								if ($type > 3 or $type == "") {
												$errormessagefileupload = "Please upload only .jpg,.gif,.png image types";
								} else {
												$imagewidth_height_type_array = explode(":", ImageType($_SESSION['session_actualbanlocation']));

												$imagetype = $imagewidth_height_type_array[0];
												$imagewidth = $imagewidth_height_type_array[1];
												$imageheight = $imagewidth_height_type_array[2];
												$assignedname = $_SESSION['session_currentimage'];
												$assignednameforupload = "ug_" . time() . $_FILES['fileimage']['name'];
                                                /* if site is not published*/  
												if ($_SESSION['sitetype'] == "new") {
												                /* copy the the uploaded image to workarea location(tempsites)*/
																@move_uploaded_file($_FILES['fileimage']['tmp_name'], $relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $assignednameforupload);
																@chmod($relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $assignednameforupload, 0777);
																$resizedimage = $relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/ug_rez_" . $assignednameforupload;
																$uplodaedimage = $relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $assignednameforupload;
																/* resize the uploaded image to fit in template band save it in same location(ie wrokarea location)*/
																Resizeimage($uplodaedimage, $imageheight, $imagewidth, $resizedimage);
																@chmod($resizedimage, 0777); 
																/* copy  band image to workarea location(tempsite)*/
																@copy($_SESSION['session_actualbanlocation'], $relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $_SESSION['session_currentimage']);
																/* embed the resized uploaded image to band image*/
																embedimage($relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $_SESSION['session_currentimage'], $resizedimage);
																@unlink($resizedimage);
																@copy($relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $_SESSION['session_currentimage'], $relativepathtoserver . "usergallery/$userid/images/" . $_SESSION['session_currentimage']);
																watermarkimage($relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $assignedname);
																$_SESSION['session_editedimage'] = $relativepathtoserver . "workarea/tempsites/$tmpsiteid/images/" . $_SESSION['session_currentimage'];
												} else {
												                /* copy the the uploaded image to workarea location(site)*/
																move_uploaded_file($_FILES['fileimage']['tmp_name'], $relativepathtoserver . "workarea/sites/$siteid/images/" . $assignednameforupload);
																chmod($relativepathtoserver . "workarea/sites/$siteid/images/" . $assignednameforupload, 0777);
																$resizedimage = $relativepathtoserver . "workarea/sites/$siteid/images/ug_rez_" . $assignednameforupload;
																$uplodaedimage = $relativepathtoserver . "workarea/sites/$siteid/images/" . $assignednameforupload;
																/* resize the uploaded image to fit in template band save it in same location(ie wrokarea location)*/
																Resizeimage($uplodaedimage, $imageheight, $imagewidth, $resizedimage);
																chmod($resizedimage, 0777); 
																/* copy  band image to workarea location(tempsite)*/
																copy($_SESSION['session_actualbanlocation'], $relativepathtoserver . "workarea/sites/$siteid/images/" . $_SESSION['session_currentimage']);
																/* embed the resized uploaded image to band image*/
																embedimage($relativepathtoserver . "workarea/sites/$siteid/images/" . $_SESSION['session_currentimage'], $resizedimage);
																unlink($resizedimage);
																@copy($relativepathtoserver . "workarea/sites/$siteid/images/" . $_SESSION['session_currentimage'], $relativepathtoserver . "usergallery/$userid/images/" . $_SESSION['session_currentimage']);
																$_SESSION['session_editedimage'] = $relativepathtoserver . "workarea/sites/$siteid/images/" . $_SESSION['session_currentimage'];
												} 
												header("location:imageeditor.php");
												exit;
								} 
				} 
} 
$currentloc = "../";
include "../includes/applicationheader.php";
?>   
<script>
	 window.name="targ";
</script>
</head>
<body>
<table width="100%" cellpadding=2 align=center>
   <tr>
      <td>
	                           <FIELDSET>
							    <LEGEND class=maintextbigbold>Image Manager</LEGEND>
								
								<table width="97%" border="0">
								  <tr><td colspan=6>&nbsp;</td></tr>
								  
								     <tr>
									  
									   <td>
									             <FIELDSET>
																		      <legend class=maintextbold>Upload your Image</legend>
																			    <table width="50%">
																				      <form  method="post" enctype="multipart/form-data"   name="frmImageUpload" target="targ">
																					  <tr>
																					     <td class=errormessage colspan=2><?php echo $errormessagefileupload;?></td>
																					  </tr>
																				      <tr>
																					     <td class=maintext>File</td>
																					     <td class=maintext>
																						   <input class=textbox type=file name=fileimage>
																						 </td>
																					  </tr>
																				      <tr>
																					    <td colspan=4 align=center>
																						<input id=btnuploadtype  name=btnuploadtype class=button  type=submit value="Upload" >
																						<input id=btnuploadback  name=btnuploadback class=button  type=submit value="Back" >
																							</td>
																					    </tr>
																					 
																					  </form>
																				  </table>
																			  
																			  
												  </FIELDSET>
									   </td>
									   
									 </tr>
								  
								 
							    <tr><td colspan=2>&nbsp;</td></tr>
							
								</table>   
								
							  </FIELDSET>       
	  </td>
   </tr>
  
		  
</table>
<?php
  include "./includes/editorfooter.php";
?> 