<head>
    <script>
    if ( window.history.replaceState ) 
    {
      window.history.replaceState( null, null, window.location.href );
    }
    </script>  
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>WIP | Control System</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="img/lgo1.png">
    <!--Sweetalert Plugin --->
    <script src="bower_components/sweetalert/sweetalert.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.min.js"></script>
    <!-- jQuery 3 -->
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- bootstrap timepicker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

    <!-- DataTables -->
    <link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
    <!-- datepicker js -->
    <script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap datepicker -->
    <script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <script src="dist/js/date_time.js"></script>     
    <!-- chart Js -->
    <script src="chartjs/dist/Chart.min.js"></script>
    <script src="bower_components/sweetalert/sweetalert.js"></script>
    
    <style>
        .container1 
        {
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<?php
    include_once'db/connect_db.php';
    if($id=$_GET['id'])
    {
        // $id=$_GET['id'];
        $select = $pdo2->prepare("SELECT obj,l1,l2,c1,c2,c3,lid FROM setting WHERE lid=$id");
        $select->execute();
        $row = $select->fetch(PDO::FETCH_ASSOC);
         
        $obj=$row['obj'];
        $l1=$row['l1'];
        $l2=$row['l2'];
             
        $col1=$row['c1'];
        $col2=$row['c2'];
        $col3=$row['c3'];
    }      
    if(isset($_POST['sv']))
    {   //1
        // $id2=$_GET['id'];
             
        $obn =$_POST['myob'];
        $l13 = $_POST['l11'];
        $l23 = $_POST['l22'];
        
        $c13 = $_POST['c11'];
        $c23 = $_POST['c12'];
        $c34 = $_POST['c13'];

        //  $insert = $pdo2->prepare("UPDATE setting SET obj='$obj' WHERE lid='".$_GET['id']."'");
        //$insert = $pdo2->prepare("UPDATE setting SET obj='$obn',l1='$l13',l2='$l23',c1='$c13',c2='$c23',c3='$c34' WHERE lid='".$_GET['id']."'");
        $insert = $pdo2->prepare("UPDATE setting SET obj='".$_POST['myob']."',l1='".$_POST['l11']."',l2='".$_POST['l22']."',c1='".$_POST['c11']."',c2='".$_POST['c12']."',c3='".$_POST['c13']."' WHERE lid='".$_GET['id']."'");
 
	//      $insert->bindParam(':obj',$obn);".$_GET['id']."
        // $insert = $pdo2->prepare("UPDATE setting SET obj='$obn' WHERE lid='1'");
        //obj,val,l1,l2,m1,m2,h1,c1,c2,c3,lid
              
        //$insert->bindParam(':obj',$obn);
        //$insert->bindParam(':l1', $l13);
        //$insert->bindParam(':l2',$l23);
                         
        //$insert->bindParam(':c1', $c13);
        //$insert->bindParam(':c2',$c23);
        //$insert->bindParam(':c3', $c34);
        $insert->execute();
        header('location:setting.php');
    }
    
    function Loadcolour1($id,$clr)
    {
        include('db/connect_db.php');      
        $select2 = $pdo2->prepare("SELECT c1,c2,c3,lid FROM setting where lid='$id'");    
        //   . "SELECT formid,userid FROM formaccess WHERE formid='$frmid' and userid='$userid'");
        $select2->execute();
        $row = $select2->fetch(PDO::FETCH_ASSOC);
        
        if($select2->rowCount() > 0 )
        {
            $sr11 = $row[$clr];
        }
        else
        {
            $sr11="";
        }
        return $sr11;
   }  
?>
<!-- Content Wrapper. Contains page content -->
<!-- Main content -->
    
<section class="content container-fluid" >
    <header class="main-header"  style="background-color: #f1f1f1;">
        <nav class="navbar navbar-static-top ">
            <div class="row">
                <!-- ./col --------------------------------------------------------------------------------------------->        
                <div class="col-lg-1container1 col-xs-1">
                    <img src="img/lgo1.png" class="user-image" alt="User Image" width="50" hight="50">
                </div>
                <div class="col-lg-6 col-xs-6">
                    <p> <h3>Wip Control System </h3> </p>
                </div>
                <div class="col-lg-4 col-xs-4">
                    <a><h3>
                        <b><span id="date_time" class="pull-right"></span></b>
                        <script type="text/javascript">window.onload = date_time('date_time');</script>
                        </h3>
                    </a>            
                    <!-- Tasks Menu -->
	            <!-- Tasks Menu -->
	        </div>
            </div>
            <!-- Navbar Right Menu -->
        </nav>
    </header>
    <br>
    <form action="" method="POST">
        <div class="col-md-7">
            <div class="box">
                <div class="box-header with-border">
                    <h2 class="box-title"><b>Setting</b></h2>
                </div>
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>Line Name </label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <input type="text" class="form-control" id ="myob" name="myob"  style="width:390px; height:30px;" value="<?php echo $obj; ?>" >               
                        </div>
                    </div>
                    <br>
                </div>                
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>Upper Limit</label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <input type="number" class="form-control" name="l11"  style="width:150px; height:30px;" value="<?php echo $l1; ?>"  >               
                        </div>
                    </div>
                    <br>
                </div>
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>Lower Limit</label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <input type="number" class="form-control" name="l22"  style="width:150px; height:30px;" value="<?php echo $l2; ?>" >               
                        </div>
                    </div>
                    <br>
                </div>        
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>Upper Limit Colour </label>
                        </div>
                    </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <input type="color" id="color" name="c11" value="<?php echo $col1; ?>"  style="width:150px; height:30px;">
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                    </div>
                </div> 
                <br>
            </div> 

            <div class="row">
                <div class="col-md-3">
                    <div class="form-group">
                        <label>Middle Level Colour</label>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <input type="color" id="color2" name="c12" value="<?php echo $col2; ?>"  style="width:150px; height:30px;">        
                    </div>
                </div>
                <br>
            </div>   
            <div class="row">
                <div class="col-md-3">
                    <div class="form-group">
                        <label>Lower Limit Colour</label>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <input type="color" id="c13" name="c13" value="<?php echo $col3; ?>"  style="width:150px; height:30px;">              
                    </div>
                </div>
                <br>
            </div>  
            <div class="box-footer">
                <button type="submit" class="btn btn-primary" id="sv" name="sv">Edit</button>&nbsp;&nbsp;
                <a href="setting.php" class="btn btn-warning">Back</a>
            </div>
        </div>
    </div>
</form>  
            
</section>
<!-- /.content -->
<!-- /.content-wrapper -->

<script>
    $(document).ready( function () 
    {
        $('#myRegister').DataTable();
    });
</script>

