Example #1
0
 function _get_common_report_data($time = false)
 {
     $data = array();
     $data['report_date_range_simple'] = get_simple_date_ranges($time);
     $data['months'] = get_months();
     $data['days'] = get_days();
     $data['years'] = get_years();
     $data['hours'] = get_hours($this->config->item('time_format'));
     $data['minutes'] = get_minutes();
     $data['selected_month'] = date('m');
     $data['selected_day'] = date('d');
     $data['selected_year'] = date('Y');
     return $data;
 }
			<div class="course_img_featured col-md-3">
				<?php 
    if (has_post_thumbnail()) {
        the_post_thumbnail(array(300, 180));
    }
    ?>
	
			</div><!--- course_img_featured -->
			<div class="course_title_featured col-md-8">
			<h1><?php 
    the_title();
    ?>
</h1>
				<p>
					<?php 
    get_hours('<b>Horas:</b>', 'horas');
    ?>
<br>
					<?php 
    get_requirements('<b>Requisitos:</b>');
    ?>
	
				</p>
			</div><!--- course_title_featured -->
		</div>
	</div>
		<div class="row wpc_course_content">
			<div class="container">
				<div class="course_content col-md-8">
					<?php 
    the_content();
 function definition()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     $mform =& $this->_form;
     // Don't forget the underscore!
     //userid of 0 means we want to see every worker. -- this needs fixing. XXX
     $canmanage = false;
     if (has_capability('block/timetracker:manageworkers', $this->context)) {
         $canmanage = true;
     }
     $canview = false;
     if (has_capability('block/timetracker:viewonly', $this->context)) {
         $canview = true;
     }
     $issiteadmin = false;
     if (has_capability('moodle/site:config', $this->context)) {
         $issiteadmin = true;
     }
     if ($this->userid == 0 && !($canmanage || $canview)) {
         print_error('notpermissible', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $this->courseid);
     }
     $now = time();
     if ($this->userid == 0 && ($canmanage || $canview)) {
         //supervisor -- show all!
         $workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $this->courseid));
         if (!$workers) {
             $mform->addElement('html', 'No workers found');
             return;
         }
     } else {
         $user = $DB->get_record('block_timetracker_workerinfo', array('id' => $this->userid));
         if ($user && $user->id != $this->userid && !($canmanage || $canview)) {
             print_error('notpermissible', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $this->courseid);
         }
     }
     /*
     $mform->addElement('header','general','Generate Monthly Timesheet');
     if($this->userid > 0){
         $mform->addElement('html','<center><a
         href="'.$CFG->wwwroot.'/blocks/timetracker/timesheet.php?id='.
         $this->courseid.'&userid='.
         $this->userid.'">Generate Monthly Timesheet</a></center>');
     } else {
         $mform->addElement('html','<center><a
         href="'.$CFG->wwwroot.'/blocks/timetracker/timesheet.php?id='.
         $this->courseid.'">Generate Monthly Timesheet</a></center>');
     }
     */
     $mform->addElement('header', 'general', 'Report time period');
     $mform->addElement('hidden', 'id', $this->courseid);
     $mform->addElement('hidden', 'userid', $this->userid);
     $mform->addElement('hidden', 'sesskey', sesskey());
     if ($this->reportstart == 0 || $this->reportend == 0) {
         $starttime = usergetdate($now);
         $starttime_mid = make_timestamp($starttime['year'], $starttime['mon'] - 1, $starttime['mday']);
         $this->reportstart = $starttime_mid;
         $endtime = usergetdate($now);
         $endtime_mid = make_timestamp($endtime['year'], $endtime['mon'], $endtime['mday'], 23, 59, 59);
         $this->reportend = $endtime_mid;
     }
     $mform->addElement('date_time_selector', 'reportstart', get_string('startreport', 'block_timetracker'), array('optional' => false, 'step' => 1));
     $mform->setDefault('reportstart', $this->reportstart);
     $mform->addHelpButton('reportstart', 'startreport', 'block_timetracker');
     $mform->addElement('date_time_selector', 'reportend', get_string('endreport', 'block_timetracker'), array('optional' => false, 'step' => 1));
     $mform->setDefault('reportend', $this->reportend);
     $mform->addHelpButton('reportend', 'endreport', 'block_timetracker');
     $mform->addElement('submit', 'datechange', 'Get work units');
     $baseurl = $CFG->wwwroot . '/blocks/timetracker';
     //************** PENDING WORK UNITS SECTION ****************//
     //which workers to see?
     /*
     $endtime = $this->reportend + ((60*60*23)+60*59); //23:59
     $sql = 'SELECT * FROM '.$CFG->prefix.'block_timetracker_pending WHERE timein BETWEEN '.
         $this->reportstart.' AND '.$endtime.' ';
     if($this->userid==0 && $this->courseid == 0){ //see all workers, all courses
     
         //$pendingunits = $DB->get_records_sql($sql);
         //bad bad
     
     } else if ($this->userid==0 && $this->courseid!=0){ //see all workers, this course
     
         $sql .= 'AND courseid='. $this->courseid;
     
     } else { //if ($this->userid != 0) //specific user, this course
         
         $sql .= 'AND userid='.$this->userid. ' AND courseid='. $this->courseid;
     
     }
     $sql .= ' ORDER BY timein DESC';
     $pendingunits = $DB->get_records_sql($sql);
     
     
     $mform->addElement('header', 'general', 'Pending work units');
     if(!$pendingunits){ //if they don't have them.
         $mform->addElement('html','No pending work units<br />');
     } else { //if they do have pending
         $mform->addElement('html', 
             '<table align="center" border="1" cellspacing="10px" '.
             'cellpadding="5px" width="95%">');
     
         $headers = '<tr>';
         if($this->userid == 0) $headers .= '<td style="font-weight: bold">Name</td>';
         $headers .= '<td style="font-weight: bold">Time in</td>
                     <td style="font-weight: bold; text-align: center">Action</td>';
         $headers .='</tr>';
     
         $mform->addElement('html',$headers);
     
     
         foreach($pendingunits as $pending){
             $row='<tr>';
             if($this->userid == 0){
                 $row .='<td><a href="'.$baseurl.
                     '/reports.php?id='.$this->courseid.'&userid='.
                         $pending->userid.'">'.$workers[$pending->userid]->lastname.', '.
                     $workers[$pending->userid]->firstname.'</a></td>';
             }
             $row.='<td>'.userdate($pending->timein,
                 get_string('datetimeformat','block_timetracker')).'</td>';
     
     
     
             $urlparams['id'] = $pending->courseid;
             $urlparams['userid'] = $pending->userid;
             $urlparams['sesskey'] = sesskey();
             $urlparams['unitid'] = $pending->id;
     
             $urlparams['clockout'] = 1;
     
             $cout = new moodle_url($CFG->wwwroot.'/blocks/timetracker/timeclock.php',
                 $urlparams);
             $clockouticon = new pix_icon('clock_stop','Clock out','block_timetracker');
             $clockoutaction = $OUTPUT->action_icon($cout, $clockouticon);
     
             unset($urlparams['clockout']);
     
             $deleteurl = new moodle_url($baseurl.'/deletepending.php', $urlparams);
             $deleteicon = new pix_icon('clock_delete',
                 get_string('delete'),'block_timetracker');
             $deleteaction = $OUTPUT->action_icon(
                 $deleteurl, $deleteicon, 
                 new confirm_action('Are you sure you want to delete this '.
                 ' pending work unit?'));
     
     
             if($canmanage){
                 $urlparams['ispending'] = true;
                 $editurl = new moodle_url($baseurl.'/editunit.php', $urlparams);
                 $editaction = $OUTPUT->action_icon($editurl, 
                     new pix_icon('clock_edit', get_string('edit'),'block_timetracker'));
                 unset($urlparams['ispending']);
             }
     
             if($canmanage){
                 $actions = $clockoutaction.' '.$editaction.' '.$deleteaction;
             } else {
                 $actions = $clockoutaction.' '.$deleteaction;
             }
     
             $row .= '<td style="text-align: center">'.$actions.'</td>';
             $row .= '</tr>';
             $mform->addElement('html',$row);
         }
         $mform->addElement('html','</table>');
     } 
     */
     //************** WORK UNITS SECTION ****************//
     //TODO - courseid is never really 0, unless we're viewing from main page.
     //which workers to see?
     $workerdesc = 'Completed work units';
     //$endtime = strtotime ('+1 day ', $this->reportend) - 1;
     //$endtime = $this->reportend + ((60*60*23)+60*59); //23:59
     $endtime = strtotime('+59 seconds', $this->reportend);
     $sql = 'SELECT * FROM ' . $CFG->prefix . 'block_timetracker_workunit WHERE (timeout ' . 'BETWEEN ' . $this->reportstart . ' AND ' . $endtime . ' ' . 'OR timein BETWEEN ' . $this->reportstart . ' AND ' . $endtime . ') ';
     if ($this->userid == 0 && $this->courseid == 0) {
         //see all workers, all courses
         $units = $DB->get_records_sql($sql);
     } else {
         if ($this->userid == 0 && $this->courseid != 0) {
             //see all workers, this course
             $sql .= 'AND courseid=' . $this->courseid;
             $workerdesc .= ' for all workers';
         } else {
             //specific user, this course
             if ($canmanage || $canview) {
                 $allurl = new moodle_url($baseurl . '/reports.php', array('id' => $this->courseid, 'userid' => 0, 'repstart' => $this->reportstart, 'repend' => $this->reportend));
                 $workerdesc .= ' for ' . $user->firstname . ' ' . $user->lastname . ' [ ' . $OUTPUT->action_link($allurl, 'see all') . ' ]';
             }
             $sql .= ' AND courseid=' . $this->courseid . ' AND userid=' . $this->userid;
         }
     }
     $sql .= ' ORDER BY timein DESC';
     $units = $DB->get_records_sql($sql);
     $mform->addElement('header', 'general', $workerdesc);
     if (!$units) {
         //if they don't have them.
         $mform->addElement('html', 'No completed work units<br />');
     } else {
         //if they do have some
         $mform->addElement('html', '
             <table align="center" cellspacing="10px" 
             cellpadding="5px" width="95%" style="border: 1px solid #000;" >');
         $headers = '<tr>';
         if ($canmanage || $canview) {
             $headers .= '<td style="font-weight: bold">Name</td>';
         }
         $headers .= '<td style="font-weight: bold; text-align: center">Time in/out</td>' . '<td style="font-weight: bold; text-align: center">Elapsed</td>';
         $headers .= '<td style="font-weight: bold; text-align: center">' . get_string('action') . '</td>';
         $headers .= '</tr>';
         $mform->addElement('html', $headers);
         $total = 0;
         //print_object($workers);
         foreach ($units as $unit) {
             $row = '<tr>';
             if ($this->userid == 0) {
                 $userurl = new moodle_url($baseurl . '/reports.php');
                 $userurl->params(array('id' => $this->courseid, 'userid' => $unit->userid, 'repstart' => $this->reportstart, 'repend' => $this->reportend));
                 $row .= '<td>' . $OUTPUT->action_link($userurl, $workers[$unit->userid]->lastname . ', ' . $workers[$unit->userid]->firstname) . '</td>';
             } else {
                 if ($canmanage || $canview) {
                     $row .= '<td>' . $user->lastname . ', ' . $user->firstname . '</td>';
                 }
             }
             //print them here? print all, w/br?
             if ($unit->timein < $this->reportstart || $unit->timeout > $endtime) {
                 /*
                 error_log("rstart: ".
                     userdate($this->reportstart, 
                     '%m/%d/%y %I:%M:%S %p'));
                 error_log("utin: ".
                     userdate($unit->timein,
                     '%m/%d/%y %I:%M:%S %p'));
                 error_log("rend: ".
                     userdate($this->reportend,
                     '%m/%d/%y %I:%M:%S %p'));
                 error_log("utout: ".
                     userdate($unit->timeout,
                     '%m/%d/%y %I:%M:%S %p'));
                 */
                 $singleurl = new moodle_url($baseurl . '/reports.php');
                 $singleurl->params(array('id' => $this->courseid, 'userid' => $unit->userid, 'repstart' => $unit->timein - 1, 'repend' => $unit->timeout + 1));
                 $splitunits = split_unit($unit);
                 $row .= '<td style="text-align: center">';
                 foreach ($splitunits as $subunit) {
                     $straddle = false;
                     if ($subunit->timein < $this->reportstart || $subunit->timeout > $endtime) {
                         $straddle = true;
                     }
                     /*
                     if($straddle){
                         error_log("rstart: ".
                             userdate($this->reportstart, 
                             '%m/%d/%y %I:%M:%S %p'));
                         error_log('in: '.
                             userdate($subunit->timein, 
                             get_string('datetimeformat', 'block_timetracker')));
                         error_log("rend: ".
                             userdate($endtime,
                             '%m/%d/%y %I:%M:%S %p'));
                         error_log('out: '.
                             userdate($subunit->timeout, 
                             get_string('datetimeformat', 'block_timetracker')));
                     }
                     */
                     if (!$straddle) {
                         $row .= userdate($subunit->timein, get_string('datetimeformat', 'block_timetracker'));
                         $row .= ' to ' . userdate($subunit->timeout, get_string('datetimeformat', 'block_timetracker'));
                         $row .= '<br />';
                     } else {
                         if ($subunit->timein > $this->reportstart) {
                             if ($subunit->timeout < $endtime) {
                                 $end = $subunit->timeout;
                             } else {
                                 $end = $endtime;
                             }
                             $row .= userdate($subunit->timein, get_string('datetimeformat', 'block_timetracker'));
                             $row .= ' to ' . userdate($end, get_string('datetimeformat', 'block_timetracker'));
                             $row .= '<br />';
                         } else {
                             if ($subunit->timein > $this->reportstart) {
                                 $start = $subunit->timein;
                             } else {
                                 $start = $this->reportstart;
                             }
                             $row .= userdate($start, get_string('datetimeformat', 'block_timetracker'));
                             $row .= ' to ' . userdate($subunit->timeout, get_string('datetimeformat', 'block_timetracker'));
                             $row .= '<br />';
                         }
                     }
                 }
                 $row .= 'Partial unit. ';
                 $row .= $OUTPUT->action_link($singleurl, '[ view complete work unit ]');
                 $row .= '</td>' . "\n";
                 $row .= '<td style="text-align: center">';
                 foreach ($splitunits as $subunit) {
                     $straddle = false;
                     if ($subunit->timein < $this->reportstart || $subunit->timeout > $endtime) {
                         $straddle = true;
                     }
                     if (!$straddle) {
                         $currelapsed = $subunit->timeout - $subunit->timein;
                         $hrs = get_hours($currelapsed, $subunit->courseid);
                         $total += $hrs;
                         $row .= $hrs . ' hour(s)';
                         $row .= '<br />';
                     } else {
                         if ($subunit->timein > $this->reportstart) {
                             if ($subunit->timeout < $endtime) {
                                 $end = $subunit->timeout;
                             } else {
                                 $end = $endtime;
                             }
                             $currelapsed = $end - $subunit->timein;
                         } else {
                             if ($subunit->timein > $this->reportstart) {
                                 $start = $subunit->timein;
                             } else {
                                 $start = $this->reportstart;
                             }
                             $currelapsed = $subunit->timeout - $start;
                         }
                         $hrs = get_hours($currelapsed, $subunit->courseid);
                         $total += $hrs;
                         $row .= $hrs . ' hour(s)';
                         $row .= '<br />';
                     }
                 }
                 $row .= '</td>' . "\n";
             } else {
                 //unit occurs all in one repstart-repend
                 $row .= '<td style="text-align: center">';
                 $row .= userdate($unit->timein, get_string('datetimeformat', 'block_timetracker'));
                 $row .= ' to ' . userdate($unit->timeout, get_string('datetimeformat', 'block_timetracker'));
                 $row .= '</td>';
                 $row .= '<td style="text-align: center">';
                 $currelapsed = $unit->timeout - $unit->timein;
                 $hrs = get_hours($currelapsed, $unit->courseid);
                 $total += $hrs;
                 $row .= $hrs . ' hour(s)</td>';
             }
             if ($canmanage || $canview) {
                 $urlparams['id'] = $unit->courseid;
                 $urlparams['userid'] = $unit->userid;
                 $urlparams['sesskey'] = sesskey();
                 $urlparams['unitid'] = $unit->id;
                 $unitdateinfo = usergetdate($unit->timein);
                 if ($unit->timesheetid && !$unit->submitted) {
                     //show greyed out icons and no URL
                     $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/wait.png', 'class' => 'icon')) . '</td>';
                 } else {
                     if ($unit->timesheetid && $unit->submitted) {
                         $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/certified.png', 'class' => 'icon')) . '</td>';
                     } else {
                         if (!$unit->canedit) {
                             //show greyed out icons and no URL
                             $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/clock_edit_bw.png', 'class' => 'icon')) . ' ' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/clock_delete_bw.png', 'class' => 'icon')) . '</td>';
                         } else {
                             $deleteurl = new moodle_url($baseurl . '/deleteworkunit.php', $urlparams);
                             $deleteicon = new pix_icon('clock_delete', get_string('delete'), 'block_timetracker');
                             $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action('Are you sure you want to delete this work unit?'));
                             //error_log (($now - $unit->timein)-(86400*35));
                             $editurl = new moodle_url($baseurl . '/editunit.php', $urlparams);
                             $editurl->remove_params('sesskey');
                             $editaction = $OUTPUT->action_icon($editurl, new pix_icon('clock_edit', get_string('edit'), 'block_timetracker'));
                             $row .= '<td style="text-align: center">';
                             if ($canmanage) {
                                 $row .= $editaction . ' ' . $deleteaction . '</td>';
                             } else {
                                 $row .= '&nbsp;';
                             }
                             $row .= '</td>';
                         }
                     }
                 }
             } else {
                 $urlparams['id'] = $this->courseid;
                 $urlparams['userid'] = $unit->userid;
                 $urlparams['sesskey'] = sesskey();
                 $urlparams['unitid'] = $unit->id;
                 $unitdateinfo = usergetdate($unit->timein);
                 if ($unit->timesheetid && !$unit->submitted) {
                     //show greyed out icons and no URL
                     $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/wait.png', 'class' => 'icon')) . '</td>';
                 } else {
                     if ($unit->timesheetid && $unit->submitted) {
                         $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/certified.png', 'class' => 'icon')) . '</td>';
                     } else {
                         if (!$unit->canedit) {
                             //show greyed out icons and no URL
                             $alertaction = html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/alert_bw.gif', 'class' => 'icon'));
                         } else {
                             $alerturl = new moodle_url($baseurl . '/alert.php', $urlparams);
                             $alerticon = new pix_icon('alert', 'Alert Supervisor of Error', 'block_timetracker');
                             $alertaction = $OUTPUT->action_icon($alerturl, $alerticon);
                             $row .= '<td style="text-align:center">' . $alertaction . '</td>';
                         }
                     }
                 }
             }
             $row .= '</tr>';
             $mform->addElement('html', $row);
         }
         $finalrow = '<tr>';
         if ($canmanage) {
             $finalrow .= '<td>&nbsp;</td>';
         }
         $finalrow .= '<td>&nbsp;</td>
                 <td>&nbsp;</td>
                 <td style="text-align: center; border-top: 1px solid black"><b>Total: 
                 </b>' . round($total, 3) . ' hour(s)</td>
                 <td>&nbsp;</td></tr></table>';
         $mform->addElement('html', $finalrow);
     }
 }
