Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function is_weekend($date = false)
- {
- return (date("D",strtotime($date)) == 'Sun' || date("D",strtotime($date)) == 'Sat')? true : false;
- }
- // Make a function for on time, makes that part changeable
- // gives the ability to change start times ($default) in the future
- function on_time($timein = false, $default = '09:30')
- {
- if($timein == false)
- return true;
- return (strtotime($timein) > strtotime($default))? false : true;
- }
- function early($timeout = false, $default = '18:00')
- {
- if($timeout == false)
- return true;
- return (strtotime($timeout) < strtotime($default))? false : true;
- }
- $staff = $dome = array();
- while($row = ibase_fetch_assoc($result))
- { $dome[] = $row; }
- foreach($dome as &$value)
- if (ctype_upper(substr($value['NAME'],0,2))== TRUE)
- $staff[] = $value['NAME'];
- $staff = array_values(array_unique($staff,SORT_REGULAR));
- $m = $_POST['month'];
- $y = $_POST['year'];
- //reorganize the array by day
- foreach($dome as $user) {
- if(!preg_match('/^'.$y.'/'.$m.'/',$user['DATEIN']))
- continue;
- $new[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEIN'];
- $newto[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEOUT'];
- }
- if ($m != '' || $y != '')
- echo "<br><u>Attendance for ".date("F", mktime(null, null, null, $m, 1)).", ".$y."</u>";
- else
- break;
- ?>
- <table id="caltable" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td>
- NAME
- </td>
- <?php
- // Set header row
- $day_in_mo = cal_days_in_month(CAL_GREGORIAN,$m,$y);
- for($i = 1; $i <= $day_in_mo; $i++) { ?>
- <td><?php echo $i; ?></td>
- <?php
- } ?>
- </tr>
- <?php
- // Loop through staff
- foreach($staff as $name) { ?>
- <tr>
- <td rowspan=2><?php echo $name; ?></td>
- <?php
- $keyname = strtolower($name);
- for($i = 1; $i <= $day_in_mo; $i++) {
- $timein = (!empty($new[$i][$keyname][0]))? $new[$i][$keyname][0] : false;?>
- <td class="<?php if(!is_weekend("{$y}-{$m}-{$i}")) { echo 'weekday'; if(!on_time($timein)) echo ' late'; echo '"'; } else echo 'weekend' ?>"><?php
- // Match keys and see if user is listed in that day
- echo ($timein != false)? $timein : '<div class="absent">-</div>'; ?></td>
- <?php
- } ?>
- </tr>
- <tr>
- <td style="display:none"></td>
- <?php
- $keyname = strtolower($name);
- for($i = 1; $i <= $day_in_mo; $i++) {
- $timeout = (!empty($newto[$i][$keyname][0]))? $newto[$i][$keyname][0] : false; ?>
- <td class="<?php if(!is_weekend("{$y}-{$m}-{$i}")) { echo 'weekday'; if(!early($timeout)) echo ' early'; echo '"'; } else echo 'weekend' ?>"><?php
- echo ($timeout != false)? $timeout : '<div class="absent">-</div>'; ?></td>
- <?php
- } ?>
- </tr>
- <?php
- } ?>
- </table>
- <?php
- // Make a function for the weekend to isolate that condition
- // makes it much cleaner
- function is_weekend($date = false)
- {
- return (date("D",strtotime($date)) == 'Sun' || date("D",strtotime($date)) == 'Sat')? true : false;
- }
- // Make a function for on time, makes that part changeable
- // by giving you the ability to change start times ($default) in the future
- function on_time($timein = false, $default = '09:10')
- {
- if($timein == false)
- return true;
- return (strtotime($timein) > strtotime($default))? false : true;
- }
- <!-- Just some quick styling -->
- <style>
- #caltable td {
- width: 50px;
- padding: 5px;
- font-family: Arial, Helvetica, sans-serif;
- font-size: 13px;
- text-align: center;
- border-bottom: 1px solid #CCC;
- }
- #caltable td:first-child {
- width: 150px;
- }
- .weekend {
- background-color: #FFFF00;
- }
- .late {
- background-color: orange;
- color: #FFF;
- }
- .weekday {
- background-color: #EBEBEB;
- }
- .absent {
- color: #888;
- font-weight: bold;
- }
- </style>
- $y = '2015';
- $m = '01';
- // I think it's important to reorganize the array by day
- foreach($dome as $user) {
- if(!preg_match('/^'.$y.'/'.$m.'/',$user['DATEIN']))
- continue;
- $new[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEIN'];
- } ?>
- <table id="caltable" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td>
- NAME
- </td>
- <?php
- // Set header row
- $day_in_mo = cal_days_in_month(CAL_GREGORIAN,$m,$y);
- for($i = 1; $i <= $day_in_mo; $i++) { ?>
- <td><?php echo $i; ?></td>
- <?php
- } ?>
- </tr>
- <?php
- // Loop through staff
- foreach($staff as $name) { ?>
- <tr>
- <td><?php echo $name; ?></td>
- <?php
- $keyname = strtolower($name);
- for($i = 1; $i <= $day_in_mo; $i++) {
- $timein = (!empty($new[$i][$keyname][0]))? $new[$i][$keyname][0] : false; ?>
- <td class="<?php if(is_weekend("{$y}-{$m}-{$i}")) { echo 'weekend'; if(!on_time($timein)) echo ' late'; echo '"'; } else echo 'weekday' ?>"><?php
- // Match keys and see if user is listed in that day
- echo ($timein != false)? $timein : '<div class="absent">-</div>'; ?></td>
- <?php
- } ?>
- </tr>
- <?php
- } ?>
- </table>
- $inidate = "$y/$m/01"; //$y and $m chosen by user
- $count=0;
- foreach ($staff as $key => $team) //row or use count on staff
- {
- $j=0;
- echo "<tr><td>".($count+1).".</td><td>".$team."</td>";
- for ($i=0;$i<cal_days_in_month(CAL_GREGORIAN,$m,$y);$i++) //column
- {
- $cond = FALSE;
- while (($dome[$j]['DATEIN'] != "") && ($cond == FALSE))
- {
- if ($dome[$j]['DATEIN'] == $inidate)
- {
- if (strtoupper($team) == strtoupper($dome[$j]['NAME']))
- {
- if ($dome[$j]['TIMEIN'] != "")
- {
- $cond = TRUE;
- if (date("D",strtotime($getdate)) == 'Sun' || date("D",strtotime($getdate)) == 'Sat')
- {
- //if late output time in yellow cell
- if (strtotime($dome[$j]['TIMEIN']) > strtotime('09:10'))
- echo "<td BGCOLOR='#ffff00'>".$dome[$j]['TIMEIN']."</td>";
- else //output time normally
- echo "<td>".$dome[$j]['TIMEIN']."</td>";
- }
- else //if its weekday outputs gray cell
- echo "<td BGCOLOR='#525266'>".$dome[$j]['TIMEIN']."</td>";
- }
- else
- echo "<td>AB</td>";
- }
- $j++;
- }
- }
- $inidate = strftime("%Y/%m/%d", strtotime("$inidate +1 day"));
- echo "</tr>";
- }
- $count++;
- }
- <?php
- $month = "01";
- $year = "2015";
- $staff=array('STAFF A-Full Name',
- 'STAFF B-Full Name',
- 'STAFF C-Full Name');
- $dome[]=array('NAME' => 'STAFF A-Full Name',
- 'DATEIN' => '2015/01/01' ,
- 'TIMEIN' => '09:02');
- $dome[]=array('NAME' => 'STAFF A-Full Name',
- 'DATEIN' => '2015/01/02',
- 'TIMEIN' => '08:30');
- $dome[]=array('NAME' => 'STAFF B-Full Name',
- 'DATEIN' => '2015/01/01',
- 'TIMEIN' => '08:43');
- $dome[]=array('NAME' => 'Staff B-Full Name',
- 'DATEIN' => '2015/01/03',
- 'TIMEIN' => '09:11');
- echo "<table>";
- $countTeam = 0;
- foreach ($staff as $key => $team) //row or use count on staff
- {
- $inidate = "$year/$month/01"; //$year and $month chosen by user
- echo "<tr><td>".($countTeam + 1).".</td><td>".$team."</td>";
- for ($i = 0; $i < cal_days_in_month(CAL_GREGORIAN, $month, $year); $i++) //column
- {
- $found = false;
- foreach($dome as $domeKey => $staffAssignment){
- if($found){
- break;
- }
- if ($staffAssignment['DATEIN'] == $inidate)
- {
- if (strtoupper($team) == strtoupper($staffAssignment['NAME']))
- {
- if ($staffAssignment['TIMEIN'] != "")
- {
- $found = true;
- if (date("D", strtotime($inidate)) == 'Sun' || date("D", strtotime($inidate)) == 'Sat')
- {
- //if late output time in yellow cell
- if (strtotime($staffAssignment['TIMEIN']) > strtotime('09:10')){
- echo "<td BGCOLOR='#ffff00'>".$staffAssignment['TIMEIN']."</td>";
- }
- else { //output time normally
- echo "<td>".$staffAssignment['TIMEIN']."</td>";
- }
- }
- else { //if its weekday outputs gray cell
- echo "<td BGCOLOR='#525266'>".$staffAssignment['TIMEIN']."</td>";
- }
- }
- else {
- echo "<td>AB</td>";
- }
- }
- }
- }
- if(!$found){
- echo "<td></td>";
- }
- $inidate = strftime("%Y/%m/%d", strtotime("$inidate +1 day"));
- }
- $countTeam++;
- echo "</tr>";
- }
- echo "</table>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement