<?php
/**
 * Header
 *
 */

if (!defined("_VALID_PHP"))
	die('O acesso direto a está página não é permitido');

$titulo_header = $core->empresa;
$nome_pagina = get('do');
$id_pagina = get('id');
?>

<!DOCTYPE html>
<!--[if IE 8]> <html lang="pt-BR" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="pt-BR" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="pt-BR">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta content="width=device-width, initial-scale=1.0" name="viewport" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<meta name="description" content="SIGESIS - Sistemas de Gestão - VOCÊ NO CONTROLE DA SUA EMPRESA, em qualquer lugar... a qualquer momento!" />
	<meta name="keywords" content="SIGESIS, sistemas web, aplicativos, mobile, aplicativos vale do aço, aplicativos ipatinga, sistemas de gestão, sistemas web ipatinga, sistemas ipatinga, sistemas vale do aço, sites ipatinga, sites vale do aço, SIGESIS, sigesis" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="author" content="SIGESIS" />

	<!-- Title -->
	<title><?php echo $titulo_header; ?></title>

	<!-- Favicons -->
	<link rel="shortcut icon" href="./assets/img/favicon.png">
	<link rel="apple-touch-icon" href="./assets/img/favicon_60x60.png">
	<link rel="apple-touch-icon" sizes="76x76" href="./assets/img/favicon_76x76.png">
	<link rel="apple-touch-icon" sizes="120x120" href="./assets/img/favicon_120x120.png">
	<link rel="apple-touch-icon" sizes="152x152" href="./assets/img/favicon_152x152.png">

	<!-- BEGIN GLOBAL MANDATORY STYLES -->
	<link href="./assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href="./assets/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
	<link href="./assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link href="./assets/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
	<link href="./assets/plugins/select2/select2.css" rel="stylesheet" type="text/css" />
	<!-- END GLOBAL MANDATORY STYLES -->

	<!-- BEGIN PAGE LEVEL STYLES -->
	<link href="assets/css/profile.css" rel="stylesheet" type="text/css" />
	<link href="assets/css/tasks.css" rel="stylesheet" type="text/css" />
	<!-- END PAGE LEVEL SCRIPTS -->

	<!-- BEGIN THEME STYLES -->
	<link href="./assets/css/components-rounded.css" id="style_components" rel="stylesheet" type="text/css">
	<link href="./assets/css/plugins.css" rel="stylesheet" type="text/css">
	<link href="./assets/css/layout.css" rel="stylesheet" type="text/css">
	<link href="./assets/css/themes/default.css" rel="stylesheet" type="text/css">
	<link href="./assets/css/custom.css" rel="stylesheet" type="text/css">

	<link rel="stylesheet" type="text/css" href="./assets/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/bootstrap-datepicker/css/datepicker3.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/datatables/extensions/Scroller/css/dataTables.scroller.min.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/datatables/extensions/ColReorder/css/dataTables.colReorder.min.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/typeahead/typeahead.css">
	<link rel="stylesheet" type="text/css" href="./assets/plugins/bootstrap-switch/css/bootstrap-switch.min.css" />
	<link rel="stylesheet" type="text/css" href="./assets/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />

	<!-- BEGIN NOTIFICATION STYLES -->
	<link rel="stylesheet" type="text/css" href="./assets/css/notification.css">
	<!-- END NOTIFICATION -->
	<!-- END THEME STYLES -->

	<script src="./assets/plugins/jquery.min.js" type="text/javascript"></script>
	<script src="./assets/scripts/jquery.mask.js" type="text/javascript"></script>
	<script src="./assets/scripts/jquery.maskMoney.js" type="text/javascript"></script>
	<script src="./assets/scripts/shortcut.js" type="text/javascript"></script>

	<!-- dataTables -->
	<script src="./assets/plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="./assets/plugins/datatables/dataTables.select.min.js"></script>
	<script src="./assets/plugins/datatables/dataTables.buttons.min.js"></script>
	<script src="./assets/plugins/datatables/buttons.flash.min.js"></script>
	<script src="./assets/plugins/datatables/jszip.min.js"></script>
	<script src="./assets/plugins/datatables/pdfmake.min.js"></script>
	<script src="./assets/plugins/datatables/vfs_fonts.js"></script>
	<script src="./assets/plugins/datatables/buttons.html5.min.js"></script>
	<script src="./assets/plugins/datatables/buttons.print.min.js"></script>

	<!--[if lt IE 9]>
	<script src="./assets/plugins/respond.min.js"></script>
	<script src="./assets/plugins/excanvas.min.js"></script>
	<![endif]-->

	<!-- IMPORTANT! Load jquery-ui.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
	<script src="./assets/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/jquery.blockui.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/jquery.cokie.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/typeahead/handlebars.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/typeahead/typeahead.bundle.min.js" type="text/javascript"></script>
	<!-- END CORE PLUGINS -->

	<!-- BEGIN PAGE LEVEL PLUGINS -->
	<script src="./assets/plugins/select2/select2.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-growl/jquery.bootstrap-growl.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-datepicker/js/locales/bootstrap-datepicker.pt-BR.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
	<script src="./assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
	<!-- END PAGE LEVEL PLUGINS -->

