Location: PHPKode > projects > SolBT > sol/tipos_de_chamado.php
<?php
  include("../sol/sessao.php");
  
  //Verifica permissao
  $nivelnecessario = 0;
  if ($_SESSION["univel"] > $nivelnecessario)
  {
    header('Location:/sol/index.php?erroperm='.$nivelnecessario);
  }
  
  //Alterar estas variaveis para cadastro
  $pagina_nome = "Tipo de chamado";
  $maxcampodescricao = 50;
  $tabela = "tipos_de_chamado";
  $campoid = "id_tipos";
  $campo_descricao = "tipo";
?>
<!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 AtivaEdicao(campoID)
      {
        EsconderForms();
        
        document.getElementById('frm' + campoID).style.display = '';
        document.getElementById('a' + campoID).style.display = 'none';
        document.getElementById('i' + campoID).style.display = 'none';
        document.getElementById('edt' + campoID).value = document.getElementById('a' + campoID).innerHTML;
        document.getElementById('edt' + campoID).focus();
      }
      
      function EsconderForms()
      {
        for (var i = 0; i < document.forms.length - 1; i++)
        {
          document.getElementById('frm' + i).style.display = 'none';
          document.getElementById('a' + i).style.display = '';
          document.getElementById('i' + i).style.display = '';
        }
      }
      
      function Esconde(campoID)
      {
        document.getElementById('frm' + campoID).style.display = 'none';
      }
      
      function TrimCampo(campoID)
      {
        String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
        document.getElementById('edt' + campoID).value = document.getElementById('edt' + campoID).value.trim();
      }
    </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 />
          <span class="Titulo">Cadastro de <?=strtolower($pagina_nome)?></span><br />&nbsp;<br />
          <p id="avisoexc" style="display:none; color:#FF0000;"><em>Este registro n&atilde;o pode ser exclu&iacute;do pois possui lan&ccedil;amentos vinculados a ele.</em></p>
          <table cellspacing="1" cellpadding="3" style="background-color:#666666;">
            <tr style="color:#FFFFFF; font-weight:bold;">
              <td align="center">ID</td><td><?=$pagina_nome?></td>
            </tr>
            <?php
              //Conecta ao banco e abre query
              $dados = new dados();
              $dados->get_conexao();
              
              $temfilhos = false;
              
              //Atualiza
              if (($_GET["acao"] == "editar") || ($_GET["acao"] == "inserir") || ($_GET["acao"] == "excluir"))
              {
                $idx = str_replace('#', '', $_GET["id"]);
              
                if ($_GET["acao"] == "editar")
                {
                  if (!empty($_POST["edt".$idx]))
                  {
                    $sql = "UPDATE ".$tabela." SET ".$campo_descricao." = '".TrataStr($_POST["edt".$idx])."' WHERE ".$campoid." = ".$idx;
                    mysql_query($sql);
                  }
                }
                if ($_GET["acao"] == "excluir")
                {
                  //Andamentos
                  $sql = "SELECT * FROM chamados WHERE tipo = ".$idx;
                  $rs = mysql_query($sql);
                  
                  if (mysql_num_rows($rs) > 0) $temfilhos = true;
                
                  if (!$temfilhos)
                  {
                    $sql = "DELETE FROM ".$tabela." WHERE ".$campoid." = ".$idx;
                    mysql_query($sql);
                  }
                }
                else
                {
                  if (!empty($_POST["edtCampo"]))
                  {
                    $sql = "INSERT INTO ".$tabela." (".$campo_descricao.") VALUES ('".TrataStr($_POST["edtCampo"])."')";
                    mysql_query($sql);
                  }
                }
              }
              
              $sql = "SELECT * FROM ".$tabela." ORDER BY ".$campo_descricao." ASC";
              
              $rs = mysql_query($sql);
              
              $i = 1;
              
              while ($reg = mysql_fetch_array($rs))
              {
                $valorcampo = utf8_encode($reg[$campo_descricao]);
                $y = $reg[$campoid];
            ?>
            <tr style="background-color:#<? if ($i % 2 == 0) echo "E8E8E8"; else echo "FFFFFF"; ?>;">
              <td align="center" valign="middle"><?=($y)?></td>
              <td valign="middle">
                <!-- CAMPO -->
                <a id="a<?=($i - 1)?>" style="cursor:pointer;" onclick="AtivaEdicao(<?=($i - 1)?>);"><?=$valorcampo?></a>
                <img src="/sol/includes/excluir.gif" border="0" id="i<?=($i - 1)?>" alt="Excluir..." align="top" onclick="if (confirm('Confirmar exclusão de <?=TrataStrForJS($valorcampo)?>?')) window.open('<?=$_SERVER["PHP_SELF"]?>?acao=excluir&id=<?=($y)?>', '_self');" style="cursor:pointer;" title="Excluir..." />
                <form action="<?=$_SERVER["PHP_SELF"]?>?acao=editar&id=<?=$y?>" method="post" id="frm<?=($i - 1)?>" onsubmit="TrimCampo(<?=($i - 1)?>);">
                  <input type="text" id="edt<?=($i - 1)?>" name="edt<?=$y?>" value="<?=$valorcampo?>" maxlength="<?=$maxcampodescricao?>" size="<?=$maxcampodescricao?>" onblur="TrimCampo(<?=($i - 1)?>);" />
                  <input type="submit" value="OK" id="btn<?=($i - 1)?>" style="font-weight:bold;" />
                  <input type="button" value="Cancelar" onclick="EsconderForms();" />
                </form>
                <!-- FIM DO CAMPO -->
                <script language='JavaScript' type="text/javascript">Esconde(<?=($i - 1)?>);</script>
              </td>
            </tr>
            <?php
                $i++;
              }
            ?>
          </table>
          <br />&nbsp;<br />
          <strong>Inserir novo registro</strong><br />&nbsp;<br />
          <form action="<?=$_SERVER["PHP_SELF"]?>?acao=inserir" method="post" id="frmInserir" onsubmit="TrimCampo('Campo');" onreset="document.getElementById('edtCampo').focus();">
            <?=$pagina_nome?>: <input type="text" id="edtCampo" name="edtCampo" value="" maxlength="<?=$maxcampodescricao?>" size="<?=$maxcampodescricao?>" onblur="TrimCampo('Campo');" onfocus="EsconderForms();" />
            <input type="submit" value="OK" id="btnCampo" style="font-weight:bold;" />
            <input type="reset" value="Cancelar" />
          </form>
          <br />&nbsp;<br />
        </td>
      </tr>
      <!-- FIM DE CONTEUDO DA PAGINA -->
      
      <?php
        include("../sol/includes/rp.php");
      ?>
    </table>
  </body>
  <script language='JavaScript' type="text/javascript">
    <?php
      if ($temfilhos)
      {
    ?>
    document.getElementById('avisoexc').style.display = '';
    <?php
      }
    ?>
  </script>
</html>
<?php
  @mysql_close();
?>
Return current item: SolBT