<!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');
    ?> 
  <body>
      <?php
        $this->load->view('user/login_header');
        $currency_info = defaultcurrency();
      ?>

     <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
      
       <div class="table-list clearfix mb-20">
    
    <h4 class="other-title theme-color"><?php echo $this->lang->line('menu_ex_trade');?></h4>
    
    
    <div class="table-responsive  main-table">
       
        <table>
          <thead>
            <tr>
              <th><?php echo $this->lang->line('menu_ex_time');?></th>
              <th><?php echo $this->lang->line('menu_ex_type');?></th>
              <th><?php echo $this->lang->line('menu_ex_pair');?></th>
              <th><?php echo $this->lang->line('menu_ex_price');?></th>
              <th><?php echo $this->lang->line('menu_ex_locked');?></th>
              <th><?php echo $this->lang->line('menu_ex_desc');?></th>
              <th><?php echo $this->lang->line('menu_ex_status');?></th>
            </tr>
          </thead>
          <tbody>
          <?php
            $userid=$this->session->userdata('uusersid');

            $res=$this->db->query("select * from exchange where (userid='$userid' or rec_user='$userid') and exchange_mode='0' order by date desc");
            $row=$res->result();
            if($row)
            {
              foreach($row as $row)
              {
                $type=$row->type;

                $status=$row->status;

                if($type=='3')
                  $type="Ask";
                else if($type=='4')
                  $type='Bid';
              else if($type=="1")
                  $type="BUY";
                else
                  $type="SELL";

                if($status=='1')
                  $status1='Opened';
                else if($status=='2')
                  $status1='Requested';
                else if($status=='3')
                  $status1='Closed';
                else
                  $status1="Canceled";

                $first_dat=$this->db->query("select * from coin_info where coid='".$row->pair."'");
                $fir_d=$first_dat->result();
                $sec_dat=$this->db->query("select * from coin_info where coid='".$row->market_type."'");
                $sec_d=$sec_dat->result();

                $pair=strtoupper($fir_d[0]->coin_symbol).'/'.strtoupper($sec_d[0]->coin_symbol);


              ?>
                <tr>
                  <td><?php echo $row->date;?></td>
                  <td><?php echo $type;?></td>
                  <td><?php echo $pair;?></td>
                  <td><?php echo $row->price;?> <?php echo strtoupper($sec_d[0]->coin_symbol);?></td>
                  <td><?php echo $row->total;?> <?php echo strtoupper($sec_d[0]->coin_symbol);?></td>
                  <?php
                  if($row->type=='1')
                  {
                    $userid=$this->session->userdata('uusersid');
                    if($userid==$row->rec_user)
                    {
                      $rec_user=$row->userid;
                      $user_det=$this->db->query("select * from uusers where uusersid='$rec_user'");
                      $user_det=$user_det->result();
                      $data="Sent Trade to ".$user_det[0]->username;

                    } 
                    else
                    {

                      $rec_user=$row->rec_user;
                      $user_det=$this->db->query("select * from uusers where uusersid='$rec_user'");
                      $user_det=$user_det->result();
                      $data="Received Trade From ".$user_det[0]->username;

                    } 
                    
                  }
                  else if($row->type=='2')
                  {

                    $userid=$this->session->userdata('uusersid');
                    if($userid==$row->rec_user)
                    {
                      $rec_user=$row->userid;
                      $user_det=$this->db->query("select * from uusers where uusersid='$rec_user'");
                      $user_det=$user_det->result();
                      $data="Sent Trade to ".$user_det[0]->username;

                    } 
                    else
                    {

                      $rec_user=$row->rec_user;
                      $user_det=$this->db->query("select * from uusers where uusersid='$rec_user'");
                      $user_det=$user_det->result();
                      $data="Received Trade From ".$user_det[0]->username;

                    } 
                  }
                  else
                  {
                    $data="---";
                  }

                  ?>
                  <td><?php echo $data;?></td>
                  <td><?php echo $status1;?></td>
                </tr>
              <?php
              }
            }
            ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
<?php
$this->load->view('user/footer');
$this->load->view('user/common_script');
// $this->load->view('user/result_check');
?>
</body>
</html>
