<?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_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO pagamentos (id_clientes, nome_clientes, `data`, mes_pgto, valor, obs) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_clientes'], "int"),
                       GetSQLValueString($_POST['nome_clientes'], "text"),
                       GetSQLValueString($_POST['data'], "date"),
					   GetSQLValueString($_POST['mes'], "text"),
                       GetSQLValueString($_POST['valor'], "text"),
                       GetSQLValueString($_POST['obs'], "text"));

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

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

mysql_select_db($database_controle, $controle);
$query_pgto = "SELECT * FROM pagamentos";
$pgto = mysql_query($query_pgto, $controle) or die(mysql_error());
$row_pgto = mysql_fetch_assoc($pgto);
$totalRows_pgto = mysql_num_rows($pgto);

$colname_clientes = "-1";
if (isset($_GET['id'])) {
  $colname_clientes = $_GET['id'];
}
mysql_select_db($database_concontrol, $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='http://fonts.googleapis.com/css?family=Text+Me+One' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Petit+Formal+Script' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Cinzel:400,700' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Josefin+Slab:400,700,700italic' rel='stylesheet' type='text/css'/>
<link href="../css/estilos_clientes.css" rel="stylesheet" type="text/css" />
<script src= "../../jquery/jquery-1.7.1.js" type="text/javascript"></script>
<script src= "../../jquery/jquery.maskedinput-1.2.2.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($){ 
     $("#data_pgto").mask("99/99/9999");
	 });
</script>
</head>

<body>
<div id="inserirpgto">

<?php include "../funcoes/data_extenso.php"; ?>
<table width="305" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" class="style9"><?php echo $row_clientes['Nome']; ?></td>
  </tr>
  <tr>
    <td align="left"><form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
      <table width="304" border="0" align="left" cellpadding="0" cellspacing="10">
        
        <tr>
          <td colspan="2" align="center">&nbsp;</td>
        </tr>
        <tr>
          <td width="77" align="right"><span class="style9">Data pgto.</span></td>
          <td width="257"><label>
            <input name="data" type="text" id="data" value="<?php echo date('Y-m-d');?>" />
          </label></td>
        </tr>
          <tr  ><td width="98" align="right"><span class="style9">Mês pgto:</span></td>
          <td width="522"><label for="mes"></label>
            <input name="mes" type="text" id="mes" value="<?php echo "$mes_port";?>"/></td>
        
        <tr>
          <td align="right" class="style9">Valor: R$</td>
          <td><label>
            <input name="valor" type="text" id="valor"  placeholder="000,00"/>
          </label></td>
        </tr>
        <tr>
          <td><span class="style9">Observação:</span></td>
          <td><label>
            <textarea name="obs" id="obs" cols="30" rows="5"></textarea>
          </label></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><input type="submit" name="button" id="button" value="Inserir" /></td>
          </tr>
      </table>
        <input type="hidden" name="MM_insert" value="form1" />
        <input name="id_clientes" type="hidden" id="id_clientes" value="<?php echo $row_clientes['id']; ?>" />
        <input name="nome_clientes" type="hidden" id="nome_clientes" value="<?php echo $row_clientes['Nome']; ?>" />
         
    </form>    </td>
  </tr>
  <tr>
    <td align="center"><a href="lista_clientes.php" target="inicial">VOLTAR</a></td>
  </tr>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($pgto);

mysql_free_result($clientes);
?>



</head>

<body>
</body>
</html>