</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<!-- DOC: Apply "page-header-menu-fixed" class to set the mega menu fixed  -->
<!-- DOC: Apply "page-header-top-fixed" class to set the top menu fixed  -->

<body>
	<!-- BEGIN HEADER -->
	<div class="page-header" <?php echo (Filter::$acao == "novavenda") ? ' style="height: 145px;" ' : '' ?>>
		<?php if (Filter::$acao == "novavenda"): ?>
			<div class="page-header-top">
				<div class="" id="containerpdv" style="margin: 0 40px 0 40px"> <!-- class="container" -->
					<!-- BEGIN LOGO -->
					<!-- BEGIN RESPONSIVE MENU TOGGLER -->
					<a href="javascript:;" class="menu-toggler" id="menu-toggler-pdv"></a>
					<!-- END RESPONSIVE MENU TOGGLER -->
					<div id="headerpdv">
						<div class="col-md-1 page-logo pull-left">
							<img src="./assets/img/logo.png" alt="logo" class="logo-default" id="btn_logo_admin_pdv" style="cursor: pointer;" title="Acesso Administrativo">
						</div>
						<!-- END LOGO -->
						<div class="col-md-7" id="valores">
							<div class="row" id="headvalores">
								<div class="col-md-4" style="text-align: center;">
									<h4 class="bold nomenclatura_valores"><?php echo lang('VALOR_TOTAL'); ?></h4>
									<i>
										<h2 class="bold italic font-blue-madison" id="valor2" style="margin-top: -3px">
											R$ 0,00
										</h2>
									</i>
								</div>
								<div class="col-md-4" style="text-align: center;">
									<h4 class="bold nomenclatura_valores"><?php echo lang('VALOR_PAGAR'); ?></h4>
									<i>
										<h2 class="bold italic font-green-seagreen" id="valor_pagar"
											style="margin-top: -3px">
											R$ 0,00
										</h2>
									</i>
								</div>
								<div class="col-md-4" style="text-align: center;">
									<h4 class="bold nomenclatura_valores"><?php echo lang('TROCO_DINHEIRO'); ?></h4>
									<i>
										<h2 class="bold italic font-red" id="troco" style="margin-top: -3px">
											R$ 0,00
										</h2>
									</i>
								</div>
							</div>
							<div class="row" id="headvalores_secundarios">
								<div class="col-md-4" style="text-align: center;">
									<span><?php echo lang('DESCONTO') . ':'; ?></span>
									<span id="valor_desconto_pdv">R$ 0,00</span>
									<br>
									<span><?php echo lang('ACRESCIMO') . ':'; ?></span>
									<span id="valor_acrescimo_pdv">R$ 0,00</span>
								</div>
								<div class="col-md-4" style="text-align: center;">
									<span><?php echo lang('VALOR_PAGO') . ':'; ?></span>
									<span id="valor_pago_pdv">R$ 0,00</span>
									</i>
								</div>
							</div>
						</div>
						<?php
						$rowempresa = Core::getRowById('empresa', 'id=1');
						?>
						<div class="pull-right">
							<a href="#">
								<img src="./uploads/logomarcapdv/<?php echo $rowempresa->logomarca_pdv; ?>"
									alt="Logo cliente" class="logo-default" id="logo_cliente_header" height="85">
							</a>
						</div>
					</div>
					<!-- BEGIN TOP NAVIGATION MENU -->
					<div class="top-menu" id="top-menu-header2"> <!-- style="margin-top: -15px;" -->
						<ul class="nav navbar-nav pull-right">
							<li class="droddown dropdown-separator">
								<span class="separator"></span>
							</li>
							<li class="dropdown dropdown-dark">
								<a href="javascript:void(0);" class="dropdown-toggle">
									<span class="username username-hide-mobile">
										<?php echo $usuario->nomeempresa; ?>
									</span>
								</a>
							</li>
							<!-- END USER LOGIN DROPDOWN -->
							<li class="droddown dropdown-separator">
								<span class="separator"></span>
							</li>
							<!-- BEGIN VENDA RAPIDA -->
							
							<!-- SEPARATOR -->
							<li class="droddown dropdown-separator">
								<span class="separator"></span>
							</li>
							<li class="dropdown dropdown-user dropdown-dark">
								<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
									data-close-others="true">
									<span class="username username-hide-mobile">
										<?php echo $usuario->nome; ?>
									</span>
								</a>
								<ul class="dropdown-menu dropdown-menu-default">
									<li>
										<a href="logout.php">
											<i class="icon-key"></i>
											<?php echo lang('SAIR'); ?>
										</a>
									</li>
								</ul>
							</li>
							<!-- END USER LOGIN DROPDOWN -->
						</ul>
					</div>
					<!-- END TOP NAVIGATION MENU -->
				</div>
			</div>
			<!-- USADO EM TODOS MENOS NOVA VENDA -->
		<?php else: ?>
			<!-- BEGIN HEADER TOP -->
			<div class="page-header-top">
				<div class="" style="margin: 0 40px 0 40px;"> <!-- class="container" -->
					<!-- BEGIN LOGO -->
					<div class="page-logo">
						<img src="./assets/img/logo.png" alt="logo" class="logo-default" id="btn_logo_admin_normal" style="cursor: pointer;" title="Acesso Administrativo">
					</div>
					<!-- END LOGO -->
					<!-- BEGIN RESPONSIVE MENU TOGGLER -->
					<a href="javascript:;" class="menu-toggler"></a>
					<!-- END RESPONSIVE MENU TOGGLER -->
					<!-- BEGIN TOP NAVIGATION MENU -->
					<div class="top-menu">
						<ul class="nav navbar-nav pull-right">
							<li class="droddown dropdown-separator">
								<span class="separator"></span>
							</li>
							<li class="dropdown dropdown-dark">
								<a href="javascript:void(0);" class="dropdown-toggle">
									<span class="username username-hide-mobile">
										<?php echo substr($usuario->nomeempresa, 0, 30); ?>
										<!-- NOME DA EMPRESA TERÁ SOMENTE 3O CARACTERS -->
									</span>
								</a>
							</li>
							<!-- END USER LOGIN DROPDOWN -->
							<li class="dropdown dropdown-user dropdown-dark">
								<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown"
									data-close-others="true">
									<span class="username username-hide-mobile">
										<?php echo $usuario->nome; ?>
									</span>
								</a>
								<ul class="dropdown-menu dropdown-menu-default">
									<li>
										<a href="logout.php">
											<i class="icon-key"></i>
											<?php echo lang('SAIR'); ?>
										</a>
									</li>
								</ul>
							</li>
							<!-- END USER LOGIN DROPDOWN -->
						</ul>
					</div>
					<!-- END TOP NAVIGATION MENU -->
				</div>
			</div>
			<!-- END HEADER TOP -->
		<?php endif; ?>
