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

// Estatísticas
$total_streamings = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings WHERE codigo_cliente = '".$dados_revenda["codigo"]."'"));
$total_streamings_subrevendas = mysqli_fetch_array(mysqli_query($conexao,"SELECT SUM(streamings) as total FROM revendas WHERE codigo_revenda = '".$dados_revenda["codigo"]."'"));
$ouvintes = mysqli_fetch_array(mysqli_query($conexao,"SELECT SUM(ouvintes) as total FROM streamings WHERE codigo_cliente = '".$dados_revenda["codigo"]."'"));
$ouvintes_subrevendas = mysqli_fetch_array(mysqli_query($conexao,"SELECT SUM(ouvintes) as total FROM revendas WHERE codigo_revenda = '".$dados_revenda["codigo"]."'"));
$espaco_subrevendas = mysqli_fetch_array(mysqli_query($conexao,"SELECT SUM(espaco) as total FROM revendas WHERE codigo_revenda = '".$dados_revenda["codigo"]."'"));
$espaco_streamings = mysqli_fetch_array(mysqli_query($conexao,"SELECT SUM(espaco) as total FROM streamings WHERE codigo_cliente = '".$dados_revenda["codigo"]."'"));

$total_ouvintes = $ouvintes["total"]+$ouvintes_subrevendas["total"];

$porcentagem_uso_streamings = ($dados_revenda["streamings"] == 0) ? "0" : ($total_streamings+$total_streamings_subrevendas["total"])*100/$dados_revenda["streamings"];
$porcentagem_uso_ouvintes = ($dados_revenda["ouvintes"] == 0) ? "0" : $total_ouvintes*100/$dados_revenda["ouvintes"];
$porcentagem_uso_espaco_ftp = ($dados_revenda["espaco"] == 0) ? "0" : ($espaco_subrevendas["total"]+$espaco_streamings["total"])*100/$dados_revenda["espaco"];

$stat_streamings_descricao = "(".$total_streamings." / ".str_replace("999999","<code>".lang_info_ilimitado."</code>",$dados_revenda["streamings"]).")";
$stat_ouvintes_descricao = "(".$total_ouvintes." / ".str_replace("999999","<code>".lang_info_ilimitado."</code>",$dados_revenda["ouvintes"]).")";
$stat_espaco_descricao = "(".tamanho(($espaco_subrevendas["total"]+$espaco_streamings["total"]))." / ".tamanho($dados_revenda["espaco"]).")";

