diff --git a/grade/report/outcomes/course.html b/grade/report/outcomes/course.html index 59232aaf549..5a1010f32c2 100755 --- a/grade/report/outcomes/course.html +++ b/grade/report/outcomes/course.html @@ -1,3 +1,5 @@ +
\ No newline at end of file diff --git a/grade/report/outcomes/course.php b/grade/report/outcomes/course.php index 21795e505f5..93c72f65a40 100755 --- a/grade/report/outcomes/course.php +++ b/grade/report/outcomes/course.php @@ -4,10 +4,78 @@ *********************************/ include_once('../../../config.php'); -$courseid = required_param('id', SITEID, PARAM_INT); // course id +require_once($CFG->libdir.'/tablelib.php'); + +$page = optional_param('page', 0, PARAM_INT); // current page +$search = optional_param('search', 0, PARAM_TEXT); +$deleteid = optional_param('deleteid', 0, PARAM_INT); // which outcome to delete +$confirm = optional_param('confirm', 0, PARAM_INT); +$perpage = 30; + +$courseid = required_param('id', PARAM_INT); // course id +if (!$course = get_record('course', 'id', $courseid)) { + print_error('nocourseid'); +} + +require_login($courseid); /// form processing - print_header(); + if ($deleteid && confirm_sesskey()) { + if ($confirm) { + // delete all outcomes used in courses + // delete all outcomes used in grade items + delete_records('grade_outcomes_courses', 'outcomeid', $deleteid); + delete_records('grade_outcomes', 'id', $deleteid); + } else { + // prints confirmation + $strgrades = get_string('grades'); + $stroutcomes = get_string('outcomes', 'grades'); + $navlinks = array(); + $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc'); + $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc'); + + $navigation = build_navigation($navlinks); + +/// Print header + print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true); + + $strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades'); + notice_yesno($strdeleteoutcomecheck, + 'course.php?id='.$courseid.'&deleteid='.$deleteid.'&confirm=1&sesskey='.sesskey(), + 'course.php?id='.$courseid.'&'); + print_footer(); + exit; + } + } + + if ($data = data_submitted()) { + + if (!empty($data->add) && !empty($data->addoutcomes)) { + /// add all selected to course list + foreach ($data->addoutcomes as $add) { + $goc -> courseid = $courseid; + $goc -> outcomeid = $add; + insert_record('grade_outcomes_courses', $goc); + } + } else if (!empty($data->remove) && !empty($data->removeoutcomes)) { + /// remove all selected from course outcomes list + foreach ($data->removeoutcomes as $remove) { + delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove); + } + } + } + +// Build navigation +$strgrades = get_string('grades'); +$stroutcomes = get_string('outcomes', 'grades'); +$navlinks = array(); +$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc'); +$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc'); + +$navigation = build_navigation($navlinks); + +/// Print header +print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true); // Add tabs $currenttab = 'outcomesettings'; @@ -15,11 +83,90 @@ $courseid = required_param('id', SITEID, PARAM_INT); // course id /// listing of all site outcomes + this course specific outcomes $outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix.'grade_outcomes - WHERE ISNULL(courseid)'); - get_records('grade_outcomes', 'courseid', $courseid); + WHERE courseid < 1'); + + $courseoutcomes = get_records_sql('SELECT go.id, go.fullname + FROM '.$CFG->prefix.'grade_outcomes_courses goc, + '.$CFG->prefix.'grade_outcomes go + WHERE goc.courseid = '.$courseid.' + AND goc.outcomeid = go.id'); + + if (empty($courseoutcomes)) { + $courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid); + } elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $courseid)) { + $courseoutcomes += $mcourseoutcomes; + } + check_theme_arrows(); include_once('course.html'); + + /// interface to add/edit/delete course specific outcomes + echo ''; + print_string('coursespecoutcome', 'grades'); // course sepcific outcomes + + $totalcount = count_records('grade_outcomes_courses', 'courseid', $courseid); + $baseurl = "course.php"; + print_paging_bar($totalcount, $page, $perpage, $baseurl); + + if ($outcomes = get_recordset('grade_outcomes', 'courseid', $courseid, '', '*', $page * $perpage, $perpage)) { + + $tablecolumns = array('outcome', 'scale', 'edit', 'usedgradeitems'); + $tableheaders = array(get_string('outcomes'), + get_string('scale'), + get_string('operations'), + get_string('usedgradeitem')); + + $table = new flexible_table('outcomes'); + $table->define_columns($tablecolumns); + $table->define_headers($tableheaders); + $table->define_baseurl($baseurl); + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'user-grade'); + $table->set_attribute('class', 'boxaligncenter generaltable'); + + $table->setup(); + + foreach ($outcomes as $outcome) { + $data = array(); + + // full name of the outcome + $data[] = $outcome['fullname']; + + // full name of the scale used by this outcomes + $scale= get_record('scale', 'id', $outcome['scaleid']); + $data[] = $scale->name; + + // add operations + $data[] = '
+
'; // icons and links
+
+ // num of gradeitems using this
+ $num = count_records('grade_items', 'outcomeid' ,$outcome['id']);
+ $data[] = (int) $num;
+
+ // num of courses using this outcome
+ $table->add_data($data);
+ }
+
+ $table->print_html();
+ }
+
+ echo 'Add a new outcome';
print_footer();
+
+/**
+ * truncates a string to a length of num
+ * @param string string
+ * @param int num
+ * @return string
+ */
+function truncate($string, $num) {
+ if (strlen($string) > $num + 3) {
+ $text = substr($string, 0, $num);
+ $text = $text."...";
+ }
+ return $string;
+}
?>
\ No newline at end of file
diff --git a/grade/report/outcomes/editoutcomes.php b/grade/report/outcomes/editoutcomes.php
index 6988a840e2d..73237059f5e 100755
--- a/grade/report/outcomes/editoutcomes.php
+++ b/grade/report/outcomes/editoutcomes.php
@@ -43,7 +43,8 @@ class edit_outcomes_form extends moodleform {
$id = optional_param('id', 0, PARAM_INT); // id of the outcome
if ($courseid = optional_param('courseid', 0, PARAM_INT)) {
// optional course id, if set, editting from course
- $returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php";
+ require_login($courseid);
+ $returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php?id=$courseid";
} else {
// admin editting site level outcomes
$returnurl = $CFG->wwwroot."/grade/report/outcomes/site.php";
@@ -73,11 +74,19 @@ if ($data = $mform->get_data()) {
redirect($returnurl);
}
+// Build navigation
+$strgrades = get_string('grades');
+$stroutcomes = get_string('outcomes', 'grades');
+$navlinks = array();
+$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
+$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
+
+$navigation = build_navigation($navlinks);
+/// Print header
+print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// Add tabs
$currenttab = 'editoutcomes';
include('tabs.php');
-
-print_header();
$mform->display();
print_footer();
?>
\ No newline at end of file
diff --git a/grade/report/outcomes/site.php b/grade/report/outcomes/site.php
index 65376539390..ed2f5726d61 100755
--- a/grade/report/outcomes/site.php
+++ b/grade/report/outcomes/site.php
@@ -26,17 +26,22 @@ $perpage = 30;
delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
delete_records('grade_outcomes', 'id', $deleteid);
} else {
+
+ $strgrades = get_string('grades');
+ $stroutcomes = get_string('outcomes', 'grades');
+ $navlinks = array();
+ $navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc');
+ $navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc');
+
+ $navigation = build_navigation($navlinks);
+
+/// Print header
+ print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// prints confirmation
- print_header('');
- echo '';
+ $strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
+ notice_yesno($strdeleteoutcomecheck,
+ 'site.php?deleteid='.$deleteid.'&confirm=1&sesskey='.sesskey(),
+ 'site.php');
print_footer();
exit;
}
@@ -51,7 +56,7 @@ $perpage = 30;
include('tabs.php');
$totalcount = count_records('grade_outcomes');
- $baseurl = "settings.php";
+ $baseurl = "site.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
if ($outcomes = get_recordset('grade_outcomes', '', '', '', '*', $page * $perpage, $perpage)) {
@@ -94,14 +99,14 @@ $perpage = 30;
// add operations
$data[] = '
-
'; // icons and links
+
'; // icons and links
// num of gradeitems using this
- $num = count_records('grade_outcomes_courses', 'outcomeid' ,$outcome['id']);
+ $num = count_records('grade_items', 'outcomeid' ,$outcome['id']);
$data[] = (int) $num;
// num of courses using this outcome
- $num = count_records('grade_items', 'outcomeid', $outcome['id']);
+ $num = count_records('grade_outcomes_courses', 'outcomeid', $outcome['id']);
$data[] = (int) $num;
$table->add_data($data);