2 /*********************************
3 * Course outcomes editting page *
4 *********************************/
6 include_once('../../../config.php');
7 require_once($CFG->libdir
.'/tablelib.php');
9 $page = optional_param('page', 0, PARAM_INT
); // current page
10 $search = optional_param('search', 0, PARAM_TEXT
);
11 $deleteid = optional_param('deleteid', 0, PARAM_INT
); // which outcome to delete
12 $confirm = optional_param('confirm', 0, PARAM_INT
);
15 $courseid = required_param('id', PARAM_INT
); // course id
16 if (!$course = get_record('course', 'id', $courseid)) {
17 print_error('nocourseid');
20 require_login($courseid);
21 require_capability('gradereport/outcomes:view', get_context_instance(CONTEXT_SYSTEM
));
24 if ($deleteid && confirm_sesskey()) {
25 require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE
, $courseid));
27 // delete all outcomes used in courses
28 // delete all outcomes used in grade items
29 delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
30 delete_records('grade_outcomes', 'id', $deleteid);
32 // prints confirmation
33 $strgrades = get_string('grades');
34 $stroutcomes = get_string('outcomes', 'grades');
36 $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot
. '/grade/index.php?id='.$courseid, 'type' => 'misc');
37 $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
39 $navigation = build_navigation($navlinks);
42 print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
44 $strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
45 notice_yesno($strdeleteoutcomecheck,
46 'course.php?id='.$courseid.'&deleteid='.$deleteid.'&confirm=1&sesskey='.sesskey(),
47 'course.php?id='.$courseid.'&');
53 if ($data = data_submitted()) {
54 require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE
, $courseid));
55 if (!empty($data->add
) && !empty($data->addoutcomes
)) {
56 /// add all selected to course list
57 foreach ($data->addoutcomes
as $add) {
58 $goc -> courseid
= $courseid;
59 $goc -> outcomeid
= $add;
60 insert_record('grade_outcomes_courses', $goc);
62 } else if (!empty($data->remove
) && !empty($data->removeoutcomes
)) {
63 /// remove all selected from course outcomes list
64 foreach ($data->removeoutcomes
as $remove) {
65 delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove);
71 $strgrades = get_string('grades');
72 $stroutcomes = get_string('outcomes', 'grades');
74 $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot
. '/grade/index.php?id='.$courseid, 'type' => 'misc');
75 $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
77 $navigation = build_navigation($navlinks);
80 print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
83 $currenttab = 'courseoutcomes';
86 /// listing of all site outcomes + this course specific outcomes
87 $outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix
.'grade_outcomes
88 WHERE courseid IS NULL');
90 // outcomes used in this course
91 $courseoutcomes = get_records_sql('SELECT go.id, go.fullname
92 FROM '.$CFG->prefix
.'grade_outcomes_courses goc,
93 '.$CFG->prefix
.'grade_outcomes go
94 WHERE goc.courseid = '.$courseid.'
95 AND goc.outcomeid = go.id');
97 if (empty($courseoutcomes)) {
98 $courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid);
99 } elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $courseid)) {
100 $courseoutcomes +
= $mcourseoutcomes;
103 check_theme_arrows();
104 include_once('course.html');
106 /// interface to add/edit/delete course specific outcomes
108 print_heading(get_string('coursespecoutcome', 'gradereport_outcomes')); // course sepcific outcomes
110 $totalcount = count_records('grade_outcomes_courses', 'courseid', $courseid);
111 $baseurl = "course.php";
112 print_paging_bar($totalcount, $page, $perpage, $baseurl);
114 if ($outcomes = get_recordset('grade_outcomes', 'courseid', $courseid, '', '*', $page * $perpage, $perpage)) {
116 $tablecolumns = array('outcome', 'scale', 'edit', 'usedgradeitems');
117 $tableheaders = array(get_string('outcomes', 'grades'),
120 get_string('activities'));
122 $table = new flexible_table('outcomes');
123 $table->define_columns($tablecolumns);
124 $table->define_headers($tableheaders);
125 $table->define_baseurl($baseurl);
126 $table->set_attribute('cellspacing', '0');
127 $table->set_attribute('id', 'user-grade');
128 $table->set_attribute('class', 'boxaligncenter generaltable');
132 while ($outcome = rs_fetch_next_record($outcomes)) {
135 // full name of the outcome
136 $data[] = $outcome->fullname
;
138 // full name of the scale used by this outcomes
139 $scale= get_record('scale', 'id', $outcome->scaleid
);
140 $data[] = $scale->name
;
142 if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE
, $courseid))) {
144 $data[] = '<a href="editoutcomes.php?id='.$outcome->id
.'&courseid='.$courseid.'&sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot
.'/pix/t/edit.gif"/></a>
145 <a href="course.php?deleteid='.$outcome->id
.'&id='.$courseid.'&sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot
.'/pix/t/delete.gif"/></a>'; // icons and links
149 // num of gradeitems using this
150 $num = count_records('grade_items', 'outcomeid' ,$outcome->id
);
151 $data[] = (int) $num;
153 // num of courses using this outcome
154 $table->add_data($data);
157 $table->print_html();
159 if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE
, $courseid))) {
160 echo '<a href="editoutcomes.php?courseid='.$courseid.'">'.get_string('addoutcome', 'gradereport_outcomes').'</a>';
165 * truncates a string to a length of num
166 * @param string string
170 function truncate($string, $num) {
171 if (strlen($string) > $num +
3) {
172 $text = substr($string, 0, $num);