/** * Generate the alert links for a course * @param $courseid id of the course * @param $alerticon create the alert icon (using new pix_icon) * @param $alertaction create the action of the alert (usually $OUTPUT->action_icon($alertsurl,$alertaction) * @return hyperlink with number of existing alerts * Example: Manage Alerts (3) */ function get_alerts_link($courseid, $alerticon, $alertaction) { global $CFG, $DB; //getnumalerts from $courseid $numalerts = ''; $n = has_course_alerts($courseid); if ($n > 0) { $numalerts = '(' . $n . ')'; } $urlparams['id'] = $courseid; $baseurl = $CFG->wwwroot . '/blocks/timetracker'; $url = new moodle_url($baseurl . '/managealerts.php', $urlparams); $text = $alertaction . ' <a href="' . $url . 'style="color: red">Manage Alerts ' . $numalerts . '</a><br />'; return $text; }
function get_content() { global $CFG, $DB, $USER, $OUTPUT, $COURSE; //$this->config = get_timetracker_config($COURSE->id); $clockin = optional_param('clockin', 0, PARAM_INTEGER); $clockout = optional_param('clockout', 0, PARAM_INTEGER); $courseid = $COURSE->id; $worker = $DB->get_record('block_timetracker_workerinfo', array('mdluserid' => $USER->id, 'courseid' => $COURSE->id)); if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); //echo $this->config->block_timetracker_default_max_earnings; if (!isset($this->config)) { if (has_capability('block/timetracker:manageworkers', $this->context)) { $this->content->text = 'TimeTracker block must be configured before used.'; } else { $this->content->text = '<span style="color: red"> TimeTracker is not yet configured. Contact your supervisor with this error</span>'; } return $this->content; } $baseurl = $CFG->wwwroot . '/blocks/timetracker'; $canmanage = false; if (has_capability('block/timetracker:manageworkers', $this->context)) { $canmanage = true; } $canview = false; if (has_capability('block/timetracker:viewonly', $this->context)) { $canview = true; } if ($canmanage || $canview) { //if config is setup to show term hours/earnings AND //terms are not configured, provide a link to the terms page. if ($this->config->block_timetracker_show_term_hours == 1 || $this->config->block_timetracker_show_term_earnings == 1) { $numterms = $DB->count_records('block_timetracker_term', array('courseid' => $COURSE->id)); if ($numterms == 0) { $this->content->text .= '<b><center><a style="color: red" href="' . $CFG->wwwroot . '/blocks/timetracker/terms.php?id=' . $COURSE->id . '">**Configure terms**</center></b></a>'; $this->content->text .= "<br /><br />"; } } $hasalerts = has_course_alerts($COURSE->id); if (has_capability('moodle/site:config', $this->context)) { $hasalerts = has_course_alerts($COURSE->id); } $indexparams['id'] = $courseid; $this->content->text .= '<div style="text-align: left">'; //check to see if the supervisor needs to manage if ($hasalerts && $canmanage) { $alertsurl = new moodle_url($baseurl . '/managealerts.php', $indexparams); $alerticon = new pix_icon('alert', 'Manage Alerts', 'block_timetracker'); $alertaction = $OUTPUT->action_icon($alertsurl, $alerticon); $this->content->text .= get_alerts_link($COURSE->id, $alerticon, $alertaction); } $hastimesheets = has_unsigned_timesheets($COURSE->id); if (has_capability('moodle/site:config', $this->context)) { $hastimesheets = has_unsigned_timesheets($COURSE->id); } if ($hastimesheets && $canmanage) { $timesheetsurl = new moodle_url($baseurl . '/supervisorsig.php', $indexparams); $timesheetsicon = new pix_icon('alert', 'Sign Timesheets', 'block_timetracker'); $timesheetsaction = $OUTPUT->action_icon($timesheetsurl, $timesheetsicon); $this->content->text .= get_timesheet_link($COURSE->id, $timesheetsicon, $timesheetsaction); } $index = new moodle_url($baseurl . '/index.php', $indexparams); $timeclockdataicon = new pix_icon('manage', 'Manage', 'block_timetracker'); $timeclockdataaction = $OUTPUT->action_icon($index, $timeclockdataicon); $this->content->text .= $timeclockdataaction . ' ' . $OUTPUT->action_link($index, 'Main') . '<br />'; $reportsurl = new moodle_url($baseurl . '/reports.php', $indexparams); $reportsaction = $OUTPUT->action_icon($reportsurl, new pix_icon('report', 'Reports', 'block_timetracker')); $this->content->text .= $reportsaction . ' ' . $OUTPUT->action_link($reportsurl, 'Reports') . '<br />'; $timesheeturl = new moodle_url($baseurl . '/timesheet.php', $indexparams); $timesheetaction = $OUTPUT->action_icon($timesheeturl, new pix_icon('date', 'Timesheets', 'block_timetracker')); $this->content->text .= $timesheetaction . ' ' . $OUTPUT->action_link($timesheeturl, 'Timesheet') . '<br />'; $manageurl = new moodle_url($baseurl . '/manageworkers.php', array('id' => $COURSE->id)); $manageaction = $OUTPUT->action_icon($manageurl, new pix_icon('user_group', 'Manage workers', 'block_timetracker')); $this->content->text .= $manageaction . ' ' . $OUTPUT->action_link($manageurl, 'Manage workers') . '<br />'; $numtimeclock = $DB->count_records('block_timetracker_workerinfo', array('courseid' => $courseid, 'timetrackermethod' => 0)); if ($numtimeclock > 0) { //show anyone who has a pending: $pendingunits = $DB->get_records('block_timetracker_pending', array('courseid' => $courseid)); $this->content->text .= "<br />Currently Clocked In:"; $this->content->text .= '<ul>'; if (!$pendingunits) { $this->content->text .= '<li>None</li>'; } else { $workers = $DB->get_records('block_timetracker_workerinfo'); foreach ($pendingunits as $pending) { $this->content->text .= '<li><a href="' . $CFG->wwwroot . '/blocks/timetracker/reports.php?id=' . $courseid . '&userid=' . $pending->userid . '">' . $workers[$pending->userid]->lastname . ', ' . $workers[$pending->userid]->firstname . ' ' . '</a>' . userdate($pending->timein, get_string('timeformat', 'block_timetracker')) . '</li>' . "\n"; } } } $this->content->text .= '</ul>'; } else { //worker //Worker doesn't exist yet, or has missing data if (!$worker) { // || ($worker->address=='0')){ //print_object($worker); $link = '/blocks/timetracker/updateworkerinfo.php?id=' . $COURSE->id . '&userid=' . $worker->id; $action = null; $this->content->text = '<center>'; $this->content->text .= '<span style="color: red">' . $OUTPUT->action_link($link, get_string('registerinfo', 'block_timetracker'), $action); $this->content->text .= '</span></center>'; return $this->content; } else { /* if($worker->active == 0){ $this->content->text = get_string('notactiveerror','block_timetracker'); return $this->content; } */ // Implement Icons - Timeclock Method if ($worker->timetrackermethod == 0) { $ttuserid = $worker->id; $pendingrecord = $DB->get_record('block_timetracker_pending', array('userid' => $ttuserid, 'courseid' => $courseid)); $urlparams['userid'] = $ttuserid; $urlparams['id'] = $courseid; $indexparams['userid'] = $ttuserid; $indexparams['id'] = $courseid; $index = new moodle_url($baseurl . '/index.php', $indexparams); if (!$pendingrecord) { $urlparams['clockin'] = 1; $timeclockurl = new moodle_url($baseurl . '/timeclock.php', $urlparams); $timeclockicon = new pix_icon('clock_play', 'Clock in', 'block_timetracker'); $timeclockdesc = ' Clock-in'; } else { $urlparams['clockout'] = 1; $urlparams['ispending'] = true; $urlparams['unitid'] = $pendingrecord->id; $timeclockurl = new moodle_url($CFG->wwwroot . '/blocks/timetracker/timeclock.php', $urlparams); $timeclockicon = new pix_icon('clock_stop', 'Clock in', 'block_timetracker'); $timeclockdesc = ' Clock-out'; $alertlink = new moodle_url($baseurl . '/alert.php', $urlparams); $alerticon = new pix_icon('alert', 'Alert Supervisor of Error', 'block_timetracker'); $alertaction = $OUTPUT->action_icon($alertlink, $alerticon); } //Icons $timeclockaction = $OUTPUT->action_icon($timeclockurl, $timeclockicon); $timeclockdataicon = new pix_icon('manage', 'Manage', 'block_timetracker'); $timeclockdataaction = $OUTPUT->action_icon($index, $timeclockdataicon); $editurl = new moodle_url($baseurl . '/updateworkerinfo.php', $indexparams); $editurl->params(array('mdluserid' => $USER->id)); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('user_edit', get_string('edit'), 'block_timetracker')); $reportsurl = new moodle_url($baseurl . '/reports.php', $indexparams); $reportsurl->params(array('userid' => $worker->id)); $reportsaction = $OUTPUT->action_icon($reportsurl, new pix_icon('report', 'Reports', 'block_timetracker')); $timesheeturl = new moodle_url($baseurl . '/timesheet.php', $indexparams); $timesheeturl->params(array('userid' => $worker->id)); $timesheetaction = $OUTPUT->action_icon($reportsurl, new pix_icon('date', 'Timesheets', 'block_timetracker')); $this->content->text .= '<div style="text-align: left">'; $this->content->text .= $timeclockdataaction . ' <a href="' . $index . '">Main</a><br />' . $timeclockaction . ' <a href="' . $timeclockurl . '">' . $timeclockdesc . '</a><br />' . $reportsaction . ' <a href="' . $reportsurl . '">Reports</a><br />' . $timesheetaction . ' <a href="' . $timesheeturl . '">Timesheets</a><br />' . $editaction . ' <a href="' . $editurl . '"> Edit my info</a><br /><br />'; $this->content->text .= '</div>'; if ($pendingrecord) { $pendingtimestamp = $DB->get_record('block_timetracker_pending', array('userid' => $ttuserid, 'courseid' => $courseid)); $this->content->text .= 'Clock-in:<br />' . $alertaction . ' ' . userdate($pendingtimestamp->timein, get_string('datetimeformat', 'block_timetracker')) . '<br />'; } $this->content->text .= '<hr>'; } else { if ($worker->timetrackermethod == 1) { //Hourlog Method $ttuserid = $worker->id; $urlparams['userid'] = $ttuserid; $urlparams['id'] = $courseid; $indexparams['userid'] = $ttuserid; $indexparams['id'] = $courseid; $hourlogurl = new moodle_url($CFG->wwwroot . '/blocks/timetracker/hourlog.php', $urlparams); $index = new moodle_url($CFG->wwwroot . '/blocks/timetracker/index.php', $indexparams); // Clock In Icon $this->content->text .= '<div style="text-align: left">'; $clockinicon = new pix_icon('clock_add', 'Add work unit', 'block_timetracker'); $clockinaction = $OUTPUT->action_icon($hourlogurl, $clockinicon); $timeclockdataicon = new pix_icon('manage', 'Manage', 'block_timetracker'); $timeclockdataaction = $OUTPUT->action_icon($index, $timeclockdataicon); $reportsurl = new moodle_url($baseurl . '/reports.php', $indexparams); $reportsurl->params(array('userid' => $worker->id)); $reportsaction = $OUTPUT->action_icon($reportsurl, new pix_icon('report', 'Reports', 'block_timetracker')); $editurl = new moodle_url($baseurl . '/updateworkerinfo.php', $indexparams); $editurl->params(array('mdluserid' => $USER->id)); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('user_edit', get_string('edit'), 'block_timetracker')); $timesheeturl = new moodle_url($baseurl . '/timesheet.php', $indexparams); $timesheeturl->params(array('userid' => $worker->id)); $timesheetaction = $OUTPUT->action_icon($reportsurl, new pix_icon('date', 'Timesheets', 'block_timetracker')); $this->content->text .= '<div style="text-align: left">'; $this->content->text .= $timeclockdataaction . ' <a href="' . $index . '">Main</a><br />' . $clockinaction . ' <a href="' . $hourlogurl . '">Add work unit</a><br />' . $reportsaction . ' <a href="' . $reportsurl . '">Reports</a><br />' . $timesheetaction . ' <a href="' . $timesheeturl . '">Timesheets</a><br />' . $editaction . ' <a href="' . $editurl . '"> Edit my info</a><br /><br />'; $this->content->text .= '</div>'; $this->content->text .= '<hr>'; } } $stats = get_worker_stats($ttuserid, $COURSE->id); //calculate if this user is within $50 of reaching maxtermearnings $closetomax = false; if ($worker->maxtermearnings > 0 && ($stats['termearnings'] > $worker->maxtermearnings || $worker->maxtermearnings - $stats['termearnings'] <= 50)) { $closetomax = true; } $this->content->text .= '<br /><span style="font-weight: bold;">' . '*Official term earnings: $' . number_format(get_official_earnings_this_term($ttuserid, $COURSE->id), 2) . '</span><br /><br />'; $this->content->text .= '<span style="font-size: x-small">*This represents hours for which you have already been paid</span>'; $this->content->text .= '<hr />'; if ($this->config->block_timetracker_show_month_hours || $this->config->block_timetracker_show_term_hours || $this->config->block_timetracker_show_ytd_hours || $this->config->block_timetracker_show_total_hours) { $this->content->text .= '<span style="font-weight: bold">' . get_string('hourstitle', 'block_timetracker') . '</span>'; if ($this->config->block_timetracker_show_month_hours) { $this->content->text .= '<br />'; $this->content->text .= get_string('totalmonth', 'block_timetracker'); $this->content->text .= $stats['monthhours']; } if ($this->config->block_timetracker_show_term_hours && $worker->maxtermearnings > 0) { $this->content->text .= '<br />'; if ($closetomax) { $this->content->text .= '<span style="color: red; font-weight:bold">'; } $this->content->text .= get_string('totalterm', 'block_timetracker'); $this->content->text .= $stats['termhours']; $remearnings = $worker->maxtermearnings - $stats['termearnings']; $remhours = $remearnings / $worker->currpayrate; if ($remhours < 0) { $remhours = 0; } $this->content->text .= '<br />'; $this->content->text .= get_string('remaining', 'block_timetracker'); $this->content->text .= round($remhours, 2); if ($closetomax) { $this->content->text .= '</span>'; } } if ($this->config->block_timetracker_show_ytd_hours) { $this->content->text .= '<br />'; $this->content->text .= get_string('totalytd', 'block_timetracker'); $this->content->text .= $stats['yearhours']; } if ($this->config->block_timetracker_show_total_hours) { $this->content->text .= '<br />'; $this->content->text .= get_string('total', 'block_timetracker'); $this->content->text .= $stats['totalhours']; } if ($this->config->block_timetracker_show_month_earnings || $this->config->block_timetracker_show_term_earnings || $this->config->block_timetracker_show_ytd_earnings || $this->config->block_timetracker_show_total_earnings) { $this->content->text .= '<br /><br />'; $this->content->text .= '<span style="font-weight: bold">' . get_string('earningstitle', 'block_timetracker') . '</span>'; if ($this->config->block_timetracker_show_month_earnings) { $this->content->text .= '<br />'; $this->content->text .= get_string('totalmonth', 'block_timetracker'); $this->content->text .= '$' . $stats['monthearnings']; } if ($this->config->block_timetracker_show_term_earnings && $worker->maxtermearnings > 0) { $this->content->text .= '<br />'; if ($closetomax) { $this->content->text .= '<span style="color: red; font-weight:bold">'; } $this->content->text .= get_string('totalterm', 'block_timetracker'); $this->content->text .= '$' . $stats['termearnings']; $remearnings = $worker->maxtermearnings - $stats['termearnings']; if ($remearnings < 0) { $remearnings = 0; } $this->content->text .= '<br />'; $this->content->text .= get_string('remaining', 'block_timetracker'); $this->content->text .= '$' . round($remearnings, 2); if ($closetomax) { $this->content->text .= '</span>'; } } if ($this->config->block_timetracker_show_ytd_earnings) { $this->content->text .= '<br />'; $this->content->text .= get_string('totalytd', 'block_timetracker'); $this->content->text .= '$' . $stats['yearearnings']; } if ($this->config->block_timetracker_show_total_earnings) { $this->content->text .= '<br />'; $this->content->text .= get_string('total', 'block_timetracker'); $this->content->text .= '$' . $stats['totalearnings']; } } $ttuserid = $worker->id; if ($clockin == 1) { //protect against refreshing a 'clockin' screen $pendingrecord = $DB->record_exists('block_timetracker_pending', array('userid' => $ttuserid, 'courseid' => $courseid)); if (!$pendingrecord) { $cin = new stdClass(); $cin->userid = $ttuserid; $cin->timein = time(); $cin->courseid = $courseid; $DB->insert_record('block_timetracker_pending', $cin); } } else { if ($clockout == 1) { $cin = $DB->get_record('block_timetracker_pending', array('userid' => $ttuserid, 'courseid' => $courseid)); if ($cin) { $cin->timeout = time(); $cin->lastedited = time(); $cin->lasteditedby = $USER->id; unset($cin->id); $worked = add_unit($cin); if ($worked) { $DB->delete_records('block_timetracker_pending', array('userid' => $ttuserid, 'courseid' => $courseid)); } else { print_error('couldnotclockout', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/timeclock.php?id=' . $courseid . '&userid=' . $ttuserid); } } } } } } } $this->content->text .= '</div>'; return $this->content; }
function definition() { global $CFG, $USER, $DB, $COURSE, $OUTPUT; $mform =& $this->_form; // Don't forget the underscore! $canmanage = false; if (has_capability('block/timetracker:manageworkers', $this->context)) { $canmanage = true; } $canview = false; if (has_capability('block/timetracker:viewonly', $this->context)) { $canview = true; } if ($canview && !$canmanage) { $urlparams['id'] = $COURSE->id; $nextpage = new moodle_url($CFG->wwwroot . '/blocks/timetracker/index.php', $urlparams); redirect($nextpage, 'You do not have permission to view alerts for this course. <br /> Redirecting you now.', 2); } $mform->addElement('header', 'general', get_string('managealerts', 'block_timetracker')); $mform->addHelpButton('general', 'managealerts', 'block_timetracker'); $strname = get_string('workername', 'block_timetracker'); $strprev = get_string('previous', 'block_timetracker'); $strproposed = get_string('proposed', 'block_timetracker'); $strmsg = get_string('message', 'block_timetracker'); if (!has_course_alerts($COURSE->id)) { $mform->addElement('html', '<div style="text-align:center">'); $mform->addElement('html', get_string('noalerts', 'block_timetracker')); $mform->addElement('html', '</div>'); return; } else { $mform->addElement('html', '<table align="center" border="1" cellspacing="10px" ' . 'cellpadding="5px" width="95%">'); $tblheaders = '<tr> <td><span style="font-weight: bold">' . $strname . '</span></td> <td><span style="font-weight: bold">' . $strprev . '</span></td> <td><span style="font-weight: bold">' . $strproposed . '</span></td> <td><span style="font-weight: bold">' . $strmsg . '</span></td>'; if ($canmanage) { $tblheaders .= '<td style="text-align: center">' . '<span style="font-weight: bold">' . get_string('action') . '</span></td>'; } $tblheaders .= '</tr>'; $mform->addElement('html', $tblheaders); $alertlinks = get_course_alert_links($COURSE->id); //print_object($alertlinks); if ($canmanage) { $alerts = $DB->get_records('block_timetracker_alertunits', array('courseid' => $COURSE->id), 'alerttime'); } else { $ttuserid = $DB->get_field('block_timetracker_workerinfo', 'id', array('mdluserid' => $USER->id, 'courseid' => $COURSE->id)); if (!$ttuserid) { print_error('Error obtaining mdluserid from workerinfo for ' . $USER->id); } $alerts = $DB->get_records('block_timetracker_alertunits', array('courseid' => $COURSE->id, 'userid' => $ttuserid)); } } foreach ($alerts as $alert) { $worker = $DB->get_record('block_timetracker_workerinfo', array('id' => $alert->userid)); $mform->addElement('html', '<tr>'); $row = '<td>' . $worker->lastname . ', ' . $worker->firstname . '<br />Submitted: ' . userdate($alert->alerttime, get_string('datetimeformat', 'block_timetracker')) . '</td>'; $row .= '<td>In: ' . userdate($alert->origtimein, get_string('datetimeformat', 'block_timetracker')); if ($alert->origtimeout > 0) { $row .= '<br />Out: ' . userdate($alert->origtimeout, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />Elapsed: ' . format_elapsed_time($alert->origtimeout - $alert->origtimein, $alert->courseid); } else { $row .= ''; } $row .= '</td>'; if ($alert->todelete == 0) { $row .= '<td>In: ' . userdate($alert->timein, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />Out: ' . userdate($alert->timeout, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />Elapsed: ' . format_elapsed_time($alert->timeout - $alert->timein, $alert->courseid); $row .= '</td>'; } else { $row .= '<td><span style="color: red">User requests removal</span></td>'; } $row .= '<td>' . nl2br($alert->message) . '</td>'; if ($canmanage) { $editurl = new moodle_url($alertlinks[$worker->id][$alert->id]['change']); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('clock_edit', 'Edit proposed work unit', 'block_timetracker')); $approveurl = new moodle_url($alertlinks[$worker->id][$alert->id]['approve']); $checkicon = new pix_icon('approve', 'Approve the proposed work unit', 'block_timetracker'); if ($alert->todelete) { $approveaction = $OUTPUT->action_icon($approveurl, $checkicon, new confirm_action('Are you sure you want to delete this work unit as requested by the worker?')); } else { $approveaction = $OUTPUT->action_icon($approveurl, $checkicon); } $deleteurl = new moodle_url($alertlinks[$worker->id][$alert->id]['delete']); $deleteicon = new pix_icon('delete', 'Delete this alert', 'block_timetracker'); $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action('Are you sure you want to delete this alert?')); $denyurl = new moodle_url($alertlinks[$worker->id][$alert->id]['deny']); $denyicon = new pix_icon('clock_delete', 'Deny and restore original work unit', 'block_timetracker'); $denyaction = $OUTPUT->action_icon($denyurl, $denyicon, new confirm_action('Are you sure you want to deny this alert unit?<br />The work unit will be re-inserted into the worker\'s record as it originally appeared.')); $row .= '<td style="text-align: center">' . $approveaction . ' ' . $deleteaction . ' ' . $editaction . ' ' . $denyaction . '</td>'; } $row .= '</tr>'; $mform->addElement('html', $row); } $mform->addElement('html', '</table>'); //$this->add_action_buttons(true, 'Save Changes'); if ($canmanage) { $mform->addElement('header', 'general', 'Alert Action Legend'); $legend = ' <img src="' . $CFG->wwwroot . '/blocks/timetracker/pix/approve.png" /> Approve the proposed work unit <br /> <img src="' . $CFG->wwwroot . '/blocks/timetracker/pix/delete.png" /> Delete the alert and the original/proposed work units <br /> <img src="' . $CFG->wwwroot . '/blocks/timetracker/pix/clock_edit.png" /> Edit the proposed work unit before approval<br /> <img src="' . $CFG->wwwroot . '/blocks/timetracker/pix/clock_delete.png" /> Deny the proposed work unit and re-add the original work unit'; $mform->addElement('html', $legend); } }