diff --git a/admin/settings/courses.php b/admin/settings/courses.php index f07107ca631..04f797541fe 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -85,6 +85,7 @@ if ($hassiteconfig $temp = new admin_settingpage('courserequest', new lang_string('courserequest')); $temp->add(new admin_setting_configcheckbox('enablecourserequests', new lang_string('enablecourserequests', 'admin'), new lang_string('configenablecourserequests', 'admin'), 0)); $temp->add(new admin_settings_coursecat_select('defaultrequestcategory', new lang_string('defaultrequestcategory', 'admin'), new lang_string('configdefaultrequestcategory', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('requestcategoryselection', new lang_string('requestcategoryselection', 'admin'), new lang_string('configrequestcategoryselection', 'admin'), 0)); $temp->add(new admin_setting_users_with_capability('courserequestnotify', new lang_string('courserequestnotify', 'admin'), new lang_string('configcourserequestnotify2', 'admin'), array(), 'moodle/site:approvecourse')); $ADMIN->add('courses', $temp); diff --git a/course/lib.php b/course/lib.php index cf8f3723c71..c4233f4c3bf 100644 --- a/course/lib.php +++ b/course/lib.php @@ -4144,6 +4144,11 @@ class course_request { global $USER, $DB, $CFG; $data->requester = $USER->id; + // Setting the default category is none set. + if (empty($data->category) || empty($CFG->requestcategoryselection)) { + $data->category = $CFG->defaultrequestcategory; + } + // Summary is a required field so copy the text over $data->summary = $data->summary_editor['text']; $data->summaryformat = $data->summary_editor['format']; @@ -4293,7 +4298,6 @@ class course_request { $user = $DB->get_record('user', array('id' => $this->properties->requester, 'deleted'=>0), '*', MUST_EXIST); - $category = get_course_category($CFG->defaultrequestcategory); $courseconfig = get_config('moodlecourse'); // Transfer appropriate settings @@ -4302,6 +4306,14 @@ class course_request { unset($data->reason); unset($data->requester); + // If the current user does not have the rights to change the category, or if the + // category does not exist, we set the default category to the course to be approved. + // The system level is used because the capability moodle/site:approvecourse is based on a system level. + if (!has_capability('moodle/course:changecategory', context_system::instance()) || + (!$category = get_course_category($data->category))) { + $category = get_course_category($CFG->defaultrequestcategory); + } + // Set category $data->category = $category->id; $data->sortorder = $category->sortorder; // place as the first in category diff --git a/course/pending.php b/course/pending.php index 205a42977e7..8ac583261f6 100644 --- a/course/pending.php +++ b/course/pending.php @@ -101,8 +101,8 @@ if (empty($pending)) { $table = new html_table(); $table->attributes['class'] = 'pendingcourserequests generaltable'; $table->align = array('center', 'center', 'center', 'center', 'center', 'center'); - $table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'), - get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action')); + $table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'), get_string('requestedby'), + get_string('summary'), get_string('category'), get_string('requestreason'), get_string('action')); foreach ($pending as $course) { $course = new course_request($course); @@ -110,11 +110,22 @@ if (empty($pending)) { // Check here for shortname collisions and warn about them. $course->check_shortname_collision(); + // Retreiving category name. + // If the user does not have the capability to change the category, we fallback on the default one. + // Else, the category proposed is fetched, but we fallback on the default one if we can't find it. + // It is just a matter of displaying the right information because the logic when approving the category + // proceeds the same way. The system context level is used as moodle/site:approvecourse uses it. + if (!has_capability('moodle/course:changecategory', context_system::instance()) || + (!$category = get_course_category($course->category))) { + $category = get_course_category($CFG->defaultrequestcategory); + } + $row = array(); $row[] = format_string($course->shortname); $row[] = format_string($course->fullname); $row[] = fullname($course->get_requester()); $row[] = $course->summary; + $row[] = format_string($category->name); $row[] = format_string($course->reason); $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') . $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get'); diff --git a/course/request_form.php b/course/request_form.php index e74e40bdf71..867a684e97f 100644 --- a/course/request_form.php +++ b/course/request_form.php @@ -42,7 +42,7 @@ require_once($CFG->libdir.'/formslib.php'); */ class course_request_form extends moodleform { function definition() { - global $DB, $USER; + global $CFG, $DB, $USER; $mform =& $this->_form; @@ -68,6 +68,15 @@ class course_request_form extends moodleform { $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); + if (!empty($CFG->requestcategoryselection)) { + $displaylist = array(); + $parentlist = array(); + make_categories_list($displaylist, $parentlist, ''); + $mform->addElement('select', 'category', get_string('category'), $displaylist); + $mform->setDefault('category', $CFG->defaultrequestcategory); + $mform->addHelpButton('category', 'category'); + } + $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options()); $mform->addHelpButton('summary_editor', 'coursesummary'); $mform->setType('summary_editor', PARAM_RAW); diff --git a/lang/en/admin.php b/lang/en/admin.php index 5e7b0d98264..9f62c297ae8 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -283,6 +283,7 @@ $string['configrcache'] = 'Use the cache to store database records. Remember to $string['configrcachettl'] = 'Time-to-live for cached records, in seconds. Use a short (<15) value here.'; $string['configrecaptchaprivatekey'] = 'String of characters used to communicate between your Moodle server and the recaptcha server. Obtain one for this site by visiting http://www.google.com/recaptcha'; $string['configrecaptchapublickey'] = 'String of characters used to display the reCAPTCHA element in the signup form. Generated by http://www.google.com/recaptcha'; +$string['configrequestcategoryselection'] = 'Allow the selection of a category when requesting a course.'; $string['configrequestedstudentname'] = 'Word for student used in requested courses'; $string['configrequestedstudentsname'] = 'Word for students used in requested courses'; $string['configrequestedteachername'] = 'Word for teacher used in requested courses'; @@ -871,6 +872,7 @@ $string['requires'] = 'Requires'; $string['purgecaches']= 'Purge all caches'; $string['purgecachesconfirm']= 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.'; $string['purgecachesfinished']= 'All caches were purged.'; +$string['requestcategoryselection'] = 'Enable category selection'; $string['restorernewroleid'] = 'Restorers\' role in courses'; $string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.'; $string['reverseproxy'] = 'Reverse proxy'; diff --git a/lib/db/install.xml b/lib/db/install.xml index 35c7bfc943e..bcd5920cdf2 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -426,8 +426,9 @@ - - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f3b34fdc6c1..fa68b7a0b8a 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1122,8 +1122,8 @@ function xmldb_main_upgrade($oldversion) { if ($oldversion < 2012082300.01) { // Add more custom enrol fields. $table = new xmldb_table('enrol'); - $field = new xmldb_field('customint5', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint4'); + if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } @@ -1194,5 +1194,17 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012090500.00); } + if ($oldversion < 2012090700.01) { + // Add a category field in the course_request table + $table = new xmldb_table('course_request'); + $field = new xmldb_field('category', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'summaryformat'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2012090700.01); + } + return true; } diff --git a/version.php b/version.php index 0043e10a19a..181fd869ccd 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012090700.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012090700.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes