mirror of
https://github.com/moodle/moodle.git
synced 2025-05-10 18:27:20 +02:00
MDL-37572 Course categories are now managed in /course/manage.php
Switching between categories view and edit no longer depend on global editing mode /course/index.php and /course/category.php do not contain editing code
This commit is contained in:
parent
1918a2452e
commit
2c49fb4c3e
@ -8,7 +8,7 @@ if ($hassiteconfig
|
||||
or has_capability('moodle/course:create', $systemcontext)
|
||||
or has_capability('moodle/site:approvecourse', $systemcontext)) { // speedup for non-admins, add all caps used on this page
|
||||
|
||||
$ADMIN->add('courses', new admin_externalpage('coursemgmt', new lang_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on',
|
||||
$ADMIN->add('courses', new admin_externalpage('coursemgmt', new lang_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/manage.php',
|
||||
array('moodle/category:manage', 'moodle/course:create')));
|
||||
|
||||
/// Course Default Settings Page
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
/**
|
||||
* Displays the top level category or all courses
|
||||
* In editing mode, allows the admin to edit a category,
|
||||
* and rearrange courses
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
@ -31,24 +29,8 @@ require_once($CFG->libdir.'/textlib.class.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Category id
|
||||
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
||||
$categoryedit = optional_param('categoryedit', -1, PARAM_BOOL);
|
||||
$hide = optional_param('hide', 0, PARAM_INT);
|
||||
$show = optional_param('show', 0, PARAM_INT);
|
||||
$moveup = optional_param('moveup', 0, PARAM_INT);
|
||||
$movedown = optional_param('movedown', 0, PARAM_INT);
|
||||
$moveto = optional_param('moveto', 0, PARAM_INT);
|
||||
$resort = optional_param('resort', 0, PARAM_BOOL);
|
||||
$sesskey = optional_param('sesskey', '', PARAM_RAW);
|
||||
|
||||
// MDL-27824 - This is a temporary fix until we have the proper
|
||||
// way to check/initialize $CFG value.
|
||||
// @todo MDL-35138 remove this temporary solution
|
||||
if (!empty($CFG->coursesperpage)) {
|
||||
$defaultperpage = $CFG->coursesperpage;
|
||||
} else {
|
||||
$defaultperpage = 20;
|
||||
}
|
||||
$perpage = optional_param('perpage', $defaultperpage, PARAM_INT); // how many per page
|
||||
$perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // how many per page
|
||||
|
||||
if (empty($id)) {
|
||||
print_error("unknowcategory");
|
||||
@ -61,124 +43,14 @@ $context = $PAGE->context;
|
||||
// And the object has been loaded for us no need for another DB call
|
||||
$category = $PAGE->category;
|
||||
|
||||
$canedit = can_edit_in_category($category->id);
|
||||
if ($canedit) {
|
||||
if ($categoryedit !== -1) {
|
||||
$USER->editing = $categoryedit;
|
||||
}
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
$editingon = $PAGE->user_is_editing();
|
||||
} else {
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
}
|
||||
$editingon = false;
|
||||
}
|
||||
|
||||
if (!$category->visible) {
|
||||
require_capability('moodle/category:viewhiddencategories', $context);
|
||||
}
|
||||
|
||||
$canmanage = has_capability('moodle/category:manage', $context);
|
||||
$sesskeyprovided = !empty($sesskey) && confirm_sesskey($sesskey);
|
||||
|
||||
// Process any category actions.
|
||||
if ($canmanage && $resort && $sesskeyprovided) {
|
||||
// Resort the category if requested
|
||||
if ($courses = get_courses($category->id, '', 'c.id,c.fullname,c.sortorder')) {
|
||||
collatorlib::asort_objects_by_property($courses, 'fullname', collatorlib::SORT_NATURAL);
|
||||
$i = 1;
|
||||
foreach ($courses as $course) {
|
||||
$DB->set_field('course', 'sortorder', $category->sortorder+$i, array('id'=>$course->id));
|
||||
$i++;
|
||||
}
|
||||
fix_course_sortorder(); // should not be needed
|
||||
}
|
||||
}
|
||||
|
||||
// Process any course actions.
|
||||
if ($editingon && $sesskeyprovided) {
|
||||
|
||||
// Move a specified course to a new category
|
||||
if (!empty($moveto) and $data = data_submitted()) {
|
||||
// Some courses are being moved
|
||||
// user must have category update in both cats to perform this
|
||||
require_capability('moodle/category:manage', $context);
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($moveto));
|
||||
|
||||
if (!$destcategory = $DB->get_record('course_categories', array('id' => $data->moveto))) {
|
||||
print_error('cannotfindcategory', '', '', $data->moveto);
|
||||
}
|
||||
|
||||
$courses = array();
|
||||
foreach ($data as $key => $value) {
|
||||
if (preg_match('/^c\d+$/', $key)) {
|
||||
$courseid = substr($key, 1);
|
||||
array_push($courses, $courseid);
|
||||
|
||||
// check this course's category
|
||||
if ($movingcourse = $DB->get_record('course', array('id'=>$courseid))) {
|
||||
if ($movingcourse->category != $id ) {
|
||||
print_error('coursedoesnotbelongtocategory');
|
||||
}
|
||||
} else {
|
||||
print_error('cannotfindcourse');
|
||||
}
|
||||
}
|
||||
}
|
||||
move_courses($courses, $data->moveto);
|
||||
}
|
||||
|
||||
// Hide or show a course
|
||||
if (!empty($hide) or !empty($show)) {
|
||||
if (!empty($hide)) {
|
||||
$course = $DB->get_record('course', array('id' => $hide));
|
||||
$visible = 0;
|
||||
} else {
|
||||
$course = $DB->get_record('course', array('id' => $show));
|
||||
$visible = 1;
|
||||
}
|
||||
|
||||
if ($course) {
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
require_capability('moodle/course:visibility', $coursecontext);
|
||||
// Set the visibility of the course. we set the old flag when user manually changes visibility of course.
|
||||
$DB->update_record('course', array('id' => $course->id, 'visible' => $visible, 'visibleold' => $visible, 'timemodified' => time()));
|
||||
add_to_log($course->id, "course", ($visible ? 'show' : 'hide'), "edit.php?id=$course->id", $course->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Move a course up or down
|
||||
if (!empty($moveup) or !empty($movedown)) {
|
||||
require_capability('moodle/category:manage', $context);
|
||||
|
||||
// Ensure the course order has continuous ordering
|
||||
fix_course_sortorder();
|
||||
$swapcourse = NULL;
|
||||
|
||||
if (!empty($moveup)) {
|
||||
if ($movecourse = $DB->get_record('course', array('id' => $moveup))) {
|
||||
$swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder - 1));
|
||||
}
|
||||
} else {
|
||||
if ($movecourse = $DB->get_record('course', array('id' => $movedown))) {
|
||||
$swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder + 1));
|
||||
}
|
||||
}
|
||||
if ($swapcourse and $movecourse) {
|
||||
// check course's category
|
||||
if ($movecourse->category != $id) {
|
||||
print_error('coursedoesnotbelongtocategory');
|
||||
}
|
||||
$DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id));
|
||||
$DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id));
|
||||
add_to_log($movecourse->id, "course", "move", "edit.php?id=$movecourse->id", $movecourse->id);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of editing stuff
|
||||
|
||||
// Prepare the standard URL params for this page. We'll need them later.
|
||||
$urlparams = array('id' => $id);
|
||||
if ($page) {
|
||||
@ -189,29 +61,12 @@ if ($perpage) {
|
||||
}
|
||||
|
||||
// Begin output
|
||||
if ($editingon && can_edit_in_category()) {
|
||||
// Integrate into the admin tree only if the user can edit categories at the top level,
|
||||
// otherwise the admin block does not appear to this user, and you get an error.
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
navigation_node::override_active_url(new moodle_url('/course/category.php', array('id' => $id)));
|
||||
admin_externalpage_setup('coursemgmt', '', $urlparams, $CFG->wwwroot . '/course/category.php');
|
||||
$PAGE->set_context($context); // Ensure that we are actually showing blocks etc for the cat context
|
||||
|
||||
$settingsnode = $PAGE->settingsnav->find_active_node();
|
||||
if ($settingsnode) {
|
||||
$settingsnode->make_inactive();
|
||||
$settingsnode->force_open();
|
||||
$PAGE->navbar->add($settingsnode->text, $settingsnode->action);
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
} else {
|
||||
$site = get_site();
|
||||
$PAGE->set_title("$site->shortname: $category->name");
|
||||
$PAGE->set_heading($site->fullname);
|
||||
$PAGE->set_button(print_course_search('', true, 'navbar'));
|
||||
$PAGE->set_pagelayout('coursecategory');
|
||||
echo $OUTPUT->header();
|
||||
}
|
||||
$PAGE->set_pagelayout('coursecategory');
|
||||
$site = get_site();
|
||||
$PAGE->set_title("$site->shortname: $category->name");
|
||||
$PAGE->set_heading($site->fullname);
|
||||
$PAGE->set_button(print_course_search('', true, 'navbar'));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print the category selector
|
||||
$displaylist = array();
|
||||
@ -225,33 +80,17 @@ echo $OUTPUT->render($select);
|
||||
echo '</div>';
|
||||
|
||||
/// Print current category description
|
||||
if (!$editingon && $category->description) {
|
||||
echo $OUTPUT->box_start();
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$options->para = false;
|
||||
$options->overflowdiv = true;
|
||||
if (!isset($category->descriptionformat)) {
|
||||
$category->descriptionformat = FORMAT_MOODLE;
|
||||
}
|
||||
$text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'coursecat', 'description', null);
|
||||
echo format_text($text, $category->descriptionformat, $options);
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
||||
if ($editingon && $canmanage) {
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
|
||||
// Print button to update this category
|
||||
$url = new moodle_url('/course/editcategory.php', array('id' => $category->id));
|
||||
echo $OUTPUT->single_button($url, get_string('editcategorythis'), 'get');
|
||||
|
||||
// Print button for creating new categories
|
||||
$url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
|
||||
echo $OUTPUT->single_button($url, get_string('addsubcategory'), 'get');
|
||||
|
||||
echo $OUTPUT->container_end();
|
||||
echo $OUTPUT->box_start();
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$options->para = false;
|
||||
$options->overflowdiv = true;
|
||||
if (!isset($category->descriptionformat)) {
|
||||
$category->descriptionformat = FORMAT_MOODLE;
|
||||
}
|
||||
$text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'coursecat', 'description', null);
|
||||
echo format_text($text, $category->descriptionformat, $options);
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
// Print out all the sub-categories
|
||||
// In order to view hidden subcategories the user must have the viewhiddencategories
|
||||
@ -310,7 +149,7 @@ if (!$courses) {
|
||||
if (empty($subcategorieswereshown)) {
|
||||
echo $OUTPUT->heading(get_string("nocoursesyet"));
|
||||
}
|
||||
} else if ($numcourses <= $CFG->courseswithsummarieslimit and !$pagingmode and !$editingon) {
|
||||
} else if ($numcourses <= $CFG->courseswithsummarieslimit and !$pagingmode) {
|
||||
// We display courses with their summaries as we have not reached the limit, also we are not
|
||||
// in paging mode and not allowed to edit either.
|
||||
echo $OUTPUT->box_start('courseboxes');
|
||||
@ -324,16 +163,10 @@ if (!$courses) {
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<table border="0" cellspacing="2" cellpadding="4" class="generaltable boxaligncenter"><tr>';
|
||||
echo '<th class="header" scope="col">'.get_string('courses').'</th>';
|
||||
if ($editingon) {
|
||||
echo '<th class="header" scope="col">'.get_string('edit').'</th>';
|
||||
echo '<th class="header" scope="col">'.get_string('select').'</th>';
|
||||
} else {
|
||||
echo '<th class="header" scope="col"> </th>';
|
||||
}
|
||||
echo '<th class="header" scope="col"> </th>';
|
||||
echo '</tr>';
|
||||
|
||||
$count = 0;
|
||||
$abletomovecourses = false; // for now
|
||||
|
||||
// Checking if we are at the first or at the last page, to allow courses to
|
||||
// be moved up and down beyond the paging border
|
||||
@ -361,108 +194,28 @@ if (!$courses) {
|
||||
echo '<tr>';
|
||||
$coursename = get_course_display_name_for_list($acourse);
|
||||
echo '<td><a '.$linkcss.' href="view.php?id='.$acourse->id.'">'. format_string($coursename) .'</a></td>';
|
||||
if ($editingon) {
|
||||
echo '<td>';
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
$url = new moodle_url('/course/edit.php', array('id' => $acourse->id, 'category' => $id, 'returnto' => 'category'));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/edit', get_string('settings')));
|
||||
echo '<td align="right">';
|
||||
// print enrol info
|
||||
if ($icons = enrol_get_course_info_icons($acourse)) {
|
||||
foreach ($icons as $pix_icon) {
|
||||
echo $OUTPUT->render($pix_icon);
|
||||
}
|
||||
|
||||
// role assignment link
|
||||
if (has_capability('moodle/course:enrolreview', $coursecontext)) {
|
||||
$url = new moodle_url('/enrol/users.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/enrolusers', get_string('enrolledusers', 'enrol')));
|
||||
}
|
||||
|
||||
if (can_delete_course($acourse->id)) {
|
||||
$url = new moodle_url('/course/delete.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/delete', get_string('delete')));
|
||||
}
|
||||
|
||||
// MDL-8885, users with no capability to view hidden courses, should not be able to lock themselves out
|
||||
if (has_capability('moodle/course:visibility', $coursecontext) && has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
|
||||
if (!empty($acourse->visible)) {
|
||||
$url = new moodle_url($baseurl, array('hide' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/hide', get_string('hide')));
|
||||
} else {
|
||||
$url = new moodle_url($baseurl, array('show' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/show', get_string('show')));
|
||||
}
|
||||
}
|
||||
|
||||
if (has_capability('moodle/backup:backupcourse', $coursecontext)) {
|
||||
$url = new moodle_url('/backup/backup.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/backup', get_string('backup')));
|
||||
}
|
||||
|
||||
if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
|
||||
$url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/restore', get_string('restore')));
|
||||
}
|
||||
|
||||
if ($canmanage) {
|
||||
if ($up) {
|
||||
$url = new moodle_url($baseurl, array('moveup' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/up', get_string('moveup')));
|
||||
}
|
||||
|
||||
if ($down) {
|
||||
$url = new moodle_url($baseurl, array('movedown' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')));
|
||||
}
|
||||
$abletomovecourses = true;
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
echo '<td align="center">';
|
||||
echo '<input type="checkbox" name="c'.$acourse->id.'" />';
|
||||
echo '</td>';
|
||||
} else {
|
||||
echo '<td align="right">';
|
||||
// print enrol info
|
||||
if ($icons = enrol_get_course_info_icons($acourse)) {
|
||||
foreach ($icons as $pix_icon) {
|
||||
echo $OUTPUT->render($pix_icon);
|
||||
}
|
||||
}
|
||||
if (!empty($acourse->summary)) {
|
||||
$url = new moodle_url("/course/info.php?id=$acourse->id");
|
||||
echo $OUTPUT->action_link($url, '<img alt="'.get_string('info').'" class="icon" src="'.$OUTPUT->pix_url('i/info') . '" />',
|
||||
new popup_action('click', $url, 'courseinfo'), array('title'=>get_string('summary')));
|
||||
}
|
||||
echo "</td>";
|
||||
}
|
||||
if (!empty($acourse->summary)) {
|
||||
$url = new moodle_url("/course/info.php?id=$acourse->id");
|
||||
echo $OUTPUT->action_link($url, '<img alt="'.get_string('info').'" class="icon" src="'.$OUTPUT->pix_url('i/info') . '" />',
|
||||
new popup_action('click', $url, 'courseinfo'), array('title'=>get_string('summary')));
|
||||
}
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
if ($abletomovecourses) {
|
||||
$movetocategories = array();
|
||||
$notused = array();
|
||||
make_categories_list($movetocategories, $notused, 'moodle/category:manage');
|
||||
$movetocategories[$category->id] = get_string('moveselectedcoursesto');
|
||||
echo '<tr><td colspan="3" align="right">';
|
||||
echo html_writer::label(get_string('moveselectedcoursesto'), 'movetoid', false, array('class' => 'accesshide'));
|
||||
echo html_writer::select($movetocategories, 'moveto', $category->id, null, array('id'=>'movetoid', 'class' => 'autosubmit'));
|
||||
$PAGE->requires->yui_module('moodle-core-formautosubmit',
|
||||
'M.core.init_formautosubmit',
|
||||
array(array('selectid' => 'movetoid', 'nothing' => $category->id))
|
||||
);
|
||||
echo '<input type="hidden" name="id" value="'.$category->id.'" />';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
echo '</div></form>';
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<div class="buttons">';
|
||||
if ($canmanage and $numcourses > 1) {
|
||||
// Print button to re-sort courses by name
|
||||
$url = new moodle_url('/course/category.php', array('id' => $category->id, 'resort' => 'name', 'sesskey' => sesskey()));
|
||||
echo $OUTPUT->single_button($url, get_string('resortcoursesbyname'), 'get');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:create', $context)) {
|
||||
// Print button to create a new course
|
||||
$url = new moodle_url('/course/edit.php', array('category' => $category->id, 'returnto' => 'category'));
|
||||
@ -474,6 +227,4 @@ if (!empty($CFG->enablecourserequests) && $category->id == $CFG->defaultrequestc
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
print_course_search();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -49,7 +49,7 @@
|
||||
|
||||
$message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname, true, array('context' => $coursecontext)) . " (" . $courseshortname . ")";
|
||||
|
||||
echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
|
||||
echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "manage.php?id=$course->category");
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
@ -80,7 +80,7 @@
|
||||
|
||||
echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
|
||||
|
||||
echo $OUTPUT->continue_button("category.php?id=$course->category");
|
||||
echo $OUTPUT->continue_button("manage.php?id=$course->category");
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
@ -121,8 +121,8 @@ class delete_category_form extends moodleform {
|
||||
$mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
|
||||
}
|
||||
|
||||
$mform->addElement('hidden', 'delete');
|
||||
$mform->setType('delete', PARAM_ALPHANUM);
|
||||
$mform->addElement('hidden', 'deletecat');
|
||||
$mform->setType('deletecat', PARAM_ALPHANUM);
|
||||
$mform->addElement('hidden', 'sure');
|
||||
$mform->setType('sure', PARAM_ALPHANUM);
|
||||
$mform->setDefault('sure', md5(serialize($category)));
|
||||
|
@ -90,6 +90,12 @@ if ($editform->is_cancelled()) {
|
||||
case 'category':
|
||||
$url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$categoryid));
|
||||
break;
|
||||
case 'catmanage':
|
||||
$url = new moodle_url($CFG->wwwroot.'/course/manage.php', array('id'=>$categoryid));
|
||||
break;
|
||||
case 'topcatmanage':
|
||||
$url = new moodle_url($CFG->wwwroot.'/course/manage.php');
|
||||
break;
|
||||
case 'topcat':
|
||||
$url = new moodle_url($CFG->wwwroot.'/course/');
|
||||
break;
|
||||
|
@ -85,11 +85,11 @@ $mform->set_data($category);
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
if ($id) {
|
||||
redirect($CFG->wwwroot . '/course/category.php?id=' . $id . '&categoryedit=on');
|
||||
redirect($CFG->wwwroot . '/course/manage.php?id=' . $id);
|
||||
} else if ($parent) {
|
||||
redirect($CFG->wwwroot .'/course/category.php?id=' . $parent . '&categoryedit=on');
|
||||
redirect($CFG->wwwroot .'/course/manage.php?id=' . $parent);
|
||||
} else {
|
||||
redirect($CFG->wwwroot .'/course/index.php?categoryedit=on');
|
||||
redirect($CFG->wwwroot .'/course/manage.php');
|
||||
}
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$newcategory = new stdClass();
|
||||
@ -128,7 +128,7 @@ if ($mform->is_cancelled()) {
|
||||
add_to_log(SITEID, "category", $logaction, "editcategory.php?id=$newcategory->id", $newcategory->id);
|
||||
fix_course_sortorder();
|
||||
|
||||
redirect('category.php?id='.$newcategory->id.'&categoryedit=on');
|
||||
redirect('manage.php?id='.$newcategory->id);
|
||||
}
|
||||
|
||||
// Unfortunately the navigation never generates correctly for this page because technically this page doesn't actually
|
||||
@ -150,7 +150,7 @@ if ($node) {
|
||||
// Failing that we'll override the URL, not as accurate and chances are things
|
||||
// won't be 100% correct all the time but should work most times.
|
||||
// A common reason to arrive here is having the management capability within only a particular category (not at system level).
|
||||
navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryedit' => 'on')));
|
||||
navigation_node::override_active_url(new moodle_url('/course/manage.php'));
|
||||
}
|
||||
|
||||
$PAGE->set_title($title);
|
||||
|
384
course/index.php
384
course/index.php
@ -16,8 +16,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* For most people, just lists the course categories
|
||||
* Allows the admin to create, delete and rename course categories
|
||||
* Lists the course categories
|
||||
*
|
||||
* @copyright 1999 Martin Dougiamas http://dougiamas.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -27,15 +26,6 @@
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$categoryedit = optional_param('categoryedit', -1,PARAM_BOOL);
|
||||
$delete = optional_param('delete',0,PARAM_INT);
|
||||
$hide = optional_param('hide',0,PARAM_INT);
|
||||
$show = optional_param('show',0,PARAM_INT);
|
||||
$move = optional_param('move',0,PARAM_INT);
|
||||
$moveto = optional_param('moveto',-1,PARAM_INT);
|
||||
$moveup = optional_param('moveup',0,PARAM_INT);
|
||||
$movedown = optional_param('movedown',0,PARAM_INT);
|
||||
|
||||
$site = get_site();
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
@ -44,355 +34,53 @@ $PAGE->set_url('/course/index.php');
|
||||
$PAGE->set_context($systemcontext);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
if (can_edit_in_category()) {
|
||||
if ($categoryedit !== -1) {
|
||||
$USER->editing = $categoryedit;
|
||||
}
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
$adminediting = $PAGE->user_is_editing();
|
||||
} else {
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
}
|
||||
$adminediting = false;
|
||||
}
|
||||
|
||||
$stradministration = get_string('administration');
|
||||
$strcategories = get_string('categories');
|
||||
$strcategory = get_string('category');
|
||||
$strcourses = get_string('courses');
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$straction = get_string('action');
|
||||
$strfulllistofcourses = get_string('fulllistofcourses');
|
||||
|
||||
|
||||
// Unless it's an editing admin, just print the regular listing of courses/categories.
|
||||
if (!$adminediting) {
|
||||
$showaddcoursebutton = true;
|
||||
// Print form for creating new categories.
|
||||
$countcategories = $DB->count_records('course_categories');
|
||||
if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) {
|
||||
$strcourses = get_string('courses');
|
||||
$strcategories = get_string('categories');
|
||||
|
||||
$PAGE->navbar->add($strcategories);
|
||||
$PAGE->set_title("$site->shortname: $strcategories");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_button(update_category_button());
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strcategories);
|
||||
echo $OUTPUT->skip_link_target();
|
||||
echo $OUTPUT->box_start('categorybox');
|
||||
print_whole_category_list();
|
||||
echo $OUTPUT->box_end();
|
||||
print_course_search();
|
||||
} else {
|
||||
$PAGE->navbar->add($strfulllistofcourses);
|
||||
$PAGE->set_title("$site->shortname: $strfulllistofcourses");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_button(update_category_button());
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->skip_link_target();
|
||||
echo $OUTPUT->box_start('courseboxes');
|
||||
$showaddcoursebutton = print_courses(0);
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
if (has_capability('moodle/course:create', $systemcontext) && $showaddcoursebutton) {
|
||||
// Print link to create a new course, for the 1st available category.
|
||||
$options = array('category' => $CFG->defaultrequestcategory);
|
||||
echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');
|
||||
}
|
||||
print_course_request_buttons($systemcontext);
|
||||
echo $OUTPUT->container_end();
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
$countcategories = $DB->count_records('course_categories');
|
||||
if (can_edit_in_category()) {
|
||||
$managebutton = $OUTPUT->single_button(new moodle_url('/course/manage.php'),
|
||||
get_string('managecourses'), 'get');
|
||||
}
|
||||
/// Everything else is editing on mode.
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('coursemgmt');
|
||||
|
||||
/// Delete a category.
|
||||
if (!empty($delete) and confirm_sesskey()) {
|
||||
if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) {
|
||||
print_error('invalidcategoryid');
|
||||
$showaddcoursebutton = true;
|
||||
if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) {
|
||||
$strcategories = get_string('categories');
|
||||
|
||||
$PAGE->set_title("$site->shortname: $strcategories");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
if (isset($managebutton)) {
|
||||
$PAGE->set_button($managebutton);
|
||||
}
|
||||
$context = context_coursecat::instance($delete);
|
||||
require_capability('moodle/category:manage', $context);
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent));
|
||||
|
||||
$heading = get_string('deletecategory', 'moodle', format_string($deletecat->name, true, array('context' => $context)));
|
||||
require_once('delete_category_form.php');
|
||||
$mform = new delete_category_form(null, $deletecat);
|
||||
$mform->set_data(array('delete'=>$delete));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('index.php');
|
||||
|
||||
} else if (!$data= $mform->get_data()) {
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($heading);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($heading);
|
||||
echo $OUTPUT->heading($strcategories);
|
||||
echo $OUTPUT->skip_link_target();
|
||||
echo $OUTPUT->box_start('categorybox');
|
||||
print_whole_category_list();
|
||||
echo $OUTPUT->box_end();
|
||||
print_course_search();
|
||||
} else {
|
||||
$strfulllistofcourses = get_string('fulllistofcourses');
|
||||
|
||||
if ($data->fulldelete) {
|
||||
$deletedcourses = category_delete_full($deletecat, true);
|
||||
|
||||
foreach($deletedcourses as $course) {
|
||||
echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
|
||||
}
|
||||
echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name, true, array('context' => $context))), 'notifysuccess');
|
||||
|
||||
} else {
|
||||
category_delete_move($deletecat, $data->newparent, true);
|
||||
$PAGE->set_title("$site->shortname: $strfulllistofcourses");
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
if (isset($managebutton)) {
|
||||
$PAGE->set_button($managebutton);
|
||||
}
|
||||
|
||||
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
|
||||
if ($delete == $CFG->defaultrequestcategory) {
|
||||
set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent'=>0)));
|
||||
}
|
||||
|
||||
echo $OUTPUT->continue_button('index.php');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->skip_link_target();
|
||||
echo $OUTPUT->box_start('courseboxes');
|
||||
$showaddcoursebutton = print_courses(0);
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
||||
/// Create a default category if necessary
|
||||
if (!$categories = get_categories()) { /// No category yet!
|
||||
// Try and make one
|
||||
$tempcat = new stdClass();
|
||||
$tempcat->name = get_string('miscellaneous');
|
||||
$tempcat->id = $DB->insert_record('course_categories', $tempcat);
|
||||
$tempcat->context = context_coursecat::instance($tempcat->id);
|
||||
mark_context_dirty('/'.SYSCONTEXTID);
|
||||
fix_course_sortorder(); // Required to build course_categories.depth and .path.
|
||||
set_config('defaultrequestcategory', $tempcat->id);
|
||||
}
|
||||
|
||||
/// Move a category to a new parent if required
|
||||
if (!empty($move) and ($moveto >= 0) and confirm_sesskey()) {
|
||||
if ($cattomove = $DB->get_record('course_categories', array('id'=>$move))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($cattomove->parent));
|
||||
if ($cattomove->parent != $moveto) {
|
||||
$newparent = $DB->get_record('course_categories', array('id'=>$moveto));
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($moveto));
|
||||
move_category($cattomove, $newparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hide or show a category
|
||||
if ($hide and confirm_sesskey()) {
|
||||
if ($tempcat = $DB->get_record('course_categories', array('id'=>$hide))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent));
|
||||
if ($tempcat->visible == 1) {
|
||||
course_category_hide($tempcat);
|
||||
}
|
||||
}
|
||||
} else if ($show and confirm_sesskey()) {
|
||||
if ($tempcat = $DB->get_record('course_categories', array('id'=>$show))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent));
|
||||
if ($tempcat->visible == 0) {
|
||||
course_category_show($tempcat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Move a category up or down
|
||||
if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) {
|
||||
fix_course_sortorder();
|
||||
$swapcategory = NULL;
|
||||
|
||||
if (!empty($moveup)) {
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($moveup));
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) {
|
||||
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder<? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder DESC', '*', 0, 1)) {
|
||||
$swapcategory = reset($swapcategory);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($movedown));
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) {
|
||||
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) {
|
||||
$swapcategory = reset($swapcategory);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($swapcategory and $movecategory) {
|
||||
$DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id));
|
||||
$DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id));
|
||||
add_to_log(SITEID, "category", "move", "editcategory.php?id=$movecategory->id", $movecategory->id);
|
||||
}
|
||||
|
||||
// finally reorder courses
|
||||
fix_course_sortorder();
|
||||
}
|
||||
|
||||
/// Print headings
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strcategories);
|
||||
|
||||
/// Print out the categories with all the knobs
|
||||
$strcategories = get_string('categories');
|
||||
$strcourses = get_string('courses');
|
||||
$strmovecategoryto = get_string('movecategoryto');
|
||||
$stredit = get_string('edit');
|
||||
|
||||
$displaylist = array();
|
||||
$parentlist = array();
|
||||
|
||||
$displaylist[0] = get_string('top');
|
||||
make_categories_list($displaylist, $parentlist);
|
||||
|
||||
echo '<table id="coursecategories" class="admintable generaltable editcourse"><tr class="header">';
|
||||
echo '<th class="header" scope="col">'.$strcategories.'</th>';
|
||||
echo '<th class="header" scope="col">'.$strcourses.'</th>';
|
||||
echo '<th class="header" scope="col">'.$stredit.'</th>';
|
||||
echo '<th class="header" scope="col">'.$strmovecategoryto.'</th>';
|
||||
echo '</tr>';
|
||||
|
||||
print_category_edit(NULL, $displaylist, $parentlist);
|
||||
echo '</table>';
|
||||
|
||||
echo '<div class="buttons">';
|
||||
if (has_capability('moodle/course:create', $systemcontext)) {
|
||||
// print create course link to first category
|
||||
$options = array('category' => $CFG->defaultrequestcategory);
|
||||
$options['returnto'] = 'topcat';
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
if (has_capability('moodle/course:create', $systemcontext) && $showaddcoursebutton) {
|
||||
// Print link to create a new course, for the 1st available category.
|
||||
$options = array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat');
|
||||
echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');
|
||||
}
|
||||
|
||||
// Print button for creating new categories
|
||||
if (has_capability('moodle/category:manage', $systemcontext)) {
|
||||
$options = array('parent'=>0);
|
||||
echo $OUTPUT->single_button(new moodle_url('editcategory.php', $options), get_string('addnewcategory'), 'get');
|
||||
}
|
||||
|
||||
print_course_request_buttons($systemcontext);
|
||||
echo '</div>';
|
||||
|
||||
echo $OUTPUT->container_end();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) {
|
||||
/// Recursive function to print all the categories ready for editing
|
||||
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
|
||||
static $str = NULL;
|
||||
|
||||
if (is_null($str)) {
|
||||
$str = new stdClass;
|
||||
$str->edit = get_string('edit');
|
||||
$str->delete = get_string('delete');
|
||||
$str->moveup = get_string('moveup');
|
||||
$str->movedown = get_string('movedown');
|
||||
$str->edit = get_string('editthiscategory');
|
||||
$str->hide = get_string('hide');
|
||||
$str->show = get_string('show');
|
||||
$str->cohorts = get_string('cohorts', 'cohort');
|
||||
$str->spacer = $OUTPUT->spacer().' ';
|
||||
}
|
||||
|
||||
if (!empty($category)) {
|
||||
|
||||
if (!isset($category->context)) {
|
||||
$category->context = context_coursecat::instance($category->id);
|
||||
}
|
||||
|
||||
echo '<tr><td class="leftalign name">';
|
||||
for ($i=0; $i<$depth;$i++) {
|
||||
echo ' ';
|
||||
}
|
||||
$linkcss = $category->visible ? '' : ' class="dimmed" ';
|
||||
echo '<a '.$linkcss.' title="'.$str->edit.'" '.
|
||||
' href="category.php?id='.$category->id.'&categoryedit=on&sesskey='.sesskey().'">'.
|
||||
format_string($category->name, true, array('context' => $category->context)).'</a>';
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="centeralign count">'.$category->coursecount.'</td>';
|
||||
|
||||
echo '<td class="centeralign icons">'; /// Print little icons
|
||||
|
||||
if (has_capability('moodle/category:manage', $category->context)) {
|
||||
echo '<a title="'.$str->edit.'" href="editcategory.php?id='.$category->id.'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.$str->edit.'" /></a> ';
|
||||
|
||||
echo '<a title="'.$str->delete.'" href="index.php?delete='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.$str->delete.'" /></a> ';
|
||||
|
||||
if (!empty($category->visible)) {
|
||||
echo '<a title="'.$str->hide.'" href="index.php?hide='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/hide') . '" class="iconsmall" alt="'.$str->hide.'" /></a> ';
|
||||
} else {
|
||||
echo '<a title="'.$str->show.'" href="index.php?show='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/show') . '" class="iconsmall" alt="'.$str->show.'" /></a> ';
|
||||
}
|
||||
|
||||
if (has_capability('moodle/cohort:manage', $category->context) or has_capability('moodle/cohort:view', $category->context)) {
|
||||
echo '<a title="'.$str->cohorts.'" href="'.$CFG->wwwroot.'/cohort/index.php?contextid='.$category->context->id.'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/cohort') . '" class="iconsmall" alt="'.$str->cohorts.'" /></a> ';
|
||||
}
|
||||
|
||||
if ($up) {
|
||||
echo '<a title="'.$str->moveup.'" href="index.php?moveup='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/up') . '" class="iconsmall" alt="'.$str->moveup.'" /></a> ';
|
||||
} else {
|
||||
echo $str->spacer;
|
||||
}
|
||||
if ($down) {
|
||||
echo '<a title="'.$str->movedown.'" href="index.php?movedown='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/down') . '" class="iconsmall" alt="'.$str->movedown.'" /></a> ';
|
||||
} else {
|
||||
echo $str->spacer;
|
||||
}
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="leftalign">';
|
||||
if (has_capability('moodle/category:manage', $category->context)) {
|
||||
$tempdisplaylist = $displaylist;
|
||||
unset($tempdisplaylist[$category->id]);
|
||||
foreach ($parentslist as $key => $parents) {
|
||||
if (in_array($category->id, $parents)) {
|
||||
unset($tempdisplaylist[$key]);
|
||||
}
|
||||
}
|
||||
$popupurl = new moodle_url("index.php?move=$category->id&sesskey=".sesskey());
|
||||
$select = new single_select($popupurl, 'moveto', $tempdisplaylist, $category->parent, null, "moveform$category->id");
|
||||
$select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide'));
|
||||
echo $OUTPUT->render($select);
|
||||
}
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
} else {
|
||||
$category = new stdClass();
|
||||
$category->id = '0';
|
||||
}
|
||||
|
||||
if ($categories = get_categories($category->id)) { // Print all the children recursively
|
||||
$countcats = count($categories);
|
||||
$count = 0;
|
||||
$first = true;
|
||||
$last = false;
|
||||
foreach ($categories as $cat) {
|
||||
$count++;
|
||||
if ($count == $countcats) {
|
||||
$last = true;
|
||||
}
|
||||
$up = $first ? false : true;
|
||||
$down = $last ? false : true;
|
||||
$first = false;
|
||||
|
||||
print_category_edit($cat, $displaylist, $parentslist, $depth+1, $up, $down);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1665,41 +1665,6 @@ function can_edit_in_category($categoryid = 0) {
|
||||
return has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the turn editing on/off button on course/index.php or course/category.php.
|
||||
*
|
||||
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
|
||||
* @return string HTML of the editing button, or empty string, if this user is not allowed
|
||||
* to see it.
|
||||
*/
|
||||
function update_category_button($categoryid = 0) {
|
||||
global $CFG, $PAGE, $OUTPUT;
|
||||
|
||||
// Check permissions.
|
||||
if (!can_edit_in_category($categoryid)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Work out the appropriate action.
|
||||
if ($PAGE->user_is_editing()) {
|
||||
$label = get_string('turneditingoff');
|
||||
$edit = 'off';
|
||||
} else {
|
||||
$label = get_string('turneditingon');
|
||||
$edit = 'on';
|
||||
}
|
||||
|
||||
// Generate the button HTML.
|
||||
$options = array('categoryedit' => $edit, 'sesskey' => sesskey());
|
||||
if ($categoryid) {
|
||||
$options['id'] = $categoryid;
|
||||
$page = 'category.php';
|
||||
} else {
|
||||
$page = 'index.php';
|
||||
}
|
||||
return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Print courses in category. If category is 0 then all courses are printed.
|
||||
* @param int|stdClass $category category object or id.
|
||||
|
716
course/manage.php
Normal file
716
course/manage.php
Normal file
@ -0,0 +1,716 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Allows the admin to create, delete and rename course categories,
|
||||
* rearrange courses
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("../config.php");
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT); // Category id
|
||||
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
||||
$sesskey = optional_param('sesskey', '', PARAM_RAW);
|
||||
$perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // how many per page
|
||||
|
||||
// actions to manage courses
|
||||
$hide = optional_param('hide', 0, PARAM_INT);
|
||||
$show = optional_param('show', 0, PARAM_INT);
|
||||
$moveup = optional_param('moveup', 0, PARAM_INT);
|
||||
$movedown = optional_param('movedown', 0, PARAM_INT);
|
||||
$moveto = optional_param('moveto', 0, PARAM_INT);
|
||||
$resort = optional_param('resort', 0, PARAM_BOOL);
|
||||
|
||||
// actions to manage categories
|
||||
$deletecat = optional_param('deletecat',0,PARAM_INT);
|
||||
$hidecat = optional_param('hidecat',0,PARAM_INT);
|
||||
$showcat = optional_param('showcat',0,PARAM_INT);
|
||||
$movecat = optional_param('movecat',0,PARAM_INT);
|
||||
$movetocat = optional_param('movetocat',-1,PARAM_INT);
|
||||
$moveupcat = optional_param('moveupcat',0,PARAM_INT);
|
||||
$movedowncat = optional_param('movedowncat',0,PARAM_INT);
|
||||
|
||||
require_login();
|
||||
$PAGE->set_url(new moodle_url('/course/manage.php', array('id' => $id)));
|
||||
if ($id) {
|
||||
$PAGE->set_category_by_id($id);
|
||||
// This is sure to be the category context
|
||||
$context = $PAGE->context;
|
||||
// And the object has been loaded for us no need for another DB call
|
||||
$category = $PAGE->category;
|
||||
} else {
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
// create fake object for 0-category
|
||||
$category = (object)array(
|
||||
'id' => 0,
|
||||
'sortorder' => 0,
|
||||
'visible' => true
|
||||
);
|
||||
}
|
||||
|
||||
if (!can_edit_in_category($category->id)) {
|
||||
if ($category->id) {
|
||||
redirect(new moodle_url('/course/category.php', array('id' => $category->id)));
|
||||
} else {
|
||||
redirect(new moodle_url('/course/index.php'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$category->visible) {
|
||||
require_capability('moodle/category:viewhiddencategories', $context);
|
||||
}
|
||||
|
||||
$canmanage = has_capability('moodle/category:manage', $context);
|
||||
$sesskeyprovided = !empty($sesskey) && confirm_sesskey($sesskey);
|
||||
|
||||
/// Create a default category if necessary
|
||||
if (!$id && (!$categories = get_categories())) { /// No category yet!
|
||||
// Try and make one
|
||||
$tempcat = new stdClass();
|
||||
$tempcat->name = get_string('miscellaneous');
|
||||
$tempcat->id = $DB->insert_record('course_categories', $tempcat);
|
||||
$tempcat->context = context_coursecat::instance($tempcat->id);
|
||||
mark_context_dirty('/'.SYSCONTEXTID);
|
||||
fix_course_sortorder(); // Required to build course_categories.depth and .path.
|
||||
set_config('defaultrequestcategory', $tempcat->id);
|
||||
}
|
||||
|
||||
// Process any category actions.
|
||||
|
||||
/// Delete a category.
|
||||
if (!empty($deletecat) and confirm_sesskey()) {
|
||||
if (!$cattodelete = $DB->get_record('course_categories', array('id'=>$deletecat))) {
|
||||
print_error('invalidcategoryid');
|
||||
}
|
||||
$context = context_coursecat::instance($deletecat);
|
||||
require_capability('moodle/category:manage', $context);
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($cattodelete->parent));
|
||||
|
||||
$heading = get_string('deletecategory', 'moodle', format_string($cattodelete->name, true, array('context' => $context)));
|
||||
require_once('delete_category_form.php');
|
||||
$mform = new delete_category_form(null, $cattodelete);
|
||||
$mform->set_data(array('deletecat'=>$deletecat));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('manage.php');
|
||||
|
||||
} else if (!$data= $mform->get_data()) {
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($heading);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($heading);
|
||||
|
||||
if ($data->fulldelete) {
|
||||
$deletedcourses = category_delete_full($cattodelete, true);
|
||||
|
||||
foreach($deletedcourses as $course) {
|
||||
echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
|
||||
}
|
||||
echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($cattodelete->name, true, array('context' => $context))), 'notifysuccess');
|
||||
|
||||
} else {
|
||||
category_delete_move($cattodelete, $data->newparent, true);
|
||||
}
|
||||
|
||||
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
|
||||
if ($deletecat == $CFG->defaultrequestcategory) {
|
||||
set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent'=>0)));
|
||||
}
|
||||
|
||||
echo $OUTPUT->continue_button('manage.php');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
|
||||
/// Move a category to a new parent if required
|
||||
if (!empty($movecat) and ($movetocat >= 0) and confirm_sesskey()) {
|
||||
if ($cattomove = $DB->get_record('course_categories', array('id'=>$movecat))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($cattomove->parent));
|
||||
if ($cattomove->parent != $movetocat) {
|
||||
$newparent = $DB->get_record('course_categories', array('id'=>$movetocat));
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($movetocat));
|
||||
move_category($cattomove, $newparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hide or show a category
|
||||
if ($hidecat and confirm_sesskey()) {
|
||||
if ($tempcat = $DB->get_record('course_categories', array('id'=>$hidecat))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent));
|
||||
if ($tempcat->visible == 1) {
|
||||
course_category_hide($tempcat);
|
||||
}
|
||||
}
|
||||
} else if ($showcat and confirm_sesskey()) {
|
||||
if ($tempcat = $DB->get_record('course_categories', array('id'=>$showcat))) {
|
||||
require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent));
|
||||
if ($tempcat->visible == 0) {
|
||||
course_category_show($tempcat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Move a category up or down
|
||||
if ((!empty($moveupcat) or !empty($movedowncat)) and confirm_sesskey()) {
|
||||
fix_course_sortorder();
|
||||
$swapcategory = NULL;
|
||||
|
||||
if (!empty($moveupcat)) {
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($moveupcat));
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveupcat))) {
|
||||
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder<? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder DESC', '*', 0, 1)) {
|
||||
$swapcategory = reset($swapcategory);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($movedowncat));
|
||||
if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedowncat))) {
|
||||
if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) {
|
||||
$swapcategory = reset($swapcategory);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($swapcategory and $movecategory) {
|
||||
$DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id));
|
||||
$DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id));
|
||||
add_to_log(SITEID, "category", "move", "editcategory.php?id=$movecategory->id", $movecategory->id);
|
||||
}
|
||||
|
||||
// finally reorder courses
|
||||
fix_course_sortorder();
|
||||
}
|
||||
|
||||
// Resort courses
|
||||
if ($canmanage && $resort && $sesskeyprovided) {
|
||||
// Resort the category if requested
|
||||
if ($courses = get_courses($category->id, '', 'c.id,c.fullname,c.sortorder')) {
|
||||
collatorlib::asort_objects_by_property($courses, 'fullname', collatorlib::SORT_NATURAL);
|
||||
$i = 1;
|
||||
foreach ($courses as $course) {
|
||||
$DB->set_field('course', 'sortorder', $category->sortorder+$i, array('id'=>$course->id));
|
||||
$i++;
|
||||
}
|
||||
fix_course_sortorder(); // should not be needed
|
||||
}
|
||||
}
|
||||
|
||||
// Process any course actions.
|
||||
if ($sesskeyprovided) {
|
||||
|
||||
// Move a specified course to a new category
|
||||
if (!empty($moveto) and $data = data_submitted()) {
|
||||
// Some courses are being moved
|
||||
// user must have category update in both cats to perform this
|
||||
require_capability('moodle/category:manage', $context);
|
||||
require_capability('moodle/category:manage', context_coursecat::instance($moveto));
|
||||
|
||||
if (!$destcategory = $DB->get_record('course_categories', array('id' => $data->moveto))) {
|
||||
print_error('cannotfindcategory', '', '', $data->moveto);
|
||||
}
|
||||
|
||||
$courses = array();
|
||||
foreach ($data as $key => $value) {
|
||||
if (preg_match('/^c\d+$/', $key)) {
|
||||
$courseid = substr($key, 1);
|
||||
array_push($courses, $courseid);
|
||||
|
||||
// check this course's category
|
||||
if ($movingcourse = $DB->get_record('course', array('id'=>$courseid))) {
|
||||
if ($movingcourse->category != $id ) {
|
||||
print_error('coursedoesnotbelongtocategory');
|
||||
}
|
||||
} else {
|
||||
print_error('cannotfindcourse');
|
||||
}
|
||||
}
|
||||
}
|
||||
move_courses($courses, $data->moveto);
|
||||
}
|
||||
|
||||
// Hide or show a course
|
||||
if (!empty($hide) or !empty($show)) {
|
||||
if (!empty($hide)) {
|
||||
$course = $DB->get_record('course', array('id' => $hide));
|
||||
$visible = 0;
|
||||
} else {
|
||||
$course = $DB->get_record('course', array('id' => $show));
|
||||
$visible = 1;
|
||||
}
|
||||
|
||||
if ($course) {
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
require_capability('moodle/course:visibility', $coursecontext);
|
||||
// Set the visibility of the course. we set the old flag when user manually changes visibility of course.
|
||||
$DB->update_record('course', array('id' => $course->id, 'visible' => $visible, 'visibleold' => $visible, 'timemodified' => time()));
|
||||
add_to_log($course->id, "course", ($visible ? 'show' : 'hide'), "edit.php?id=$course->id", $course->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Move a course up or down
|
||||
if (!empty($moveup) or !empty($movedown)) {
|
||||
require_capability('moodle/category:manage', $context);
|
||||
|
||||
// Ensure the course order has continuous ordering
|
||||
fix_course_sortorder();
|
||||
$swapcourse = NULL;
|
||||
|
||||
if (!empty($moveup)) {
|
||||
if ($movecourse = $DB->get_record('course', array('id' => $moveup))) {
|
||||
$swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder - 1));
|
||||
}
|
||||
} else {
|
||||
if ($movecourse = $DB->get_record('course', array('id' => $movedown))) {
|
||||
$swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder + 1));
|
||||
}
|
||||
}
|
||||
if ($swapcourse and $movecourse) {
|
||||
// check course's category
|
||||
if ($movecourse->category != $id) {
|
||||
print_error('coursedoesnotbelongtocategory');
|
||||
}
|
||||
$DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id));
|
||||
$DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id));
|
||||
add_to_log($movecourse->id, "course", "move", "edit.php?id=$movecourse->id", $movecourse->id);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of editing stuff
|
||||
|
||||
// Prepare the standard URL params for this page. We'll need them later.
|
||||
$urlparams = array('id' => $id);
|
||||
if ($page) {
|
||||
$urlparams['page'] = $page;
|
||||
}
|
||||
if ($perpage) {
|
||||
$urlparams['perpage'] = $perpage;
|
||||
}
|
||||
|
||||
// Begin output
|
||||
$PAGE->set_pagelayout('coursecategory');
|
||||
if (can_edit_in_category()) {
|
||||
// Integrate into the admin tree only if the user can edit categories at the top level,
|
||||
// otherwise the admin block does not appear to this user, and you get an error.
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
if ($id) {
|
||||
navigation_node::override_active_url(new moodle_url('/course/category.php', array('id' => $id)));
|
||||
}
|
||||
admin_externalpage_setup('coursemgmt', '', $urlparams, $CFG->wwwroot . '/course/manage.php');
|
||||
|
||||
$settingsnode = $PAGE->settingsnav->find_active_node();
|
||||
if ($id && $settingsnode) {
|
||||
$settingsnode->make_inactive();
|
||||
$settingsnode->force_open();
|
||||
$PAGE->navbar->add($settingsnode->text, $settingsnode->action);
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
} else {
|
||||
$site = get_site();
|
||||
$PAGE->set_title("$site->shortname: $category->name");
|
||||
$PAGE->set_heading($site->fullname);
|
||||
$PAGE->set_button(print_course_search('', true, 'navbar'));
|
||||
echo $OUTPUT->header();
|
||||
}
|
||||
|
||||
if (!$category->id) {
|
||||
/// Print out the categories with all the knobs
|
||||
$strcategories = get_string('categories');
|
||||
$strcourses = get_string('courses');
|
||||
$strmovecategoryto = get_string('movecategoryto');
|
||||
$stredit = get_string('edit');
|
||||
|
||||
$displaylist = array();
|
||||
$parentlist = array();
|
||||
|
||||
$displaylist[0] = get_string('top');
|
||||
make_categories_list($displaylist, $parentlist);
|
||||
|
||||
echo '<table id="coursecategories" class="admintable generaltable editcourse"><tr class="header">';
|
||||
echo '<th class="header" scope="col">'.$strcategories.'</th>';
|
||||
echo '<th class="header" scope="col">'.$strcourses.'</th>';
|
||||
echo '<th class="header" scope="col">'.$stredit.'</th>';
|
||||
echo '<th class="header" scope="col">'.$strmovecategoryto.'</th>';
|
||||
echo '</tr>';
|
||||
|
||||
print_category_edit(NULL, $displaylist, $parentlist);
|
||||
echo '</table>';
|
||||
} else {
|
||||
/// Print the category selector
|
||||
$displaylist = array();
|
||||
$notused = array();
|
||||
make_categories_list($displaylist, $notused);
|
||||
|
||||
echo '<div class="categorypicker">';
|
||||
$select = new single_select(new moodle_url('/course/manage.php'), 'id',
|
||||
// TODO 'Top' => string
|
||||
array(0 => 'Top') + $displaylist, $category->id, null, 'switchcategory');
|
||||
$select->set_label(get_string('categories').':');
|
||||
echo $OUTPUT->render($select);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ($canmanage) {
|
||||
echo $OUTPUT->container_start('buttons');
|
||||
|
||||
// Print button to update this category
|
||||
if ($category->id) {
|
||||
$url = new moodle_url('/course/editcategory.php', array('id' => $category->id));
|
||||
echo $OUTPUT->single_button($url, get_string('editcategorythis'), 'get');
|
||||
}
|
||||
|
||||
// Print button for creating new categories
|
||||
$url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
|
||||
echo $OUTPUT->single_button($url, get_string('addsubcategory'), 'get');
|
||||
|
||||
echo $OUTPUT->container_end();
|
||||
}
|
||||
|
||||
if ($category->id) {
|
||||
// Print out all the sub-categories (plain mode)
|
||||
// In order to view hidden subcategories the user must have the viewhiddencategories
|
||||
// capability in the current category.
|
||||
if (has_capability('moodle/category:viewhiddencategories', $context)) {
|
||||
$categorywhere = '';
|
||||
} else {
|
||||
$categorywhere = 'AND cc.visible = 1';
|
||||
}
|
||||
// We're going to preload the context for the subcategory as we know that we
|
||||
// need it later on for formatting.
|
||||
|
||||
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
|
||||
$sql = "SELECT cc.*, $ctxselect
|
||||
FROM {course_categories} cc
|
||||
JOIN {context} ctx ON cc.id = ctx.instanceid
|
||||
WHERE cc.parent = :parentid AND
|
||||
ctx.contextlevel = :contextlevel
|
||||
$categorywhere
|
||||
ORDER BY cc.sortorder ASC";
|
||||
$subcategories = $DB->get_recordset_sql($sql, array('parentid' => $category->id, 'contextlevel' => CONTEXT_COURSECAT));
|
||||
// Prepare a table to display the sub categories.
|
||||
$table = new html_table;
|
||||
$table->attributes = array('border' => '0', 'cellspacing' => '2', 'cellpadding' => '4', 'class' => 'generalbox boxaligncenter category_subcategories');
|
||||
$table->head = array(new lang_string('subcategories'));
|
||||
$table->data = array();
|
||||
$baseurl = new moodle_url('/course/manage.php');
|
||||
foreach ($subcategories as $subcategory) {
|
||||
// Preload the context we will need it to format the category name shortly.
|
||||
context_helper::preload_from_record($subcategory);
|
||||
$context = context_coursecat::instance($subcategory->id);
|
||||
// Prepare the things we need to create a link to the subcategory
|
||||
$attributes = $subcategory->visible ? array() : array('class' => 'dimmed');
|
||||
$text = format_string($subcategory->name, true, array('context' => $context));
|
||||
// Add the subcategory to the table
|
||||
$baseurl->param('id', $subcategory->id);
|
||||
$table->data[] = array(html_writer::link($baseurl, $text, $attributes));
|
||||
}
|
||||
|
||||
$subcategorieswereshown = (count($table->data) > 0);
|
||||
if ($subcategorieswereshown) {
|
||||
echo html_writer::table($table);
|
||||
}
|
||||
|
||||
$courses = get_courses_page($category->id, 'c.sortorder ASC',
|
||||
'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible',
|
||||
$totalcount, $page*$perpage, $perpage);
|
||||
$numcourses = count($courses);
|
||||
} else {
|
||||
$subcategorieswereshown = true;
|
||||
$courses = array();
|
||||
$numcourses = $totalcount = 0;
|
||||
}
|
||||
|
||||
if (!$courses) {
|
||||
// There is no course to display.
|
||||
if (empty($subcategorieswereshown)) {
|
||||
echo $OUTPUT->heading(get_string("nocoursesyet"));
|
||||
}
|
||||
} else {
|
||||
// display a basic list of courses with paging/editing options.
|
||||
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "/course/manage.php?id=$category->id&perpage=$perpage");
|
||||
|
||||
echo '<form id="movecourses" action="manage.php" method="post"><div>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<table border="0" cellspacing="2" cellpadding="4" class="generalbox boxaligncenter"><tr>';
|
||||
echo '<th class="header" scope="col">'.get_string('courses').'</th>';
|
||||
echo '<th class="header" scope="col">'.get_string('edit').'</th>';
|
||||
echo '<th class="header" scope="col">'.get_string('select').'</th>';
|
||||
echo '</tr>';
|
||||
|
||||
$count = 0;
|
||||
$abletomovecourses = false; // for now
|
||||
|
||||
// Checking if we are at the first or at the last page, to allow courses to
|
||||
// be moved up and down beyond the paging border
|
||||
if ($totalcount > $perpage) {
|
||||
$atfirstpage = ($page == 0);
|
||||
if ($perpage > 0) {
|
||||
$atlastpage = (($page + 1) == ceil($totalcount / $perpage));
|
||||
} else {
|
||||
$atlastpage = true;
|
||||
}
|
||||
} else {
|
||||
$atfirstpage = true;
|
||||
$atlastpage = true;
|
||||
}
|
||||
|
||||
$baseurl = new moodle_url('/course/manage.php', $urlparams + array('sesskey' => sesskey()));
|
||||
foreach ($courses as $acourse) {
|
||||
$coursecontext = context_course::instance($acourse->id);
|
||||
|
||||
$count++;
|
||||
$up = ($count > 1 || !$atfirstpage);
|
||||
$down = ($count < $numcourses || !$atlastpage);
|
||||
|
||||
$linkcss = $acourse->visible ? '' : ' class="dimmed" ';
|
||||
echo '<tr>';
|
||||
$coursename = get_course_display_name_for_list($acourse);
|
||||
echo '<td><a '.$linkcss.' href="view.php?id='.$acourse->id.'">'. format_string($coursename) .'</a></td>';
|
||||
echo '<td>';
|
||||
if (has_capability('moodle/course:update', $coursecontext)) {
|
||||
$url = new moodle_url('/course/edit.php', array('id' => $acourse->id, 'category' => $id, 'returnto' => 'catmanage'));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/edit', get_string('settings')));
|
||||
}
|
||||
|
||||
// role assignment link
|
||||
if (has_capability('moodle/course:enrolreview', $coursecontext)) {
|
||||
$url = new moodle_url('/enrol/users.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/enrolusers', get_string('enrolledusers', 'enrol')));
|
||||
}
|
||||
|
||||
if (can_delete_course($acourse->id)) {
|
||||
$url = new moodle_url('/course/delete.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/delete', get_string('delete')));
|
||||
}
|
||||
|
||||
// MDL-8885, users with no capability to view hidden courses, should not be able to lock themselves out
|
||||
if (has_capability('moodle/course:visibility', $coursecontext) && has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
|
||||
if (!empty($acourse->visible)) {
|
||||
$url = new moodle_url($baseurl, array('hide' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/hide', get_string('hide')));
|
||||
} else {
|
||||
$url = new moodle_url($baseurl, array('show' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/show', get_string('show')));
|
||||
}
|
||||
}
|
||||
|
||||
if (has_capability('moodle/backup:backupcourse', $coursecontext)) {
|
||||
$url = new moodle_url('/backup/backup.php', array('id' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/backup', get_string('backup')));
|
||||
}
|
||||
|
||||
if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
|
||||
$url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/restore', get_string('restore')));
|
||||
}
|
||||
|
||||
if ($canmanage) {
|
||||
if ($up) {
|
||||
$url = new moodle_url($baseurl, array('moveup' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/up', get_string('moveup')));
|
||||
}
|
||||
|
||||
if ($down) {
|
||||
$url = new moodle_url($baseurl, array('movedown' => $acourse->id));
|
||||
echo $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')));
|
||||
}
|
||||
$abletomovecourses = true;
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
echo '<td align="center">';
|
||||
echo '<input type="checkbox" name="c'.$acourse->id.'" />';
|
||||
echo '</td>';
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
if ($abletomovecourses) {
|
||||
$movetocategories = array();
|
||||
$notused = array();
|
||||
make_categories_list($movetocategories, $notused, 'moodle/category:manage');
|
||||
$movetocategories[$category->id] = get_string('moveselectedcoursesto');
|
||||
echo '<tr><td colspan="3" align="right">';
|
||||
echo html_writer::label(get_string('moveselectedcoursesto'), 'movetoid', false, array('class' => 'accesshide'));
|
||||
echo html_writer::select($movetocategories, 'moveto', $category->id, null, array('id'=>'movetoid', 'class' => 'autosubmit'));
|
||||
$PAGE->requires->yui_module('moodle-core-formautosubmit',
|
||||
'M.core.init_formautosubmit',
|
||||
array(array('selectid' => 'movetoid', 'nothing' => $category->id))
|
||||
);
|
||||
echo '<input type="hidden" name="id" value="'.$category->id.'" />';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
echo '</div></form>';
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<div class="buttons">';
|
||||
if ($canmanage and $numcourses > 1) {
|
||||
// Print button to re-sort courses by name
|
||||
$url = new moodle_url('/course/manage.php', array('id' => $category->id, 'resort' => 'name', 'sesskey' => sesskey()));
|
||||
echo $OUTPUT->single_button($url, get_string('resortcoursesbyname'), 'get');
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:create', $context)) {
|
||||
// Print button to create a new course
|
||||
$url = new moodle_url('/course/edit.php');
|
||||
if (!$category->id) {
|
||||
$url->params(array('category' => $CFG->defaultrequestcategory,
|
||||
'returnto' => 'topcatmanage'));
|
||||
} else {
|
||||
$url->params(array('category' => $category->id,
|
||||
'returnto' => 'catmanage'));
|
||||
}
|
||||
echo $OUTPUT->single_button($url, get_string('addnewcourse'), 'get');
|
||||
}
|
||||
|
||||
if (!empty($CFG->enablecourserequests) && $category->id == $CFG->defaultrequestcategory) {
|
||||
print_course_request_buttons(context_system::instance());
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
print_course_search();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) {
|
||||
/// Recursive function to print all the categories ready for editing
|
||||
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
|
||||
static $str = NULL;
|
||||
|
||||
if (is_null($str)) {
|
||||
$str = new stdClass;
|
||||
$str->edit = get_string('edit');
|
||||
$str->delete = get_string('delete');
|
||||
$str->moveup = get_string('moveup');
|
||||
$str->movedown = get_string('movedown');
|
||||
$str->edit = get_string('editthiscategory');
|
||||
$str->hide = get_string('hide');
|
||||
$str->show = get_string('show');
|
||||
$str->cohorts = get_string('cohorts', 'cohort');
|
||||
$str->spacer = $OUTPUT->spacer().' ';
|
||||
}
|
||||
|
||||
if (!empty($category)) {
|
||||
|
||||
if (!isset($category->context)) {
|
||||
$category->context = context_coursecat::instance($category->id);
|
||||
}
|
||||
|
||||
echo '<tr><td class="leftalign name">';
|
||||
for ($i=0; $i<$depth;$i++) {
|
||||
echo ' ';
|
||||
}
|
||||
$linkcss = $category->visible ? '' : ' class="dimmed" ';
|
||||
echo '<a '.$linkcss.' title="'.$str->edit.'" '.
|
||||
' href="manage.php?id='.$category->id.'&sesskey='.sesskey().'">'.
|
||||
format_string($category->name, true, array('context' => $category->context)).'</a>';
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="centeralign count">'.$category->coursecount.'</td>';
|
||||
|
||||
echo '<td class="centeralign icons">'; /// Print little icons
|
||||
|
||||
if (has_capability('moodle/category:manage', $category->context)) {
|
||||
echo '<a title="'.$str->edit.'" href="editcategory.php?id='.$category->id.'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.$str->edit.'" /></a> ';
|
||||
|
||||
echo '<a title="'.$str->delete.'" href="manage.php?deletecat='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.$str->delete.'" /></a> ';
|
||||
|
||||
if (!empty($category->visible)) {
|
||||
echo '<a title="'.$str->hide.'" href="manage.php?hidecat='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/hide') . '" class="iconsmall" alt="'.$str->hide.'" /></a> ';
|
||||
} else {
|
||||
echo '<a title="'.$str->show.'" href="manage.php?showcat='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/show') . '" class="iconsmall" alt="'.$str->show.'" /></a> ';
|
||||
}
|
||||
|
||||
if (has_capability('moodle/cohort:manage', $category->context) or has_capability('moodle/cohort:view', $category->context)) {
|
||||
echo '<a title="'.$str->cohorts.'" href="'.$CFG->wwwroot.'/cohort/index.php?contextid='.$category->context->id.'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/cohort') . '" class="iconsmall" alt="'.$str->cohorts.'" /></a> ';
|
||||
}
|
||||
|
||||
if ($up) {
|
||||
echo '<a title="'.$str->moveup.'" href="manage.php?moveupcat='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/up') . '" class="iconsmall" alt="'.$str->moveup.'" /></a> ';
|
||||
} else {
|
||||
echo $str->spacer;
|
||||
}
|
||||
if ($down) {
|
||||
echo '<a title="'.$str->movedown.'" href="manage.php?movedowncat='.$category->id.'&sesskey='.sesskey().'"><img'.
|
||||
' src="'.$OUTPUT->pix_url('t/down') . '" class="iconsmall" alt="'.$str->movedown.'" /></a> ';
|
||||
} else {
|
||||
echo $str->spacer;
|
||||
}
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="leftalign">';
|
||||
if (has_capability('moodle/category:manage', $category->context)) {
|
||||
$tempdisplaylist = $displaylist;
|
||||
unset($tempdisplaylist[$category->id]);
|
||||
foreach ($parentslist as $key => $parents) {
|
||||
if (in_array($category->id, $parents)) {
|
||||
unset($tempdisplaylist[$key]);
|
||||
}
|
||||
}
|
||||
$popupurl = new moodle_url("manage.php?movecat=$category->id&sesskey=".sesskey());
|
||||
$select = new single_select($popupurl, 'movetocat', $tempdisplaylist, $category->parent, null, "moveform$category->id");
|
||||
$select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide'));
|
||||
echo $OUTPUT->render($select);
|
||||
}
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
} else {
|
||||
$category = new stdClass();
|
||||
$category->id = '0';
|
||||
}
|
||||
|
||||
if ($categories = get_categories($category->id)) { // Print all the children recursively
|
||||
$countcats = count($categories);
|
||||
$count = 0;
|
||||
$first = true;
|
||||
$last = false;
|
||||
foreach ($categories as $cat) {
|
||||
$count++;
|
||||
if ($count == $countcats) {
|
||||
$last = true;
|
||||
}
|
||||
$up = $first ? false : true;
|
||||
$down = $last ? false : true;
|
||||
$first = false;
|
||||
|
||||
print_category_edit($cat, $displaylist, $parentslist, $depth+1, $up, $down);
|
||||
}
|
||||
}
|
||||
}
|
@ -977,6 +977,7 @@ $string['makeafolder'] = 'Create folder';
|
||||
$string['makeeditable'] = 'If you make \'{$a}\' editable by the web server process (eg apache) then you could edit this file directly from this page';
|
||||
$string['makethismyhome'] = 'Make this my default home page';
|
||||
$string['manageblocks'] = 'Blocks';
|
||||
$string['managecategorythis'] = 'Manage this category';
|
||||
$string['managecourses'] = 'Manage courses';
|
||||
$string['managedatabase'] = 'Database';
|
||||
$string['manageeditorfiles'] = 'Manage files used by editor';
|
||||
|
@ -558,7 +558,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
|
||||
$params = array();
|
||||
|
||||
$categoryselect = "";
|
||||
if ($categoryid != "all" && is_numeric($categoryid)) {
|
||||
if ($categoryid !== "all" && is_numeric($categoryid)) {
|
||||
$categoryselect = "WHERE c.category = :catid";
|
||||
$params['catid'] = $categoryid;
|
||||
} else {
|
||||
|
@ -3484,3 +3484,43 @@ function delete_course_module($id) {
|
||||
delete_context(CONTEXT_MODULE, $cm->id);
|
||||
return $DB->delete_records('course_modules', array('id'=>$cm->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the turn editing on/off button on course/index.php or course/category.php.
|
||||
*
|
||||
* @deprecated since 2.5
|
||||
*
|
||||
* @param integer $categoryid The id of the category we are showing, or 0 for system context.
|
||||
* @return string HTML of the editing button, or empty string, if this user is not allowed
|
||||
* to see it.
|
||||
*/
|
||||
function update_category_button($categoryid = 0) {
|
||||
global $CFG, $PAGE, $OUTPUT;
|
||||
debugging('Function update_category_button() is deprecated. Pages to view '.
|
||||
'and edit courses are now separate and no longer depend on editing mode.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
// Check permissions.
|
||||
if (!can_edit_in_category($categoryid)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Work out the appropriate action.
|
||||
if ($PAGE->user_is_editing()) {
|
||||
$label = get_string('turneditingoff');
|
||||
$edit = 'off';
|
||||
} else {
|
||||
$label = get_string('turneditingon');
|
||||
$edit = 'on';
|
||||
}
|
||||
|
||||
// Generate the button HTML.
|
||||
$options = array('categoryedit' => $edit, 'sesskey' => sesskey());
|
||||
if ($categoryid) {
|
||||
$options['id'] = $categoryid;
|
||||
$page = 'category.php';
|
||||
} else {
|
||||
$page = 'index.php';
|
||||
}
|
||||
return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
|
||||
}
|
||||
|
@ -4027,20 +4027,15 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
$categorynode = $this->add(print_context_name($this->context), null, null, null, 'categorysettings');
|
||||
$categorynode->force_open();
|
||||
$onmanagepage = $this->page->url->compare(new moodle_url('/course/manage.php'), URL_MATCH_BASE);
|
||||
|
||||
if (has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $this->context)) {
|
||||
$url = new moodle_url('/course/category.php', array('id'=>$this->context->instanceid, 'sesskey'=>sesskey()));
|
||||
if ($this->page->user_is_editing()) {
|
||||
$url->param('categoryedit', '0');
|
||||
$editstring = get_string('turneditingoff');
|
||||
} else {
|
||||
$url->param('categoryedit', '1');
|
||||
$editstring = get_string('turneditingon');
|
||||
}
|
||||
if (can_edit_in_category($this->context->instanceid) && !$onmanagepage) {
|
||||
$url = new moodle_url('/course/manage.php', array('id' => $this->context->instanceid));
|
||||
$editstring = get_string('managecategorythis');
|
||||
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
|
||||
}
|
||||
|
||||
if ($this->page->user_is_editing() && has_capability('moodle/category:manage', $this->context)) {
|
||||
if ($onmanagepage && has_capability('moodle/category:manage', $this->context)) {
|
||||
$editurl = new moodle_url('/course/editcategory.php', array('id' => $this->context->instanceid));
|
||||
$categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', ''));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user