Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

course request: MDL-9854 major cleanup to the course request code.

* Rewrite all the forms to use formslib and improve usability.
* Put the place where admins need to go to process approvals in the admin menu.
* Show the request course/pending requests button on the page for the category that requested courses get added to.
  • Loading branch information...
commit 7f2e6a23a96097e8bb0aa2d213087d432ebb9f9b 1 parent 32b1759
authored December 05, 2008
9  admin/settings/courses.php
@@ -5,7 +5,8 @@
5 5
 if ($hassiteconfig
6 6
  or has_capability('moodle/site:backup', $systemcontext)
7 7
  or has_capability('moodle/category:manage', $systemcontext)
8  
- or has_capability('moodle/course:create', $systemcontext)) { // speedup for non-admins, add all caps used on this page
  8
+ or has_capability('moodle/course:create', $systemcontext)
  9
+ or has_capability('moodle/site:approvecourse', $systemcontext)) { // speedup for non-admins, add all caps used on this page
9 10
 
10 11
     $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on',
11 12
             array('moodle/category:manage', 'moodle/course:create')));
@@ -18,6 +19,12 @@
18 19
     $temp->add(new admin_settings_coursecat_select('defaultrequestcategory', get_string('defaultrequestcategory', 'admin'), get_string('configdefaultrequestcategory', 'admin'), 1));
19 20
     $ADMIN->add('courses', $temp);
20 21
 
  22
+    // Pending course requests.
  23
+    if (!empty($CFG->enablecourserequests)) {
  24
+        $ADMIN->add('courses', new admin_externalpage('coursespending', get_string('pendingrequests'),
  25
+                $CFG->wwwroot . '/course/pending.php', array('moodle/site:approvecourse')));
  26
+    }
  27
+
21 28
     // "backups" settingpage
22 29
     if (!empty($CFG->backup_version)) {
23 30
         $bi = array();
4  course/category.php
@@ -456,6 +456,10 @@
456 456
         $options['category'] = $category->id;
457 457
         print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
458 458
     }
  459
+
  460
+    if (!empty($CFG->enablecourserequests) && $category->id == $CFG->enablecourserequests) {
  461
+        print_course_request_buttons(get_context_instance(CONTEXT_SYSTEM));
  462
+    }
459 463
     echo '</div>';
460 464
 
461 465
     print_course_search();
12  course/index.php
@@ -74,19 +74,13 @@
74 74
         }
75 75
 
76 76
         echo '<div class="buttons">';
77  
-        if ($CFG->enablecourserequests and isloggedin() and !isguest() and !has_capability('moodle/course:create', $systemcontext)) {
78  
-        /// Print link to request a new course
79  
-            print_single_button('request.php', NULL, get_string('courserequest'), 'get');
80  
-        }
81 77
         if (has_capability('moodle/course:create', $systemcontext)) {
82 78
         /// Print link to create a new course
83 79
         /// Get the 1st available category
84 80
             $options = array('category' => $CFG->defaultrequestcategory);
85 81
             print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
86 82
         }
87  
-        if (has_capability('moodle/site:approvecourse', $systemcontext) and !empty($CFG->enablecourserequests)) {
88  
-            print_single_button('pending.php',NULL, get_string('coursespending'),'get');
89  
-        }
  83
+        print_course_request_buttons($systemcontext);
90 84
         echo '</div>';
91 85
         print_footer();
92 86
         exit;
@@ -293,9 +287,7 @@
293 287
         print_single_button('editcategory.php', $options, get_string('addnewcategory'), 'get');
294 288
     }
295 289
 
296  
-    if (has_capability('moodle/site:approvecourse', $systemcontext)  and !empty($CFG->enablecourserequests)) {
297  
-        print_single_button('pending.php',NULL, get_string('coursespending'), 'get');
298  
-    }
  290
+    print_course_request_buttons($systemcontext);
299 291
     // admin page does not allow custom buttons in the navigation bar
300 292
     echo '<div class="singlebutton">';
301 293
     echo update_category_button();
20  course/lib.php
@@ -1865,6 +1865,26 @@ function print_category_info($category, $depth, $showcourses = false) {
1865 1865
 }
1866 1866
 
1867 1867
 /**
  1868
+ * Print the buttons relating to course requests.
  1869
+ *
  1870
+ * @param object $systemcontext the system context.
  1871
+ */
  1872
