<?
ob_start();
session_start();
include("../include/db.inc.php");
include("../include/bit_functions.inc.php");
 //include("function_img.php");
include("thumb_function.php");
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
   if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
   {
			header("location:login.php");
   }
		$pid=$_GET['id'];
			if(isset($_POST['sub_btn']))
			{
			$featured=$_POST[featured];
			$fea=mysql_fetch_array(mysql_query("select featured from t123go_product where pid='".$pid."'"));

			$TR_product_name=str_replace("/","|",$_POST['TR_product_name']);

		$cat1=$_POST['category1'];
		$cat2=$_POST['category2'];
		$cat3=$_POST['category3'];
		$cat4=$_POST['category4'];
		$cat5=$_POST['category5'];
		$cat6=$_POST['category6'];
		if($cat6 > 0)
		$top = $cat6;
		else if($cat5 > 0)
		$top = $cat5;
		else if($cat4 > 0)
		$top = $cat4;
		else if($cat3 > 0)
		$top = $cat3;
		else if($cat2 > 0)
		$top = $cat2;
		else if($cat1 > 0)
		$top = $cat1;
		else
		$top=0;

			$sel_query=mysql_query("select pid from t123go_product where pname='".$TR_product_name."' and pid!=".$_GET['id']);
			$product_exists=mysql_num_rows($sel_query);
			if($product_exists){
			echo "You edited product ' ".$TR_product_name." ' already exists";

			}
			if($_FILES['FL_thumbnail']['tmp_name']!='' && is_uploaded_file($_FILES['FL_thumbnail']['tmp_name']))
			{
                    $productId = $pid;
					if($productId)
					{
						$maindir = "../images/product/";
						$thumbnail = $_FILES['FL_thumbnail']['name'];
						if($thumbnail<>"")
						{
								$randstr= rand(11111,99999);
								$uploaddir = $maindir.$productId;
								if(!file_exists($uploaddir)){
									@mkdir($uploaddir,0777);
								}

								$uploadfile = $uploaddir."/".$thumbnail;

								if(copy($_FILES['FL_thumbnail']['tmp_name'], $uploadfile))
								{
									$ext = substr($thumbnail,-3,3);
									$upload_file1 = $uploaddir."/".$productId."_".$randstr."_tmb1.".$ext;
									$upload_file2 = $uploaddir."/".$productId."_".$randstr."_tmb2.".$ext;
									$upload_file3 = $uploaddir."/".$productId."_".$randstr."_tmb3.".$ext;
									$upload_file4 = $uploaddir."/".$productId."_".$randstr."_tmb4.".$ext;
									$upload_file5 = $uploaddir."/".$productId."_".$randstr."_tmb5.".$ext;
									$upload_file6 = $uploaddir."/".$productId."_".$randstr."_tmb6.".$ext;

									$file_tbl_name = $productId."_".$randstr."_tmb.".$ext;

									//$feature=0;
									mysql_query("update t123go_product set thumbnail ='".$file_tbl_name."' where pid='$productId'");

									if($ext=='jpg'){	
												jpgimage($uploadfile,$upload_file1,$upload_file2,$upload_file3,$upload_file4,$upload_file5,$upload_file6);
											}else if($ext=='gif'){
												gifimage($uploadfile,$upload_file1,$upload_file2,$upload_file3,$upload_file4,$upload_file5,$upload_file6);
											}else if($ext=='png'){
												pngimage($uploadfile,$upload_file1,$upload_file2,$upload_file3,$upload_file4,$upload_file5,$upload_file6);
											}	
								}
						}
					}

				}else{
					$file_tbl_name=$_POST['thumbnail'];
				}


  
				 $update_query=mysql_query("update t123go_product set
				cid='".$top."',
				pname='".htmlentities($TR_product_name)."',
				brand='".$_POST['brand']."',
				description='".$_POST['TR_description']."',
				description1='".$_POST['TR_description1']."',
				type1='".$_POST['type1']."',
				delivery_cost='".$_POST['TR_delivery']."',
				price='".$_POST['NR_price']."',
				fixed_price='".$_POST['fixed_price']."',
				starting_bidprice='".$_POST['NR_startbid_price']."',
				bid_price='".$_POST['NR_startbid_price']."',
				break_even_point='".$_POST['break_even_point']."',
				dummy_user_from='".$_POST['dummy_user_from']."',
				dummy_user_to='".$_POST['dummy_user_to']."',
				thumbnail='".$file_tbl_name."',
				community_offset='".$_POST['community_offset']."'				
				where pid=".$pid);
                
				echo '"'.$TR_product_name.'" Product has been edited';
				if($featured==1)
				{
				header("location:featured_product.php");
				}else{
				header("location:product_list.php");
				}
            	}

		$sel_qry=mysql_query("select * from t123go_product where pid=".$pid);
		$mypro=mysql_fetch_array($sel_qry);

		$tree=get_cat_tree($mypro['cid']);
		$arr=explode(",",$tree);
	    $catarr=array_reverse($arr);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Money-Auctions Administion Console</title>
<link href="index.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<?=_BASEURLCSSNEW_?>/dhtmlgoodies_calendar.css?random=20051112" media="screen" />
<script language="JavaScript" src="../js/common.js"></script>
<script language="javascript" src="../js/dhtmlgoodies_calendar.js?random=20060118"></script>
<script language="JavaScript" src="../js/common.js"></script>
<script language="JavaScript">
function veiws(pid){

		window.open('thumbnail.php?id='+pid,'','scrollbars,width=800,height=600,top=50,left=180');
	}
</script>
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,spellchecker",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		content_css : "/example_data/example_full.css",
	    plugin_insertdate_dateFormat : "%Y-%m-%d",
	    plugin_insertdate_timeFormat : "%H:%M:%S",
		extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		external_link_list_url : "example_data/example_link_list.js",
		external_image_list_url : "example_data/example_image_list.js",
		flash_external_list_url : "example_data/example_flash_list.js",
		file_browser_callback : "mcFileManager.filebrowserCallBack",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		apply_source_formatting : true,
		spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
	});
