-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
241 lines (202 loc) · 9.65 KB
/
index.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
<?php
// エラー表示(必要な時以外はコメントアウト)
// error_reporting(E_ALL);
// ini_set("display_errors", "1");
// セッション開始
session_start();
// config読み込み
require_once "config/config.php";
// データベース接続
require_once "config/database.php";
// ユーザーログイン確認
require "app/functions/student_id_check.php";
$student_id = studentIdCheck();
// 写真データを取得
try {
// すべての写真データを取得
$sql = "SELECT name, path, detection, comment FROM photos";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$result_photo_data = $stmt->fetchAll();
if ($result_photo_data === false) {
// データベースエラー
http_response_code(500);
include("error/database.php");
exit;
}
$sql = "SELECT name FROM students WHERE id = :student_id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(":student_id", $student_id, PDO::PARAM_INT);
$stmt->execute();
$student_name = $stmt->fetchColumn();
// 結果を出力
if ($student_name === false) {
// データベースエラー
http_response_code(500);
include("error/database.php");
exit;
}
} catch (PDOException $e) {
// エラー表示(必要時以外はコメントアウト)
//echo $e->getMessage();
http_response_code(500);
include("error/database.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="ja">
<head prefix="og: http://ogp.me/ns#">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>みーつけた</title>
<meta name="description" content="「みーつけた」は生徒の学校での様子を保護者に簡単・安全に届けることができるWebアプリケーションです。">
<meta name="format-detection" content="telephone=no"/>
<meta name="robots" content="noindex">
<link rel="manifest" href="https://<?php echo $config["domain"] ?>/manifest.json">
<!-- アイコン -->
<link rel="icon" href="https://<?php echo $config["domain"]; ?>/assets/img/favicon.ico"/>
<link rel="apple-touch-icon" href="https://<?php echo $config["domain"]; ?>/assets/img/apple-touch-icon.png"/>
<!-- OGP -->
<meta property="og:url" content="https://<?php echo $config["domain"]; ?>"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="みーつけた - 生徒写真共有Webアプリ"/>
<meta property="og:description" content="「みーつけた」は生徒の学校での様子を保護者に簡単・安全に届けることができるWebアプリケーションです。"/>
<meta property="og:site_name" content="みーつけた"/>
<meta property="og:image" content="https://<?php echo $config["domain"]; ?>/assets/img/site-share.png"/>
<meta property="og:locale" content="ja_JP"/>
<!-- CSS -->
<link rel="stylesheet" href="https://<?php echo $config["domain"]; ?>/assets/css/style.css" type="text/css">
<!-- JSにドメインを受け渡し -->
<script> var domain = "<?php echo $config["domain"]; ?>"; </script>
</head>
<body>
<!-- ヘッダー -->
<header>
<a href="https://<?php echo $config["domain"]; ?>"><h1>みーつけた</h1></a>
<nav class="desktop-nav">
<div class="dropdown">
<button class="dropdown-button">メニュー</button>
<div class="dropdown-content">
<a href="https://<?php echo $config["domain"]; ?>/">ホーム</a>
<a href="https://<?php echo $config["domain"]; ?>/setting">設定</a>
<a href="https://<?php echo $config["domain"]; ?>/dashboard">ダッシュボード</a>
</div>
</div>
<div class="dropdown">
<button class="dropdown-button" onclick="logout()">ログアウト</button>
</div>
</nav>
<div class="hamburger-menu" onclick="headerMenu()">
<span></span>
<span></span>
<span></span>
</div>
<nav class="side-menu">
<ul>
<li><a href="https://<?php echo $config["domain"]; ?>/">ホーム</a></li>
<li><a href="https://<?php echo $config["domain"]; ?>/setting">設定</a></li>
<li><a href="https://<?php echo $config["domain"]; ?>/dashboard">ダッシュボード</a></li>
<li><a href="#" onclick="logout()">ログアウト</a></li>
</ul>
</nav>
</header>
<!-- コンテンツ -->
<div class="content">
<!-- コンテナ -->
<div class="container">
<!-- らしき写真 -->
<p><i class="fa-solid fa-user" style="color: #188681;"></i> <?php echo $student_name; ?>さんらしき写真</p>
<div class="gallery" id="gallery1">
<?php
// らしき写真挿入数
$i = 0;
// らしき写真を挿入
foreach ($result_photo_data as $row) {
$comment = isset($row["comment"]) ? htmlspecialchars($row["comment"], ENT_QUOTES, "UTF-8") : "";
$detection = isset($row["detection"]) ? json_decode($row["detection"], true) : false;
if ($detection != false) {
if (in_array($student_id, $detection)) {
echo '<div class="gallery-div">';
echo '<img src="https://' . $config["domain"] . '/app/api/media_read.php/?id=' . htmlspecialchars($row["path"], ENT_QUOTES, "UTF-8") . '" alt="' . htmlspecialchars($row["name"], ENT_QUOTES, "UTF-8") . '" data-comment="' . $comment . '" onclick="openModal(this)">';
echo "</div>";
$i++;
}
}
}
// もし挿入数が0だったら
if ($i == 0) {
echo"<p>らしき写真が見つかりませんでした。</p>";
}
?>
</div> <!-- gallery -->
<!-- すべての写真 -->
<p><i class="fa-solid fa-images" style="color: #188681;"></i> 全ての写真</p>
<div class="gallery" id="gallery2">
<?php
// すべての写真挿入
$total_pages = ceil(count($result_photo_data) / 10); // 写真の総数/1ページあたりの表示数
$page_now = isset($_GET["page"]) ? $_GET["page"] : 1; // 現在のページをGETから受信(値がない場合は「1」)
$start_img = ($page_now - 1) * 10; // 現在のページの最初のimg
// 画像をページごとに表示
$i = 0;
foreach (array_slice($result_photo_data, $start_img, 10) as $row) {
$comment = isset($row["comment"]) ? htmlspecialchars($row["comment"], ENT_QUOTES, "UTF-8") : "";
echo '<div class="gallery-div">';
echo '<img src="https://' . $config["domain"] . '/app/api/media_read.php/?id=' . htmlspecialchars($row["path"], ENT_QUOTES, "UTF-8") . '" alt="' . htmlspecialchars($row["name"], ENT_QUOTES, "UTF-8") . '" data-comment="' . $comment . '" onclick="openModal(this)">';
echo "</div>";
$i++;
}
// もし挿入数が0だったら
if ($i == 0) {
echo "<p>写真がありませんでした。</p>";
}
?>
</div> <!-- gallery -->
<!-- モーダル -->
<div class="modal" id="modal" onclick="closeModal(event)">
<span class="modal-close" id="modal-close">×</span>
<img class="modal-img" id="modal-img">
<div class="modal-frame" id="modal-frame">
<div class="modal-caption" id="modal-caption"></div>
<p id="comment"></p>
<a class="modal-dl-btn" id="modal-dl-btn">保存</a>
</div>
</div> <!-- modal -->
<!-- ページネーション -->
<div class="pagination">
<?php
// 前へボタン挿入
if ($page_now > 1) {
echo '<a href="?page=' . $page_now - 1 . '">« 前へ</a>';
} else {
echo "<span>« 前へ</span>";
}
// ページボタン挿入
for ($page = 1; $page <= $total_pages; $page++) {
if ($page == $page_now) {
echo '<a href="?page=' . strval($page) . '" class="active">' . $page . '</a>';
} else {
echo '<a href="?page=' . strval($page) . '">' . $page . '</a>';
}
}
// 次へボタン挿入
if ($page_now < $total_pages) {
echo '<a href="?page=' . $page_now + 1 . '">次へ »</a>';
} else {
echo "<span>次へ »</span>";
}
?>
</div> <!-- pagination -->
</div> <!-- container -->
</div> <!-- contents -->
<!-- フッター -->
<footer>
<p>© 2025 YukiShima</p>
</footer>
<!-- FontAwesome -->
<script type="text/javascript" charset="UTF-8" src="https://kit.fontawesome.com/91559ddbec.js" crossorigin="anonymous"></script>
<!-- student-home.js -->
<script type="text/javascript" charset="UTF-8" src="https://<?php echo $config["domain"]; ?>/assets/js/student-home.js"></script>
</body>
</html>