<!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>
 <?php
  $this->load->view('user/common_style');
  $this->load->view('user/header');
 ?>
</head>
<style type="text/css">
.table-responsive {
    min-height: .01%;
    overflow-x: scroll;
    scrollbar-width:thin;
}

.dataTables_filter > label
{
  display: block;
  color: rgb(239, 239, 239);
}

.dataTables_filter label > input[type=search]::after {
    font-family: 'FontAwesome';
    /*color:red;*/
    position: relative;
    left: -5px;
    content: "\f007";
    height:45px !important;
}
.err
{
  color:red;
  font-size:13px;
}

.table-responsive
{
  overflow-y:hidden;
}

.other-title
{
  font-weight:400 !important;
  font-size: 14px !important;
}
.cl
{
  font-size:13px;
  font-weight:bold;
}

</style>
<body>
<?php

// $this->load->view('user/login_header');
$data=$_SERVER['QUERY_STRING'];
$exchange=explode("_",$data);
//$ex1=$exchange[0];
//$ex2=$exchange[1];
$ex1=str_replace("&&","*",$exchange[0]);
$ex2=str_replace("&&","*",$exchange[1]);
$first_dat=$this->db->query("select * from coin_info where coin_symbol='".$ex1."'");
$fir_d=$first_dat->result();
$sec_dat=$this->db->query("select * from coin_info where coin_symbol='".$ex2."'");
$sec_d=$sec_dat->result();
$ex1_fee=$fir_d[0]->trade_fees;
$ex2_fee=$sec_d[0]->trade_fees;
$this->session->set_userdata('sec_id',$sec_d[0]->coid);
$this->session->set_userdata('fir_id',$fir_d[0]->coid);
$select_f=$this->db->query("select * from currency_upgrade where cid='".$sec_d[0]->coid."'");
$f_data=$select_f->result();
$values=$f_data[0]->datas;
$values=json_decode($values);
$outputx = json_decode(json_encode($values), True);
$perc=$outputx['cap24hrChange'];

$supply=$outputx['supply'];
$volume=$outputx['volume'];
$market=$outputx['market_cap'];


$select_t=$this->db->query("select * from currency_upgrade where cid='".$fir_d[0]->coid."'");
$f_data1=$select_t->result();
$values1=$f_data1[0]->datas;
$values1=json_decode($values1);
$outputx1 = json_decode(json_encode($values1), True);
$perc1=$outputx1['cap24hrChange'];
$changeval=$perc1-$perc;

$find_data=$this->db->query("select * from currency_market where market_id='".$sec_d[0]->coid."' and curid='".$fir_d[0]->coid."' order by date desc limit 1");
$value_data=$find_data->result();
$value_find=$value_data[0]->price;
$volume=$value_data[0]->volume;
if($value_find!='')
{
  $price_det=str_replace("[",'',$value_find);
  $price_det=str_replace("]",'',$price_det);
  $cnt_det=explode(",",$price_det);
  $price1=$value_data[0]->price_usd;
  $price=$cnt_det[4];
  $open=$cnt_det[1];
  $min=$cnt_det[3];
  $max=$cnt_det[2];
}
if($open=='')
  $open='--';

if($price=='')
    $price='--';

if($volume=='')
    $volume='--';

if($market=='')
    $market='--';

$change_flag=0;
if($changeval!='--' && $changeval!='')
{

    if($changeval > 0)
    {
      $change_flag=1;
      $changeval="<span style='color:black;'>".$changeval."</span> <i class='fa fa-arrow-up' style='color:green;'></i>";
    }
    else
    {
      $changeval="<span style='color:red;'>".$changeval."</span> <i class='fa fa-arrow-down' style='color:red;'></i>";
    }
}
else
  $changeval='--';

//$url1 ="https://api.cryptonator.com/api/ticker/".$fir_d[0]->coin_symbol."-".$sec_d[0]->coin_symbol;

// echo $url1;
// exit();

$url = "https://min-api.cryptocompare.com/data/price?fsym=".$fir_d[0]->coin_symbol."&tsyms=".$sec_d[0]->coin_symbol."&api_key=7559f7ec39d851bc927432e1bc09ffa6f4037d9b45cd73581c49b47f53349411";

//echo $url;

$linkdata=json_decode(file_get_contents($url),true);

// print_r($linkdata[$sec_d[0]->coin_symbol]);
// exit();


// $liveprice=$linkdata[ticker][price];

$cur_price= number_format($linkdata[$sec_d[0]->coin_symbol],11);





if ($volume > 999 && $volume <= 999999) {
    $result = floor($volume / 1000) . ' K';
} elseif ($volume > 999999) {
    $result = floor($volume / 1000000) . ' M';
} else {
    $result = $volume;
}





if($change_flag==1)
{
  $clr="green";
}
else
  $clr="purple";