+function print_course_request_buttons($systemcontext) {
  1873
+    global $CFG;
  1874
+    if (empty($CFG->enablecourserequests)) {
  1875
+        return;
  1876
+    }
  1877
+    if (isloggedin() && !isguestuser() && !has_capability('moodle/course:create', $systemcontext)) {
  1878
+    /// Print a button to request a new course
  1879
+        print_single_button('request.php', NULL, get_string('requestcourse'), 'get');
  1880
+    }
  1881
+    /// Print a button to manage pending requests
  1882
+    if (has_capability('moodle/site:approvecourse', $systemcontext)) {
  1883
+        print_single_button('pending.php', NULL, get_string('coursespending'), 'get', '_self', false, '', !record_exists('course_request'));
  1884
+    }
  1885
+}
  1886
+
  1887
+/**
1868 1888
  * Prints the turn editing on/off button on course/index.php or course/category.php.
1869 1889
  *
1870 1890
  * @param integer $categoryid The id of the category we are showing, or 0 for system context.
7  course/pending-reject.html
... ...
@@ -1,7 +0,0 @@
1  
-<form action="pending.php" method="post" id="reject">
2  
-<input type="hidden" name="reject" value="<?php p($reject->id); ?>" />
3  
-<textarea name="rejectnotice" rows="10" cols="50"></textarea><br />
4  
-<input type="submit" value="<?php print_string("savechanges");?>" />
5  
-<input type="button" value="<?php print_string("cancel"); ?>"  onClick="window.location='pending.php';" />
6  
-<input type="hidden" name="sesskey" value="<?php echo sesskey();?>" />
7  
-</form>
280  course/pending.php
... ...
@@ -1,133 +1,209 @@
1 1
 <?php  // $Id$
2  
-       // allow the administrators to look through a list of course requests and either approve them or reject them.
3 2
 
4  
-    require_once('../config.php');
5  
-    require_once($CFG->libdir.'/pagelib.php');
6  
-    require_once($CFG->libdir.'/blocklib.php');
7  
-    require_once('lib.php');
  3
+///////////////////////////////////////////////////////////////////////////
  4
+//                                                                       //
  5
+// NOTICE OF COPYRIGHT                                                   //
  6
+//                                                                       //
  7
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
  8
+//          http://moodle.org                                            //
  9
+//                                                                       //
  10
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
  11
+//                                                                       //
  12
+// This program is free software; you can redistribute it and/or modify  //
  13
+// it under the terms of the GNU General Public License as published by  //
  14
+// the Free Software Foundation; either version 2 of the License, or     //
  15
+// (at your option) any later version.                                   //
  16
+//                                                                       //
  17
+// This program is distributed in the hope that it will be useful,       //
  18
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  19
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  20
+// GNU General Public License for more details:                          //
  21
+//                                                                       //
  22
+//          http://www.gnu.org/copyleft/gpl.html                         //
  23
+//                                                                       //
  24
+///////////////////////////////////////////////////////////////////////////
8 25
 
9  
-    require_login();
  26
+/**
  27
+ * Allow the administrator to look through a list of course requests and approve or reject them.
  28
+ *
  29
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  30
+ * @package course
  31
+ *//** */
  32
+
  33
+    require_once(dirname(__FILE__) . '/../config.php');
  34
+    require_once($CFG->libdir . '/pagelib.php');
  35
+    require_once($CFG->libdir . '/blocklib.php');
  36
+    require_once($CFG->libdir . '/adminlib.php');
  37
+    require_once($CFG->dirroot . '/course/lib.php');
  38
+    require_once($CFG->dirroot . '/course/request_form.php');
10 39
 
  40
+    require_login();
11 41
     require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
12 42
 
13  
-    $approve      = optional_param('approve', 0, PARAM_INT);
14  
-    $reject       = optional_param('reject', 0, PARAM_INT);
15  
-    $rejectnotice = optional_param('rejectnotice', '', PARAM_CLEANHTML);
  43
+    $approve = optional_param('approve', 0, PARAM_INT);
  44
+    $reject = optional_param('reject', 0, PARAM_INT);
16 45
 
  46
+    $baseurl = $CFG->wwwroot . '/course/pending.php';
  47
+    admin_externalpage_setup('coursespending');
  48
+
  49
