<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";
	 
	$act  = $_REQUEST['act'];
	$id_diamonds  = $_REQUEST['id_diamonds'];
	$price  = $_REQUEST['price'];
	$fetch = mysql_fetch_array(mysql_query("select * from  tbl_diamonds where id_diamonds = '$id_diamonds'"));
	$diamonds = $fetch['diamonds'];
	$keterangan = $fetch['keterangan'];
	$pricebefore = $fetch['price'];
	
	if($act == 1)
	{
		$id_diamonds  = $_REQUEST['id_diamonds'];
		$price = str_replace(",","", $_REQUEST['price']);
		if($price ==  "")
		{
		?>
				<script language="javascript">
                alert("Input Price");
                document.location="edit_diamonds.php?id_diamonds=<?php echo $id_diamonds; ?>";
                </script>
		<?php	
		}
		else
		{
			$insert = mysql_query("update tbl_diamonds set price = '$price',user_update = '$USERNAME' where id_diamonds='$id_diamonds'");
			$insert2 = mysql_query("INSERT into log_diamonds (diamonds,keterangan,price,price_before,user_update,date_update) values ('$diamonds','$keterangan','$price','$pricebefore','$USERNAME','$tanggal_update')");
			if($insert & $insert2)
			{
				?>
				<script language="javascript">
                alert("Edit Diamonds Categorization in Types Success");
                document.location="master_diamonds.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Edit Diamonds Categorization in Types Failed");
                document.location="edit_diamonds.php?id_diamonds=<?php echo $id_diamonds; ?>";
                </script>
				<?php	
			}
		}
	}
	?>
<script language="javascript">
function intFormat(n)
{
var
regex = /(\d)((\d{3},?)+)$/;

n = n.split(',').join('');

while(regex.test(n))
{
n = n.replace(regex, '$1,$2');
}

return n;
}

function numFormat(n)
{
var
pointReg = /([\d,\.]*)\.(\d*)$/, f;

if(pointReg.test(n))
{
f = RegExp.$2;
return intFormat(RegExp.$1) + '.' + f;
}
return intFormat(n);
}
</script>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-th"></i> Edit Diamonds Categorization in Types</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="edit_diamonds.php?act=1&id_diamonds=<?php echo $id_diamonds; ?>" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Diamonds</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="diamonds" id="diamonds" value="<?php echo $diamonds; ?>"  readonly="readonly">
                          </div>
                        </div>
                      <div class="form-group">
                          <label class="col-md-4 control-label">Keterangan</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="keterangan" id="keterangan" value="<?php echo $keterangan; ?>" readonly >
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Price</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control"  name="price" id="price" value="<?php  echo number_format($pricebefore, 0, ',', ','); ?>"  onKeyUp="this.value = numFormat(this.value)">
                          </div>
                        </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>