function amt_check($curr)
{

  /*$datas1=file_get_contents("https://min-api.cryptocompare.com/data/price?fsym=".$curr."&tsyms=BTC");
  $output1=json_decode($datas1);
  $output1=json_decode(json_encode($output1),True);
  $data1=$output1['BTC'];
  $data1=number_format($data1,6);*/
  $data1=0;
  return $data1;

}
?>
<div class="page-container page-section-1-ptb no-gutter">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-12 col-lg-2">
        <div class="crypro-title mb-6">
          <h4 class="theme-color m-0"><?php echo $ex1;?> <small class="text-gray1">/ <?php echo $ex2;?> </small></h4>
        </div>
      </div>
      <div class="col-md-12 col-lg-10" >
      <?php if($this->session->flashdata('success_message')) {?>
      <p class="frgtpwd frgtpwd1"><i class="fa fa-thumbs-up"></i><?php echo $this->session->flashdata('success_message');?></p>
      <?php } elseif ($this->session->flashdata('error_message')) { ?>
       <p class="frgtpwd frgtpwd1 frgtpwdred"><i class="fa fa-thumbs-down"></i><?php echo $this->session->flashdata('error_message');?></p>
      <?php } else { }?>

            <div class="crypro-info  mb-10" id="price_vol" style="border:none;">
          <ul>
            <li>
              <?php 
              $price_disp=$price;
              ?>
              <label>Last Price: </label>
              <span class="<?php echo $clr;?>"><?php echo $price;?><small class="grey">$<?php echo $price1;?></small></span> </li>
            <li>
              <label>24h Change : </label>
              <span class=""><?php echo $changeval;?> </span> </li>
            <li>
                <label>24h Open : </label>
                <span><?php echo $open;?> </span> </li>
             <li>
                <label>24h High : </label>
                <span> <?php echo $max;?> </span> </li>
              <li>
              <label>24h Low :</label>
              <span><?php echo $min;?> </span> 
              </li>
          </ul>
        </div>
    </div>
    </div>
    <div class="row">
      <div class="col-md-12 col-lg-3">
        <div class="atitle"><i class="fa fa-suitcase"></i> Balances</div>
        <hr><br>
      <div class="balance">
      <table class="tableBodyScroll" width="100%">
      <thead >
       <th width='40%'>Currency</th>
       <th width='60%' style="text-align:right;">Amount</th>
      </thead>
      </table>
      </div>
      <div class="balance slim-scroll" id="slim">
      <table class="tableBodyScroll" width="100%">
       <tbody>
        <?php 
        $total_btc=0;
        $find_coin=$this->db->query("select * from coin_info where status='1'")->result();
        if($find_coin)
        {
          foreach ($find_coin as $coins) 
          {
             $coid=$coins->coid;
             $buy_bal=curbalance($this->session->userdata('uusersid'),$coid);
             $buy_bal1=str_replace(",","", $buy_bal);
             $order_bal=order($this->session->userdata('uusersid'),$coid);
             $order_bal1=str_replace(",","",$order_bal);
             $total=$buy_bal1+$order_bal1;

             if(strtoupper($coins->coin_symbol)=='BTC')
                $total_btc+=$buy_bal;
            else
            {
              if($buy_bal>0)
              {
                $check_amount=amt_check(strtoupper($coins->coin_symbol));
                $total_btc+=$check_amount*$buy_bal1;
              }

            }

         ?>
            <tr>
              <td width='40%'><?php echo ucwords($coins->coin_symbol);?></td>
              <!--<td width='60%'><?php echo number_format($buy_bal,$coins->coin_decimal);?></td>-->
              <td width='60%'><?php echo $buy_bal;?></td>
            </tr>
        <?php 
          }
      }
      ?>

    </tbody>
    </table>
    </div>
    <div style="clear:both;"><br></div>
    <div class="balance">
     <table class="tableBodyScroll" width="100%" >
       <tbody>
       <tr>
       <td style="background:none;font-weight:bold;">Est. BTC</td>
       <td style="background:none;"><?php echo number_format($total_btc,6);?> BTC</td>
       </tr>
       </tbody>
      </table>
    </div>
      <div style="clear:both;"><br></div>
       <div class="atitle"><i class="fa fa-cubes"></i> Market</div>
       <hr><br>
        <div class="tabbable-panel price-compare" id="list" style="width:95%;">
          <div class="tabbable-line">
            <ul class="nav nav-tabs">
            <?php
            $coins=$this->db->query("select * from coin_info where market_currency='1' and market_status='1' order by coid");
            $coin_det=$coins->result(); 
            if($coin_det)
            {
              $i=0;
              foreach($coin_det as $coin)
              {
                $i++;

                $f_curs=strtoupper($coin->coin_symbol);

                if($i=='1')
                {
                  if($f_curs==$ex2)
                    $class="active";
                  else
                    $class="";
              ?>
                <li class="<?php echo $class;?>"> <a href="#tab_default_<?php echo $i;?>" data-toggle="tab"> <?php echo strtoupper($coin->coin_symbol);?> </a> </li>
              <?php
              }
              else
              {
                if($f_curs==$ex2)
                    $class="active";
                  else
                    $class="";
              ?>
                <li class="<?php echo $class;?>"> <a href="#tab_default_<?php echo $i;?>" data-toggle="tab"> <?php echo strtoupper($coin->coin_symbol);?> </a> </li>

              <?php
              }
              
              }
            }
            ?>
            </ul>
            <div class="crypto-search position-re">
              </div>
            <div class="tab-content" id="list">
            <?php
            $coins=$this->db->query("select * from coin_info where market_currency='1' and market_status='1' order by coid Asc limit 4");
            $coin_det=$coins->result(); 
            if($coin_det)
            {
              $iz=0;
              foreach($coin_det as $coin)
              {
                  $iz++;
                  $first_dat=$this->db->query("select * from coin_info where coid='".$coin->coid."'");
                  $first_d=$first_dat->result();
                  $f_curs=strtoupper($first_d[0]->coin_symbol);
                  if($iz=='1')
                  {
                    if($f_curs==$ex2)
                       $class="tab-pane active";
                    else
                       $class="tab-pane";
                  }
                  else
                  {
                  
                    if($f_curs==$ex2)
                       $class="tab-pane active";
                    else
                     $class="tab-pane";
                }
              ?>
                  <div class="<?php echo $class;?>" id="tab_default_<?php echo $iz;?>">

                   <div class="table-responsive main-table" style="overflow-x:hidden;">
                  <table>
                    <thead class="body_tr">
                      <tr>
                        <th>Pair</th>
                        <th>last price</th>
                        <th>24h Change</th>
                      </tr>
                    </thead>
                     <tbody>
                    <?php
                    $market_data=$this->db->query("select * from currency_pair where mark_curr='".$coin->coid."'");
                    $mark=$market_data->result();
                    if($mark)
                    {
                      foreach($mark as $mark)
                      {
                        $open='--';
                        $high='--';
                        $low='--';
                        $changeval="--";
                        $sid=$mark->curid;
                        $first_curr=$this->db->query("select * from coin_info where coid='".$coin->coid."'");
                        $first=$first_curr->result();
                        $sec_curr=$this->db->query("select * from coin_info where coid='$sid'");
                        $sec=$sec_curr->result();
                        $f=strtoupper($first[0]->coin_symbol);
                        $s=strtoupper($sec[0]->coin_symbol); 


                        $select_f=$this->db->query("select * from currency_upgrade where cid='".$first[0]->coid."'");
                        $f_data=$select_f->result();
                        $values=$f_data[0]->datas;
                        $values=json_decode($values);
                        $outputx = json_decode(json_encode($values), True);
                        $perc=$outputx['cap24hrChange'];

                        $supply=$outputx['supply'];
                        $volume=$outputx['volume'];
                        $market=$outputx['market_cap'];


                        $select_t=$this->db->query("select * from currency_upgrade where cid='".$sec[0]->coid."'");
                        $f_data1=$select_t->result();
                        $values1=$f_data1[0]->datas;
                        $values1=json_decode($values1);
                        $outputx1 = json_decode(json_encode($values1), True);
                        $perc1=$outputx1['cap24hrChange'];
                        $changeval=$perc1-$perc;
                        
                        $data=$s.'_'.$f;
                        $data=str_replace("*", "&&", $data);
                        $find_data=$this->db->query("select * from currency_market where curid='$sid' and market_id='".$coin->coid."' order by date desc limit 1");
                        $value_data=$find_data->result();
                        $value_find=$value_data[0]->price;


                        if($value_find!='')
                        {
                          $price_det=str_replace("[",'',$value_find);
                          $price_det=str_replace("]",'',$price_det);
                          $cnt_det=explode(",",$price_det);
                          $price=$cnt_det[4];
                          $open=$cnt_det[1];
                          $low=$cnt_det[3];
                          $high=$cnt_det[2];
                        }

                        $price1=$value_data[0]->price_usd;

                        //$url1 ="https://api.cryptonator.com/api/ticker/".$first[0]->coin_symbol."-".$sec[0]->coin_symbol;

                        //$linkdata=json_decode(file_get_contents($url1),true);

                        //$price2=$linkdata[ticker][price];
                        //$changeval =$linkdata[ticker][change];


                         $flag=0;
                          if($changeval!='--' && $changeval!='')
                          {
                            if($changeval > 0)
                            {
                              $flag=1;
                              $changeval="<span style='color:green;'>".number_format($changeval,3)."%</span>";
                            }
                            else
                              $changeval="<span style='color:#ea0070;'>".number_format($changeval,3)."%</span>";
                          }
                          else
                            $changeval='--';

                            $prix=$price1;
                        
                          if ($s) {
                              
                          

                        ?>
                        <tr data-href='<?php echo base_url();?>trade?<?php echo $data;?>' class="body_tr">
                          <td><a href="<?php echo base_url();?>trade?<?php echo $data;?>"><?php echo $s;?></a></td>
                          <?php
                          if($flag=='1')
                            $cls="style='color:green;'";
                          else
                            $cls="style='color:#ea0070;'";
                          ?>
                          <td><a <?php echo $cls;?> href="<?php echo base_url();?>trade?<?php echo $data;?>"><?php echo number_format($prix,6);?></a></td>
                          <td><a href="<?php echo base_url();?>trade?<?php echo $data;?>"><?php echo $changeval;?></a></td>
                        </tr>
                       
                      <?php
                      
                          }

                      }
                    }
                    ?>
                    </tbody>
                </table>
              </div>
            </div>
             <?php
              }
          }
         ?>
            </div>
          </div>
        </div>
    </div>

      <div class="col-md-12 col-lg-6" style="padding:0px 5px 5px;">
        <div id="btc" class="mb-10" style="height:300px; min-width: 310px;background:#fff;">
          <div align="center">
            <div style="clear:both;height:50px;"><br></div>
            <span style="color:purple;">No Data's charts Found</span>
            </div>
        </div>
        
        <div class="two-block clearfix">
         
         <div class="col-md-12">
          <p class="frgtpwd frgtpwd1" id="scu" style="display:none;"><i class="fa fa-thumbs-up"></i>Trade Requested successfully</p>
         </div>
        
        <div class="col-md-6">
          <div class="order-block mb-10">
          <h6 class="other-title theme-color"> <i class="fa fa-plus-circle" style="font-weight:bold;"></i> Buy <?php echo $ex1;?> </h6>
          <?php
          
          //echo $sec_d[0]->coid;


          $buy_bal=curbalance($this->session->userdata('uusersid'),$sec_d[0]->coid);
          

          //echo $this->db->last_query();

          ?>
          <span class="clearfix">Your balance : <small class="green"><?php echo $buy_bal;?> <?php echo $ex2;?></small></span>
          <div style="clear:both;"><Br></div>
          
          <div class="tabbable-panel price-compare">
          <div class="tabbable-line">
            <ul class="nav nav-tabs">
                <li class="active"> <a href="#tab_default_limit" data-toggle="tab"> Limit </a> </li>
                <li class=""> <a href="#tab_default_market" data-toggle="tab"> Market </a> </li>
            </ul>
            <div class="tab-content" >
              <div class="tab-pane active" id="tab_default_limit">
               <form action="<?php echo base_url();?>addblimit" name="eltrades" id="eltrades" class="form-validate eltrade" method="post">
              <div class="order-block-inp">
                <input type="text" placeholder="Price <?php echo $ex2.'/'.$ex2;?>" name="price_e_lprice" style='text-align:right;' id="price_e_lprice" value="<?php echo $price_disp;?>" onkeypress="e_ltradekey();"/>
                <div class="err" id="lprice_err"></div>
                <input type="text" placeholder="Amount <?php echo $ex1;?>"  name="price_e_lamount" id="price_e_lamount" style='text-align:right;' onkeyup="e_ltradekey();" />
                <div class="err" id="lamt_err"></div>
                <input type="text" placeholder="Total <?php echo $ex2;?>" readonly="readonly" style='background:#ddd;text-align:right;'  name="price_e_ltotal" id="price_e_ltotal"  />

                <?php
                  $coin_mode=0;
                  $find_buy=$this->db->query("select * from site_controls where settings_name='user' and site_key='user_buyback'")->row();
                  if($find_buy->site_value=='on')
                  {
                    $coin_mode=$fir_d[0]->buyback;
                    if($coin_mode=='1')
                    {
                    ?>
                      <lable class="cl"><input type="checkbox" name="buyback_blimit" id="buyback_blimit" value="1"> Buyback Wallet</lable>
                      <?php if($fir_d[0]->buy_fees > 0) { ?><p style="font-weight:bold;">(Admin Fees Deduct for Buyback <?php echo $fir_d[0]->buy_fees;?> %)</p> <?php }?>
                      <div style="clear:both;"><br></div>
                      <?php 
                      }
                  }
                  ?>

                  <input type="hidden" name="e_l_fees" id="e_l_fees" value="">
                  <input type="hidden" name="e_l_back" id="e_l_back" value="<?php echo $coin_mode;?>">
                  <input type="hidden" name="e_l_back_admin" id="e_l_back_admin" value="<?php echo $fir_d[0]->buy_fees;?>">
                  <input type="hidden" name="e_l_back_ad" id="e_l_back_ad" value="0">
                  <input type="hidden" name="cur_bal" id="cur_bal" value="<?php echo str_replace(",","",$buy_bal)?>">
              </div>
              <span>Fee <span id="e_l_feesp">0</span> <small class="text-gray"> <?php echo $ex2;?></small> <small class="green">(<?php echo $ex2_fee;?>%)</small> </span><br /><br />
              <?php
              if($this->session->userdata('uusersid')!='')
              {
                $button='Buy ('.$ex2.' -> '.$ex1.')';
              ?>
                <input type="button" onclick="javascript:eltrade();" class="btn-trade" value="<?php echo $button;?>">
            <?php
              } 
              else
              {
                ?>
                  <a class="btn-trade" href="<?php echo base_url()?>login"><i class="fa fa-user"></i> Login or Register To Trade</a>
                <?php
              }
              ?> 
                </form>
            </div>
              <div class="tab-pane" id="tab_default_market">
            <form action="<?php echo base_url();?>addbmarket" name="emtrades" id="emtrades" class="form-validate eltrade" method="post">
              <div class="order-block-inp">
                <input type="text" placeholder="Price <?php echo $ex2.'/'.$ex2;?>" name="price_e_mprice" style='text-align:right;background:#ddd;' id="price_e_mprice" value="<?php echo $price_disp;?>" readonly='readonly'/>
                <input type="text" placeholder="Amount <?php echo $ex1;?>"  name="price_e_mamount" id="price_e_mamount" style='text-align:right;' onkeyup="e_mtradekey();" />
                <div class="err" id="mamt_err"></div>
                <input type="text" placeholder="Total <?php echo $ex2;?>" readonly="readonly" style='background:#ddd;text-align:right;'  name="price_e_mtotal" id="price_e_mtotal" />

                 <?php
                  $coin_mode=0;
                  $find_buy=$this->db->query("select * from site_controls where settings_name='user' and site_key='user_buyback'")->row();
                  if($find_buy->site_value=='on')
                  {
                    $coin_mode=$fir_d[0]->buyback;
                    if($coin_mode=='1')
                    {
                    ?>
                      <lable class="cl"><input type="checkbox" name="buyback_bmarket" id="buyback_bmarket" value="1"> Buyback Wallet</lable>
                      <?php if($fir_d[0]->buy_fees > 0) { ?><p style="font-weight:bold;">(Admin Fees Deduct for Buyback <?php echo $fir_d[0]->buy_fees;?> %)</p> <?php }?>
                      <div style="clear:both;"><br></div>
                      <?php 
                      }
                  }
                  ?>
                <input type="hidden" name="e_m_fees" id="e_m_fees" value="">
                <input type="hidden" name="e_m_back" id="e_m_back" value="<?php echo $coin_mode;?>">
                <input type="hidden" name="e_m_back_admin" id="e_m_back_admin" value="<?php echo $fir_d[0]->buy_fees;?>">
                <input type="hidden" name="e_m_back_ad" id="e_m_back_ad" value="0">
              </div>
              <span>Fee <span id="e_m_feesp">0</span> <small class="text-gray"> <?php echo $ex2;?></small> <small class="green">(<?php echo $ex2_fee;?>%)</small> </span><br /><br />
              <?php
              if($this->session->userdata('uusersid')!='')
              {
                $button='Buy ('.$ex2.' -> '.$ex1.')';
              ?>
                <input type="button" onclick="javascript:emtrade();" class="btn-trade" value="<?php echo $button;?>">
            <?php
              } 
              else
              {
                ?>
                  <a class="btn-trade" href="<?php echo base_url()?>login"><i class="fa fa-user"></i> Login or Register To Trade</a>
                <?php
              }
              ?> 
                </form>
             
             </div>
            </div>
          </div>
        </div>
        </div>
        </div>
        
        <div class="col-md-6">
          <div class="order-block mb-10">
          <h6 class="other-title theme-color">  <i class="fa fa-minus-circle" style="font-weight:bold;"></i> Sell <?php echo $ex1;?> </h6>

          <?php

          //echo $fir_d[0]->coid;


          $sel_bal=curbalance($this->session->userdata('uusersid'),$fir_d[0]->coid);
          
          //echo $this->db->last_query();

          ?>
         <span class="clearfix">Your balance :  <small class="purple"><?php echo $sel_bal;?> <?php echo $ex1;?></small></span>
       
       <div style="clear:both;"><br></div>

         <div class="tabbable-panel price-compare">
          <div class="tabbable-line">
            <ul class="nav nav-tabs">
                <li class="active"> <a href="#tab_default_limit1" data-toggle="tab"> Limit </a> </li>
                <li class=""> <a href="#tab_default_market1" data-toggle="tab"> Market </a> </li>
            </ul>

            <div class="tab-content" >
              <div class="tab-pane active" id="tab_default_limit1">
               <form action="<?php echo base_url();?>addslimit" name="sltrades" id="sltrades" class="form-validate eltrade" method="post">
              <div class="order-block-inp">
                <input type="text" placeholder="Price <?php echo $ex2.'/'.$ex1;?>" name="price_s_lprice" style='text-align:right;' id="price_s_lprice" value="<?php echo $price_disp;?>" onkeypress="s_ltradekey();"/>
                <div class="err" id="slprice_err"></div>
                <input type="text" placeholder="Amount <?php echo $ex1;?>"  name="price_s_lamount" id="price_s_lamount" style='text-align:right;' onkeyup="s_ltradekey();" />
                <div class="err" id="slamt_err"></div>
                <input type="text" placeholder="Total <?php echo $ex2;?>" readonly="readonly" style='background:#ddd;text-align:right;'  name="price_s_ltotal" id="price_s_ltotal"  />

                <input type="hidden" name="e_s_fees" id="e_s_fees" value="">
              </div>
              <span>Fee <span id="e_s_feesp">0</span> <small class="text-gray"> <?php echo $ex1;?></small> <small class="green">(<?php echo $ex1_fee;?>%)</small> </span><br /><br />
              <?php
              if($this->session->userdata('uusersid')!='')
              {
                $button='Sell ('.$ex1.' -> '.$ex2.')';
              ?>
                <input type="button" onclick="javascript:sltrade();" class="btn-trade" value="<?php echo $button;?>">
            <?php
              } 
              else
              {
                ?>
                  <a class="btn-trade" href="<?php echo base_url()?>login"><i class="fa fa-user"></i> Login or Register To Trade</a>
                <?php
              }
              ?> 
                </form>
            </div>
              <div class="tab-pane" id="tab_default_market1">
            <form action="<?php echo base_url();?>addsmarket" name="smtrades" id="smtrades" class="form-validate eltrade" method="post">
              <div class="order-block-inp">
                <input type="text" placeholder="Price <?php echo $ex2.'/'.$ex2;?>" name="price_s_mprice" style='text-align:right;background:#ddd;' id="price_s_mprice" value="<?php echo $price_disp;?>" readonly='readonly'/>
                <div class="err" id="smprice_err"></div>
                <input type="text" placeholder="Amount <?php echo $ex1;?>"  name="price_s_mamount" id="price_s_mamount" style='text-align:right;' onkeyup="s_mtradekey();" />
                <div class="err" id="smamt_err"></div>
                <input type="text" placeholder="Total <?php echo $ex2;?>" readonly="readonly" style='background:#ddd;text-align:right;'  name="price_s_mtotal" id="price_s_mtotal"  />
                <input type="hidden" name="e_sm_fees" id="e_sm_fees" value="">
                
              </div>
              <span>Fee <span id="e_sm_feesp">0</span> <small class="text-gray"> <?php echo $ex1;?></small> <small class="green">(<?php echo $ex1_fee;?>%)</small> </span><br /><br />
              <?php
              if($this->session->userdata('uusersid')!='')
              {
                $button='Sell ('.$ex1.' -> '.$ex2.')';
              ?>
                <input type="button" onclick="javascript:smtrade();" class="btn-trade" value="<?php echo $button;?>">
              <?php
              } 
              else
              {
                ?>
                  <a class="btn-trade" href="<?php echo base_url()?>login"><i class="fa fa-user"></i> Login or Register To Trade</a>
                <?php
              }
              ?> 
                </form>
             
             </div>
            </div>
          </div>
           </div>
        </div>
        </div>
        </div> 

        <div class="tabbable-panel order" id="trade_buy">
         <?php 
           $this->load->view('user/trade_buy');
          ?>
      
        </div>
        
      </div>
      <div class="col-md-12 col-lg-3">
          <div class="history order" id="trade_history">
          <?php 
           $this->load->view('user/trade_history');
          ?>
          </div>

          <!--chatbox-->

          <div style="clear:both;"><br></div>

          <div class="chat_box">
              <div class="atitle"><i class="fa fa-weixin"></i> Chat </div>
            <hr><br>
          <div class="scrolling slim-scroll" id="slim1">
            <?php 
             $this->load->view('user/chat_list');
            ?>
          </div>
            <div class="submit_box">
            <?php
            $cht=1;
            if($this->session->userdata('uusersid'))
            {
              $fetch_chat=$this->db->query("select * from chat_message where block_status='1' and from_id='".$this->session->userdata('uusersid')."' order by date desc")->row(); 
              if($fetch_chat)
              {
                  $now=date("Y-m-d H:i:s");
                  $exist=$fetch_chat->block_exist;
                  if(strtotime($exist) > strtotime($now))
                  {
                   
                    $cht=0;
                  }
              }
              if($cht=='1')
              {
            ?>
            <div class="p2"><a id="chat-btn" class="btn_chat" href="javascript:chat();">Send</a></div>
            <?php
              }
              else
              {
                ?>
                <div class="p2"><a id="chat-btn" class="btn_chat" disabled style="cursor:not-allowed;">Send</a></div>

                <?php 

              } 
            }
            else
            {
            ?>
            <div class="p2"><button data-toggle="modal" data-target="#chat" class="btn_chat">Send</button></div>
            <?php }?>

            <div class="p1"><span class="p3"><input type="text" id="chat_id" name="chat_id"></span></div>
            <input type="hidden" id="chat_rep" name="chat_rep" value="0">
            <div class="err" id="chat_err" style="font-size:12px;"></div>
            <?php 
            if($cht=='0')
            {
              ?>
                <p style="color:red;font-size:12px;">(Chat blocked until..<?php echo $fetch_chat->block_exist;?>)</p>
              <?php 

            }
            ?>
            </div>
          </div>