+/// Process approval of a course.
17 50
     if (!empty($approve) and confirm_sesskey()) {
18  
-        if ($course = get_record("course_request","id",$approve)) {
19  
-            foreach (array_keys((array)$course) as $key) {
20  
-                $course->$key = addslashes($course->$key);
21  
-            }
  51
+    /// Load the request.
  52
+        if (!$course = get_record('course_request', 'id', $approve)) {
  53
+            print_error('unknowncourserequest');
  54
+        }
  55
+        foreach (array_keys((array)$course) as $key) {
  56
+            $course->$key = addslashes($course->$key);
  57
+        }
22 58
 
23  
-            // place at beginning of category
24  
-            fix_course_sortorder();
  59
+    /// Ensure all is well before proceeding.
  60
+        fix_course_sortorder();
  61
+        if (empty($CFG->defaultrequestcategory) or !record_exists('course_categories', 'id', $CFG->defaultrequestcategory)) {
  62
+        /// default to first top level directory, hacky but means things don't break
  63
+            $CFG->defaultrequestcategory = get_field('course_categories', 'id', 'parent', '0');
  64
+        }
25 65
 
26  
-            if (empty($CFG->defaultrequestcategory) or !record_exists('course_categories', 'id', $CFG->defaultrequestcategory)) {
27  
-                // default to first top level directory, hacky but means things don't break
28  
-                $CFG->defaultrequestcategory = get_field('course_categories', 'id', 'parent', '0');
29  
-            }
  66
+    /// Build up a course record based on the request.
  67
+        $course->category = $CFG->defaultrequestcategory;
  68
+        $course->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$course->category");
  69
+        if (empty($course->sortorder)) {
  70
+            $course->sortorder = 1000;
  71
+        }
  72
+        $course->requested = 1;
  73
+        unset($course->reason);
  74
+        unset($course->id);
  75
+        $teacherid = $course->requester;
  76
+        unset($course->requester);
  77
+        $course->teacher = get_string("defaultcourseteacher");
  78
+        $course->teachers = get_string("defaultcourseteachers");
  79
+        $course->student = get_string("defaultcoursestudent");
  80
+        $course->students = get_string("defaultcoursestudents");
  81
+        if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
  82
+            $course->restrictmodules = 1;
  83
+        }
30 84
 
31  
-            $course->category = $CFG->defaultrequestcategory;
32  
-            $course->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$course->category");
33  
-            if (empty($course->sortorder)) {
34  
-                $course->sortorder = 1000;
35  
-            }
36  
-            $course->requested = 1;
37  
-            unset($course->reason);
38  
-            unset($course->id);
39  
-            $teacherid = $course->requester;
40  
-            unset($course->requester);
41  
-            $course->teacher = get_string("defaultcourseteacher");
42  
-            $course->teachers = get_string("defaultcourseteachers");
43  
-            $course->student = get_string("defaultcoursestudent");
44  
-            $course->students = get_string("defaultcoursestudents");
45  
-            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
46  
-                $course->restrictmodules = 1;
47  
-            }
48  
-            if ($courseid = insert_record("course",$course)) {
49  
-                $page = page_create_object(PAGE_COURSE_VIEW, $courseid);
50  
-                blocks_repopulate_page($page); // Return value not checked because you can always edit later
51  
-                $context = get_context_instance(CONTEXT_COURSE, $courseid);
52  
-                role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
53  
-                $course->id = $courseid;
54  
-                if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) { // if we're all or requested we're ok.
55  
-                    $allowedmods = explode(',',$CFG->defaultallowedmodules);
56  
-                    update_restricted_mods($course,$allowedmods);
57  
-                }
58  
-                delete_records('course_request','id',$approve);
59  
-                $success = 1;
60  
-            }
61  
-            if (!empty($success)) {
62  
-                $user = get_record('user','id',$teacherid);
63  
-                $a->name = $course->fullname;
64  
-                $a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
65  
-                $a->teacher = $course->teacher;
66  
-                email_to_user($user,$USER,get_string('courseapprovedsubject'),get_string('courseapprovedemail','moodle',$a));
67  
-                redirect($CFG->wwwroot.'/course/edit.php?id='.$courseid);
68  
-                exit;
69  
-            }
70  
-            else {
71  
-                print_error('courseapprovedfailed');
72  
-                exit;
  85
+    /// Insert the record.
  86
+        if ($courseid = insert_record('course', $course)) {
  87
+            $page = page_create_object(PAGE_COURSE_VIEW, $courseid);
  88
+            blocks_repopulate_page($page); // Return value not checked because you can always edit later
  89
+            $context = get_context_instance(CONTEXT_COURSE, $courseid);
  90
+            role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
  91
+            $course->id = $courseid;
  92
+            if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) { // if we're all or requested we're ok.
  93
+                $allowedmods = explode(',',$CFG->defaultallowedmodules);
  94
+                update_restricted_mods($course,$allowedmods);
73 95
             }
  96
+            delete_records('course_request','id',$approve);
  97
+            $success = 1;
  98
+        }
  99
