From 3ea8d828edd5e57cc832dfdfe9c1921c059954cc Mon Sep 17 00:00:00 2001 From: kemasama Date: Sun, 22 May 2022 17:25:43 +0900 Subject: [PATCH] fix: timecard --- .gitignore | 3 +-- provide/classes/BootLoader.php | 10 +++++++++- provide/classes/Timecard.php | 27 ++++++++++++++++++++++++--- template/view.php | 25 +++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 96e1dc5..0f9bd0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ config.php -install.php - +.htaccess diff --git a/provide/classes/BootLoader.php b/provide/classes/BootLoader.php index 2dcfa0c..1cf7014 100644 --- a/provide/classes/BootLoader.php +++ b/provide/classes/BootLoader.php @@ -32,8 +32,15 @@ class BootLoader $isAdmin = false; $loginUser = []; $works = []; + $month = 0; $page = filter_input(INPUT_GET, "p") ?? "home"; + $tmonth = filter_input(INPUT_GET, "m"); + + if ($result = filter_var($tmonth, FILTER_VALIDATE_INT)) + { + $month = $result; + } if ($user->hasLogout()) { @@ -109,7 +116,7 @@ class BootLoader } $result = $this->cards->hasCard($loginUser["id"], $isAdmin); - $works = $this->cards->SelectTimes($loginUser["id"]); + $works = $this->cards->SelectTimes($loginUser["id"], $month); $lastCard = $this->cards->getLastInsert($loginUser["id"]); $users = $this->cards->getUsers(); @@ -118,6 +125,7 @@ class BootLoader "users" => $users, "user" => $loginUser, "works" => $works, + "queryTime" => $this->cards->queryTime, "canonical" => $this->config["canonical"], "config" => $this->config, "addCard" => $result, diff --git a/provide/classes/Timecard.php b/provide/classes/Timecard.php index ebe30c9..3291285 100644 --- a/provide/classes/Timecard.php +++ b/provide/classes/Timecard.php @@ -12,6 +12,7 @@ class Timecard } protected $pdo; + public $queryTime = []; public function InitTables() { @@ -94,14 +95,34 @@ class Timecard return true; } - public function SelectTimes($uid) + public function SelectTimes($uid, $month = 0) { try { + $mm = strtotime(sprintf("%dmonth", $month)); $today = ((int) date("d")) - 1; $dayCount = (int) date("t"); - $startTime = date("Y-m-d 00:00:00", strtotime(sprintf("-%ddays", $today))); - $endTime = date("Y-m-d 00:00:00", strtotime(sprintf("+%ddays", $dayCount - $today))); + if ( $month == 0 ) + { + $startTime = date("Y-m-d 00:00:00", strtotime(sprintf("-%ddays", $today))); + $endTime = date("Y-m-d 00:00:00", strtotime(sprintf("+%ddays", $dayCount - $today))); + } else { + $y = date("Y", $mm); + $m = date("m", $mm); + $ly = $y; + $lm = $m + 1; + if ($lm > 12) + { + $ly += 1; + $lm = 1; + } + + $startTime = date("Y-m-d 00:00:00", strtotime(sprintf("%d-%d-01", $y, $m))); + $endTime = date("Y-m-d 00:00:00", strtotime(sprintf("%d-%d-01", $ly, $lm))); + } + + + $this->queryTime = [$startTime, $endTime]; $smt = $this->pdo->prepare("SELECT * FROM cards WHERE startTime > ? AND endTime < ? AND uid=?;"); $smt->execute([ diff --git a/template/view.php b/template/view.php index effb7ca..6e7ad2d 100644 --- a/template/view.php +++ b/template/view.php @@ -118,12 +118,37 @@
+ +
+
+ +
+
+

タイムカードは登録されていません。

+ + + + + + + + + +
開始日終了日
+
+
始業