-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplaneditmulti.php
More file actions
425 lines (421 loc) · 14.6 KB
/
planeditmulti.php
File metadata and controls
425 lines (421 loc) · 14.6 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
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<!DOCTYPE html>
<?php
require_once __DIR__ . '/vendor/owasp/csrf-protector-php/libs/csrf/csrfprotector.php';
csrfProtector::init();
require('config/config.php');
require('func/plantype.php');
$showform = true;
$action = $_POST["action"] ?? "view";
$planids = explode(",", $_GET["ids"] ?? "");
?>
<html lang="zh-Hant-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
require __DIR__ . '/commonhead.php';
?>
<title><?=$C["titlename"]?>/編輯多筆教案</title>
<style type="text/css">
body {
padding-top: 4.5rem;
}
.itemicon {
width: 18px;
text-align: center;
}
</style>
</head>
<body>
<?php
require("header.php");
$showform = true;
if (!$U["islogin"]) {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
此功能需要驗證帳號,請<a href="<?=$C["path"]?>/login/">登入</a>
</div>
<?php
$showform = false;
}
if ($showform) {
$D["plans"]["file"] = array();
foreach ($planids as $planid) {
$sth = $G["db"]->prepare("SELECT * FROM `plan` WHERE `id` = :id");
$sth->bindValue(":id", $planid);
$sth->execute();
$D["plan"][$planid] = $sth->fetch(PDO::FETCH_ASSOC);
if ($D["plan"][$planid] === false) {
?>
<div class="alert alert-danger" role="alert">
找不到教案 <?=$planid?>,<a href="<?=$C["path"]?>/manageplans/">請回到列表重新選擇</a>
</div>
<?php
$showform = false;
} else {
$D["plan"][$planid]["tag"] = json_decode($D["plan"][$planid]["tag"], true);
$D["plan"][$planid]["file"] = json_decode($D["plan"][$planid]["file"], true);
foreach ($D["plan"][$planid]["file"] as $file) {
if (!in_array($file, $D["plans"]["file"])) {
$D["plans"]["file"][]= $file;
}
}
foreach ($D["plan"][$planid]["file"] as $file) {
if (!isset($D["file"][$planid][$file])) {
$sthfile = $G["db"]->prepare("SELECT * FROM `file` WHERE `id` = :id");
$sthfile->bindValue(":id", $file);
$sthfile->execute();
$D["file"][$file] = $sthfile->fetch(PDO::FETCH_ASSOC);
}
}
}
}
}
if ($showform && $action == "edit") {
if ($_POST["edityear"] == 1) {
$sth = $G["db"]->prepare("UPDATE `plan` SET `year` = :year WHERE `id` = :id");
foreach ($planids as $planid) {
$sth->bindValue(":year", $_POST["year"]);
$sth->bindValue(":id", $planid);
$sth->execute();
}
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改學年度
</div>
<?php
}
if ($_POST["type"] !== "") {
$sth = $G["db"]->prepare("UPDATE `plan` SET `type` = :type WHERE `id` = :id");
foreach ($planids as $planid) {
$sth->bindValue(":type", $_POST["type"]);
$sth->bindValue(":id", $planid);
$sth->execute();
}
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改分類
</div>
<?php
}
if ($_POST["editdescription"] == "1") {
$sth = $G["db"]->prepare("UPDATE `plan` SET `description` = :description WHERE `id` = :id");
foreach ($planids as $planid) {
$sth->bindValue(":description", $_POST["description"]);
$sth->bindValue(":id", $planid);
$sth->execute();
}
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改說明
</div>
<?php
}
$addtag = array();
$deltag = array();
if (isset($_POST["tag"])) {
foreach ($_POST["tag"] as $tag => $status) {
if ($status == 1) {
$addtag[]= $tag;
} else if ($status == 0) {
$deltag[]= $tag;
}
}
}
foreach ($_POST["newtag"] as $newtag) {
$newtag = trim($newtag);
$newtag = preg_replace("/[[:cntrl:]]/", "", $newtag);
if ($newtag != "" && !in_array($newtag, $addtag)) {
$addtag[] = $newtag;
}
}
$sth = $G["db"]->prepare("UPDATE `plan` SET `tag` = :tag WHERE `id` = :id");
foreach ($planids as $planid) {
$tag = array_diff($D["plan"][$planid]["tag"], $deltag);
$tag = array_merge($tag, $addtag);
$tag = array_unique($tag);
if ($tag != $D["plan"][$planid]["tag"]) {
$sth->bindValue(":tag", json_encode($tag));
$sth->bindValue(":id", $planid);
$sth->execute();
?>
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改冊別 <?=$D["plan"][$planid]["name"]?>
</div>
<?php
}
}
if (count($addtag)) {
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已為所有教案加上這些冊別:<?=implode("、", $addtag)?>
</div>
<?php
}
if (count($deltag)) {
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已從所有教案移除這些冊別:<?=implode("、", $deltag)?>
</div>
<?php
}
$addfile = array();
$delfile = array();
if (isset($_POST["file"])) {
foreach ($_POST["file"] as $file => $status) {
if ($status == 1) {
$addfile[]= $file;
} else if ($status == 0) {
$delfile[]= $file;
}
}
}
foreach ($_POST["newfile"] as $newfile) {
$newfile = trim($newfile);
$newfile = preg_replace("/[[:cntrl:]]/", "", $newfile);
if ($newfile != "" && !in_array($newfile, $addfile)) {
$addfile[] = $newfile;
}
}
$sth = $G["db"]->prepare("UPDATE `plan` SET `file` = :file WHERE `id` = :id");
foreach ($planids as $planid) {
$file = array_diff($D["plan"][$planid]["file"], $delfile);
$file = array_merge($file, $addfile);
$file = array_unique($file);
if ($file != $D["plan"][$planid]["file"]) {
$sth->bindValue(":file", json_encode($file));
$sth->bindValue(":id", $planid);
$sth->execute();
?>
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改檔案 <?=$D["plan"][$planid]["name"]?>
</div>
<?php
}
}
if (count($addfile)) {
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已為所有教案加上這些檔案:<?=implode("、", $addfile)?>
</div>
<?php
}
if (count($delfile)) {
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已從所有教案移除這些檔案:<?=implode("、", $delfile)?>
</div>
<?php
}
if ($_POST["inuse"] != -1) {
$sth = $G["db"]->prepare("UPDATE `plan` SET `inuse` = :inuse WHERE `id` = :id");
foreach ($planids as $planid) {
$sth->bindValue(":inuse", $_POST["inuse"]);
$sth->bindValue(":id", $planid);
$sth->execute();
}
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已修改狀態
</div>
<?php
}
} else if ($showform && $action == "del") {
if (isset($_POST["del"])) {
foreach ($planids as $planid) {
$sth = $G["db"]->prepare("DELETE FROM `plan` WHERE `id` = :id");
$sth->bindValue(":id", $planid);
$sth->execute();
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
已刪除 <?=$D["plan"][$planid]["name"]?>
</div>
<?php
}
?>
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<a href="<?=$C["path"]?>/manageplans/">回到教案列表</a>
</div>
<?php
$showform = false;
} else {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
請勾選「確認刪除」
</div>
<?php
}
}
require("func/tag.php");
if ($showform) {
?>
<div class="container">
<h2>編輯多筆教案 <a class="btn btn-sm btn-info" href="<?=$C["path"]?>/plan/<?=($_GET["ids"] ?? "")?>/" role="button" target="_blank"><i class="fa fa-eye" aria-hidden="true"></i> 查看</a></h2>
<form action="" method="post">
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-header itemicon" aria-hidden="true"></i> 標題</label>
<div class="col-sm-9 col-md-10">
<?php
foreach ($D["plan"] as $planid => $plan) {
echo htmlentities($plan["name"])."<br>";
}
?>
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-calendar itemicon" aria-hidden="true"></i> 學年度</label>
<div class="col-sm-9 col-md-10 form-inline">
<label class="form-control-label">
<input class="form-control" type="radio" name="edityear" value="0" checked> 不修改
</label>
<label class="form-control-label">
<input class="form-control" type="radio" name="edityear" id="edityear1" value="1"> 修改為
</label>
<input class="form-control" type="number" name="year" onfocus="edityear1.checked=true;" min="0" max="99999999">
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-bookmark itemicon" aria-hidden="true"></i> 分類</label>
<div class="col-sm-9 col-md-10">
<select name="type" class="form-control">
<option value="">不修改</option>
<?php
foreach ($D['plantype'] as $id => $plantype) {
?><option value="<?=$id?>"><?=$plantype?></option><?php
}
?>
</select>
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-info itemicon" aria-hidden="true"></i> 說明</label>
<div class="col-sm-9 col-md-10">
<div class="row">
<div class="col-12 form-inline">
<label class="form-control-label">
<input class="form-control" type="radio" name="editdescription" value="0" checked> 不修改
</label>
<label class="form-control-label">
<input class="form-control" type="radio" name="editdescription" id="editdescription1" value="1"> 修改為
</label>
</div>
</div>
<div class="row">
<div class="col-12">
<textarea class="form-control" name="description" onfocus="editdescription1.checked=true;"></textarea>
</div>
</div>
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-tags itemicon" aria-hidden="true"></i> 標籤</label>
<div class="col-sm-9 col-md-10">
<div class="checkbox">
<?php
foreach ($D['tag'] as $tag => $cnt) {
?>
<label class="form-control-label"><input type="radio" name="tag[<?=$tag?>]" value="-1" checked> 不修改</label>
<label class="form-control-label"><input type="radio" name="tag[<?=$tag?>]" value="1"> 加上</label>
<label class="form-control-label"><input type="radio" name="tag[<?=$tag?>]" value="0"> 移除</label>
<mark><?=htmlentities($tag)?> (<?=$cnt?>)</mark>
<br>
<?php
}
?>
<div id="taglist">
<input type="text" name="newtag[]" placeholder="新增" maxlength="15">
</div>
<button type="button" class="btn btn-default btn-sm" onclick="moretag()"><i class="fa fa-tag" aria-hidden="true"></i> 更多</button>
</div>
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-files-o itemicon" aria-hidden="true"></i> 檔案</label>
<div class="col-sm-9 col-md-10">
<div class="checkbox">
<?php
foreach ($D["plans"]["file"] as $file) {
?>
<label class="form-control-label"><input type="radio" name="file[<?=$file?>]" value="-1" checked> 不修改</label>
<label class="form-control-label"><input type="radio" name="file[<?=$file?>]" value="1"> 加上</label>
<label class="form-control-label"><input type="radio" name="file[<?=$file?>]" value="0"> 移除</label>
<a href="<?=$C["path"]?>/file/<?=$file?>/" target="_blank"><?=htmlentities($D["file"][$file]["name"])?></a>
<br>
<?php
}
?>
<div id="filelist">
<input type="text" name="newfile[]" placeholder="新檔案" hidden>
</div>
<button type="button" class="btn btn-default btn-sm" onclick="pickfile()"><i class="fa fa-file" aria-hidden="true"></i> 更多檔案</button>
</div>
</div>
</div>
<div class="row">
<label class="col-sm-3 col-md-2 form-control-label"><i class="fa fa-eye itemicon" aria-hidden="true"></i> 狀態</label>
<div class="col-sm-9 col-md-10">
<label>
<input type="radio" name="inuse" value="-1" checked> 不修改
</label>
<label>
<input type="radio" name="inuse" value="1"> <i class="fa fa-eye" aria-hidden="true"></i> <?=$G["inuse"][1]?>
</label>
<label>
<input type="radio" name="inuse" value="0"> <i class="fa fa-eye-slash" aria-hidden="true"></i> <?=$G["inuse"][0]?>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-9 col-md-10 offset-sm-2">
<button type="submit" name="action" value="edit" class="btn btn-success"><i class="fa fa-pencil" aria-hidden="true"></i> 編輯多筆</button>
</div>
</div>
<div class="row">
<div class="col-sm-9 col-md-10 offset-sm-2">
<button type="submit" name="action" value="del" class="btn btn-danger"><i class="fa fa-trash-o" aria-hidden="true"></i> 刪除</button>
<label>
<input type="checkbox" name="del">確認刪除
</label>
</div>
</div>
</form>
</div>
<script type="text/javascript">
function moretag(){
var temp=taglist.children[0].cloneNode(true);
temp.value="";
taglist.appendChild(temp);
}
function morefile(id=""){
var temp=filelist.children[0].cloneNode(true);
temp.value=id;
temp.hidden=false;
filelist.appendChild(temp);
}
function removefile(id){
document.all["file_"+id].remove();
}
function pickfile(id){
window.open("<?=$C["path"]?>/pickfile/", "_blank");
}
</script>
<?php
}
require("footer.php");
?>
</body>
</html>