Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/08/2008, 08:38
cccardenaso
 
Fecha de Ingreso: mayo-2008
Mensajes: 11
Antigüedad: 16 años
Puntos: 0
Respuesta: Departamento, Ciudad, Modificar

mecliente.php

<?php
session_start();
$clie=$_SESSION['cliente'];
$grup=$_SESSION['grupo'];
$cont=$_SESSION['contrato'];
$campo=$_SESSION['campop'];

include ("archivos/plantilla.php");
$obj= new interfaz();
$obj->amgsup($dom1,$clie,$cont,$campo,$_SESSION['login']);
$db1= new DBase();
?>
<html>
<head>
<script language="JavaScript" type="text/JavaScript">

function MM_reloadPage(init)
{ //reloads the window if Nav4 resized
if (init==true) with (navigator)
{
if ((appName=="Netscape")&&(parseInt(appVersion)==4))
{
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
}
}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
}

MM_reloadPage(true);
allsub = false

function traerInfo(tipo,cod)
{
var http = null;
var strcadena;
var stHtml;
if(window.XMLHttpRequest)
http = new XMLHttpRequest();
else if (window.ActiveXObject)
http = new ActiveXObject("Microsoft.XMLHTTP");
http.onreadystatechange = function()
{
if((http.readyState == 4) && (http.status == 200))
{
strcadena = http.responseText;

if(tipo=="cl_nit")
{
cliente.innerHTML = strcadena;
/*alert(strcadena);*/
}
}
}
if (tipo=="cl_nit")
{
http.open('GET', 'ajax2.php?cl_nit=' + cod, true);
http.send("");
}
}

function traerInfo2(tipo,cod,cl_nit,orden)
{
var http = null;
var strcadena;
var stHtml;

if(window.XMLHttpRequest)
http = new XMLHttpRequest();
else if (window.ActiveXObject)
http = new ActiveXObject("Microsoft.XMLHTTP");

http.onreadystatechange = function()
{
if((http.readyState == 4) && (http.status == 200))
{
strcadena = http.responseText;

if(tipo=="depto")
{
dpto.innerHTML = strcadena;
}
}
}

if (tipo=="depto")
{
http.open('GET', 'ajax1.php?depto=' + cod +'&cliente='+ cl_nit +'&orden='+ orden, true);
http.send("");
}
}
</script>
<link href="archivos/styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<?
// Comprobar errores
$error = false;

if (isset($modi))
{
// Validación de Campos
// Departamento
if (trim($depto) == 0)
{
$errores["depto"] = "Departamento no puede ser Vac&iacute;o";
$error = true;
}
else
$errores["depto"] = "";

// Ciudad
if (trim($cl_ciudad) == 0)
{
$errores["cl_idciudad"] = "Ciudad no puede ser Vac&iacute;o";
$error = true;
}
else
$errores["cl_idciudad"] = "";
}