</script>

<script language="javascript" type="text/javascript">
function validfrm()
{
if(document.form1.type1.value=='1' && document.form1.fixed_price.value=='0.00')
	{
		alert("Enter Your Fixed Price Value");
		document.form1.fixed_price.focus();
		return false;

	}
	}
</script>
<script language="javascript">
<?
for($a=1; $a<6; $a++)
{
$b=$a+1;
?>
function populate<?=$a?>(catid, form1)
{
	for(x=form1['category<?=$b?>'].length; x>=0; x=x-1)
	{
		form1['category<?=$b?>'][x]=null;
	}

		<?php
		$sql=mysql_query("SELECT * FROM add_category");
		while($res=mysql_fetch_object($sql))
		{
			$c_id = $res->id;

		?>

		if(catid == '<?php echo $c_id; ?>')
			{

				<?php
					$subsql=mysql_query("SELECT * FROM add_category WHERE top='$c_id'");
				?>
				form1['category<?=$b?>'][form1['category<?=$b?>'].length]=new Option("--Select--", "0", "", false);
				<?php
				while($subres=mysql_fetch_object($subsql))
					{
						$s_id = $subres->id;
						$s_text = $subres->name;
				?>
						form1['category<?=$b?>'][form1['category<?=$b?>'].length]=new Option("<? echo $s_text; ?>", "<?php echo $s_id; ?>", "", false);

			<?php	} ?>
			}
<?php	} ?>

}
<? }?>

</script>
</head>
<body bgcolor="#ffffff">
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum">