Example #4
0
if ($streak > 0) {
    if ($count % 4 == 1) {
        echo "<tr>";
    }
    echo "<td> <img src='img/badges/70h_streak.jpg'  title='This is no sense! You are working 70hrs streak until now, thank you so much!'></td>";
    $badges = true;
    $count++;
    if ($count % 4 == 0) {
        echo "</tr>";
        $count++;
    }
}
/* 90H STREAK */
$streak = 0;
while ($yearweek >= $yearweek_min) {
    $result = get_hours($conn, $user_id, $yearweek);
    while ($row = mysqli_fetch_assoc($result)) {
        if ($row["hours"] > 90) {
            $streak++;
        }
    }
    if ($row["hours"] <= 90) {
        break;
    }
    $yearweek--;
}
if ($streak > 0) {
    if ($count % 4 == 1) {
        echo "<tr>";
    }
    echo "<td> <img src='img/badges/90h_streak.jpg'  title='You are unstoppable! You are working 90hrs streak until now, thank you so much!'></td>";
Example #5
0
/**
* @return hours (in decimal) for the current term
*
*/
function get_hours_this_term($userid, $courseid = -1)
{
    $boundaries = get_term_boundaries($courseid);
    $units = get_split_units($boundaries['termstart'], $boundaries['termend'], $userid, $courseid);
    if (!$units) {
        return 0;
    }
    $round = get_rounding_config($courseid);
    $total = 0;
    foreach ($units as $unit) {
        $total += round_time($unit->timeout - $unit->timein, $round);
    }
    return get_hours($total, $courseid);
}
function generate_xls($month, $year, $userid, $courseid, $method = 'I', $base = '')
{
    global $CFG, $DB;
    $monthinfo = get_month_info($month, $year);
    $workerrecord = $DB->get_record('block_timetracker_workerinfo', array('id' => $userid, 'courseid' => $courseid));
    if (!$workerrecord) {
        print_error('usernotexist', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $courseid);
    }
    //TODO -- change this to a filename, comment out 'send' function
    $fn = $year . '_' . ($month < 10 ? '0' . $month : $month) . 'Timesheet_' . substr($workerrecord->firstname, 0, 1) . $workerrecord->lastname . '_' . $workerrecord->mdluserid . '.xls';
    if ($method == 'F') {
        $workbook = new MoodleExcelWorkbook($base . '/' . $fn);
    } else {
        $workbook = new MoodleExcelWorkbook('-');
        $workbook->send($fn);
    }
    // Formatting
    $format_bold =& $workbook->add_format();
    $format_bold->set_bold();
    $format_cal_block =& $workbook->add_format();
    $format_cal_block->set_left(1);
    $format_cal_block->set_right(1);
    $format_cal_block->set_bottom(1);
    $format_cal_block->set_text_wrap();
    $format_cal_block->set_v_align('Top');
    $format_cal_block->set_size(8);
    $format_cal_total =& $workbook->add_format();
    $format_cal_total->set_align('center');
    $format_cal_total->set_bold();
    $format_cal_total->set_size(12);
    $format_cal_total->set_left(1);
    $format_cal_total->set_right(1);
    $format_cal_total->set_bottom(1);
    $format_calendar_dates =& $workbook->add_format();
    $format_calendar_dates->set_bold();
    $format_calendar_dates->set_align('center');
    $format_calendar_dates->set_size(8);
    $format_calendar_dates->set_left(1);
    $format_calendar_dates->set_right(1);
    $format_calendar_days =& $workbook->add_format();
    $format_calendar_days->set_bold();
    $format_calendar_days->set_align('center');
    $format_calendar_days->set_size(8);
    $format_calendar_days->set_fg_color(22);
    $format_calendar_days->set_border(1);
    $format_center =& $workbook->add_format();
    $format_center->set_align('center');
    $format_footer =& $workbook->add_format();
    $format_footer->set_bold();
    $format_footer->set_bottom(1);
    $format_footer->set_v_align('Top');
    $format_footer->set_text_wrap();
    $format_footer_block =& $workbook->add_format();
    $format_footer_block->set_bottom(1);
    $format_footer_block->set_top(1);
    $format_footer_block->set_left(1);
    $format_footer_block->set_right(1);
    $format_timesheet_header =& $workbook->add_format();
    $format_timesheet_header->set_bold();
    $format_timesheet_header->set_align('center');
    $format_timesheet_header->set_size(12);
    $format_timesheet_header->set_bottom(1);
    $format_title =& $workbook->add_format();
    $format_title->set_bold();
    $format_title->set_align('center');
    $format_title->set_size(12);
    $format_week_header =& $workbook->add_format();
    $format_week_header->set_bold();
    $format_week_header->set_align('center');
    $format_week_header->set_size(8);
    // Collect Data
    $mdluser = $DB->get_record('user', array('id' => $workerrecord->mdluserid));
    $conf = get_timetracker_config($courseid);
    $worksheet = array();
    $worksheet[1] =& $workbook->add_worksheet('First worksheet');
    // Set column widths
    $worksheet[1]->set_column(0, 8, 10.57);
    // Write data to spreadsheet
    $worksheet[1]->write_string(0, 0, 'Mars Hill College', $format_title);
    $worksheet[1]->merge_cells(0, 0, 0, 7);
    $worksheet[1]->write_string(1, 0, 'Timesheet - ' . $monthinfo['monthname'] . ', ' . $year, $format_timesheet_header);
    $worksheet[1]->merge_cells(1, 0, 1, 7);
    // Creates separator line under 'Timesheet'
    foreach (range(1, 7) as $i) {
        $worksheet[1]->write_blank(1, $i, $format_timesheet_header);
    }
    // Header Data
    $worksheet[1]->write_string(2, 0, 'WORKER: ' . strtoupper($workerrecord->lastname) . ', ' . strtoupper($workerrecord->firstname), $format_bold);
    $worksheet[1]->merge_cells(2, 0, 2, 3);
    $worksheet[1]->write_string(3, 0, "ID: {$mdluser->username}", $format_bold);
    $worksheet[1]->merge_cells(3, 0, 3, 3);
    $worksheet[1]->write_string(4, 0, "ADDRESS: {$workerrecord->address}", $format_bold);
    $worksheet[1]->merge_cells(4, 0, 4, 3);
    $worksheet[1]->write_string(5, 0, 'YTD Earnings: $' . number_format(get_earnings_this_year($userid, $courseid), 2), $format_bold);
    $worksheet[1]->merge_cells(5, 0, 5, 3);
    $worksheet[1]->write_string(2, 4, 'SUPERVISOR: ' . $conf['supname'], $format_bold);
    $worksheet[1]->merge_cells(2, 4, 2, 7);
    $worksheet[1]->write_string(3, 4, 'DEPARTMENT: ' . $conf['department'], $format_bold);
    $worksheet[1]->merge_cells(3, 4, 3, 7);
    $worksheet[1]->write_string(4, 4, 'POSITION: ' . $conf['position'], $format_bold);
    $worksheet[1]->merge_cells(4, 4, 4, 7);
    $worksheet[1]->write_string(5, 4, 'BUDGET: ' . $conf['budget'], $format_bold);
    $worksheet[1]->merge_cells(5, 4, 5, 7);
    // Calendar Data
    $worksheet[1]->write_string(7, 0, 'Sunday', $format_calendar_days);
    $worksheet[1]->write_string(7, 1, 'Monday', $format_calendar_days);
    $worksheet[1]->write_string(7, 2, 'Tuesday', $format_calendar_days);
    $worksheet[1]->write_string(7, 3, 'Wednesday', $format_calendar_days);
    $worksheet[1]->write_string(7, 4, 'Thursday', $format_calendar_days);
    $worksheet[1]->write_string(7, 5, 'Friday', $format_calendar_days);
    $worksheet[1]->write_string(7, 6, 'Saturday', $format_calendar_days);
    $worksheet[1]->write_string(7, 7, 'Total Hours', $format_calendar_days);
    $worksheet[1]->set_row(9, 69);
    $worksheet[1]->set_row(11, 69);
    $worksheet[1]->set_row(13, 69);
    $worksheet[1]->set_row(15, 69);
    $worksheet[1]->set_row(17, 69);
    $worksheet[1]->set_row(19, 69);
    $worksheet[1]->set_row(8, 11.25);
    $worksheet[1]->set_row(10, 11.25);
    $worksheet[1]->set_row(12, 11.25);
    $worksheet[1]->set_row(14, 11.25);
    $worksheet[1]->set_row(16, 11.25);
    $worksheet[1]->set_row(18, 11.25);
    foreach (range(0, 7) as $i) {
        $worksheet[1]->write_blank(8, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(9, $i, $format_cal_block);
        $worksheet[1]->write_blank(10, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(11, $i, $format_cal_block);
        $worksheet[1]->write_blank(12, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(13, $i, $format_cal_block);
        $worksheet[1]->write_blank(14, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(15, $i, $format_cal_block);
        $worksheet[1]->write_blank(16, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(17, $i, $format_cal_block);
        $worksheet[1]->write_blank(18, $i, $format_calendar_dates);
        $worksheet[1]->write_blank(19, $i, $format_cal_block);
    }
    // Footer
    foreach (range(0, 7) as $i) {
        $worksheet[1]->write_blank(20, $i, $format_footer_block);
        $worksheet[1]->write_blank(21, $i, $format_footer_block);
    }
    // Number the Days and add data
    $units = get_split_month_work_units($workerrecord->id, $courseid, $month, $year);
    $date = 1;
    $dayofweek = $monthinfo['dayofweek'];
    $weeksum = 0;
    $monthsum = 0;
    for ($currentrow = 8; $currentrow < 20; $currentrow += 2) {
        //echo "inside for loop <br />";
        $dayofweek = $dayofweek % 7;
        do {
            $worksheet[1]->write_string($currentrow, $dayofweek, $date, $format_calendar_dates);
            //begin of print work units
            // Print the data in the correct date blocks
            $wustr = "";
            $mid = 86400 * ($date - 1) + $monthinfo['firstdaytimestamp'];
            $eod = 86400 * ($date - 1) + ($monthinfo['firstdaytimestamp'] + 86399);
            if ($units) {
                foreach ($units as $unit) {
                    if ($unit->timein < $eod && $unit->timein >= $mid) {
                        $in = userdate($unit->timein, get_string('timeformat', 'block_timetracker'));
                        $out = userdate($unit->timeout, get_string('timeformat', 'block_timetracker'));
                        if ($unit->timeout - $unit->timein > 449) {
                            $wustr .= "In: {$in}\nOut: {$out}\n";
                            $weeksum += get_hours($unit->timeout - $unit->timein);
                        }
                    }
                }
            }
            $worksheet[1]->write_string($currentrow + 1, $dayofweek, $wustr, $format_cal_block);
            //end of print work units
            //if day of week = 7, copy value over and reset weekly sum to 0.
            // Calculate total hours
            if ($dayofweek == 6 || $date == $monthinfo['lastday']) {
                //Add week sum to monthly sum
                //Print value in weekly totals column
                //clear weekly sum
                $monthsum = $monthsum + $weeksum;
                $worksheet[1]->write_string($currentrow + 1, 7, $weeksum, $format_cal_total);
                $weeksum = 0;
            }
            $dayofweek++;
            $date++;
        } while ($date <= $monthinfo['lastday'] && $dayofweek % 7 != 0);
        if ($date >= $monthinfo['lastday']) {
            break;
        }
    }
    // Write footer data
    $worksheet[1]->write_string(20, 0, "Pay Rate or Stipend Amount\n" . '$' . number_format($workerrecord->currpayrate, 2), $format_footer);
    $worksheet[1]->merge_cells(20, 0, 20, 3);
    $worksheet[1]->write_string(20, 4, 'Total Hours/Earnings for ' . $monthinfo['monthname'] . ', ' . $year . ":\n" . number_format($monthsum, 2) . ' / $' . $monthsum * $workerrecord->currpayrate, $format_footer);
    $worksheet[1]->merge_cells(20, 4, 20, 7);
    $worksheet[1]->write_string(21, 0, 'Supervisor Signature/Date', $format_footer);
    $worksheet[1]->merge_cells(21, 0, 21, 3);
    $worksheet[1]->write_string(21, 4, 'Worker Signature/Date', $format_footer);
    $worksheet[1]->merge_cells(21, 4, 21, 7);
    $worksheet[1]->set_row(20, 30);
    $worksheet[1]->set_row(21, 42);
    $workbook->close();
    return $fn;
}
/**
    @return an array of HTML pages used for printing - one page per array item
*/
function generate_html($start, $end, $userid, $courseid, $timesheetid = -1, $unsignedonly = false)
{
    global $CFG, $DB;
    $pages = array();
    $startstring = userdate($start, "%m%Y");
    $endstring = userdate($end, "%m%Y");
    $samemonth = $startstring == $endstring;
    $workerrecord = $DB->get_record('block_timetracker_workerinfo', array('id' => $userid));
    if (!$workerrecord) {
        print_error('usernotexist', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $courseid);
    }
    // Collect Data
    $conf = get_timetracker_config($courseid);
    $firstmonth = userdate($start, "%m");
    $firstyear = userdate($start, "%Y");
    $firstmonthinfo = make_timestamp($firstyear, $firstmonth, 1);
    //$curr = $start;
    $curr = $firstmonthinfo;
    $overallhoursum = 0;
    $overalldollarsum = 0;
    while ($curr <= $end) {
        $month = userdate($curr, "%m");
        $year = userdate($curr, "%Y");
        $monthinfo = get_month_info($month, $year);
        $mid = $monthinfo['firstdaytimestamp'];
        $eod = strtotime('+ 1 day', $mid);
        $eod -= 1;
        $monthhoursum = 0;
        $monthdollarsum = 0;
        $units = get_split_month_work_units($workerrecord->id, $courseid, $month, $year, $timesheetid, $unsignedonly);
        // Add Page
        /**DING DING DING**/
        //$pdf->AddPage();
        // ********** HEADER ********** //
        $htmldoc = '
            <table style="margin-left: auto; margin-right: auto" cellspacing="0"' . 'cellpadding="0" width="540px">
            <tr>
                <td align="center"><font size="10"><b>' . $conf['institution'] . '</b></font></td>
            </tr>
            <tr>
                <td align="center"><font size="10"><b>Timesheet - ' . $monthinfo['monthname'] . ', ' . $year . '</b></font>
                </td>
            </tr>
        </table>
        <hr style="height: 1px" />';
        //$pdf->writeHTML($htmldoc, true, false, false, false, '');
        // ********** WORKER AND SUPERVISOR DATA ********** //
        $htmldoc .= '
            <table style="margin-left: auto: margin-right: auto" cellspacing="0"' . 'cellpadding="0" width="540px">
            <tr>
                <td><font size="8.5"><b>WORKER: ' . strtoupper($workerrecord->lastname) . ', ' . strtoupper($workerrecord->firstname) . '<br />' . 'ID: ' . $workerrecord->idnum . '<br />' . 'ADDRESS: ' . $workerrecord->address . '<br />
                YTD Earnings: $ ' . get_earnings_this_year($userid, $courseid) . '</b></font></td>
                <td><font size="8.5"><b>SUPERVISOR: ' . $conf['supname'] . '<br />' . 'DEPARTMENT: ' . $conf['department'] . '<br />' . 'POSITION: ' . $conf['position'] . '<br />' . 'BUDGET: ' . $conf['budget'] . '</b></font></td>
            </tr>
        </table>
        <br />';
        //$pdf->writeHTML($htmldoc, true, false, false, false, '');
        // ********** CALENDAR DAYS HEADER (Sun - Sat) ********** //
        // ********** CALENDAR DATES AND DATA ********** //
        //Arrays for dates and vals;
        $days = array();
        $vals = array();
        $date = 1;
        $dayofweek = $monthinfo['dayofweek'];
        $weeksum = 0;
        $monthhoursum = 0;
        $htmldoc .= '
    
            <table border="1" cellpadding="2px" width="540px" ' . 'style="margin-right: auto; margin-left: auto">
            <tr bgcolor="#C0C0C0">
                <td class="calendar" align="center"><font size="8"><b>Monday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Tuesday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Wednesday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Thursday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Friday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Saturday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Sunday</b></font></td>
                <td class="calendar" align="center"><font size="8"><b>Total Hours</b>' . '</font></td>
            </tr>
        ';
        // ********** START THE TABLE AND DATA ********** //
        //write blank cells to catch up to the first day of the month
        $counter = 1;
        while ($counter != $dayofweek) {
            $counter++;
            $days[] = '<td class="calendar" style="height: 10px">&nbsp;</td>';
            $vals[] = '<td class="calendar" style="height: 70px">&nbsp;</td>';
            $counter %= 7;
        }
        //a "week" - a row in the table
        for ($row = 0; $row < 6; $row++) {
            $dayofweek = $dayofweek % 7;
            do {
                $days[] = '<td class="calendar" style="height: 10px" align="center"><b>' . $date . '</b></td>';
                //begin of print work units
                // Print the data in the correct date blocks
                $wustr = "";
                if ($units) {
                    foreach ($units as $unit) {
                        if ($unit->timein < $eod && $unit->timein >= $mid && $unit->timein >= $start && $unit->timeout <= $end) {
                            $in = userdate($unit->timein, get_string('timeformat', 'block_timetracker'));
                            $out = userdate($unit->timeout, get_string('timeformat', 'block_timetracker'));
                            //FIXMEFIXME!
                            if (array_key_exists('round', $conf) && $conf['round'] > 0) {
                                $factor = $conf['round'] / 2 - 1;
                            } else {
                                $factor = 0;
                            }
                            if ($unit->timeout - $unit->timein > $factor) {
                                //WHAT IF NOT ROUNDED?
                                $wustr .= "In: {$in}<br />Out: {$out}<br />";
                                $hours = get_hours($unit->timeout - $unit->timein, $unit->courseid);
                                //overtime or regular?
                                if ($hours + $weeksum > 40) {
                                    $ovthours = $reghours = 0;
                                    if ($weeksum > 40) {
                                        //already over 40
                                        //no reghours, just ovthours
                                        $ovthours = $hours;
                                    } else {
                                        //not already over 40
                                        $reghours = 40 - $weeksum;
                                        $ovthours = $hours - $reghours;
                                    }
                                    $amt = $reghours * $unit->payrate;
                                    $ovtamt = $ovthours * ($workerrecord->currpayrate * 1.5);
                                    $amt += $ovtamt;
                                } else {
                                    $amt = $hours * $unit->payrate;
                                }
                                $monthdollarsum += $amt;
                                $overalldollarsum += $amt;
                                $weeksum += $hours;
                                $overallhoursum += $hours;
                            }
                        }
                    }
                }
                $vals[] = '<td class="calendar"  style="height: 70px"><font size="7">' . $wustr . '</font></td>';
                //if day of week = 0 (Sunday), copy value over and reset weekly sum to 0.
                // Calculate total hours
                if ($dayofweek == 0) {
                    //Add week sum to monthly sum
                    //Print value in weekly totals column
                    //clear weekly sum
                    $monthhoursum += $weeksum;
                    $days[] = '<td class="calendar" style="height: 10px">&nbsp;</td>';
                    if ($weeksum == 0) {
                        $weeksum = '&nbsp;';
                    }
                    $vals[] = '<td class="calendar" style="height: 70px" align="center">' . '<font size="10"><b><br /><br />' . $weeksum . '</b><br /></font></td>';
                    $weeksum = 0;
                } else {
                    if ($date == $monthinfo['lastday']) {
                        //what about when we reach the end of the month?
                        //Still need to put totals!!!
                        $counter = $dayofweek;
                        while ($counter != 0) {
                            //pad to the rightmost column
                            $days[] = '<td class="calendar" style="height: 10px">&nbsp;</td>';
                            $vals[] = '<td class="calendar" style="height: 70px">&nbsp;</td>';
                            $counter++;
                            $counter %= 7;
                        }
                        $monthhoursum += $weeksum;
                        $days[] = '<td class="calendar" style="height: 10px">&nbsp;</td>';
                        if ($weeksum == 0) {
                            $weeksum = '&nbsp;';
                        }
                        $vals[] = '<td class="calendar" style="height: 70px" align="center">' . '<font size="10"><b><br /><br />' . $weeksum . '</b><br /></font></td>';
                        $weeksum = 0;
                    }
                }
                $mid = strtotime('+ 1 day', $mid);
                //midnight
                $eod = strtotime('+ 1 day', $eod);
                //23:59:59
                $dayofweek++;
                $date++;
                $curr = strtotime('+1 day', $curr);
            } while ($date <= $monthinfo['lastday'] && $dayofweek != 7);
            if ($date >= $monthinfo['lastday']) {
                break;
            }
        }
        //this is a single "row" or "week"
        for ($i = 0; $i < 6; $i++) {
            $htmldoc .= "\n<tr>\n";
            for ($j = 0; $j < 8; $j++) {
                $spot = $j + 8 * $i;
                if (isset($days[$spot])) {
                    $htmldoc .= "\t" . $days[$spot] . "\n";
                } else {
                    $htmldoc .= "\t" . '<td class="calendar" style="height: 10px">&nbsp;</td>' . "\n";
                }
            }
            $htmldoc .= "\n</tr>\n";
            $htmldoc .= "\n<tr>\n";
            for ($j = 0; $j < 8; $j++) {
                $spot = $j + 8 * $i;
                if (isset($vals[$spot])) {
                    $htmldoc .= "\t" . $vals[$spot] . "\n";
                } else {
                    $htmldoc .= "\t" . '<td class="calendar" style="height: 70px">&nbsp;</td>' . "\n";
                }
            }
            $htmldoc .= "\n</tr>\n";
        }
        $htmldoc .= '</table><br />';
        //$pdf->writeHTML($htmldoc, true, false, false, false, '');
        // ********** FOOTER TOTALS ********** //
        $htmldoc .= '
            <table border="1" cellpadding="5px" width="540px" ' . 'style="margin-left: auto; margin-right: auto">
        <tr>
            <td style="height: 25px"><font size="13"><b>Base Pay Rate</b></font>
            <br />
                <font size="10">$' . round($workerrecord->currpayrate, 2) . '</font></td>
            <td style="height: 20px"><font size="13"><b>Total Hours/Earnings for ' . $monthinfo['monthname'] . ', ' . $year . '</b></font><br /><font size="10">' . round($monthhoursum, 3) . ' / $' . round($monthdollarsum, 2) . '</font></td>
        </tr></table><br />';
        //$pdf->writeHTML($htmldoc, true, false, false, false, '');
        //here is a new page!!!
        $pages[] = $htmldoc;
    }
    end($pages);
    $key = key($pages);
    $htmldoc = $pages[$key];
    // ********** OVERALL TOTALS AND SIGNATURES********** //
    if ($timesheetid != -1) {
        $ts = $DB->get_record('block_timetracker_timesheet', array('id' => $timesheetid));
    }
    $htmldoc .= '
        <table border="1" cellpadding="5px" width="540px" ' . 'style="margin-left: auto; margin-right: auto">';
    if (!$samemonth) {
        $desc = '';
        if ($timesheetid == -1) {
            $desc = userdate($start, get_string('dateformat', 'block_timetracker')) . ' to ' . userdate($end, get_string('dateformat', 'block_timetracker'));
        }
        $htmldoc .= '
        <tr>
        <td colspan="2" style="height: 35px"><font size="13"><b>Total Hours/Earnings  ' . $desc . '</b></font><br /><font size="10">' . round($overallhoursum, 3) . ' / $' . round($overalldollarsum, 2) . '</font></td>
        </tr>';
    }
    if ($timesheetid != -1) {
        $datestr = get_string('datetimeformat', 'block_timetracker');
        $htmldoc .= '
        <tr>
            <td style="height: 45px"><font size="13"><b>Worker Signature/Date</b></font>' . '<br />' . '<font size="8">Signed by ' . $workerrecord->firstname . ' ' . $workerrecord->lastname . '<br />' . userdate($ts->workersignature, $datestr) . '</font></td>' . '<td style="height: 45px"><font size="13"><b>Supervisor Signature/Date</b>' . '</font><br />' . '<font size="8">';
        if ($ts->supervisorsignature != 0) {
            $super = $DB->get_record('user', array('id' => $ts->supermdlid));
            if (!$super) {
                print_error('Supervisor does not exist');
            }
            $htmldoc .= 'Signed by ' . $super->firstname . ' ' . $super->lastname . '<br />' . userdate($ts->supervisorsignature, $datestr);
        } else {
            $htmldoc .= 'Awaiting supervisor signature';
        }
        $htmldoc .= '
            </font></td>
        </tr>
        </table><br />';
    } else {
        /*
        $htmldoc .='
        
        <tr>
            <td style="height: 45px"><font size="13"><b>Worker Signature/Date</b></font></td>
            <td style="height: 45px"><font size="13"><b>Supervisor Signature/Date</b></font></td>
        </tr>
        */
        $htmldoc .= ' </table><br />';
    }
    $pages[$key] = $htmldoc;
    return $pages;
}