/**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     Validator::extend('compare_time', function ($attribute, $value, $parameters, $validator) {
         $yourTime = array_get($validator->getData(), $parameters[0]);
         $winnersTime = $value;
         if (preg_match('/^([0-5][0-9]|[0-9])?:?([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])(\\.\\d{1,2})?$/', $yourTime)) {
             $yourTimeSec = time_to_sec($yourTime);
         } else {
             return false;
         }
         if (preg_match('/^([0-5][0-9]|[0-9])?:?([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])(\\.\\d{1,2})?$/', $winnersTime)) {
             $winnersTimeSec = time_to_sec($winnersTime);
         } else {
             return false;
         }
         return $yourTimeSec >= $winnersTimeSec;
     });
 }
Esempio n. 2
0
 public function home_user()
 {
     // We are gathering the data for the insert
     $location = $this->session->userdata('logged_in');
     $messages = '';
     if ($this->input->post('calcvalues') != NULL) {
         $clerk = $this->input->post('calcvalues');
         $action = $this->input->post('action');
         $date = date('Y-m-d');
         $time = date('H:i:s');
         $clerk_id = $this->load_file->get_data_extend_where('clerk', 'clerk_id, clerk_name', 'secret_no =' . $clerk);
         // Check if the clerk exists or not
         if ($clerk_id != NULL) {
             $temp = array('locations' => $location['name']);
             $location_id = $this->load_file->get_data_extend_where('locations', 'location_id', $temp);
             // we get the time margins for the clock in and out of this particular clerk
             $temp = $this->load_file->get_clerks($clerk_id[0]['clerk_id']);
             $time_in_margin = $temp[0]['in_time_margin'];
             $time_out_margin = $temp[0]['out_time_margin'];
             // We check if the database has any data for this clerk at this date
             $check = $this->load_file->get_data_extend_where('clerks_check', 'clerk_id, status, time', 'clerk_id =' . $clerk_id[0]['clerk_id'], $date);
             // we build the array
             $data_for = array('clerk_id' => $clerk_id[0]['clerk_id'], 'location_id' => $location_id[0]['location_id'], 'sign_time' => $time, 'status' => $action, 'date' => $date, 'time' => $time);
             // set defaults for the check in case that they don't exist
             if (!isset($check[0])) {
                 $check[0] = array('clerk_id' => -1, 'status' => 'not set');
             }
             if (!isset($check[1])) {
                 $check[1] = array('clerk_id' => -1, 'status' => 'not set');
             }
             if ($data_for['status'] == 'out' && ($check[0]['status'] == 'out' || $check[0]['status'] == 'not set')) {
                 $messages = '<h4 class="error_msg">You need to clock in first ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                 // with that condition we prevent someone to clock out first
             } else {
                 if ($action == 'in') {
                     ######################################################
                     ##             clock IN condition                   ##
                     ######################################################
                     if ($check[0]['clerk_id'] == $clerk_id[0]['clerk_id'] && $check[0]['status'] == $action) {
                         if ($check[0]['status'] == 'in' && $check[1]['status'] == 'out') {
                             $messages = '<h4 class="error_msg">You have finished your shift for today ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                         } else {
                             $messages = '<h4 class="error_msg">You are already clocked in ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                         }
                     } else {
                         // check the rota first
                         $cond = array('clerk_id' => $clerk_id[0]['clerk_id']);
                         $cond3 = array('status_id' => 1);
                         // Get the rota from the database
                         $time_check = $this->load_file->get_data_extend_where('clerks_list_rota', 'location_id, rota_from, status_id', $cond, $date);
                         // we check if it exists
                         if ($time_check != NULL) {
                             // this is for testing later is gonna be from database
                             $time_margin = '- ' . $time_in_margin . ' minutes';
                             // debug msg
                             echo 'the real time in is: ' . $data_for['sign_time'] . '<br>';
                             // we put the margin to the current time, and we move the time some minutes earlier
                             $data_for['sign_time'] = date('H:i:s', strtotime($time_margin));
                             $clock_in_time = time_to_sec($data_for['sign_time']);
                             $rota_in_time = time_to_sec($time_check[0]['rota_from']);
                             // We check the times to see if we gonna add deductions
                             if ($clock_in_time <= $rota_in_time) {
                                 ##
                                 ## NOTE: You can use this in order to set early clock ins
                                 ##
                                 $messages = $messages . '<br><h4 class="norm_msg">Great! ' . $clerk_id[0]['clerk_name'] . ' are on time! ;) </h4><br>';
                                 $data_for['sign_time'] = '00:00:00';
                             } else {
                                 // debug msg //
                                 echo 'the calculated time in is: ' . $data_for['sign_time'] . '<br>';
                                 // We calculate how many the deductions would be and we put them to the variable for the insert
                                 $deduction = time_filter(sec_to_time(abs($clock_in_time - $rota_in_time)));
                                 $data_for['sign_time'] = $deduction;
                                 $messages = $messages . '<br><h4 class="error_msg">You late for ' . $deduction . ' ' . $clerk_id[0]['clerk_name'] . '!</h4><br>';
                             }
                         } else {
                             $messages = '<h4 class="error_msg">Rota for ' . $clerk_id[0]['clerk_name'] . ' not found!</h4><br>';
                             $data_for['sign_time'] = '00:00:00';
                         }
                         // insert to database
                         $this->load_file->insert_data('clerks_check', $data_for);
                         $data_temp = array('clerk_id' => $clerk_id[0]['clerk_id'], 'location_id' => $location_id[0]['location_id'], 'sign_time' => '00:00:00', 'status' => 'out', 'date' => $date, 'time' => '00:00:00');
                         $this->load_file->insert_data('clerks_check', $data_temp);
                         $messages = $messages . '<h4 class="norm_msg">You clocked in Successfuly ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                     }
                 } else {
                     ######################################################
                     ##             clock OUT condition                  ##
                     ######################################################
                     if ($check[1]['clerk_id'] == $clerk_id[0]['clerk_id'] && $check[1]['status'] == $action && $check[1]['time'] != '00:00:00') {
                         if ($check[0]['status'] == 'in' && $check[1]['status'] == 'out') {
                             $messages = '<h4 class="error_msg">You have finished your shift for today ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                         } else {
                             $messages = '<h4 class="error_msg">You are already clocked out ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                         }
                     } else {
                         // check the rota first
                         $cond = array('clerk_id' => $clerk_id[0]['clerk_id']);
                         $cond3 = array('status_id' => 1);
                         // Get the rota from the database
                         $time_check = $this->load_file->get_data_extend_where('clerks_list_rota', 'location_id, rota_to, status_id', $cond, $date);
                         // we check if it exists
                         if ($time_check != NULL) {
                             // this is for testing later is gonna be from database
                             $time_margin = '+ ' . $time_in_margin . ' minutes';
                             // debug msg
                             echo 'the real time in is: ' . $data_for['sign_time'] . '<br>';
                             // we put the margin to the current time, and we move the time some minutes earlier
                             $data_for['sign_time'] = date('H:i:s', strtotime($time_margin));
                             $clock_out_time = time_to_sec($data_for['sign_time']);
                             $rota_out_time = time_to_sec($time_check[0]['rota_to']);
                             // debug msg //
                             echo 'the calculated time in is: ' . $data_for['sign_time'] . '<br>';
                             echo $clock_out_time . ' clock out time in sec <br>';
                             echo $rota_out_time . ' rota out time in sec <br>';
                             // We check the times to see if we gonna add overtime or not
                             if ($clock_out_time <= $rota_out_time) {
                                 $data_for['sign_time'] = '00:00:00';
                                 ##
                                 ## NOTE: You can use this in order to set early clock outs
                                 ##
                                 //$messages = $messages . '<br> Great! ' . $clerk_id[0]['clerk_name'] . ' are on time! ;) <br>';
                             } else {
                                 $overtime = time_filter(sec_to_time(abs($rota_out_time - $clock_out_time)));
                                 $data_for['sign_time'] = $overtime;
                                 $messages = $messages . '<br><h4 class="norm_msg">Your overtime is: ' . $overtime . ' ' . $clerk_id[0]['clerk_name'] . '!</h4><br>';
                             }
                         } else {
                             $messages = '<h4 class="error_msg">Rota for ' . $clerk_id[0]['clerk_name'] . ' not found!</h4><br>';
                             $data_for['sign_time'] = '00:00:00';
                         }
                         // insert to database
                         $field = array('clerk_id' => $clerk_id[0]['clerk_id'], 'date' => $date, 'status' => 'out');
                         $this->load_file->update_data('clerks_check', $data_for, $field);
                         $messages = $messages . '<h4 class="norm_msg">You clocked out Successfuly ' . $clerk_id[0]['clerk_name'] . '!</h4>';
                     }
                 }
             }
         } else {
             // In case that the clerk doesn't exist
             $messages = "<h4 class='error_msg'>This Clerk doesn't exist!</h4>";
         }
     }
     // Get the data for this week selected rota
     // Get the week dates
     $week_start = date('z', strtotime('this week'));
     $week_end = date('z', strtotime('next week'));
     for ($i = $week_start; $i < $week_end; $i++) {
         $date_this[] = date('D d M', strtotime("January 1st +" . $i . " days"));
     }
     //query the database
     $this_week = $this->load_file->get_clerks_date('*', date('Y-m-d', strtotime($date_this[0])), date('Y-m-d', strtotime($date_this[6])), $location['id']);
     // Prepare data for the form
     $data = array('name' => $location['name'], 'message_display' => $messages, 'rota' => $this_week, 'dates' => $date_this, 'property' => '');
     // Load the view as a result and check if the user is logged in
     if ($this->login_database->is_logged()) {
         $this->load->view('user_page', $data);
     } else {
         $this->load->view('login_form', $data);
     }
 }
Esempio n. 3
0
function overtime_deductions($clerk_details, $extra)
{
    $total_deductions = 0;
    $total_overtime = 0;
    // we calculate the overtime and the overal late times
    foreach ($clerk_details as $id => $entry) {
        foreach ($entry as $key => $value) {
            if ($id == $entry[$key]['clerk_id'] && $entry[$key]['status'] == 'in') {
                // Late Deductions
                if ($extra == TRUE) {
                    $deductions[] = array('date' => '', 'time' => '', 'real_time' => '');
                    if ($entry[$key]['approval'] == 1) {
                        $deductions[] = array('date' => $entry[$key]['date'], 'time' => $entry[$key]['sign_time'], 'real_time' => $entry[$key]['time']);
                        $total_deductions = $total_deductions + time_to_sec($entry[$key]['sign_time']);
                    }
                } else {
                    $deductions[] = array('id' => $entry[$key]['id'], 'approval' => $entry[$key]['approval'], 'date' => $entry[$key]['date'], 'time' => $entry[$key]['sign_time'], 'real_time' => $entry[$key]['time']);
                    $total_deductions = $total_deductions + time_to_sec($entry[$key]['sign_time']);
                }
            } else {
                // Overtime
                if ($extra == TRUE) {
                    $overtime[] = array('date' => '', 'time' => '', 'real_time' => '');
                    if ($entry[$key]['approval'] == 1) {
                        $overtime[] = array('date' => $entry[$key]['date'], 'time' => $entry[$key]['sign_time'], 'real_time' => $entry[$key]['time']);
                        $total_overtime = $total_overtime + time_to_sec($entry[$key]['sign_time']);
                    }
                } else {
                    $overtime[] = array('id' => $entry[$key]['id'], 'approval' => $entry[$key]['approval'], 'date' => $entry[$key]['date'], 'time' => $entry[$key]['sign_time'], 'real_time' => $entry[$key]['time']);
                    $total_overtime = $total_overtime + time_to_sec($entry[$key]['sign_time']);
                }
                $clerk_list[$id] = array('clerk_name' => $entry[$key]['clerk_name'], 'secret_no' => $entry[$key]['secret_no'], 'deductions' => $deductions, 'total_deductions' => $total_deductions, 'overtime' => $overtime, 'total_overtime' => $total_overtime);
            }
        }
        unset($deductions);
        $total_deductions = 0;
        unset($overtime);
        $total_overtime = 0;
    }
    return $clerk_list;
}
<?php

session_start();
$exam_id = $_GET["id"];
$query = "SELECT * FROM tbl_exams WHERE id = {$exam_id} ";
$result = $dbObj->doQuery($query);
$row = $dbObj->fetchObject($result);
function time_to_sec($time)
{
    $hours = substr($time, 0, -6);
    $minutes = substr($time, -5, 2);
    $seconds = substr($time, -2);
    return $hours * 3600 + $minutes * 60 + $seconds;
}
$time_limit = time_to_sec($row->duration);
if (!isset($_SESSION["start_time"])) {
    $_SESSION["start_time"] = mktime(date(G), date(i), date(s), date(m), date(d), date(Y)) + $time_limit;
}
// Add $time_limit (total time) to start time. And store into session variable.
if (!isset($_SESSION["load_time"])) {
    date_default_timezone_set('Asia/Dhaka');
    $_SESSION["load_time"] = date("Y-m-d H:i:s a");
}
?>
<style>
#countdown {
	border:0px solid red;
	font-family:verdana;
	font-size:16pt;
	font-weight:bold;
	background: none;
Esempio n. 5
0
        if (isset($_POST['expire'])) {
            $expire = empty($_POST['expire']) ? time_to_sec($_POST['expire_text']) : intval($_POST['expire']);
        } else {
            $expire = getDateField('expire');
        }
        $data['ldate'] = $data['edate'] = $edate;
        $data['expire'] = $expire;
        $data['topicid'] = param('topicid', 1);
        foreach ($iargs as $name) {
            $data[$name] = param($name);
        }
        foreach ($targs as $name) {
            $data[$name] = param($name, "");
        }
        $data['ldate'] = 0;
        $data['closetime'] = time_to_sec($data['before']);
        if ($adm) {
            $data['status'] = param('status');
        }
        $data['optvars'] = post_optvars(_EG_OPTDEFS);
    }
}
if (!isset($data['status'])) {
    $data['status'] = $xoopsModuleConfig['auth'] ? STAT_POST : STAT_NORMAL;
}
$extent_sets = array();
if (isset($_POST['extent_sets'])) {
    $init = false;
    $sets = $_POST['extent_sets'];
} else {
    $init = true;
Esempio n. 6
0
</tr>
</thead>
<tbody>
<?php 
$idx = 0;
while ($al = $res_assenze_alunni->fetch_assoc()) {
    $assenze = $totali['giorni'] - $al['giorni'];
    $perc_assenze = round($assenze / $totali['giorni'] * 100, 2);
    /**
     * calcolo della percentuale oraria di assenze mediante conversione
     * dei time in secondi
     */
    // numero totale di ore di lezione
    $tot_hours = time_to_sec($totali['ore']);
    // ore di assenza
    $abs_hours = time_to_sec($al['ore_assenza']);
    $perc_hours = round($abs_hours / $tot_hours * 100, 2);
    // formattazione ore assenza
    list($abs_h, $abs_m, $abs_s) = explode(":", $al['ore_assenza']);
    $ore_assenza = $abs_h . ":" . $abs_m;
    $background = "";
    ?>