if (isset($modi) && $error==false)
{
$psql=$db1->ejecutar("UPDATE `cliente`
SET `cl_razon` = '$cl_razon',
`cl_iddepto` = '$depto',
`cl_idciudad` = '$cl_ciudad',
WHERE `cl_nit` = '$cl_nit'");
COMMIT;
mensaje1();
}
else
{
?>
<p align="center" class="titulo">Modificar Cliente</p>
<form name="forma" method="get" onSubmit="return checkSubmit()" ACTION="<?php echo $php_self?>">
<table width="350" align="center" height="200" border=0 cellpadding=1 cellspacing=4 background="archivos/cuadro.jpg">
<tr>
<td bordercolor="#FFDB70" class="texto">&nbsp;Cliente
<select name="cl_nit" onChange="traerInfo(this.name,this.value);" class="texto">
<option value="" selected>Seleccione</option>
<?
$rds4 = $db->ejecutar("SELECT *
FROM `cliente`
ORDER BY `cl_razon` asc");
while($row = mysql_fetch_array($rds4))
{
?>
<option value="<? echo $row["cl_nit"];?>"><? echo $row["cl_razon"];?></option>
<?
}
?>
</select>
<div align="left">
<span id="cliente" name="cliente"></span>
</div>
</td>
</tr>
<tr>
<td bordercolor="#FED83D" align="center">
<input name="modi" class="texto" type=submit value="Modificar" onClick="validar();">
<input type="button" value="Cancelar" name="cancelar" class="texto" id="cancelar" onClick="cancelar1();" />
</td>
</tr>
<script>
cl_nit_value = '<? echo $cl_nit?>';
traerInfo('cl_nit',cl_nit_value);
</script>
<?
if($error==true)
{
?>
<table width="350" align="center" border=0 cellpadding=1 cellspacing=4 background="archivos/cuadro.jpg">
<tr>
<td bordercolor="#FFDB70" class="texto">

<?
print ("<BR><P CLASS='red' align='left'><img src=archivos/warning.jpg> Tenga en cuenta que:</P>");
}
if ($errores["depto"] != "")
print ("<BR><SPAN CLASS='red'> * " . $errores["depto"] . "</SPAN>");
if ($errores["cl_idciudad"] != "")
print ("<BR><SPAN CLASS='red'> * " . $errores["cl_idciudad"] . "</SPAN>");
?>
</td>
</tr>
</table>
<?
}
?>
</table>
</form>
</BODY>
</HTML>

ajax1.php

<?
// Ciudad de acuerdo del Dpto
if(isset($_GET['depto']))
{
$rds2 = $db->ejecutar("SELECT *
FROM `cliente`
WHERE `cl_nit` ='".$_GET['cliente']."'");

while($row = mysql_fetch_array($rds2))
{
$iddepto = $row['cl_iddepto'];
$idciudad = $row['cl_idciudad'];

$rds3 = $db->ejecutar("SELECT *
FROM `ciudad`
WHERE `ci_idciudad`='$idciudad'");

while($row = mysql_fetch_array($rds3))
{
$ciudadnombre = $row["ci_ciudad"];
}
mysql_free_result($rds3);

$rds4 = $db->ejecutar("SELECT *
FROM `departamento`
WHERE `de_iddepto`='$iddepto'");

while($row = mysql_fetch_array($rds4))
{
$deptonombre = $row["de_nombre"];
}
mysql_free_result($rds4);
}
mysql_free_result($rds2);

if($iddepto == $_GET['depto'])
{
$res = "<Select name='cl_ciudad' class='texto'>
<option value=".$idciudad." selected>".$ciudadnombre."</option>";

$rds = $db->ejecutar("SELECT *
FROM `ciudad`
WHERE `ci_iddepto` = '$iddepto'
AND `ci_idciudad` != '$idciudad'
ORDER BY `ci_ciudad` ASC");
while($row = mysql_fetch_array($rds))
{
$res =$res."<option value=".$row["ci_idciudad"].">".$row["ci_ciudad"]."</option>";
}
}
else
{
$res = "<Select name='cl_ciudad' class='texto'>
<option value=0 selected>Seleccione</option>";
$rds = $db->ejecutar("SELECT *
FROM `ciudad`
WHERE `ci_iddepto` = '".$_GET['depto']."'
ORDER BY `ci_ciudad` ASC");

while($row = mysql_fetch_array($rds))
{
$res =$res."<option value=".$row["ci_idciudad"].">".$row["ci_ciudad"]."</option>";
}
}
mysql_free_result($rds);
echo $res."</select>";

echo "<BR><SPAN CLASS='red'> ( Actualmente Departamento ".$deptonombre." Ciudad ".$ciudadnombre." )</SPAN>";
}
?>

ajax2.php

<?
// Es para traer Datos Clientes
if(isset($_GET['cl_nit']))
{
$rds1 = $db->ejecutar("select * from `cliente` WHERE `cl_nit` = '".$_GET['cl_nit']."'");
while($row = mysql_fetch_array($rds1))
{
$cl_nit = $row["cl_nit"];
$cl_iddepto = $row["cl_iddepto"];
$cl_idciudad = $row["cl_idciudad"];
?>
<table width="837" align="center">
<tr>
<td height="40" bgcolor="#ffffff" bordercolor="#ffffff" class="texto" colspan="5"><strong>Datos del Cliente </strong> </td>
</tr>
<tr>
<td class="texto">NIT</td>
<td width="386">
<input type="text" class="texto" readonly name="cl_nit" size="20" maxlength="20" value="<? echo $cl_nit ?>" /></td>
</tr>
<tr>
<td bordercolor="#ffffff" class="texto">Departamento</td>
<td>
<?
$rds2 = $db->ejecutar("SELECT *
FROM `departamento`
WHERE `de_iddepto`= '$cl_iddepto'");
while($row = mysql_fetch_array($rds2))
{
$de_iddepto= $row["de_iddepto"];
$de_nombre= $row["de_nombre"];
}
mysql_free_result($rds2);

/*OJO al enviar valores con 0 antes deben enviar como se muestra en este onchange*/
$res = "<Select name='depto' class='texto' class='texto' onChange=\"traerInfo2(this.name,this.value,'$cl_ni t',1);\">
<option value=".$de_iddepto." selected>".$de_nombre."</option>";
$rds = $db->ejecutar("SELECT *
FROM `departamento`
WHERE `de_iddepto` != $cl_iddepto
ORDER BY `de_nombre` ASC" );
while($row = mysql_fetch_array($rds))
{
$res =$res."<option value=".$row["de_iddepto"].">".$row["de_nombre"]."</option>";
}
mysql_free_result($rds);
echo $res."</select>";
?>
</td>
<td width="88" bordercolor="#ffffff" class="texto">Ciudad</td>
<td height="23" bordercolor="#ffffff" class="texto" colspan="2">
<span id="dpto" name="dpto"> </span>
</td>
</tr>
</table>
<? }
}
// ---------------------------------------------------------------Fin Clientes
?>