-
-
Save josegomezr/21482b941e80afed02e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class persona | |
{ | |
private $cedula; | |
private $nombre; | |
private $apellido; | |
function __construct($nombre,$apellido,$cedula) | |
{ | |
$this->nombre=$nombre; | |
$this->apellido=$apellido; | |
$this->cedula=$cedula; | |
} | |
function agregar() | |
{ | |
include('conexion.php'); | |
$sql="insert into persona (cedula,nombre,apellido) values ('{$this->cedula}','{$this->nombre}','{$this->apellido}')"; | |
if(mysql_query($sql,$conexion)) | |
return 1; | |
else | |
return 0; | |
} | |
function buscar() | |
{ | |
include('conexion.php'); | |
$sql="select * from persona order by nombre asc"; | |
$con=mysql_query($sql,$conexion); | |
$cad=""; | |
while($atrib=mysql_fetch_array($con,MYSQL_ASSOC)) | |
$cad=$cad." ".$atrib['cedula'].", ".$atrib['nombre'].", ".$atrib['apellido']."<br>"; | |
echo $cad; | |
} | |
function buscar_id() | |
{ | |
include('conexion.php'); | |
$sql="select * from persona where cedula='{$this->cedula}'"; | |
$con=mysql_query($sql,$conexion); | |
if(mysql_num_rows($con)>0) | |
{ | |
$atrib=mysql_fetch_array($con,MYSQL_ASSOC); | |
$cad=$cad." ".$atrib['cedula'].", ".$atrib['nombre'].", ".$atrib['apellido']; | |
echo $cad; | |
} | |
else | |
return 0; | |
} | |
function eliminar() | |
{ | |
include('conexion.php'); | |
$sql="delete from persona where cedula='{$this->cedula}'"; | |
if(mysql_query($sql,$conexion)) | |
return 1; | |
else | |
return 0; | |
} | |
function actualizar() | |
{ | |
include('conexion.php'); | |
$sql="update persona set nombre='{$this->nombre}',apellido='{$this->apellido}' where cedula='{$this->cedula}'"; | |
if(mysql_query($sql,$conexion)) | |
return 1; | |
else | |
return 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('clase_persona.php'); | |
$accion=$_POST['accion']; | |
$cedula=$_POST['cedula']; | |
$nombre=$_POST['nombre']; | |
$apellido=$_POST['apellido']; | |
switch ($accion) | |
{ | |
case 'agregar': | |
$Per=new Persona($nombre,$apellido,$cedula); | |
$res=$Per->agregar(); | |
echo $res; | |
break; | |
case 'buscar': | |
$Per=new Persona($nombre,$apellido,$cedula); | |
$res=$Per->buscar(); | |
echo $res; | |
break; | |
case 'traer': | |
$Per=new Persona($nombre,$apellido,$cedula); | |
$res=$Per->buscar_id(); | |
echo $res; | |
break; | |
case 'eliminar': | |
$Per=new Persona($nombre,$apellido,$cedula); | |
$res=$Per->eliminar(); | |
echo $res; | |
break; | |
case 'actualizar': | |
$Per=new Persona($nombre,$apellido,$cedula); | |
$res=$Per->actualizar(); | |
echo $res; | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript Document | |
function guardar() { | |
if (validar()) { | |
var cedula = document.getElementById('cedula').value; | |
var nombre = document.getElementById('nombre').value; | |
var apellido = document.getElementById('apellido').value; | |
var parametros = "&cedula=" + cedula + "&nombre=" + nombre + "&apellido=" + apellido + "&accion=agregar"; | |
var url = "objeto_persona.php"; | |
AjaxRequest.post({ | |
'queryString': parametros, | |
'url': url, | |
'onSuccess': function(req) { | |
var respuesta = req.responseText; | |
var resultado = eval("(" + respuesta + ")"); | |
if (respuesta == '1') { | |
alert("Se han guardado los datos satisfactoriamente.") | |
limpiar(); | |
buscar(); | |
} else { | |
alert("Se produjo un error al intentar guardar los datos.") | |
} | |
}, | |
'onError': function(req) { | |
alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText); | |
} | |
}); | |
} | |
} | |
function buscar() { | |
var parametros = "&accion=buscar"; | |
var url = "objeto_persona.php"; | |
AjaxRequest.post({ | |
'queryString': parametros, | |
'url': url, | |
'onSuccess': function(req) { | |
var respuesta = req.responseText; | |
//alert(respuesta); | |
var resultado = respuesta.split("<br>"); | |
var a = resultado.length; | |
document.getElementById('cuerpo_persona').style.display = "block"; | |
var tabla = '<table border="0" width="100%" cellspacing="2" cellpadding="2" align="center">'; | |
tabla += '<tr class="tit"><td>Cedula</td><td>Nombre</td><td>Apellido</td></tr>'; | |
for (i = 0; i < a - 1; i++) { | |
var datos = resultado[i].split(", "); | |
tabla += '<tr class="person2"><td>' + datos[0] + '</td><td>' + datos[1] + '</td><td>' + datos[2] + '</td></tr>'; | |
} | |
tabla += '</table>'; | |
document.getElementById("cuerpo_persona").innerHTML = tabla; | |
}, | |
'onError': function(req) { | |
alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText); | |
} | |
}); | |
} | |
function traer_datos() { | |
var cedula = document.getElementById('cedula').value; | |
var parametros = "&cedula=" + cedula + "&accion=traer"; | |
var url = "objeto_persona.php"; | |
AjaxRequest.post({ | |
'queryString': parametros, | |
'url': url, | |
'onSuccess': function(req) { | |
var respuesta = req.responseText; | |
var resultado = respuesta.split(", "); | |
if (resultado[0] != 0) { | |
document.getElementById('cedula').value = resultado[0]; | |
document.getElementById('nombre').value = resultado[1]; | |
document.getElementById('apellido').value = resultado[2]; | |
document.getElementById('submit').disabled = true; | |
document.getElementById('modif').disabled = false; | |
document.getElementById('elim').disabled = false; | |
document.getElementById('cedula').disabled = true; | |
} else { | |
document.getElementById('nombre').value = ""; | |
document.getElementById('apellido').value = ""; | |
document.getElementById('modif').disabled = true; | |
document.getElementById('elim').disabled = true; | |
document.getElementById('submit').disabled = false; | |
document.getElementById('cedula').disabled = false; | |
} | |
}, | |
'onError': function(req) { | |
alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText); | |
} | |
}); | |
} | |
function eliminar() { | |
var cedula = document.getElementById('cedula').value; | |
var parametros = "&cedula=" + cedula + "&accion=eliminar"; | |
var url = "objeto_persona.php"; | |
AjaxRequest.post({ | |
'queryString': parametros, | |
'url': url, | |
'onSuccess': function(req) { | |
var respuesta = req.responseText; | |
var resultado = eval("(" + respuesta + ")"); | |
if (respuesta == '1') { | |
alert("Datos eliminados satisfactoriamente.") | |
limpiar(); | |
buscar(); | |
} else { | |
alert("Se produjo un error al intentar eliminar los datos.") | |
} | |
}, | |
'onError': function(req) { | |
alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText); | |
} | |
}); | |
} | |
function actualizar() { | |
var cedula = document.getElementById('cedula').value; | |
var nombre = document.getElementById('nombre').value; | |
var apellido = document.getElementById('apellido').value; | |
var parametros = "&cedula=" + cedula + "&nombre=" + nombre + "&apellido=" + apellido + "&accion=actualizar"; | |
var url = "objeto_persona.php"; | |
AjaxRequest.post({ | |
'queryString': parametros, | |
'url': url, | |
'onSuccess': function(req) { | |
var respuesta = req.responseText; | |
var resultado = eval("(" + respuesta + ")"); | |
if (respuesta == '1') { | |
alert("Se han actualizado los datos satisfactoriamente.") | |
limpiar(); | |
buscar(); | |
} else { | |
alert("Se produjo un error al intentar actualizar los datos.") | |
} | |
}, | |
'onError': function(req) { | |
alert('Error!\nStatusText=' + req.statusText + '\nContents=' + req.responseText); | |
} | |
}); | |
} | |
function limpiar() { | |
document.getElementById('cedula').value = ""; | |
document.getElementById('nombre').value = ""; | |
document.getElementById('apellido').value = ""; | |
document.getElementById('cedula').disabled = false; | |
document.getElementById('modif').disabled = true; | |
document.getElementById('elim').disabled = true; | |
document.getElementById('submit').disabled = false; | |
document.getElementById('cuerpo_persona').style.display = "none"; | |
} | |
function validar() { | |
var cad = "", | |
sw = 0; | |
for (i = 0; i < document.forms[0].elements.length; i++) { | |
if (document.forms[0].elements[i].value == "") { | |
sw = 1; | |
cad = cad + " -" + document.forms[0].elements[i].name + "\n"; | |
} | |
} | |
if (sw == 1) { | |
alert("Faltan campos por llenar\n" + cad); | |
return false; | |
} else { | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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>Untitled Document</title> | |
<script language="javascript" src="persona.js"></script> | |
<script language="javascript" src="AjaxRequest.js"></script> | |
<link href="estilo.css" rel="stylesheet" type="text/css"></link> | |
</head> | |
<body bgcolor="#C0C0C0"> | |
<form name="ajax" method="post"> | |
<table align="center" border="0" cellspacing="0" cellpadding="0" style="border:#ccc ridge"> | |
<tr> | |
<td> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"> | |
<tr class="tit"> | |
<td width="32%" colspan="8" height="25px" align="center"><strong>DATOS PERSONALES</strong> | |
</td> | |
</tr> | |
<tr> | |
<td class="person"> </td> | |
<td class="person"> </td> | |
<td colspan="2" class="person"> </td> | |
<td colspan="3" class="person"> </td> | |
<td class="person"> </td> | |
</tr> | |
<tr> | |
<td class="person"> </td> | |
<td class="person"> </td> | |
<td colspan="2" class="person"><strong>Cedula:</strong> | |
</td> | |
<td colspan="3" class="person"> | |
<input name="cedula" id="cedula" type="text" onblur="traer_datos();" /> | |
</td> | |
<td class="person"> </td> | |
</tr> | |
<tr> | |
<td class="person"> </td> | |
<td align="center" class="person"> </td> | |
<td colspan="2" align="center" class="person"> </td> | |
<td colspan="3" align="center" class="person"> </td> | |
<td class="person"> </td> | |
</tr> | |
<tr> | |
<td class="person"> </td> | |
<td width="32%" class="person"> </td> | |
<td width="32%" colspan="2" class="person"><strong>Nombre:</strong> | |
</td> | |
<td width="32%" colspan="3" class="person"> | |
<input name="nombre" id="nombre" type="text" /> | |
</td> | |
<td class="person"> </td> | |
</tr> | |
<tr class="person"> | |
<td> </td> | |
<td colspan="6" class="person"> </td> | |
<td> </td> | |
</tr> | |
<tr class="person"> | |
<td class="person"> </td> | |
<td class="person"> </td> | |
<td colspan="2" class="person"><strong>Apellido:</strong> | |
</td> | |
<td colspan="3" class="person"> | |
<input name="apellido" id="apellido" type="text" /> | |
</td> | |
<td> </td> | |
</tr> | |
<tr class="person"> | |
<td> </td> | |
<td colspan="6" align="center" class="person"> </td> | |
<td> </td> | |
</tr> | |
<tr class="person"> | |
<td height="28"> </td> | |
<td align="center" class="person"> </td> | |
<td align="center" class="person"> | |
<input name="submit" id="submit" type="button" value="Enviar" onclick="guardar();" /> | |
</td> | |
<td align="center" class="person"> | |
<input name="modif" id="modif" type="button" value="Modificar" disabled="disabled" onclick="actualizar();" /> | |
</td> | |
<td align="center" class="person"> | |
<input name="elim" id="elim" type="button" value="Eliminar" disabled="disabled" onclick="eliminar();" /> | |
</td> | |
<td align="center" class="person"> | |
<input name="reset" id="reset" type="button" value="Buscar" onclick="buscar();" /> | |
</td> | |
<td align="center" class="person"> | |
<input name="cancelar" id="cancelar" type="button" value="Cancelar" onclick="limpiar();" /> | |
</td> | |
<td> </td> | |
</tr> | |
<tr class="person"> | |
<td> </td> | |
<td colspan="6" class="person"> </td> | |
<td> </td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
<tr> | |
<td> | |
<div align="center" id="cuerpo_persona" class="person" style="display:none"></div> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</form> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment