/// Build page
$returnurl = $CFG->wwwroot . '/local/catalog/section.php';
$PAGE->set_url($returnurl);
$PAGE->set_context($systemcontext);
$PAGE->set_heading($SITE->fullname);
//page layout
$PAGE->set_pagelayout('standard');
$data = new stdClass();
$data->url = new moodle_url($returnurl);
$data->wwwroot = $CFG->wwwroot;
$PAGE->set_title(get_string('coursecatalog', 'local_catalog'));
$PAGE->navbar->add(get_string('coursecatalog', 'local_catalog'), new moodle_url('/local/catalog/catalog.php'), global_navigation::TYPE_CUSTOM);
$data->header = $OUTPUT->header();
$data->heading = $OUTPUT->heading(get_string('coursecatalog', 'local_catalog'));
$data->footer = $OUTPUT->footer();
$sections = local_catalog_get_sections();
$i = 0;
foreach ($sections as $s) {
    if ($s['enabled'] == 0) {
        continue;
    }
    $data->section[$i]['name'] = $s['name'];
    if (strlen($s['tagline']) > 0) {
        $data->section[$i]['tagline'] = $s['tagline'];
    }
    $data->section[$i]['id'] = $s['id'];
    $data->section[$i]['courses'] = local_catalog_get_course_tiles($s['id']);
    $i++;
}
$data->section[count($data->section) - 1]['last'] = true;
echo $OUTPUT->render_from_template('local_catalog/catalog', $data);
    confirm_sesskey();
    local_catalog_section_course_move("up", $cid, $section_id);
    $displayindex = false;
    $displayedit = true;
}
if ($displayindex) {
    $data = new stdClass();
    $data->returnurl = new moodle_url($returnurl);
    $data->sesskey = sesskey();
    $data->deleteicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall'));
    $data->editicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall'));
    $data->upicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/up'), 'alt' => get_string('up'), 'class' => 'iconsmall'));
    $data->downicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/down'), 'alt' => get_string('down'), 'class' => 'iconsmall'));
    $addform = new local_catalog_addcourse(new moodle_url($returnurl, array('action' => 'addsection')));
    $data->addform = $addform->render();
    $data->courselist = local_catalog_get_sections();
    if (count($data->courselist) > 0) {
        $data->has_courses = true;
        $data->courselist[0]['first'] = true;
        $data->courselist[count($data->courselist) - 1]['last'] = true;
    }
    $data->header = $OUTPUT->header();
    $data->heading = $OUTPUT->heading(get_string('sectionsetup', 'local_catalog'));
    $data->footer = $OUTPUT->footer();
    echo $OUTPUT->render_from_template('local_catalog/section_add', $data);
}
if ($displayedit) {
    if (isset($section_id)) {
        $id = $section_id;
    } else {
        $id = required_param('id', PARAM_INT);