function action_coreqedit()
 {
     $id = $this->required_param('id', PARAM_INT);
     $curcrsid = $this->required_param('association_id', PARAM_INT);
     $curcrs = new curriculumcourse($curcrsid);
     $curcrs->seturl(null, array('s' => $this->pagename, 'action' => 'coreqedit', 'id' => $id));
     $coreqform = $curcrs->create_corequisite_form();
     if ($coreqform->is_cancelled()) {
         $this->action_default();
         return;
     } else {
         if ($coreqform->is_submitted() && $coreqform->is_validated()) {
             $form_data = $coreqform->get_data();
             $output = '';
             $added = 0;
             $deleted = 0;
             /// Process requested corequisite deletions.
             $scoreqs = isset($form_data->scoreqs) ? $form_data->scoreqs : array();
             foreach ($scoreqs as $scoreq) {
                 if ($curcrs->del_corequisite($scoreq)) {
                     $deleted++;
                 }
             }
             /// Process requested corequisite additions.
             $coreqs = isset($form_data->coreqs) ? $form_data->coreqs : array();
             foreach ($coreqs as $coreq) {
                 if (coursepage::_has_capability('block/curr_admin:course:view', $prereq) && $curcrs->add_corequisite($coreq, !empty($form_data->add_to_curriculum))) {
                     $added++;
                 }
             }
             if ($deleted > 0) {
                 $delString = $deleted > 1 ? 'deleted_corequisites' : 'deleted_corequisite';
                 $output .= get_string($delString, 'block_curr_admin', $deleted);
             }
             if ($added > 0) {
                 $addString = $added > 1 ? 'added_corequisites' : 'added_corequisite';
                 $output .= ($deleted > 0 ? ' / ' : '') . get_string($addString, 'block_curr_admin', $added);
             }
             if ($deleted > 0 || $added > 0) {
                 $output .= "\n";
             }
             $curriculum = $curcrs->curriculum;
             if ($curriculum->iscustom) {
                 $curassid = $CURMAN->db->get_field(CURASSTABLE, 'id', 'curriculumid', $curriculum->id);
                 $stucur = new curriculumstudent($curassid);
                 redirect('index.php?s=stucur&section=curr&id=' . $stucur->id . '&action=edit', $output, 3);
             }
             echo $output;
             // recreate the form, to reflect changes in the lists
             $coreqform = $curcrs->create_corequisite_form();
         }
     }
     $coreqform->display();
 }
 /**
  * Display form to manage corequisites.
  */
 public function display_coreqedit()
 {
     $id = $this->required_param('id', PARAM_INT);
     $curcrsid = $this->required_param('association_id', PARAM_INT);
     $curcrs = new curriculumcourse($curcrsid);
     $curcrs->seturl(null, array('s' => $this->pagename, 'action' => 'coreqedit', 'id' => $id));
     $coreqform = $curcrs->create_corequisite_form();
     if ($coreqform->is_cancelled()) {
         $this->display_default();
         return;
     } else {
         if ($coreqform->is_submitted() && $coreqform->is_validated()) {
             $formdata = $coreqform->get_data();
             $output = '';
             $added = 0;
             $deleted = 0;
             // Process requested corequisite deletions.
             $scoreqs = isset($formdata->scoreqs) ? $formdata->scoreqs : array();
             foreach ($scoreqs as $scoreq) {
                 if ($curcrs->del_corequisite($scoreq)) {
                     $deleted++;
                 }
             }
             // Process requested corequisite additions.
             $coreqs = isset($formdata->coreqs) ? $formdata->coreqs : array();
             // TODO: Ugly, this needs to be overhauled.
             $cpage = new coursepage();
             foreach ($coreqs as $coreq) {
                 if ($cpage->_has_capability('local/elisprogram:course_view', $coreq) && $curcrs->add_corequisite($coreq, !empty($formdata->add_to_curriculum))) {
                     $added++;
                 }
             }
             if ($deleted > 0) {
                 $delstring = $deleted > 1 ? 'deleted_corequisites' : 'deleted_corequisite';
                 $output .= get_string($delstring, 'local_elisprogram', $deleted);
             }
             if ($added > 0) {
                 $addstring = $added > 1 ? 'added_corequisites' : 'added_corequisite';
                 $output .= ($deleted > 0 ? ' / ' : '') . get_string($addstring, 'local_elisprogram', $added);
             }
             if ($deleted > 0 || $added > 0) {
                 $output .= "\n";
             }
             $curriculum = $curcrs->curriculum;
             if ($curriculum->iscustom) {
                 $curassid = $this->_db->get_field(curriculumstudent::TABLE, 'id', array('curriculumid' => $curriculum->id));
                 $stucur = new curriculumstudent($curassid);
                 redirect('index.php?s=stucur&section=curr&id=' . $stucur->id . '&action=edit', $output, 3);
             }
             echo $output;
             // Recreate the form, to reflect changes in the lists.
             $coreqform = $curcrs->create_corequisite_form();
         }
     }
     $coreqform->display();
 }