<? ob_start(); ?>
<?php require_once('../../Connections/controle.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_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE clientes SET Nome=%s, Url_Site=%s, Data_Inicio=%s, Valor_Inicial=%s, Valor_Mensal=%s, obs=%s, ativo=%s WHERE id=%s",
                       GetSQLValueString($_POST['Nome'], "text"),
                       GetSQLValueString($_POST['Url_Site'], "text"),
                       GetSQLValueString($_POST['Data_Inicio'], "text"),
                       GetSQLValueString($_POST['Valor_Inicial'], "text"),
                       GetSQLValueString($_POST['Valor_Mensal'], "text"),
                       GetSQLValueString($_POST['obs'], "text"),
                       GetSQLValueString($_POST['ativo'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_controle, $controle);
  $Result1 = mysql_query($updateSQL, $controle) or die(mysql_error());

  $updateGoTo = "lista_clientes.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_clientes = "-1";
if (isset($_GET['id'])) {
  $colname_clientes = $_GET['id'];
}
mysql_select_db($database_controle, $controle);
$query_clientes = sprintf("SELECT * FROM clientes WHERE id = %s", GetSQLValueString($colname_clientes, "int"));
$clientes = mysql_query($query_clientes, $controle) or die(mysql_error());
$row_clientes = mysql_fetch_assoc($clientes);
$totalRows_clientes = mysql_num_rows($clientes);
?>
<!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>Documento sem título</title>

<link href="../css/estilos_clientes.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="editclientes">
  <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    <table width="680" align="center" cellspacing="5" class="table">
      <tr valign="baseline">
        <td colspan="2" align="center" nowrap="nowrap">&nbsp;</td>
      </tr>
      <tr valign="baseline">
        <td colspan="2" align="center" nowrap="nowrap">EDITAR CLIENTES</td>
      </tr>
      <tr valign="baseline">
        <td width="200" align="right" nowrap="nowrap">&nbsp;</td>
        <td width="459">&nbsp;</td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Nome:</td>
        <td><input type="text" name="Nome" value="<?php echo htmlentities($row_clientes['Nome'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Url do Site:</td>
        <td><input type="text" name="Url_Site" value="<?php echo htmlentities($row_clientes['Url_Site'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Data de Inicio:</td>
        <td><input type="text" name="Data_Inicio" value="<?php echo htmlentities($row_clientes['Data_Inicio'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Valor Inicial:</td>
        <td><input type="text" name="Valor_Inicial" value="<?php echo htmlentities($row_clientes['Valor_Inicial'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Valor Mensal:</td>
        <td><input type="text" name="Valor_Mensal" value="<?php echo htmlentities($row_clientes['Valor_Mensal'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right" valign="top">Observações:</td>
        <td><textarea name="obs" cols="40" rows="5"><?php echo htmlentities($row_clientes['obs'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">Ativo:</td>
        <td><input type="text" name="ativo" value="<?php echo htmlentities($row_clientes['ativo'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td nowrap="nowrap" align="right">&nbsp;</td>
        <td><input type="submit" value="Atualizar registro" /></td>
      </tr>
    </table>
    <input type="hidden" name="MM_update" value="form1" />
    <input type="hidden" name="id" value="<?php echo $row_clientes['id']; ?>" />
  </form>
  <p>&nbsp;</p>
</div>
</body>
</html>
<?php
mysql_free_result($clientes);
?>
<? ob_end_flush(); ?>