8ed5dd63ee
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557. * Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories. * Enforce those correctly. (Note MDL 17502 is still outstanding.) * Don't screw up category sort order when you just edit name or description. * Niceties like where redirects go when you cancel or submit forms. * Make sure a global course creator can see the site admin block. * Don't allow a category to be made the child of one of its children! * General code cleanup to bring key files more in line with best pracitice. Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten. Merged from MOODLE_19_STABLE.
92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php //$Id$
|
|
|
|
require_once($CFG->libdir.'/formslib.php');
|
|
|
|
class delete_category_form extends moodleform {
|
|
|
|
var $_category;
|
|
|
|
function definition() {
|
|
global $CFG;
|
|
|
|
$mform =& $this->_form;
|
|
$category = $this->_customdata;
|
|
ensure_context_subobj_present($category, CONTEXT_COURSECAT);
|
|
$this->_category = $category;
|
|
|
|
$mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name)));
|
|
|
|
$displaylist = array();
|
|
$notused = array();
|
|
make_categories_list($displaylist, $notused, 'moodle/course:create', $category->id);
|
|
|
|
// Check permissions, to see if it OK to give the option to delete
|
|
// the contents, rather than move elsewhere.
|
|
$candeletecontent = true;
|
|
$tocheck = array($category);
|
|
while (!empty($tocheck)) {
|
|
$checkcat = array_pop($tocheck);
|
|
$tocheck = $tocheck + get_child_categories($checkcat->id);
|
|
if (!has_capability('moodle/category:manage', $checkcat->context)) {
|
|
$candeletecontent = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// TODO check that the user is allowed to delete all the courses MDL-17502!
|
|
|
|
$options = array();
|
|
|
|
if ($displaylist) {
|
|
$options[0] = get_string('move');
|
|
}
|
|
|
|
if ($candeletecontent) {
|
|
$options[1] = get_string('delete');
|
|
}
|
|
|
|
if (empty($options)) {
|
|
print_error('nocategorydelete', 'error', 'index.php', format_string($category->name));
|
|
}
|
|
|
|
$mform->addElement('select', 'fulldelete', get_string('categorycontents'), $options);
|
|
$mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
|
|
$mform->setDefault('newparent', 0);
|
|
|
|
if ($displaylist) {
|
|
$mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
|
|
if (in_array($category->parent, $displaylist)) {
|
|
$mform->setDefault('newparent', $category->parent);
|
|
}
|
|
}
|
|
|
|
$mform->addElement('hidden', 'delete');
|
|
$mform->addElement('hidden', 'sure');
|
|
$mform->setDefault('sure', md5(serialize($category)));
|
|
|
|
//--------------------------------------------------------------------------------
|
|
$this->add_action_buttons(true, get_string('delete'));
|
|
|
|
}
|
|
|
|
/// perform some extra moodle validation
|
|
function validation($data, $files) {
|
|
$errors = parent::validation($data, $files);
|
|
|
|
if (!empty($data['fulldelete'])) {
|
|
// already verified
|
|
} else {
|
|
if (empty($data['newparent'])) {
|
|
$errors['newparent'] = get_string('required');
|
|
}
|
|
}
|
|
|
|
if ($data['sure'] != md5(serialize($this->_category))) {
|
|
$errors['categorylabel'] = get_string('categorymodifiedcancel');
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
}
|
|
?>
|