diff --git a/action.php b/action.php index 4512c08..39219a3 100644 --- a/action.php +++ b/action.php @@ -24,7 +24,19 @@ function returnToSender($msg, $arg = "") { } switch ($VARS['action']) { - case "time": + case "punchin": + if ($database->has('punches', ['AND' => ['uid' => $_SESSION['uid'], 'out' => null]])) { + returnToSender("already_in"); + } + $database->insert('punches', ['uid' => $_SESSION['uid'], 'in' => date("Y-m-d H:i:s"), 'out' => null, 'notes' => '']); + returnToSender("punched_in"); + case "punchout": + if (!$database->has('punches', ['AND' => ['uid' => $_SESSION['uid'], 'out' => null]])) { + returnToSender("already_out"); + } + $database->update('punches', ['uid' => $_SESSION['uid'], 'out' => date("Y-m-d H:i:s")], ['out' => null]); + returnToSender("punched_out"); + case "gettime": $out = ["status" => "OK", "time" => date(TIME_FORMAT), "date" => date(LONG_DATE_FORMAT), "seconds" => date("s")]; header('Content-Type: application/json'); exit(json_encode($out)); diff --git a/lang/en_us.php b/lang/en_us.php index 5cebf56..4487f12 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -27,5 +27,9 @@ define("STRINGS", [ "home" => "Home", "punch in out" => "Punch In/Out", "you are punched in" => "You are punched in.", - "you are not punched in" => "You are not on the clock." + "you are not punched in" => "You are not on the clock.", + "already punched in" => "You are already on the clock.", + "already punched out" => "You are already punched out.", + "punched in" => "You are now on the clock.", + "punched out" => "You are now off the clock." ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 8ac0b7a..086124f 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -12,5 +12,21 @@ define("MESSAGES", [ "404_error" => [ "string" => "page not found", "type" => "info" + ], + "already_in" => [ + "string" => "already punched in", + "type" => "danger" + ], + "already_out" => [ + "string" => "already punched out", + "type" => "danger" + ], + "punched_in" => [ + "string" => "punched in", + "type" => "success" + ], + "punched_out" => [ + "string" => "punched out", + "type" => "success" ] ]); diff --git a/pages/home.php b/pages/home.php index ff832c1..b4986ad 100644 --- a/pages/home.php +++ b/pages/home.php @@ -21,9 +21,9 @@
- +
- +