updated schema with foreign keys, updated sample config to include new params
This commit is contained in:
parent
dc77dc7e65
commit
d74c62649e
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
//********** PLEASE EDIT THE FOLLOWING **********//
|
||||
// Paths and directories must include a trailing slash!!!
|
||||
$yaptc_dirpath = '/usr/share/nginx/html/yaptc/'; // Absolute directory path to the root of this program
|
||||
$yaptc_webpath = 'http://server-ip/yaptc/'; // Absolute URL to the root of this program
|
||||
$yaptc_appname = 'Timecard System'; // Program name to display in title bar
|
||||
$yaptc_company = 'Widgets, Inc.'; // Your company name
|
||||
$sql = new PDO('mysql:host=localhost;dbname=your_database;', 'your_user', 'your_password'); // Database connection string
|
||||
$adminmessage = ''; // Message will display on all pages!
|
||||
$yaptc_dirpath = '/usr/share/nginx/html/yaptc/'; // Absolute directory path to the root of this program
|
||||
$yaptc_webpath = 'http://server-ip/yaptc/'; // Absolute URL to the root of this program
|
||||
$yaptc_appname = 'Timecard System'; // Program name to display in title bar
|
||||
$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!
|
||||
|
||||
|
||||
//********** NO NEED TO EDIT PAST HERE **********//
|
||||
@ -17,6 +17,32 @@ $yaptc_incweb = $yaptc_webpath . 'includes/';
|
||||
$yaptc_lib = $yaptc_dirpath . 'lib/';
|
||||
$yaptc_libweb = $yaptc_webpath . 'lib/';
|
||||
|
||||
// db settings
|
||||
$yaptc_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$yaptc_db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
|
||||
// Get user list for users management page
|
||||
function listUsers($yaptc_db) {
|
||||
$stmt = $yaptc_db->query("SELECT users.id as userid, users.username as username, users.email as email, users.created as created, users.firstname as firstname, users.lastname as lastname, users.usertype as usertypeid, usertypes.typename as usertype
|
||||
FROM yaptc.users
|
||||
INNER JOIN usertypes ON users.usertype = usertypes.id
|
||||
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
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
// Get login status - returns true or false
|
||||
function getSessionStatus()
|
||||
{
|
||||
@ -37,11 +63,11 @@ function killSession()
|
||||
}
|
||||
|
||||
// Get user access level. Call with $sql passed or it will not work correctly
|
||||
function getSessionAccess($sql)
|
||||
function getSessionAccess($yaptc_db)
|
||||
{
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
$query3 = "SELECT users.id as userid, usertypes.typename AS usertype FROM users, usertypes WHERE users.id = :id";
|
||||
$stmt3 = $sql->prepare($query3);
|
||||
$stmt3 = $yaptc_db->prepare($query3);
|
||||
$stmt3->execute(array(
|
||||
':id' => $_SESSION['user_id']
|
||||
));
|
||||
@ -50,4 +76,16 @@ function getSessionAccess($sql)
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user