$a->name = $data->{'bucket_' . $i . '_name'}; $a->number = 1; $errors[] = get_string('err_invalid_bucket', 'block_courseprefs', $a); continue; } foreach ($data->{'bucket_' . $i} as $sectionsid) { // Tried to hack a sectionised that's not theirs if (!array_key_exists($sectionsid, $sections)) { $a->sectionsid = $sectionsid; $errors[] = get_string('err_invalid_section', 'block_courseprefs', $a); continue; } if (array_key_exists($sectionsid, $splits)) { $split = $splits[$sectionsid]; if ($i != $split->getGroupingsId()) { reset_prefs(array($split)); $split->setId(null); $split->setGroupingsId($i); } $split->setShellName($data->{'bucket_' . $i . '_name'}); $split->setStatus('todo'); insert_into_array($sections[$sectionsid], $changed_splits, $split->getShellName()); } else { $split = new CoursePrefsSplit($user->getId(), $sectionsid, $i, $data->{'bucket_' . $i . '_name'}, 'todo'); insert_into_array($sections[$sectionsid], $new_splits, $split->getShellName()); } // Try to save try { $split->save(); } catch (Exception $e) { $errors[] = 'Error trying to insert a split record.';
redirect_error(ERROR_USER_MISSING); } // Disallow anyone who does not have any splittable courses $splits = $user->getSplittableCourses(); if (!$splits) { redirect_error(ERROR_SPLIT_MISSING); } $current_splits = $user->getSplits(); list($semestersid, $coursesid) = split_selected($selected); // Reset post processing if ($mode == 'perform_reset') { $my_splits = $current_splits[$semestersid][$coursesid]; if (!$my_splits) { redirect_error(ERROR_COURSE_NONE); } reset_prefs($my_splits); redirect($CFG->wwwroot . '/blocks/courseprefs/split.php'); } require_js($CFG->wwwroot . '/blocks/courseprefs/functions.js'); // Render the page headers and forms $heading_main = get_string('split_heading', 'block_courseprefs'); $navigation = array(array('name' => get_string('blockname', 'block_courseprefs'), 'link' => '', 'type' => 'title'), array('name' => $heading_main, 'link' => '', 'type' => 'title')); print_header_simple($heading_main, '', build_navigation($navigation)); print_heading_with_help($heading_main, 'split', 'block_courseprefs'); if ($user->getCrDelete()) { echo '<div class="cps_error">' . get_string('error_preference', 'block_courseprefs'); $split = $splits[$semestersid][$coursesid]; echo isset($split) ? $split->year . ' ' . $split->name . ' ' . $split->department . ' ' . $split->course_number . '.' : get_string('error_preference_any', 'block_courseprefs'); echo '<p class="cps_smallerror">' . get_string('error_preference_sub', 'block_courseprefs') . '</p>'; echo '</div>'; }
function findResetables($user, $courses, $semestersid) { global $CFG, $USER; $semester = get_record('block_courseprefs_semesters', 'id', $semestersid); $semester_name = "{$semester->year}{$semester->name}{$user->getUsername()}cl"; $numbers = $user->findClNumbers($semestersid, $courses); foreach ($numbers as $number) { $crosslists = CoursePrefsCrosslist::findByNumber($semester_name . $number); if (empty($crosslists)) { continue; } reset_prefs($crosslists); } }
} } // Refresh accept and remove forms due to new information $accept_form = new teamteach_accept_form(); $remove_form = new teamteach_remove_form(); } else { if ($data = $remove_form->get_data()) { // Prematurely set heading that the form submission was processed and necessary emails were sent $heading = get_string('email_sent', 'block_courseprefs'); $teamteaches = array(); // Iterate over selected team teach requests and delete them accordingly foreach ($remove_form->selected_teamteaches as $id) { $teamteaches[$id] = CoursePrefsTeamTeach::findById($id); delete_email($teamteaches[$id], $user); } reset_prefs($teamteaches); // Refresh remove form due to new information $remove_form = new teamteach_remove_form(); } } } // Render the page headers and forms $heading_main = get_string('teamteach_heading', 'block_courseprefs'); $navigation = array(array('name' => get_string('blockname', 'block_courseprefs'), 'link' => '', 'type' => 'title'), array('name' => $heading_main, 'link' => '', 'type' => 'title')); print_header_simple($heading_main, '', build_navigation($navigation)); print_heading_with_help($heading_main, 'teamteach', 'block_courseprefs'); if ($heading) { print_heading($heading, 'center', 3); } // Determined teachers should see this regardless if ($user->getCrDelete()) {
foreach ($data->{'bucket_' . $i} as $sectionsid) { // They tried to hack section's id if (!array_key_exists($sectionsid, $sections)) { $a->sectionsid = $sectionsid; $errors[] = get_string('err_invalid_section', 'block_courseprefs', $a); continue; } $section = $sections[$sectionsid]; $suggested_idnumber = "{$section->year}{$section->name}{$user->getUsername()}cl{$i}"; if (array_key_exists($sectionsid, $crosslisted)) { $cr = $crosslisted[$sectionsid]; if ($suggested_idnumber == $cr->getIdnumber()) { $cr->setShellName($data->{'bucket_' . $i . '_name'}); $cr->setStatus('todo'); } else { reset_prefs(array($cr)); } insert_into_array($section, $changed_cr, $cr->getShellName()); } else { $cr = new CoursePrefsCrosslist($user->getId(), $sectionsid, 'todo', $data->{'bucket_' . $i . '_name'}, $suggested_idnumber); insert_into_array($section, $new_cr, $cr->getShellName()); } try { $cr->save(); } catch (Exception $e) { $errors[] = 'Could not save a cross list entry!'; } } } $params = array($changed_cr, $new_cr, $errors); build_form('finished_content', $params, 'Next', '', 'GET', 'crosslist.php');