From 65204a6c591c9ad4bcbb5e3b468db6ce3e410328 Mon Sep 17 00:00:00 2001 From: Josh North Date: Tue, 24 Feb 2015 10:37:52 -0500 Subject: [PATCH] Major overhauls, added admin punch as well --- config.inc.php.example | 2 +- includes/functions.inc.php | 184 +++++++++++++---- includes/menu.inc.php | 63 +++--- includes/side-menu.css | 23 ++- index.php | 17 +- lib/pure/HISTORY.md | 413 ------------------------------------- lib/pure/README.md | 170 --------------- manualpunch.php | 95 +++++++++ profile.php | 65 +++--- punchlog.php | 46 ++--- reports.php | 23 ++- users.php | 19 +- 12 files changed, 356 insertions(+), 764 deletions(-) delete mode 100755 lib/pure/HISTORY.md delete mode 100755 lib/pure/README.md create mode 100755 manualpunch.php diff --git a/config.inc.php.example b/config.inc.php.example index ecd3c63..038d0f6 100755 --- a/config.inc.php.example +++ b/config.inc.php.example @@ -8,7 +8,7 @@ $yaptc_company = 'Widgets, Inc.'; // Your company name $yaptc_db = new PDO('mysql:host=localhost;dbname=YOUR_DATABASE;charset=utf8', 'YOUR_USER', 'YOUR_PASSWORD'); // Database connection string $yaptc_adminmsg = ''; // Message will display on all pages! $yaptc_allowadvancedpunch = 'yes'; // Should we allow users to make manual punch entries? set to yes or no - +$yaptc_min_password = '8'; // Minimum password length diff --git a/includes/functions.inc.php b/includes/functions.inc.php index 1b41ba3..7b6f2b1 100755 --- a/includes/functions.inc.php +++ b/includes/functions.inc.php @@ -9,27 +9,7 @@ ORDER BY users.lastname ASC;"); return $stmt->fetchAll(PDO::FETCH_ASSOC); } -// Update user profile -function updateUserProfile($yaptc_db, $userid, $firstname, $lastname, $email) -{ -$stmt = $yaptc_db->prepare("UPDATE users SET firstname = :firstname, lastname = :lastname, email = :email WHERE id = :userid;"); -$stmt->execute(array( - ':userid' => $userid, - ':firstname' => $firstname, - ':lastname' => $lastname, - ':email' => $email, - )); -} -// Update user profile -function updateUserPassword($yaptc_db, $userid, $password) -{ -$stmt = $yaptc_db->prepare("UPDATE users SET password = :password WHERE id = :userid;"); -$stmt->execute(array( - ':userid' => $userid, - ':password' => $password, - )); -} // Get login status - returns true or false @@ -51,37 +31,29 @@ function killSession() header("Location: login.php"); } -// Get user access level. Call with $sql passed or it will not work correctly -function getSessionAccess($yaptc_db) -{ - if (isset($_SESSION['user_id'])) { - $query3 = "SELECT users.id as userid, usertypes.typename AS usertype FROM yaptc.users INNER JOIN yaptc.usertypes ON users.usertype = usertypes.id WHERE users.id = :id"; - $stmt3 = $yaptc_db->prepare($query3); - $stmt3->execute(array( - ':id' => $_SESSION['user_id'] - )); - $user3 = $stmt3->fetchObject(); - return $user3->usertype; - } -} + // Punch Out -function punchOut($yaptc_db, $punchid, $notes) +function punchOut($yaptc_db, $punchid, $notes, $outtime, $modified=NULL) { -$stmt = $yaptc_db->prepare("UPDATE punches SET punches.outtime = NOW(), punches.notes = :notes WHERE punches.id = :punchid;"); +$stmt = $yaptc_db->prepare("UPDATE punches SET punches.outtime = :outtime, punches.notes = :notes, punches.modified = :modified WHERE punches.id = :punchid;"); $stmt->execute(array( ':punchid' => $punchid, + ':modified' => $modified, + ':outtime' => $outtime, ':notes' => $notes )); } // Punch In -function punchIn($yaptc_db, $userid, $notes) +function punchIn($yaptc_db, $userid, $notes, $punchtime, $modified=NULL) { -$stmt = $yaptc_db->prepare("INSERT INTO punches (punches.userid, punches.notes, punches.intime) VALUES (:userid, :notes, NOW());"); +$stmt = $yaptc_db->prepare("INSERT INTO punches (punches.userid, punches.notes, punches.intime, punches.modified) VALUES (:userid, :notes, :punchtime, :modified);"); $stmt->execute(array( ':userid' => $userid, - ':notes' => $notes + ':notes' => $notes, + ':punchtime' => $punchtime, + ':modified' => $modified )); } @@ -96,16 +68,140 @@ function getPunchStatus($yaptc_db, $userid) return array ($result['punchid'], $result['userid'], $result['intime'], $result['outtime'], $result['notes']); } + + +// List punches sorted by intime. Pass uid or % for all. Pass limit to restrict row results. Default is set to tons of 9's because no wildcard exists for limit in mysql or pgsql +function listPunches($db, $uid, $limit = "999999999999999") { + $stmt = $db->prepare(' + SELECT + ROUND(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600,2) AS punchhours, + punches.id as punchid, + punches.intime as intime, + punches.outtime as outtime, + users.id AS userid, + users.firstname as firstname, + users.lastname as lastname, + REPLACE (punches.modified, "1", "YES") as modified, + punches.notes as notes + FROM yaptc.punches + INNER JOIN yaptc.users ON punches.userid = users.id + WHERE users.id LIKE :uid + ORDER BY punches.intime DESC + LIMIT :limit + '); + $stmt->execute(array( + ':uid' => $uid, + ':limit' => $limit, + )); + return $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +// Get user info from user id. Pass uid or % for all. +function getUserInfo($db, $uid) { + $stmt = $db->prepare(' + SELECT + users.id AS userid, + users.username AS username, + users.firstname AS firstname, + users.lastname AS lastname, + users.email AS email, + usertypes.typename AS usertype, + usertypes.id AS usertypeid, + users.created AS created, + users.password AS password + FROM yaptc.users + INNER JOIN yaptc.usertypes ON users.usertype = usertypes.id + WHERE users.id LIKE :uid + ORDER BY users.lastname ASC; + '); + $stmt->execute(array( + ':uid' => $uid + )); + return $stmt->fetchAll(PDO::FETCH_ASSOC); +} + + +// Update user profile +function updateUserPassword($yaptc_db, $userid, $password) +{ +$stmt = $yaptc_db->prepare("UPDATE users SET password = :password WHERE id = :userid;"); +$stmt->execute(array( + ':userid' => $userid, + ':password' => $password, + )); +} + + + +// Set user info from user id +function setUserInfo($db, $uid, $firstname, $lastname, $email, $usertypeid, $password) { + $stmt = $db->prepare(' + UPDATE + yaptc.users + SET + firstname = :firstname, + lastname = :lastname, + email = :email, + usertype = :usertypeid, + password = :password + WHERE id = :uid + '); + $stmt->execute(array( + ':uid' => $uid, + ':firstname' => $firstname, + ':lastname' => $lastname, + ':email' => $email, + ':usertypeid' => $usertypeid, + ':password' => $password, + )); + +} + // Report - Weekly Hours by Week then User -function reportWeeklyByUser($yaptc_db) { - $stmt = $yaptc_db->query("SELECT YEAR(punches.intime) AS g_year, WEEK(punches.intime) AS g_week, ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours, punches.id as punchid, users.id as user, users.username as username, users.firstname as firstname, users.lastname as lastname, punches.intime as intime, punches.outtime as outtime, punches.notes as notes, punches.modified as modified FROM punches INNER JOIN users ON punches.userid = users.id GROUP BY g_year, g_week, users.username;"); - return $stmt->fetchAll(PDO::FETCH_ASSOC); +function reportWeeklyByUser($yaptc_db) +{ + $statement = $yaptc_db->prepare(' + SELECT + YEAR(punches.intime) AS g_year, + WEEK(punches.intime) AS g_week, + ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours, + punches.intime as intime, + punches.outtime as outtime, + users.firstname as firstname, + users.lastname as lastname, + REPLACE (punches.modified, "1", "YES") as modified, + punches.notes as notes + FROM yaptc.punches + INNER JOIN yaptc.users ON punches.userid = users.id + GROUP BY g_year, g_week, users.username + '); + $statement->execute(); + return $statement->fetchAll(PDO::FETCH_ASSOC); } // Report - Monthly Hours by Month then User -function reportMonthlyByUser($yaptc_db) { - $stmt = $yaptc_db->query("SELECT YEAR(punches.intime) AS g_year, MONTHNAME(punches.intime) AS g_month, ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours, punches.id as punchid, users.id as user, users.username as username, users.firstname as firstname, users.lastname as lastname, punches.intime as intime, punches.outtime as outtime, punches.notes as notes, punches.modified as modified FROM punches INNER JOIN users ON punches.userid = users.id GROUP BY g_year, g_month, users.username;"); - return $stmt->fetchAll(PDO::FETCH_ASSOC); +function reportMonthlyByUser($yaptc_db) +{ + $statement = $yaptc_db->prepare(' + SELECT + YEAR(punches.intime) AS g_year, + MONTHNAME(punches.intime) AS g_month, + ROUND(SUM(TIME_TO_SEC(TIMEDIFF(punches.outtime, punches.intime))/3600),2) AS punchhours, + punches.intime as intime, + punches.outtime as outtime, + users.firstname as firstname, + users.lastname as lastname, + REPLACE (punches.modified, "1", "YES") as modified, + punches.notes as notes + FROM yaptc.punches + INNER JOIN yaptc.users ON punches.userid = users.id + GROUP BY g_year, g_month, users.username; + '); + $statement->execute(); + return $statement->fetchAll(PDO::FETCH_ASSOC); } + + +// EOF ?> diff --git a/includes/menu.inc.php b/includes/menu.inc.php index 0090857..83e8dd0 100755 --- a/includes/menu.inc.php +++ b/includes/menu.inc.php @@ -12,38 +12,39 @@ ';} else {echo '>';} echo 'Home'; - } -// Profile -if ($userLogged == true) { - echo '';} else {echo '>';} echo 'Profile'; - } -// Punch Log -if ($userLogged == true) { - echo '';} else {echo '>';} echo 'Punch Log'; - } -// Users -if ($userLogged == true && $userAccess == "Administrator") { - echo '';} else {echo '>';} echo 'Users'; - } -// Reports -if ($userLogged == true && $userAccess == "Administrator") { - echo '';} else {echo '>';} echo 'Reports'; - } -// Logout -if ($userLogged == true) { - echo '';} else {echo '>';} echo 'Logout'; - } -// Login -if ($userLogged == false) { +// Menu Setup + +// For logged-out users +if ($session_status == false): echo '';} else {echo '>';} echo 'Login'; - } +// For logged-in users, depending on access +elseif ($session_status == true): +// Home +echo ''; else: echo '>'; endif; echo 'Home'; +// Profile Menu +echo ''; else: echo '>'; endif; echo 'Profile'; +// Punch Log Menu +echo ''; else: echo '>'; endif; echo 'Punch Log'; +// Users Menu +if ($session_user["0"]["usertype"] == "Administrator"): + echo ''; else: echo '>'; endif; echo 'Users'; +endif; +// Manual Punch +if ($session_user["0"]["usertype"] == "Administrator"): + echo ''; else: echo '>'; endif; echo 'Manual Punch'; +endif; +// Reports Menu +if ($session_user["0"]["usertype"] == "Administrator"): + echo ''; else: echo '>'; endif; echo 'Reports'; +endif; +// Logout Menu +echo ''; else: echo '>'; endif; echo 'Logout'; + +endif; ?> @@ -54,7 +55,7 @@ if ($userLogged == false) {

