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

if($_POST["alterar_dados"]) {

$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 pagina de tutoriais invalida.</div>';
header("Location: ".$_SERVER['HTTP_REFERER']."");
exit;
}

mysqli_query($conexao,"Update revendas set url_suporte = '".$_POST["url_suporte"]."', dominio_padrao = '".$dominio_padrao."', stm_exibir_tutoriais = '".$_POST["stm_exibir_tutoriais"]."', url_tutoriais = '".$_POST["url_tutoriais"]."', stm_exibir_downloads = '".$_POST["stm_exibir_downloads"]."', idioma_painel = '".$_POST["idioma_painel"]."', stm_exibir_app_android = '".$_POST["stm_exibir_app_android"]."', stm_exibir_app_android_painel = '".$_POST["stm_exibir_app_android_painel"]."', url_logo = '".$_POST["url_logo"]."' where codigo = '".$_SESSION["code_user_logged"]."'") or die(mysqli_error($conexao));


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

// 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>[<?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>
          <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:100%;" value="<?php echo $dados_revenda["url_tutoriais"]; ?>" /></span>                      </td>
                                            </tr>
                                            <tr>
                                              <td width="150" height="50" align="left" style="padding-left:5px;"><strong><?php echo lang_info_pagina_config_revenda_recursos_downloads; ?></strong></td>
                                              <td width="740" align="left" data-toggle="tooltip" data-placement="bottom" title="<?php echo lang_info_pagina_config_revenda_recursos_downloads_ajuda; ?>">
                                              <input name="stm_exibir_downloads" type="radio" value="sim" <?php if($dados_revenda["stm_exibir_downloads"] == "sim") { echo 'checked="checked"';} ?> />&nbsp;<?php echo lang_opcao_sim; ?>
                                              <input name="stm_exibir_downloads" type="radio" value="nao" <?php if($dados_revenda["stm_exibir_downloads"] == "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>
      <!-- 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;
    }
  }); 
  </script>
</body>
</html>