-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshift_delete_form.php
300 lines (241 loc) · 6.74 KB
/
shift_delete_form.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
<?php
session_start();
//データベースに接続
$dsn = 'mysql:dbname=*******;host=localhost';
$user = '*******';
$password = '********';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print('Error:' . $e->getMessage());
die();
}
//タイムゾーン設定
date_default_timezone_set('Asia/Tokyo');
$today = filter_input(INPUT_POST, 'today');
$monthNext = filter_input(INPUT_POST, 'monthNext');
$yearNext = filter_input(INPUT_POST, 'yearNext');
$monthPrev = filter_input(INPUT_POST, 'monthPrev');
$yearPrev = filter_input(INPUT_POST, 'yearPrev');
$caldate = time();
if ($today == 1) {
$month = date("n", $caldate);
$year = date("Y", $caldate);
}
if ($monthNext > 12) {
$monthNext = 1;
$yearNext++;
}
if ($monthPrev === "0") {
$monthPrev = 12;
$yearPrev--;
}
$month = $monthNext ?? $monthPrev ?? date('n');
$year = $yearNext ?? $yearPrev ?? date('Y');
//ページ更新時の処理
if (isset($_SESSION['form_month']) && isset($_SESSION['form_year']) && isset($_SESSION['btn_pushed3'])) {
$month = $_SESSION['form_month'];
$year = $_SESSION['form_year'];
unset($_SESSION['btn_pushed3']);
}
$_SESSION['form_month'] = $month;
$_SESSION['form_year'] = $year;
//月末日を取得
$end_month = date('t', strtotime($year . $month . '01'));
$_SESSION['year'] = $year;
$_SESSION['month'] = $month;
$_SESSION['end_month'] = $end_month;
$id = $_SESSION['user_id'];
$aryCalendar = [];
//リダイレクト
if (isset($_SESSION['user_id'])) { //ログインしているとき
} else { //ログインしていない時
header('Location: ./login_form.php');
exit();
}
//入力欄の生成
for ($i = 1; $i <= $end_month; $i++) {
//startの初期値を設定
$sql_start = sprintf("
select start_time
from request
where id = '%s' and
year = '%s' and
month = '%s' and
day = '%s'
", $id, $year, $month, $i);
$stmt1 = $dbh->prepare($sql_start);
$stmt1->execute();
$start = $stmt1->fetch();
//endの初期値を設定
$sql_end = sprintf("
select end_time
from request
where id = '%s' and
year = '%s' and
month = '%s' and
day = '%s'
", $id, $year, $month, $i);
$stmt2 = $dbh->prepare($sql_end);
$stmt2->execute();
$end = $stmt2->fetch();
$aryScheduler[$i] = '';
if ((!empty($start['start_time'])) || (!empty($end['end_time']))) {
if (!empty($start['start_time'])) {
$aryScheduler[$i] .= $start['start_time'];
} else {
$aryScheduler[$i] .= ' ';
}
$aryScheduler[$i] .= '~';
if (!empty($end['end_time'])) {
$aryScheduler[$i] .= $end['end_time'];
} else {
$aryScheduler[$i] .= ' ';
}
}
}
//ステータスの確認
$status = [];
for ($i = 1; $i <= $end_month; $i++) {
$sql = sprintf("
select status
from request
where id = '%s' and
year = '%s' and
month = '%s' and
day = '%s'
", $id, $year, $month, $i);
$stmt3 = $dbh->prepare($sql);
$stmt3->execute();
$s = $stmt3->fetch();
//値が格納されている日のみ処理を行う
$tmp = isset($s['status']);
//値が格納されている場合
if ($tmp == 1) {
if ($s['status'] == 0) {
$status[$i] = '<font color="#0000ff">申請中</font>';
} else {
$status[$i] = '<font color="#ff7f7f">申請済</font>';
}
//値が格納されていない場合
} else {
$status[$i] = '';
}
}
$select = [];
for ($i = 1; $i <= $end_month; $i++) {
$sql = sprintf("
select status
from request
where id = '%s' and
year = '%s' and
month = '%s' and
day = '%s'
", $id, $year, $month, $i);
$stmt3 = $dbh->prepare($sql);
$stmt3->execute();
$s = $stmt3->fetch();
//値が格納されている日のみ処理を行う
$tmp = isset($s['status']);
if ($tmp == 1) {
if ($s['status'] == 0) {
$select[$i] = '<input type="checkbox" class="button" name="check_box';
$select[$i] .= $i;
$select[$i] .= '"value="';
$select[$i] .= $id;
$select[$i] .= '">';
}else{
$select[$i] = '';
}
//値が格納されていない場合
} else {
$select[$i] = '';
}
}
//1日から月末日までループ
for ($i = 1; $i <= $end_month; $i++) {
$aryCalendar[$i]['day'] = $i;
$aryCalendar[$i]['week'] = date('w', mktime(12, 00, 00, $month, sprintf('%02d', $i), $year));
$aryCalendar[$i]['text'] = $aryScheduler[$i];
$aryCalendar[$i]['status'] = $status[$i];
$aryCalendar[$i]['select'] = $select[$i];
}
$aryWeek = ['日', '月', '火', '水', '木', '金', '土'];
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>シュシュ勤怠管理システム</title>
<link rel="stylesheet" href="styles2.css">
</head>
<body>
<a href="index.php">
<header>
<div class="container">
<h1>シュシュ勤怠管理システム</h1>
</div>
</header>
</a>
<div class="bar">
<div class="container">
<section>
<article>
<form action="" method="post">
<th><button type="submit" id="prev">
«
<input type="hidden" name="monthPrev" value="<?php echo $month - 1; ?>">
<input type="hidden" name="yearPrev" value="<?php echo $year; ?>">
</button></th>
</form>
</article>
<article>
<h1><?php echo $year ?></h1>
<bar>
<h1><?php echo $month ?></h1>
</article>
<article>
<form action="" method="post">
<th><button type="submit" id="next">
»
<input type="hidden" name="monthNext" value="<?php echo $month + 1; ?>">
<input type="hidden" name="yearNext" value="<?php echo $year; ?>">
</button></th>
</form>
</article>
</section>
</div>
</div>
<FORM ACTION="shift_delete.php" METHOD="GET">
<div class="container">
<table class="calender_column">
<?php foreach ($aryCalendar as $value) { ?>
<?php if ($value['day'] != date('j')) { ?>
<tr class="week<?php echo $value['week'] ?>">
<?php } else { ?>
<tr class="today">
<?php } ?>
<td>
<?php echo $value['day'] ?>(<?php echo $aryWeek[$value['week']] ?>)
</td>
<td>
<?php echo $value['text'] ?>
</td>
<td>
<?php echo $value['status'] ?>
</td>
<td>
<?php echo $value['select'] ?>
</td>
</tr>
<?php } ?>
</table>
</div>
<BR>
<div class="container">
<INPUT TYPE="submit" VALUE="送信" class="button" name="btn">
</div>
<BR>
</FORM>
</body>
</html>