Ejemplo n.º 1
0
 function walk($onBefore = null, $onEveryRow = null, $onAfter = null)
 {
     // Search employee time records and walk through them.
     // The beginning time $begin_local_timestamp, a local timestamp, must be set
     // to be the beginning of the week of interest. The sum of weekly hours and the
     // computation of overtime commences from the $this->begin_local_timestamp. The
     // $this->end_local_timestamp is for the end of the work week. It cannot span more than one
     // week otherwise the computation of overtime is wrong. Argument functions are used
     // to actually print (or process) the entries.
     // Returns a 4 element array of number of 1) rows processed, 2) the total work hours,
     // 3) total overtime hours, and 4) total hours worked today.
     // Configuration variables.
     global $show_display_name, $timefmt, $datefmt;
     global $overtime_week_limit, $timecard_list_punch_outs, $timecard_punchitem;
     // Initialize totals
     $this->week_hours = 0;
     $this->overtime_hours = 0;
     $this->today_hours = null;
     // not used unless week includes today
     // Set flag to tally today's hours if within current week.
     $local_timestamp = local_timestamp();
     // current time
     if ($local_timestamp >= $this->begin_local_timestamp && $local_timestamp <= $this->end_local_timestamp) {
         // In current work week, set flag to look for and sum today's hours too.
         $do_today_hours = true;
         $today_date = date('Ymd', local_timestamp());
         $this->today_hours = 0;
     }
     // Initialize
     $row_count = 0;
     // Make SQL search parameters.
     $begin_utm_timestamp = utm_timestamp($this->begin_local_timestamp);
     // must be beginning of work week
     $end_utm_timestamp = utm_timestamp($this->end_local_timestamp);
     // can be any time within work week
     if ($this->begin_local_timestamp < $local_timestamp) {
         // Get previous record to timecard to see if employee is already signed in at beginning of the period.
         $result = mysql_query($this->_query_prev_record($begin_utm_timestamp)) or trigger_error('Timecard->walk: no previous result: ' . mysql_error(), E_USER_WARNING);
         if ($result && mysql_num_rows($result) > 0) {
             $this->row = mysql_fetch_array($result);
             if ($this->row['in_or_out'] == 1) {
                 $row_count++;
                 // Initialize
                 $this->start_time = day_timestamp($this->begin_local_timestamp);
                 $this->in_or_out = $this->row['in_or_out'];
                 $this->row['notes'] = "(cont.)";
                 // add note
                 // Trigger onBefore function.
                 if ($onBefore) {
                     $onBefore($this);
                 }
             }
             mysql_free_result($result);
         }
     }
     // Get timecard entries.
     $query = $this->_query($begin_utm_timestamp, $end_utm_timestamp);
     $result = mysql_query($query) or trigger_error('Timecard->walk: no result: ' . mysql_error(), E_USER_WARNING);
     // Process timecard entries.
     while ($this->next_row = mysql_fetch_array($result)) {
         $row_count++;
         $this->end_time = local_timestamp($this->next_row['timestamp']);
         // normalize timestamp to local time
         if ($row_count == 1) {
             // Initialize
             $this->start_time = $this->end_time;
             $this->in_or_out = $this->next_row['in_or_out'];
             $this->row = $this->next_row;
             // Trigger onBefore function.
             if ($onBefore) {
                 $onBefore($this);
             }
             continue;
         }
         // Is employee punched in?
         if ($this->in_or_out == 1) {
             list($this->hours, $this->overtime) = compute_work_hours($this->start_time, $this->end_time, $this->week_hours);
             if ($do_today_hours) {
                 $this->today_hours += compute_day_hours($today_date, $this->start_time, $this->end_time);
             }
             $this->week_hours += $this->hours;
             $this->overtime_hours += $this->overtime;
             $this->total_hours = $this->week_hours + $this->overtime_hours;
         }
         // Trigger onEveryRow function.
         if ($onEveryRow) {
             $onEveryRow($this);
         }
         // Re-initialize
         $this->start_time = $this->end_time;
         $this->in_or_out = $this->next_row['in_or_out'];
         $this->row = $this->next_row;
     }
     // Complete processing of the last time record.
     if ($row_count > 0) {
         $row_count++;
         if ($this->in_or_out == 1) {
             // Last record still has employee punched in.
             $this->end_time = $this->end_local_timestamp > $local_timestamp ? $local_timestamp : $this->end_local_timestamp;
             list($this->hours, $this->overtime) = compute_work_hours($this->start_time, $this->end_time, $this->week_hours);
             if ($do_today_hours) {
                 $this->today_hours += compute_day_hours($today_date, $this->start_time, $this->end_time);
             }
             $this->week_hours += $this->hours;
             $this->overtime_hours += $this->overtime;
             $this->total_hours = $this->week_hours + $this->overtime_hours;
             // Add another record into timecard indicating pseudo punch-out at current time or end of week.
             // Trigger onEveryRow function.
             if ($onEveryRow) {
                 $onEveryRow($this);
             }
             // Re-initialize
             $this->start_time = $this->end_time;
             $this->in_or_out = 0;
             $this->row = $this->next_row;
             // Fill in pseudo row
             $this->row['in_or_out'] = $this->in_or_out;
             $this->row['color'] = '#333';
             $this->row['inout'] = $this->row['punchitems'] = $timecard_punchitem;
             $this->row['notes'] = $this->end_time == $local_timestamp ? "(current time) " . $this->row['notes'] : "(end of period) " . $this->row['notes'];
             // add note
         }
         // Trigger onEveryRow function.
         if ($onEveryRow) {
             $onEveryRow($this);
         }
         // Trigger onAfter function.
         if ($onAfter) {
             $onAfter($this);
         }
     }
     mysql_free_result($result);
     return array($row_count, $this->total_hours, $this->overtime_hours, $this->today_hours);
 }
