<?php
$target = 'nombre';
include("funciones/funciones_backup.php");
include("conexion/conexion.php");
include("Menu/menu_inicio.php");
include("Zonas/zona_urbana.php");
$conexionObj = new conexion();
$conexionObj->conectarse();
$nombrepagina = "ACTUALIZACION PERSONAL";
encabezado($target);
$user = $_SESSION['validar'];
$filas = 1;
if ($filas == 1) {

    class llamado {

        var $menuObj;

        function validar1($id_user, $id_sucursal) {
            $this->menuObj = new menu_inicio();
            $this->menuObj->menu2($id_user, $id_sucursal);
        }

    }

    $llamadoObj = new llamado();
    $llamadoObj->validar1($_GET['id_user'], $_GET['suc']);
    entrada($user, $_GET['id_user'], $_GET['suc']);
    echo"</td>";
    echo"<td width=79% background=\"imagenes/bg3.jpg\" valign=top>";
    mostrar_cabeza_trabajo($nombrepagina);
    ?>
    <CENTER>
        <form action="" method="POST" name="backup">
            <table width="300" border="0" class="primaria">
                <tr class=miTable_tr>
                    <td colspan="2" class=miTable_th1><div align="center">..:: Actualizacion Personal ::..</div></td>
                </tr>
                <tr class="miTable_tr">
                    <td width="180" valign=top height="42" class=miTable_td2>
                        Guia:</td>
                    <td width="150" valign=top height="42" class="miTable_td">
                        <input type="text" name="nguia" value="<? echo $nguia ?>" class="inputbox" size="25">
                    </td>
                </tr>

                <tr class=miTable_tr>
                    <td class=miTable_th1 colspan="2">
                        <div align="center">
                            <input type="submit" name="Buscar" value="Buscar" class="inputbox">
                        </div>
                    </td>
                </tr>
            </table>
        </form>
    </CENTER>
    <?
    if (!isset($Buscar)) {
        
    } else {
        $nguia = trim($nguia);
        $rst_validar = $conexionObj->consultar("SELECT direccion,especial10,identificacion,nom_cliente FROM guias_proceso WHERE guia='" . $nguia . "'");
        if (mysql_num_rows($rst_validar) <= 0) {
            $msgBOX2 = "Guia no se encuentra en el Sistema.";
            echo "<script>
                                    alert('$msgBOX2');
	  		  	</script>";
        } else {
            $curactualiza = mysql_fetch_array($rst_validar);
            $diro = $curactualiza[0];
            $dirn = $curactualiza[1];
            $codid = $curactualiza[2];
            $codcl = $curactualiza[3];            
            ?>
            <CENTER>
                <table width="300" border="0" class="primaria">
                    <form action="" method="POST" name="backup">
                        <tr class=miTable_tr>
                            <td colspan="2" class=miTable_th1><div align="center">..:: Direccion ::..</div></td>
                        </tr>

                        <tr class="miTable_tr">
                            <td width="150" valign=top height="42" class=miTable_td2>
                                Original:</td>
                            <td width="250" valign=top height="42" class="miTable_td">
                                <input type="text" readonly size="100" name="dirorg" class="inputbox" value="<? echo $diro; ?>">
                            </td>
                        </tr>


                        <tr class="miTable_tr">
                            <td width="180" valign=top height="42" class=miTable_td2>
                                Normalizada:</td>
                            <td width="250" valign=top height="42" class="miTable_td">
                                <input type="text" readonly size="100" name="dirnorm" class="inputbox" value="<? echo $dirn; ?>">
                            </td>
                        </tr>

                        <tr class="miTable_tr">
                            <td width="180" valign=top height="42" class=miTable_td2>
                                Identificacion:</td>
                            <td width="250" valign=top height="42" class="miTable_td">
                                <input type="text" readonly size="25" name="codced" class="inputbox" value="<? echo $codid; ?>">
                            </td>
                        </tr>


                        <tr class="miTable_tr">
                            <td width="180" valign=top height="42" class=miTable_td2>
                                Actualizacion:</td>
                            <td width="250" valign=top height="42" class="miTable_td">
                                <input type="text" size="100" name="actdir" onkeyup="this.value=this.value.toUpperCase()" class="inputbox" >
                                <input type="hidden" size="100" name="actguia" value="<? echo $_POST['nguia']; ?>" class="inputbox" >
                                <input type="hidden" size="100" name="cod_cli" value="<? echo $codcl; ?>" class="inputbox" >
                            </td>
                        </tr>                    


                        <tr class=miTable_tr>
                            <td class=miTable_th1 colspan="2">
                                <div align="center">
                                    <input type="submit" name="editar" value="Actualizar" class="inputbox">
                                </div>
                            </td>
                        </tr>
                    </form>
                </table>

                <?
            }
        }



        if (isset($editar)) {

            $normal = $_POST['dirnorm'];
            $dirn = $_POST['actdir'];
            $actg = $_POST['actguia'];
            $codid = $_POST['codced'];
            $codcli=$_POST['cod_cli'];
            $norg=$_POST['dirorg'];
            $nnorm=$_POST['dirnorm'];

            IF (!EMPTY($dirn) and !empty($codid) and !empty($codcli)) {
                $rst_validar = $conexionObj->consultar("update guias_proceso set direccion='" . $dirn . "' where guia='" . $actg . "'");
                if (mysql_affected_rows() > 0) {
                    //$conexionObj->consultar("update personal set dir_original_act='" . $dirn . "',dir_normal_act='" . $dirn . "' where identificacion='" . $codid . "' and id_cliente='".$codcli."'");                    
                    $conexionObj->consultar("insert into personal (id_cliente,identificacion,dir_original,dir_normal,dir_original_act,dir_normal_act,fecha) 
                         values('".$codcli."','".$codid."','".$norg."','".$nnorm."','".$dirn."','".$dirn."',NOW()) ON DUPLICATE KEY UPDATE 
                              dir_original_act='".$dirn."',dir_normal_act='".$dirn."',fecha=NOW()");                    
                    $msgBOX2 = "Direccion Actualizada.";                 
                    echo "<script>
                                    alert('$msgBOX2');
	  		  	</script>";
                }
            }else{
                $msgBOX2 = "La Identificacion,codigo del Cliente y direccion nueva no pueden ser vacios.";                    
                    echo "<script>
                                    alert('$msgBOX2');
	  		  	</script>";
            }
        }
        mostrar_pie();
    }
    echo"</td>";
    echo"</tr>";
    echo"</table>";
    echo"<table width=503 border=0 align=center cellpadding=0 cellspacing=0>";
    echo"<tbody><tr>";
    echo"<td></td>";
    echo"</tr>";
    echo"<tr>";
    echo"<td height=7 background=imagenes/lineas_pie.jpg><img src=index2_files/spacer.html width=1 height=15></td>";
    echo"</tr>";
    echo"<tr>";
    ?>
    <td>
    <center>
        <?
        pie_de_pagina();
        ?>
    </center>
</td>
<?php
echo"</tr>";
echo"</tbody></table>";
echo"</center>";
echo"</body>";
echo"</html>";
?>
