<?php
require_once("inc/protecao-revenda.php");

$dados_subrevenda = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM revendas WHERE (codigo_revenda = '".$dados_revenda["codigo"]."' AND codigo = '".code_decode(query_string('2'),"D")."')"));
$validar_subrevenda = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM revendas WHERE (codigo_revenda = '".$dados_revenda["codigo"]."' AND codigo = '".code_decode(query_string('2'),"D")."')"));

if($validar_subrevenda == 0) {

// Cria o sessão do status das ações executadas e redireciona.
$_SESSION["status_acao"] = '<div class="alert alert-danger text-center" role="alert">'.lang_info_acesso_stm_nao_permitido.'</div>';

header("Location: /admin/revenda");
exit;
}

if($dados_revenda["idioma_painel"] == "pt-br") {
$lang_sortable = "Portuguese-Brasil";
} elseif($dados_revenda["idioma_painel"] == "en-us") {
$lang_sortable = "English";
} else {
$lang_sortable = "Spanish";
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>[<?php echo $dados_revenda["id"]; ?>] Revenda - Reseller</title>
  <link rel="stylesheet" href="/inc/materialdesignicons.min.css">
  <link rel="stylesheet" href="/inc/font-awesome.min.css">
  <link rel="stylesheet" href="/inc/vendor.bundle.base.css">
  <link rel="stylesheet" href="/inc/vendor.bundle.addons.css">  
  <?php if($dados_revenda["tema_dark"] == "sim") { ?>
  <link rel="stylesheet" href="/inc/theme-dark.css">
  <?php } else { ?>
  <?php if($dados_revenda["tema_dark"] == "sim") { ?>
  <link rel="stylesheet" href="/inc/theme-dark.css">
  <?php } else { ?>
  <link rel="stylesheet" href="/inc/theme.css">
  <?php } ?>
  <?php } ?>
  <link rel="shortcut icon" href="/img/favicon.ico" />
  <script type="text/javascript" src="/admin/inc/ajax-revenda.js"></script>
  <script type="text/javascript" src="/admin/inc/javascript.js"></script>
</head>
<body>
  <div class="container-scroller">
    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
      <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
        <?php if($dados_revenda["url_logo"]) { ?>
        <a class="navbar-brand brand-logo" href="/admin/revenda"><img id="logo" src="<?php echo $dados_revenda["url_logo"]; ?>" title="Painel" height="60" border="0"></a>
        <?php } else { ?>
        <a class="navbar-brand brand-logo" href="/admin/revenda"><span>Painel Revenda</span></a>
        <?php } ?>
        <a class="navbar-brand brand-logo-mini" href="/admin/revenda"><i class="fa fa-video-camera text-muted"></i></a>
      </div>
      <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end justify-content-lg-start">
        <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
          <span class="mdi mdi-menu text-icones"></span>
        </button>
        <ul class="navbar-nav mr-lg-2">
          <li class="nav-item nav-search d-none d-lg-block">
            <div class="input-group">
              <div class="input-group-prepend">
                <span class="input-group-text" id="search">
                  <i class="mdi mdi-magnify"></i>
                </span>
              </div>
              <input type="text" class="form-control" id="busca_chave" placeholder="Busca" aria-label="search" aria-describedby="search">
            </div>
          </li>
        </ul>
        <ul class="navbar-nav navbar-nav-right">
          <li class="nav-item dropdown">
            <a class="nav-link count-indicator dropdown-toggle" id="notificationDropdown" href="#" data-toggle="dropdown">
              <i class="mdi mdi-bell-outline mx-0"></i>
              <span class="count"></span>            
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list" aria-labelledby="notificationDropdown" style="min-width: 300px">
              <a class="dropdown-item">
                <p class="mb-0 font-weight-normal float-left"><?php echo lang_info_pagina_informacoes_revenda_tab_avisos; ?></p>
              </a>
              <div class="dropdown-divider"></div>
              <?php carregar_avisos_revenda($conexao); ?>
            </div>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/admin/sair"><i class="mdi mdi-logout f-22 text-icones" data-toggle="tooltip" data-placement="bottom" title="Sair/logout"></i></a>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="mdi mdi-menu text-icones"></span>
        </button>
      </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
      <nav class="sidebar sidebar-offcanvas" id="sidebar">
        <ul class="nav">
          <li class="nav-item">
            <a class="nav-link" href="/admin/revenda">
              <i class="fa fa-home text-icones"></i>
              <span class="menu-title">Dashboard</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/admin/revenda-streamings">
              <i class="fa fa-video-camera text-icones"></i>
              <span class="menu-title"><?php echo lang_menu_streaming; ?></span>
            </a>
          </li>
          <?php if($dados_revenda["subrevendas"] > 0 && ($dados_revenda["tipo"] == 1 || $dados_revenda["tipo"] == 2)) { ?>
          <li class="nav-item">
            <a class="nav-link" href="/admin/revenda-subrevendas">
              <i class="fa fa-users text-icones"></i>
              <span class="menu-title"><?php echo lang_menu_subrevenda; ?></span>
            </a>
          </li>
          <?php } ?>
          <li class="nav-item">
            <a class="nav-link" href="/admin/revenda-busca-avancada">
              <i class="fa fa-search text-icones"></i>
              <span class="menu-title"><?php echo lang_menu_busca_avancada; ?></span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" data-toggle="collapse" href="#integracao" aria-expanded="false" aria-controls="integracao">
              <i class="fa fa-tasks text-icones"></i>
              <span class="menu-title"><?php echo lang_menu_integracao; ?></span>
              <i class="menu-arrow"></i>
            </a>
            <div class="collapse" id="integracao">
              <ul class="nav flex-column sub-menu">
                <li class="nav-item"> <a class="nav-link" href="/admin/revenda-api"> <?php echo lang_menu_integracao_api; ?></a></li>
                <li class="nav-item"> <a class="nav-link" href="/admin/revenda-modulo-whmcs"> <?php echo lang_menu_integracao_modulo_whmcs; ?></a></li>
              </ul>
            </div>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/admin/revenda-configuracoes">
              <i class="fa fa-cog text-icones"></i>
              <span class="menu-title"><?php echo lang_menu_configuracoes; ?></span>
            </a>
          </li>   
        </ul>
        </ul>
      </nav>
      <!-- partial -->
      <div class="main-panel">
        <div class="content-wrapper">
          <div id="local-status-acoes"><?php echo $_SESSION['status_acao'];unset($_SESSION['status_acao']); ?></div>
          <div class="row">            

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_subrevenda_streamings_tab_titulo; ?></header>
                  </div>
                <div class="card-body">
                    <table class="table table-hover mb-0">
                                                <thead>
                                                    <tr>
                                                        <th><?php echo lang_info_subrevenda_streamings_login; ?></th>
                                                        <th><?php echo lang_info_subrevenda_streamings_servidor; ?></th>
                                                        <th><?php echo lang_info_subrevenda_streamings_plano; ?></th>
                                                        <th><?php echo lang_info_subrevenda_streamings_status; ?></th>
                                                        <th><?php echo lang_info_subrevenda_streamings_acoes; ?></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
<?php
$total_streamings = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings WHERE codigo_cliente = '".$dados_subrevenda["codigo"]."'"));

if($total_streamings > 0) {

$sql = mysqli_query($conexao,"SELECT * FROM streamings WHERE codigo_cliente = '".$dados_subrevenda["codigo"]."' ORDER by login ASC");
while ($dados_stm = mysqli_fetch_array($sql)) {

$dados_servidor = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor"]."'"));

if($dados_stm["status"] > 1) {
$cor_status = "class='table-danger'";
}

$status_streaming = status_streaming($dados_servidor["ip"],$dados_servidor["senha"],$dados_stm["login"]);

if($status_streaming["status"] == "loaded") {
$status = "<i class='ik ik-check-circle text-green'>&nbsp;".lang_info_status_ligado."</i>";
} else {
$status = "<i class='ik ik-info'>&nbsp;".lang_info_status_desligado."</i>";
}

if($status_streaming["status_transmissao"] == "aovivo") {
$status = "<i class='ik ik-check-circle text-red'>&nbsp;".lang_info_status_aovivo."</i>";
}

$servidor = ($dados_subrevenda["dominio_padrao"]) ? strtolower($dados_servidor["nome"]).".".$dados_subrevenda["dominio_padrao"] : strtolower($dados_servidor["nome"]).".".$dados_config["dominio_padrao"];

$login_code = code_decode($dados_stm["login"],"E");

echo "<tr id='".$login_code."' ".$cor_status.">
<td height='25' align='left' scope='col'>&nbsp;".$dados_stm["login"]."</td>
<td height='25' align='left' scope='col'>&nbsp;".$servidor."</td>
<td height='25' align='left' scope='col'>&nbsp;".$dados_stm["espectadores"]." ".lang_info_subrevenda_streamings_espectadores." | ".$dados_stm["bitrate"]." Kbps | ".tamanho($dados_stm["espaco"])." FTP</td>
<td height='25' align='left' scope='col'>".$status."</td>
<td height='25' align='left' scope='col'>
<a href='javascript:mover_streaming_subrevenda_revenda(\"".$login_code."\");' data-toggle='tooltip' data-placement='bottom' title='".lang_info_subrevenda_streamings_acao_mover_streaming."'><i class='ik ik-repeat f-16 text-pink'></i></a>&nbsp;
<a href='javascript:mover_streaming_subrevenda_subrevenda(\"".$login_code."\");' data-toggle='tooltip' data-placement='bottom' title='".lang_info_subrevenda_streamings_acao_mover_streaming_subrevenda."'><i class='ik ik-repeat f-16 text-orange'></i></a>
</td>
</td>
</tr>";

unset($cor_status);
unset($status);
}

} else {

echo "<tr>
    <td height='23' colspan='5' align='center' class='texto_padrao'>".lang_info_sem_registros."</td>
  </tr>";

}

?>
                                                </tbody>
                                            </table>
                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
      <!-- modal -->
      <div class="modal fade" id="avisos" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><?php echo $lang['lang_info_pagina_informacoes_tab_avisos']; ?></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body" id="avisos-conteudo"><img src="/img/ajax-loader.gif" align="center" /></div>
            </div>
        </div>
        </div>
                
        <div class="modal fade" id="log-sistema" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-body" id="log-sistema-conteudo" style="text-align:center"><img src="/img/ajax-loader.gif" /></div>
            </div>
        </div>
      </div>
    </div>
  </div>
  <script src="/inc/vendor.bundle.base.js"></script>
  <script src="/inc/vendor.bundle.addons.js"></script>
  <script src="/inc/theme.js"></script>
  <script>
  $('#busca_chave').keypress(function (e) {
    if (e.which == 13) {
       window.location = "/admin/revenda-streamings/resultado/porta/"+document.getElementById("busca_chave").value;
    }
  }); 
        $(document).ready(function() {

            var table = $('#data_table').DataTable({
                responsive: true,
                "lengthMenu": [[25, 50, 100, 200, -1], [25, 50, 100, 200, "Todos/All"]],
                language: {
                    "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/<?php echo $lang_sortable; ?>.json"
                },
                select: true,
                'aoColumnDefs': [{
                    'bSortable': false,
                    'aTargets': ['nosort']
                }]
            });
            $('#data_table tbody').on( 'click', 'tr', function() {
                if ( $(this).hasClass('selected') ) {
                    $(this).removeClass('selected');
                }
                else {
                    table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });

        });  
  </script>
</body>
</html>