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

$dados_stm = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".code_decode(query_string('2'),"D")."'"));

?>
<!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>Administra&ccedil;&atilde;o</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.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">
        <a class="navbar-brand brand-logo" href="/admin/admin-configuracoes"><span>Administra&ccedil;&atilde;o</span></a>
        <a class="navbar-brand brand-logo-mini" href="/admin/admin-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">
            <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="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-admin.php"); ?>
      <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_pagina_configurar_streaming_titulo; ?> <?php echo $dados_stm["porta"]; ?></header>
                  </div>
                <div class="card-body">
                    <form method="post" action="/admin/admin-configura-streaming" name="configurar">
                                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_revenda; ?></strong></td>
                                            <td align="left">
                                            <select name="codigo_cliente" class="form-control" id="codigo_cliente" style="width:100%;">
                                            <option value="0">Root</option>                                            
                                            <?php

                                            $query = mysqli_query($conexao,"SELECT * FROM revendas ORDER by nome ASC");
                                            while ($dados_revenda = mysqli_fetch_array($query)) {

                                                if($dados_revenda["codigo"] == $dados_stm["codigo_cliente"]) {
                                                echo '<option value="' . $dados_revenda["codigo"] . '" selected="selected">' . $dados_revenda["nome"] . ' - ' . $dados_revenda["id"] . ' - ' . $dados_revenda["email"] . '</option>';
                                                } else {
                                                echo '<option value="' . $dados_revenda["codigo"] . '">' . $dados_revenda["nome"] . ' - ' . $dados_revenda["id"] . ' - ' . $dados_revenda["email"] . '</option>';
                                                }
                                            }
                                            ?>
                                              </select>
                                           </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_servidor; ?></strong></td>
                                            <td align="left">
                                            <select name="servidor" class="form-control" id="servidor" style="width:100%;">
                                            <?php
                                            $query_servidor = mysqli_query($conexao,"SELECT * FROM servidores WHERE tipo = 'streaming' ORDER by ordem ASC");
                                            while ($dados_servidor = mysqli_fetch_array($query_servidor)) {

                                            $total_streamings = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings where codigo_servidor = '".$dados_servidor["codigo"]."'"));

                                            if($dados_stm["codigo_servidor"] == $dados_servidor["codigo"]) {
                                            echo '<option value="'.$dados_servidor["codigo"].'" selected="selected">'.$dados_servidor["nome"].' - '.$dados_servidor["ip"].' ('.$total_streamings.')</option>';
                                            } else {
                                            echo '<option value="'.$dados_servidor["codigo"].'">'.$dados_servidor["nome"].' - '.$dados_servidor["ip"].' ('.$total_streamings.')</option>';
                                            }

                                            }
                                            ?>
                                            </select>
                                        </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_servidor_rtmp; ?></strong></td>
                                            <td align="left">
                                            <select name="servidor_aacplus" class="form-control" id="servidor_aacplus" style="width:100%;">
                                            <option value="0">Nenhum</option>
                                            <?php
                                            $query_servidor = mysqli_query($conexao,"SELECT * FROM servidores WHERE tipo = 'aacplus' ORDER by ordem ASC");
                                            while ($dados_servidor_aacplus = mysqli_fetch_array($query_servidor)) {

                                            $total_streamings = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings where codigo_servidor_aacplus = '".$dados_servidor_aacplus["codigo"]."'"));

                                            if($dados_stm["codigo_servidor_aacplus"] == $dados_servidor_aacplus["codigo"]) {
                                            echo '<option value="'.$dados_servidor_aacplus["codigo"].'" selected="selected">'.$dados_servidor_aacplus["nome"].' - '.$dados_servidor_aacplus["ip"].' ('.$total_streamings.')</option>';
                                            } else {
                                            echo '<option value="'.$dados_servidor_aacplus["codigo"].'">'.$dados_servidor_aacplus["nome"].' - '.$dados_servidor_aacplus["ip"].' ('.$total_streamings.')</option>';
                                            }

                                            }
                                            ?>
                                            </select>
                                           </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_ouvintes; ?></strong></td>
                                            <td align="left"><input name="ouvintes" type="text" class="form-control" id="ouvintes" style="width:100%;" value="<?php echo $dados_stm["ouvintes"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_bitrate; ?></strong></td>
                                            <td align="left"><div class="input-group">
                                            <select name="bitrate" class="form-control" id="bitrate" style="width:90%;">
                                              <?php
                                               foreach(array("24","32","48","64","96","128","256","320") as $bitrate){
                                               
                                               if($dados_stm["bitrate"] == $bitrate) {
                                                echo "<option value=\"".$bitrate."\" selected=\"selected\">".$bitrate."</option>";
                                               } else {
                                                echo "<option value=\"".$bitrate."\">".$bitrate."</option>";
                                               }
                                               
                                               }
                                              ?>
                                             </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_configurar_streaming_ativar_autodj; ?></strong></td>
                                            <td align="left"><code><?php if($dados_stm["autodj"] == "sim") {echo lang_opcao_sim; } else {echo lang_opcao_nao; } ?></code></td>
                                          </tr>
                                          <?php if($dados_stm["autodj"] == "sim") { ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_espaco_ftp; ?></strong></td>
                                            <td align="left"><div class="input-group"><input name="espaco" type="text" class="form-control" id="espaco" style="width:90%;" value="<?php echo $dados_stm["espaco"]; ?>" /><span class="input-group-append" id="basic-addon3"><label class="input-group-text">MB</label></span></div></td>
                                          </tr>
                                          <?php } ?>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_senha; ?></strong></td>
                                            <td align="left"><div class="input-group"><input name="senha" type="text" class="form-control" id="senha" style="width:90%; vertical-align:middle" value="<?php echo $dados_stm["senha"]; ?>" /><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_configurar_streaming_senha; ?> Admin</strong></td>
                                            <td align="left"><div class="input-group"><input name="senha_admin" type="text" class="form-control" id="senha_admin" style="width:90%; vertical-align:middle" value="<?php echo $dados_stm["senha_admin"]; ?>" /><span class="input-group-append" id="basic-addon3" onclick="gerar_senha('senha_admin');"><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_configurar_streaming_identificacao; ?></strong></td>
                                            <td align="left"><input name="identificacao" type="text" class="form-control" id="identificacao" style="width:100%;" value="<?php echo $dados_stm["identificacao"]; ?>" />
                                              &nbsp;</td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_email; ?></strong></td>
                                            <td align="left"><input name="email" type="text" class="form-control" id="email" style="width:100%;" value="<?php echo $dados_stm["email"]; ?>" />
                                              &nbsp;</td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_programas; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="programas" name="programas" value="sim" <?php if($dados_stm["programas"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_programetes; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="programetes" name="programetes" value="sim" <?php if($dados_stm["programetes"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_pp_download; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="download_programetes_programas" name="download_programetes_programas" value="sim" <?php if($dados_stm["download_programetes_programas"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_streaming_camera_studio; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="camera_studio" name="camera_studio" value="sim" <?php if($dados_stm["camera_studio"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="35" align="left" style="padding-left:5px;"><strong>Site Administr&aacute;vel</strong></td>
                                            <td align="left"><input type="checkbox" id="site_adm" name="site_adm" value="sim"  <?php if($dados_stm["site_adm"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </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.configurar.submit();"><?php echo lang_botao_titulo_configurar; ?></button><input name="porta" type="hidden" id="porta" value="<?php echo $dados_stm["porta"]; ?>" /></td>
                                          </tr>
                                        </table>
                                      </form>
                </div>
              </div>
            </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/admin-streamings/resultado/"+document.getElementById("busca_chave").value;
    }
  }); 
  </script>
</body>
</html>