2015-02-12 15:23:08 -05:00
< ? php
session_start ();
require_once ( " config.inc.php " );
$yaptc_pagename = " Reports " ;
require_once ( $yaptc_inc . " header.inc.php " );
require_once ( $yaptc_inc . " menu.inc.php " );
// Is user logged in? If not, they shouldn't be here - kill all variables and redirect to login...
if ( ! isset ( $_SESSION [ 'user_id' ]) || ! isset ( $_SESSION [ 'signature' ]) || ! isset ( $_SESSION [ 'loggedIn' ]) || $_SESSION [ 'loggedIn' ] != true || $_SESSION [ 'signature' ] != md5 ( $_SESSION [ 'user_id' ] . $_SERVER [ 'HTTP_USER_AGENT' ]))
{
session_start ();
session_unset ();
session_destroy ();
header ( " Refresh:3; url=login.php " , true , 303 );
echo " <h2 class= \" content-subhead \" >You are not logged in!!!</h2> " ;
}
else
{
//********** BEGIN CONTENT **********//
2015-02-18 05:13:53 -05:00
2015-02-12 15:23:08 -05:00
echo " <h2 class= \" content-subhead \" >Punch History</h2> " ;
2015-02-18 05:13:53 -05:00
echo " <p>Below is your company punch history. The below drop-down can be used to select pre-configured reports. Other reports are currently being written.</p> " ;
2015-02-12 15:23:08 -05:00
echo " <form class= \" pure-form pure-form-stacked \" action= \" reports.php \" method= \" post \" > " ;
echo " <fieldset> " ;
echo " <div class= \" pure-g \" > " ;
2015-02-18 05:13:53 -05:00
echo " <div class= \" pure-u-1 \" > " ;
echo " <label for= \" reporttype \" >Report Type</label> " ;
echo " <select name= \" reporttype \" class= \" pure-input-1-2 \" > " ;
if ( isset ( $_POST [ 'reporttype' ])) { echo " <option value= \" " . $_POST [ 'reporttype' ] . " \" > " . $_POST [ 'reporttype' ] . " </option><option>----------</option> " ;}
else { echo " <option></option> " ;}
echo " <option value= \" Hours per week per user \" >Hours per week per user</option> " ;
echo " <option value= \" Hours per month per user \" >Hours per month per user</option> " ;
2015-02-12 15:23:08 -05:00
echo " </select> " ;
echo " </div> " ;
echo " </div> " ;
echo " <button type= \" submit \" class= \" pure-button pure-button-primary \" >Submit</button> " ;
echo " </fieldset> " ;
echo " </form> " ;
2015-02-18 05:13:53 -05:00
if ( isset ( $_POST [ 'reporttype' ])) {
if ( $_POST [ 'reporttype' ] == " Hours per week per user " ) {
$query = " SELECT
YEAR ( punches . intime ) AS g_year ,
WEEK ( punches . intime ) AS g_week ,
SUM ( TIME_TO_SEC ( TIMEDIFF ( punches . outtime , punches . intime )) / 3600 ) 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 ; " ;
$stmt = $sql -> prepare ( $query );
$stmt -> execute ();
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
2015-02-12 15:23:08 -05:00
2015-02-18 05:13:53 -05:00
//set up table header and open table
echo '<table class="pure-table">' ;
echo '<thead>' ;
echo '<tr>' ;
echo '<th>Year</th>' ;
echo '<th>Week#</th>' ;
echo '<th>Username</th>' ;
echo '<th>Hours</th>' ;
echo '</tr>' ;
echo '</thead>' ;
echo '<tbody>' ;
2015-02-12 15:23:08 -05:00
2015-02-18 05:13:53 -05:00
// $rows is an array containing all records...
foreach ( $rows as $row ) {
echo " <tr> " ;
echo " <td> " . $row [ 'g_year' ] . " </td> " ;
echo " <td> " . $row [ 'g_week' ] . " </td> " ;
echo " <td> " . $row [ 'username' ] . " </td> " ;
echo " <td> " . $row [ 'punchhours' ] . " </td> " ;
echo " </tr> " ;
}
echo '</tbody>' ;
echo '</table>' ;
}
elseif ( $_POST [ 'reporttype' ] == " Hours per month per user " ) {
2015-02-12 15:23:08 -05:00
$query = " SELECT
2015-02-18 05:13:53 -05:00
YEAR ( punches . intime ) AS g_year ,
MONTH ( punches . intime ) AS g_month ,
SUM ( TIME_TO_SEC ( TIMEDIFF ( punches . outtime , punches . intime )) / 3600 ) AS punchhours ,
2015-02-12 15:23:08 -05:00
punches . id as punchid ,
users . id as user ,
2015-02-18 05:13:53 -05:00
users . username as username ,
2015-02-12 15:23:08 -05:00
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
2015-02-18 05:13:53 -05:00
INNER JOIN users ON punches . userid = users . id
GROUP BY g_year , g_month , users . username ; " ;
$stmt = $sql -> prepare ( $query );
2015-02-12 15:23:08 -05:00
$stmt -> execute ();
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
//set up table header and open table
echo '<table class="pure-table">' ;
echo '<thead>' ;
echo '<tr>' ;
2015-02-18 05:13:53 -05:00
echo '<th>Year</th>' ;
echo '<th>Month</th>' ;
echo '<th>Username</th>' ;
2015-02-12 15:23:08 -05:00
echo '<th>Hours</th>' ;
echo '</tr>' ;
echo '</thead>' ;
echo '<tbody>' ;
// $rows is an array containing all records...
2015-02-18 05:13:53 -05:00
foreach ( $rows as $row ) {
echo " <tr> " ;
echo " <td> " . $row [ 'g_year' ] . " </td> " ;
echo " <td> " . $row [ 'g_month' ] . " </td> " ;
echo " <td> " . $row [ 'username' ] . " </td> " ;
echo " <td> " . $row [ 'punchhours' ] . " </td> " ;
echo " </tr> " ;
}
2015-02-12 15:23:08 -05:00
echo '</tbody>' ;
echo '</table>' ;
2015-02-18 05:13:53 -05:00
}
else {
echo " no query " ;
}
} else { echo " no query " ; }
2015-02-12 15:23:08 -05:00
//********** END CONTENT **********//
}
require_once ( $yaptc_inc . " footer.inc.php " );
?>