Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'users/init.php';
- require_once $abs_us_root.$us_url_root.'users/includes/header.php';
- require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
- if (!securePage($_SERVER['PHP_SELF'])){die();}
- $userId = Input::get('id');
- $userdetails = fetchUserDetails(NULL, NULL, $userId); //Fetch user details
- //Go to Break
- if(!empty($_POST['break_out'])){
- $date = date('Y-m-d H:i:s');
- $outfields = array(
- 'user_id' => $user->data()->id,
- 'username' => $user->data()->username,
- 'timestamp' => $date
- );
- $db->insert('break_out',$outfields);
- $db->query("UPDATE users SET on_break = 1 WHERE id = ?",array($user->data()->id));
- $db->query("UPDATE users SET on_lunch = 0 WHERE id = ?",array($user->data()->id));
- Redirect::to('index.php?err=You+are+now+on+break');
- }
- //Return from Break
- if(!empty($_POST['break_in'])){
- $date = date('Y-m-d H:i:s');
- $infields = array(
- 'user_id' => $user->data()->id,
- 'username' => $user->data()->username,
- 'timestamp' => $date
- );
- $db->insert('break_in',$infields);
- $db->query("UPDATE users SET on_break = 0 WHERE id = ?",array($user->data()->id));
- Redirect::to('index.php?err=You+are+back+from+break');
- }
- //Go to Lunch
- if(!empty($_POST['lunch_out'])){
- $date = date('Y-m-d H:i:s');
- $lunchfields = array(
- 'user_id' => $user->data()->id,
- 'username' => $user->data()->username,
- 'timestamp' => $date
- );
- $db->insert('break_in',$lunchfields);
- $db->query("UPDATE users SET on_break = 0 WHERE id = ?",array($user->data()->id));
- $db->query("UPDATE users SET on_lunch = 1 WHERE id = ?",array($user->data()->id));
- Redirect::to('index.php?err=You+are+on+lunch');
- }
- //Return from Lunch
- if(!empty($_POST['lunch_in'])){
- $date = date('Y-m-d H:i:s');
- $lunchfields2 = array(
- 'user_id' => $user->data()->id,
- 'username' => $user->data()->username,
- 'timestamp' => $date
- );
- $db->insert('break_out',$lunchfields2);
- $db->query("UPDATE users SET on_lunch = 0 WHERE id = ?",array($user->data()->id));
- Redirect::to('index.php?err=You+are+on+lunch');
- }
- $date = date('m/d/Y H:i:s');
- ?>
- <!--The Forms-->
- <!--10 second auto-refresh for the stats showing who is on break/on lunch-->
- <head>
- <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- setInterval(function(){
- $('#stats').load(location.href+ ' #stats');
- }, 10000)
- });
- </script>
- </head>
- <div id="page-wrapper">
- <div class="container">
- <br><br><br><br>
- <!--Go to Break-->
- <div class="row text-center">
- <p>This page will automatically refresh every 10 seconds...</p>
- </div>
- <div class="row">
- <div class="col-xs-6 col-md-3">
- <form class="text-center" action="index.php" method="post">
- <input class='btn btn-primary' type='submit' name='break_out' value='Go to Break!' />
- </form>
- </div>
- <!--Return from Break-->
- <div class="col-xs-6 col-md-3">
- <form class="text-center" action="index.php" method="post">
- <input class='btn btn-primary' type='submit' name='break_in' value='Return from Break!' />
- </form>
- </div>
- <!--Go to Lunch-->
- <div class="col-xs-6 col-md-3">
- <form class="text-center" action="index.php" method="post">
- <input class='btn btn-primary' type='submit' name='lunch_out' value='Go to Lunch!' />
- </form>
- </div>
- <!--Return from Lunch-->
- <div class="col-xs-6 col-md-3">
- <form class="text-center" action="index.php" method="post">
- <input class='btn btn-primary' type='submit' name='lunch_in' value='Return from Lunch!' />
- </form>
- </div>
- <div id="stats">
- <div class="row">
- <div class="col-xs-12 col-md-6">
- <?php
- //Stats and shit
- $breaksQ = $db->query("SELECT * FROM users WHERE on_break = 1");
- $breaks = $breaksQ->results();
- $countbreaks = $breaksQ->count();
- if ($countbreaks == 1) {
- ?>
- <h3>There is <?=$countbreaks?> person on break right now.</h3>
- <? foreach ($breaks as $b){
- echo $b->fname;
- echo "<br>";
- }
- }
- elseif ($countbreaks > 1) {
- ?>
- <h3>There are <?=$countbreaks?> people on break right now.</h3>
- <? foreach ($breaks as $b) {
- echo $b->fname;
- echo "<br>";
- }
- }
- else {
- echo "<h3>There is no one on break right now.</h3>";
- }
- ?>
- </div>
- <div class="col-xs-12 col-md-6">
- <?
- $lunchQ = $db->query("SELECT * FROM users WHERE on_lunch = 1");
- $lunch = $lunchQ->results();
- $countlunch = $lunchQ->count();
- if ($countlunch == 1) {
- ?>
- <h3>There is <?=$countlunch?> person on lunch right now.</h3>
- <? foreach ($lunch as $l){
- echo $l->fname;
- echo "<br>";
- }
- }
- elseif ($countlunch > 1) {
- ?>
- <h3>There are <?=$countlunch?> people on lunch right now.</h3>
- <? foreach ($lunch as $l) {
- echo $l->fname;
- echo "<br>";
- }
- }
- else {
- echo "<h3>There is no one on lunch right now.</h3>";
- }
- ?>
- </div>
- </div>
- <?
- echo "<br><br><a href='users/reports.php'>Generate Reports</a>";
- /*
- //Example for showing stats
- $query = $db->query("SELECT * FROM break_out WHERE user_id = ?",array($user->data()->id));
- $results = $query->results();
- $count = $query->count();
- if ($count > 0 ){
- ?>
- <h3>You have previously went to break <?=$count?> times.</h3>
- <h3>Here are your previous break starting times...</h3>
- <?php foreach ($results as $r){
- echo $r->timestamp;
- echo "<br>";
- }
- }
- */
- ?>
- </div>
- </div><!-- /stats -->
- </div><!-- /.row -->
- </div> <!-- /container -->
- </div> <!-- /#page-wrapper -->
- <!-- footers -->
- <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
- <!-- Place any per-page javascript here -->
- <?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement