2 // allow the administrators to look through a list of course requests and either approve them or reject them.
4 require_once('../config.php');
5 require_once($CFG->libdir
.'/pagelib.php');
6 require_once($CFG->libdir
.'/blocklib.php');
7 require_once('lib.php');
11 require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
13 $approve = optional_param('approve', 0, PARAM_INT
);
14 $reject = optional_param('reject', 0, PARAM_INT
);
15 $rejectnotice = optional_param('rejectnotice', '', PARAM_CLEANHTML
);
17 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);
23 // place at beginning of category
24 fix_course_sortorder();
25 if (empty($CFG->defaultrequestedcategory
)) {
26 $CFG->defaultrequestedcategory
= 1; //yuk, but default to miscellaneous.
28 $course->category
= $CFG->defaultrequestedcategory
;
29 $course->sortorder
= get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$course->category");
30 if (empty($course->sortorder
)) {
31 $course->sortorder
= 1000;
33 $course->requested
= 1;
34 unset($course->reason
);
36 $teacherid = $course->requester
;
37 unset($course->requester
);
38 $course->teacher
= get_string("defaultcourseteacher");
39 $course->teachers
= get_string("defaultcourseteachers");
40 $course->student
= get_string("defaultcoursestudent");
41 $course->students
= get_string("defaultcoursestudents");
42 if (!empty($CFG->restrictmodulesfor
) && $CFG->restrictmodulesfor
!= 'none' && !empty($CFG->restrictbydefault
)) {
43 $course->restrictmodules
= 1;
45 if ($courseid = insert_record("course",$course)) {
46 $page = page_create_object(PAGE_COURSE_VIEW
, $courseid);
47 blocks_repopulate_page($page); // Return value not checked because you can always edit later
48 add_teacher($teacherid,$courseid);
49 $course->id
= $courseid;
50 if (!empty($CFG->restrictmodulesfor
) && $CFG->restrictmodulesfor
!= 'none' && !empty($CFG->restrictbydefault
)) { // if we're all or requested we're ok.
51 $allowedmods = explode(',',$CFG->defaultallowedmodules
);
52 update_restricted_mods($course,$allowedmods);
54 delete_records('course_request','id',$approve);
57 if (!empty($success)) {
58 $user = get_record('user','id',$teacherid);
59 $a->name
= $course->fullname
;
60 $a->url
= $CFG->wwwroot
.'/course/view.php?id='.$courseid;
61 $a->teacher
= $course->teacher
;
62 email_to_user($user,$USER,get_string('courseapprovedsubject'),get_string('courseapprovedemail','moodle',$a));
63 redirect($CFG->wwwroot
.'/course/edit.php?id='.$courseid);
67 error(get_string('courseapprovedfailed'));
73 $strtitle = get_string('coursespending');
74 $strheading = get_string(((!empty($reject)) ?
'coursereject' : 'coursespending'));
76 print_header($strtitle,$strheading,build_navigation(array(array('name'=>$strheading,'link'=>'','type'=>'misc'))));
78 if (!empty($reject) and confirm_sesskey()) {
79 if ($reject = get_record("course_request","id",$reject)) {
80 if (empty($rejectnotice)) {
81 // display a form for writing a reason
82 print_simple_box_start('center');
83 print_string('courserejectreason');
84 include('pending-reject.html');
85 print_simple_box_end();
88 $user = get_record("user","id",$reject->requester
);
89 email_to_user($user,$USER,get_string('courserejectsubject'),get_string('courserejectemail','moodle',$rejectnotice));
90 delete_records("course_request","id",$reject->id
);
91 notice(get_string('courserejected'),'pending.php');
94 } else if ($pending = get_records("course_request")) {
96 $table->cellpadding
= 4;
97 $table->cellspacing
= 3;
98 $table->align
= array('center','center','center','center','center','center','center');
99 $table->head
= array(' ',get_string('shortname'),get_string('fullname'),get_string('requestedby'),get_string('summary'),
100 get_string('requestreason'),'');
101 $strrequireskey = get_string('requireskey');
102 foreach ($pending as $course) {
103 $requester = get_record('user','id',$course->requester
);
104 // check here for shortname collisions and warn about them.
105 if ($match = get_record("course","shortname",$course->shortname
)) {
106 $course->shortname
.= ' [*]';
109 //do not output raw html from request, quote html entities using s()!!
110 $table->data
[] = array(((!empty($course->password
)) ?
111 '<img hspace="1" alt="'.$strrequireskey.'" class="icon" src="'.$CFG->pixpath
.'/i/key.gif" />' : ''),
112 format_string($course->shortname
),format_string($course->fullname
),fullname($requester),
113 format_string($course->summary
),format_string($course->reason
),
114 '<a href="pending.php?approve='.$course->id
.'&sesskey='.sesskey().'">'.get_string('approve').'</a> | '
115 .'<a href="pending.php?reject='.$course->id
.'&sesskey='.sesskey().'">'.get_string('reject').'</a>');
118 if (!empty($collision)) {
119 print_string('shortnamecollisionwarning');
122 notice(get_string('nopendingcourses'));
123 // no pending messages.