<?php


session_start();
if($_SESSION['dbName']==""){
    header("location:../index.php");
}
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);

include("config.inc.php");
include("function.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$querylog="SELECT FI_SellingPriceAdjust as loginaccess, username as UserName from ".$_SESSION['dbLabel'].".ListUserDir where Usercode='".$_SESSION['useraccount']."' 	and Upper(concat(CompanyName,'_',Diryear)) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
	
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
 


$group_code 		= $_POST['group_code'];
$subgroup_code 		= $_POST['subgroup_code'];
$category_code 		= $_POST['category_code'];
$AdjustDays 		= $_POST['AdjustDays'];
$AdjustCoef 		= $_POST['AdjustCoef'];
$itemloaded 		= $_POST['itemloaded'];  


if (($itemloaded == 1 ) && $mode == 'changeQtys'){


	
	for($i=0;$i<count($item_code);$i++){
		// echo $sql = "$i -- update items set item_minqty = ".$item_Nminqty[$i].", item_maxqty = ".$item_Nmaxqty[$i]." where item_code = '".$item_code[$i]."' ";
		// echo"<HR>";
		echo $sql = "update items set item_minqty = ".$item_Nminqty[$i].", item_maxqty = ".$item_Nmaxqty[$i]." where item_code = '".$item_code[$i]."' ";
		$result = mysql_query($sql,$connection);

	}
	 
	
	$message = "Selling Price Updated Successfully! ";
  	exit;
}

print <<<HERE
	<form name='sellingprice' method='POST' action='Form_itemsAdjust.php'>
		<input type='hidden' name='message' id='message' value='$message'> 
		<input type='hidden' name='group_code' id='group_code' value='$group_code'>
		<input type='hidden' name='subgroup_code' id='subgroup_code' value='$subgroup_code'>
		<input type='hidden' name='category_code' id='category_code' value='$category_code'>
		<input type='hidden' name='AdjustDays' id='AdjustDays' value='$AdjustDays'>
		<input type='hidden' name='AdjustCoef' id='AdjustCoef' value='$AdjustCoef'>
	</form>
	<script>
		document.sellingprice.submit();
	</script>

HERE;
?>