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

if($_POST["alterar_dados"]) {

$dados_revenda_atual = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM revendas WHERE codigo = '".$_SESSION["code_user_logged"]."'"));

$dominio_padrao = str_replace("http://","",$_POST["dominio_padrao"]);
$dominio_padrao = str_replace("www.","",$dominio_padrao);

if($_POST["stm_exibir_tutoriais"] == "url" && filter_var($_POST["url_tutoriais"], FILTER_VALIDATE_URL) === false) {

$_SESSION["status_acao"] = '<div class="alert alert-danger text-center" role="alert">URL Inválida/Invalid URL</div>';

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

if($_POST["url_downloads"] != "") {
if(filter_var($_POST["url_downloads"], FILTER_VALIDATE_URL) === false) {

$_SESSION["status_acao"] = '<div class="alert alert-danger text-center" role="alert">URL Download Inválida/Invalid Download URL</div>';

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

mysqli_query($conexao,"Update revendas set url_suporte = '".$_POST["url_suporte"]."', dominio_padrao = '".$dominio_padrao."', smtp_servidor = '".$_POST["smtp_servidor"]."', smtp_porta = '".$_POST["smtp_porta"]."', smtp_email = '".$_POST["smtp_email"]."', smtp_senha = '".$_POST["smtp_senha"]."', stm_exibir_tutoriais = '".$_POST["stm_exibir_tutoriais"]."', url_tutoriais = '".$_POST["url_tutoriais"]."', url_downloads = '".$_POST["url_downloads"]."', stm_exibir_app_android = '".$_POST["stm_exibir_app_android"]."', stm_exibir_mini_site = '".$_POST["stm_exibir_mini_site"]."', stm_exibir_app_android_painel = '".$_POST["stm_exibir_app_android_painel"]."', idioma_painel = '".$_POST["idioma_painel"]."', url_logo = '".$_POST["url_logo"]."' where codigo = '".$_SESSION["code_user_logged"]."'");

if($_POST["senha"]) {
mysqli_query($conexao,"Update revendas set senha = PASSWORD('".$_POST["senha"]."') where codigo = '".$_SESSION["code_user_logged"]."'");
}

// Verifica se o app android foi ativado/desativado
if($dados_revenda_atual["stm_exibir_app_android"] != $_POST["stm_exibir_app_android"]) {
mysqli_query($conexao,"Update streamings set exibir_app_android ='".$_POST["stm_exibir_app_android"]."' where codigo_cliente = '".$_SESSION["code_user_logged"]."'");
}

// Verifica se o mini site foi ativado/desativado
if($dados_revenda_atual["stm_exibir_mini_site"] != $_POST["stm_exibir_mini_site"]) {
mysqli_query($conexao,"Update streamings set stm_exibir_mini_site ='".$_POST["stm_exibir_mini_site"]."' where codigo_cliente = '".$_SESSION["code_user_logged"]."'");
}

// Insere a ação executada no registro de logs.
logar_acao($conexao,"revenda","".$dados_revenda_atual["codigo"]."","Configurações da revenda alteradas com sucesso.");

// 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_info_pagina_config_revenda_resultado_ok.'</div>';

header("Location: /admin/revenda-configuracoes");
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>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-configuracoes" name="configuracoes">
          <div class="row">            

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_config_revenda_tab_config_geral; ?></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_config_revenda_config_geral_senha; ?></strong></td>
                                              <td align="left"><input name="senha" type="password"class="form-control" id="senha" style="width:100%;" value="" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_config_geral_senha_ajuda; ?>" /></td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_config_geral_idioma; ?></strong></td>
                                              <td align="left">
                                              <select name="idioma_painel"class="form-control" id="idioma_painel" style="width:100%;" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_config_geral_idioma_ajuda; ?>">
                                                <option value="pt-br" <?php if($dados_revenda["idioma_painel"] == "pt-br") { echo 'selected="selected"';} ?>>Portugu&ecirc;s(Brasil)</option>
                                                <option value="es" <?php if($dados_revenda["idioma_painel"] == "es") { echo 'selected="selected"';} ?>>Espa&ntilde;ol</option>
                                                <option value="en-us" <?php if($dados_revenda["idioma_painel"] == "en-us") { echo 'selected="selected"';} ?>>English(USA)</option>        
                                              </select>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_config_geral_url_suporte; ?></strong></td>
                                              <td align="left"><input name="url_suporte" type="text"class="form-control" id="url_suporte" style="width:100%;" value="<?php echo $dados_revenda["url_suporte"]; ?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_config_geral_url_suporte_ajuda; ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td height="50" colspan="2" align="right"><button type="button" class="btn btn-info" onClick="document.configuracoes.submit();"><?php echo lang_botao_titulo_alterar_config; ?></button><input name="alterar_dados" type="hidden" id="alterar_dados" value="<?php echo time(); ?>" /></td>
                                              </tr>
                                          </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_config_revenda_tab_config_dominio; ?></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_config_revenda_config_dominio_dominio; ?></strong></td>
                                            <td align="left"><input name="dominio_padrao" type="text"class="form-control" id="dominio_padrao" style="width:100%;" value="<?php echo $dados_revenda["dominio_padrao"]; ?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_config_dominio_ajuda; ?>" /><br />
                                                <a href="#" onclick="window.location = '/admin/revenda-dominio';"><?php echo lang_info_pagina_config_revenda_config_dominio_link; ?></a></td>
                                            </tr>
                                            <tr>
                                                <td height="50" colspan="2" align="right"><button type="button" class="btn btn-info" onClick="document.configuracoes.submit();"><?php echo lang_botao_titulo_alterar_config; ?></button></td>
                                            </tr>
                                            <tr>
                                                <td height="40" colspan="2"></td>
                                            </tr>
                                          </table>
                </div>
              </div>
            </div>

            <div class="col-lg-12">
              <div class="card">
                  <div class="card-header">
                    <header><?php echo lang_info_pagina_config_revenda_tab_recursos; ?></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_config_revenda_recursos_tutoriais; ?></strong></td>
                                              <td align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_tutoriais_ajuda; ?>">
                                              <input name="stm_exibir_tutoriais" type="radio" value="sim" onclick="document.getElementById('div_tutoriais_url').style.display = 'none';" <?php if($dados_revenda["stm_exibir_tutoriais"] == "sim") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_sim; ?>
                                              <input name="stm_exibir_tutoriais" type="radio" value="nao" onclick="document.getElementById('div_tutoriais_url').style.display = 'none';" <?php if($dados_revenda["stm_exibir_tutoriais"] == "nao") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_nao; ?>
                                              <input name="stm_exibir_tutoriais" type="radio" value="url" onclick="document.getElementById('div_tutoriais_url').style.display = 'block';" <?php if($dados_revenda["stm_exibir_tutoriais"] == "url") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_info_pagina_config_revenda_recursos_tutoriais_url; ?>
                                                  <span id="div_tutoriais_url" style="display:<?php if($dados_revenda["stm_exibir_tutoriais"] == "url") { echo "block"; } else { echo "none"; } ?>"><br /><input name="url_tutoriais" type="text"class="form-control" id="url_tutoriais" style="width:250px;" value="<?php echo $dados_revenda["url_tutoriais"]; ?>" /></span>                      </td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_downloads_url; ?></strong></td>
                                              <td align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_downloads_url_info; ?>"><input name="url_downloads" type="text"class="form-control" id="url_downloads" style="width:100%;" value="<?php echo $dados_revenda["url_downloads"]; ?>" /></td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_app_android; ?></strong></td>
                                              <td align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_app_android_info; ?>">
                                              <input name="stm_exibir_app_android" type="radio" value="sim" <?php if($dados_revenda["stm_exibir_app_android"] == "sim") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_sim; ?>
                                              <input name="stm_exibir_app_android" type="radio" value="nao" <?php if($dados_revenda["stm_exibir_app_android"] == "nao") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_nao; ?></td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_app_android_painel; ?></strong></td>
                                              <td align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_app_android_painel_info; ?>">
                                              <input name="stm_exibir_app_android_painel" type="radio" value="sim" <?php if($dados_revenda["stm_exibir_app_android_painel"] == "sim") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_sim; ?>
                                              <input name="stm_exibir_app_android_painel" type="radio" value="nao" <?php if($dados_revenda["stm_exibir_app_android_painel"] == "nao") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_nao; ?></td>
                                            </tr>
                                            <tr>
                                              <td width="150" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_mini_site; ?></strong></td>
                                              <td align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_mini_site_ajuda; ?>">
                                              <input name="stm_exibir_mini_site" type="radio" value="sim" <?php if($dados_revenda["stm_exibir_mini_site"] == "sim") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_sim; ?>
                                              <input name="stm_exibir_mini_site" type="radio" value="nao" <?php if($dados_revenda["stm_exibir_mini_site"] == "nao") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_nao; ?></td>
                                            </tr>
                                            <tr>
                                              <td height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_url_logo; ?></strong></td>
                                              <td align="left"><input name="url_logo" type="text"class="form-control" id="url_logo" style="width:100%;" value="<?php echo $dados_revenda["url_logo"]; ?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_url_logo_info; ?>" /></td>
                                            </tr>
                                            <tr>
                                                <td height="50" colspan="2" align="right"><button type="button" class="btn btn-info" onClick="document.configuracoes.submit();"><?php echo lang_botao_titulo_alterar_config; ?></button></td>
                                            </tr>
                                          </table>
                </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>