<?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;
}
}

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;
}
}

$colname_clientes = "-1";
if (isset($_GET['id'])) {
  $colname_clientes = $_GET['id'];
}
$id_url = $_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);

$colname_pgto = "-1";
if (isset($_GET['id'])) {
  $colname_pgto = $_GET['id'];
}
mysql_select_db($database_controle, $controle);
$query_pgto = sprintf("SELECT * FROM pagamentos WHERE id_clientes = %s ORDER BY id DESC", GetSQLValueString($colname_pgto, "int"));
$pgto = mysql_query($query_pgto, $controle) or die(mysql_error());
$row_pgto = mysql_fetch_assoc($pgto);
$totalRows_pgto = mysql_num_rows($pgto);
?>
<!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" />
</head>

<body>

<div id="fichaclientes"> 
  
<table width="680"  class="table22">
  <tr>
    <td align="left"><a href="lista_clientes.php" target="_self">VOLTAR</a></td>
    <td align="left">&nbsp;</td>
  </tr>
  <tr>
    <td width="257" align="right">EMPRESA:</td>
    <td width="423" align="left"><h2><?php echo $row_clientes['Nome']; ?></h2></td>
  </tr>
  <tr>
    <td align="right">URL:</td>
    <td align="left"><h2><?php echo $row_clientes['Url_Site']; ?></h2></td>
  </tr>
  <tr>
    <td align="right">Data Início:</td>
    <td align="left"><h2><?php echo $row_clientes['Data_Inicio']; ?></h2></td>
  </tr>
  <tr>
    <td align="right">Valor Inicial:</td>
    <td align="left"><h2><?php echo $row_clientes['Valor_Inicial']; ?></h2></td>
  </tr>
  <tr>
    <td align="right">Valor Mensal:</td>
    <td align="left"><h2><?php echo $row_clientes['Valor_Mensal']; ?></h2></td>
  </tr>
  <tr>
    <td align="right">Observação:</td>
    <td align="left"><h2><?php echo $row_clientes['obs']; ?></h2></td>
  </tr>
  <tr>
    <td colspan="2" align="right">&nbsp;</td>
  </tr>
</table>
<table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="321" align="left"><h4>MÊS</h4></td>
    <td width="47"><h4>DATA</h4></td>
    <td width="312" align="right"><h4>VALOR</h4></td>
  </tr>
</table>
<table width="600" align="center" >
  <tr>
    <?php
$pgto_endRow = 0;
$pgto_columns = 1; // number of columns
$pgto_hloopRow1 = 0; // first row flag
do {
    if($pgto_endRow == 0  && $pgto_hloopRow1++ != 0) echo "<tr>";
   ?>
    <td>
    <div class=" table22"><table class="table22">
      <tr>
        <td width="180" align="left"><?php echo $row_pgto['mes_pgto']; ?></td>
        <td width="122" align="center"><?php echo date('d-m-Y', strtotime($row_pgto[data]));?></td>
        <td width="162" align="right">R$&nbsp; <?php echo $row_pgto['valor']; ?></td>
      </tr>
    </table></div></td>
    <?php  $pgto_endRow++;
if($pgto_endRow >= $pgto_columns) {
  ?>
    </tr>
  <?php
 $pgto_endRow = 0;
  }
} while ($row_pgto = mysql_fetch_assoc($pgto));
if($pgto_endRow != 0) {
while ($pgto_endRow < $pgto_columns) {
    echo("<td>&nbsp;</td>");
    $pgto_endRow++;
}
echo("</tr>");
}?>
</table>

</div><!---FIM FICHACLIENTES--->


</body>
</html>
<?php
mysql_free_result($clientes);

mysql_free_result($pgto);
?>
