function validation($data) { global $OUTPUT, $CFG; $errors = array(); if ($data['timein'] > $data['timeout']) { $errors['timein'] = 'Time in cannot be before time out'; } else { if ($data['timein'] > time() || $data['timeout'] > time()) { $errors['timein'] = 'Time cannot be set in the future'; } else { $conflicts = find_conflicts($data['timein'], $data['timeout'], $data['userid']); if (sizeof($conflicts) > 0) { $errormsg = 'Work unit conflicts with existing unit(s):<br />'; $errormsg .= '<table>'; foreach ($conflicts as $conflict) { $errormsg .= '<tr>'; $alerticon = new pix_icon('alert', 'Alert Supervisor of Error', 'block_timetracker'); $alertaction = $OUTPUT->action_icon($conflict->alertlink, $alerticon); $errormsg .= '<td>' . $conflict->display . '</td><td>'; $errormsg .= ' ' . $alertaction . '</td></tr>'; } $errormsg .= '</table>'; $errors['timein'] = $errormsg; } } } return $errors; }
function validation($data) { global $COURSE, $OUTPUT, $CFG, $SESSION; $errors = array(); if (isset($data['timeout'])) { if ($data['timein'] > $data['timeout']) { $errors['timein'] = 'Time in cannot be before time out'; } if ($data['timein'] > time() || $data['timeout'] > time()) { $errors['timein'] = 'Time cannot be set in the future'; } if (!isset($data['payrate']) || $data['payrate'] == '') { $errors['payrate'] = 'Payrate cannot be empty'; } $conflicts = find_conflicts($data['timein'], $data['timeout'], $data['userid'], $data['unitid']); if (sizeof($conflicts) > 0) { $params['userid'] = $data['userid']; $params['id'] = $data['id']; $params['start'] = $data['timein']; $params['end'] = $data['timeout']; $params['ispending'] = $data['ispending']; $params['unitid'] = $data['unitid']; //$SESSION->fromurl = $next; $errormsg = 'Work unit conflicts with existing unit(s).<br />'; $errormsg .= '<table>'; foreach ($conflicts as $conflict) { $errormsg .= '<tr>'; $extras = '&next=editunit&eunitid=' . $data['unitid'] . '&astart=' . $data['timein'] . '&aend=' . $data['timeout']; $conflict->editlink .= $extras; $editaction = $OUTPUT->action_icon($conflict->editlink, new pix_icon('clock_edit', 'Edit unit', 'block_timetracker')); $conflict->deletelink .= $extras; $deleteaction = $OUTPUT->action_icon($conflict->deletelink, new pix_icon('clock_delete', get_string('delete'), 'block_timetracker'), new confirm_action('Are you sure you want to delete this ' . ' conflicting work unit?')); $errormsg .= '<td>' . $conflict->display . '</td><td>'; if ($conflict->editlink != '#') { //not a pending clock-in $errormsg .= ' ' . $editaction; } $errormsg .= ' ' . $deleteaction . '</td></tr>'; } $errormsg .= '</table>'; $errors['timein'] = $errormsg; } } return $errors; }
function validation($data) { global $OUTPUT; $errors = array(); if ($data['timeout'] > time()) { $errors['timeout'] = 'Time cannot be set in the future.'; } else { if ($data['timein'] > $data['timeout']) { $errors['timein'] = 'Time out cannot be set before time in.'; } else { $conflicts = find_conflicts($data['timein'], $data['timeout'], $data['userid']); if (sizeof($conflicts) > 0) { $errormsg = 'Work unit conflicts with existing unit(s):<br />'; $errormsg .= '<table>'; foreach ($conflicts as $conflict) { $errormsg .= '<tr>'; $editaction = $OUTPUT->action_icon($conflict->editlink, new pix_icon('clock_edit', get_string('edit'), 'block_timetracker')); $deleteaction = $OUTPUT->action_icon($conflict->deletelink, new pix_icon('clock_delete', get_string('delete'), 'block_timetracker'), new confirm_action('Are you sure you want to delete this ' . ' conflicting work unit?')); $errormsg .= '<td>' . $conflict->display . '</td><td>'; /* if($conflict->editlink != '#') //not a pending clock-in $errormsg .= ' '.$editaction; $errormsg .= ' '.$deleteaction.'</td></tr>'; */ } $errormsg .= '</table>'; $errors['timein'] = $errormsg; } } } return $errors; }
function validation($data) { global $OUTPUT; $errors = array(); $teachers = $data['teacherid']; $hasteach = false; foreach ($teachers as $teacherid => $selectedval) { //if($firstteach == -1) $firstteach = $teacherid; $firstteach = $teacherid; if ($selectedval == 1) { $hasteach = true; break; } } //if it gets here, we had no teachers selected. Use the first teacherid value to //place the error if (!$hasteach) { $errors['teacherid[' . $firstteach . ']'] = 'You didn\'t select any supervisors to alert. As default, all supervisors have been selected.'; } //if delete was checked, don't check any of the times/conflicts if (isset($data['deleteunit'])) { return $errors; } if ($data['timeinerror'] > time()) { $errors['timeinerror'] = 'Time cannot be set in the future.'; } else { if ($data['timeinerror'] > $data['timeouterror']) { $errors['timeinerror'] = 'Your time out cannot be before your time in.'; } else { if ($data['timeouterror'] > time()) { $errors['timeouterror'] = 'Time cannot be set in the future.'; } else { $conflicts = find_conflicts($data['timeinerror'], $data['timeouterror'], $data['userid'], $data['unitid'], -1, $data['ispending']); if (sizeof($conflicts) > 0) { $errormsg = 'Work unit conflicts with existing unit(s):<br />'; $errormsg .= '<table>'; foreach ($conflicts as $conflict) { $errormsg .= '<tr>'; $alerticon = new pix_icon('alert', 'Alert Supervisor of Error', 'block_timetracker'); //$alertaction= $OUTPUT->action_icon($conflict->alertlink, $alerticon); $errormsg .= '<td>' . $conflict->display . '</td><td>'; //$errormsg .= ' '.$alertaction.'</td></tr>'; } $errormsg .= '</table>'; $errors['timeinerror'] = $errormsg; } } } } return $errors; }
} $in = make_timestamp($tdate['year'], $tdate['mon'], $tdate['mday'], $tdate['hours'], $tdate['minutes']); //echo "In: ".userdate($in, $datetimeformat)."\n"; //end time of class if (strlen($endtime) == 4) { $tdate['hours'] = substr($endtime, 0, 2); $tdate['minutes'] = substr($endtime, 2, 2); $tdate['minutes'] = $tdate['minutes'] - 5; } else { $tdate['hours'] = substr($endtime, 0, 1); $tdate['minutes'] = substr($endtime, 1, 2); $tdate['minutes'] = $tdate['minutes'] - 5; } $out = make_timestamp($tdate['year'], $tdate['mon'], $tdate['mday'], $tdate['hours'], $tdate['minutes']); //echo "Out: ".userdate($out, $datetimeformat)."\n"; $conflicts = find_conflicts($in, $out, $worker->id, -1, $worker->courseid); if (sizeof($conflicts) > 0) { foreach ($conflicts as $conflict) { $contents .= "{$worker->lastname} ,{$worker->firstname} ," . "{$coursename} {$days_string} {$dispstarttime} to {$dispendtime} ," . userdate($iterator, '%m/%d/%y %A', 99, false) . "," . $conflict->display . "," . $course->shortname . "," . $supervisor . "\n"; //echo $contents; } } $iterator = strtotime('+1 week', $iterator); } } break; } } fclose($handle); } else { error_log("Error opening file");
function check_worker_hours_for_conflicts($workerid, $from, $to) { //error_log("checking for class conflicts"); global $CFG, $DB, $USER; $myconflicts = array(); $datetimeformat = '%m/%d/%y %I:%M %p'; $day_names = array(); $day_names['m'] = 'Monday'; $day_names['t'] = 'Tuesday'; $day_names['w'] = 'Wednesday'; $day_names['r'] = 'Thursday'; $day_names['f'] = 'Friday'; $day_names['s'] = 'Saturday'; $worker = $DB->get_record('block_timetracker_workerinfo', array('id' => $workerid)); if (!$worker) { error_log('This worker does not exist in workerinfo'); return $myconflicts; } $mdlworker = $DB->get_record('user', array('id' => $worker->mdluserid)); if (!$mdlworker) { error_log('This worker does not exist in mdl_user'); return $myconflicts; } $scheduleitems = $DB->get_records('block_timetracker_schedules', array('studentid' => strtolower($mdlworker->username))); if (!$scheduleitems) { error_log('no schedule items for ' . $mdlworker->username); return $myconflicts; } foreach ($scheduleitems as $item) { if (strtolower($item->days) == 'tba') { continue; } if (strtolower($item->days) == 'mtof') { $item->days = 'MTWRF'; } $days_array = preg_split('//', $item->days, -1, PREG_SPLIT_NO_EMPTY); foreach ($days_array as $day) { $day = strtolower($day); //echo "Checking $day\n"; if (!isset($day_names[$day])) { echo "Day {$day} does not exist in day_names array\n"; continue; } $iterator = strtotime("Next {$day_names[$day]}", $from); if ($item->begin_time >= 1200) { $dispstarttime = $item->begin_time; if ($item->begin_time >= 1300) { $dispstarttime -= 1200; } $dispstarttime .= 'pm'; } else { $dispstarttime = $item->begin_time . 'am'; } if ($item->end_time >= 1200) { $dispendtime = $item->end_time; if ($item->end_time >= 1300) { $dispendtime -= 1200; } $dispendtime .= 'pm'; } else { $dispendtime = $item->end_time . 'am'; } while ($iterator < $to) { if ($iterator > $item->end_date) { break; } if ($iterator < $item->begin_date) { $iterator = strtotime('+1 week', $iterator); continue; } $tdate = usergetdate($iterator); //class start if (strlen($item->begin_time) == 4) { $tdate['hours'] = substr($item->begin_time, 0, 2); $tdate['minutes'] = substr($item->begin_time, 2, 2); $tdate['minutes'] = $tdate['minutes'] + 5; } else { $tdate['hours'] = substr($item->begin_time, 0, 1); $tdate['minutes'] = substr($item->begin_time, 1, 2); $tdate['minutes'] = $tdate['minutes'] + 5; } $in = make_timestamp($tdate['year'], $tdate['mon'], $tdate['mday'], $tdate['hours'], $tdate['minutes']); //end time of class if (strlen($item->end_time) == 4) { $tdate['hours'] = substr($item->end_time, 0, 2); $tdate['minutes'] = substr($item->end_time, 2, 2); $tdate['minutes'] = $tdate['minutes'] - 5; } else { $tdate['hours'] = substr($item->end_time, 0, 1); $tdate['minutes'] = substr($item->end_time, 1, 2); $tdate['minutes'] = $tdate['minutes'] - 5; } $out = make_timestamp($tdate['year'], $tdate['mon'], $tdate['mday'], $tdate['hours'], $tdate['minutes']); //check to see if this class was during a break; if so, skip it. $duringbreak = $DB->count_records_select('block_timetracker_holiday', 'start <= ' . $in . ' AND end >= ' . $out); //error_log($duringbreak); if (!$duringbreak) { $conflicts = find_conflicts($in, $out, $worker->id, -1, $worker->courseid, false, true); if (sizeof($conflicts) > 0) { foreach ($conflicts as $conflict) { $conflict->conflictcourse = "{$item->course_code} {$item->days} {$dispstarttime} to " . $dispendtime; $myconflicts[] = $conflict; /* echo "\"$worker->lastname\",\"$worker->firstname\",". "\"$item->course_code $item->days ". "$dispstarttime to $dispendtime\",\"". userdate($iterator,'%m/%d/%y %A',99,false).'","'. $conflict->display.'"'."\n"; */ } } } $iterator = strtotime('+1 week', $iterator); } } } return $myconflicts; }
* Set the timein and timeout as the same value so that this will ensure the unit * doesn't show on the monthly report and add to the 'workunit' table so that data * isn't lost. */ unset($alertunit->id); $alertunit->timein = $alertunit->origtimein; $alertunit->timeout = $alertunit->origtimein; //$DB->insert_record('block_timetracker_workunit', $alertunit); add_unit($alertunit); } else { // Add work unit back to 'workunit' table unset($alertunit->id); $alertunit->timein = $alertunit->origtimein; $alertunit->timeout = $alertunit->origtimeout; //$DB->insert_record('block_timetracker_workunit', $alertunit); $conflicts = find_conflicts($alertunit->timein, $alertunit->timeout, $alertunit->userid); if (sizeof($conflicts) == 0) { $result = add_unit($alertunit); if (!$result) { print_error('Something bad happened :('); } } else { redirect($managealerts, 'Cannot approve this unit; it conflicts with an existing work unit!', 3); } } // Email worker and any other supervisor(s) that the work unit has been denied $from = $USER; $subject = get_string('denysubject', 'block_timetracker', $worker->firstname . ' ' . $worker->lastname . ' in ' . $course->shortname); //********** PLAIN TEXT **********//
function validation($data) { global $OUTPUT, $SESSION; $errors = array(); if ($data['timein'] > $data['timeout']) { $errors['timein'] = 'Time in cannot be before time out'; } else { if ($data['timein'] > time() || $data['timeout'] > time()) { $errors['timein'] = 'Time cannot be set in the future'; } else { $conflicts = find_conflicts($data['timein'], $data['timeout'], $data['userid']); if (sizeof($conflicts) > 0) { $params['userid'] = $data['userid']; $params['id'] = $data['id']; $params['timein'] = $data['timein']; $params['timeout'] = $data['timeout']; /* $next = new moodle_url(qualified_me(), $params); $SESSION->fromurl = $next; */ $errormsg = 'Work unit conflicts with existing unit(s):<br />'; $errormsg .= '<table>'; foreach ($conflicts as $conflict) { $errormsg .= '<tr>'; $extras = '&next=addunit&astart=' . $data['timein'] . '&aend=' . $data['timeout']; $conflict->editlink .= $extras; $editaction = $OUTPUT->action_icon($conflict->editlink, new pix_icon('clock_edit', 'Edit unit', 'block_timetracker')); $conflict->deletelink .= $extras; $deleteaction = $OUTPUT->action_icon($conflict->deletelink, new pix_icon('clock_delete', get_string('delete'), 'block_timetracker'), new confirm_action('Are you sure you want to delete this ' . ' conflicting work unit?')); $errormsg .= '<td>' . $conflict->display . '</td><td>'; if ($conflict->editlink != '#') { //not a pending clock-in $errormsg .= ' ' . $editaction; } $errormsg .= ' ' . $deleteaction . '</td></tr>'; } $errormsg .= '</table>'; $errors['timein'] = $errormsg; } } } return $errors; }