-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddReceta.php
149 lines (134 loc) · 5.03 KB
/
addReceta.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
<?php
/**
* @author Michal
* @author Grace
* @author Carlo
*/
require_once 'Controler/RecetaControler.php';
require_once 'Model/Receta.php';
require_once 'Model/Ingrediente.php';
require_once 'Controler/IngredienteControler.php';
require_once 'View/libHTML.php';
require_once 'View/RecetaView.php';
head();
$receta=new Receta();
$ingrediente=new Ingrediente();
$exito = array(
"succes" => false,
"id" => 0,
);
if (isset($_REQUEST['enviar'])) {
$cuantos=count($_REQUEST['ingredientes']);
$arrIngredientes=array();
for ($i = 0; $i < $cuantos; $i++) {
$ingrediente->setAll($_REQUEST['ingredientes'][$i],"","",$_REQUEST['cantidad'][$i]);
array_push($arrIngredientes, clone $ingrediente);
}
$imagen=fopen($_FILES['imagen']['tmp_name'], 'rb');
$receta->setAll(0,$_REQUEST['nom'],$_REQUEST['descripcion'],$arrIngredientes,$_REQUEST['preparacion'],$_REQUEST['tiempo'],$_REQUEST['personas'],$imagen);
$recetaControler = new RecetaControler();
$exito=$recetaControler->save($receta);
}
?>
<div class="container-fluid">
<form role="form" enctype="multipart/form-data" method="post" class="form-horizontal col-sm-8 col-sm-offset-2" action="addReceta.php">
<?php
if (isset($_REQUEST['enviar']) && $exito['succes']) {
echo "<p>Receta añadida correctamente!</p>";
echo "<p>Puedes ver su receta <a href='recetas.php?receta=".$exito['id']."'>Aqui</a></p>";
}
?>
<p><center><h3>Cree su propia Receta ¡¡</h3><center></p>
<div class="form-group">
<label for="imagen">Imagen</label>
<input type="file" id="imagen" name="imagen">
<p class="help-block">Elige el imagen de la receta(JPG o PNG).</p>
</div>
<div class="form-group">
<label for="nom" class="col-sm-3 control-label">Nombre de la Receta</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="nom" name="nom" placeholder="Nombre" required="required">
</div>
</div>
<div class="form-group">
<label for="descripcion" class="col-sm-3 control-label">Descripcion</label>
<div class="col-sm-8">
<textarea class="form-control" rows="3" id="descripcion" name="descripcion" placeholder="Descripcion" required="required"></textarea>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<p><strong>Ingredientes:</strong></p>
</div>
</div>
<div class="row">
<div class="col-sm-5 col-sm-offset-3">
<table class="table" id="taula">
<tr>
<th>Cantidad</th>
<th>Ingrediente</th>
</tr>
<tr>
<td class="col-sm-5">
<input type="text" class="form-control" id="cantidad" name="cantidad[]" placeholder="0" required="required">
</td>
<td>
<select name="ingredientes[]" id="ingredientesSelect" class="form-control">
<?php
$ingredienteControler= new IngredienteControler();
$listaIngredientes = $ingredienteControler->listaIngredientes();
foreach ($listaIngredientes as $ing) {
echo '<option value="'.$ing->getId().'">'.$ing->getIngrediente().'('.$ing->getUnidad().')</option>';
}
?>
</select>
</td>
<td><button type="button" class="btn btn-default" id="anadir" onclick="anadirIngrediente()">+</button></td>
</tr>
</table>
</div>
</div>
</div>
<div class="form-group">
<label for="preparacion" class="col-sm-3 control-label">Preparacion</label>
<div class="col-sm-8">
<textarea class="form-control" rows="3" id="preparacion" name="preparacion" placeholder="Preparacion" required="required"></textarea>
</div>
</div>
<div class="form-group">
<label for="tiempo" class="col-sm-3 control-label">Tiempo(horas)</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="tiempo" name="tiempo" placeholder="0" required="required">
</div>
</div>
<div class="form-group">
<label for="personas" class="col-sm-3 control-label">Comensales</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="personas" name="personas" placeholder="0" required="required">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<button type="submit" class="btn btn-default" name="enviar">Añadir</button>
</div>
</div>
</form>
<script type="text/javascript">
function anadirIngrediente() {
var table = document.getElementById('taula').getElementsByTagName('tbody')[0];
var select = document.getElementById('ingredientesSelect');
var options = select.innerHTML;
var row = table.insertRow(table.rows.length);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = '<input type="text" class="form-control" id="cantidad" name="cantidad[]" placeholder="0" required="required">';
cell2.innerHTML = '<select name="ingredientes[]" class="form-control">'+options+'</select>';
cell3.innerHTML = '<button type="button" class="btn btn-default" id="anadir" onclick="anadirIngrediente()">+</button>';
}
</script>
</div>
<?php
footer();
?>