?>
<!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>Revenda <?php echo $dados_revenda["id"]; ?></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">
  <link rel="stylesheet" href="/inc/theme.css">
  <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-configuracoes"><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-configuracoes"><span>Painel Revenda</span></a>
        <?php } ?>
        <a class="navbar-brand brand-logo-mini" href="/admin/revenda-configuracoes"><img src="/img/icones/img-icone-logo.png" title="Painel" width="32" height="32" border="0"></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>
        <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 class="navbar-nav navbar-nav-right">
          <li class="nav-item dropdown">
            <a class="nav-link count-indicator dropdown-toggle d-flex align-items-center justify-content-center" id="notificationDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
              <i class="mdi mdi-bell f-22 text-icones" data-toggle="tooltip" data-placement="bottom" title="<?php echo $lang['lang_info_pagina_informacoes_tab_avisos']; ?>"></i>
              <?php if($total_avisos_exibir > 0) { ?><span class="count bg-success"><?php echo $total_avisos_exibir; ?></span><?php } ?>           
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list" aria-labelledby="notificationDropdown">
              <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>

    <!-- 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="playlists-autodj" 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">AutoDJ</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body text-center" id="playlists-autodj-conteudo" style="text-align: center;"><img src="/img/ajax-loader.gif" /></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 class="container-fluid page-body-wrapper">      
    <?php require_once("menu-revenda.php"); ?>
      <div class="main-panel">
        <div class="content-wrapper">
          <div id="local-status-acoes"><?php echo $_SESSION['status_acao'];unset($_SESSION['status_acao']); ?></div>
          <form method="post" action="/admin/revenda-cadastra-streaming" name="cadastrar">
          <div class="row">            

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_cadastrar_streaming_tab_titulo; ?></header>
                  </div>
                <div class="card-body">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td width="150" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_ouvintes; ?></strong></td>
                                        <td align="left"><input name="ouvintes" type="text" class="form-control" id="ouvintes" style="width:100%;" value="" />&nbsp;
                                        <?php if($dados_revenda["ouvintes"] == '999999') { ?>
                                        <input type="checkbox" id="ouvintes_ilimitados" onclick="configurar_ilimitados('ouvintes');" style="vertical-align:middle" />&nbsp;<code><?php echo lang_info_pagina_cadastrar_streaming_ouvintes_ilimitados; ?></code>
                                        <?php } ?>
                                        </td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_bitrate; ?></strong></td>
                                        <td align="left"><div class="input-group">
                                        <select name="bitrate" class="form-control" id="bitrate" style="width:60%;">
                                          <?php
                                           foreach(array("24","32","48","64","96","128","256","320") as $bitrate){
                                           
                                           if($bitrate <= $dados_revenda["bitrate"]) {
                                           
                                           if($bitrate == $dados_revenda["bitrate"]) {
                                           echo "<option value=\"".$bitrate."\">".$bitrate."</option>\n";
                                           } else {
                                           echo "<option value=\"".$bitrate."\">".$bitrate."</option>\n";
                                           }

                                           }
                                            
                                           }
                                          ?>
                                        </select><span class="input-group-append" id="basic-addon3"><label class="input-group-text">Kbps</label></span></div>
                                    </td>
                                      </tr>
                                      <tr>
                                        <td height="35" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_ativar_autodj; ?></strong></td>
                                        <td align="left"><input type="checkbox" id="autodj" name="autodj" value="sim" checked /></td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_espaco_autodj; ?></strong></td>
                                        <td align="left"><div class="input-group"><input name="espaco" type="text" class="form-control" id="espaco" style="width:60%;" value="" /><span class="input-group-append" id="basic-addon3"><label class="input-group-text">MB</label></span></div></td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_senha; ?></strong></td>
                                        <td align="left"><div class="input-group"><input name="senha" type="text" class="form-control" id="senha" style="width:60%; vertical-align:middle" value="" /><span class="input-group-append" id="basic-addon3" onclick="gerar_senha('senha');"><label class="input-group-text" style="cursor: pointer;"><i class="fa fa-lock text-yellow">&nbsp;</i></label></span></div></td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_identificacao; ?></strong></td>
                                        <td align="left"><input name="identificacao" type="text" class="form-control" id="identificacao" style="width:100%;" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_cadastrar_streaming_identificacao_ajuda; ?>" /></td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_idioma; ?></strong></td>
                                        <td align="left">
                                        <select name="idioma_painel" id="idioma_painel" class="form-control" style="width:100%;" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_cadastrar_streaming_idioma_ajuda; ?>">
                                          <option value="pt-br" selected="selected">Portugu&ecirc;s(Brasil)</option>
                                          <option value="es">Espa&ntilde;ol</option>
                                          <option value="en-us">English(USA)</option>
                                        </select></td>
                                      </tr>
                                      <tr>
                                        <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_email; ?></strong></td>
                                        <td align="left"><input name="email" type="text" class="form-control" id="email" style="width:100%;" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_cadastrar_streaming_email_ajuda; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong>Tipo Servidor</strong></td>
                                            <td align="left"><select name="tipo_servidor" class="form-control" id="tipo_servidor">
                                              <option value="shoutcast" <?php if($dados_stm["tipo_servidor"] == "sim") { echo ' selected="selected"'; } ?>>ShoutCast</option>
                                              <option value="icecast" <?php if($dados_stm["tipo_servidor"] == "sim") { echo ' selected="selected"'; } ?>>IceCast</option>
                                             </select>
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="50" colspan="2" align="right"><button type="button" class="btn btn-info" onClick="document.cadastrar.submit();"><?php echo lang_botao_titulo_cadastrar; ?></button></td>
                                          </tr>
                                    </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_cadastrar_streaming_aba_recursos; ?></header>
                  </div>
                <div class="card-body">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td width="160" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_permitir_alterar_senha; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="permitir_alterar_senha" name="permitir_alterar_senha" value="sim" checked /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_app_android; ?></strong></td>
                                                <td align="left"><input type="checkbox" id="exibir_app_android" name="exibir_app_android" value="sim" checked /></td>
                                            </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_mini_site; ?></strong></td>
                                                <td align="left"><input type="checkbox" id="exibir_mini_site" name="exibir_mini_site" value="sim" checked /></td>
                                              </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_cadastrar_streaming_encoders; ?></strong></td>
                                                <td align="left"><input type="checkbox" id="encoder_mp3" name="encoder_mp3" value="sim" checked />&nbsp;<?php echo lang_info_pagina_cadastrar_streaming_encoders_mp3; ?>&nbsp;<input type="checkbox" id="encoder_aacplus" name="encoder_aacplus" value="sim" checked />&nbsp;<?php echo lang_info_pagina_cadastrar_streaming_encoders_aacplus; ?></td>
                                          </tr>
                                          <?php if($dados_revenda["programetes"] == 'sim') { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Programetes</strong></td>
                                            <td align="left"><input type="checkbox" id="programetes" name="programetes" value="sim" checked /></td>
                                          </tr>
                                          <?php } ?>
                                          <?php if($dados_revenda["programas"] == 'sim') { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Programas</strong></td>
                                            <td align="left"><input type="checkbox" id="programas" name="programas" value="sim" checked /></td>
                                          </tr>
                                          <?php } ?>
                                          <?php if($dados_revenda["programetes"] == 'sim' || $dados_revenda["programas"] == 'sim') { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Download P & P</strong></td>
                                            <td align="left"><input type="checkbox" id="download_programetes_programas" name="download_programetes_programas" value="sim" checked /></td>
                                          </tr>
                                          <?php } ?>
                                          <?php if($dados_revenda["camera_studio"] == 'sim') { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Camera Studio</strong></td>
                                            <td align="left"><input type="checkbox" id="camera_studio" name="camera_studio" value="sim" checked /></td>
                                          </tr>
                                          <?php } ?>
                                          <?php if($dados_revenda["site_adm"] > 0) { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Site Adm</strong></td>
                                            <td align="left"><input type="checkbox" id="site_adm" name="site_adm" value="sim" checked /></td>
                                          </tr>
                                          <?php } ?>
                                        </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_cadastrar_subrevenda_estatisticas_tab_titulo; ?></header>
                  </div>
                <div class="card-body">
                    <p class="mb-10"><?php echo lang_info_pagina_cadastrar_subrevenda_estatisticas_stm; ?> <small><?php echo $stat_streamings_descricao; ?></small></p>
                                        <div class="progress mb-30">
                                            <div class="progress-bar bg-twitter" style="width:<?php echo $porcentagem_uso_streamings; ?>%"></div>
                                        </div>
                                        <p class="mb-10"><?php echo lang_info_pagina_cadastrar_subrevenda_estatisticas_ouvintes; ?> <small><?php echo $stat_ouvintes_descricao; ?></small></p>
                                        <div class="progress mb-30">
                                            <div class="progress-bar bg-twitter" style="width:<?php echo $porcentagem_uso_ouvintes; ?>%"></div>
                                        </div>
                                        <p class="mb-10"><?php echo lang_info_pagina_cadastrar_subrevenda_estatisticas_espaco_ftp; ?> <small><?php echo $stat_espaco_descricao; ?></small></p>
                                        <div class="progress mb-30">
                                            <div class="progress-bar bg-twitter" style="width:<?php echo $porcentagem_uso_espaco; ?>%"></div>
                                        </div>
                </div>
              </div>
            </div>

          </div>
        </form>
        </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;
    }
  }); 
        
  </script>
</body>
</html>