-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproductoView.php
More file actions
174 lines (150 loc) · 5.11 KB
/
productoView.php
File metadata and controls
174 lines (150 loc) · 5.11 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Created by PhpStorm.
* User: Alfredo Hinojosa
* Date: 10/4/2015
* Time: 1:35 AM
*/
include ("includes/conn.php");
$title = "Productos deseados";
include ("head.php");
$mysqli = con_start();
$notYet = [];
$done = [];
$favorite = [];
$count1 = 0;
$count2 = 0;
//$id = 1;
$smtp = $mysqli->prepare("SELECT id_product, name, description, amount, completed FROM Product WHERE id_user = 1
AND id_trans = 0 AND hidden = 0");
$smtp->execute();
$smtp->store_result();
$smtp->bind_result($id, $name, $info, $cost, $completed);
while ($smtp->fetch()) {
if($completed == 1){
$done[$count2][0] = $name;
$done[$count2][1] = $info;
$done[$count2][2] = $cost;
$done[$count2][3] = $id;
$count2++;
} else {
$notYet[$count1][0] = $name;
$notYet[$count1][1] = $info;
$notYet[$count1][2] = $cost;
$notYet[$count2][3] = $id;
$count1++;
}
}
var_dump($notYet);
$smtp->free_result();
$smtp = $mysqli->prepare("SELECT name, description, amount, completed FROM Product WHERE id_user = 1
AND id_trans = 1 AND hidden = 0");
$smtp->execute();
$smtp->store_result();
$count = 0;
$smtp->bind_result($name, $info, $cost, $completed);
while($smtp->fetch()){
$favorite[0][0] = $name;
$favorite[0][1] = $info;
$favorite[0][2] = $cost;
$count++;
}
$smtp->free_result();
$smtp->close();
//var_dump($ret);
?>
<div class="container">
<p> </p>
<p> </p>
<p> </p>
<?php if ($count == 0) {?>
<h2 id="heading" class="text-center">Favor de establecer producto objetivo</h2>
<p><a id="chart" style="display:none;" class="btn btn-lg btn-success center-block" href="productoChart.php" role="button">¿Cuanto me falta?</a></p>
<?php }else{ ?>
<h2 id="heading" class="text-center">Tu objetivo actual es comprar: <?php echo $favorite[0][0]?> con precio de $<?php echo $favorite[0][2]?></h2>
<p><a id="chart" class="btn btn-lg btn-success center-block" href="productoChart.php" role="button">¿Cuanto me falta?</a></p>
<?php } ?>
<br>
<h2>Estos son los productos que estan marcados como objetivos próximos</h2>
<table class="table">
<tr>
<th>Producto</th>
<th>Descripción</th>
<th>Costo</th>
<th>Marcar como favorito</th>
<th>Eliminar</th>
</tr>
<?php
foreach($notYet as $ok){
if($ok[0] != null){
echo "<tr>";
echo "<td>".$ok[0]."</td>";
echo "<td>".$ok[1]."</td>";
echo "<td id='".str_replace(" ", "", $ok[0])."'>$".$ok[2]."</td>";
echo "<td><button id='".$ok[0]."' type='button' class='btn btn-default btn-lg center-block addFav'><span class='glyphicon glyphicon-star' aria-hidden='true'></span></button></td>";
echo "<td><button id='".$ok[0]."' type='button' class='btn btn-default btn-lg center-block deleteProd'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button></td>";
echo "</tr>";
}
}
?>
</table>
<p><a class="btn btn-lg btn-primary" href="producto.php" role="button">Agregar nuevo</a></p>
<br><h2>Estos son los productos que has comprado, ¡Felicidades!</h2>
<table class="table">
<tr>
<th>Producto</th>
<th>Descripción</th>
<th>Costo</th>
<th>Eliminar</th>
</tr>
<?php
foreach($done as $ok){
echo "<tr id='".$ok[0]."'>";
echo "<td>".$ok[0]."</td>";
echo "<td>".$ok[1]."</td>";
echo "<td>$".$ok[2]."</td>";
echo "<td><button id='".$ok[0]."' type='button' class='btn btn-default btn-lg center-block deleteProd'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button></td>";
echo "</tr>";
}
?>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#productoView').addClass("active");
});
$('.addFav').on('click', function (e) {
var id = this.id;
$.ajax({
type: 'POST',
url: './productoFunciones.php',
data: {funcion: "addFav", idprod: id},
success: function(dtx){
console.log(dtx);
var price = $("td#" + dtx.replace(" ", "")).html();
$("#heading").text("Tu objetivo actual es comprar: " + dtx + " con precio de " + price);
$("#chart").show();
},
error: function (json) {
console.log(json);
}
});
});
$('.deleteProd').on('click', function (e) {
var row = $(this);
var id = this.id;
$.ajax({
type: 'POST',
url: './productoFunciones.php',
data: {funcion: "deleteProd", idprod: id},
success: function(dtx){
$(row).parent().parent().hide();
console.log(dtx);
},
error: function (json) {
console.log(json);
}
});
});
</script>
</div><!-- /.container -->
<?php include("foot.php") ?>