Location: PHPKode > projects > SolBT > sol/configuracoes_especiais.php
<?php
  include("../sol/sessao.php");
  
   //Verifica permissao
  $nivelnecessario = 0;
  if ($_SESSION["univel"] > $nivelnecessario)
  {
    header('Location:/sol/index.php?erroperm='.$nivelnecessario);
  }
  
  $MyNivel = 3;
  
  if (!empty($_GET['nivel'])) $MyNivel = $_GET['nivel'];

   //Conecta ao banco e abre query
  $dados = new dados();
  $dados->get_conexao();
  
  if ($_GET['acao'] == 'excluir')
  {
    $sql = "DELETE FROM permissoes_especiais WHERE id = ".$_GET['id'];
    mysql_query($sql);
  }
  
  $Duplicidade = false;
  
  if ($_GET['acao'] == 'inserir')
  {
    //Verifica se ja tem
    $sql = "SELECT COUNT(*) AS JaTemEssa FROM permissoes_especiais WHERE usuario = ".$_POST['npuser']." AND tela = '".TrataStr($_POST['nppermissao'])."'";
    
    $rs = mysql_query($sql);
    $reg = mysql_fetch_array($rs);
    
    if ($reg['JaTemEssa'] == 0)
    {
      $sql = "INSERT INTO permissoes_especiais
                (usuario, tela, descricao)
              VALUES
                (".$_POST['npuser'].", '".TrataStr($_POST['nppermissao'])."', '".TrataStr($_POST['nppermissaodescr'])."')";
      mysql_query($sql);
    }
    else
    {
      $Duplicidade = true;
    }
  }
  
  $sql = "SELECT
            u.id_usuario, u.username, d.departamento, p.id, p.descricao
          FROM
            usuarios AS u
          INNER JOIN
            departamentos AS d ON (d.id = u.id_departamento)
          LEFT JOIN
            permissoes_especiais AS p ON (p.usuario = u.id_usuario)
          WHERE
            u.nivel = $MyNivel
          ORDER BY
            u.username";
            
  $rs = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>SolBT - <?=$sitenome?></title>
    <link rel="StyleSheet" type="text/css" href="../sol/includes/estilos.css" id="estilo" />
    <script language='JavaScript' src='../sol/includes/FuncoesTela.js' type="text/javascript"></script>
    
    <script language="JavaScript" type="text/javascript">
      function getTxtPerm()
      {
        document.getElementById('nppermissaodescr').value = document.getElementById('nppermissao').options[document.getElementById('nppermissao').selectedIndex].text;
      }
    </script>
  </head>
  
  <body>
    <?php
      include("../sol/includes/menus.php");
    ?>
    
    <table width="100%">
      <?php
        include("../sol/includes/top.php");
      ?>
      
      <!-- CONTEUDO DA PAGINA -->
      <tr>
        <td id="Conteudo">
          <br />
          <? if ($Duplicidade) echo '<font color="Red"><em>* Permiss&atilde;o j&aacute; cadastrada para o usu&aacute;rio indicado.</em></font><br />&nbsp;<br />'; ?>
          <span class="Titulo">Configura&ccedil;&otilde;es especiais</span><br />&nbsp;<br />
          <strong>Permiss&otilde;es especiais para:</strong> &nbsp; <? if ($MyNivel == 3) echo "<strong style='background-color:#CCCCCC;'>&nbsp;"; ?><a href="configuracoes_especiais.php?nivel=3">Usu&aacute;rios comuns</a><? if ($MyNivel == 3) echo "&nbsp;</strong>"; ?>
          &nbsp;
          <? if ($MyNivel == 2) echo "<strong style='background-color:#CCCCCC;'>&nbsp;"; ?><a href="configuracoes_especiais.php?nivel=2">Encarregados de departamento</a><? if ($MyNivel == 2) echo "&nbsp;</strong>"; ?>
          
          <br />&nbsp;<br />
          <table cellspacing="0" cellpadding="4" style="background-color:#B8B8B8;">
            <tr style="color:#FFFFFF; font-weight:bold; background-color:#666666;">
              <td align="center">Usu&aacute;rio</td>
              <td align="center">Departamento</td>
              <td>Permiss&atilde;o especial</td>
              <td></td>
            </tr>
            <?php
              //Lista os usuarios
              $i = 1;
              $ii = 0;
              
              //Pega primeiro usuario
              $reg = mysql_fetch_array($rs);
              $usuanterior = $reg['id_usuario'];
              
              //Le todos
              $rs = mysql_query($sql);
              while ($reg = mysql_fetch_array($rs))
              {
                if ($ii == 0) $mesmo = false; else $mesmo = true;
                if ($reg['id_usuario'] != $usuanterior)
                {
                  $usuanterior = $reg['id_usuario'];
                  $mesmo = false;
                  $i++;
                }
                
                if ((!$mesmo) && ($ii > 0)) echo '<tr heigth="1"><td></td><td></td><td></td><td></td></tr>';
            ?>
            <tr style="background-color:#<? if ($i % 2 == 0) echo "E8E8E8"; else echo "FFFFFF"; ?>;">
              <td align="center"><a onclick="document.getElementById('np').style.display = ''; document.getElementById('nppermissao').focus(); document.getElementById('npusername').innerHTML = '<?=utf8_encode($reg["username"])?>'; document.getElementById('npuser').value = '<?=$reg["id_usuario"]?>'; document.getElementById('nppermissao').selectedIndex = 0;" style="cursor:pointer;" title="Cadastrar nova permiss&atilde;o especial para este usu&aacute;rio."><? if (!$mesmo) echo utf8_encode($reg["username"]); ?></a></td>
              <td align="center"><? if (!$mesmo) echo utf8_encode($reg["departamento"]); ?></td>
              <td>
                <?php
                  echo utf8_encode($reg["descricao"]);
                  if (empty($reg["descricao"])) echo ' <em>Usu&aacute;rio sem permiss&otilde;es especiais.</em>';
                ?>
              </td>
              <td>
                <? if (!empty($reg["descricao"])) { ?>
                <img src="/sol/includes/excluir.gif" border="0" alt="Excluir..." align="top" onclick="if (confirm('Confirmar exclusão?')) window.open('<?=$_SERVER["PHP_SELF"]?>?acao=excluir&id=<?=$reg['id']?>&nivel=<?=$MyNivel?>', '_self');" style="cursor:pointer;" title="Excluir..." />
                <? }  ?>
              </td>
            </tr>
            <?php
              $ii++;
              }
            ?>
            <tr heigth="1"><td></td><td></td><td></td><td></td></tr>
           </table>

          <form id="np" name="np" style="display:none;" action="<?=$_SERVER["PHP_SELF"]?>?acao=inserir&nivel=<?=$MyNivel?>" method="post">
            <br />&nbsp;<br />
            <strong>Cadastrar permiss&atilde;o especial para: <span id="npusername"></span></strong>
            <br />&nbsp;<br />
            <input type="hidden" name="npuser" id="npuser" value="" />
            Permiss&atilde;o:
            <select id="nppermissao" name="nppermissao" onchange="getTxtPerm();">
              <? if ($MyNivel == 3) { ?><option value="cad_cli">Cadastrar novo cliente</option><? } ?>
              <? if (($MyNivel == 3) || ($MyNivel == 2)) { ?><option value="cad_edt_cli">Cadastrar e editar informa&ccedil;&otilde;es de clientes</option><? } ?>
            </select>
            <input type="hidden" name="nppermissaodescr" id="nppermissaodescr" value="" />
            <script language="JavaScript" type="text/javascript">
              document.getElementById('nppermissao').selectedIndex = 0;
              getTxtPerm();
            </script>
            <input type="submit" value="OK"  style="font-weight:bold;" />
            <input type="button" onclick="document.getElementById('np').style.display = 'none';" value="Cancelar" />
          </form>
          <br />&nbsp;<br />
        </td>
      </tr>
      <!-- FIM DE CONTEUDO DA PAGINA -->
      
      <?php
        include("../sol/includes/rp.php");
      ?>
    </table>
  </body>
</html>
<?php
  @mysql_close();
?>
Return current item: SolBT