<?php
$router = service('router'); 
if($router->controllerName()!='user' && $router->controllerName()!='cms' && $router->controllerName()!='faq' && $router->controllerName()!='news' && $router->controllerName()!='contact')
{
  $flag='0';
}
else
{
 $flag='1';
}


?>


<header>
<?php
$db = db_connect();
$date_chk=$db->query("select * from currency_market order by date desc limit 1");
$date=$date_chk->getResult();
$dats=$date[0]->date;
$res=$db->query("select * from currency_market where date='$dats' order by rand() limit 10");
$coin_det=$res->getResult();
if($coin_det)
{
  ?>

 <div class="top-bar black-bg pt-10 pb-10">
    <div class="container-fluid">
      <div class="row">

      <marquee>
        <ul class="crypto-scroll">
          <?php
          foreach($coin_det as $coin)
          {
            $ex1=$coin->market_id;
            $ex2=$coin->curid;
            $value_data=$coin->price;
            $cnt=explode("&",$value_data);
            $cntz=count($cnt);
            for($i=0;$i<count($cnt);$i++)
            {
                if($i==$cntz-1)
                {
                    $data_val=explode(",",$cnt[$i]);
                    $valuex=$data_val[0];
                    $price=$data_val[1];
                    $price1=$data_val[2];
                    $volume=$data_val[4];
                    $changeval=number_format($data_val[3],2);
                    $market=$data_val[5];
                }
            }

          
            $first_dat=$db->query("select * from coin_info where coid='".$ex1."'");
            $fir_d=$first_dat->getResult();
            $sec_dat=$db->query("select * from coin_info where coid='".$ex2."'");
            $sec_d=$sec_dat->getResult();

            $pairs=strtoupper($sec_d[0]->coin_symbol).'/'.strtoupper($fir_d[0]->coin_symbol);
          
            // $url = "https://min-api.cryptocompare.com/data/price?fsym=".$sec_d[0]->coin_symbol."&tsyms=".$fir_d[0]->coin_symbol;



            // $linkdata3 = json_decode(file_get_contents($url), true);

            //  foreach ($linkdata3 as $key ) {
            //      $key;
            // }

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


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

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

          ?>
              <li> <img src="<?php echo base_url('uploads/coins/'.$sec_d[0]->coin_image);?>" width="18" height="18"></i> &nbsp;
               <div class="price"> <span><?php echo $pairs;?> 
               <?php
               if($changeval > 0)
               {
               ?>
                <sup class="green"> <i class="fa fa-caret-up" title="arrow"></i></sup> </span>
                <?php
              }
              else
              { 
                ?>
                <sup class="purple"> <i class="fa fa-caret-down" title="arrow"></i></sup> </span>
                <?php
               }
              ?>
                  <price><?php echo number_format($price,6);?></price>
                </div>
             </li>
          <?php
            }
          ?>
        </ul>
        </marquee>

      </div>
    </div>
  </div> 
  <?php

}
?>

 
  <div class="head theme-bgcolor pt-10 pb-10">
    <div class="container-fluid">
      <div class="row">
       <div class="col-md-2 col-sm-2  col-xs-12">
        <?php 
                    $logo_img = site_info('site_logo');
                    
                    if($logo_img) {
                ?>
                    <a class="logo" href="<?php echo base_url();?>"><img class="img-responsive" src="content/site/<?php echo site_info('site_logo');?>" alt="<?php echo site_info('site_logo');?>"></a>
                <?php } else { ?>
                    <a class="logo" href="<?php echo base_url();?>"><img class="img-responsive" src="styles/img/logo.png" alt="logo"></a>
                <?php } ?> </a>
      </div>

        <div class="col-md-6 col-sm-6  col-xs-12">
          <div class="head-left">
          
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
              <h4>Menu</h4>
            </div>

            <?php
            if(session()->get('uusersid')=='')
            { ?>
            <nav class="navbar navbar-inverse">
              <div class="collapse navbar-collapse" id="myNavbar">
                <ul class="nav navbar-nav">
                  <li><a href="<?php echo base_url();?>"> <?php echo lang('language_lang.text_home');?> </a></li>
                  <li><a href="<?php echo base_url();?>login"> <?php echo lang('language_lang.menu_ex_wallet');?> </a></li>
                  
                  <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="<?php echo base_url();?>login"><?php echo lang('language_lang.menu_ex_market');?><i class="fa fa-angle-down"></i> </a>
                    <ul class="dropdown-menu mega-menu">
                    <?php
                    $coins=$db->query("select * from coin_info where market_currency='1' and market_status='1'");
                    $coin_det=$coins->getResult(); 
                    if($coin_det)
                    {

                      foreach($coin_det as $coin)
                      {

                        $coid=$coin->coid;

                        $find_par=$db->query("select * from currency_pair where mark_curr='$coid' and status='1'");
                        $rows=$find_par->getResult();
                        $cou=$find_par->getNumRows();
                        if($cou > 0)
                        {

                          $market=$rows[0]->mark_curr;
                          $curid=$rows[0]->curid;
                          $first_curr=$db->query("select * from coin_info where coid='".$curid."'");
                          $first=$first_curr->getResult();
                          $sec_curr=$db->query("select * from coin_info where coid='$market'");
                          $sec=$sec_curr->getResult();
                          $f=strtoupper($first[0]->coin_symbol);
                          $s=strtoupper($sec[0]->coin_symbol); 
                          $m_data=$f.'_'.$s;


                    ?>
                      <li><a href="<?php echo base_url();?>trade?<?php echo $m_data;?>"> <?php echo $coin->coin_symbol;?> Markets</a></li>
                     
                    <?php
                        }
                      }
                    }
                    ?>

                    </ul>
                  </li>

                  <li><a href="<?php echo base_url();?>contact"><?php echo lang('language_lang.menu_ex_help');?></a></li>
                </ul>
              </div>
            </nav>
            <?php }
            else
            {
              if($flag=='0')
              { ?>
                  <nav class="navbar navbar-inverse">
                    <div class="collapse navbar-collapse" id="myNavbar">
                      <ul class="nav navbar-nav">
                        <li><a href="<?php echo base_url();?>"> <?php echo lang('language_lang.text_home');?> </a></li>
                        <li><a href="<?php echo base_url();?>/user/dashboard"> <?php echo lang('language_lang.menu_ex_wallet');?> </a></li>
                        <li><a href="<?php echo base_url();?>/user/activation">Activation</a></li>
                       <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="<?php echo base_url();?>login"><?php echo lang('language_lang.menu_ex_market');?><i class="fa fa-angle-down"></i> </a>
                    <ul class="dropdown-menu mega-menu">
                    <?php
                    $coins=$db->query("select * from coin_info where market_currency='1' and market_status='1'");
                    $coin_det=$coins->getResult(); 
                    if($coin_det)
                    {
                      foreach($coin_det as $coin)
                      {
                        $coid=$coin->coid;

                        $find_par=$db->query("select * from currency_pair where mark_curr='$coid' and status='1'");
                        $rows=$find_par->getResult();
                        $cou=$find_par->getNumRows();
                        if($cou > 0)
                        {

                          $market=$rows[0]->mark_curr;
                          $curid=$rows[0]->curid;
                          $first_curr=$db->query("select * from coin_info where coid='".$curid."'");
                          $first=$first_curr->getResult();
                          $sec_curr=$db->query("select * from coin_info where coid='$market'");
                          $sec=$sec_curr->getResult();
                          $f=strtoupper($first[0]->coin_symbol);
                          $s=strtoupper($sec[0]->coin_symbol); 
                          $m_data=$f.'_'.$s;
                    ?>
                      <li><a href="<?php echo base_url();?>trade?<?php echo $m_data;?>"> <?php echo $coin->coin_symbol;?> Markets</a></li>
                    <?php
                        }
                      }
                    }
                    ?>

                    </ul>
                    </li>
                        <li><a href="<?php echo base_url();?>/user/tickets"><?php echo lang('language_lang.menu_ex_help');?> </a></li>
                      </ul>
                    </div>
                  </nav> 
              <?php }
              else
              {?>
                 <nav class="navbar navbar-inverse">
                  <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
                      <li><a href="<?php echo base_url();?>"> <?php echo lang('language_lang.text_home');?> </a></li>
                       <li><a href="<?php echo base_url();?>user/dashboard"> <?php echo lang('language_lang.menu_ex_wallet');?> </a></li>
                       <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="<?php echo base_url();?>login"><?php echo lang('language_lang.menu_ex_market');?><i class="fa fa-angle-down"></i> </a>
                      <ul class="dropdown-menu mega-menu">
                      <?php
                      $coins=$db->query("select * from coin_info where market_currency='1' and market_status='1'");
                      $coin_det=$coins->getResult(); 
                      if($coin_det)
                      {
                        foreach($coin_det as $coin)
                        {
                          $coid=$coin->coid;
                          $find_par=$db->query("select * from currency_pair where mark_curr='$coid' and status='1'");
                          $rows=$find_par->getResult();
                          $cou=$find_par->getNumRows();
                          if($cou > 0)
                          {
                            $market=$rows[0]->mark_curr;
                            $curid=$rows[0]->curid;
                            $first_curr=$db->query("select * from coin_info where coid='".$curid."'");
                            $first=$first_curr->getResult();
                            $sec_curr=$db->query("select * from coin_info where coid='$market'");
                            $sec=$sec_curr->getResult();
                            $f=strtoupper($first[0]->coin_symbol);
                            $s=strtoupper($sec[0]->coin_symbol); 
                            $m_data=$f.'_'.$s;

                      ?>
                        <li><a href="<?php echo base_url();?>trade?<?php echo $m_data;?>"> <?php echo $coin->coin_symbol;?> Markets</a></li>
                       
                      <?php
                            }
                        }
                      }
                      ?>

                      </ul>
                      </li>
                        <li><a href="<?php echo base_url();?>contact"><?php echo lang('language_lang.menu_ex_contact');?></a></li>
                        <li><a href="<?php echo base_url();?>tickets"><?php echo lang('language_lang.menu_ex_help');?> </a></li>
                    </ul>
                  </div>
                </nav>
              <?php }
            } ?>

          </div>
        </div>
        <div class="col-md-4 col-sm-4 col-xs-12">
          <div class="head-right">
            <?php
            if(session()->get('uusersid')=='')
            { ?>
                <a class="link" href="register"><?php echo lang('language_lang.menu_signup');?></a>
                <a class="yellow-btn" href="login"><?php echo lang('language_lang.menu_login');?></a>
            <?php
            }
            else
            { 
              if($flag!='0')
              { ?>
                <a class="link" href="<?php echo base_url('dashboard');?>"><?php echo lang('language_lang.menu_dashboard');?></a>
                <a class="yellow-btn" href="<?php echo base_url('logout');?>"><?php echo lang('language_lang.menu_logout');?></a>
              <?php }
              else
              { 
                  $condition = "uusersid = '".session()->get('uusersid')."'";
                  $a = $this->common_model->GetRow('uusers',$condition);
                ?>
                <a class="yellow-btn" href="<?php echo base_url('logout');?>"><?php echo lang('language_lang.menu_logout');?></a>
                <div  class="profile-user "><a class="dropdown-toggle" data-toggle="dropdown" href="#"> <?php echo $a->fullname;?> <i class="fa fa-angle-down"></i> </a>
          
                    <div class="dropdown-menu mega-menu">
                      <span><a href="<?php echo base_url('editprofile');?>"><?php echo lang('language_lang.menu_ex_edit');?>  </a></span>
                       <span><a href="<?php echo base_url('/user/tradehistory')?>"><?php echo lang('language_lang.menu_ex_trade');?></a></span>
                    </div>
                  </div>
              <?php }
              ?>  
            <?php } ?>    
            
              <div class="language">
             <select  id="head_lang">             
                <?php
                  $list_lan_res = activelang();
                  $lang = activeLanginfo();
                  $lang_id = $lang->language_id;

                  foreach ($list_lan_res as $lang_row)
                  {              
                    if(session()->get('user_langid')==$lang_row->language_id)
                    { ?>
                      <option value="<?php echo $lang_row->language_name;?>" selected="selected"> <?php echo ucfirst($lang_row->language_code);?> </option>
                    <?php
                    }
                    else
                    { ?>
                      <option value="<?php echo $lang_row->language_name;?>"> <?php echo ucfirst($lang_row->language_code);?> </option>
                    <?php }
                  } ?>
              </select>
             
            </div>


          </div>
        </div>
      </div>
    </div>
  </div>
</header>

