Skip to content

Commit

Permalink
course request: MDL-17575 and MDL-6160 further improvements:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tjhunt committed Dec 10, 2008
1 parent bc7bc8e commit 5d922e4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions admin/settings/courses.php
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion course/lib.php
Expand Up @@ -1879,7 +1879,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');
}
Expand Down
20 changes: 19 additions & 1 deletion course/request.php
Expand Up @@ -44,27 +44,45 @@
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 (!insert_record('course_request', $data)) {
print_error('errorsavingrequest', '', $returnurl);
}

/// Notify the admin if required.
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');
print_header($strtitle, $strtitle, build_navigation($strtitle), $requestform->focus());
print_heading($strtitle);
$requestform->display();
Expand Down
12 changes: 12 additions & 0 deletions course/request_form.php
Expand Up @@ -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"');
Expand Down
4 changes: 4 additions & 0 deletions lang/en_utf8/admin.php
Expand Up @@ -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.';
Expand Down Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/role.php
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions lib/db/access.php
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -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

Expand Down

0 comments on commit 5d922e4

Please sign in to comment.