From: tjhunt Date: Wed, 10 Dec 2008 02:57:41 +0000 (+0000) Subject: course request: MDL-17575 and MDL-6160 further improvements: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e452210a18f2a81ff20cf889d205c905881c9c34;p=moodle.git course request: MDL-17575 and MDL-6160 further improvements: 1/ email notification when course requested 2/ course request capability so that we can limit who can request new course 3/ list of my pending course requests on the request form Implemented in 1.9 by Petr Skoda, and reviewed and merged to HEAD by me. --- diff --git a/admin/settings/courses.php b/admin/settings/courses.php index 74f28e6f1f..dc2380acf6 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -122,6 +122,7 @@ if ($hassiteconfig $temp = new admin_settingpage('courserequest', get_string('courserequest')); $temp->add(new admin_setting_configcheckbox('enablecourserequests', get_string('enablecourserequests', 'admin'), get_string('configenablecourserequests', 'admin'), 0)); $temp->add(new admin_settings_coursecat_select('defaultrequestcategory', get_string('defaultrequestcategory', 'admin'), get_string('configdefaultrequestcategory', 'admin'), 1)); + $temp->add(new admin_setting_configtext('courserequestnotify', get_string('courserequestnotify', 'admin'), get_string('configcourserequestnotify', 'admin'), '')); $ADMIN->add('courses', $temp); /// Pending course requests. diff --git a/course/lib.php b/course/lib.php index 68a1b5ac13..a3b1bc4b33 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1981,7 +1981,7 @@ function print_course_request_buttons($systemcontext) { if (empty($CFG->enablecourserequests)) { return; } - if (isloggedin() && !isguestuser() && !has_capability('moodle/course:create', $systemcontext)) { + if (isloggedin() && !isguestuser() && !has_capability('moodle/course:create', $systemcontext) && has_capability('moodle/course:request', $systemcontext)) { /// Print a button to request a new course print_single_button('request.php', NULL, get_string('requestcourse'), 'get'); } diff --git a/course/request.php b/course/request.php index 36a706823d..86dcfc66d8 100644 --- a/course/request.php +++ b/course/request.php @@ -44,27 +44,55 @@ if (empty($CFG->enablecourserequests)) { print_error('courserequestdisabled', '', $returnurl); } + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + require_capability('moodle/course:request', $systemcontext); /// Set up the form. $requestform = new course_request_form($CFG->wwwroot . '/course/request.php'); + $strtitle = get_string('courserequest'); + /// Standard form processing if statement. if ($requestform->is_cancelled()){ redirect($returnurl); } else if ($data = $requestform->get_data()) { + print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus()); + print_heading($strtitle); + /// Record the request. $data->requester = $USER->id; if (!$DB->insert_record('course_request', $data)) { print_error('errorsavingrequest', '', $returnurl); } + /// Notify the admin if required. + if ($CFG->courserequestnotify) { + if ($user = $user = $DB->get_record('user', array('username' => $CFG->courserequestnotify, + 'mnethostid' => $CFG->mnet_localhost_id))) { + $eventdata = new object(); + $eventdata->modulename = 'moodle'; + $eventdata->component = 'course'; + $eventdata->name = 'courserequested'; + $eventdata->userfrom = $USER; + $eventdata->userto = $user; + $eventdata->subject = get_string('courserequest'); + $a = new object(); + $a->link = "$CFG->wwwroot/course/pending.php"; + $a->user = fullname($USER); + $eventdata->fullmessage = get_string('courserequestnotifyemail', 'admin', $a); + $eventdata->fullmessageformat = FORMAT_PLAIN; + $eventdata->fullmessagehtml = ''; + $eventdata->smallmessage = ''; + events_trigger('message_send', $eventdata); + } + } + /// and redirect back to the course listing. notice(get_string('courserequestsuccess'), $returnurl); } /// Show the request form. - $strtitle = get_string('courserequest'); print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus()); print_heading($strtitle); $requestform->display(); diff --git a/course/request_form.php b/course/request_form.php index ad2782576b..d0de92b6c0 100644 --- a/course/request_form.php +++ b/course/request_form.php @@ -38,8 +38,20 @@ require_once($CFG->libdir.'/formslib.php'); */ class course_request_form extends moodleform { function definition() { + global $DB, $USER; + $mform =& $this->_form; + if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) { + $mform->addElement('header', 'pendinglist', get_string('coursespending')); + $list = array(); + foreach ($pending as $cp) { + $list[] = format_string($cp->fullname); + } + $list = implode(', ', $list); + $mform->addElement('static', 'pendingcourses', get_string('courses'), $list); + } + $mform->addElement('header','coursedetails', get_string('courserequestdetails')); $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"'); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 7ffac421c4..60e488bfd0 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -87,6 +87,7 @@ $string['configcookiehttponly'] = 'Enables new PHP 5.2.0 feature - browsers are $string['configcookiesecure'] = 'If server is accepting only https connections it is recommended to enable sending of secure cookies. If enabled please make sure that web server is not accepting http:// or set up permanent redirection to https:// address. When wwwroot address does not start with https:// this setting is turned off automatically.'; $string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.'; $string['configcoursemanager'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.'; +$string['configcourserequestnotify'] = 'Type username of user to be notified when new course requested.'; $string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.'; $string['configcreatornewroleid'] = 'This role is automatically assigned to creators in new courses they created. This role is not assigned if creator already has needed capabilities in parent context.'; $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. This is especially useful for large/busy sites or sites built on cluster of servers. For most sites this should probably be left disabled so that the server disk is used instead. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.'; @@ -273,6 +274,9 @@ $string['coursemanager'] = 'Course managers'; $string['coursemgmt'] = 'Add/edit courses'; $string['courseoverview'] = 'Course overview'; $string['courserequests'] = 'Course Requests'; +$string['courserequestnotify'] = 'Course request notification'; +$string['courserequestnotifyemail'] = 'User $a->user requested a new course at $a->link'; +$string['courserequestspending'] = 'Pending course requests'; $string['courses'] = 'Courses'; $string['coursesperpage'] = 'Courses per page'; $string['creatornewroleid'] = 'Creators\' role in new courses'; diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index 67122ac4d5..d2cb28706a 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -58,6 +58,7 @@ $string['course:managefiles'] = 'Manage files'; $string['course:managegroups'] = 'Manage groups'; $string['course:managemetacourse'] = 'Manage metacourse'; $string['course:managescales'] = 'Manage scales'; +$string['course:request'] = 'Request new courses'; $string['course:reset'] = 'Reset course'; $string['course:sectionvisibility'] = 'Control section visibility'; $string['course:setcurrentsection'] = 'Set current section'; diff --git a/lib/db/access.php b/lib/db/access.php index de14be2cc4..fcb75e48e5 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -491,6 +491,14 @@ $moodle_capabilities = array( ) ), + 'moodle/course:request' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'user' => CAP_ALLOW, + ) + ), + 'moodle/course:delete' => array( 'riskbitmask' => RISK_DATALOSS, diff --git a/version.php b/version.php index b93b40ded1..75eea08cc4 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008120801; // YYYYMMDD = date of the last version bump + $version = 2008121000; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20081210)'; // Human-friendly version name