-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowDetail.php
401 lines (365 loc) · 16 KB
/
showDetail.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
// session_start();
// showDetail()
function showDetail(){
require_once("recipe.php");
print("<form data-ajax='false' method='post' action='index.php?action=saveSonR'>");
$r=new recipe;
if ($_REQUEST["id"] == ""){
print("信息不完整!");
return;
}else{
$r->__set("id",$_REQUEST["id"]);
$recipeName=$r->queryRI("name");
$instruc=$r->queryRI("instructions");
$temperatureU=$r->queryRI("temperatureU");
$temperatureD=$r->queryRI("temperatureD");
$cooktime=$r->queryRI("cooktime");
$recipeType=$r->queryRI("type");
$r=null;
// 显示配料详情
$ingre=new ingre;
$ingre->__set("recipeId", $_REQUEST["id"]);
$all_ingres=$ingre->queryRID();
$ingre=null;
}
if (isset($_SESSION["deleted"])) {
if($_SESSION["deleted"]==1){
print("<div class='red'>这是垃圾筒内的配方,删除后将无法恢复!</div>");
print("<a href='index.php?action=deleteR&id=".$_REQUEST["id"]."'>删除此配方</a>");
}
} else {
print("<a href='index.php?action=delR&id=".$_REQUEST["id"]."'>删除此配方</a>");
}
print("<table data-role='table' data-mode='reflow' class='ui-body-d table-stripe my-custom-breakpoint'>
<thead>
<tr>
<th colspan='5'>
<div data-role='fieldcontain'>
<label for='rName' class='ui-hidden-accessible'>配方:</label>
<input type='text' name='rName' id='rName' value='".$recipeName."' data-inline='true'>
<input type='submit' name='submit' id='submit5' value='改名' data-inline='true' data-mini='true'>
<div id='mySpan'></div>
</div>
</th>
</tr>
<tr>
<th>配料</th>
<th>用量</th>
<th>百分比</th>
<th>主</th>
<th></th>
</tr>
</thead>
<tbody>");
$i=1;
$rowSum=0;
foreach ($all_ingres as $item) {
print("
<tr id='".$i."'>
<td class='ui-field-contain'><input type='text' name='ingre".$i."' id='ingre".$i."' value=\"$item->name\"><input type='hidden' name='ingreId".$i."' id='ingreId".$i."' value=\"$item->id\"></td>
<td class='ui-field-contain'><input type='text' name='metric".$i."' id='metric".$i."' value=\"$item->metric\"></td>
<td class='ui-field-contain'><input type='text' name='percent".$i."' id='percent".$i."' value=\"$item->percent\"></td>
<td class='ui-field-contain'><input type='checkbox' style='margin-top:5px;' name='isMain".$i."' id='isMain".$i."' onclick='checkSet($item->id)' value=\"1\"></td>
<td class='ui-field-contain'><a href=\"#\" data-role=\"button\" data-mini=\"true\" class=\"ui-btn ui-mini\" onclick=\"delIngre(".$_REQUEST["id"].",$item->id,$i,$rowSum)\">删</a></td>
</tr>
");
$i++;
$rowSum+=1;
$sum=$item->sum;
$percentSum=$item->perSum;
}
print("
</tbody>
</table>
");
print("<ul data-role='listview' data-inset='true'>
<li class='ui-field-contain'>
<label for='requireSum'>需求总量: <span id='hint' style='background:#FF0;font-weight:bold'></span></label>
<input type='number' name='requireSum' id='requireSum'>
</li>
<li class='ui-field-contain'>
<label for='remark'>备 注:</label>
<input type='text' name='remark' id='remark'>
</li>
<li class='ui-field-contain'>
<input type='hidden' name='recipeName' id='recipeName' value=\"$recipeName\">
<input type='hidden' name='recipeId' id='recipeId' value='".$_REQUEST["id"]."'>
<fieldset data-role='controlgroup' data-type='horizontal' data-mini='true'>
<legend>计算保存:</legend>
<input type='button' name='generateRecipe' id='generateRecipe' value='计算' data-inline='true'>
<input type='submit' name='submit' id='saveSonRecipe' value='保存' data-inline='true' disabled=\"disabled\">
<input type='button' name='rowNum' id='rowNum' value='".$rowSum."' data-inline='true'>
<input type='hidden' name='rowNum' id='rowNumOld' value='".$rowSum."'>
<input type='hidden' name='rowNumNew' id='rowNumNew' value='".$rowSum."'>
<a href='#addActualPercent' data-rel='popup' data-position-to='window' class='ui-btn ui-corner-all ui-shadow ui-btn-inline' data-transition='pop'>AAP</a>
<div data-role='popup' id='addActualPercent'>
<a href='#' data-rel='back' class='ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-left'>Close</a>
<form>
<div style='padding:10px 20px;'>
<h3>增加添加剂:</h3>
<label for='tjjName'>添加剂</label>
<input type='text' name='tjjName' id='tjjName' value='' />
<label for='actPerc'>实际百分比</label>
<input type='text' name='actPerc' id='actPerc' value='' />
<label for='nowSum'>现总量</label>
<input type='text' name='nowSum' id='nowSum' value='".$sum."' />
<a href='#' id='saveActPerc' data-rel='back' class='ui-btn ui-corner-all ui-shadow'>保存</a>
</div>
</form>
</div>
</fieldset>
</li>
<li class='ui-field-contain'>
<fieldset data-role=\"controlgroup\" data-type=\"horizontal\" data-mini='true'>
<legend>修改配方:</legend>
<input type=\"button\" name=\"add\" id=\"add\" value=\"增加一行\" data-inline=\"true\">
");
if ($recipeType == 2) {
print("<input type=\"button\" name=\"reCalculateSpon\" id=\"reCalculateSpon\" value=\"RC2\" data-inline=\"true\">");
print("<input type=\"button\" name=\"reCalculateSum\" id=\"reCalculateSum\" value=\"RC3\" data-inline=\"true\">");
print("<input type=\"hidden\" name=\"recipeType\" id=\"recipeType\" value=\"2\">");
} else if($recipeType == 3){
print("<input type=\"button\" name=\"reCalculateSum\" id=\"reCalculateSum\" value=\"RC3\" data-inline=\"true\">");
print("<input type=\"button\" name=\"reCalculate\" id=\"reCalculate\" value=\"RC1\" data-inline=\"true\">");
print("<input type=\"hidden\" name=\"recipeType\" id=\"recipeType\" value=\"3\">");
} else {
print("<input type=\"button\" name=\"reCalculate\" id=\"reCalculate\" value=\"RC1\" data-inline=\"true\">");
print("<input type=\"button\" name=\"reCalculateSum\" id=\"reCalculateSum\" value=\"RC3\" data-inline=\"true\">");
print("<input type=\"hidden\" name=\"recipeType\" id=\"recipeType\" value=\"1\">");
}
print("<a href=\"#\" data-role=\"button\" onclick=\"clearPercentCol()\">clearP</a>
</fieldset>
</li>
<li class='ui-field-contain'>
<a href='index.php?action=showSonRecipes&id=".$_REQUEST["id"]."'>查看生成的子配方</a>
</li>
<li class='ui-field-contain'>
<label for='sum'>总产量</label>
<input type='text' name='sum' id='sum' value=\"$sum\">
</li>
<li class='ui-field-contain'>
<label for='percentSum'>总百分比</label>
<input type='text' name='percentSum' id='percentSum' value=\"$percentSum\">
</li>
<li class='ui-field-contain'>
<label for='temperatureU'>上火</label>
<input type='text' name='temperatureU' id='temperatureU' value=\"$temperatureU\">
</li>
<li class='ui-field-contain'>
<label for='temperatureD'>下火</label>
<input type='text' name='temperatureD' id='temperatureD' value=\"$temperatureD\">
</li>
<li class='ui-field-contain'>
<label for='cooktime'>烘焙时间</label>
<input type='text' name='cooktime' id='cooktime' value=\"$cooktime\">
</li>
<li class='ui-field-contain'>
<label for='instruc'>制作说明:</label>
<textarea cols='80' rows='8' name='instruc' id='instruc'>$instruc</textarea>
</li>
<li class='ui-field-contain'>
<fieldset data-role='controlgroup' data-type='horizontal' data-mini='true'>
<legend>更新保存:</legend>
<input type='submit' name='submit' id='updateRecipe' value='更新配方' data-inline='true' onclick='return confirm(\"你确定要更新配方内容吗?如果是将删除所有过时的子配方.\");'>
<input type='submit' name='submit' id='updataROther' value='更新其它' data-inline='true'>
<input type='submit' name='submit' id='saveAsNewRecipe' value='另存为新配方' data-inline='true'>
<input type='submit' name='submit' id='saveNewAddingre' value='保存新增加配料' data-inline='true'>
</fieldset>
</li>
</ul>
");
// 显示图像
require_once("class_recimg.php");
$img = new recimg;
$img->__set("recipeId",$_REQUEST['id']);
$arr_img = $img->query();
$img=null;
foreach ($arr_img as $item) {
print "<a target='_blank' href='".$item->imgpath."'><img src='".$item->imgpath."'></a>\n";
}
print("</form>");
}
// saveSonR
function saveSonR(){
require_once("recipe.php");
// print("<pre>");
// var_dump($_REQUEST);
// print("<pre>");
// return;
if($_REQUEST["submit"]=="改名"){
$r=new recipe;
$r->__set("id",$_REQUEST["recipeId"]);
$r->__set("name",$_REQUEST["rName"]);
$r->updateName();
$r=null;
$ingre=new ingre;
$ingre->__set("recipeId",$_REQUEST["recipeId"]);
$ingre->__set("recipeName",$_REQUEST["rName"]);
$ingre->updateRecipeName();
$ingre=null;
print("<script>alert('配方 \"".$_REQUEST["rName"]."\" 改名 成功!');</script>");
print("<script>location.href='index.php?action=showDetail&id=".$_REQUEST["recipeId"]."';</script>");
}else if($_REQUEST["submit"] == "更新其它"){
$r=new recipe;
$r->__set("id",$_REQUEST["recipeId"]);
// $r->__set(name,$_REQUEST[rName]);
$r->__set("instructions",$_REQUEST["instruc"]);
$r->__set("temperatureU",$_REQUEST["temperatureU"]);
$r->__set("temperatureD",$_REQUEST["temperatureD"]);
$r->__set("cooktime",$_REQUEST["cooktime"]);
$r->updateOther();
$r=null;
print("<script>alert('配方 \"".$_REQUEST["rName"]."\" 更新其它 成功!');</script>");
print("<script>location.href='index.php?action=showDetail&id=".$_REQUEST["recipeId"]."';</script>");
}else if ($_REQUEST["submit"] == "更新配方"){
$r=new recipe;
$r->__set("id",$_REQUEST["recipeId"]);
$r->__set("name",$_REQUEST["rName"]);
$r->__set("instructions",$_REQUEST["instruc"]);
$r->__set("temperatureU",$_REQUEST["temperatureU"]);
$r->__set("temperatureD",$_REQUEST["temperatureD"]);
$r->__set("cooktime",$_REQUEST["cooktime"]);
$r->update();
$r = null;
$rowsNum=$_REQUEST["rowNum"];
for ($i = 0; $i < $rowsNum; $i++) {
$ingre = new ingre;
$ingre->__set("id",$_REQUEST["ingreId".($i+1)]);
$ingre->__set("name",$_REQUEST["ingre".($i+1)]);
$ingre->__set("recipeName",$_REQUEST["rName"]);
$ingre->__set("metric",$_REQUEST["metric".($i+1)]);
$ingre->__set("percent",$_REQUEST["percent".($i+1)]);
$ingre->__set("sum",$_REQUEST["sum"]);
$ingre->__set("perSum",$_REQUEST["percentSum"]);
$ingre->update();
$ingre = null;
}
// 更新原配方后删除所有子配方
$ingre=new ingre;
$ingre->__set("recipeId",$_REQUEST["recipeId"]);
$ingre->delAllSonByRID();
$ingre=null;
// print("修改成功!<br />");
// print("<a href='index.php'>查看结果</a>");
// print("<a href='index.php?action=showDetail&id=".$_REQUEST[recipeId]."'>查看结果</a>");
print("<script>alert('配方 \"".$_REQUEST["rName"]."\" 配方更新 成功!');</script>");
print("<script>location.href='index.php?action=showDetail&id=".$_REQUEST["recipeId"]."';</script>");
}else if($_REQUEST["submit"]=="保存"){
// 要插入ingres表的总行数等于($_REQUEST总数-多余的项)/3
// $rowsNum = (count($_REQUEST) - SAVESONEXTRANUM)/3;
$rowsNum=$_REQUEST["rowNum"];
for($i=1;$i<=$rowsNum;$i++){
$ingre=new ingre;
$ingre->__set("name",$_REQUEST['ingre'.$i]);
$ingre->__set("metric",$_REQUEST['metric'.$i]);
$ingre->__set("percent",$_REQUEST['percent'.$i]);
$ingre->__set("recipeId",$_REQUEST["recipeId"]);
$ingre->__set("recipeName",$_REQUEST["recipeName"]);
$ingre->__set("requireSum",$_REQUEST["requireSum"]);
$ingre->__set("perSum",$_REQUEST["percentSum"]);
$ingre->__set("remark",$_REQUEST["remark"]);
$ingre->addreq();
$ingre=null;
}
print("保存子配方成功!<br />");
print("<a href='index.php?action=showSonRecipes&id=".$_REQUEST["recipeId"]."'>查看生成的子配方</a>");
}else if($_REQUEST["submit"]=="另存为新配方"){
// print("<pre>");
// var_dump($_REQUEST);
// print("</pre>");
// return;
// 插入 recipes表
require_once("recipe.php");
if ($_REQUEST["rName"]==""||
$_REQUEST["sum"]==""||
$_REQUEST["percentSum"]==""){
print("<div class='prompt'>添加失败,请把信息填写完整</div>");
print("<a href='javascript:history.go(-1)'>重试</a>");
}
else{
$r=new recipe;
$r->__set("name",$_REQUEST["rName"]);
$r->__set("user_id",$_SESSION["user_id"]);
$r->__set("instructions",$_REQUEST["instruc"]);
$r->__set("temperatureU",$_REQUEST["temperatureU"]);
$r->__set("temperatureD",$_REQUEST["temperatureD"]);
$r->__set("cooktime",$_REQUEST["cooktime"]);
$r->__set("type",$_REQUEST["recipeType"]);
$r->add();
// $r=null;
// print("<script>alert('配方: ".$_REQUEST[rName]." 增加成功!');</script>");
}
// 插入 ingres 表
// $r=new recipe;
$r->__set("name",$_REQUEST["rName"]);
// echo $r->__get(name);
$id=$r->queryId();
$r=null;
// echo $id;
// return;
// 下面一行中的9在服务器上是10因为服务器多传了一个数据,这里是11因为比addRecipes.php多了3项
// echo SAVEASEXTRANUM;
// return;
// $rowsNum = (count($_REQUEST)-SAVEASEXTRANUM)/3; // 通过公式计算要插入数据库原料表中的个数, "4"代表其它和原料无关的元素 "3"代表配方表的三个属性
$rowsNum=$_REQUEST["rowNum"];
for ($i =0; $i < $rowsNum; $i++){
// echo $_POST['ingre'.($i+1)];
$ingre = new ingre; // 建立一个配方对象
$ingre->__set('name',$_REQUEST['ingre'.($i+1)]);
$ingre->__set('metric',$_REQUEST['metric'.($i+1)]);
$ingre->__set('percent',$_REQUEST['percent'.($i+1)]);
$ingre->__set('recipeName',$_REQUEST['rName']);
$ingre->__set('recipeId',$id);
$ingre->__set('sum',$_REQUEST['sum']);
$ingre->__set('perSum',$_REQUEST['percentSum']);
$ingre->add();
$ingre=NULL;
// echo "原料: ".$_REQUEST['ingre'.($i+1)]." 用量: ".$_REQUEST['metric'.($i+1)]." 百分比: ".$_REQUEST['percent'.($i+1)]." 添加成功!<br />";
}
// echo "总量: ".$_REQUEST['sum']." 百分比: ".$_REQUEST['percentSum']." 添加成功!<br />";
echo "<script>alert('配方: ".$_REQUEST["recipeName"]." 另存为 ".$_REQUEST["rName"]." 成功!');</script>";
echo "<script>location.href='index.php';</script>";
}
else if ($_REQUEST["submit"] == "保存新增加配料") {
$rowsNumOld = $_REQUEST["rowNum"];
$rowsNumNew = $_REQUEST["rowNumNew"];
$sum = $_REQUEST['sum'];
$perSum = $_REQUEST['percentSum'];
if ($rowsNumNew > $rowsNumOld) {
# code...
for ($i = 1; $i <= $rowsNumNew ; $i++) {
if ($i <= $rowsNumOld) {
# code...
$ingre = new ingre;
$ingre->__set("id",$_REQUEST["ingreId".$i]);
$ingre->__set('sum', $_REQUEST['sum']);
$ingre->__set('perSum', $_REQUEST['percentSum']);
$ingre->updateSum();
} else {
# code...
$ingre = new ingre; // 建立一个配方对象
$ingre->__set('name',$_REQUEST['ingre'.$i]);
$ingre->__set('metric',$_REQUEST['metric'.$i]);
$ingre->__set('percent',$_REQUEST['percent'.$i]);
$ingre->__set('recipeName',$_REQUEST['rName']);
$ingre->__set('recipeId',$_REQUEST['recipeId']);
$ingre->__set('sum',$_REQUEST['sum']);
$ingre->__set('perSum',$_REQUEST['percentSum']);
$ingre->add();
$ingre=NULL;
}
}
} else {
echo "<script>alert('请确认你己经增加新配料!');</script>";
echo "<script>location.href='index.php?action=showDetail&id=".$_REQUEST["recipeId"]."';</script>";
}
// 更新配方总量和总百分比
print("<script>alert('配方 \"".$_REQUEST["rName"]."\" 配方新增项 成功!');</script>");
print("<script>location.href='index.php?action=showDetail&id=".$_REQUEST["recipeId"]."';</script>");
}
else {
print("<script>location.href='index.php';</script>");
}
}
?>