$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.'; } } } $params = array($changed_splits, $new_splits, $errors); build_form('finished_content', $params, 'Next', ''); print_footer(); function insert_into_array($object, &$array, $key = null) {
} else { if ($mode == 'reset') { $split = $splits[$semestersid][$coursesid]; build_form('reset_content', $split, 'Reset', 'Back', "POST"); } else { if ($number && $number == $splits[$semestersid][$coursesid]->count) { // if they have already split, then tell them to reset first // they would only get this message if they tried to hack it if (!array_key_exists($coursesid, $splits[$semestersid])) { redirect_error(''); } $new_splits = array(); $sections = $user->getSectionsForCourse($semestersid, $coursesid, false); $count = 0; foreach ($sections as $sectionsid => $section) { $split = new CoursePrefsSplit($user->getId(), $sectionsid, ++$count, "Section {$section->getSectionNumber()}", 'todo'); $split->save(); $new_splits[$split->getShellName()] = $sections[$sectionsid]; } $params = array(array(), $new_splits, array()); build_form('finished_content', $params, 'Next', ''); } else { $params = array($semestersid, $coursesid, $number, $user, $current_splits); build_form('numbered_content', $params, get_string('submit'), "", "POST", "post_split.php", 'onsubmit="return validate();"'); } } } } print_footer(); ?>