</div>
</div>
</div>
          <!--chatbox-->
        
    </div>
  </div>
</div>

<div class="modal fade" id="chat" tabindex="-1" role="dialog" aria-labelledby="calcModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
          <div class="modal-body">
            <div class="panel panel-default" >
              <div class="panel-heading" style="background:#051649; color: #fff;">Error! <button type="button" class="close" data-dismiss="modal" style="color:#fff !important;">X</button></div>
              <div class="panel-body">
                <p>You Must login first</p>
                <!--<button type="button" class="btn_chat" data-dismiss="modal" >Close</button>-->
                <a href="<?php echo base_url();?>login"><button type="button" class="btn_chat">Login</button></a>
              </div>
            </div>
          </div>
    </div>
    </div> 
<?php
$this->load->view('user/footer');
$this->load->view('user/common_script');
?>

<script type="text/javascript">
  



$(function(){       
    $('.body_tr').click(function(){
        window.location = $(this).data('href');
        return false;
    });
});






function eltrade()
{
  document.getElementById("lprice_err").innerHTML="";
  document.getElementById("lamt_err").innerHTML="";
  var price=document.getElementById("price_e_lprice").value;
  var amount=document.getElementById("price_e_lamount").value;
  var total=document.getElementById("price_e_ltotal").value;
  flag=0;
  if(price=='')
  {
    flag=1;
    document.getElementById("lprice_err").innerHTML="Pls Enter Price";

  }
  if(price!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(price))
    {
      flag=1;
      document.getElementById("lprice_err").innerHTML="Invalid Format";
    }

  }
  if(amount=='')
  {
    flag=1;
    document.getElementById("lamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("lamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag=='0')
  {
    var total=parseFloat(price)*parseFloat(amount);
    // alert("limit:"+total);
    var percent="<?php echo $ex2_fee;?>";
    var total_tran=parseFloat(total)*parseFloat(percent)/100;
    var coin_mode=document.getElementById("e_l_back").value;
    if(coin_mode=='1')
    {
      if(document.getElementById("buyback_blimit").checked==true)
      {
        var admin_deduct="<?php echo $fir_d[0]->buy_fees;?>";
        if(parseFloat(admin_deduct)>0)
        { 
          var total_ded=parseFloat(total)*parseFloat(admin_deduct)/100;
          var final=parseFloat(total)+parseFloat(total_tran)+parseFloat(total_ded);
          document.getElementById("e_l_back_ad").value=total_ded.toFixed(8);
        }
        else
        {
            var total_ded='0';
            var final=parseFloat(total)+parseFloat(total_tran);
        }
      }
      else
      {
        var final=parseFloat(total)+parseFloat(total_tran); 
        document.getElementById("e_l_back_ad").value='0';
      }
    }
    else
    {
      var final=parseFloat(total)+parseFloat(total_tran);
      document.getElementById("e_l_back_ad").value='0';
    }
    
    document.getElementById("price_e_ltotal").value=total.toFixed(4);
    document.getElementById("e_l_fees").value=total_tran.toFixed(4);
    document.getElementById("e_l_feesp").value=total_tran.toFixed(4);
    var eth_balance="<?php echo str_replace(",", "", $buy_bal);?>";
    if(parseFloat(final)>parseFloat(eth_balance))
    {
      document.getElementById("lamt_err").innerHTML="Insufficent Balance";
    }
    else
    {
     

       //document.getElementById("eltrades").submit();
        $.ajax({
                type: "POST",
                url: "<?php echo base_url();?>addblimit",
                data: $('#eltrades').serialize(),
                success: function(msg) {

                  
                    
                  $("#scu").css("display",'block');
                  $("#trade_buy").load('<?php echo base_url();?>user/trade/trand_buy');
                  $("#trade_history").load('<?php echo base_url();?>user/trade/trand_his');
                  $("#open_order").load('<?php echo base_url();?>user/trade/trand_open');
                  $("#price_e_lprice").val('<?php echo $price_disp;?>');
                  $("#price_e_lamount").val('');
                  $("#price_e_ltotal").val('');
                  $("#e_l_feesp").html('0');

                }
            });
    }

  }

}

