<?php
	session_start();
    header( "Content-type: text/html; charset=utf-8" );
	include "config/conf.php";
	include "config/icons.php";
?>
<!DOCTYPE html>
<html>
<head>
	<title>Grupo RBK</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="utf-8">
	<base href="<?php echo "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]; ?>" />

	<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>

	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/sb-admin.css">
	<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="css/jasny-bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css">
	<link rel="stylesheet" type="text/css" href="css/wysiwyg-color.css">

	<link rel="stylesheet" type="text/css" href="css/style.css">
	
    <link rel="shortcut icon" type="image/x-icon" href="<?=$base;?>/icone.png">

    <link href="summernote.css" rel="stylesheet">
   

	<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/jqBootstrapValidation.js"></script>
	<script type="text/javascript" src="js/bootstrap-inputmask.min.js"></script>
	<script type="text/javascript" src="js/jquery.maskMoney.min.js"></script>
	<script type="text/javascript" src="js/prettify.js"></script>
	<script type="text/javascript" src="js/jquery.colorbox-min.js"></script>

    <script src="js/jquery.complexify.js"></script> 
    <script src="summernote.min.js"></script>

	<link rel="stylesheet" type="text/css" href="colorbox.css">
	<script>
	  $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );
	</script>
</head>
<body>
<?php
	//se nao está logado ou a página está vazia
	if ((!isset($_SESSION["admin"]["id"])) or (empty($page))) {

		include "pages/login.php";


	} else {
		//senao monta a página
		?>
		<div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html"><img src="images/logo2.png" title="<?=$title;?>" alt="<?=$title;?>" height="40px"></a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">
            	<?php
            		
            		@$img = $_SESSION["admin"]["foto"];
            		$img = $pastaFotos."/".$img."p.jpg";
            		if (!file_exists($img)) $img = "images/user.png";

            	?>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    	<img src="<?php echo $img; ?>" width="35" alt="<?php echo $_SESSION["admin"]["nome"];?>" title="<?php echo $_SESSION["admin"]["nome"];?>" class="img-circle"> Olá <?php echo $_SESSION["admin"]["nome"];?> <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <!--<li>
                            <a href="dados"><i class="fa fa-fw fa-user"></i> Meus Dados</a>
                        </li>-->
                        <li>
                            <a href="senha"><i class="fa fa-fw fa-envelope"></i> Mudar Senha</a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="sair.php"><i class="fa fa-fw fa-power-off"></i> Sair</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav side-nav">
                    <li class="active">
                        <a href="home"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>

                    </li>
                   
                    <?php
	                    $tipo = $_SESSION["admin"]["tipo"];

	                    $sql = "select * from TABLES where TABLE_SCHEMA = '$banco' ";
	                    $consulta = $is->prepare($sql); 
						//$consulta->bindParam(1, $banco); 
						if($consulta->execute()){
							while ($row = $consulta->fetch(PDO::FETCH_OBJ)) {
								
                                $dados = explode(",",$row->TABLE_COMMENT);

								if ($dados[0] != "N")
								$menu[] = array("order"=>(int)$dados[0],
                                    "table"=>$row->TABLE_NAME,
                                    "menu"=>@$dados[1],
                                    "icone"=>@$dados[3],
                                    "tipo"=>@$dados[2],
                                    "busca"=>@$dados[4]);
							}
						}

						ksort($menu);
						$t = $_SESSION["admin"]["tipo"];

		            	foreach ($menu as $m) {

		            		if ($t == "Admin") {
                                if (!empty($m["menu"])) {
			            		   $i = $m["icone"];
			            		   @$icone = $icons[$i];
			            		   echo "<li><a href='listar/".$m["table"]."' title='".$m["menu"]."'><i class='$icone'></i> &nbsp;".$m["menu"]."</a></li>";
			            	    }
                            } else if (($t == "Normal")) {
			            		if (!empty($m["menu"])) {
                                    $i = $m["icone"];
			            		   $icone = $icons[$i];
			            		   echo "<li><a href='listar/".$m["table"]."' title='".$m["menu"]."'><i class='$icone'></i>  &nbsp;".$m["menu"]."</a></li>";
			            	    }
                            }
		            		
		            	}

                    ?>
                    

                    <li><a href='cadastro/migrar' title=''><i class="glyphicon glyphicon-random"></i> Migrar Funcionários</a></li>
                    <li><a href='cadastro/avulso' title=''><i class="glyphicon glyphicon-envelope"></i> Enviar Mensagens Avulsas</a></li>
                    <li><a href='cadastro/email' title=''><i class="fa fa-barcode"></i> Enviar Boletos e Notas</a></li>
                    
                    <li><a href='cadastro/boletos' title=''><i class="glyphicon glyphicon-save"></i> Importar Boletos e Notas</a></li>
                    <li><a href='cadastro/importar' title=''><i class="glyphicon glyphicon-transfer"></i> Importar Dados</a></li>
                    <li><a href='cadastro/envios' title=''><i class="glyphicon glyphicon-list-alt"></i> Relatório de Envios</a></li>
                    <!--<li><a href='cadastro/relRecebimentos' title=''><i class="glyphicon glyphicon-list-alt"></i> Relatório de Recebimentos</a></li>-->
                    <li><a href='cadastro/acessos' title=''><i class="glyphicon glyphicon-eye-open"></i> Relatório de Acessos</a></li>
                    
                    

                    
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

            	<?php

            		$table = "";
            		$id = "";

                    if (!empty($param[0])) $page = $param[0];
            		if (!empty($param[1])) $table = $param[1];
            		if (!empty($param[2])) $id = $param[2];

                    /*echo "<br><br><pre>";

                    print_r( $_POST );
                    print_r( $param ); 

                    echo "</pre>";       */            

                    if (($page == "login") and (isset($_SESSION["admin"]["id"]))) $page = "home";

                    if (!in_array($table, $tables)) {
                        echo "<br><br><div class='well'>Erro ao acessar cadastro! Você não possui acesso!</div>";
                        //exit;
                    } else 	if (file_exists($page.".php")) include $page.".php";
            		else {
            			$arquivo = "pages/".$page.".php";
            			if (file_exists($arquivo)) include $arquivo;
            			else include "home.php";


            		}

            	?>

            </div>
            <!-- /.container-fluid -->
            
        </div>
        <!-- /#page-wrapper -->
        <?php
                if ( $page != "login" ) echo "<footer class='clearfix'><p class='text-right'>Desenvolvimento: Uniti TI</p></footer>";
            ?>
    </div>
    <!-- /#wrapper -->

		<?php

	}

?>
<script>
$(document).ready(function(){
	$(".foto").colorbox({rel:'foto'});
})

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', '<?=$analitycs;?>', 'auto');
  ga('send', 'pageview');

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