Repository navigation
Expand file tree
/
Copy pathowner.php
More file actions
209 lines (194 loc) · 6.45 KB
/
Copy pathowner.php
File metadata and controls
209 lines (194 loc) · 6.45 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
<?php
$times = array(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 1, 2, 3, 4, 5);
//表に表示する曜日
$weekJpNames = array("月", "火", "水", "木", "金", "土", "日");
$shiftDatPath = "./data/shift.dat";
$workerDatPath = "./data/worker.dat";
$hours = 24;
$oneWeekDays = 7;
//新規の従業員登録のための情報が入力されてるか判定
if(isset($_POST["newWorker"]) && !(empty($_POST["newWorker"])) && !(empty($_FILES["upfile"]["name"]))) {
$newWorker = $_POST["newWorker"];
//画像ファイルをアップロード
if(is_uploaded_file($_FILES["upfile"]["tmp_name"])) {
if(move_uploaded_file($_FILES["upfile"]["tmp_name"],"./workericons/".$_FILES["upfile"]["name"])) {
chmod("./workericons/".$_FILES["upfile"]["name"],0750);
echo $_FILES["upfile"]["name"]."をアップロードしました。";
echo $_FILES["upfile"]["error"];
echo"<a href='http://192.168.33.10/shiftapp/owner.php'></a>";
} else {
echo "ファイルをアップロードできません。";
}
} else {
echo "ファイルが選択されていません。";
}
//登録した画像ファイルの変数を定義
$upfile =$_FILES["upfile"]["name"];
//投稿された名前と画像ファイルを従業員管理ファイルに書き込むための指定
$workerIcon = $newWorker.",".$upfile;
//新規従業員を従業員管理ファイルに書き込む
if(is_writable($workerDatPath) === false) {
echo "not writable";
exit;
}
$filePointer = fopen($workerDatPath, "a");
if($filePointer == false) {
echo "could not open";
exit;
}
if(fwrite($filePointer, $workerIcon."\n") === false) {
echo "could not write";
exit;
}
fclose($filePointer);
}
//従業員管理ファイルを読み込む
$workerData = file($workerDatPath);
$newWorkerMax = count($workerData);
//従業員管理ファイルを配列化
for($i = 0; $i < $newWorkerMax; $i++) {
//$workerIcons[][0]登録した従業員の名前
//$workerIcons[][1]登録した従業員の画像
$workerIcons[] = explode(",", $workerData[$i]);
}
//従業員シフト情報ファイルを読み込む
$shiftTimes = file($shiftDatPath);
$workerMax = count($shiftTimes);
$workerName = $_POST["workerName"];
//指定した従業員のシフト情報をファイルにから削除
for($i = 0; $i < $workerMax; $i++) {
if(strpos($shiftTimes[$i], $workerName) !== false) {
unset($shiftTimes[$i]);
}
}
//削除した配列を詰める
$shiftTimes = array_merge($shiftTimes);
//変更された、従業員シフト情報ファイルを配列化
$workerMax = count($shiftTimes);
for($i = 0; $i < $workerMax; $i++) {
//$workerShifts[][0]名前
//$workerShifts[][1]開始時間
//$workerShifts[][2]終了時間
//$workerShifts[][3]曜日
$workerShifts[] = explode(",", $shiftTimes[$i]);
}
//従業員情報を管理するファイルを、空にして書き直す
if(is_writable($shiftDatPath) === false) {
echo "not writable";
exit;
}
$filePointer = fopen($shiftDatPath, "w");
if($filePointer === false) {
echo "could not open";
exit;
}
//配列を1行づつ書き込む
for($i = 0; $i < $workerMax; $i++ ) {
if(fwrite($filePointer, $shiftTimes[$i]) === false) {
echo "could not write";
exit;
}
}
fclose($filePointer);
?>
<!DOCTYPE html>
<html lang ='ja'>
<head>
<meta charaset = 'UTF-8'>
<title>シフトを確認して調整しましょう</title>
<link rel="stylesheet" href="./stylesheet/style.css">
</head>
<body>
<h1>シフトのチェックができます</h1>
<table>
<?php
//週の曜日の7行+時間帯の表示の1行を表示させるため<=条件式とする
for($i = 0; $i <= $oneWeekDays; $i++):
if ($i == 0){
echo "<thead>";
} elseif($i == 1){
echo "<tbody>";
}
?>
<tr>
<?php
//1日24時間分の列+曜日の表示の1列を表示させるため<=条件式とする
for($j = 0; $j <= $hours; $j++):
?>
<td>
<?php
//表に時間と曜日を表示
if($j > 0 && $i == 0) {
echo $times[$j-1];
} elseif ($j == 0 && $i > 0) {
echo $weekJpNames[$i-1];
} else {
echo ' ';
}
//表示するためにtime配列内のシフトの開始時間と終了時間の添え字を取り出す
for($k = 0; $k < $workerMax; $k++) {
for($l = 0; $l < $hours; $l++) {
if($times[$l] == $workerShifts[$k][1]) {
$startTime = $l;
}
if($times[$l] == $workerShifts[$k][2]) {
$endTime = $l;
}
}
//時間表示の1行に書き込まれないようにする
if($i > 0 && $j - 1 >= $startTime && $j - 1 <= $endTime && $workerShifts[$k][3][$i-1] == 1) {
// echo "<img src='{$workerIcons[$workerShihts[$k][0]]}'>\n";
for($m = 0; $m < $newWorkerMax; $m++) {
if($workerShifts[$k][0] == $workerIcons[$m][0]) {
echo "<img src='./workericons/{$workerIcons[$m][1]}'>\n";
//echo "<img src='./workericons/{$workerIcons[0][1]}'>";
}
}
}
}
?>
</tb>
<?php endfor; ?>
</tr>
<?php endfor; ?>
<?php
if ($i == 0) {
echo "</thead>";
} elseif ($i == $oneWeekDays) {
echo "</tbody>";
}
?>
</table>
<form action='' method='post' enctype="multipart/form-data">
シフトを変更したい従業員を選択してください
<br>
<br>
<select name='workerName'>
<option value="従業員一覧">従業員</option>]
<?php
for ($i = 0; $i < $newWorkerMax; $i++){
echo "<option value='{$workerIcons[$i][0]}'>";
echo $workerIcons[$i][0];
echo "</option>";
}
?>
</select>
<br>
<p1><input type='submit' value='シフトをリセットする'></p1>
<br>
<br>
追加したい従業員を登録できます。
<br>
<br>
名前
<p2><input type='text' value='' name='newWorker'></p2>
<br>
<p3><input type="file" name="upfile"><p3>
<p4><input type='submit' value='登録する'></p4>
<br>
<a href="host.php">完成したシフトはこちら</a>
<a href="shift.php">シフト登録はこちら</a>
</form>
<br>
</body>
</html>