$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.
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');
}
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();
*/
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"');
$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.';
$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';
$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';
)
),
+ 'moodle/course:request' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ 'legacy' => array(
+ 'user' => CAP_ALLOW,
+ )
+ ),
+
'moodle/course:delete' => array(
'riskbitmask' => RISK_DATALOSS,
// 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