+        if (!empty($success)) {
  100
+            $user = get_record('user','id',$teacherid);
  101
+            $a->name = $course->fullname;
  102
+            $a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
  103
+            $a->teacher = $course->teacher;
  104
+            email_to_user($user, $USER, get_string('courseapprovedsubject'),
  105
+                    get_string('courseapprovedemail', 'moodle', $a));
  106
+            redirect($CFG->wwwroot.'/course/edit.php?id='.$courseid);
  107
+
  108
+        } else {
  109
+            print_error('courseapprovedfailed');
74 110
         }
75 111
     }
76 112
 
77  
-    $strtitle = get_string('coursespending');
78  
-    $strheading = get_string(((!empty($reject)) ? 'coursereject' : 'coursespending'));
  113
+/// Process rejection of a course.
  114
+    if (!empty($reject)) {
  115
+    /// Load the request.
  116
+        if (!$course = get_record('course_request', 'id', $reject)) {
  117
+            print_error('unknowncourserequest');
  118
+        }
79 119
 
80  
-    print_header($strtitle,$strheading,build_navigation(array(array('name'=>$strheading,'link'=>'','type'=>'misc'))));
  120
+    /// Prepare the form.
  121
+        $rejectform = new reject_request_form($baseurl);
  122
+        $default = new stdClass();
  123
+        $default->reject = $reject;
  124
+        $rejectform->set_data($default);
81 125
 
82  
-    if (!empty($reject) and confirm_sesskey()) {
83  
-        if ($reject = get_record("course_request","id",$reject)) {
84  
-            if (empty($rejectnotice)) {
85  
-                //  display a form for writing a reason
86  
-                print_simple_box_start('center');
87  
-                print_string('courserejectreason');
88  
-                include('pending-reject.html');
89  
-                print_simple_box_end();
90  
-            }
91  
-            else {
92  
-                $user = get_record("user","id",$reject->requester);
93  
-                email_to_user($user,$USER,get_string('courserejectsubject'),get_string('courserejectemail','moodle',$rejectnotice));
94  
-                delete_records("course_request","id",$reject->id);
95  
-                notice(get_string('courserejected'),'pending.php');
96  
-            }
  126
+    /// Standard form processing if statement.
  127
+        if ($rejectform->is_cancelled()){
  128
+            redirect($baseurl);
  129
+    
  130
+        } else if ($data = $rejectform->get_data()) {
  131
+        /// Send an email to the requester.
  132
+            $user = get_record('user', 'id', $course->requester);
  133
+            email_to_user($user, $USER, get_string('courserejectsubject'),
  134
+                    get_string('courserejectemail', '', $data->rejectnotice));
  135
+
  136
+        /// Delete the request
  137
+            delete_records('course_request', 'id', $course->id);
  138
+
  139
+        /// Redirect back to the course listing.
  140
+            redirect($baseurl, get_string('courserejected'));
97 141
         }
98  
-    } else if ($pending = get_records("course_request")) {
99  
-        // loop through
100  
-        $table->cellpadding = 4;
101  
-        $table->cellspacing = 3;
102  
-        $table->align = array('center','center','center','center','center','center','center');
103  
-        $table->head = array('&nbsp;',get_string('shortname'),get_string('fullname'),get_string('requestedby'),get_string('summary'),
104  
-                               get_string('requestreason'),'');
  142
+
  143
+    /// Display the form for giving a reason for rejecting the request.
  144
+        admin_externalpage_print_header($rejectform->focus());
  145
+        $rejectform->display();
  146
+        admin_externalpage_print_footer();
  147
+        exit;
  148
+    }
  149
+
  150
+/// Print a list of all the pending requests.
  151
+    admin_externalpage_print_header();
  152
+
  153
+    $pending = get_records('course_request');
  154
+    if (empty($pending)) {
  155
+        print_heading(get_string('nopendingcourses'));
  156
+    } else {
  157
+        print_heading(get_string('coursespending'));
  158
+
  159
+    /// Build a table of all the requests.
  160
+        $table->class = 'pendingcourserequests generaltable';
  161
+        $table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
  162
+        $table->head = array('&nbsp;', get_string('shortname'), get_string('fullname'),
  163
+                get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
105 164
         $strrequireskey = get_string('requireskey');
  165
+
  166
+    /// Loop over requested courses.
106 167
         foreach ($pending as $course) {
107  
-            $requester = get_record('user','id',$course->requester);
108  
-            // check here for shortname collisions and warn about them.
109  
-            if ($match = get_record("course","shortname",$course->shortname)) {
  168
+            $requester = get_record('user', 'id', $course->requester);
  169
+            $row = array();
  170
+
  171
+        /// Check here for shortname collisions and warn about them.
  172
+            if (record_exists('course', 'shortname', $course->shortname)) {
110 173
                 $course->shortname .= ' [*]';
111 174
                 $collision = 1;
112 175
             }
113  
-            //do not output raw html from request, quote html entities using s()!!
114  
-            $table->data[] = array(((!empty($course->password)) ?
115  
-                                    '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$CFG->pixpath.'/i/key.gif" />' : ''),
116  
-                                   format_string($course->shortname),format_string($course->fullname),fullname($requester),
117  
-                                   format_string($course->summary),format_string($course->reason),
118  
-                                   '<a href="pending.php?approve='.$course->id.'&amp;sesskey='.sesskey().'">'.get_string('approve').'</a> | '
119  
-                                   .'<a href="pending.php?reject='.$course->id.'&amp;sesskey='.sesskey().'">'.get_string('reject').'</a>');
  176
+
  177
+        /// Show an enrolment key icon in the first column if applicable.
  178
+            if (!empty($course->password)) {
  179
+                $row[] = '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$CFG->pixpath.'/i/key.gif" />';
  180
+            } else {
  181
+                $row[] = '';
  182
+            }
  183
+
  184
+        /// Info in the other columns.
  185
+            $row[] = format_string($course->shortname);
  186
+            $row[] = format_string($course->fullname);
  187
+            $row[] = fullname($requester);
  188
+            $row[] = format_string($course->summary);
  189
+            $row[] = format_string($course->reason);
  190
+            $row[] = print_single_button($baseurl, array('approve' => $course->id, 'sesskey' => sesskey()), get_string('approve'), 'get', '', true) .
  191
+                    print_single_button($baseurl, array('reject' => $course->id), get_string('rejectdots'), 'get', '', true);
  192
+
  193
+        /// Add the row to the table.
  194
+            $table->data[] = $row;
120 195
         }
  196
+
  197
+    /// Display the table.
121 198
         print_table($table);
  199
+
  200
+    /// Message about name collisions, if necessary.
122 201
         if (!empty($collision)) {
123 202
             print_string('shortnamecollisionwarning');
124 203
         }
125  
-    } else {
126  
-        notice(get_string('nopendingcourses'));
127  
-        // no pending messages.
128 204
     }
129 205
 
130  
-print_footer();
131  
-
132  
-
  206
+/// Finish off the page.
  207
+    print_single_button($CFG->wwwroot . '/course/index.php', array(), get_string('backtocourselisting'));
  208
+    admin_externalpage_print_footer();
133 209
 ?>
91  course/request.php
... ...
@@ -1,52 +1,73 @@
1 1
 <?php  // $Id$
2 2
 
3  
-    /// this allows a student to request a course be created for them.
4  
-
5  
-    require_once('../config.php');
6  
-    require_once('request_form.php');
7  
-
  3
+///////////////////////////////////////////////////////////////////////////
  4
+//                                                                       //
  5
+// NOTICE OF COPYRIGHT                                                   //
  6
+//                                                                       //
  7
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
  8
+//          http://moodle.org                                            //
  9
+//                                                                       //
  10
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
  11
+//                                                                       //
  12
+// This program is free software; you can redistribute it and/or modify  //
  13
+// it under the terms of the GNU General Public License as published by  //
  14
+// the Free Software Foundation; either version 2 of the License, or     //
  15
+// (at your option) any later version.                                   //
  16
+//                                                                       //
  17
+// This program is distributed in the hope that it will be useful,       //
  18
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  19
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  20
+// GNU General Public License for more details:                          //
  21
+//                                                                       //
  22
+//          http://www.gnu.org/copyleft/gpl.html                         //
  23
+//                                                                       //
  24
+///////////////////////////////////////////////////////////////////////////
  25
+
  26
+/**
  27
+ * Allows a user to request a course be created for them.
  28
+ *
  29
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  30
+ * @package course
  31
+ *//** */
  32
+
  33
+    require_once(dirname(__FILE__) . '/../config.php');
  34
+    require_once($CFG->dirroot . '/course/request_form.php');
  35
+
  36
+/// Where we came from. Used in a number of redirects.
  37
+    $returnurl = $CFG->wwwroot . '/course/index.php';
  38
+
  39
+/// Check permissions.
8 40
     require_login();
9  
-
10  
-    if (isguest()) {
11  
-        error("No guests here!");
  41
+    if (isguestuser()) {
  42
+        print_error('guestsarenotallowed', '', $returnurl);
12 43
     }
13  
-
14 44
     if (empty($CFG->enablecourserequests)) {
15  
-        print_error('courserequestdisabled');
  45
+        print_error('courserequestdisabled', '', $returnurl);
16 46
     }
17 47
 
18  
-    $requestform = new course_request_form();
19  
-
20  
-    $strtitle = get_string('courserequest');
21  
-    $navlinks = array();
22  
-    $navlinks[] = array('name' => $strtitle, 'link' => null, 'type' => 'misc');
23  
-    $navigation = build_navigation($navlinks);
24  
-
25  
-    print_header($strtitle, $strtitle, $navigation, $requestform->focus());
26  
-
27  
-    print_simple_box_start('center');
28  
-    print_string('courserequestintro');
29  
-    print_simple_box_end();
30  
-
  48
+/// Set up the form.
  49
+    $requestform = new course_request_form($CFG->wwwroot . '/course/request.php');
31 50
 
  51
+/// Standard form processing if statement.
32 52
     if ($requestform->is_cancelled()){
  53
+        redirect($returnurl);
33 54
 
34  
-        redirect($CFG->wwwroot);
35  
-
36  
-    }elseif ($data = $requestform->get_data()) {
  55
+    } else if ($data = $requestform->get_data()) {
  56
+    /// Record the request.
37 57
         $data->requester = $USER->id;
38  
-
39  
-        if (insert_record('course_request', $data)) {
40  
-            notice(get_string('courserequestsuccess'));
41  
-        } else {
42  
-            notice(get_string('courserequestfailed'));
  58
+        if (!insert_record('course_request', $data)) {
  59
+            print_error('errorsavingrequest', '', $returnurl);
43 60
         }
44 61
 
45  
-    } else {
46  
-
47  
-        $requestform->display();
  62
+    /// and redirect back to the course listing.
  63
+        notice(get_string('courserequestsuccess'), $returnurl);
48 64
     }
49 65
 
  66
+/// Show the request form.
  67
+    $strtitle = get_string('courserequest');
  68
+    print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
  69
+    print_heading($strtitle);
  70
+    $requestform->display();
50 71
     print_footer();
51 72
 
52  
-?>
  73
+?>
102  course/request_form.php
... ...
@@ -1,34 +1,73 @@
1 1
 <?php  // $Id$
2 2
 
  3
+///////////////////////////////////////////////////////////////////////////
  4
+//                                                                       //
  5
+// NOTICE OF COPYRIGHT                                                   //
  6
+//                                                                       //
  7
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
  8
+//          http://moodle.org                                            //
  9
+//                                                                       //
  10
+// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
  11
+//                                                                       //
  12
+// This program is free software; you can redistribute it and/or modify  //
  13
+// it under the terms of the GNU General Public License as published by  //
  14
+// the Free Software Foundation; either version 2 of the License, or     //
  15
+// (at your option) any later version.                                   //
  16
+//                                                                       //
  17
+// This program is distributed in the hope that it will be useful,       //
  18
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  19
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  20
+// GNU General Public License for more details:                          //
  21
+//                                                                       //
  22
+//          http://www.gnu.org/copyleft/gpl.html                         //
  23
+//                                                                       //
  24
+///////////////////////////////////////////////////////////////////////////
  25
+
  26
+/**
  27
+ * Forms associated with requesting courses, and having requests approved.
  28
+ * Note that several related forms are defined in this one file.
  29
+ *
  30
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  31
+ * @package course
  32
+ *//** */
  33
+
3 34
 require_once($CFG->libdir.'/formslib.php');
4 35
 
  36
+/**
  37
+ * A form for a user to request a course.
  38
+ */
5 39
 class course_request_form extends moodleform {
6 40
     function definition() {
7 41
         $mform =& $this->_form;
8 42
 
  43
+        $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
  44
+
9 45
         $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
  46
+        $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
10 47
         $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
11  
-        $mform->setType('fullname', PARAM_TEXT);
  48
+        $mform->setType('fullname', PARAM_MULTILANG);
12 49
 
13 50
         $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="100" size="20"');
  51
+        $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
14 52
         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
15  
-        $mform->setType('shortname', PARAM_TEXT);
  53
+        $mform->setType('shortname', PARAM_MULTILANG);
16 54
 
17 55
         $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
18  
-        $mform->addRule('summary', get_string('missingsummary'), 'required', null, 'client');
  56
+        $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
19 57
         $mform->setType('summary', PARAM_RAW);
20  
-        $mform->setHelpButton('summary', array('text', get_string('helptext')));
21 58
 
  59
+        $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
  60
+        $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
  61
+        $mform->setDefault('password', '');
  62
+        $mform->setType('password', PARAM_RAW);
22 63
 
23  
-        $mform->addElement('textarea', 'reason', get_string('courserequestreason'), array('rows'=>'15', 'cols'=>'50'));
  64
+        $mform->addElement('header','requestreason', get_string('courserequestreason'));
  65
+
  66
+        $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
24 67
         $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
25 68
         $mform->setType('reason', PARAM_TEXT);
26 69
 
27  
-        $mform->addElement('text', 'password', get_string('enrolmentkey'), 'size="25"');
28  
-        $mform->setType('password', PARAM_RAW);
29  
-
30  
-
31  
-        $this->add_action_buttons();
  70
+        $this->add_action_buttons(true, get_string('requestcourse'));
32 71
     }
33 72
 
34 73
     function validation($data, $files) {
@@ -49,27 +88,42 @@ function validation($data, $files) {
49 88
         }
50 89
 
51 90
         if (!empty($foundcourses)) {
52  
-
53  
-            if (!empty($foundcourses)) {
54  
-                foreach ($foundcourses as $foundcourse) {
55  
-                    if (isset($foundcourse->requester) && $foundcourse->requester) {
56  
-                        $pending = 1;
57  
-                        $foundcoursenames[] = $foundcourse->fullname.' [*]';
58  
-                    } else {
59  
-                        $foundcoursenames[] = $foundcourse->fullname;
60  
-                    }
  91
+            foreach ($foundcourses as $foundcourse) {
  92
+                if (!empty($foundcourse->requester)) {
  93
+                    $pending = 1;
  94
+                    $foundcoursenames[] = $foundcourse->fullname.' [*]';
  95
+                } else {
  96
+                    $foundcoursenames[] = $foundcourse->fullname;
61 97
                 }
62  
-                $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
  98
+            }
  99
+            $foundcoursenamestring = implode(',', $foundcoursenames);
63 100
 
64  
-                $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
65  
-                if (!empty($pending)) {
66  
-                    $errors['shortname'] .= get_string('starpending');
67  
-                }
  101
+            $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
  102
+            if (!empty($pending)) {
  103
+                $errors['shortname'] .= get_string('starpending');
68 104
             }
69 105
         }
70 106
 
71 107
         return $errors;
72 108
     }
  109
+}
  110
+
  111
+/**
  112
+ * A form for an administrator to reject a course request.
  113
+ */
  114
+class reject_request_form extends moodleform {
  115
+    function definition() {
  116
+        $mform =& $this->_form;
73 117
 
  118
+        $mform->addElement('hidden', 'reject', 0);
  119
+
  120
+        $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
  121
+
  122
+        $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
  123
+        $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
  124
+        $mform->setType('rejectnotice', PARAM_TEXT);
  125
+
  126
+        $this->add_action_buttons(true, get_string('reject'));
  127
+    }
74 128
 }
75 129
 ?>
3  lang/en_utf8/error.php
@@ -38,6 +38,7 @@
38 38
 $string['errorcreatingfile'] = 'Error creating file \"$a\"';
39 39
 $string['erroronline'] = 'Error on line $a';
40 40
 $string['errorreadingfile'] = 'Error reading file \"$a\"';
  41
+$string['errorsavingrequest'] = 'An error occurred when trying to save your request.';
41 42
 $string['errorunzippingfiles'] = 'Error unzipping files';
42 43
 $string['fieldrequired'] = '\"$a\" is a required field';
43 44
 $string['filenotfound'] = 'Sorry, the requested file could not be found';
@@ -48,6 +49,7 @@
48 49
 $string['groupunknown'] = 'Group $a not associated to specified course';
49 50
 $string['guestnoeditprofile'] = 'The guest user cannot edit their profile';
50 51
 $string['guestnoeditprofileother'] = 'The guest user profile cannot be edited';
  52
+$string['guestsarenotallowed'] = 'The guest user is not allowed to do this';
51 53
 $string['invalidcontext'] = 'Invalid context';
52 54
 $string['invalidcourse'] = 'Invalid course';
53 55
 $string['invalidcourseid'] = 'You are trying to use an invalid course ID ($a)';
@@ -108,6 +110,7 @@
108 110
 $string['unicodeupgradeerror'] = 'Sorry, but your database is not already in Unicode, and this version of Moodle is not able to migrate your database to Unicode.  Please upgrade to Moodle 1.7.x first and perform the Unicode migration from the Admin page.  After that is done you should be able to migrate to Moodle $a';
109 111
 $string['unknowncourse'] = 'Unknown course named \"$a\"';
110 112
 $string['unknowncourseidnumber'] = 'Unknown Course ID \"$a\"';
  113
+$string['unknowncourserequest'] = 'Unknown course request';
111 114
 $string['unknowngroup'] = 'Unknown group \"$a\"';
112 115
 $string['unknownrole'] = 'Unknown role \"$a\"';
113 116
 $string['unknownuseraction'] = 'Sorry, I do not understand this user action';
7  lang/en_utf8/moodle.php
@@ -135,6 +135,7 @@
135 135
 $string['availablecourses'] = 'Available Courses';
136 136
 $string['backtoparticipants'] = 'Back to participants list';
137 137
 $string['back'] = 'Back';
  138
+$string['backtocourselisting'] = 'Back to course listing';
138 139
 $string['backup'] = 'Backup';
139 140
 $string['backupactivehelp'] = 'Choose whether or not to do automated backups.';
140 141
 $string['backupcancelled'] = 'Backup Cancelled';
@@ -282,6 +283,8 @@
282 283
 $string['coursenotaccessible'] = 'This course does not allow public access';
283 284
 $string['courseoverview'] = 'Course overview';
284 285
 $string['courseoverviewgraph'] = 'Course overview graph';
  286
+$string['coursereasonforrejecting'] = 'Your reasons for rejecting this request';
  287
+$string['coursereasonforrejectingemail'] = 'This will be emailed to the requester';
285 288
 $string['coursereject'] = 'Reject a course request';
286 289
 $string['courserejected'] = 'Course has been rejected and the requester has been notified.';
287 290
 $string['courserejectemail'] = 'Sorry, but the course you requested has been rejected. Here is the reason provided:
@@ -291,11 +294,13 @@
291 294
 $string['courserejectsubject'] = 'Your course has been rejected';
292 295
 $string['coursereports'] = 'Course reports';
293 296
 $string['courserequest'] = 'Course request';
  297
+$string['courserequestdetails'] = 'Details of the course you are requesting';
294 298
 $string['courserequestdisabled'] = 'Sorry, but requesting courses has been disabled by the administrator';
295 299
 $string['courserequestfailed'] = 'For some reason, your course request could not be saved';
296 300
 $string['courserequestintro'] = 'Use this form to request a course to be created for you.<br />Try and fill in as much information as you can to allow<br />the administrators to understand your reasons for wanting this course.';
297 301
 $string['courserequestreason'] = 'Reasons for wanting this course';
298 302
 $string['courserequestsuccess'] = 'Successfully saved your course request. Expect an email within a few days with the outcome';
  303
+$string['courserequestsupport'] = 'Supporting information to help the administrator evaluate this request';
299 304
 $string['courserestore'] = 'Course restore';
300 305
 $string['courses'] = 'Courses';
301 306
 $string['coursescategory'] = 'Courses in the same category';
@@ -1170,6 +1175,7 @@
1170 1175
 $string['paymentsorry'] = 'Thank you for your payment!  Unfortunately your payment has not yet been fully processed, and you are not yet registered to enter the course \"$a->fullname\".  Please try continuing to the course in a few seconds, but if you continue to have trouble then please alert the $a->teacher or the site administrator';
1171 1176
 $string['paymentthanks'] = 'Thank you for your payment!  You are now enrolled in your course:<br />\"$a\"';
1172 1177
 $string['people'] = 'People';
  1178
+$string['pendingrequests'] = 'Pending requests';
1173 1179
 $string['periodending'] = 'Period ending ($a)';
1174 1180
 $string['personal'] = 'Personal';
1175 1181
 $string['personalprofile'] = 'Personal profile';
@@ -1239,6 +1245,7 @@
1239 1245
 $string['registrationsend'] = 'Send registration information to moodle.org';
1240 1246
 $string['registrationyes'] = 'Yes, please notify me about important issues';
1241 1247
 $string['reject'] = 'Reject';
  1248
+$string['rejectdots'] = 'Reject...';
1242 1249
 $string['reload'] = 'Reload';
1243 1250
 $string['remoteappuser'] = 'Remote $a User';
1244 1251
 $string['remove'] = 'Remove';
16  theme/standard/styles_layout.css
@@ -2012,7 +2012,21 @@ body#course-info .generalbox.info {
2012 2012
 #my-index .name {
2013 2013
   margin-left: 5px;
2014 2014
 }
2015  
-
  2015
+#course-pending .pendingcourserequests {
  2016
+  margin-bottom: 1em;
  2017
+}
  2018
+#course-pending .pendingcourserequests .singlebutton {
  2019
+  display: inline;
  2020
+}
  2021
+#course-pending .pendingcourserequests .cell {
  2022
+  padding: 0 5px;
  2023
+}
  2024
+#course-pending .pendingcourserequests .cell.c6 {
  2025
+  white-space: nowrap;
  2026
+}
  2027
+#course-pending .singlebutton {
  2028
+  text-align: center;
  2029
+}
2016 2030
 .categorylist {
2017 2031
   width: 90%;
2018 2032
   margin-left: auto;

0 notes on commit 7f2e6a2

Please sign in to comment.
Something went wrong with that request. Please try again.