<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Guru Commodity User Login</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
<script>
var socket=io.connect("http://localhost:4000");
$(document).ready(function(){
	socket.on("tr_emit",function(data){
		console.log(data.trid);
		$("tr#"+data.trid).html(data.trdata);
		$("tr#"+data.trid+" td:nth-child(2)").css("background-color",data.color);
		setTimeout(function(){ $("tr#"+data.trid+" td:nth-child(2)").css("background","none"); }, 2000);
	});
	socket.on("tr_emit_user",function(data){
		console.log(data.trid);
		$("tr#"+data.trid).html(data.tr);
//		$("tr#"+data.trid+" td:nth-child(2)").css("background-color",data.color);
//		setTimeout(function(){ $("tr#"+data.trid+" td:nth-child(2)").css("background","none"); }, 2000);
	});
	setInterval(function(){
				var cur_rate_class=$("#cur_rate").attr("class");
				//console.log(cur_rate_class);
				//$(".GOLD_ticker").text($("tr#GOLD td:nth-child(2)").text());
				if(cur_rate_class!=""){
				var v=$("tr#"+cur_rate_class+" td:nth-child(2)").text();
				}
				$("#cur_rate").val(v);
				}, 1000);
	$("#metal_select").change(function(){
				var vall=$(this).val();
				var t=vall.split("-");
				$("#cur_rate").attr("class",t[0]);
			//	$("#limit").attr("class",t[0]+"_ticker form-control");
			});
			$("#marketprice").click(function(){
				if ($('input[type="checkbox"]').is(':checked')){
					$("#limit").attr('disabled',true);
				}else{
					$("#limit").removeAttr('disabled');
				}
				//
			});
});
</script>
<body style="font-family: 'Josefin Sans', sans-serif;">

	<div class="container">
    	<div class="row">
        	<div class="col-md-6">
            <table id="fullMcxPriceTable" class="table table-condensed table-bordered table-striped">
            <tr><th>Commodity</th><th>Price</th><th>Chg</th><th>%Chg</th><th>Open</th><th>High</th><th>Low</th><th>Time</th></tr>
				<?php $metals=$this->db->get("metals")->result();
					foreach($metals as $d){?>
                <tr id="<?php echo $d->metal;?>" class="metals_tr">
                	<td><?php echo $d->metal;?></td>
                    <td></td>
               		<td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td></tr>
                <?php }?>
            </table>
            </div>
        	<div class="col-md-6">
            <h2 class="text-success">Start Trading
            <?php if($this->session->userdata("user")){?>
                     <div class="dropdown pull-right">
                      <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Hi, <?php echo $this->session->userdata("name");?>
                      <span class="caret"></span></button>
                      <ul class="dropdown-menu">
                        <li><a href="<?php echo base_url();?>home/logout"> <i class="fa fa-sign-out"></i> Logout</a></li>
                      </ul>
                    </div> 
                    <?php }?>
            </h2>
            <form id="test_trade_form" action="<?php echo base_url();?>home/buynow" method="post" style="background:#FBFBFB; border:5px solid antiquewhite; padding:10px;">
                        <div class="row">
                        <div class="form-group col-md-4">
                        	<label>TYPE</label><br/>
                        	<label>
                              <input type="radio" name="type" value="BUY" checked> BUY
                            </label>
                            <label>
                              <input type="radio" name="type" value="SELL"> SELL
                            </label>
                        </div>
                    	<div class="form-group col-md-4">
                        	<label>Asset</label>
                            <select name="metal" class="form-control" required id="metal_select">
                            	<option value="">Select Asset</option>
                                <option value="GOLD-100">GOLD</option>
                                <option value="GOLDM-10">GOLDM</option>
                                <option value="SILVER-30">SILVER</option>
                                <option value="SILVERM-5">SILVERM</option>
                                <option value="COPPER-1000">COPPER</option>
                                <option value="COPPERM-250">COPPERM</option>
                                <option value="ALUMINIUM-5000">ALUMINIUM</option>
                                <option value="ALUMINI-1000">ALUMINI</option>
                                <option value="CRUDEOIL-100">CRUDEOIL</option>
                                <option value="CRUDEOILM-10">CRUDEOILM</option>
                                <option value="ZINC-5000">ZINC</option>
                                <option value="ZINCMINI-1000">ZINCMINI</option>
                                <option value="LEAD-5000">LEAD</option>
                                <option value="LEADMINI-1000">LEADMINI</option>
                                <option value="NICKEL-250">NICKEL</option>
                                <option value="NICKELM-100">NICKELM</option>
                                <option value="NATURALGAS-1200">NATURALGAS</option>
                            </select>
                            <input type="hidden" name="cur_rate" id="cur_rate" value="" class="" />
                        </div>
                        <div class="form-group col-md-4">
                        	<label>Lot Size</label>
                            <input type="number" name="lotsize" required class="form-control" />
                        </div>
                        <div class="form-group col-md-4">
                        	<label>Limit</label>
       <label class="pull-right"><input id="marketprice" type="checkbox" name="marketprice" value="marketprice" /> Market Rate</label>
                            <input type="text" name="setlimit" id="limit"  required class="form-control" />
                        </div>
                        <div class="form-group col-md-4">
                        	<label>Set Target</label>
                            <input type="text" name="target" class="form-control" />
                        </div>
                        <div class="form-group col-md-4">
                        	<label>Set StopLoss</label>
                            <input type="text" name="stoploss" class="form-control" />
                        </div>
                         
                        </div>
                        <button type="submit" class="btn btn-warning buybtn">Submit</button>
                    </form>
        <table class="table table-bordered table-condensed table-striped">
			<thead>
  <tr><th>S.No.</th><th>Metal</th><th>TradeType</th><th>Live</th><th>Limit</th><th>Target</th><th>Stoploss</th><th>Profit/Loss</th><th>Time</th></tr></thead>
            <tbody id="live_trades">
            <?php $trades=$this->db->get_where("buysell",array("status!="=>"EXIT","uid"=>$this->session->userdata("user")))->result();	
			 $i=1;foreach($trades as $tr){?>
            <tr id="<?php echo $tr->bsid;?>"><td><?php echo $tr->bsid;?></td></tr>
            <?php }?>
            </tbody>
        </table>
            </div>
        </div>
    </div>

</body>
</html>