<table width="98%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td width="10" align="center" valign="top">&nbsp;</td>
    <td align="center" valign="top"><table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr>
          <td width="1" valign="top">&nbsp;</td>
          <td valign="top"><br> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr>
                <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                <td background="img/bg01.gif"><strong>&nbsp;EDIT PRODUCT</strong></td>
                <td width="35"><img src="img/04.gif" width="35" height="23"></td>
              </tr>
            </table>
            <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr>
                <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
                <td valign="top" align="center">

                  <br> <FORM ACTION="" METHOD="post" enctype="multipart/form-data" name="form1" onSubmit="return validfrm()">
				  <input type="hidden" name="featured" value="<?=$_GET['featured']?>">
                  <input type="hidden" name="thumbnail" value="<?=$mypro['thumbnail']?>">
                    <table width="90%"  border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                      <tr bgcolor="#FFFFFF" class="headingtxt">
                        <td height="25" style="padding-left:10px;"> Key</td>
                        <td height="25" style="padding-left:10px;">Value</td>
                        <td height="25" style="padding-left:10px;">Description</td>
                      </tr>
					  <tr bgcolor="#FFFFFF">
                              <td  colspan="3" class="txt" style="padding-left:10px;">
                <table width="90%" align="center" border="0" cellspacing="0" cellpadding="2">
                  <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">CATEGORIES</div></th>
                    <td width="71%" style="padding-left:20px">
                    <select name="category1"   id="category1" onChange="populate1(this.options[this.selectedIndex].value, document.form1);" style="width:250px" />
                      <option value="0">--Select--</option>
                      <?
					   $sql="select * from add_category where top='0' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[0]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                      </select>
                    </td>
                  </tr>
                  <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold" >SUB CATEGORIE 1</div></th>
                    <td width="71%" style="padding-left:20px">
                    <select name="category2"  style="width:250px" id="category2"  onChange="populate2(this.options[this.selectedIndex].value, document.form1);"/>
                    <option value="0">--Select--</option>
                     <?
					   $sql="select * from add_category where top='".$catarr[0]."' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[1]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                    </select>
                    </td>
                  </tr>
                  <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">SUB CATEGORIE 2</div></th>
                    <td width="71%" style="padding-left:20px">
                     <select name="category3"  style="width:250px" id="category3"  onChange="populate3(this.options[this.selectedIndex].value, document.form1);"/>
                     <option value="0">--Select--</option>
                     <?
					   $sql="select * from add_category where top='".$catarr[1]."' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[2]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                      </select>
                    </td>
                  </tr>
                  <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">SUB CATEGORIE 3</div></th>
                    <td width="71%" style="padding-left:20px">
                    <select name="category4"  style="width:250px" id="category4"  onChange="populate4(this.options[this.selectedIndex].value, document.form1);"/>
                    <option value="0">--Select--</option>
                    <?
					   $sql="select * from add_category where top='".$catarr[2]."' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[3]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                    </select>
                    </td>
                  </tr>
                  <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">SUB CATEGORIE 4</div></th>
                    <td width="71%" style="padding-left:20px">
                     <select name="category5"  style="width:250px" id="category5"  onChange="populate5(this.options[this.selectedIndex].value, document.form1);"/>
                    <option value="0">--Select--</option>
                    <?
					   $sql="select * from add_category where top='".$catarr[3]."' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[4]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                      </select>
                    </td>
                  </tr>
                 <tr>
                    <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">SUB CATEGORIE 5</div></th>
                    <td width="71%" style="padding-left:20px">
                     <select name="category6"  style="width:250px" id="category6"  onChange="populate6(this.options[this.selectedIndex].value, document.form1);"/>
                     <option value="0">--Select--</option>
                    <?
					   $sql="select * from add_category where top='".$catarr[4]."' order by name";
					   $res=mysql_query($sql);
					while($row=mysql_fetch_array($res))
						{
								if($catarr[5]==$row['id'])
								{
									echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
								}

							}
						?>
                      </select>
                    </td>
                  </tr>
                </table>
              </td>
                            </tr>
                      <tr bgcolor="#FFFFFF">
                        <td class="txt" style="padding-left:10px;">Product Name
                          :</td>
                        <td style="padding-left:10px;"><input name="TR_product_name" type="text" class="inp" size="45" value="<?=$mypro['pname']?>"></td>
                        <td style="padding-left:10px;">Which will be displayed
                          on front end</td>
                      </tr>
                      <tr bgcolor="#FFFFFF">
                        <td height="28" class="txt" style="padding-left:10px;">Caption :</td>
                        <td style="padding-left:10px;"><input name="brand" type="text" class="inp" size="45" value="<?=$mypro['brand']?>"></td>
                        <td style="padding-left:10px;">Brand related product</td>
                      </tr>
                     
					  
                      <tr bgcolor="#FFFFFF" id="priceid">
                        <td class="txt" style="padding-left:10px;">Market Price :</td>
                        <td style="padding-left:10px;"><input name="NR_price" type="text" class="inp" size="45" value="<?=$mypro['price']?>"></td>
                        <td style="padding-left:10px;">Fixed Price of product</td>
                      </tr>
					  <tr bgcolor="#FFFFFF" id="priceid">
                        <td class="txt" style="padding-left:10px;">Fixed Price :</td>
                        <td style="padding-left:10px;"><input name="fixed_price" type="text" class="inp" size="45" value="<?=$mypro['fixed_price']?>"></td>
                        <td style="padding-left:10px;">Fixed Price Of Product</td>
                      </tr>
                     <tr bgcolor="#FFFFFF">
                          <td class="txt" style="padding-left:10px;">Start BidPrice :</td>
                          <td style="padding-left:10px;"><input name="NR_startbid_price" type="text" value="<?=$mypro['starting_bidprice']?>" class="inp" size="45"></td>
                          <td style="padding-left:10px;">Starting Bid Point Price of product</td>
                        </tr>
                      <tr bgcolor="#FFFFFF">
                        <td class="txt" style="padding-left:10px;">Thumbnail :</td>
                        <td style="padding-left:10px;"><input name="FL_thumbnail" type="file" class="inp" size="31">
                          <a href="javascript:veiws('<?=$mypro['pid']?>')" class="link4">Current
                          Thumbnail</a> </td>
                        <td style="padding-left:10px;">Main Image of product</td>
                      </tr>
					  <tr bgcolor="#FFFFFF">
                              <td class="txt" style="padding-left:10px;">Break Even Point :</td>
                              <td style="padding-left:10px;"><input name="break_even_point" type="text" class="inp" size="45" value="<?=$mypro['break_even_point']?>"></td>
                              <td style="padding-left:10px;">Break Even Price</td>
                            </tr>
							<tr bgcolor="#FFFFFF">
                              <td class="txt" style="padding-left:10px;">Dummy Users:</td>
                              <td style="padding-left:10px;">From
                              <input type="text" name="dummy_user_from" value="<?=$mypro['dummy_user_from']?>" style="width:50px">				  
                             To
                              <input type="text" name="dummy_user_to" value="<?=$mypro['dummy_user_to']?>" style="width:50px">					 
							  </td>
                              <td style="padding-left:10px;">No. of Dummy Users</td>
                            </tr>
					  <tr bgcolor="#FFFFFF">
                      <td class="txt" style="padding-left:10px;">Type 1:</td>
                      <td style="padding-left:10px;">
							  <select name="type1">
							  <option value="0">--select type of auction--</option>
							   <? $sql_type="select type_id,auction_type from t123go_auctiontype";
								$type=mysql_query($sql_type);
								while($row_type=mysql_fetch_array($type))
									{?>
								  <option value="<?php echo $row_type['type_id'];?>" <? if($mypro['type1']==$row_type['type_id']){ echo "selected";}?> > 
								  <?php echo ucfirst($row_type['auction_type']);?> </option>
								
								  <?
									}?>
							  
								  </select>
							  </td>
                              <td style="padding-left:10px;">Type of product</td>
                            </tr>
                    <tr bgcolor="#FFFFFF">
                              <td class="txt" style="padding-left:10px;">Shipping Amounts :</td>
                              <td style="padding-left:10px;"><input name="TR_delivery" type="text" class="inp" size="45" ><?=$mypro['deleviry_cost']?></td>
                             <td style="padding-left:10px;">Product Delivery cost</td>
                            </tr>
							<tr bgcolor="#FFFFFF">
                              <td class="txt" style="padding-left:10px;">Community Offset :</td>
                              <td style="padding-left:10px;"><input name="community_offset" type="text" class="inp" size="45"></td>
                             <td style="padding-left:10px;">Product Community Offset</td>
                            </tr>
							
                    </table>
                    <table width="90%"  border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                      <tr bgcolor="#FFFFFF">
                        <td width="17%" class="txt" style="padding-left:10px;">Description :</td>
                        <td width="83%" style="padding-left:10px;">
						<textarea name="TR_description" cols="74" rows="3" class="inp" style="width:800px; height:300px"><?=$mypro['description']?></textarea><br />
<textarea name="TR_description1" cols="74" rows="3" class="inp" style="width:800px; height:300px"><?=$mypro['description1']?></textarea></td>
                      </tr>
                    </table>
                    <br>
                    <table width="90%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                      <tr>
                        <td align="center" bgcolor="#EDEDED"> <input name="sub_btn" type="submit" class="buttons" value="Save">
                          &nbsp;&nbsp;
                          <input name="back" type="button" class="buttons" onClick="window.location.href='<? if($_GET['featured']){ echo "featured_product.php";}else{ echo "product_list.php";}?>'" value="Back To List"> </td>
                      </tr>
                    </table>
                    </FORM>
                  <br> </td>
                <td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9"></td>
              </tr>
            </table>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td  width="709" align="right" background="img/tbl-bg.gif"></td>
                <td width="33"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table></td>
          <td width="20" valign="top">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
 

<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>

<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->

</body>
</html>
