-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage_schoolformat.php
333 lines (321 loc) · 12.1 KB
/
manage_schoolformat.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
<?php
require_once(__DIR__."/config/config.php");
require_once(__DIR__."/func/school.php");
require_once(__DIR__."/func/school_input.php");
require_once(__DIR__."/func/data.php");
require_once(__DIR__."/func/fonts.php");
require_once(__DIR__."/func/log.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;
writelog(sprintf("[manage_schoolformat] %s view no premission.", $U["ip"]));
}
$showpdf = false;
if (isset($_POST["grid"])) {
$showpdf = true;
$_SESSION["file"] = "school";
$_SESSION["mode"] = "grid";
}
if (isset($_POST["preview"])) {
$showpdf = true;
$_SESSION["file"] = "school";
$_SESSION["mode"] = "preview";
}
function write_school($data) {
$handle = fopen(__DIR__."/data/school.csv", "w");
if ($handle === false) {
writelog(sprintf("[manage_schoolformat] %s %s read school.csv failed.", $U["data"]["account"], $U["ip"]));
exit("取得school.csv錯誤");
}
foreach ($data as $row) {
unset($row['source']);
fputcsv($handle, $row);
}
fclose($handle);
}
if ($showform && isset($_POST["delete"])) {
foreach ($_POST["deleteitem"] as $hash) {
?>
<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['school'][$hash][0]?>
</div>
<?php
unset($D['school'][$hash]);
writelog(sprintf("[manage_schoolformat] %s %s delete %s successed.", $U["data"]["account"], $U["ip"], $D['school'][$hash][0]));
}
write_school($D['school']);
require(__DIR__."/func/school.php");
}
if ($showform && isset($_POST["new"])) {
$data = [$_POST["column"], $_POST["positionx"], $_POST["positionx2"], $_POST["positiony"], $_POST["font"], $_POST["size"], $_POST["style"], $_POST["align"]];
$hash = md5(serialize($data));
if (isset($D['school'][$hash])) {
?>
<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
writelog(sprintf("[manage_schoolformat] %s %s new failed. dup:%s.", $U["data"]["account"], $U["ip"], json_encode($data)));
} else {
$D['school'] []= $data;
write_school($D['school']);
require(__DIR__."/func/school.php");
?>
<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>
已新增 <?=$_POST["column"]?>
</div>
<?php
writelog(sprintf("[manage_schoolformat] %s %s new successed. %s.", $U["data"]["account"], $U["ip"], json_encode($data)));
}
}
if ($showform && isset($_POST["edit"])) {
foreach ($_POST["format"] as $hash => $row) {
if (isset($D['school'][$hash])) {
$old = $D['school'][$hash];
unset($old['source']);
$new = [
$row["column"],
$row["positionx"],
$row["positionx2"],
$row["positiony"],
$row["font"],
$row["size"],
$row["style"],
$row["align"],
];
if ($old != $new) {
?>
<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['school'][$hash][0]?>
</div>
<?php
$D['school'][$hash] = $new;
writelog(sprintf("[manage_schoolformat] %s %s edit successed. %s -> %s.", $U["data"]["account"], $U["ip"], json_encode($old), json_encode($new)));
}
}
}
write_school($D['school']);
require(__DIR__."/func/school.php");
}
foreach ($D['school'] as $row) {
if ($row['source'] === "none") {
?>
<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>
設定錯誤:欄位 <?=$row[0]?> 不存在於學生資料、手動輸入、內建函數
</div>
<?php
}
}
?>
<!DOCTYPE html>
<html lang="zh-Hant-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<title><?=$C["titlename"]?>/管理學校下載格式</title>
<style type="text/css">
body {
padding-top: 4.5rem;
}
</style>
</head>
<body>
<?php
require("header.php");
if ($showform) {
?>
<div class="container-fluid">
<h2>管理學校下載格式</h2>
<div class="row">
<div class="col-12 col-md-4">
<form action="" method="post">
<button class="btn btn-default" type="submit" name="grid"><i class="fa fa-eye" aria-hidden="true"></i> 檢視格線檔</button>
<button class="btn btn-default" type="submit" name="preview"><i class="fa fa-eye" aria-hidden="true"></i> 檢視預覽檔</button>
</form>
</div>
<div class="col-12 col-md-8">
<?php
if ($showpdf) {
?>
<embed width="100%" height="900" src="<?=$C["path"]?>/download.php#zoom=80"></embed>
<?php
}
?>
</div>
</div>
<div class="row">
<div class="col">
<form action="" method="post" class="form-inline">
<div class="table-responsive">
<table class="table">
<tr>
<th>欄位</th>
<th>位置(X軸)</th>
<th>位置(Y軸)</th>
<th>字型</th>
<th>文字大小</th>
<th>樣式</th>
<th>對齊</th>
<th>操作</th>
</tr>
<?php
foreach ($D['school'] as $hash => $row) {
?>
<tr <?=($row['source']==='none'?' class="table-danger"':'')?>>
<td><input class="form-control" type="text" name="format[<?=$hash?>][column]" value="<?=$row[0]?>"> (<?=$G["source_text"][$row['source']]?>)</td>
<td><input class="form-control" type="number" name="format[<?=$hash?>][positionx]" value="<?=$row[1]?>" style="width: 80px;">~<input class="form-control" type="number" name="format[<?=$hash?>][positionx2]" value="<?=$row[2]?>" style="width: 80px;"> (<?=$row[2]-$row[1]?>)</td>
<td><input class="form-control" type="number" name="format[<?=$hash?>][positiony]" value="<?=$row[3]?>" style="width: 80px;"></td>
<td>
<select class="form-control" name="format[<?=$hash?>][font]">
<?php
foreach ($D['fonts'] as $font) {
?>
<option value="<?=$font["name"]?>" <?=($row[4]==$font["name"]?"selected":"")?> ><?=$font["text"]?></option>
<?php
}
?>
</select>
</td>
<td><input class="form-control" type="number" name="format[<?=$hash?>][size]" value="<?=$row[5]?>" style="width: 80px;"></td>
<td>
<select class="form-control" name="format[<?=$hash?>][style]">
<option value="" <?=($row[6]==""?"selected":"")?> >無</option>
<option value="B" <?=($row[6]=="B"?"selected":"")?> >粗體</option>
<option value="I" <?=($row[6]=="I"?"selected":"")?> >斜體</option>
<option value="U" <?=($row[6]=="U"?"selected":"")?> >底線</option>
<option value="BI" <?=($row[6]=="BI"?"selected":"")?> >粗斜</option>
<option value="BU" <?=($row[6]=="BU"?"selected":"")?> >粗底</option>
<option value="IU" <?=($row[6]=="IU"?"selected":"")?> >斜底</option>
<option value="BIU" <?=($row[6]=="BIU"?"selected":"")?> >粗斜底</option>
</select>
</td>
<td>
<select class="form-control" name="format[<?=$hash?>][align]">
<option value="L" <?=($row[7]=="L"?"selected":"")?> >靠左對齊</option>
<option value="C" <?=($row[7]=="C"?"selected":"")?> >置中</option>
<option value="R" <?=($row[7]=="R"?"selected":"")?> >靠右對齊</option>
<option value="J" <?=($row[7]=="J"?"selected":"")?> >左右對齊</option>
</select>
</td>
<td>
<label><input type="checkbox" name="deleteitem[]" value="<?=$hash?>"> 刪除此項</label>
</td>
</tr>
<?php
}
?>
</table>
</div>
<div class="row">
<div class="col">
<button type="submit" name="edit" class="btn btn-success"><i class="fas fa-edit"></i> 編輯</button>
<button type="submit" name="delete" class="btn btn-danger"><i class="fas fa-trash"></i> 刪除勾選的項目</button>
</div>
</div>
</form>
</div>
</div>
<h3 style="margin-top: 1em;">新增</h3>
<div class="row">
<div class="col">
<form action="" method="post">
<div class="row">
<label class="col-sm-2 form-control-label">欄位</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="column" required>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">位置(X軸,左)</label>
<div class="col-sm-10">
<input class="form-control" type="number" name="positionx" required>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">位置(X軸,右)</label>
<div class="col-sm-10">
<input class="form-control" type="number" name="positionx2" required>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">位置(Y軸)</label>
<div class="col-sm-10">
<input class="form-control" type="number" name="positiony" required>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">字型</label>
<div class="col-sm-10">
<select class="form-control" name="font">
<?php
foreach ($D['fonts'] as $font) {
?>
<option value="<?=$font["name"]?>"><?=$font["text"]?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">文字大小</label>
<div class="col-sm-10">
<input class="form-control" type="number" name="size" value="16" required>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">樣式</label>
<div class="col-sm-10">
<select class="form-control" name="style">
<option value="" selected>無</option>
<option value="B">粗體</option>
<option value="I">斜體</option>
<option value="U">底線</option>
<option value="BI">粗體+斜體</option>
<option value="BU">粗體+底線</option>
<option value="IU">斜體+底線</option>
<option value="BIU">粗體+斜體+底線</option>
</select>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-control-label">對齊</label>
<div class="col-sm-10">
<select class="form-control" name="align">
<option value="L">靠左對齊</option>
<option value="C" selected>置中</option>
<option value="R">靠右對齊</option>
<option value="J">左右對齊</option>
</select>
</div>
</div>
<div class="row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-success" name="new"><i class="fa fa-plus" aria-hidden="true"></i> 新增</button>
</div>
</div>
</form>
</div>
</div>
</div>
<?php
}
require("footer.php");
?>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DzthAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"></body>
</html>