<? ob_start();

session_start();

require_once("../dbconnect.php");




require_once("sesurl.php");
$prid = (int) ($_GET["prid"]);
//////****csv***/////

//$fp1 = fopen('products.csv', 'w');
    $fp1=fopen('Wallpaper.csv','w');
    
	 fwrite($fp1,"pid,");
	 fwrite($fp1,"catid,");
	 fwrite($fp1,"subcat_id,");
	 fwrite($fp1,"subsubcatid,");
	 fwrite($fp1,"itemno,");
	 fwrite($fp1,"pname,");
	 fwrite($fp1,"unitsprice,");
	 fwrite($fp1,"colors,");
	 fwrite($fp1,"description,");
	 fwrite($fp1,"discount,");
	 fwrite($fp1,"mini,");
	 fwrite($fp1,"maxi,");
	 fwrite($fp1,"status,");
	 fwrite($fp1,"addedon,");
	 fwrite($fp1,"weight,");
	 fwrite($fp1,"sizes,");
	 fwrite($fp1,"Print\n,");
	 fclose($fp1);

			  
// for insert related products
$id = isset($_GET["id"])?($_GET["id"]):0;
	if((isset($_GET["id"])) && ($_GET["id"]!="")){
		$id = isset($_GET["id"])?($_GET["id"]):0;
		$sql =mysql_query(" select * from quantity_master where id = ".$id."");
		$result =mysql_fetch_assoc($sql);
		
		$id = $result["id"];
		
		$quantity = $result["quantity"];
		
	}
	$addRqst = isset($_POST["add"])?TRUE:FALSE;
    $updateRqst = isset($_POST["update"])?TRUE:FALSE;
	if($addRqst || $updateRqst){
		$quantity=isset($_POST["quantity"])?stripslashes($_POST["quantity"]):"";
		

		//validation
		
		$style="";
		
		if(empty($quantity)){
			$errMsg= "error";
			$quantity_style="style='border:solid 1px #ff0000; '";
			$err_quantity="Please enter quantity\n";
		}
		
		
		else {
			$and = "";
			if($id!=0)
					$and .= " AND id<>".$id;
				$qry1 = "SELECT id FROM quantity_master WHERE quantity=".$quantity." and prid = ".$prid .$and;
				$rs1 = mysql_query($qry1);
				if(mysql_num_rows($rs1) > 0) {
					$errMsg= "error";
					$quantity_style="style='border:solid 1px #ff0000; '";
					$err_quantity="Quantity Already Exits\n";
				} 
				
			
			if($addRqst){
				
				if(empty($errMsg)){
					$insert_qry = "insert into quantity_master (`quantity`,`prid`) values (".$quantity.",".$prid.")";			
					if(mysql_query($insert_qry)){
						header("location:quantity_listing.php?prid=".$prid."&msg");
						exit;
					}
				}		
			}	
			if($updateRqst){
				if(empty($errMsg)){
					$update_qry = "update quantity_master set quantity = ".$quantity." where id = ".$id;
					if(mysql_query($update_qry)){
						header("location:quantity_listing.php?prid=".$prid."smsg");
						exit;
					}
				}		
			}	
		}
	}

?>

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Welcome to Sir Box and Plastics</title>

<style type="text/css">

<!--

body {

	margin-left: 0px;

	margin-top: 0px;

	margin-right: 0px;

	margin-bottom: 0px;

}

-->

</style>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

<script language="javascript" src="ajaxvalid.js"></script>



</head>

<body>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

      <tr>

        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

          <tr>

            <td><? require_once("header.php"); ?></td>

          </tr>

          <tr>

            <td>&nbsp;</td>

          </tr>

			<tr>
				<td>
					<center>		
					<table >
						<tr>
							<td><?php if ($id!=0) echo "<b>Edit Quantity</b> "; else echo "<b>Add quantity</b>";?></td>			
						</tr>			
						<tr>
							<td>
								<form name="form1" method="post">
								<table cellpadding="3" width="500" border="1">
									<tr>
										<td><b>Quantity</b></td>	
										<td><input type="text" name="quantity" value="<?php echo $quantity;?>" <?php echo $quantity_style; ?> > <span style="color:red;"><?php echo $err_quantity;?> </span></td>	
									</tr>
									<?php
																									  
									  if($id!=0){
										$name = "name='update'";
										$onclick = "onClick=\"return product('mod')\"";
										}		
									  else{ 	
										$name = "name='add'";	
										$onclick = "onClick=\"return product()\"";			
										}	
										?>
									<tr>		
										<td colspan="2" > <input type="submit" <?php echo $name;?>  value="Submit"></td>		
									</tr>		
								</table>
								</form>
							</td>			
						</tr>		
					</table>
					</center>
				</td>
			<tr>

          </tr>

          <tr>

            <td>&nbsp;</td>

          </tr>



          <tr>

            <td><? require_once("footer.php"); ?></td>

          </tr>

          <tr>

            <td height="200">&nbsp; </td>

          </tr>

        </table></td>

      </tr>

    </table></td>

  </tr>

</table>

</body>

</html>

