forked from obetancourthunicah/IF412NegociosWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathej9.php
161 lines (158 loc) · 5.7 KB
/
ej9.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
require_once("ado.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!', 'ej8.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!', 'ej9.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!', 'ej8.php');
}
break;
case "del":
$mode = "delete";
if(isset($_POST["btnInsert"])){
if(isset($_POST["prdid"])){
$strdelete = "DELETE FROM `nw201501`.`productos` WHERE `prdid` = %d;";
$strdelete = sprintf($strdelete,intval($_POST["prdid"]));
deleteRegistro($strdelete);
redirectWithMessage('Producto Borrado!', 'ej8.php');
}
}
$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!', 'ej8.php');
}
break;
default:
//truquito muy util.
redirectWithMessage('No Tiene Acceso a Esta página, redirigiendo.', 'ej8.php');
}
}else{
// ESTO ES ULTRA IMPORTANTE
// PARA REDIRIGIR A OTRA PAGINA
// DESDE PHP
header("location:ej8.php");
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body>
<h1><?php echo $modeDescription[$mode]; ?></h1>
<form action="ej9.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="<?php echo $mode;?>" />
<?php print_r($categorias); die();?>
</form>
</body>
</html>