Ejemplo n.º 2
0
/**
 * Display time and day.
 *
 * Part of punchclock.php program.
 */
/* TODO: Text substitutions on the Javascript Date.toLocaleString() method is used to display
 * the time on the browser. The Date.toLocaleString() does not return the same string in all
 * browders. Safari and Chrome should have times adjusted to 12hr format if specified by $timefmt.
 *	Firefox:	Monday, March 08, 2010 3:22:01 PM
 *	IE8:		Monday, March 08, 2010 3:22:01 PM
 *	Safari:		Monday, March 08, 2010 15:22:01
 *	Chrome:		Mon Mar 08 2010 15:22:01 GMT-0700 (Mountain Standard Time)
 *	Opera:		3/8/10  3:22:01 PM
 */
require_once "lib.common.php";
$timestamp = utm_timestamp() + timezone_offset();
$timeclock = date('l F j, Y H:i', $timestamp);
// initial display
// Define javascript replacement function for changing Date.toLocaleString() text according to $timefmt config option.
switch ($timefmt) {
    case 'G:i':
        // 24 hour w/o leading 0
        $replace_func = "function(p0,p1,p2,p3,p4,p5) { return timer.time.getHours().toString().replace(/^0(!:0)/,'')+':'+p2+':'+p3; }";
        break;
    case 'H:i':
        // 24 hour
        $replace_func = "function(p0,p1,p2,p3,p4,p5) { return ((timer.time.getHours() < 10) ? '0' : '')+timer.time.getHours()+':'+p2+':'+p3; }";
        break;
    case 'g:i A':
        // 12 hour AM/PM
        $replace_func = "function(p0,p1,p2,p3,p4,p5) { return p1+':'+p2+':'+p3+p4+p5; }";
Ejemplo n.º 3
0
    $notes = isset($_POST['notes']) ? $_POST['notes'] : '';
    $q_notes = mysql_real_escape_string($notes);
    $h_notes = htmlentities($notes);
    $q_empfullname = mysql_real_escape_string($empfullname);
    // Validate and get inout display color.
    $query = "select color from " . $db_prefix . "punchlist where punchitems = '{$q_inout}'";
    $punchlist_result = mysql_query($query);
    $inout_color = mysql_result($punchlist_result, 0, 0);
    if (!$inout_color) {
        #print error_msg("In/Out Status is not in the database.");
        trigger_error('In/Out Status is not in the database.', E_USER_WARNING);
        exit;
    }
    $h_color = htmlentities($inout_color);
    // Record time.
    $tz_stamp = utm_timestamp();
    $ip = strtolower($ip_logging) == "yes" ? "'" . get_ipaddress() . "'" : 'NULL';
    $insert_query = <<<End_Of_SQL
insert into {$db_prefix}info (fullname, `inout`, timestamp, notes, ipaddress)
values ('{$q_empfullname}', '{$q_inout}', '{$tz_stamp}', '{$q_notes}', {$ip})
End_Of_SQL;
    $update_query = <<<End_Of_SQL
update {$db_prefix}employees
set tstamp = '{$tz_stamp}'
where empfullname = '{$q_empfullname}'
End_Of_SQL;
    if (mysql_query($insert_query)) {
        mysql_query($update_query) or trigger_error('entry: cannot update tstamp in employee record. ' . mysql_error(), E_USER_WARNING);
    } else {
        trigger_error('entry: cannot insert timestamp into info record. ' . mysql_error(), E_USER_WARNING);
    }
Ejemplo n.º 4
0
/**
 * Export display of hours.
 */
if (!isset($_SESSION['application'])) {
    header('Location:export.php');
    exit;
}
require_once 'class.Timecard.php';
// Construct query parameters
$begin_local_timestamp = make_timestamp($from_date);
// begins at midnight
$end_local_timestamp = make_timestamp($to_date) + $one_day - 1;
// through end of day
$begin_utm_timestamp = utm_timestamp($begin_local_timestamp);
$end_utm_timestamp = utm_timestamp($end_local_timestamp);
$employee_clause = $user_name == 'All' ? '' : "   and {$db_prefix}employees.empfullname = '" . mysql_real_escape_string($user_name) . "'\n";
$office_clause = $office_name == 'All' ? '' : "   and {$db_prefix}employees.office = '" . mysql_real_escape_string($office_name) . "'\n";
$groups_clause = $group_name == 'All' ? '' : "   and {$db_prefix}employees.groups = '" . mysql_real_escape_string($group_name) . "'\n";
// Select employees whose timecards need to be scanned.
$query = <<<End_Of_SQL
select distinct fullname
  from {$db_prefix}info
  left join {$db_prefix}employees on {$db_prefix}info.fullname = {$db_prefix}employees.empfullname
where timestamp between {$begin_utm_timestamp} and {$end_utm_timestamp}
{$employee_clause}{$office_clause}{$groups_clause}order by 1
End_Of_SQL;
$result = mysql_query($query) or trigger_error("export_display: Cannot select employees. " . mysql_error(), E_USER_WARNING);
// Scan employee timecards between given dates and record computed hours.
setup_record_hours();
$week_begin_local_timestamp = work_week_begin($begin_local_timestamp);