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); }
<th width="10%" align="left">Group</th> End_Of_HTML; } print <<<End_Of_HTML <th align="left">Notes</th> </tr> </thead> <tbody> End_Of_HTML; } $row_count++; $row_class = $row_count % 2 ? 'odd' : 'even'; if ($row['timestamp'] > 0) { $display_stamp = local_timestamp($row['timestamp']); $time = date($timefmt, $display_stamp); $date = date($datefmt, $display_stamp); } else { // New employees do not have timestamp to display yet. $time = $date = ''; } $u_empfullname = urlencode($row['empfullname']); $h_name = htmlentities($show_display_name == 'yes' ? $row['displayname'] : $row['empfullname']); $h_color = htmlentities($row['color']); $h_inout = htmlentities($row['inout']); $h_office = htmlentities($row['office']); $h_groups = htmlentities($row['groups']); $h_notes = htmlentities($row['notes']); // Make DOM id out of employee fullname column (which is assumed to be their employee id). $id = htmlentities(make_id($row['empfullname']));
$empfullname = isset($_REQUEST['empfullname']) ? $_REQUEST['empfullname'] : null; if (!$empfullname) { $empfullname = $emp; } // from url or form entry if (!$empfullname) { die(error_msg("Unrecognized employee.")); } // no employee specified // To run this report, employee must have been authorized to punch-in/out first. $authorized = isset($_SESSION['authenticated']) ? $_SESSION['authenticated'] == $empfullname : false; if (!$authorized) { die(error_msg("Not authorized to run this report.")); } // Find which week to print timecard. $local_timestamp_in_week = isset($_REQUEST['t']) ? $_REQUEST['t'] : local_timestamp(); if (isset($_REQUEST['prev'])) { $local_timestamp_in_week -= $one_week; } if (isset($_REQUEST['next'])) { $local_timestamp_in_week += $one_week; } // Connect to db. $db = mysql_connect($db_hostname, $db_username, $db_password) or die("Could not connect to the database."); mysql_select_db($db_name); $u_empfullname = rawurlencode($empfullname); // Print navigation buttons to next and previous week. // Note: cannot put title attribute on <a> as nyroModal uses that for a title over the next display. print <<<End_Of_HTML <div class="nav-buttons"> <a href="timecard.ajax.php?emp={$empfullname}&t={$local_timestamp_in_week}&prev" class="nyroModal"><img src="images/prev_page.gif" alt="Previous" /></a><a href="timecard.ajax.php?emp={$empfullname}&t={$local_timestamp_in_week}&next" class="nyroModal"><img src="images/next_page.gif" alt="Next" /></a>
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('punchclock: cannot update tstamp in employee record. ' . mysql_error(), E_USER_WARNING); } else { trigger_error('punchclock: cannot insert timestamp into info record. ' . mysql_error(), E_USER_WARNING); } // Update display line on punchclock list and close form. $id = make_id($empfullname); $display_stamp = local_timestamp($tz_stamp); $time = date($timefmt, $display_stamp); $date = date($datefmt, $display_stamp); # Note nyroModal 1.6.2: must have LF (IE needs characters) outside of <script> otherwise nyroModal window does not close. print <<<End_Of_HTML <p>stupid text to get this to work in IE</p> <script type="text/javascript"> //<![CDATA[ // Post results to main page employee list \$('#{$id} td').each(function(index){ \tif (index == 1) { \t\tthis.innerHTML = "{$h_inout}"; \t\tthis.style.color = "{$inout_color}"; \t} \tif (index == 2) this.innerHTML = "{$time}"; \tif (index == 3) this.innerHTML = "{$date}";
/** * Current employee punch-in/out status for entry.php */ if (!isset($_SESSION['application'])) { header('Location:entry.php'); exit; } require_once 'config.inc.php'; require_once 'lib.common.php'; // Configuration variables. global $timefmt, $datefmt, $timecard_display_hours_minutes; // Get status list($in_or_out, $color, $inout, $timestamp, $notes) = get_employee_status($empfullname); // Compute hours $punch_time = local_timestamp($timestamp); $hours = compute_hours($punch_time, local_timestamp()); $h_color = htmlentities($color); $h_inout = htmlentities($inout); $h_time = date($timefmt, $punch_time); $h_date = date($datefmt, $punch_time); if ($in_or_out == 1) { if ($timecard_display_hours_minutes == "yes") { $h_hours = hrs_min($hours); } else { $h_hours = sprintf("%01.02f", $hours); } } else { $h_hours = ''; } $h_notes = htmlentities($notes); ?>