<div class="modal fade" id="modal_senha_master_header" tabindex="-1" role="dialog" aria-hidden="true" style="z-index: 10052;">
    <div class="modal-dialog modal-sm" style="margin-top: 15%;">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #d84a38; color: #fff;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="color:#fff">&times;</button>
                <h4 class="modal-title"><i class="fa fa-lock"></i> Acesso Master</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>Senha de Liberação:</label>
                    <input type="password" class="form-control" id="input_senha_master_header" name="input_senha_master_header" placeholder="Digite a senha...">
                </div>
                <div id="msg_erro_master_header" style="color: red; display: none; margin-top:5px; font-weight: bold;">
                    <i class="fa fa-times"></i> Senha incorreta!
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn red btn-block" id="btn_confirmar_master_header">ACESSAR</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
    // Função para abrir o modal
    function abrirModalMaster() {
        $('#input_senha_master_header').val('');
        $('#msg_erro_master_header').hide();
        $('#modal_senha_master_header').modal('show');
        
        // Foca no campo após abrir
        setTimeout(function() {
            $('#input_senha_master_header').focus();
        }, 500);
    }

    // Escuta o clique na logo do PDV
    $('#btn_logo_admin_pdv').click(function() {
        abrirModalMaster();
    });

    // Escuta o clique na logo Normal (caso precise sair de outras telas)
    $('#btn_logo_admin_normal').click(function() {
        abrirModalMaster();
    });

    // Ao clicar no botão de confirmar
    $('#btn_confirmar_master_header').click(function() {
        validarSenhaMaster();
    });

    // Ao apertar ENTER no campo de senha
    $('#input_senha_master_header').keyup(function(e) {
        if (e.keyCode == 13) {
            validarSenhaMaster();
        }
    });

    function validarSenhaMaster() {
        var senha = $('#input_senha_master_header').val();
        var botao = $('#btn_confirmar_master_header');
        
        if(senha === "") {
            $('#input_senha_master_header').focus();
            return;
        }

        botao.text('Verificando...').prop('disabled', true);

        $.ajax({
            url: 'webservices/verificar_master.php',
            type: 'POST',
            dataType: 'json',
            data: { senha: senha },
            success: function(response) {
                if (response.status === 'sucesso') {
                    // SUCESSO
                    window.location.href = "https://ccpb.sigesisn1.com.br"; 
                } else {
                    // ERRO DE SENHA (retornado pelo PHP)
                    $('#msg_erro_master_header').show();
                    
                    // Se o PHP mandou uma mensagem específica, pode ser útil ver no console:
                    if(response.msg) console.log("Erro PHP: " + response.msg);
                    
                    $('#input_senha_master_header').val('').focus();
                    botao.text('ACESSAR').prop('disabled', false);
                }
            },
            error: function(xhr, status, error) {
                // AGORA VOCÊ VERÁ O ERRO REAL
                console.log("Status: " + status);
                console.log("Erro: " + error);
                console.log("Resposta do Servidor: " + xhr.responseText);
                
                alert('Erro técnico. Abra o Console (F12) para ver detalhes.\n\nProvável erro: ' + xhr.status + ' - ' + error);
                
                botao.text('ACESSAR').prop('disabled', false);
            }
        });
    }
});
</script>
	</div>
	<!-- END HEADER -->