diff --git a/lib/reports.php b/lib/reports.php index 4dde41d..50dc7b6 100644 --- a/lib/reports.php +++ b/lib/reports.php @@ -295,19 +295,69 @@ function getJobsReport($showdeleted = true) { return $out; } +function getJobHistoryReport($user = null, $start = null, $end = null) { + global $database; + global $allowed_users; + $where = []; + if ((bool) strtotime($start) == TRUE) { + $where["OR #start"] = [ + "start[>=]" => date("Y-m-d", strtotime($start)), + "end[>=]" => date("Y-m-d", strtotime($start)) + ]; + } + if ((bool) strtotime($end) == TRUE) { + // Make the date be the end of the day, not the start + $where["start[<=]"] = date("Y-m-d", strtotime($end)) . " 23:59:59"; + } + if ($user != null && array_key_exists('uid', $user) && ($allowed_users === true || in_array($user['uid'], $allowed_users))) { + $where["uid"] = $user['uid']; + } else if ($user != null && array_key_exists('uid', $user) && $allowed_users !== true && !in_array($user['uid'], $allowed_users)) { + $where["uid"] = -1; + } else { + if ($allowed_users !== true) { + $where["uid"] = $allowed_users; + } + } + if (count($where) > 1) { + $where = ["AND" => $where]; + } + $jobs = $database->select( + "job_tracking", [ + "[>]jobs" => ["jobid" => "jobid"] + ], [ + "jobs.jobid", "uid", "start", "end", "jobname", "jobcode" + ], $where + ); + $header = [lang("name", false), lang("job", false), lang("code", false), lang("start", false), lang("end", false)]; + $out = [$header]; + $usercache = []; + for ($i = 0; $i < count($jobs); $i++) { + if (!array_key_exists($jobs[$i]["uid"], $usercache)) { + $usercache[$jobs[$i]["uid"]] = getUserByID($jobs[$i]["uid"]); + } + $out[] = [ + $usercache[$jobs[$i]["uid"]]["name"] . " (" . $usercache[$jobs[$i]["uid"]]["username"] . ")", + $jobs[$i]['jobname'], + $jobs[$i]['jobcode'], + date(DATETIME_FORMAT, strtotime($jobs[$i]['start'])), + (is_null($jobs[$i]['end']) ? "" : date(DATETIME_FORMAT, strtotime($jobs[$i]['end']))), + ]; + } + return $out; +} + function getReportData($type, $user = null, $start = null, $end = null, $deleted = true) { switch ($type) { case "shifts": return getShiftReport($user); - break; case "punches": return getPunchReport($user, $start, $end); - break; case "totals": return getTotalsReport($user, $start, $end); - break; case "alljobs": return getJobsReport($deleted); + case "jobs": + return getJobHistoryReport($user, $start, $end); default: return [["error"]]; } diff --git a/pages/export.php b/pages/export.php index 08feb4a..9d33a07 100644 --- a/pages/export.php +++ b/pages/export.php @@ -27,6 +27,7 @@ if (!account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE") && !accou + diff --git a/pages/jobs.php b/pages/jobs.php index 27cd9a5..84c7592 100644 --- a/pages/jobs.php +++ b/pages/jobs.php @@ -58,7 +58,7 @@ redirectifnotloggedin(); - + @@ -71,7 +71,7 @@ redirectifnotloggedin(); - +