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

$dados_revenda = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM revendas where codigo = '".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_revenda_titulo; ?> <?php echo $dados_revenda["id"]; ?></header>
                  </div>
                <div class="card-body">
                    <form method="post" action="/admin/admin-configura-revenda" name="configurar">
                                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td width="130" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_nome; ?></strong></td>
                                            <td align="left"><input name="nome" type="text" class="form-control" id="nome" style="width:100%;" value="<?php echo $dados_revenda["nome"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td width="130" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_id; ?></strong></td>
                                            <td align="left"><input name="id" type="text" class="form-control" id="id" style="width:100%;" value="<?php echo $dados_revenda["id"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_email; ?></strong></td>
                                            <td align="left"><input name="email" type="text" class="form-control" id="email" style="width:100%;" value="<?php echo $dados_revenda["email"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_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="" /><span class="input-group-append" id="basic-addon3" onclick="gerar_senha('senha');"><label class="input-group-text" style="cursor: pointer;"><i class="ik ik-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_revenda_subrevendas; ?></strong></td>
                                            <td align="left"><input name="subrevendas" type="text" class="form-control" id="subrevendas" style="width:100%;" value="<?php echo $dados_revenda["subrevendas"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_streamings; ?></strong></td>
                                            <td align="left"><input name="streamings" type="text" class="form-control" id="streamings" style="width:100%;" value="<?php echo $dados_revenda["streamings"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_ouvintes; ?></strong></td>
                                            <td align="left"><input name="ouvintes" type="text" class="form-control" id="ouvintes" style="width:100%;" value="<?php echo $dados_revenda["ouvintes"]; ?>" /></td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_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_revenda[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="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_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_revenda["espaco"]; ?>" /><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_configurar_revenda_programas; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="programas" name="programas" value="sim" <?php if($dados_revenda["programas"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_programetes; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="programetes" name="programetes" value="sim" <?php if($dados_revenda["programetes"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_pp_download; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="download_programetes_programas" name="download_programetes_programas" value="sim" <?php if($dados_revenda["download_programetes_programas"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_configurar_revenda_camera_studio; ?></strong></td>
                                            <td align="left"><input type="checkbox" id="camera_studio" name="camera_studio" value="sim" <?php if($dados_revenda["camera_studio"] == "sim") { echo ' checked="checked"'; } ?> />
                                            </td>
                                          </tr>
                                          <tr>
                                            <td height="50" align="left" style="padding-left:5px;"><strong>Servidor Privado</strong></td>
                                            <td align="left">
                                              <select name="codigo_servidor_privado" class="input" id="codigo_servidor_privado" style="width:100%;">
                                                <option value="0" selected="selected">Usar Servidor Compartilhado</option>
                                                  <?php
                                                  $query_servidor = mysqli_query($conexao,"SELECT * FROM servidores 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_revenda["codigo_servidor_privado"] == $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>Site Administr&aacute;vel</strong></td>
                                            <td align="left"><input name="site_adm" type="number" class="form-control" id="site_adm" style="width:30%;" value="<?php echo $dados_revenda["site_adm"]; ?>" /><small>(Infome o limite de sites ou use 0 para desativar o acesso)</small></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_alterar_config; ?></button><input name="codigo_revenda" type="hidden" id="codigo_revenda" value="<?php echo $dados_revenda["codigo"]; ?>" /></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>