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

if($_POST["cadastrar"]) {

if(empty($_POST["nome"]) or empty($_POST["espectadores"]) or empty($_POST["bitrate"])) {
$_SESSION["status_acao"] = "<div class='alert alert-danger text-center' role='alert'>".lang_info_campos_vazios."</div>";
header("Location: /admin/revenda-gerenciar-planos");
exit;
}

mysqli_query($conexao,"INSERT INTO revendas_planos (codigo_revenda,nome,espectadores,bitrate,espaco_ftp,ipcameras,subrevendas,streamings,tipo,aplicacao) VALUES ('".$dados_revenda["codigo"]."','".$_POST["nome"]."','".$_POST["espectadores"]."','".$_POST["bitrate"]."','".$_POST["espaco_ftp"]."','".$_POST["ipcameras"]."','".$_POST["subrevendas"]."','".$_POST["streamings"]."','".$_POST["tipo"]."','".$_POST["aplicacao"]."')");

if(!mysqli_error($conexao)) {

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

} else {

// 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_pagina_gerenciar_planos_cadastrar_resultado_erro."</div>";

}


header("Location: /admin/revenda-gerenciar-planos");
exit();

}
?>
<!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_pagina_gerenciar_planos_aba_planos; ?></header>
                  </div>
                <div class="card-body">
                    <table id="data_table" class="table dataTable no-footer table-hover" role="grid" aria-describedby="data_table_info">
                        <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_nome; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_espectadores; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_bitrate; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_espaco_ftp; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_ipcameras; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_subrevendas; ?></th>
                                <th class="sorting_asc" tabindex="0" aria-controls="data_table" rowspan="1" colspan="1" aria-sort="ascending"><?php echo lang_pagina_gerenciar_planos_aplicacao; ?></th>
                                <th><?php echo lang_info_executar_acao; ?></th>
                            </tr>
                        </thead>
                        <tbody>
<?php
$sql = mysqli_query($conexao,"SELECT * FROM revendas_planos where codigo_revenda = '".$dados_revenda["codigo"]."' ORDER by nome");
while ($dados_plano = mysqli_fetch_array($sql)) {

$plano_code = code_decode($dados_plano["codigo"],"E");

echo "<tr id='".$plano_code."'>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["nome"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["espectadores"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["bitrate"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".tamanho($dados_plano["espaco_ftp"])."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["ipcameras"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["subrevendas"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;".$dados_plano["aplicacao"]."</td>
<td height='25' align='left' scope='col' class='texto_padrao'>&nbsp;<a href='javascript:remover_plano(\"".$plano_code."\");'><i class='fa fa-trash-o f-16 text-red'></i></a></td>
</tr>";

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

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_pagina_gerenciar_planos_aba_cadastrar_plano; ?></header>
                  </div>
                <div class="card-body">
                    <form method="post" action="/admin/revenda-gerenciar-planos" style="padding:0px; margin:0px" name="planos">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="160" height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_tipo_plano; ?></td>
        <td align="left"><select name="tipo" id="tipo" class="form-control" onchange="validar_tipo_plano( this.value );">
      <option value="streaming" selected="selected">Streaming</option>
          <option value="subrevenda">SubReseller</option>
        </select></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_aplicacao; ?></td>
        <td align="left"><select name="aplicacao" id="aplicacao" class="form-control" onchange="validar_aplicacao( this.value );">
      <option value="tvstation" selected="selected">Tv Station (live & ondemand)</option>
          <option value="live">Live</option>
          <option value="vod">OnDemand</option>
          <option value="ipcamera">IP Camera</option>
        </select></td>
      </tr>
      <tr>
        <td width="160" height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_nome; ?></td>
        <td align="left"><input name="nome" type="text" class="form-control" id="nome" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_espectadores; ?></td>
        <td align="left" class="texto_padrao_vermelho_destaque"><input name="espectadores" type="number" class="form-control" id="espectadores" value="0" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_bitrate; ?></td>
        <td align="left"><input name="bitrate" type="number" class="form-control" id="bitrate" value="0" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_espaco_ftp; ?></td>
        <td align="left"><input name="espaco_ftp" type="number" class="form-control" id="espaco_ftp" value="0" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_ipcameras; ?></td>
        <td align="left"><input name="ipcameras" type="number" disabled="disabled" class="form-control" id="ipcameras" style="cursor:not-allowed" value="0" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_subrevendas; ?></td>
        <td align="left"><input name="subrevendas" type="number" disabled="disabled" class="form-control" id="subrevendas" style="cursor:not-allowed" value="0" /></td>
      </tr>
      <tr>
        <td height="50" align="left" style="padding-left:5px;"><?php echo lang_pagina_gerenciar_planos_streamings; ?></td>
        <td align="left"><input name="streamings" type="number" disabled="disabled" class="form-control" id="streamings" style="cursor:not-allowed" value="0" /></td>
      </tr>
      <tr>
        <td height="50" colspan="2" align="left">
          <button type="button" class="btn btn-info" onClick="document.planos.submit();"><?php echo lang_botao_titulo_cadastrar; ?></button>
          <input name="cadastrar" type="hidden" id="cadastrar" value="sim" /></td>
      </tr>
    </table>
    </form>
                </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;
    }
  }); 
  function validar_tipo_plano( tipo ) {

document.getElementById('subrevendas').disabled = true;
document.getElementById('subrevendas').value = "0";
document.getElementById('subrevendas').style.cursor = "not-allowed";
document.getElementById('streamings').disabled = true;
document.getElementById('streamings').value = "0";
document.getElementById('streamings').style.cursor = "not-allowed";
document.getElementById('aplicacao').disabled = false;
document.getElementById('aplicacao').style.cursor = "default";

if(tipo == "subrevenda") {
document.getElementById('streamings').disabled = false;
document.getElementById('streamings').value = "0";
document.getElementById('streamings').style.cursor = "default";
document.getElementById('subrevendas').disabled = false;
document.getElementById('subrevendas').value = "0";
document.getElementById('subrevendas').style.cursor = "default";
document.getElementById('aplicacao').disabled = true;
document.getElementById('aplicacao').style.cursor = "not-allowed";
}

}

function validar_aplicacao( tipo ) {

document.getElementById('espaco_ftp').disabled = false;
document.getElementById('espaco_ftp').value = "0";
document.getElementById('espaco_ftp').style.cursor = "default";
document.getElementById('ipcameras').disabled = true;
document.getElementById('ipcameras').value = "0";
document.getElementById('ipcameras').style.cursor = "not-allowed";

if(tipo == "live") {
document.getElementById('espaco_ftp').disabled = true;
document.getElementById('espaco_ftp').value = "0";
document.getElementById('espaco_ftp').style.cursor = "not-allowed";
}

if(tipo == "ipcamera") {
document.getElementById('espaco_ftp').disabled = true;
document.getElementById('espaco_ftp').value = "0";
document.getElementById('espaco_ftp').style.cursor = "not-allowed";
document.getElementById('ipcameras').disabled = false;
document.getElementById('ipcameras').value = "0";
document.getElementById('ipcameras').style.cursor = "default";
}

}
  </script>
</body>
</html>