<?php session_start(); ?> <!-- session start -->
<?php include("../include/config.php"); ?> <!-- database connection -->
<?php include("../include/connect_url.php"); ?> <!-- connection url/link folder -->
<?php include("../include/date_time.php"); ?> <!-- date & time format -->
<?php include("../database/account.php"); ?> <!-- query database account -->
<?php include("../include/lang.php"); ?> <!-- language -->
<?php include("../include/session_login.php"); ?> <!-- session login -->

<!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=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php include("../template/title.php"); ?></title>

<link rel="shortcut icon" href="<?php echo $connect_url_data; ?>/favicon.ico" />

<link href="<?php echo $connect_url_data; ?>/css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="<?php echo $connect_url_data; ?>/css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->
<link rel="stylesheet" href="<?php echo $connect_url_data; ?>/font/font-awesome-4.3.0/css/font-awesome.min.css">

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery183.js"></script> 
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery192.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.autosize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.select2.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.culture.de-DE.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.culture.ja-JP.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.mousewheel.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/files/bootstrap.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/files/functions.js"></script>

</head>

<body>

<?php    
$query_item2 = mysql_query("SELECT * FROM tbl_item WHERE id='$_GET[item_id]'"); 
while($row= mysql_fetch_assoc($query_item2))
{
    $db_item2_id = $row['id'];
    $db_item2_item_no = $row['item_no'];
    $db_item2_barcode = $row['barcode'];
    $db_item2_item = $row['item'];
    $db_item2_description = $row['description'];
    $db_item2_item_category_id = $row['item_category_id'];
    $db_item2_user_id= $row['user_id'];
    $db_item2_date = $row['date'];
    $db_item2_time = $row['time'];
    $db_item2_a_status = $row['a_status'];
}
?>

<?php
$query_item_category2 = mysql_query("SELECT * FROM tbl_item_category WHERE id='$db_item2_item_category_id'");
while($row= mysql_fetch_assoc($query_item_category2))
{
    $db_item_category2_id = $row['id'];
    $db_item_category2_item_category = $row['item_category'];
}
?>

<?php
$query_item_price2 = mysql_query("SELECT * FROM tbl_item_price WHERE item_id='$db_item2_id' AND a_status=1");
while($row= mysql_fetch_assoc($query_item_price2))
{
    $db_item_price2_id = $row['id'];
    $db_item_price2_price = $row['price'];
}
?>


<?php

