Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ejercicio4 #2

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
04a5d7d
First Commit
obetancourth Jun 26, 2014
781ea5a
Agregando funcionalidad para nuevo libro
obetancourth Jun 27, 2014
23f2a3e
Agregando Estilos y otros elementos a considerar
obetancourth Jun 27, 2014
b354a3d
corrección de un error que permitía ingresar datos vacios aun validado
obetancourth Jun 27, 2014
822e8d4
Cambios realizados y ejemplo de catalogo de productos con paginación …
obetancourth Jul 22, 2014
6aa1677
Se Agrega funcionalidad de carretilla de compras parcial falta las va…
obetancourth Jul 23, 2014
fe969c2
Se agrega validación de stock disponible, manejados de errores por me…
obetancourth Jul 24, 2014
909bbc8
Cambio al Renderizador para poder utilizar layouts simples, y cambios…
obetancourth Jul 24, 2014
eda5fb1
Agregando Visor de carretilla y listado de los productos de la carret…
obetancourth Jul 25, 2014
0cb883f
Se agrega estilos para la carretilla, sumatorias de datos y el enlace…
obetancourth Jul 25, 2014
fb20478
Modelo de Seguridad Implementado.
obetancourth Jul 30, 2014
6967f13
Estructura de tablas actualizada para categorías
obetancourth Aug 1, 2014
8612e8e
Cambio Realizado
nadiagise Jan 23, 2015
e9d4d7f
Ejercicio1 en PHP
nadiagise Jan 27, 2015
c768fb7
Ejercicio 4
nadiagise Feb 5, 2015
9cd6dc2
Ejercicio 3
nadiagise Feb 20, 2015
5486255
Importante
nadiagise Feb 23, 2015
48fd81e
Importante
nadiagise Mar 3, 2015
6fd7045
Actualización a versión de Nuevo Plantillero
obetancourth Mar 4, 2015
c94a311
Limpieza de Archivos antiguos
obetancourth Mar 4, 2015
c52fd49
Merge branch 'master' of https://github.com/obetancourthunicah/IF412N…
nadiagise Mar 5, 2015
91635d5
Se crean algunas mejoras en el manejo y estilo del sitio.
obetancourth Mar 5, 2015
f3c521b
Limpieza de Elementos
obetancourth Mar 5, 2015
7ddeadf
Merge branch 'master' of https://github.com/obetancourth/simplePHPMVC
nadiagise Mar 6, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Eje8Nr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
// #include c++
// import c#
// using vb
// require_once php
require_once("ado3.php");
$sqlstr = "Select * from productos;";
$productos = obtenerRegistros($sqlstr);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Trabajar con Productos</title>
</head>
<body>
<h1>Productos</h1>
<a href="Eje9Nr.php?action=new">Nuevo Producto</a>
<table border="1">
<tr>
<th>Código</th>
<th>Producto</th>
<th>CB</th>
<th>Inventario</th>
<th>Estado</th>
<th>Categoría</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
/*
prdid
prddsc
prdbrc
prdctd
prdest
ctgid
*/
foreach($productos as $producto){
echo "<tr><td>".$producto["prdid"]."</td>";
echo "<td>".$producto["prddsc"]."</td>";
echo "<td>".$producto["prdbrc"]."</td>";
echo "<td>".$producto["prdctd"]."</td>";
echo "<td>".$producto["prdest"]."</td>";
echo "<td>".$producto["ctgid"]."</td>";
echo '<td><a href="Eje9Nr.php?action=upd&prdid='.$producto["prdid"].'"> -> </a></td></tr>';
echo '<td><a href="Eje9Nr.php?action=del&prdid='.$producto["prdid"].'"> x </a></td></tr>';
}
?>
</table>
</body>
</html>
166 changes: 166 additions & 0 deletions Eje9Nr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php
require_once("ado3.php");
require_once("utilities.php");
$producto = array(
"prdid" => 0,
"prddsc" =>"",
"prdbrc" =>"",
"prdctd" =>0,
"prdest" =>"ACT",
"ctgid " =>0
);
$categorias = array();
$categorias = obtenerRegistros("select * from categorias where ctgest='ACT';");
$mode = "noset";
$modeDescription = array(
"insert" => "Nuevo Producto",
"update" => "Actualizar Producto",
"delete" => "Borrar Producto"
);
if(isset($_GET["action"])){
switch($_GET["action"]){
case "new":
$mode= "insert";
if(isset($_POST["btnInsert"])){
$sqlinsert = "INSERT INTO `productos` (`prddsc`,`prdbrc`,`prdctd`,`prdest`,`ctgid`) VALUES ('%s','%s',%d,'%s', %d);";
$sqlinsert = sprintf($sqlinsert,
$_POST["prddsc"],
$_POST["prdbrc"],
intval($_POST["prdctd"]),
$_POST["prdest"],
intval($_POST["ctgid"])
);
insertRegistro($sqlinsert);
redirectWithMessage('Registro guardado con exito!', 'Eje8Nr.php');
}
break;
case "upd":
if(isset($_POST["btnInsert"])){
if(isset($_POST["prdid"])){
$strupdate = "UPDATE `productos` SET `prddsc` = '%s', `prdbrc` = '%s', `prdctd` =%d, `prdest` = '%s', `ctgid` = %d WHERE `prdid` = %d;";
$strupdate = sprintf($strupdate,
$_POST["prddsc"],
$_POST["prdbrc"],
intval($_POST["prdctd"]),
$_POST["prdest"],
intval($_POST["ctgid"]),
intval($_POST["prdid"])
);
updateRegistro($strupdate);
redirectWithMessage('Producto Actualizado!', 'Eje9Nr.php?action=upd&prdid='.$_POST["prdid"]);
}
}
$mode= "update";
$strsql = "select * from productos where prdid = %d;";
$strsql = sprintf($strsql,$_GET["prdid"]);
$producto = obtenerUnRegistro($strsql);
if($producto){
$modeDescription[$mode] .= " " . $_GET["prdid"] . " " . $producto["prddsc"];
}else{
redirectWithMessage('EL producto no existe!', 'Eje8Nr.php');
}
break;
case "del":
if(isset($_POST["btnInsert"])){
if(isset($_POST["prdid"])){
$strDelete = "DELETE `productos` WHERE `prdid` = %d;";
$strDelete = sprintf($strDelete,
$_POST["prddsc"],
$_POST["prdbrc"],
intval($_POST["prdctd"]),
$_POST["prdest"],
intval($_POST["ctgid"]),
intval($_POST["prdid"])
);
updateRegistro($strDelete);
redirectWithMessage('Producto Eliminado!', 'Eje9Nr.php?action=del&prdid='.$_POST["prdid"]);
}
}
$mode= "delete";
$strsql = "select * from productos where prdid = %d;";
$strsql = sprintf($strsql,$_GET["prdid"]);
$producto = obtenerUnRegistro($strsql);
if($producto){
$modeDescription[$mode] .= " " . $_GET["prdid"] . " " . $producto["prddsc"];
}else{
redirectWithMessage('EL producto no existe!', 'Eje8Nr.php');
}
break;
default:
//truquito muy util.
redirectWithMessage('No Tiene Acceso a Esta página, redirigiendo.', 'Eje8Nr.php');
}
}else{
// ESTO ES ULTRA IMPORTANTE
// PARA REDIRIGIR A OTRA PAGINA
// DESDE PHP
header("location:Eje8Nr.php");
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body>
<h1><?php echo $modeDescription[$mode]; ?></h1>
<form action="Eje9Nr.php?action=<?php echo $_GET["action"]; ?>" method="POST">
<?php
?>
<label for="prdid">
Código Producto
</label>
<input type="hidden" value="<?php echo $producto["prdid"]; ?>"
name="prdid" id="prdid" />

<br/>
<label for="prddsc">
Producto
</label>
<input type="text" value="<?php echo $producto["prddsc"]; ?>"
name="prddsc" id="prddsc" />
<br/>
<label for="prdbrc">
Código de Barra<br/><i>EAN32, QR, CODE 189</i>
</label>
<input type="text" value="<?php echo $producto["prdbrc"]; ?>"
name="prdbrc" id="prdbrc" />
<br/>

<label for="prdctd">
Cantidad
</label>
<input type="number" value="<?php echo $producto["prdctd"]; ?>"
name="prdctd" id="prdctd" />
<br/>

<label for="prdest">
Estado
</label>
<select id="prdest" name="prdest">
<option value="ACT" <?php echo ($producto["prdest"]=="ACT")?"selected":""; ?> >Activo</option>
<option value="INA" <?php echo ($producto["prdest"]=="INA")?"selected":""; ?>>Inactivo</option>
<option value="DES" <?php echo ($producto["prdest"]=="DES")?"selected":""; ?>>Descontinuado</option>
<option value="RET"<?php echo ($producto["prdest"]=="RET")?"selected":""; ?>>Retirado</option>
</select>
<br/>
<label for="ctgid"> Categoría</label>
<select id="ctgid" name="ctgid">
<?php
foreach($categorias as $categoria){
echo '<option value="'.$categoria["ctgid"];
echo '"';
if($categoria["ctgid"] == $producto["ctgid"]){
echo " selected ";
}
echo '>'.$categoria["ctgdsc"].'</option>';
}
?>
</select>
<br/>
<input type="submit" name="btnInsert" id="btnInsert" value="Guardar" />
</form>
</body>
</html>
65 changes: 65 additions & 0 deletions Ejercicio4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
$result = "";
$txtOrg = "";
// +3 Elia
if(isset($_POST["btnPrc"])){
$txtOrg = strtolower($_POST["txtOrg"]);
$txtOrg = str_replace("."," ",$txtOrg);
$txtOrg = str_replace(","," ",$txtOrg);
$txtOrg = str_replace("?"," ",$txtOrg);
$txtOrg = str_replace("!"," ",$txtOrg);
$txtOrg = str_replace("�","",$txtOrg);
$txtOrg = str_replace("�","",$txtOrg);
$txtOrg = str_replace(" "," ",$txtOrg);
//preg_replace remplazar mendiante expresiones
//regulares
$arregloPalabras = explode(" ", $txtOrg);
$arregloFrecuencias = array();
foreach($arregloPalabras as $palabra){
if(isset($arregloFrecuencias[$palabra])){
$arregloFrecuencias[$palabra] ++;
}else{
$arregloFrecuencias[$palabra] = 1;
}
}
if(is_array($arregloFrecuencias)
&& count($arregloFrecuencias) > 0 ){
arsort($arregloFrecuencias);
foreach($arregloFrecuencias as $palabrak=>$freq){
$result = "La palabra << $palabrak >> con mayor frecuencia de : $freq";
break;
}
}else{
$result="No hay palabras que analizar";
}
//associative reverse sort
//asort();
//associative sort
//para depuracion
//print_r($arregloFrecuencias);
//die();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo de Uso de Arreglos Xtreme</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>Stats de Blogs</h1>
<form action="bb.php" method="POST">
<label for="txtOrg">Texto de un Blog</label>
<br/>
<textarea id="txtOrg" name="txtOrg">
<?php echo $txtOrg; ?>
</textarea>
<br/>
<input type="submit" id="btnPrc"
name="btnPrc" value="Procesar" />
</form>
<div>
<?php echo $result; ?>
</div>
</body>
</html>
85 changes: 85 additions & 0 deletions Mantenimiento1Nr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
$registros = array();
$lasInsertID = 0;
//Realizar la conexion con MySQL
$conn = new mysqli("127.0.0.1", "root", "", "nw201501");
if($conn->errno){
die("DB no can: " . $conn->error);
}

if(isset($_POST["btnIns"])){
$registro = array();
$registro["ctgid"] = 0;
$registro["ctgdsc"] = $_POST["txtDsc"];
$registro["ctgest"] = $_POST["txtGest"];


//Preparar el Insert Statement
$sqlstr = "INSERT INTO `nw201501`.`categorias`(`ctgdsc`,`ctgest`)";
$sqlstr .= "VALUES ('" . $registro["ctgdsc"] . "', '". $registro["ctgest"] ."');";

//Ejecutar el Insert Statement
$result = $conn->query($sqlstr);

//Obtener el último codigo generado
$lasInsertID= $conn->insert_id;

//Obtener los registros de la tabla
$sqlQuery = "Select * from categorias;";
$resulCursor = $conn->query($sqlQuery);
//fetch: agarrar de ese cursor la posiciona actual del registro
//y assoc el valor del registro asociativo
while($registro = $resulCursor->fetch_assoc()){
$registros[] = $registro;
}

}



?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Mantenimiento de la tabla Categorías</title>
</head>
<body>
<h1>Categorías</h1>
<form action="Mantenimiento1Nr.php" method="POST">

<label for="txtDsc">Descripción</label>
<input type="text" name="txtDsc" id="txtDsc" />
<br/>
<br/>
<label for="txtGest">Gestión</label>
<input type="text" name="txtGest" id="txtGest" />
<br/>

<br/>
<input type="submit" name="btnIns" value="Guardar" />

</form>
<div>
<h2>Datos</h2>
<?php if($lasInsertID) echo "Último ID generado = $lasInsertID" ?>
<table border="1">
<tr>
<th>Codigo</th>
<th>Descripción</th>
<th>Gestión</th>
</tr>
<?php
if(count($registros) > 0){
foreach($registros as $registro){
echo "<tr><td>".$registro["ctgid"]."</td>";
echo "<td>".$registro["ctgdsc"]."</td>";
echo "<td>".$registro["ctgest"]."</td>";

}
}
?>
</table>
</div>
</body>
</html>
Loading