-

+

" . $adminmessage . "

"; endif; ?> diff --git a/includes/side-menu.css b/includes/side-menu.css index e017617..dbe4a1f 100755 --- a/includes/side-menu.css +++ b/includes/side-menu.css @@ -31,32 +31,33 @@ body { } /*The content `
` is where all your content goes.*/ .content { - margin:0 auto; - padding:0 2em; + margin:0; + padding:0; max-width:800px; margin-bottom:50px; - line-height:1.6em; + line-height:1em; } .header { margin:0; color:#333; - text-align:center; - padding:2.5em 2em 0; - border-bottom:1px solid #eee; + padding:.0; + border-bottom:2px solid #eee; } .header h1 { - margin:0.2em 0; + margin:0; font-size:3em; font-weight:300; + padding:0; } .header h2 { + margin:0; + font-size:1em; font-weight:300; - color:#ccc; padding:0; - margin-top:0; + color:#888; } -.content-subhead { - margin:50px 0 20px 0; +.content-subhead { + margin:1em 0 0 0; font-weight:300; color: #888; } diff --git a/index.php b/index.php index 1e2262f..e95bc01 100755 --- a/index.php +++ b/index.php @@ -10,13 +10,15 @@ killSession(); else: ?> -

Current Status

- +

You do not appear to have any punches on record.

You have been Punched since .

@@ -37,6 +39,7 @@ else: ?> + + diff --git a/lib/pure/HISTORY.md b/lib/pure/HISTORY.md deleted file mode 100755 index 445de01..0000000 --- a/lib/pure/HISTORY.md +++ /dev/null @@ -1,413 +0,0 @@ -Pure Change History -=================== - -0.5.0 (2014-05-27) ------------------- - -### Base - -* Added the `.pure-img` class name for make images scale with the viewport in - fluid layouts. - -### Grids - -* __[!]__ Removed `.pure-g-r` from core, in favor of a mobile-first responsive - grid system. ([#24][], [#267][]) - - To use the mobile-first grid system, you need to pull in `pure.css`, along - with `grids-responsive.css`. We also have `grids-responsive-old-ie.css` that - you can serve to IE < 9 users so that they can view a desktop-version of your - website: - - ```html - - - - - - - ``` - - Find out more about the new grid system at . - -### Tables - -* Switched cell padding in Tables from `px` to `em` units, and also increased - the amount of padding to `padding: 0.5em 1em`. - - -[#24]: https://github.com/yui/pure/issues/24 -[#267]: https://github.com/yui/pure/pull/267 - - -0.4.2 (2014-02-13) ------------------- - -* Added `main` to Pure's `bower.json` file to allow easier integration with - build processes and tooling. ([#286][] @stevenvachon) - -### Forms - -* Improved how `` elements look in Chrome by fixing - paddings. ([#283][] @jpetto) - -* Removed `font-size` rules from ``, ``, and `
` - elements within `.pure-form`. Font sizes are now inherited from the - application's CSS file. ([#265][]) - -* Invalid `` elements within a Pure Form no longer explicitly set a - `border-width`. ([#295][] @kwando) - - -[#265]: https://github.com/yui/pure/issues/265 -[#283]: https://github.com/yui/pure/issues/283 -[#286]: https://github.com/yui/pure/issues/286 -[#295]: https://github.com/yui/pure/issues/295 - - -0.4.1 (2014-02-06) ------------------- - -### Base - -* Elements that have Pure classnames which set a `display` declaration _and_ use - the `hidden` HTML attribute will now properly be hidden. With these changes, - the following button will be hidden from view: - - ```html - - ``` - - A new rule for the `[hidden]` selector has been added with the declaration: - `display: none !important;`. This is a time where it's appropriate for a - project like Pure to use `!important`. ([#177][]) - -### Buttons - -* Removed all the occurrences of `-ms-linear-gradient()` from Buttons since it - has never been in the final version of IE 10. ([#200][]: @AurelioDeRosa) - -* `` Buttons now have the same height as non-input buttons. - `font-family: inherit;` has been added to the `.pure-button` selector to - normalize the difference in height. ([#221][] @narcis-radu) - -* Buttons now have visually uniform default `padding` on all four sides. The - left/right padding is 2x the top/bottom padding. ([#191][] @achalv) - -### Forms - -* Added `vertical-align: top;` to `