function e_ltradekey()
{
  document.getElementById("lprice_err").innerHTML="";
  document.getElementById("lamt_err").innerHTML="";
  var price=document.getElementById("price_e_lprice").value;
  var amount=document.getElementById("price_e_lamount").value;
  var total=document.getElementById("price_e_ltotal").value;
  flag=0;
  if(price=='')
  {
    flag=1;
    document.getElementById("lprice_err").innerHTML="Pls Enter Price";

  }
  if(price!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(price))
    {
      flag=1;
      document.getElementById("lprice_err").innerHTML="Invalid Format";
    }

  }
  if(amount=='')
  {
    flag=1;
    document.getElementById("lamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='')
  {

    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("lamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag!='1')
  {
    var total=parseFloat(price)*parseFloat(amount);
    var percent="<?php echo $ex2_fee;?>";
    var total_tran=parseFloat(total)*parseFloat(percent)/100;
    document.getElementById("price_e_ltotal").value=total.toFixed(4);
    document.getElementById("e_l_fees").value=total_tran.toFixed(4);
    document.getElementById("e_l_feesp").innerHTML=total_tran.toFixed(4);

  }

}

/*buy market trade*/

function emtrade()
{
  document.getElementById("mamt_err").innerHTML="";
  var price="<?php echo $price_disp;?>";
  var amount=document.getElementById("price_e_mamount").value;
  var total=document.getElementById("price_e_mtotal").value;
  var flag=0;

  if(amount=='' || amount=='0')
  {
    flag=1;
    document.getElementById("mamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='0')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {flag=1;
      document.getElementById("mamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag!='1')
  {

      var total=parseFloat(price)*parseFloat(amount);
      //alert("market : "+total);
      var percent="<?php echo $ex2_fee;?>";
      var total_tran=parseFloat(total)*parseFloat(percent)/100;
      //var final=parseFloat(total)+parseFloat(total_tran);
      var coin_mode=document.getElementById("e_m_back").value;
      if(coin_mode=='1')
      {
          var admin_deduct="<?php echo $fir_d[0]->buy_fees;?>";
          alert(admin_deduct);
          if(parseFloat(admin_deduct)>0)
          { 
            var total_ded=parseFloat(total)*parseFloat(admin_deduct)/100;
            var final=parseFloat(total)+parseFloat(total_tran)+parseFloat(total_ded);
          }
          else
          {
            var total_ded='0';
            var final=parseFloat(total)+parseFloat(total_tran);
          }
      }
      else
      { 
          var total_ded='0';
          var final=parseFloat(total)+parseFloat(total_tran);
      }

      document.getElementById("price_e_mtotal").value=total.toFixed(4);
      document.getElementById("e_m_fees").value=total_tran.toFixed(4);
      document.getElementById("e_m_feesp").value=total_tran.toFixed(4);
      document.getElementById("e_m_back_ad").value=total_ded.toFixed(8);
      var eth_balance="<?php echo str_replace(",", "", $buy_bal);?>";
      if(parseFloat(final)>parseFloat(eth_balance))
      {
        document.getElementById("mamt_err").innerHTML="Insufficent Balance";
      }
      else
      {
          //document.getElementById("emtrades").submit();
          
          $.ajax({
                type: "POST",
                url: "<?php echo base_url();?>addbmarket",
                data: $('#emtrades').serialize(),
                success: function(msg) {
                    
                  $("#scu").css("display",'block');
                  $("#trade_buy").load('<?php echo base_url();?>user/trade/trand_buy');
                  $("#trade_history").load('<?php echo base_url();?>user/trade/trand_his');
                  $("#open_order").load('<?php echo base_url();?>user/trade/trand_open');
                  $("#price_e_mamount").val('');
                  $("#price_e_mtotal").val('');
                  $("#e_m_feesp").html('0');

                }
            });
      }

  }

}


function e_mtradekey()
{

  document.getElementById("mamt_err").innerHTML="";
  var price="<?php echo $price_disp;?>";
  var amount=document.getElementById("price_e_mamount").value;
  var total=document.getElementById("price_e_mtotal").value;

  var flag=0;

  if(amount=='' || amount=='0')
  {
    flag=1;
    document.getElementById("mamt_err").innerHTML="Pls Enter Amount";
  }
  if(amount!='0')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("mamt_err").innerHTML="Invalid Format";
    }

  }
  if(flag!='1')
  {
    var total=parseFloat(price)*parseFloat(amount);
    var percent="<?php echo $ex2_fee;?>";
    var total_tran=parseFloat(total)*parseFloat(percent)/100;
    document.getElementById("price_e_mtotal").value=total.toFixed(4);
    document.getElementById("e_m_fees").value=total_tran.toFixed(4);
    document.getElementById("e_m_feesp").innerHTML=total_tran.toFixed(4);

  }




}

/*buy market trade*/

/*sell limit trade*/

function sltrade()
{

  document.getElementById("slprice_err").innerHTML="";
  document.getElementById("slamt_err").innerHTML="";
  var price=document.getElementById("price_s_lprice").value;
  var amount=document.getElementById("price_s_lamount").value;
  var total=document.getElementById("price_s_ltotal").value;
  flag=0;
  if(price=='')
  {
    flag=1;
    document.getElementById("slprice_err").innerHTML="Pls Enter Price";

  }
  if(price!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(price))
    {
      flag=1;
      document.getElementById("slprice_err").innerHTML="Invalid Format";
    }

  }
  if(amount=='')
  {
    flag=1;
    document.getElementById("slamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("slamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag=='0')
  {
    var total=parseFloat(price)*parseFloat(amount);
    var total1=parseFloat(amount);
    var percent="<?php echo $ex1_fee;?>";
    var total_tran=parseFloat(total1)*parseFloat(percent)/100;
    


    var final=parseFloat(total1)+parseFloat(total_tran);
    document.getElementById("price_s_ltotal").value=total.toFixed(4);
    document.getElementById("e_s_fees").value=total_tran.toFixed(4);
    document.getElementById("e_s_feesp").value=total_tran.toFixed(4);
    var eth_balance="<?php echo str_replace(",", "", $sel_bal);?>";
    if(parseFloat(final)>parseFloat(eth_balance))
    {
      document.getElementById("slamt_err").innerHTML="Insufficent Balance";
    }
    else
    {
      //document.getElementById("sltrades").submit();
      $.ajax({
                type: "POST",
                url: "<?php echo base_url();?>addslimit",
                data: $('#sltrades').serialize(),
                success: function(msg) {
                    
                  $("#scu").css("display",'block');
                  $("#trade_buy").load('<?php echo base_url();?>user/trade/trand_buy');
                  $("#trade_history").load('<?php echo base_url();?>user/trade/trand_his');
                  $("#open_order").load('<?php echo base_url();?>user/trade/trand_open');
                  $("#price_s_lprice").val('<?php echo $price_disp;?>');
                  $("#price_s_lamount").val('');
                  $("#price_s_ltotal").val('');
                  $("#e_s_feesp").html('0');


                  //location.reload();

                }
            });
    }

}

}


function s_ltradekey()
{

  document.getElementById("slprice_err").innerHTML="";
  document.getElementById("slamt_err").innerHTML="";
  var price=document.getElementById("price_s_lprice").value;
  var amount=document.getElementById("price_s_lamount").value;
  var total=document.getElementById("price_s_ltotal").value;
  flag=0;
  if(price=='')
  {
    flag=1;
    document.getElementById("slprice_err").innerHTML="Pls Enter Price";

  }
  if(price!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(price))
    {
      flag=1;
      document.getElementById("slprice_err").innerHTML="Invalid Format";
    }

  }
  if(amount=='')
  {
    flag=1;
    document.getElementById("slamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("slamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag=='0')
  {
    var total=parseFloat(price)*parseFloat(amount);
    var total1 = parseFloat(amount);
    var percent="<?php echo $ex1_fee;?>";
    var total_tran=parseFloat(total1)*parseFloat(percent)/100;
    var final=parseFloat(total)+parseFloat(total_tran);
    //var final=parseFloat(total_tran);
    document.getElementById("price_s_ltotal").value=total.toFixed(4);
    document.getElementById("e_s_fees").value=total_tran.toFixed(4);
    document.getElementById("e_s_feesp").innerHTML=total_tran.toFixed(4);
    var eth_balance="<?php echo str_replace(",", "", $sel_bal);?>";
    /*if(parseFloat(final)>parseFloat(eth_balance))
    {
      document.getElementById("slamt_err").innerHTML="Insufficent Balance";
    }*/
    var price=document.getElementById('price_s_lamount').value;
    if(parseFloat(price)>parseFloat(eth_balance))
    {
      document.getElementById("slamt_err").innerHTML="Insufficent Balance";
    }


  }

}



/*sell limit trade*/


/*sell market trade*/


function smtrade()
{

  document.getElementById("smamt_err").innerHTML="";
  var price="<?php echo $price_disp;?>";
  var amount=document.getElementById("price_s_mamount").value;
  var total=document.getElementById("price_s_mtotal").value;
  var flag=0;

  if(amount=='' || amount=='0')
  {
    flag=1;
    document.getElementById("smamt_err").innerHTML="Pls Enter Amount";

  }
  if(amount!='0')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {flag=1;
      document.getElementById("smamt_err").innerHTML="Invalid Format";
    }

  }

  if(flag!='1')
  {

      var total=parseFloat(price)*parseFloat(amount);
      var percent="<?php echo $ex1_fee;?>";
      var total_tran=parseFloat(total)*parseFloat(percent)/2;
      var final=parseFloat(total)+parseFloat(total_tran);
      //var final=parseFloat(total_tran);
      document.getElementById("price_s_mtotal").value=total.toFixed(4);
      document.getElementById("e_sm_fees").value=total_tran.toFixed(4);
      document.getElementById("e_sm_feesp").value=total_tran.toFixed(4);
      var eth_balance="<?php echo str_replace(",", "", $sel_bal);?>";
      if(parseFloat(price)>parseFloat(eth_balance))
      {
        document.getElementById("smamt_err").innerHTML="Insufficent Balance";
      }
      else
      {
          //document.getElementById("smtrades").submit();
          $.ajax({
                type: "POST",
                url: "<?php echo base_url();?>addsmarket",
                data: $('#smtrades').serialize(),
                success: function(msg) {
                    
                  $("#scu").css("display",'block');
                  $("#trade_buy").load('<?php echo base_url();?>user/trade/trand_buy');
                  $("#trade_history").load('<?php echo base_url();?>user/trade/trand_his');
                  $("#open_order").load('<?php echo base_url();?>user/trade/trand_open');
                  $("#price_s_mamount").val('');
                  $("#price_s_mtotal").val('');
                  $("#e_sm_feesp").html('0');

                }
            });



        
      }

  }

 


}


function s_mtradekey()
{

  document.getElementById("smamt_err").innerHTML="";
  var price="<?php echo $price_disp;?>";
  var amount=document.getElementById("price_s_mamount").value;
  var total=document.getElementById("price_s_mtotal").value;

  var flag=0;

  if(amount=='' || amount=='0')
  {
    flag=1;
    document.getElementById("smamt_err").innerHTML="Pls Enter Amount";
  }
  if(amount!='0')
  {
    var mq =/^[0-9.]+$/;
    if(!mq.test(amount))
    {
      flag=1;
      document.getElementById("smamt_err").innerHTML="Invalid Format";
    }

  }
  if(flag!='1')
  {
    var total=parseFloat(price)*parseFloat(amount);
    var percent="<?php echo $ex1_fee;?>";
    var total_tran=parseFloat(total)*parseFloat(percent)/100;
    document.getElementById("price_s_mtotal").value=total.toFixed(4);
    document.getElementById("e_sm_fees").value=total_tran.toFixed(4);
    document.getElementById("e_sm_feesp").innerHTML=total_tran.toFixed(4);
  }

}
/*sell market trade*/

function chat()
{
  document.getElementById("chat_err").innerHTML="";
  var chat = document.getElementById("chat_id").value;
  if(chat=='')
  {
    document.getElementById("chat_err").innerHTML="Pls Enter content";
  }
  else
  {
    if(chat.length < 15)
    {
        document.getElementById("chat_err").innerHTML="Pls Enter min 15 characters";
    }
    else
    {

      var formData = {
                'chat': $('#chat_id').val(),
                'chat_rep': $('#chat_rep').val()//for get email 
            };

            console.log(formData);
            $.ajax({
                type: "POST",
                url: "<?php echo base_url();?>addchat",
                data:formData,
                success: function(msg) {
                  $("#slim1").load('<?php echo base_url();?>user/trade/chat_list');
                  $("#chat_id").val('');
                  $('#slim1').animate({
                      scrollTop: $('#slim1')[0].scrollHeight}, 2000);
                }
            });
      }

  }
}


function check_user(str,str1)
{
  var str = str+" ; ";
  document.getElementById('chat_id').value=str;
  document.getElementById('chat_rep').value=str1;

}

function value_store(str,str1,str2)
{
  document.getElementById("price_e_lprice").value=str;
  document.getElementById("price_e_lamount").value=str1;
  document.getElementById("price_e_ltotal").value=str2;
  document.getElementById("price_s_lprice").value=str;
  document.getElementById("price_s_lamount").value=str1;
  document.getElementById("price_s_ltotal").value=str2;


}
</script>
</html>