if($_POST)
{

$barcode =mysql_real_escape_string($_POST['barcode']); 
$item =mysql_real_escape_string(ucwords($_POST['item']));
$description =mysql_real_escape_string($_POST['description']);
$item_category =$_POST['item_category'];


//number format
include("../include/number_format.php");

$a_status = $_POST['a_status'];

if($item==""){
die ("<script> alert('Please fill item.');
window.location.href='javascript:history.back();';		
</script> ");
}

//item
$sql = "UPDATE tbl_item SET  barcode='$barcode' ,item='$item', description='$description', item_category_id = '$item_category', a_status='$a_status' WHERE  id ='$db_item2_id '";
$result = mysql_query($sql) or die("Error: Failed to Update!");

//price
if($price_nf==$db_item_price2_price)
{}else{
$sql = "UPDATE tbl_item_price SET  a_status='2' WHERE item_id ='$db_item2_id ' AND a_status='1'";
$result = mysql_query($sql) or die("Error: Failed to Update!");  
    
$query_insert = mysql_query("
  INSERT INTO tbl_item_price VALUES ('','$db_item2_id','$price_nf','$db_user_id','$date','$time','1');
");
}





die ("<script> alert('Saved.');
window.close();		
</script> ");
}


if($_GET['type']=="detele"&&$_GET['item_bed_id']){
$sql = "UPDATE tbl_item_bed SET  a_status='2' WHERE id ='$_GET[item_bed_id]' AND a_status='1'";
$result = mysql_query($sql) or die("Error: Failed to Update!");      
    
die ("<script> alert('Deleted.');
window.location.href='$connect_url_data/item/e/$db_item2_id';		
</script> ");   
}
?>

<form name="form" id="form" action="<?php echo $connect_url_data; ?>/item/e/<?php echo $db_item2_id; ?>" class="main" method="POST"  enctype="multipart/form-data">
            <fieldset style="margin-top:-35px;">
                <div class="widget fluid">
                    <div class="whead"><h6><span class="fa fa-edit" style="margin-top:-2px;"></span>&nbsp; <?php echo $lang['Edit Item']; ?></h6></div>
                    
		    <!-- Tabs -->
		<div class="fluid" >
                <div class="widget grid12" style="margin-top:-0px;">       
                    <div class="tabs">
                        <ul>
                            <li><a href="#tabs-1"><?php echo $lang['Item Information']; ?></a></li>
                            <li><a href="#tabs-2"><?php echo $lang['Price']; ?></a></li>
                        </ul>
			
			
			
                <div id="tabs-1">
                    
                    <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Barcode']; ?>:</label></div>
                        <div class="grid10"><input type="text" name="barcode" id="barcode" value="<?php echo $db_item2_barcode; ?>"/></div>
                    </div>
		    
		    <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Item']; ?>:</label></div>
                        <div class="grid10"><input type="text" name="item" id="item" value="<?php echo $db_item2_item; ?>"/></div>
                    </div>
                    
                       <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Description']; ?>:</label></div>
                        <div class="grid10">
                            <textarea rows="8" cols="" name="description" id="description" class="auto lim"><?php echo $db_item2_description; ?></textarea>
                            <span class="note" id="limitingtext">Field limited to 100 characters.</span>
                        </div>
                    </div>
		    
		     <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Category']; ?>:</label></div>
                            <div class="grid10">
                               <?php
				$query_item_category1=mysql_query("SELECT * FROM tbl_item_category WHERE id!='$db_item_category2_id' ORDER BY item_category ASC");
				$option_item_category1="";
				while($row=mysql_fetch_array($query_item_category1)) {
				$option_item_category1 .= "<option value='$row[id]'";
				$option_item_category1 .= ">". $row['item_category'] ."</option>";  }
				?>    
				<select name="item_category" id="item_category"  data-placeholder="Choose" class="select" tabindex="2" style="width:100%;">
                                <?php if($db_item2_item_category_id!=0){echo "<option value='$db_item2_item_category_id'>$db_item_category2_item_category</option>"; }else{echo"<option value=''></option> ";}?>
				<?php echo $option_item_category1; ?>
				</select>
                            </div>             
                    </div>
		    
		    <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Status']; ?>:</label></div>
                            <div class="grid10">
                               <select name="a_status" id="a_status" class="select" tabindex="2" style="width:100%;">
				<?php
				if($db_item2_a_status==1){
				echo "
				<option value='1' SELECTED>Active</option>
				<option value='2'>Inactive</option>
				";
				}
				if($db_item2_a_status==2){
				echo "
				<option value='2' SELECTED>Inactive</option>
				<option value='1'>Active</option>
				";
				}							
				
				?>
				</select>
                            </div>             
                    </div>
		    
		
		    
	     </div>
	    <!-- end tabs 1 -->
	    
	    <div id="tabs-2">
                
                    <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Price']; ?>:</label></div>
                        <div class="grid10"><input type="text" name="price" id="price" value="<?php echo $db_item_price2_price; ?>"/></div>
                    </div>    
            </div>
	
	    
</div>
</div>	    
<!-- end tabs body -->
                  
                </div>
            </fieldset>
	    
    <div class="formRow">
                    <div class="grid2"></div>
                    <div class="grid10">
<a href="#" class="buttonM bBlue" onclick="document.getElementById('form').submit();"><span class="fa fa-save"></span><span><?php echo $lang['Save']; ?></span></a>
		        <a href="#" class="buttonM bBlue" onclick="window.close();"><span class="fa fa-times-circle"></span><span><?php echo $lang['Cancel']; ?></span></a>
		    </div>
		    
		    </div>
             
</body>
</html>
