<?php require_once('../Connections/conn_sustentabilidade.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_tipo_insere")) {
  $insertSQL = sprintf("INSERT INTO tbtipos (id_tipo, sigla_tipo, rotulo_tipo) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['id_tipo'], "int"),
                       GetSQLValueString($_POST['sigla_tipo'], "text"),
                       GetSQLValueString($_POST['rotulo_tipo'], "text"));

  mysql_select_db($database_conn_sustentabilidade, $conn_sustentabilidade);
  $Result1 = mysql_query($insertSQL, $conn_sustentabilidade) or die(mysql_error());

  $insertGoTo = "tipo_lista.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
	<title>Tipos - Insere</title>
	<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
<section id="topo" class="container-fluid">
	<a href="tipo_lista.php"><h4><span class="glyphicon glyphicon-menu-left "></span> Voltar</h4></a>
	<section id="titulo" class="container">
		<h1>Tipos - Insere</h1>
		<hr>
	</section>
</section>
<section id="insere_centro" class="container-fluid">
  <section id="form" class="container">
  <form name="form_tipo_insere" action="<?php echo $editFormAction; ?>" method="POST" id="form_rotulo_insere" enctype="multipart/form-data">
            	<label for="rotulo_tipo">Rótulo:</label>
                <p class="input-group">
					<span class="input-group-addon"></span>
                    <input name="rotulo_tipo" class="form-control input" type="text" id="rotulo_tipo" maxlength="15" required placeholder="Digite o rótulo">
				</p>
                <label for="sigla_tipo">Sigla:</label>
                <p class="input-group">
					<span class="input-group-addon"></span>
                    <input name="sigla_tipo" class="form-control input" type="text" id="sigla_tipo" maxlength="3" required placeholder="Digite uma sigla" >
                </p>
		
                <p><div class="btn-group btn-group-justified" role="group" aria-label="...">
					<div class="btn-group" role="group">
						<input class="btn btn-success btn-block" type="submit" value="Atualizar">
					</div>
					<div class="btn-group" role="group">
	            		<input class="btn btn-danger btn-block" type="reset" value="Limpar">
					</div>
	  			</div></p>
                <input type="hidden" name="MM_insert" value="form_tipo_insere">
            </form>
		</section>
	</section>
	<!-- Jquery (obrigatório para plugin JS do Bootstrap) -->
<script src="../bootstrap/jquery.min.js"></script>

	<!-- Plugin JS-->
<script src="../bootstrap/js/bootstrap.min.js"></script>
</body>
</html>