<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}
if(isset($_POST['btnSaveChanges'])){
          //first set as non fetured
          $sql = "update ".$tableprefix."products set featured='N' WHERE product_id= '".addslashes($productid)."' ";
		  $result = mysql_query($sql);



		 $qry="select * from  ".$tableprefix."products  WHERE featured='Y'  ";
		 $excqry=mysql_query($qry);
		 if(mysql_num_rows($excqry)>=6){
             $message .= "* You can add maximum of six items as featured! <br>";

		 }else{
				     $featured=$_POST['featured'];
					 if($_POST['featured']=="F"){
					  $sql = "update ".$tableprefix."products set featured='Y' WHERE product_id= '".addslashes($productid)."' ";

					  $result = mysql_query($sql);
					 }else{
					   $sql = "update ".$tableprefix."products set featured='N' WHERE product_id= '".addslashes($productid)."' ";

					  $result = mysql_query($sql);
					 }
                    $message .= "*Changes updated successfully! <br>";
		 }



}
$prodimagedir = "../products/";

$sql = "SELECT p.*,a.artist_name FROM ".$tableprefix."products p
       left join ".$tableprefix."artists a on p.product_artist_id=a.artist_id WHERE product_id= '".addslashes($productid)."' ";
$result = mysql_query($sql);
if(mysql_num_rows($result) != 0){
	$row = mysql_fetch_array($result);
	$txtProductName =$row["product_name"];
	$txtProductCode =$row["product_code"];
	$txtDescription =$row["product_description"];
	$txtPrice = $row["product_price"];
	$ddlCategory = $row["product_category"];
	$ddlArtist = $row["product_artist_id"];
	$imgsmall = $row["product_image_small"];
	$imgbig = $row["product_image_big"];
	$txtStock = $row["product_stock"];
	$txtReorderLevel = $row["reorder_level"];
	$txtfeatured=$row["featured"];
	$ddlArtistName=$row["artist_name"];
}

include "../includes/htmltop.php";
?>
<script>
function openWindow(id)
{
	var url = "../viewimage.php?id="+id;
	window.open(url,"Image","height=500 width=500");
}

</script>
		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title">Edit Product Details</div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">																			
					
					<form name="frmProductDetails" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" enctype="multipart/form-data">
						<input type="hidden" name="productid" value="<?php echo $productid;?>" >
						<table cellpadding="2" cellspacing="2" width="100%" class="manage_table" border=0>
							<tr><td colspan="3">&nbsp;</td></tr>
							<tr><td colspan="3" align="left" >
							<?php
							  if ($row["product_image_big"]!= "" and $row["product_image_small"]!= "") {
									 $imageurl =  "<a href='#' onclick='openWindow(".$productid.");'> ";
									  if(!function_exists('gd_info')){
										$imageurl .= "<img src='".$prodimagedir.urlencode($row["product_image_small"])."' border='0' width='100' height='100' >";
									  }else{
										$imageurl .= "<img src='../getimagethumbnail.php?imagename=".urlencode($row["product_image_small"])."' border='0' >";
									   }
									$imageurl .= "</a>";

								}else  if ($row["product_image_small"]!= ""){
									if(!function_exists('gd_info')){
										$imageurl .= "<img src='".$prodimagedir.urlencode($row["product_image_small"])."' border='0' width='100' height='100' >";
									  }else{
										$imageurl .= "<img src='../getimagethumbnail.php?imagename=".urlencode($row["product_image_small"])."' border='0' >";
									   }
								}

							echo $imageurl;

							?>
							</td></tr>
							<tr><td colspan="3">&nbsp;</td></tr>
							<tr><td align="left" width="25%">Product Name &nbsp; </td><td width="5%">&nbsp;</td><td width="70%" align="left" style='word-break:break-all;'><?php echo htmlentities($txtProductName);?></td></tr>
							<tr><td align="left" width="25%">Product Code &nbsp; </td><td width="5%">&nbsp;</td><td align="left" style='word-break:break-all;'><?php echo htmlentities($txtProductCode);?></td></tr>
							<tr><td align="left" valign="top">Description&nbsp;</td><td >&nbsp;</td><td align="left" style='word-break:break-all;'><?php echo htmlentities($txtDescription);?></td></tr>
							<tr><td align="left" >Price&nbsp;</td><td >&nbsp;</td><td align="left" style='word-break:break-all;'><?php echo htmlentities($txtPrice);?></td></tr>
							<tr><td align="left" >Category&nbsp;</td><td align="left">&nbsp;</td>
								<td align="left">
								<?php echo getCategory("#",$ddlCategory )?>
								</td>
							</tr>
							<tr><td align="left" >Artist&nbsp;&nbsp;</td><td align="left">&nbsp;</td>
								<td align="left">
								<?php echo $ddlArtistName?>
								</td>
							</tr>
							<tr><td align="left" >Stock Available&nbsp;</td><td >&nbsp;</td><td align="left" style='word-break:break-all;'><?php echo htmlentities($txtStock);?></td></tr>
							<tr><td align="left" >Stock Reorder Level&nbsp;</td><td >&nbsp;</td><td align="left" style='word-break:break-all;'><?php echo htmlentities($txtReorderLevel);?></td></tr>
							<tr><td align="left" >Featured&nbsp;</td><td >&nbsp;</td>
								<td align="left">
								<input  name="featured" class='checkbox' type='checkbox' value="F" <?php if($txtfeatured=="Y") echo "checked";?>>
								</td>
							</tr>
							<tr><td colspan="3">&nbsp;</td></tr>

							<tr><td colspan="3" align="center"><input type="submit" value="Update" name="btnSaveChanges" class="button">&nbsp;
							<?php
							$location=$_SESSION["gbackurl"];
							?>
							<input type="button" class="button" value="Back" name="btnBack" onClick="window.location.href='featureditem.php';" ></td></tr>

						</table>
					</form>
				
				</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
	
?>