<tr>
	<td class="<?php 
    if ($idx == 0) {
        print "reg_firstrow";
    } else {
        print "reg_row";
    }
    ?>
" style="width: 35%; padding-left: 8px"><a href="#" onclick="show_menu(event, <?php 
Esempio n. 7
0
 /**
  * @param $savedrace_id
  * @param $yourTime
  *
  * @return array
  *
  * ['Racers'] => array of the 5 racers
  *      [0-4] => ['USSAPoints] => Racer's USSA points,
  *               ['FISPoints'] => Racer's FIS points,
  *               ['USSANote'] => USSA note,
  *               ['FISNote'] => FIS note,
  *               ['LastName'] => Racer's last name,
  *               ['FirstName'] => Racer's first name
  *
  * ['USSAPenalty'] => USSA penalty
  * ['FISPenalty'] => FIS penalty
  * ['RacePoints'] => Race Points
  * ['USSAFinalPoints'] => Final USSA Points
  * ['FISFinalPoints'] => Final FIS Points
  * ['RaceName'] => Race Name
  * ['Gender'] => Gender
  * ['USSA_List'] => USSA list used to score
  * ['FIS_List'] => FIS list used to score
  */
 public function scoreSavedRace($savedrace_id, $yourTime)
 {
     $race = savedrace::where('savedrace_id', '=', $savedrace_id)->first();
     /*
      * Set Variables
      */
     $output = [];
     if ($race->format == 1) {
         $fFactor = 800;
     } elseif ($race->format == 2) {
         $fFactor = 1400;
     } elseif ($race->format == 3) {
         $fFactor = 1200;
     }
     /*
      * Convert time to seconds
      */
     $usersTime = time_to_sec($yourTime);
     $winnersTime = time_to_sec($race->winners_time);
     $points = $race->getPoints()->get();
     $i = 0;
     foreach ($points as $point) {
         $output['Racers'][$i] = ['USSAPoints' => $point->USSA_points, 'FISPoints' => $point->FIS_points, 'USSANote' => $point->USSA_note, 'FISNote' => $point->FIS_note, 'LastName' => $point->savedracer()->first()->last, 'FirstName' => $point->savedracer()->first()->first];
         $racersUSSAPoints[$i] = $point->USSA_points;
         $racersFISPoints[$i] = $point->FIS_points;
         $i++;
     }
     /*
      * Calculate USSA penalty
      * Sum of three lowest points divided by 3.75
      */
     $sortResult = sort($racersUSSAPoints);
     $USSAtopThree = array_slice($racersUSSAPoints, 0, 3, true);
     $USSAPenalty = array_sum($USSAtopThree) / 3.75;
     $USSAPenalty = round($USSAPenalty, 2, PHP_ROUND_HALF_UP);
     $output['USSAPenalty'] = $USSAPenalty;
     /*
      * Calculate FIS penalty
      * Sum of three lowest points divided by 3.75
      */
     $sortResult = sort($racersFISPoints);
     $FIStopThree = array_slice($racersFISPoints, 0, 3, true);
     $FISPenalty = array_sum($FIStopThree) / 3.75;
     $FISPenalty = round($FISPenalty, 2, PHP_ROUND_HALF_UP);
     $output['FISPenalty'] = $FISPenalty;
     /*
      * Calculate race points
      *
      * Page 20
      * http://www.fis-ski.com/mm/Document/documentlibrary/Cross-Country/04/26/74/FISpointsrules2015-2016_inclattachments_English.pdf
      *
      */
     $racePoints = $usersTime * $fFactor / $winnersTime - $fFactor;
     $racePoints = round($racePoints, 2, PHP_ROUND_HALF_UP);
     $output['RacePoints'] = $racePoints;
     /*
      * Calculate final USSA Points
      */
     $USSAFinalPoints = $USSAPenalty + $racePoints;
     $output['USSAFinalPoints'] = $USSAFinalPoints;
     /*
      * Calculate final FIS Points
      */
     $FISFinalPoints = $FISPenalty + $racePoints;
     $output['FISFinalPoints'] = $FISFinalPoints;
     /*
      * Basic Race Data
      */
     $output['RaceName'] = $race->race_name;
     $output['Gender'] = $race->gender;
     $output['USSA_List'] = $race->USSA_list;
     $output['FIS_List'] = $race->FIS_list;
     /*
      * Update number of clicks
      */
     $clicks = $race->clicks;
     $clicks++;
     $race->clicks = $clicks;
     $race->save();
     return $output;
 }