<? 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);

			  

// delete record
	$delId = (int)isset($_POST["delId"])?$_POST["delId"]:0;	
	$delRqst = !empty($delId)?TRUE:FALSE;
	
	if($delRqst) {
		foreach ($_REQUEST["del"] as $a_id) {	
		
			if(is_numeric($a_id) && $a_id > 0 ){	

				$where = " id = {$a_id} ";
				$sql = mysql_query("delete from quantity_master where id = ".$a_id);
			}
				
		}
		header("location:quantity_listing.php?prid=".$prid."&dmsg");
				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>
<script type="text/javascript">
	function confirmdeleteproduct(){
	var f=0;
	var len=document.form1.length;
	for(i=1;i<len;i++){
		if(document.form1.elements[i].checked==true){
			f=1;
			break;
		}
		else{	
			f=0;
		}
	}
	if(f==0){
		alert("Atleast select one record to be deleted..!");
		return false;
	}
	else{
		var temp=confirm("Do you really want to delete...!");
			if(temp==false)	{
				return false;
			}
			else{
				document.getElementById("delId").value="del";
				document.form1.submit();
			}
	}
}

function selectall()
{
	
	if(document.form1.delall.checked==true)
	{
		var chks = document.getElementsByName('del[]');
		
		for(i=0;i<chks.length;i++)
		{
			chks[i].checked=true;
		}
	}
	else if(document.form1.delall.checked==false)
	{
		var chks = document.getElementsByName('del[]');
		
		for(i=0;i<chks.length;i++)
		{
			chks[i].checked=false;
		}
	}
}
</script>


</head>

<body>
<center>
<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>
					<table align="center" >
						<tr>
							<td><b>Quantity Listing</b> <span style="float:right;"><a href="quantity_process.php?prid=<?php echo $prid;?>"><input type="button" value="Add quantity"></a></span></td>			
						</tr>			
						<tr>
							<td>
								<form name="form1" method="post">
								<table>
									<?php
										$msg = "";			
											if(isset($_GET["dmsg"])) 
												$msg = "Your record is successfully deleted";
											if(isset($_GET["smsg"]))  
												$msg = "Your record is successfully updated";
											if(isset($_GET["msg"]))  	
												$msg = "Your record is successfully inserted";		
										?>
											
										<tr>
											<td colspan="2" style="color:red;text-align:center;"><?php echo $msg;?></td>
										</tr>
									
									<tr >
								<td>
										
									<table   style="border-collapse: collapse;" border="1" cellspacing="2"  cellpadding="3" rules="all" width="500"> 
										<input type="hidden" name="delId" id = "delId" value="" />	
										<tbody>
											<tr class="repeat arial-b">
												<td width="10%" align="center" style="padding:4px;"><input name="delall" onClick="selectall()" type="checkbox" /></td>
												<td width="50%"><b>Quantity</b></td>
												<td width="40%"><b>Action</b></td>
												
											</tr>
											<?php 
												$Query= "select * from quantity_master where prid=".$prid."   order by id";
		
												$result = mysql_query($Query);
												$totRows = mysql_num_rows($result);
												if($totRows > 0){
												$srnum=$totCount;
													while($rs = mysql_fetch_assoc($result)){
														$id = $rs["id"];
														$quantity = $rs["quantity"];
														
														$srnum++;
														if (($srnum % 2) == 0)
															$bgcolor = "class='first'";
														else
															$bgcolor = "";
													
											?>	
											<tr  <? echo $bgcolor;?>>
												<td  align="center" style="padding:5px;"><input value=<? echo $id; ?> name="del[]" type="checkbox">																	</td>
												<td><? echo stripslashes($quantity); ?></td>
												<td class="black_text"><a href="quantity_process.php?prid=<?php echo $prid;?>&id=<? echo $id; ?>">Modify</a></td>
											</tr>
											
											<?php
													}
												?>
												<tr>
													<td colspan="3"><input name="delete" id="delet" Value="delete" type="button" onClick="return confirmdeleteproduct();" > <a href="quantity_process.php?prid=<?php echo $prid;?>"><input type="button" value="Add quantity"></a></td>
													
												</tr>
												<?php	
												}// End of If Loop
												else{
												?>
												<tr>
													<td align="center" valign="middle" class="red11" height="20" colspan="10">No Quantity Available </td>
												</tr>
												<?php
												 }
												?>  
										</tbody>
									</table>
									
								</td>
							</tr>
								</table>
								</form>
							</td>			
						</tr>		
					</table>
				</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>
</center>
</body>

</html>

