<?php require_once('../Connections/cn_conexion.php'); ?>
<?php
$numcajas=$_GET["num_cajas"];
$idcliente=$_GET["id_cliente"];
?>
<?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;
}
}

mysql_select_db($database_cn_conexion, $cn_conexion);
$query_rs_numcaja = "SELECT * FROM caja_gastos WHERE caja_gastos.id_cliente='".$idcliente."' AND caja_gastos.hab_cajagasto='1'";
$rs_numcaja = mysql_query($query_rs_numcaja, $cn_conexion) or die(mysql_error());
$row_rs_numcaja = mysql_fetch_assoc($rs_numcaja);
$totalRows_rs_numcaja = mysql_num_rows($rs_numcaja);

?>
<?php
if($totalRows_rs_numcaja==1){
	$numcaja=$row_rs_numcaja['num_caja'];
	$insert_caja='0';
	}else{
		$numcaja=$numcajas+1;
		$insert_caja='1';
		}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Numero de Caja</td>
  </tr>
  <tr>
    <td><input name="numcaja" type="text" class="fn_text" id="numcaja" value="<?php echo($numcaja);?>" size="15" />
    <input name="insert_caja" type="hidden" id="insert_caja" value="<?php echo($insert_caja);?>"></td>
  </tr>
</table>
<?php
mysql_free_result($rs_numcaja);
?>
