# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/admin/settings/courses.php
--- moodle/admin/settings/courses.php Base (1.14.2.6)
+++ moodle/admin/settings/courses.php Locally Modified (Based On 1.14.2.6)
@@ -17,6 +17,7 @@
     $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: moodle/course/lib.php
--- moodle/course/lib.php Base (1.538.2.63)
+++ moodle/course/lib.php Locally Modified (Based On 1.538.2.63)
@@ -1879,7 +1879,7 @@
     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: moodle/course/request.php
--- moodle/course/request.php Base (1.14.2.1)
+++ moodle/course/request.php Locally Modified (Based On 1.14.2.1)
@@ -38,6 +38,7 @@
 
 /// Check permissions.
     require_login();
+
     if (isguestuser()) {
         print_error('guestsarenotallowed', '', $returnurl);
     }
@@ -45,26 +46,44 @@
         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 (!insert_record('course_request', $data)) {
             print_error('errorsavingrequest', '', $returnurl);
         }
 
+        if ($CFG->courserequestnotify) {
+            if ($user = get_record('user', 'username', $CFG->courserequestnotify, 'mnethostid', $CFG->mnet_localhost_id)) {
+                $subject     = get_string('courserequest');
+                $a = new object();
+                $a->link = "$CFG->wwwroot/course/pending.php";
+                $a->user = fullname($USER);
+                $messagetext = get_string('courserequestnotifyemail', 'admin', $a);
+                email_to_user($user, $USER, $subject, $messagetext);
+            }
+        }
+
     /// and redirect back to the course listing.
         notice(get_string('courserequestsuccess'), $returnurl);
     }
 
 /// Show the request form.
-    $strtitle = get_string('courserequest');
\ No newline at end of file
     print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
     print_heading($strtitle);
     $requestform->display();
Index: moodle/course/request_form.php
--- moodle/course/request_form.php Base (1.11.2.3)
+++ moodle/course/request_form.php Locally Modified (Based On 1.11.2.3)
@@ -38,8 +38,20 @@
  */
 class course_request_form extends moodleform {
     function definition() {
+        global $USER;
+
         $mform =& $this->_form;
 
+        if ($pending = get_records('course_request', '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: moodle/lang/en_utf8/admin.php
--- moodle/lang/en_utf8/admin.php Base (1.154.2.67)
+++ moodle/lang/en_utf8/admin.php Locally Modified (Based On 1.154.2.67)
@@ -78,6 +78,7 @@
 $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.';
@@ -261,6 +262,9 @@
 $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: moodle/lang/en_utf8/role.php
--- moodle/lang/en_utf8/role.php Base (1.47.2.17)
+++ moodle/lang/en_utf8/role.php Locally Modified (Based On 1.47.2.17)
@@ -39,6 +39,7 @@
 $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: moodle/lib/db/access.php
--- moodle/lib/db/access.php Base (1.75.2.16)
+++ moodle/lib/db/access.php Locally Modified (Based On 1.75.2.16)
@@ -463,6 +463,14 @@
         )
     ),
 
+    'moodle/course:request' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'user' => CAP_ALLOW,
+        )
+    ),
+
     'moodle/course:delete' => array(
 
         'riskbitmask' => RISK_DATALOSS,
Index: moodle/version.php
--- moodle/version.php Base (1.563.2.338)
+++ moodle/version.php Locally Modified (Based On 1.563.2.338)
@@ -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 = 2007101532.10;  // YYYYMMDD          = date of the 1.9 branch (don't change)
+    $version = 2007101532.11;  // YYYYMMDD          = date of the 1.9 branch (don't change)
                                         //                   X       = release number 1.9.[0,1,2,3...]
                                         //                     Y.YY = micro-increments between releases
 
