Advertisement
Guest User

teststuff

a guest
Nov 23rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.24 KB | None | 0 0
  1. <?php
  2. require_once 'users/init.php';
  3. require_once $abs_us_root.$us_url_root.'users/includes/header.php';
  4. require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';
  5. if (!securePage($_SERVER['PHP_SELF'])){die();}
  6. $userId = Input::get('id');
  7. $userdetails = fetchUserDetails(NULL, NULL, $userId); //Fetch user details
  8.  
  9. //Go to Break
  10.     if(!empty($_POST['break_out'])){
  11.         $date = date('Y-m-d H:i:s');
  12.         $outfields = array(
  13.             'user_id' => $user->data()->id,
  14.             'username' => $user->data()->username,
  15.             'timestamp' => $date
  16.             );
  17.         $db->insert('break_out',$outfields);
  18.         $db->query("UPDATE users SET on_break = 1 WHERE id = ?",array($user->data()->id));
  19.         $db->query("UPDATE users SET on_lunch = 0 WHERE id = ?",array($user->data()->id));
  20.         Redirect::to('index.php?err=You+are+now+on+break');
  21.     }
  22.  
  23. //Return from Break
  24.  
  25.         if(!empty($_POST['break_in'])){
  26.                 $date = date('Y-m-d H:i:s');
  27.                 $infields = array(
  28.                         'user_id' => $user->data()->id,
  29.                         'username' => $user->data()->username,
  30.                         'timestamp' => $date
  31.                         );
  32.                 $db->insert('break_in',$infields);
  33.         $db->query("UPDATE users SET on_break = 0 WHERE id = ?",array($user->data()->id));
  34.                 Redirect::to('index.php?err=You+are+back+from+break');
  35.         }
  36.  
  37. //Go to Lunch
  38.  
  39.    if(!empty($_POST['lunch_out'])){
  40.                 $date = date('Y-m-d H:i:s');
  41.                 $lunchfields = array(
  42.                         'user_id' => $user->data()->id,
  43.                         'username' => $user->data()->username,
  44.                         'timestamp' => $date
  45.                         );
  46.                 $db->insert('break_in',$lunchfields);
  47.                 $db->query("UPDATE users SET on_break = 0 WHERE id = ?",array($user->data()->id));
  48.         $db->query("UPDATE users SET on_lunch = 1 WHERE id = ?",array($user->data()->id));
  49.                 Redirect::to('index.php?err=You+are+on+lunch');
  50.     }
  51.  
  52. //Return from Lunch
  53.  
  54.    if(!empty($_POST['lunch_in'])){
  55.                 $date = date('Y-m-d H:i:s');
  56.                 $lunchfields2 = array(
  57.                         'user_id' => $user->data()->id,
  58.                         'username' => $user->data()->username,
  59.                         'timestamp' => $date
  60.                         );
  61.                 $db->insert('break_out',$lunchfields2);
  62.                 $db->query("UPDATE users SET on_lunch = 0 WHERE id = ?",array($user->data()->id));
  63.                 Redirect::to('index.php?err=You+are+on+lunch');
  64.         }
  65.  
  66. $date = date('m/d/Y H:i:s');
  67.  
  68. ?>
  69.  
  70. <!--The Forms-->
  71.  
  72. <!--10 second auto-refresh for the stats showing who is on break/on lunch-->
  73. <head>
  74. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
  75. <script type="text/javascript">
  76. $(document).ready(function () {
  77. setInterval(function(){
  78.     $('#stats').load(location.href+ ' #stats');
  79. }, 10000)
  80. });
  81. </script>
  82. </head>
  83.  
  84. <div id="page-wrapper">
  85. <div class="container">
  86. <br><br><br><br>
  87. <!--Go to Break-->
  88. <div class="row text-center">
  89. <p>This page will automatically refresh every 10 seconds...</p>
  90. </div>
  91. <div class="row">
  92. <div class="col-xs-6 col-md-3">
  93. <form class="text-center" action="index.php" method="post">
  94.   <input class='btn btn-primary' type='submit' name='break_out' value='Go to Break!' />
  95. </form>
  96. </div>
  97.  
  98. <!--Return from Break-->
  99. <div class="col-xs-6 col-md-3">
  100. <form class="text-center" action="index.php" method="post">
  101.   <input class='btn btn-primary' type='submit' name='break_in' value='Return from Break!' />
  102. </form>
  103. </div>
  104.  
  105. <!--Go to Lunch-->
  106. <div class="col-xs-6 col-md-3">
  107. <form class="text-center" action="index.php" method="post">
  108.   <input class='btn btn-primary' type='submit' name='lunch_out' value='Go to Lunch!' />
  109. </form>
  110. </div>
  111.  
  112. <!--Return from Lunch-->
  113. <div class="col-xs-6 col-md-3">
  114. <form class="text-center" action="index.php" method="post">
  115.   <input class='btn btn-primary' type='submit' name='lunch_in' value='Return from Lunch!' />
  116. </form>
  117. </div>
  118. <div id="stats">
  119. <div class="row">
  120. <div class="col-xs-12 col-md-6">
  121. <?php
  122.  
  123. //Stats and shit
  124.  
  125. $breaksQ = $db->query("SELECT * FROM users WHERE on_break = 1");
  126. $breaks = $breaksQ->results();
  127. $countbreaks = $breaksQ->count();
  128.     if ($countbreaks == 1) {
  129.     ?>
  130.         <h3>There is <?=$countbreaks?> person on break right now.</h3>
  131.         <? foreach ($breaks as $b){
  132.             echo $b->fname;
  133.             echo "<br>";
  134.         }  
  135.     }
  136.     elseif ($countbreaks > 1) {
  137.     ?>
  138.         <h3>There are <?=$countbreaks?> people on break right now.</h3>
  139.         <? foreach ($breaks as $b) {
  140.             echo $b->fname;
  141.             echo "<br>";
  142.         }
  143.     }
  144.     else {
  145.         echo "<h3>There is no one on break right now.</h3>";
  146.     }
  147. ?>
  148. </div>
  149. <div class="col-xs-12 col-md-6">
  150. <?
  151. $lunchQ = $db->query("SELECT * FROM users WHERE on_lunch = 1");
  152. $lunch = $lunchQ->results();
  153. $countlunch = $lunchQ->count();
  154.     if ($countlunch == 1) {
  155.     ?>
  156.         <h3>There is <?=$countlunch?> person on lunch right now.</h3>
  157.         <? foreach ($lunch as $l){
  158.                 echo $l->fname;
  159.                 echo "<br>";
  160.             }
  161.     }
  162.     elseif ($countlunch > 1) {
  163.     ?>
  164.         <h3>There are <?=$countlunch?> people on lunch right now.</h3>
  165.         <? foreach ($lunch as $l) {
  166.                 echo $l->fname;
  167.                 echo "<br>";
  168.             }
  169.     }
  170.     else {
  171.             echo "<h3>There is no one on lunch right now.</h3>";
  172.     }
  173. ?>
  174. </div>
  175. </div>
  176. <?
  177. echo "<br><br><a href='users/reports.php'>Generate Reports</a>";
  178.  
  179. /*
  180. //Example for showing stats
  181.  
  182. $query = $db->query("SELECT * FROM break_out WHERE user_id = ?",array($user->data()->id));
  183. $results = $query->results();
  184. $count = $query->count();
  185. if ($count > 0 ){
  186. ?>
  187. <h3>You have previously went to break <?=$count?> times.</h3>
  188. <h3>Here are your previous break starting times...</h3>
  189. <?php foreach ($results as $r){
  190.     echo $r->timestamp;
  191.     echo "<br>";
  192. }
  193. }
  194. */
  195.  
  196. ?>
  197. </div>
  198. </div><!-- /stats -->
  199. </div><!-- /.row -->
  200.  
  201. </div> <!-- /container -->
  202.  
  203. </div> <!-- /#page-wrapper -->
  204.  
  205. <!-- footers -->
  206. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  207.  
  208. <!-- Place any per-page javascript here -->
  209.  
  210.  
  211. <?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