public function get_content()
 {
     global $COURSE, $CFG;
     //load the global parameters
     $context = context_course::instance($COURSE->id);
     //set the context
     //var_dump(already_cancelled($COURSE->id));
     if (has_capability('block/cancelcourse:view', $context)) {
         //does the user have the block:view capability?
         if ($this->content !== null) {
             //does the block have content?
             return $this->content;
             //display the block
         }
         $this->content = new stdClass();
         //use the block-setting specified language. If it's not set, use the current user's display language for the message.
         if (!isset($this->config->language) || !$this->config->language) {
             $messagelang = current_language();
         } else {
             $messagelang = $this->config->language;
         }
         //set the professor's name from the block configuration. If it's not set, use a default.
         if (!isset($this->config->profname) || !$this->config->profname) {
             $profname = 'none';
         } else {
             $profname = urlencode($this->config->profname);
         }
         if (!already_cancelled($COURSE->id) || get_config('cancelcourse', 'multicancel')) {
             //add all the parameters to the link so that everything we need makes it to the next step.
             $url = new moodle_url('/blocks/cancelcourse/view.php', array('id' => $COURSE->id, 'blockid' => $this->instance->id, 'messagelang' => $messagelang, 'profname' => $profname));
             $this->content->footer = html_writer::link($url, get_string('cancelclass', 'block_cancelcourse'));
         } else {
             $this->content->footer = get_string('alreadycancelled', 'block_cancelcourse');
         }
         return $this->content;
     }
 }
Example #2
0
                $url = new moodle_url('/course/view.php', array('id' => $COURSE->id));
                echo html_writer::link($url, get_string('return_to_class', 'block_cancelcourse'));
            }
        } else {
            print_error('cancelerror', 'block_cancelcourse');
        }
        echo $OUTPUT->footer();
        //add the footer
        //Uncomment next lines to redirect to the course main page.
        //$courseurl = new moodle_url('/course/view.php', array('id'=>$courseid));
        //redirect($courseurl);
    } else {
        //form didn't validate or this is the first display
        $site = get_site();
        echo $OUTPUT->header();
        if (!already_cancelled($COURSE->id) || get_config('cancelcourse', 'multicancel')) {
            $settingsnode = $PAGE->settingsnav->add(get_string('cancelcoursesettings', 'block_cancelcourse'));
            $editurl = new moodle_url('/blocks/cancelcourse/view.php', array('id' => $courseid, 'blockid' => $blockid));
            $editnode = $settingsnode->add(get_string('editpage', 'block_cancelcourse'), $editurl);
            $editnode->make_active();
            $cancelcourse->display();
            //display the form.
            echo $OUTPUT->footer();
        } else {
            echo get_string('alreadycancelled', 'block_cancelcourse');
        }
    }
} else {
    //Access denied! This user doesn't have persmission to do this (prevents direct URL access).
    echo $OUTPUT->header();
    $site = get_site();