]> git.mjollnir.org Git - moodle.git/commitdiff
course request: MDL-17575 and MDL-6160 further improvements:
authortjhunt <tjhunt>
Wed, 10 Dec 2008 02:57:41 +0000 (02:57 +0000)
committertjhunt <tjhunt>
Wed, 10 Dec 2008 02:57:41 +0000 (02:57 +0000)
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.

admin/settings/courses.php
course/lib.php
course/request.php
course/request_form.php
lang/en_utf8/admin.php
lang/en_utf8/role.php
lib/db/access.php
version.php

index 74f28e6f1f03897fae19cd59427564909f94df9f..dc2380acf6efdb51a6ce7eb8f9a1fe88e7c72633 100644 (file)
@@ -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.
index 68a1b5ac13fecad31f10fddd7db1095c05456297..a3b1bc4b3323f00fde0345e5b0eaea6168e0b8cf 100644 (file)
@@ -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');
     }
index 36a706823d2cc5f67382ab5cc08677dccb3239f2..86dcfc66d8e8874ae4dc53f6ee377dfac9ecb9eb 100644 (file)
     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();
index ad2782576b4efc48944a80a408f6ccbae5c3c144..d0de92b6c055d5cbd26ea44de43fcca5ca4584dd 100644 (file)
@@ -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"');
index 7ffac421c4f56f57705294f6fee2755e11291ee6..60e488bfd052238709e462a456d7b482eb7ac65f 100644 (file)
@@ -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 <em>wwwroot</em> 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';
index 67122ac4d570869adad427a122386bebeaf0b2f6..d2cb28706a97bbe49fe0fd190f2937a7e6f2a92f 100644 (file)
@@ -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';
index de14be2cc46976028082f1f76663830daf12c957..fcb75e48e51a98cde28593de3e8f1c800630abfe 100644 (file)
@@ -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,
index b93b40ded1bd49c819b1361915d43eaccafa2d1f..75eea08cc4c57007ff38f00535024cc0e834cc12 100644 (file)
@@ -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