2006-04-12 07:25:09 +00:00
|
|
|
<?php // $Id$
|
|
|
|
// allow the administrators to look through a list of course requests and either approve them or reject them.
|
2005-08-16 06:15:49 +00:00
|
|
|
|
2006-04-12 07:25:09 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once($CFG->libdir.'/pagelib.php');
|
2007-08-17 19:09:11 +00:00
|
|
|
require_once($CFG->libdir.'/blocklib.php');
|
2006-04-12 07:25:46 +00:00
|
|
|
require_once('lib.php');
|
2008-07-24 08:38:03 +00:00
|
|
|
require_once($CFG->libdir.'/eventslib.php');
|
2005-08-16 06:15:49 +00:00
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
2008-04-24 08:39:47 +00:00
|
|
|
require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM));
|
2005-08-16 06:15:49 +00:00
|
|
|
|
2006-04-12 07:25:09 +00:00
|
|
|
$approve = optional_param('approve', 0, PARAM_INT);
|
|
|
|
$reject = optional_param('reject', 0, PARAM_INT);
|
|
|
|
$rejectnotice = optional_param('rejectnotice', '', PARAM_CLEANHTML);
|
2005-08-16 06:15:49 +00:00
|
|
|
|
2006-04-12 07:25:09 +00:00
|
|
|
if (!empty($approve) and confirm_sesskey()) {
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($course = $DB->get_record("course_request", array("id"=>$approve))) {
|
2005-08-16 06:15:49 +00:00
|
|
|
|
2008-06-16 14:25:53 +00:00
|
|
|
$category = get_course_category($CFG->defaultrequestcategory);
|
2008-01-08 12:51:07 +00:00
|
|
|
|
|
|
|
$course->category = $CFG->defaultrequestcategory;
|
2008-06-16 14:25:53 +00:00
|
|
|
$course->sortorder = $category->sortorder; // place as the first in category
|
2005-08-16 06:15:49 +00:00
|
|
|
$course->requested = 1;
|
|
|
|
unset($course->reason);
|
|
|
|
unset($course->id);
|
|
|
|
$teacherid = $course->requester;
|
|
|
|
unset($course->requester);
|
|
|
|
$course->teacher = get_string("defaultcourseteacher");
|
|
|
|
$course->teachers = get_string("defaultcourseteachers");
|
|
|
|
$course->student = get_string("defaultcoursestudent");
|
|
|
|
$course->students = get_string("defaultcoursestudents");
|
|
|
|
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
|
|
|
|
$course->restrictmodules = 1;
|
|
|
|
}
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($courseid = $DB->insert_record("course",$course)) {
|
2005-08-16 06:15:49 +00:00
|
|
|
$page = page_create_object(PAGE_COURSE_VIEW, $courseid);
|
|
|
|
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
2008-05-01 22:15:02 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
|
|
|
role_assign($CFG->creatornewroleid, $teacherid, 0, $context->id); // assing teacher role
|
2005-08-16 06:15:49 +00:00
|
|
|
$course->id = $courseid;
|
|
|
|
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) { // if we're all or requested we're ok.
|
|
|
|
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
|
|
|
update_restricted_mods($course,$allowedmods);
|
|
|
|
}
|
2008-06-02 08:13:24 +00:00
|
|
|
$DB->delete_records('course_request', array('id'=>$approve));
|
2005-08-16 06:15:49 +00:00
|
|
|
$success = 1;
|
2008-06-16 14:25:53 +00:00
|
|
|
fix_course_sortorder();
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
if (!empty($success)) {
|
2008-06-02 08:13:24 +00:00
|
|
|
$user = $DB->get_record('user', array('id'=>$teacherid));
|
2005-08-16 06:15:49 +00:00
|
|
|
$a->name = $course->fullname;
|
|
|
|
$a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
|
|
|
|
$a->teacher = $course->teacher;
|
2008-07-24 08:38:03 +00:00
|
|
|
|
|
|
|
$eventdata = new object();
|
|
|
|
$eventdata->modulename = 'moodle';
|
|
|
|
$eventdata->userfrom = $USER;
|
|
|
|
$eventdata->userto = $user;
|
|
|
|
$eventdata->subject = get_string('courseapprovedsubject');
|
|
|
|
$eventdata->fullmessage = get_string('courseapprovedemail','moodle',$a);
|
|
|
|
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
|
|
|
$eventdata->fullmessagehtml = '';
|
|
|
|
$eventdata->smallmessage = '';
|
|
|
|
events_trigger('message_send', $eventdata);
|
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
redirect($CFG->wwwroot.'/course/edit.php?id='.$courseid);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
else {
|
2008-04-24 08:39:47 +00:00
|
|
|
print_error('courseapprovedfailed');
|
2005-08-16 06:15:49 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2005-08-16 06:15:49 +00:00
|
|
|
$strtitle = get_string('coursespending');
|
|
|
|
$strheading = get_string(((!empty($reject)) ? 'coursereject' : 'coursespending'));
|
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
print_header($strtitle,$strheading,build_navigation(array(array('name'=>$strheading,'link'=>'','type'=>'misc'))));
|
|
|
|
|
2006-04-12 07:25:09 +00:00
|
|
|
if (!empty($reject) and confirm_sesskey()) {
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($reject = $DB->get_record("course_request", array("id"=>$reject))) {
|
2005-08-16 06:15:49 +00:00
|
|
|
if (empty($rejectnotice)) {
|
|
|
|
// display a form for writing a reason
|
|
|
|
print_simple_box_start('center');
|
|
|
|
print_string('courserejectreason');
|
|
|
|
include('pending-reject.html');
|
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
else {
|
2008-06-02 08:13:24 +00:00
|
|
|
$user = $DB->get_record("user", array("id"=>$reject->requester));
|
2008-07-24 08:38:03 +00:00
|
|
|
|
|
|
|
$eventdata = new object();
|
|
|
|
$eventdata->modulename = 'moodle';
|
|
|
|
$eventdata->userfrom = $USER;
|
|
|
|
$eventdata->userto = $user;
|
|
|
|
$eventdata->subject = get_string('courserejectsubject');
|
|
|
|
$eventdata->fullmessage = get_string('courserejectemail','moodle',$rejectnotice);
|
|
|
|
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
|
|
|
$eventdata->fullmessagehtml = '';
|
|
|
|
$eventdata->smallmessage = '';
|
|
|
|
events_trigger('message_send', $eventdata);
|
2008-08-02 00:04:29 +00:00
|
|
|
|
2008-06-02 08:13:24 +00:00
|
|
|
$DB->delete_records("course_request", array("id"=>$reject->id));
|
2005-08-16 06:15:49 +00:00
|
|
|
notice(get_string('courserejected'),'pending.php');
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 08:13:24 +00:00
|
|
|
} else if ($pending = $DB->get_records("course_request")) {
|
2005-08-16 06:15:49 +00:00
|
|
|
// loop through
|
|
|
|
$table->cellpadding = 4;
|
|
|
|
$table->cellspacing = 3;
|
2005-10-12 01:17:03 +00:00
|
|
|
$table->align = array('center','center','center','center','center','center','center');
|
2008-03-19 08:49:23 +00:00
|
|
|
$table->head = array(' ',get_string('shortnamecourse'),get_string('fullnamecourse'),get_string('requestedby'),get_string('summary'),
|
2005-08-16 06:15:49 +00:00
|
|
|
get_string('requestreason'),'');
|
2005-10-12 01:17:03 +00:00
|
|
|
$strrequireskey = get_string('requireskey');
|
2005-08-16 06:15:49 +00:00
|
|
|
foreach ($pending as $course) {
|
2008-06-02 08:13:24 +00:00
|
|
|
$requester = $DB->get_record('user', array('id'=>$course->requester));
|
2005-08-16 06:15:49 +00:00
|
|
|
// check here for shortname collisions and warn about them.
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($match = $DB->get_record("course", array("shortname"=>$course->shortname))) {
|
2005-08-16 06:15:49 +00:00
|
|
|
$course->shortname .= ' [*]';
|
|
|
|
$collision = 1;
|
|
|
|
}
|
2006-04-12 16:41:10 +00:00
|
|
|
//do not output raw html from request, quote html entities using s()!!
|
2007-08-17 19:09:11 +00:00
|
|
|
$table->data[] = array(((!empty($course->password)) ?
|
2007-01-08 09:14:05 +00:00
|
|
|
'<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$CFG->pixpath.'/i/key.gif" />' : ''),
|
2007-02-28 06:25:22 +00:00
|
|
|
format_string($course->shortname),format_string($course->fullname),fullname($requester),
|
|
|
|
format_string($course->summary),format_string($course->reason),
|
2006-04-12 16:41:10 +00:00
|
|
|
'<a href="pending.php?approve='.$course->id.'&sesskey='.sesskey().'">'.get_string('approve').'</a> | '
|
|
|
|
.'<a href="pending.php?reject='.$course->id.'&sesskey='.sesskey().'">'.get_string('reject').'</a>');
|
2005-08-16 06:15:49 +00:00
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
if (!empty($collision)) {
|
|
|
|
print_string('shortnamecollisionwarning');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
notice(get_string('nopendingcourses'));
|
|
|
|
// no pending messages.
|
|
|
|
}
|
|
|
|
|
|
|
|
print_footer();
|
|
|
|
|
|
|
|
|
2006-10-23 13:42:23 +00:00
|
|
|
?>
|