Ver Mensaje Individual
  #5 (permalink)  
Antiguo 31/03/2008, 15:02
joseverdugo
 
Fecha de Ingreso: febrero-2008
Mensajes: 8
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Refrescar lista desplegable de pagina padre desde pagina hija en ie6

Hola.

Te dejo todo el codigo, desarrollado en postgres con php5 y probado en ie6, ie7 y firefox

afp.php
Código PHP:
<!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>AFP</title>
<script type="text/javascript">
function valida_form(f)
{        
    f.submit();            
}
</script>

</head>
<!--Si esta pagina tiene padre, cargar el contenido del combo afp del padre -->
<body onLoad="if(opener != null)opener.cargaContenido('codafp')">

<?php
require("afp.class.php");
require(
"db.class.php");

$obj = new afp();
$msg='';

if(isset(
$_GET["opcion"])){
    
    if(
$_GET["opcion"] == "editar"){
        
$obj->get($_GET["codafp"]);        
    }    
    if(
$_GET["opcion"] == "save"){
        
        
$obj->setcodAfp($_GET["cod"]);

        if(
$_GET["cod"] == null)
        
$obj->setcodAfp("null");
        
$obj->setletra("null");
        
$obj->setnombre($_GET["nombre"]);
        
$obj->setporcentaje($_GET["porcentaje"]);        
        
        
$cod $obj->getcodAfp();
        
//guardando
        
$obj->save();        
        

    }
}
?>


<p><strong>Agregar/editar Afp</strong></p>
<form id="form1" name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="cod" id="cod" value="<?php echo $obj->getcodAfp();?>" />
<input type="hidden" name="opcion" id="opcion" value="save" />
  <table border="0">
    
    <tr>
      <th scope="row"><div align="left">Nombre</div></th>
      <td>
        <input type="text" name="nombre" id="nombre" tabindex="1" value="<?php echo $obj->getnombre();?>" />
     </td>
    </tr>
    <tr>
      <th scope="row"><div align="left">Porcentaje</div></th>
      <td>
        <input type="text" name="porcentaje" id="porcentaje" tabindex="2" value="<?php echo $obj->getporcentaje();?>" />
      
      </td>
    </tr>
   
  </table>
  <p>
    <label>
    <input type="button" name="button" value="Guardar" onclick="valida_form(this.form)" tabindex="4" />    
    </label>

  </p>
   
  <?php 
  
echo $msg;
  
?>
  

</form>


<?php
$obj
->verconsulta();
?>
</body>

</html>
afp.class.php
Código PHP:
<?php

class afp{
    
/*campo codAfp*/
    
private  $codAfp;
    public function 
setcodAfp($col){
        
$this->codAfp $col;
    }
    public function 
getcodAfp(){
        return 
$this->codAfp;
    }

    
/*campo nombre*/
    
private  $nombre;
    public function 
setnombre($col){
        
$this->nombre $col;
    }
    public function 
getnombre(){
        return 
$this->nombre;
    }

    
/*campo porcentaje*/
    
private  $porcentaje;
    public function 
setporcentaje($col){
        
$this->porcentaje $col;
    }
    public function 
getporcentaje(){
        return 
$this->porcentaje;
    }

    
/*campo letra*/
    
private  $letra;
    public function 
setletra($col){
        
$this->letra $col;
    }
    public function 
getletra(){
        return 
$this->letra;
    }

    function 
afp(){
        
$this->codAfp null;
        
$this->nombre null;
        
$this->porcentaje null;
        
$this->letra null;
    }
    
    function 
get($valor)
    {
        if(
$valor == null)
            return 
false;
            
        
$objDB = new db();
        
$sql "select * from \"afp\" where \"codAfp\" = $valor;";
        if(!
$objDB->query($sql) ){
            
$objDB->geterror();
            
//tratar errorreturn false;
        
}
        if(
$objDB->num() < 1){
            return 
false;
        }
        
$objetos $objDB->fetch();
        
$this->codAfp $objetos['codAfp'];
        
$this->nombre $objetos['nombre'];
        
$this->porcentaje $objetos['porcentaje'];
        
$this->letra $objetos['letra'];
        
$objDB->free();
        
$objDB->close();
        return 
$this;
    }
    
    function 
save(){
        
$objDB = new db();

        
$this->sql "select insertafp('$this->nombre', $this->porcentaje, $this->codAfp )";
        
        if(!
$objDB->query($this->sql) ){            
            return 
false;
        }

        
$cod $objDB->fetch();

        
$this->setcodAfp($cod[0]);
    }
    

    
/* Muestra los datos en una tabla html*/
    
function verconsulta() {
        
$objDB = new db();
        
$sql "select * from vista_afp";
        if(!
$objDB->query($sql) ){
            
            return 
false;
        }


        echo 
"<table border=\"2\" align=\"left\" cellpadding=\"0\" cellspacing=\"2\" >\n";
        echo 
"<tr>\n";
        
// mostramos los nombres de los campos
        
for ($i 0$i $objDB->numcampos(); $i++){
            echo 
"<td><b>".$objDB->nombrecampo($i)."</b></td>\n";
        }
        echo 
"<td><b>Editar</b></td>\n";    

        echo 
"</tr>\n";

        
// mostrarmos los registros
        
while ($row $objDB->fetch()) {

            echo 
"<tr> \n";

            for (
$i 0$i $objDB->numcampos(); $i++){
                if(
$row[$i] == null and $i == ){
                    echo 
"<td>Total</td>\n";
                }else{
                    if(
$row[$i] == null){
                        echo 
"<td align=\"center\">-</td>\n";
                    }else{
                        echo 
"<td>".$row[$i]."</td>\n";
                    }
                }

            }
            
            echo 
"<td><a href=\"".$_SERVER['PHP_SELF']."?opcion=editar&amp;codafp=".$row['Cod AFP']."\">Editar</a></td>";                        
            echo 
"</tr>\n";
            
            
        }
        echo 
"</table>";
    }

    function 
lista_select() {
        
$objDB = new db();
        
$sql "select \"codAfp\" as cod, nombre from afp order by nombre";
        if(!
$objDB->query($sql) ){            
            return 
false;
        }        

        
$n $objDB->numcampos();
        while (
$row $objDB->fetch()) {
            if(
$this->codAfp == $row['cod'])
                echo 
"<option value=\"".$row['cod']."\" selected=\"selected\">".$row['nombre']."</option>";
            else            
                echo 
"<option value=\"".$row['cod']."\">".$row['nombre']."</option>";

        }
    }


}
?>