<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Home Elegance | Sistema de Gerenciamento</title>
	
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- jQuery 2.1.3 -->
    <script src="plugins/jQuery/jQuery-2.1.3.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
    <script type="text/javascript" src="https://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>    
    <!-- Bootstrap 3.3.2 -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Font Awesome Icons -->
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <!-- Ionicons -->
    <link href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css" />
    <!-- Morris chart -->
    <link href="plugins/morris/morris.css" rel="stylesheet" type="text/css" />
    <!-- jvectormap -->
    <link href="plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
    <!-- Daterange picker -->
    <link href="plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
    <!-- AdminLTE Skins. Choose a skin from the css/skins 
         folder instead of downloading all of them to reduce the load. -->
    <link href="dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
	<script src="inclusos/script.js"></script>  
     
  </head>
  <body class="skin-blue">
<?php
include("seguranca.php"); // Inclui o arquivo com o sistema de seguran?a
protegePagina(); // Protege a página
header('Content-Type: text/html; charset=utf-8');

include("configuracao.php");//confirma no banco de dados
include("inclusos/funcoes.php");

?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <!-- LINHA DADOS -->
  <tr>
    <td colspan="4" align="center" valign="top"><table width="98%" border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td width="404" height="40" align="left" bgcolor="#CCCCCC"><strong class="TextoCinzaGrande">NÍVEL DE ACESSO: <?php echo NomeUsuario($_GET['idusuario']);?></strong></td>
        <td width="786" align="right"><img src="img/icone_atualizar.png" width="24" height="28" onClick="window.location.reload()" style="cursor:pointer"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="top"><table width="98%" border="0" cellspacing="2" cellpadding="0" bgcolor="#FFFFFF">
      <tr>
        <td width="863" colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3" align="center">
            <table width="100%" border="0" align="center" cellpadding="3" cellspacing="3" style="border:1px solid #333;">
              <tr>
                <td style="background-color:#CCC;"><strong>ITEM</strong></td>
                <td style="background-color:#CCC;"><strong>PROGRAMA</strong></td>
                <td width="100" align="center" style="background-color:#CCC;"><strong>AÇÃO</strong></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="center">&nbsp;</td>
              </tr>
              <?php
	  $contservico = 1;

	  $SelecionaCategoriaGeral = Seleciona("menus", "WHERE liberado='sim'", "ORDER BY ordem ASC");
	  while($Categoria = mysql_fetch_array($SelecionaCategoriaGeral)){
	  
		  
	  ?>
              <tr >
                <td height="30" style="border:1px solid #333; color: #FFF; background-color:#666666;"><strong><?php echo $contservico;?></strong></td>
                <td style="border:1px solid #333; color: #FFF; background-color:#666666;"><strong><?php echo $Categoria['titulo'];?></strong></td>
                <td align="center" style="border:1px solid #333; background-color:#666666;">&nbsp;</td>
              </tr>
              <?php
	  $SelecionaServicosDetalhe = Seleciona("programas", "WHERE idmenu='".$Categoria['idmenu']."' AND liberado='sim'", "ORDER BY titulo ASC");
	  $contproduto = 1;
	  while($Servico_Detalhe = mysql_fetch_array($SelecionaServicosDetalhe)){
	
//VERIFICA SE JÁ EXISTE MENU

$SelecionaMenuUsuario = Seleciona("usuarios_programas", "WHERE idusuario='".$_GET['idusuario']."' AND idmenu='".$Categoria['idmenu']."' AND idprograma='".$Servico_Detalhe['idprograma']."'", "");
while($usuario_programa = mysql_fetch_array($SelecionaMenuUsuario)){
	$acao_usuario = $usuario_programa['acao'];	
}

if($acao_usuario != ""){
$cor = 	"#B8DDF1";
}
		  	  
	  ?>
              <tr bgcolor="<?php echo $cor;?>">
                <td height="30" style="border:1px solid #333;"><?php echo $contservico.".".$contproduto;?></td>
                <td style="border:1px solid #333;"><?php echo $Servico_Detalhe['titulo'];?></td>
                <td align="center" style="border:1px solid #333;"><span style="color: #676767;  font-size: 12px;">

                  <input type="hidden" id="idmenu<?php echo $Servico_Detalhe['idprograma'];?>" name="idmenu<?php echo $Servico_Detalhe['idprograma'];?>" value="<?php echo $Servico_Detalhe['idmenu'];?>">
                  
                  <input type="hidden" id="idprograma<?php echo $Servico_Detalhe['idprograma'];?>" name="idprograma<?php echo $Servico_Detalhe['idprograma'];?>" value="<?php echo $Servico_Detalhe['idprograma'];?>">
                  
                  <select size="1" name="acao<?php echo $Servico_Detalhe['idprograma'];?>" id="acao<?php echo $Servico_Detalhe['idprograma'];?>" class='form-control' onchange="AlterarAdicionados(<?php echo $Servico_Detalhe['idprograma'];?>);"  onfocus="this.style.backgroundColor='#ff0';" onblur="this.style.backgroundColor='';">
                    <option value="" <?php if($acao_usuario == ""){ echo "Selected";}?>>Desativado</option>
                    <option value="Visualizar" <?php if($acao_usuario == "Visualizar"){ echo "Selected";}?>>Visualizar</option>
                    <option value="Inserir" <?php if($acao_usuario == "Inserir"){ echo "Selected";}?>>Inserir</option>
                    <option value="Editar" <?php if($acao_usuario == "Editar"){ echo "Selected";}?>>Editar</option>
                    <option value="Completa" <?php if($acao_usuario == "Completa"){ echo "Selected";}?>>Completa</option>                    </select>
                </span></td>
              </tr>
              <?php
	  $acao_usuario = ""; 
	  $cor = "";
	  $contproduto++;	  
	  }
	  
	  $contproduto = 1;	  
	  $contservico++;	  
	  }
	  ?>
            </table>
          </td>
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <!-- LINHA DADOS -->
  
  </table>
  
    <script type="text/javascript">
function AlterarAdicionados(idprograma)
{
	
	var dadosajax = {
        'idusuario' : <?php echo $_GET['idusuario'];?>,
        'idprograma' : $("#idprograma" + idprograma).val(),
        'idmenu' : $("#idmenu" + idprograma).val(),
        'acao' : $("#acao" + idprograma).val(),				
    };
    pageurl = 'ajax/AlterarNivelUsuario.php';
    //para consultar mais opcoes possiveis numa chamada ajax
    //http://api.jquery.com/jQuery.ajax/
    $.ajax({
	
        //url da pagina
        url: pageurl,
        //parametros a passar
        data: dadosajax,
        //tipo: POST ou GET
        type: 'POST',
        //cache
        cache: false,
        //se ocorrer um erro na chamada ajax, retorna este alerta
        //possiveis erros: pagina nao existe, erro de codigo na pagina, falha de comunicacao/internet, etc etc etc
        error: function(){
            alert('Erro: Alterar Registo!!');
        },
        //retorna o resultado da pagina para onde enviamos os dados
        success: function(result)
        { 
            //se foi inserido com sucesso
            if($.trim(result) == '1')
            {
			//window.location.reload();		
			//document.location.reload(true);
			//alert("DEU CERTO");
			//$("#valor_total" + idproduto_venda).html(this.total_final);
            }
            //se foi um erro
            else
            {
                alert("Ocorreu um erro ao inserir o seu registo!");
            }

        }
    });
}
</script>

</body>
</html>