<?php require_once('../Connections/cn_conexion.php'); ?>
<?php
$id_cli=$_GET['id_cli'];
?>
<?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_distrito = "SELECT * FROM distrito WHERE (distrito.iddep='15' OR  distrito.iddep='07' )  AND distrito.idprov='01' ORDER BY distrito.distrito ASC";
$rs_distrito = mysql_query($query_rs_distrito, $cn_conexion) or die(mysql_error());
$row_rs_distrito = mysql_fetch_assoc($rs_distrito);
$totalRows_rs_distrito = mysql_num_rows($rs_distrito);

mysql_select_db($database_cn_conexion, $cn_conexion);
$query_rs_cliente = "SELECT * FROM clientes WHERE clientes.id_cliente='".$id_cli."'";
$rs_cliente = mysql_query($query_rs_cliente, $cn_conexion) or die(mysql_error());
$row_rs_cliente = mysql_fetch_assoc($rs_cliente);
$totalRows_rs_cliente = mysql_num_rows($rs_cliente);
?>
<form id="form2" name="form2" method="POST" action="index.php">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="30" colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="74%"><p class="rot_man">&nbsp;&nbsp;&nbsp;&nbsp;Modificar  Cliente</p></td>
          <td width="26%"><p class="rot_man"><a href="index.php" class="enlace_blanco">Nuevo Cliente</a></p></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td width="58%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Empresa
            <input name="id_cliente" type="hidden" id="id_cliente" value="<?php echo $row_rs_cliente['id_cliente']; ?>" /></td>
        </tr>
        <tr>
          <td><input name="nom_cliente" type="text" class="fn_text" id="nom_cliente" value="<?php echo $row_rs_cliente['nom_cliente']; ?>" size="40" /></td>
        </tr>
      </table></td>
      <td width="39%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>RUC</td>
        </tr>
        <tr>
          <td><input name="ruc" type="text" class="fn_text" id="ruc" value="<?php echo $row_rs_cliente['ruc_cliente']; ?>" maxlength="11" /></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td width="3%">&nbsp;</td>
      <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Nombre Cliente            </td>
        </tr>
        <tr>
          <td><input name="contacto" type="text" id="contacto" size="75" class="fn_text"  value="<?php echo $row_rs_cliente['contacto']; ?>"/></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Dirección</td>
        </tr>
        <tr>
          <td><input name="direccion" type="text" class="fn_text" id="direccion" value="<?php echo $row_rs_cliente['dir_cliente']; ?>" size="40" /></td>
        </tr>
      </table></td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Distrito</td>
        </tr>
        <tr>
          <td><select name="distrito" id="distrito" class="fn_text">
            <?php
do {  
?>
            <option value="<?php echo $row_rs_distrito['id']?>" 
			<?php 
			if($row_rs_distrito['id']==$row_rs_cliente['dis_cliente']){
				echo 'selected="selected"';
			} ?>>
			<?php echo $row_rs_distrito['distrito']?></option>
            <?php
} while ($row_rs_distrito = mysql_fetch_assoc($rs_distrito));
  $rows = mysql_num_rows($rs_distrito);
  if($rows > 0) {
      mysql_data_seek($rs_distrito, 0);
	  $row_rs_distrito = mysql_fetch_assoc($rs_distrito);
  }
?>
          </select></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Telefono</td>
        </tr>
        <tr>
          <td><input name="telefono" type="text" class="fn_text" id="telefono" value="<?php echo $row_rs_cliente['telf_cliente']; ?>" maxlength="7" /></td>
        </tr>
      </table></td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Celular</td>
        </tr>
        <tr>
          <td><input name="Celular" type="text" class="fn_text" id="Celular" value="<?php echo $row_rs_cliente['cel_cliente']; ?>" maxlength="9" /></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Email</td>
        </tr>
        <tr>
          <td><input name="email" type="text" class="fn_text" id="email" value="<?php echo $row_rs_cliente['email_cliente']; ?>" size="40" /></td>
        </tr>
      </table></td>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Habilitado</td>
        </tr>
        <tr>
          <td><input <?php if (!(strcmp($row_rs_cliente['hab_cliente'],"1"))) {echo "checked=\"checked\"";} ?> name="hab_cliente" type="radio" id="radio" value="1"  />
            Si&nbsp;&nbsp;
            <input <?php if (!(strcmp($row_rs_cliente['hab_cliente'],"0"))) {echo "checked=\"checked\"";} ?> name="hab_cliente" type="radio" id="radio2" value="0" />
            No </td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td height="30">&nbsp;</td>
      <td><input type="submit" name="button2" id="button2" value="Actualizar" /></td>
    </tr>
  </table>
  <input name="MM_update" type="hidden" id="MM_update" value="form2" />
</form>
<?php
mysql_free_result($rs_distrito);

mysql_free_result($rs_cliente);
?>
