From: samhemelryk Date: Fri, 25 Sep 2009 05:24:13 +0000 (+0000) Subject: course MDL-19794 Replaced deprecated functions, added set_url calls and boilerplates X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d9cb06dc0ed75ed11fb5d81af13af58d3bc3b1b5;p=moodle.git course MDL-19794 Replaced deprecated functions, added set_url calls and boilerplates --- diff --git a/course/editsection.php b/course/editsection.php index f3c32a65f6..9b2c2a334f 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -1,61 +1,88 @@ -libdir.'/filelib.php'); - require_once('editsection_form.php'); +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . - $id = required_param('id',PARAM_INT); // Week/topic ID +/** + * Edit the introduction of a section + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ - if (! $section = $DB->get_record("course_sections", array("id"=>$id))) { - print_error("sectionnotexist"); - } +require_once("../config.php"); +require_once("lib.php"); +require_once($CFG->libdir.'/filelib.php'); +require_once('editsection_form.php'); - if (! $course = $DB->get_record("course", array("id"=>$section->course))) { - print_error("invalidcourseid"); - } +$id = required_param('id',PARAM_INT); // Week/topic ID - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/course:update', $context); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/editsection.php', array('id'=>$id))); - $draftitemid = file_get_submitted_draft_itemid('summary'); - $currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary); - - $mform = new editsection_form(null, $course); - $data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid)); - $mform->set_data($data); // set defaults +if (! $section = $DB->get_record("course_sections", array("id"=>$id))) { + print_error("sectionnotexist"); +} + +if (! $course = $DB->get_record("course", array("id"=>$section->course))) { + print_error("invalidcourseid"); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $course->id); +require_capability('moodle/course:update', $context); + +$draftitemid = file_get_submitted_draft_itemid('summary'); +$currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary); + +$mform = new editsection_form(null, $course); +$data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid)); +$mform->set_data($data); // set defaults /// If data submitted, then process and store. - if ($mform->is_cancelled()){ - redirect($CFG->wwwroot.'/course/view.php?id='.$course->id); +if ($mform->is_cancelled()){ + redirect($CFG->wwwroot.'/course/view.php?id='.$course->id); - } else if ($data = $mform->get_data()) { +} else if ($data = $mform->get_data()) { - $text = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']); - $DB->set_field("course_sections", "summary", $text, array("id"=>$section->id)); - add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); - redirect("view.php?id=$course->id"); - } + $text = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']); + $DB->set_field("course_sections", "summary", $text, array("id"=>$section->id)); + add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); + redirect("view.php?id=$course->id"); +} /// Inelegant hack for bug 3408 - if ($course->format == 'site') { - $sectionname = get_string('site'); - $stredit = get_string('edit', '', " $sectionname"); - $strsummaryof = get_string('summaryof', '', " $sectionname"); - } else { - $sectionname = get_section_name($course->format); - $stredit = get_string('edit', '', " $sectionname $section->section"); - $strsummaryof = get_string('summaryof', '', " $sectionname $section->section"); - } - - $PAGE->set_title($stredit); - $PAGE->navbar->add($stredit); - $PAGE->set_focuscontrol('theform.summary'); - echo $OUTPUT->header(); - print_heading_with_help($strsummaryof, 'summaries'); - $mform->display(); - echo $OUTPUT->footer(); +if ($course->format == 'site') { + $sectionname = get_string('site'); + $stredit = get_string('edit', '', " $sectionname"); + $strsummaryof = get_string('summaryof', '', " $sectionname"); +} else { + $sectionname = get_section_name($course->format); + $stredit = get_string('edit', '', " $sectionname $section->section"); + $strsummaryof = get_string('summaryof', '', " $sectionname $section->section"); +} + +$PAGE->set_title($stredit); +$PAGE->navbar->add($stredit); +$PAGE->set_focuscontrol('theform.summary'); +echo $OUTPUT->header(); +$helpicon = new moodle_help_icon(); +$helpicon->text = $strsummaryof; +$helpicon->page = 'summaries'; +echo $OUTPUT->heading_with_help($helpicon); +$mform->display(); +echo $OUTPUT->footer(); \ No newline at end of file diff --git a/course/enrol.php b/course/enrol.php index 24ce7fe9cf..7844da73a9 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -1,106 +1,134 @@ -dirroot/enrol/enrol.class.php"); - - $id = required_param('id', PARAM_INT); - $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed? - - if (!isloggedin()) { - // do not use require_login here because we are usually comming from it - redirect(get_login_url()); - } - - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error("That's an invalid course id"); - } - - if (! $context = get_context_instance(CONTEXT_COURSE, $course->id) ) { - print_error("That's an invalid course id"); - } +. + +/** + * Depending on the current enrolment method, this page + * presents the user with whatever they need to know when + * they try to enrol in a course. + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../config.php"); +require_once("lib.php"); +require_once("$CFG->dirroot/enrol/enrol.class.php"); + +$id = required_param('id', PARAM_INT); +$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed? + +$url = new moodle_url($CFG->wwwroot.'/course/enrol.php', array('id'=>$id)); +if ($loginasguest !== 0) { + $url->param('loginasguest', $loginasguest); +} +$PAGE->set_url($url); + +if (!isloggedin()) { + // do not use require_login here because we are usually comming from it + redirect(get_login_url()); +} + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error("That's an invalid course id"); +} + +if (! $context = get_context_instance(CONTEXT_COURSE, $course->id) ) { + print_error("That's an invalid course id"); +} /// do not use when in course login as - if (session_is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) { - print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid); - } +if (session_is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) { + print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid); +} - $enrol = enrolment_factory::factory($course->enrol); // do not use if (!$enrol... here, it can not work in PHP4 - see MDL-7529 +$enrol = enrolment_factory::factory($course->enrol); // do not use if (!$enrol... here, it can not work in PHP4 - see MDL-7529 /// Refreshing all current role assignments for the current user - load_all_capabilities(); +load_all_capabilities(); /// Double check just in case they are actually enrolled already and /// thus got to this script by mistake. This might occur if enrolments /// changed during this session or something - if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) { - if (!empty($SESSION->wantsurl)) { - $destination = $SESSION->wantsurl; - unset($SESSION->wantsurl); - } else { - $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; - } - redirect($destination); // Bye! +if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) { + if (!empty($SESSION->wantsurl)) { + $destination = $SESSION->wantsurl; + unset($SESSION->wantsurl); + } else { + $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; } + redirect($destination); // Bye! +} /// Check if the course is a meta course (bug 5734) - if ($course->metacourse) { - echo $OUTPUT->header(); - notice(get_string('coursenotaccessible'), "$CFG->wwwroot/index.php"); - } +if ($course->metacourse) { + echo $OUTPUT->header(); + notice(get_string('coursenotaccessible'), "$CFG->wwwroot/index.php"); +} /// Users can't enroll to site course - if ($course->id == SITEID) { - echo $OUTPUT->header(); - notice(get_string('enrollfirst'), "$CFG->wwwroot/index.php"); - } +if ($course->id == SITEID) { + echo $OUTPUT->header(); + notice(get_string('enrollfirst'), "$CFG->wwwroot/index.php"); +} /// Double check just in case they are enrolled to start in the future - if ($course->enrolperiod) { // Only active if the course has an enrolment period in effect - if ($roles = get_user_roles($context, $USER->id)) { - foreach ($roles as $role) { - if ($role->timestart and ($role->timestart >= time())) { - $message = get_string('enrolmentnotyet', '', userdate($student->timestart)); - echo $OUTPUT->header(); - notice($message, "$CFG->wwwroot/index.php"); - } +if ($course->enrolperiod) { // Only active if the course has an enrolment period in effect + if ($roles = get_user_roles($context, $USER->id)) { + foreach ($roles as $role) { + if ($role->timestart and ($role->timestart >= time())) { + $message = get_string('enrolmentnotyet', '', userdate($student->timestart)); + echo $OUTPUT->header(); + notice($message, "$CFG->wwwroot/index.php"); } } } +} /// Check if the course is enrollable - if (!method_exists($enrol, 'print_entry')) { - echo $OUTPUT->header(); - notice(get_string('enrolmentnointernal'), "$CFG->wwwroot/index.php"); - } - - if (!$course->enrollable || - ($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) || - ($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time()) - ) { - $PAGE->set_title($course->shortname); - $PAGE->set_heading($course->fullname); - $PAGE->navbar->add($course->shortname); - echo $OUTPUT->header(); - notice(get_string('notenrollable'), "$CFG->wwwroot/index.php"); - } +if (!method_exists($enrol, 'print_entry')) { + echo $OUTPUT->header(); + notice(get_string('enrolmentnointernal'), "$CFG->wwwroot/index.php"); +} + +if (!$course->enrollable || + ($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) || + ($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time()) + ) { + $PAGE->set_title($course->shortname); + $PAGE->set_heading($course->fullname); + $PAGE->navbar->add($course->shortname); + echo $OUTPUT->header(); + notice(get_string('notenrollable'), "$CFG->wwwroot/index.php"); +} /// Check the submitted enrolment information if there is any (eg could be enrolment key) - if ($form = data_submitted()) { - $enrol->check_entry($form, $course); // Should terminate/redirect in here if it's all OK - } +if ($form = data_submitted()) { + $enrol->check_entry($form, $course); // Should terminate/redirect in here if it's all OK +} /// Otherwise, we print the entry form. - $enrol->print_entry($course); +$enrol->print_entry($course); /// Easy! -?> +?> \ No newline at end of file diff --git a/course/import.php b/course/import.php index c5aba8e3b4..ffb0d05da8 100644 --- a/course/import.php +++ b/course/import.php @@ -1,50 +1,74 @@ -. - $id = required_param('id', PARAM_INT); // course id to import TO +/** + * Display all the interfaces for importing data into a specific course + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error("That's an invalid course id"); - } +require_once('../config.php'); - require_login($course->id); +$id = required_param('id', PARAM_INT); // course id to import TO - require_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $id)); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/import.php', array('id'=>$id))); + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error("That's an invalid course id"); +} + +require_login($course->id); + +require_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $id)); /// Always we begin an import, we delete all backup/restore/import session structures - if (isset($SESSION->course_header)) { - unset ($SESSION->course_header); - } - if (isset($SESSION->info)) { - unset ($SESSION->info); - } - if (isset($SESSION->backupprefs)) { - unset ($SESSION->backupprefs); - } - if (isset($SESSION->restore)) { - unset ($SESSION->restore); - } - if (isset($SESSION->import_preferences)) { - unset ($SESSION->import_preferences); - } - - $strimport = get_string('import'); - - $PAGE->set_title($course->fullname.': '.$strimport); - $PAGE->set_heading($course->fullname.': '.$strimport); - $PAGE->navbar->add($strimport); - - echo $OUTPUT->header(); - - $imports = get_plugin_list('import'); - - foreach ($imports as $import => $importdir) { - echo '
'; - include($importdir.'/mod.php'); - echo '
'; - } - - echo $OUTPUT->footer(); +if (isset($SESSION->course_header)) { + unset ($SESSION->course_header); +} +if (isset($SESSION->info)) { + unset ($SESSION->info); +} +if (isset($SESSION->backupprefs)) { + unset ($SESSION->backupprefs); +} +if (isset($SESSION->restore)) { + unset ($SESSION->restore); +} +if (isset($SESSION->import_preferences)) { + unset ($SESSION->import_preferences); +} + +$strimport = get_string('import'); + +$PAGE->set_title($course->fullname.': '.$strimport); +$PAGE->set_heading($course->fullname.': '.$strimport); +$PAGE->navbar->add($strimport); + +echo $OUTPUT->header(); + +$imports = get_plugin_list('import'); + +foreach ($imports as $import => $importdir) { + echo '
'; + include($importdir.'/mod.php'); + echo '
'; +} + +echo $OUTPUT->footer(); ?> diff --git a/course/import/activities/index.php b/course/import/activities/index.php index 48c666ad67..6814aab75c 100644 --- a/course/import/activities/index.php +++ b/course/import/activities/index.php @@ -1,69 +1,109 @@ -dirroot.'/backup/lib.php'); - require_once($CFG->dirroot.'/backup/restorelib.php'); +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . - $id = required_param('id', PARAM_INT); // course id to import TO - $fromcourse = optional_param('fromcourse', 0, PARAM_INT); - $fromcoursesearch = optional_param('fromcoursesearch', '', PARAM_RAW); - $page = optional_param('page', 0, PARAM_INT); - $filename = optional_param('filename', 0, PARAM_PATH); +/** + * preliminary page to find a course to import data from & interface with the + * backup/restore functionality + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ - $strimportactivities = get_string('importactivities'); +require_once('../../../config.php'); +require_once('../../lib.php'); +require_once($CFG->dirroot.'/backup/lib.php'); +require_once($CFG->dirroot.'/backup/restorelib.php'); - if (! ($course = $DB->get_record("course", array("id"=>$id)))) { - print_error("invalidcourseid"); - } +$id = required_param('id', PARAM_INT); // course id to import TO +$fromcourse = optional_param('fromcourse', 0, PARAM_INT); +$fromcoursesearch = optional_param('fromcoursesearch', '', PARAM_RAW); +$page = optional_param('page', 0, PARAM_INT); +$filename = optional_param('filename', 0, PARAM_PATH); - if (!$site = get_site()){ - print_error("siteisnotdefined", 'debug'); - } +$url = new moodle_url($CFG->wwwroot.'/course/import/activities/index.php', array('id'=>$id)); +if ($fromcourse !== 0) { + $url->param('fromcourse', $fromcourse); +} +if ($fromcoursesearch !== '') { + $url->param('fromcoursesearch', $fromcoursesearch); +} +if ($page !== 0) { + $url->param('page', $page); +} +if ($filename !== 0) { + $url->param('filename', $filename); +} +$PAGE->set_url($url); - require_login($course->id); - $tocontext = get_context_instance(CONTEXT_COURSE, $id); - if ($fromcourse) { - $fromcontext = get_context_instance(CONTEXT_COURSE, $fromcourse); - } - $syscontext = get_context_instance(CONTEXT_SYSTEM); +$strimportactivities = get_string('importactivities'); + +if (! ($course = $DB->get_record("course", array("id"=>$id)))) { + print_error("invalidcourseid"); +} + +if (!$site = get_site()){ + print_error("siteisnotdefined", 'debug'); +} - if (!has_capability('moodle/course:manageactivities', $tocontext)) { +require_login($course->id); +$tocontext = get_context_instance(CONTEXT_COURSE, $id); +if ($fromcourse) { + $fromcontext = get_context_instance(CONTEXT_COURSE, $fromcourse); +} +$syscontext = get_context_instance(CONTEXT_SYSTEM); + +if (!has_capability('moodle/course:manageactivities', $tocontext)) { + print_error('nopermissiontoimportact'); +} + +// if we're not a course creator , we can only import from our own courses. +if (has_capability('moodle/course:create', $syscontext)) { + $creator = true; +} + +if ($from = $DB->get_record('course', array('id'=>$fromcourse))) { + if (!has_capability('moodle/course:manageactivities', $fromcontext)) { print_error('nopermissiontoimportact'); } + if (!empty($filename) && file_exists($CFG->dataroot.'/'.$filename) && !empty($SESSION->import_preferences)) { + $restore = backup_to_restore_array($SESSION->import_preferences); + $restore->restoreto = RESTORETO_CURRENT_ADDING; + $restore->course_id = $id; + $restore->importing = 1; // magic variable so we know that we're importing rather than just restoring. - // if we're not a course creator , we can only import from our own courses. - if (has_capability('moodle/course:create', $syscontext)) { - $creator = true; + $SESSION->restore = $restore; + redirect($CFG->wwwroot.'/backup/restore.php?file='.$filename.'&id='.$fromcourse.'&to='.$id); } - - if ($from = $DB->get_record('course', array('id'=>$fromcourse))) { - if (!has_capability('moodle/course:manageactivities', $fromcontext)) { - print_error('nopermissiontoimportact'); - } - if (!empty($filename) && file_exists($CFG->dataroot.'/'.$filename) && !empty($SESSION->import_preferences)) { - $restore = backup_to_restore_array($SESSION->import_preferences); - $restore->restoreto = RESTORETO_CURRENT_ADDING; - $restore->course_id = $id; - $restore->importing = 1; // magic variable so we know that we're importing rather than just restoring. - - $SESSION->restore = $restore; - redirect($CFG->wwwroot.'/backup/restore.php?file='.$filename.'&id='.$fromcourse.'&to='.$id); - } - else { - redirect($CFG->wwwroot.'/backup/backup.php?id='.$from->id.'&to='.$course->id); - } + else { + redirect($CFG->wwwroot.'/backup/backup.php?id='.$from->id.'&to='.$course->id); } +} + +$PAGE->navbar->add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id))); +$PAGE->navbar->add(get_string('import'), new moodle_url($CFG->wwwroot.'/course/import.php', array('id'=>$course->id))); +$PAGE->navbar->add($strimportactivities); - $PAGE->navbar->add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id))); - $PAGE->navbar->add(get_string('import'), new moodle_url($CFG->wwwroot.'/course/import.php', array('id'=>$course->id))); - $PAGE->navbar->add($strimportactivities); +$PAGE->set_title("$course->shortname: $strimportactivities"); +$PAGE->set_heading($course->fullname); +echo $OUTPUT->header(); - $PAGE->set_title("$course->shortname: $strimportactivities"); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); +require_once('mod.php'); - require_once('mod.php'); +echo $OUTPUT->footer(); - echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/course/import/groups/index.php b/course/import/groups/index.php index c52b676648..60d47f1fc6 100755 --- a/course/import/groups/index.php +++ b/course/import/groups/index.php @@ -1,199 +1,222 @@ -dirroot.'/course/lib.php'); - require_once($CFG->dirroot.'/group/lib.php'); - - $id = required_param('id', PARAM_INT); // Course id - - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error('invalidcourseid'); - } +. + +/** + * Bulk group creation registration script from a comma separated file + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once('../../../config.php'); +require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->dirroot.'/group/lib.php'); + +$id = required_param('id', PARAM_INT); // Course id + +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/import/groups/index.php', array('id'=>$id))); + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error('invalidcourseid'); +} - require_login($course->id); - $context = get_context_instance(CONTEXT_COURSE, $id); +require_login($course->id); +$context = get_context_instance(CONTEXT_COURSE, $id); - if (!has_capability('moodle/course:managegroups', $context)) { - print_error('nopermissiontomanagegroup'); - } +if (!has_capability('moodle/course:managegroups', $context)) { + print_error('nopermissiontomanagegroup'); +} - //if (!confirm_sesskey()) { - // print_error('confirmsesskeybad', 'error'); - //} +//if (!confirm_sesskey()) { +// print_error('confirmsesskeybad', 'error'); +//} - $strimportgroups = get_string("importgroups"); + $strimportgroups = get_string("importgroups"); - $csv_encode = '/\&\#44/'; - if (isset($CFG->CSV_DELIMITER)) { - $csv_delimiter = '\\' . $CFG->CSV_DELIMITER; - $csv_delimiter2 = $CFG->CSV_DELIMITER; +$csv_encode = '/\&\#44/'; +if (isset($CFG->CSV_DELIMITER)) { + $csv_delimiter = '\\' . $CFG->CSV_DELIMITER; + $csv_delimiter2 = $CFG->CSV_DELIMITER; - if (isset($CFG->CSV_ENCODE)) { - $csv_encode = '/\&\#' . $CFG->CSV_ENCODE . '/'; - } - } else { - $csv_delimiter = "\,"; - $csv_delimiter2 = ","; + if (isset($CFG->CSV_ENCODE)) { + $csv_encode = '/\&\#' . $CFG->CSV_ENCODE . '/'; } +} else { + $csv_delimiter = "\,"; + $csv_delimiter2 = ","; +} /// Print the header - $PAGE->navbar->add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id))); - $PAGE->navbar->add(get_string('import'), new moodle_url($CFG->wwwroot.'/course/import.php', array('id'=>$course->id))); - $PAGE->navbar->add($strimportgroups); +$PAGE->navbar->add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id))); +$PAGE->navbar->add(get_string('import'), new moodle_url($CFG->wwwroot.'/course/import.php', array('id'=>$course->id))); +$PAGE->navbar->add($strimportgroups); - $PAGE->set_title("$course->shortname: $strimportgroups"); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); +$PAGE->set_title("$course->shortname: $strimportgroups"); +$PAGE->set_heading($course->fullname); +echo $OUTPUT->header(); /// If a file has been uploaded, then process it - require_once($CFG->dirroot.'/lib/uploadlib.php'); - $um = new upload_manager('userfile',false,false,null,false,0); - if ($um->preprocess_files()) { - $filename = $um->files['userfile']['tmp_name']; - - //Fix mac/dos newlines - $text = my_file_get_contents($filename); - $text = preg_replace('!\r\n?!',"\n",$text); - $fp = fopen($filename, "w"); - fwrite($fp,$text); - fclose($fp); - - $fp = fopen($filename, "r"); - - // make arrays of valid fields for error checking - $required = array("groupname" => 1, ); - $optionalDefaults = array("lang" => 1, ); - $optional = array("coursename" => 1, - "idnumber" =>1, - "description" => 1, - "enrolmentkey" => 1, - "theme" => 1, - "picture" => 1, - "hidepicture" => 1, ); - - // --- get header (field names) --- - $header = split($csv_delimiter, fgets($fp,1024)); - // check for valid field names - foreach ($header as $i => $h) { - $h = trim($h); $header[$i] = $h; // remove whitespace - if ( !(isset($required[$h]) or - isset($optionalDefaults[$h]) or - isset($optional[$h])) ) { - print_error('invalidfieldname', 'error', 'index.php?id='.$id.'&sesskey='.sesskey(), $h); - } - if ( isset($required[$h]) ) { - $required[$h] = 2; - } +require_once($CFG->dirroot.'/lib/uploadlib.php'); +$um = new upload_manager('userfile',false,false,null,false,0); +if ($um->preprocess_files()) { + $filename = $um->files['userfile']['tmp_name']; + + //Fix mac/dos newlines + $text = my_file_get_contents($filename); + $text = preg_replace('!\r\n?!',"\n",$text); + $fp = fopen($filename, "w"); + fwrite($fp,$text); + fclose($fp); + + $fp = fopen($filename, "r"); + + // make arrays of valid fields for error checking + $required = array("groupname" => 1, ); + $optionalDefaults = array("lang" => 1, ); + $optional = array("coursename" => 1, + "idnumber" =>1, + "description" => 1, + "enrolmentkey" => 1, + "theme" => 1, + "picture" => 1, + "hidepicture" => 1, ); + + // --- get header (field names) --- + $header = split($csv_delimiter, fgets($fp,1024)); + // check for valid field names + foreach ($header as $i => $h) { + $h = trim($h); $header[$i] = $h; // remove whitespace + if ( !(isset($required[$h]) or + isset($optionalDefaults[$h]) or + isset($optional[$h])) ) { + print_error('invalidfieldname', 'error', 'index.php?id='.$id.'&sesskey='.sesskey(), $h); } - // check for required fields - foreach ($required as $key => $value) { - if ($value < 2) { - print_error('fieldrequired', 'error', 'uploaduser.php?id='.$id.'&sesskey='.sesskey(), $key); - } + if ( isset($required[$h]) ) { + $required[$h] = 2; + } + } + // check for required fields + foreach ($required as $key => $value) { + if ($value < 2) { + print_error('fieldrequired', 'error', 'uploaduser.php?id='.$id.'&sesskey='.sesskey(), $key); } - $linenum = 2; // since header is line 1 + } + $linenum = 2; // since header is line 1 - while (!feof ($fp)) { + while (!feof ($fp)) { - $newgroup = new object();//to make Martin happy - foreach ($optionalDefaults as $key => $value) { - $newgroup->$key = current_language(); //defaults to current language - } - //Note: commas within a field should be encoded as , (for comma separated csv files) - //Note: semicolon within a field should be encoded as ; (for semicolon separated csv files) - $line = split($csv_delimiter, fgets($fp,1024)); - foreach ($line as $key => $value) { - //decode encoded commas - $record[$header[$key]] = preg_replace($csv_encode,$csv_delimiter2,trim($value)); - } - if ($record[$header[0]]) { - // add a new group to the database - - // add fields to object $user - foreach ($record as $name => $value) { - // check for required values - if (isset($required[$name]) and !$value) { - print_error('missingfield', 'error', 'uploaduser.php?sesskey='.sesskey(), $name); - } - else if ($name == "groupname") { - $newgroup->name = $value; - } - // normal entry - else { - $newgroup->{$name} = $value; - } + $newgroup = new object();//to make Martin happy + foreach ($optionalDefaults as $key => $value) { + $newgroup->$key = current_language(); //defaults to current language + } + //Note: commas within a field should be encoded as , (for comma separated csv files) + //Note: semicolon within a field should be encoded as ; (for semicolon separated csv files) + $line = split($csv_delimiter, fgets($fp,1024)); + foreach ($line as $key => $value) { + //decode encoded commas + $record[$header[$key]] = preg_replace($csv_encode,$csv_delimiter2,trim($value)); + } + if ($record[$header[0]]) { + // add a new group to the database + + // add fields to object $user + foreach ($record as $name => $value) { + // check for required values + if (isset($required[$name]) and !$value) { + print_error('missingfield', 'error', 'uploaduser.php?sesskey='.sesskey(), $name); } - ///Find the courseid of the course with the given shortname - - //if idnumber is set, we use that. - //unset invalid courseid - if (isset($newgroup->idnumber)){ - if (!$mycourse = $DB->get_record('course', array('idnumber'=>$newgroup->idnumber))) { - echo $OUTPUT->notification(get_string('unknowncourseidnumber', 'error', $newgroup->idnumber)); - unset($newgroup->courseid);//unset so 0 doesnt' get written to database - } - $newgroup->courseid = $mycourse->id; + else if ($name == "groupname") { + $newgroup->name = $value; } - //else use course short name to look up - //unset invalid coursename (if no id) - - else if (isset($newgroup->coursename)){ - if (!$mycourse = $DB->get_record('course', array('shortname', $newgroup->coursename))) { - echo $OUTPUT->notification(get_string('unknowncourse', 'error', $newgroup->coursename)); - unset($newgroup->courseid);//unset so 0 doesnt' get written to database - } - $newgroup->courseid = $mycourse->id; + // normal entry + else { + $newgroup->{$name} = $value; } - //else juse use current id - else{ - $newgroup->courseid = $id; + } + ///Find the courseid of the course with the given shortname + + //if idnumber is set, we use that. + //unset invalid courseid + if (isset($newgroup->idnumber)){ + if (!$mycourse = $DB->get_record('course', array('idnumber'=>$newgroup->idnumber))) { + echo $OUTPUT->notification(get_string('unknowncourseidnumber', 'error', $newgroup->idnumber)); + unset($newgroup->courseid);//unset so 0 doesnt' get written to database } + $newgroup->courseid = $mycourse->id; + } + //else use course short name to look up + //unset invalid coursename (if no id) - //if courseid is set - if (isset($newgroup->courseid)){ - - $newgroup->courseid = (int)$newgroup->courseid; - $newgroup->timecreated = time(); - $linenum++; - $groupname = $newgroup->name; - $newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid); - - ///Users cannot upload groups in courses they cannot update. - if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext)){ - echo $OUTPUT->notification(get_string('nopermissionforcreation','group',$groupname)); - - } else { - if ( $groupid = groups_get_group_by_name($newgroup->courseid, $groupname) || !($newgroup->id = groups_create_group($newgroup)) ) { - - //Record not added - probably because group is already registered - //In this case, output groupname from previous registration - if ($groupid) { - echo $OUTPUT->notification("$groupname :".get_string('groupexistforcourse', 'error', $groupname)); - } else { - echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname)); - } - } - else { - echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname)); + else if (isset($newgroup->coursename)){ + if (!$mycourse = $DB->get_record('course', array('shortname', $newgroup->coursename))) { + echo $OUTPUT->notification(get_string('unknowncourse', 'error', $newgroup->coursename)); + unset($newgroup->courseid);//unset so 0 doesnt' get written to database + } + $newgroup->courseid = $mycourse->id; + } + //else juse use current id + else{ + $newgroup->courseid = $id; + } + + //if courseid is set + if (isset($newgroup->courseid)){ + + $newgroup->courseid = (int)$newgroup->courseid; + $newgroup->timecreated = time(); + $linenum++; + $groupname = $newgroup->name; + $newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid); + + ///Users cannot upload groups in courses they cannot update. + if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext)){ + echo $OUTPUT->notification(get_string('nopermissionforcreation','group',$groupname)); + + } else { + if ( $groupid = groups_get_group_by_name($newgroup->courseid, $groupname) || !($newgroup->id = groups_create_group($newgroup)) ) { + + //Record not added - probably because group is already registered + //In this case, output groupname from previous registration + if ($groupid) { + echo $OUTPUT->notification("$groupname :".get_string('groupexistforcourse', 'error', $groupname)); + } else { + echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname)); } } - } //close courseid validity check - unset ($newgroup); - }//close if ($record[$header[0]]) - }//close while($fp) - fclose($fp); + else { + echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname)); + } + } + } //close courseid validity check + unset ($newgroup); + }//close if ($record[$header[0]]) + }//close while($fp) + fclose($fp); - echo '
'; - } + echo '
'; +} /// Print the form - require('mod.php'); +require('mod.php'); - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); function my_file_get_contents($filename, $use_include_path = 0) { /// Returns the file as one big long string @@ -209,4 +232,4 @@ function my_file_get_contents($filename, $use_include_path = 0) { return $data; } -?> +?> \ No newline at end of file diff --git a/course/import/groups/mod.php b/course/import/groups/mod.php index df47c707d8..4a73e819d2 100644 --- a/course/import/groups/mod.php +++ b/course/import/groups/mod.php @@ -1,28 +1,56 @@ -'; - echo $OUTPUT->box_start(); - - // use formslib - include_once('import_form.php'); - $mform_post = new course_import_groups_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize)); - $mform_post ->display(); - - echo $OUTPUT->box_end(); - - echo '

'; - -?> +. + +/** + * This file is part of the User section Moodle + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page +} + +$streditmyprofile = get_string("editmyprofile"); +$stradministration = get_string("administration"); +$strchoose = get_string("choose"); +$struser = get_string("user"); +$strusers = get_string("users"); +$strusersnew = get_string("usersnew"); +$strimportgroups = get_string("importgroups"); + +$helpicon = new moodle_help_icon(); +$helpicon->text = $strimportgroups; +$helpicon->page = 'uploadgroups'; +echo $OUTPUT->heading_with_help($helpicon); + +$maxuploadsize = get_max_upload_file_size(); +echo '

'; +echo $OUTPUT->box_start(); + +// use formslib +include_once('import_form.php'); +$mform_post = new course_import_groups_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize)); +$mform_post ->display(); + +echo $OUTPUT->box_end(); + +echo '

'; + +?> \ No newline at end of file diff --git a/course/importstudents.php b/course/importstudents.php index 473050e7fb..1d54c0e30e 100644 --- a/course/importstudents.php +++ b/course/importstudents.php @@ -1,6 +1,28 @@ -. + +/** + * Script to assign students to a meta course by selecting which courses the meta + * course comprises. This is basically a hack of student.php that uses courses instead. + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require_once("../config.php"); require_once("lib.php"); @@ -15,6 +37,24 @@ $previoussearch = optional_param('previoussearch', 0, PARAM_BOOL); $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0; + $url = new moodle_url($CFG->wwwroot.'/course/importstudents.php', array('id'=>$id)); + if ($add !== 0) { + $url->param('add', $add); + } + if ($remove !== 0) { + $url->param('remove', $remove); + } + if ($showall !== 0) { + $url->param('showall', $showall); + } + if ($searchtext !== '') { + $url->param('searchtext', $searchtext); + } + if ($previoussearch !== 0) { + $url->param('previoussearch', $previoussearch); + } + $PAGE->set_url($url); + if (! $site = get_site()) { redirect("$CFG->wwwroot/$CFG->admin/index.php"); } diff --git a/course/index.php b/course/index.php index 4de3d612b9..624efb02aa 100644 --- a/course/index.php +++ b/course/index.php @@ -1,270 +1,292 @@ -. + +/** + * For most people, just lists the course categories + * Allows the admin to create, delete and rename course categories + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../config.php"); +require_once("lib.php"); + +$categoryedit = optional_param('categoryedit', -1,PARAM_BOOL); +$delete = optional_param('delete',0,PARAM_INT); +$hide = optional_param('hide',0,PARAM_INT); +$show = optional_param('show',0,PARAM_INT); +$move = optional_param('move',0,PARAM_INT); +$moveto = optional_param('moveto',-1,PARAM_INT); +$moveup = optional_param('moveup',0,PARAM_INT); +$movedown = optional_param('movedown',0,PARAM_INT); + +if (!$site = get_site()) { + print_error('siteisnotdefined', 'debug'); +} - $systemcontext = get_context_instance(CONTEXT_SYSTEM); +$systemcontext = get_context_instance(CONTEXT_SYSTEM); - $PAGE->set_url('course/index.php'); - $PAGE->set_context($systemcontext); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/index.php')); +$PAGE->set_context($systemcontext); - if (can_edit_in_category()) { - if ($categoryedit !== -1) { - $USER->editing = $categoryedit; - } +if (can_edit_in_category()) { + if ($categoryedit !== -1) { + $USER->editing = $categoryedit; + } + require_login(); + $adminediting = $PAGE->user_is_editing(); +} else { + if ($CFG->forcelogin) { require_login(); - $adminediting = $PAGE->user_is_editing(); - } else { - if ($CFG->forcelogin) { - require_login(); - } - $adminediting = false; } + $adminediting = false; +} - $stradministration = get_string('administration'); - $strcategories = get_string('categories'); - $strcategory = get_string('category'); - $strcourses = get_string('courses'); - $stredit = get_string('edit'); - $strdelete = get_string('delete'); - $straction = get_string('action'); +$stradministration = get_string('administration'); +$strcategories = get_string('categories'); +$strcategory = get_string('category'); +$strcourses = get_string('courses'); +$stredit = get_string('edit'); +$strdelete = get_string('delete'); +$straction = get_string('action'); /// Unless it's an editing admin, just print the regular listing of courses/categories - if (!$adminediting) { - - /// Print form for creating new categories - $countcategories = $DB->count_records('course_categories'); - - if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) { - $strcourses = get_string('courses'); - $strcategories = get_string('categories'); - - $PAGE->navbar->add($strcategories); - $PAGE->set_title("$site->shortname: $strcategories"); - $PAGE->set_heading($strcourses); - $PAGE->set_button(update_category_button()); - echo $OUTPUT->header(); - echo $OUTPUT->heading($strcategories); - echo skip_main_destination(); - echo $OUTPUT->box_start('categorybox'); - print_whole_category_list(); - echo $OUTPUT->box_end(); - print_course_search(); - } else { - $PAGE->navbar->add($strfulllistofcourses); - $PAGE->set_title("$site->shortname: $strfulllistofcourses"); - $PAGE->set_heading($strfulllistofcourses); - $PAGE->set_button(update_category_button()); - echo $OUTPUT->header(); - echo skip_main_destination(); - echo $OUTPUT->box_start('courseboxes'); - print_courses(0); - echo $OUTPUT->box_end(); - } +if (!$adminediting) { + +/// Print form for creating new categories + $countcategories = $DB->count_records('course_categories'); + + if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) { + $strcourses = get_string('courses'); + $strcategories = get_string('categories'); + + $PAGE->navbar->add($strcategories); + $PAGE->set_title("$site->shortname: $strcategories"); + $PAGE->set_heading($strcourses); + $PAGE->set_button(update_category_button()); + echo $OUTPUT->header(); + echo $OUTPUT->heading($strcategories); + echo $OUTPUT->skip_link_target(); + echo $OUTPUT->box_start('categorybox'); + print_whole_category_list(); + echo $OUTPUT->box_end(); + print_course_search(); + } else { + $PAGE->navbar->add($strfulllistofcourses); + $PAGE->set_title("$site->shortname: $strfulllistofcourses"); + $PAGE->set_heading($strfulllistofcourses); + $PAGE->set_button(update_category_button()); + echo $OUTPUT->header(); + echo $OUTPUT->skip_link_target(); + echo $OUTPUT->box_start('courseboxes'); + print_courses(0); + echo $OUTPUT->box_end(); + } - echo $OUTPUT->container_start('buttons'); - if (has_capability('moodle/course:create', $systemcontext)) { - /// Print link to create a new course - /// Get the 1st available category - $options = array('category' => $CFG->defaultrequestcategory); - $form = html_form::make_button('edit.php', $options, get_string('addnewcourse')); - $form->method = 'get'; - echo $OUTPUT->button($form); - } - print_course_request_buttons($systemcontext); - echo $OUTPUT->container_end(); - echo $OUTPUT->footer(); - exit; + echo $OUTPUT->container_start('buttons'); + if (has_capability('moodle/course:create', $systemcontext)) { + /// Print link to create a new course + /// Get the 1st available category + $options = array('category' => $CFG->defaultrequestcategory); + $form = html_form::make_button('edit.php', $options, get_string('addnewcourse')); + $form->method = 'get'; + echo $OUTPUT->button($form); } + print_course_request_buttons($systemcontext); + echo $OUTPUT->container_end(); + echo $OUTPUT->footer(); + exit; +} /// Everything else is editing on mode. - require_once($CFG->libdir.'/adminlib.php'); - admin_externalpage_setup('coursemgmt'); +require_once($CFG->libdir.'/adminlib.php'); +admin_externalpage_setup('coursemgmt'); /// Delete a category. - if (!empty($delete) and confirm_sesskey()) { - if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) { - print_error('invalidcategoryid'); - } - $context = get_context_instance(CONTEXT_COURSECAT, $delete); - require_capability('moodle/category:manage', $context); - require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent)); - - $heading = get_string('deletecategory', format_string($deletecat->name)); - require_once('delete_category_form.php'); - $mform = new delete_category_form(null, $deletecat); - $mform->set_data(array('delete'=>$delete)); - - if ($mform->is_cancelled()) { - redirect('index.php'); - - } else if (!$data= $mform->get_data()) { - require_once($CFG->libdir . '/questionlib.php'); - admin_externalpage_print_header(); - echo $OUTPUT->heading($heading); - $mform->display(); - echo $OUTPUT->footer(); - exit(); - } +if (!empty($delete) and confirm_sesskey()) { + if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) { + print_error('invalidcategoryid'); + } + $context = get_context_instance(CONTEXT_COURSECAT, $delete); + require_capability('moodle/category:manage', $context); + require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent)); + + $heading = get_string('deletecategory', format_string($deletecat->name)); + require_once('delete_category_form.php'); + $mform = new delete_category_form(null, $deletecat); + $mform->set_data(array('delete'=>$delete)); + + if ($mform->is_cancelled()) { + redirect('index.php'); + } else if (!$data= $mform->get_data()) { + require_once($CFG->libdir . '/questionlib.php'); admin_externalpage_print_header(); echo $OUTPUT->heading($heading); + $mform->display(); + echo $OUTPUT->footer(); + exit(); + } - if ($data->fulldelete) { - $deletedcourses = category_delete_full($deletecat, true); + admin_externalpage_print_header(); + echo $OUTPUT->heading($heading); - foreach($deletedcourses as $course) { - echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess'); - } - echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name)), 'notifysuccess'); + if ($data->fulldelete) { + $deletedcourses = category_delete_full($deletecat, true); - } else { - category_delete_move($deletecat, $data->newparent, true); + foreach($deletedcourses as $course) { + echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess'); } + echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name)), 'notifysuccess'); - // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. - if ($delete == $CFG->defaultrequestcategory) { - set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent'=>0))); - } - - echo $OUTPUT->continue_button('index.php'); + } else { + category_delete_move($deletecat, $data->newparent, true); + } - echo $OUTPUT->footer(); - die; + // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. + if ($delete == $CFG->defaultrequestcategory) { + set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent'=>0))); } + echo $OUTPUT->continue_button('index.php'); + + echo $OUTPUT->footer(); + die; +} + /// Create a default category if necessary - if (!$categories = get_categories()) { /// No category yet! - // Try and make one - $tempcat = new object(); - $tempcat->name = get_string('miscellaneous'); - $tempcat->id = $DB->insert_record('course_categories', $tempcat); - $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id); - mark_context_dirty('/'.SYSCONTEXTID); - fix_course_sortorder(); // Required to build course_categories.depth and .path. - } +if (!$categories = get_categories()) { /// No category yet! + // Try and make one + $tempcat = new object(); + $tempcat->name = get_string('miscellaneous'); + $tempcat->id = $DB->insert_record('course_categories', $tempcat); + $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id); + mark_context_dirty('/'.SYSCONTEXTID); + fix_course_sortorder(); // Required to build course_categories.depth and .path. +} /// Move a category to a new parent if required - if (!empty($move) and ($moveto >= 0) and confirm_sesskey()) { - if ($cattomove = $DB->get_record('course_categories', array('id'=>$move))) { - require_capability('moodle/category:manage', get_category_or_system_context($cattomove->parent)); - if ($cattomove->parent != $moveto) { - $newparent = $DB->get_record('course_categories', array('id'=>$moveto)); - require_capability('moodle/category:manage', get_category_or_system_context($moveto)); - move_category($cattomove, $newparent); - } +if (!empty($move) and ($moveto >= 0) and confirm_sesskey()) { + if ($cattomove = $DB->get_record('course_categories', array('id'=>$move))) { + require_capability('moodle/category:manage', get_category_or_system_context($cattomove->parent)); + if ($cattomove->parent != $moveto) { + $newparent = $DB->get_record('course_categories', array('id'=>$moveto)); + require_capability('moodle/category:manage', get_category_or_system_context($moveto)); + move_category($cattomove, $newparent); } } +} /// Hide or show a category - if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { - if (!empty($hide)) { - $tempcat = $DB->get_record('course_categories', array('id'=>$hide)); - $visible = 0; - } else { - $tempcat = $DB->get_record('course_categories', array('id'=>$show)); - $visible = 1; - } - require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent)); - if ($tempcat) { - $DB->set_field('course_categories', 'visible', $visible, array('id'=>$tempcat->id)); - $DB->set_field('course', 'visible', $visible, array('category' => $tempcat->id)); - } +if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { + if (!empty($hide)) { + $tempcat = $DB->get_record('course_categories', array('id'=>$hide)); + $visible = 0; + } else { + $tempcat = $DB->get_record('course_categories', array('id'=>$show)); + $visible = 1; + } + require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent)); + if ($tempcat) { + $DB->set_field('course_categories', 'visible', $visible, array('id'=>$tempcat->id)); + $DB->set_field('course', 'visible', $visible, array('category' => $tempcat->id)); } +} /// Move a category up or down - if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { - fix_course_sortorder(); - $swapcategory = NULL; - - if (!empty($moveup)) { - require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveup)); - if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) { - if ($swapcategory = $DB->get_records_select('course_categories', "sortordersortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { - $swapcategory = reset($swapcategory); - } - } - } else { - require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $movedown)); - if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) { - if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { - $swapcategory = reset($swapcategory); - } +if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { + fix_course_sortorder(); + $swapcategory = NULL; + + if (!empty($moveup)) { + require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveup)); + if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) { + if ($swapcategory = $DB->get_records_select('course_categories', "sortordersortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { + $swapcategory = reset($swapcategory); } } - if ($swapcategory and $movecategory) { - $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id)); - $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id)); + } else { + require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $movedown)); + if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) { + if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { + $swapcategory = reset($swapcategory); + } } - - // finally reorder courses - fix_course_sortorder(); + } + if ($swapcategory and $movecategory) { + $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id)); + $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id)); } + // finally reorder courses + fix_course_sortorder(); +} + /// Print headings - admin_externalpage_print_header(); - echo $OUTPUT->heading($strcategories); +admin_externalpage_print_header(); +echo $OUTPUT->heading($strcategories); /// Print out the categories with all the knobs - $strcategories = get_string('categories'); - $strcourses = get_string('courses'); - $strmovecategoryto = get_string('movecategoryto'); - $stredit = get_string('edit'); - - $displaylist = array(); - $parentlist = array(); - - $displaylist[0] = get_string('top'); - make_categories_list($displaylist, $parentlist); - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - print_category_edit(NULL, $displaylist, $parentlist); - echo '
'.$strcategories.''.$strcourses.''.$stredit.''.$strmovecategoryto.'
'; - - echo '
'; - if (has_capability('moodle/course:create', $systemcontext)) { - // print create course link to first category - $options = array(); - $options = array('category' => $CFG->defaultrequestcategory); - $form = html_form::make_button('edit.php', $options, get_string('addnewcourse')); - $form->method = 'get'; - echo $OUTPUT->button($form); - } +$strcategories = get_string('categories'); +$strcourses = get_string('courses'); +$strmovecategoryto = get_string('movecategoryto'); +$stredit = get_string('edit'); + +$displaylist = array(); +$parentlist = array(); + +$displaylist[0] = get_string('top'); +make_categories_list($displaylist, $parentlist); + +echo ''; +echo ''; +echo ''; +echo ''; +echo ''; +echo ''; + +print_category_edit(NULL, $displaylist, $parentlist); +echo '
'.$strcategories.''.$strcourses.''.$stredit.''.$strmovecategoryto.'
'; + +echo '
'; +if (has_capability('moodle/course:create', $systemcontext)) { + // print create course link to first category + $options = array(); + $options = array('category' => $CFG->defaultrequestcategory); + $form = html_form::make_button('edit.php', $options, get_string('addnewcourse')); + $form->method = 'get'; + echo $OUTPUT->button($form); +} - // Print button for creating new categories - if (has_capability('moodle/category:manage', $systemcontext)) { - $options = array(); - $options['parent'] = 0; - $form = html_form::make_button('editcategory.php', $options, get_string('addnewcategory')); - $form->method = 'get'; - echo $OUTPUT->button($form); - } +// Print button for creating new categories +if (has_capability('moodle/category:manage', $systemcontext)) { + $options = array(); + $options['parent'] = 0; + $form = html_form::make_button('editcategory.php', $options, get_string('addnewcategory')); + $form->method = 'get'; + echo $OUTPUT->button($form); +} - print_course_request_buttons($systemcontext); - echo '
'; +print_course_request_buttons($systemcontext); +echo '
'; - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) { /// Recursive function to print all the categories ready for editing @@ -372,5 +394,4 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $ print_category_edit($cat, $displaylist, $parentslist, $depth+1, $up, $down); } } -} - +} \ No newline at end of file diff --git a/course/jumpto.php b/course/jumpto.php index cf1f91e1d3..040f1f7d1a 100644 --- a/course/jumpto.php +++ b/course/jumpto.php @@ -1,27 +1,47 @@ -. + +/** + * Jumps to a given relative or Moodle absolute URL. + * Mostly used for accessibility. * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course */ - require('../config.php'); +require('../config.php'); + +$jump = optional_param('jump', '', PARAM_RAW); - $jump = optional_param('jump', '', PARAM_RAW); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/jumpto.php')); - if (!confirm_sesskey()) { - print_error('confirmsesskeybad'); - } +if (!confirm_sesskey()) { + print_error('confirmsesskeybad'); +} - if (strpos($jump, $CFG->wwwroot) === 0) { // Anything on this site - redirect(new moodle_url(urldecode($jump))); - } else if (preg_match('/^[a-z]+\.php\?/', $jump)) { - redirect(new moodle_url(urldecode($jump))); - } +if (strpos($jump, $CFG->wwwroot) === 0) { // Anything on this site + redirect(new moodle_url(urldecode($jump))); +} else if (preg_match('/^[a-z]+\.php\?/', $jump)) { + redirect(new moodle_url(urldecode($jump))); +} - if(isset($_SERVER['HTTP_REFERER'])) { - redirect(new moodle_url($_SERVER['HTTP_REFERER'])); // Return to sender, just in case - } +if(isset($_SERVER['HTTP_REFERER'])) { + redirect(new moodle_url($_SERVER['HTTP_REFERER'])); // Return to sender, just in case +} -?> +?> \ No newline at end of file diff --git a/course/lib.php b/course/lib.php index a30ea6e230..c3d8a0f425 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1,5 +1,27 @@ -. + +/** + * Library of useful functions + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require_once($CFG->libdir.'/completionlib.php'); diff --git a/course/mod.php b/course/mod.php index a47e704e5c..7f8b1068f4 100644 --- a/course/mod.php +++ b/course/mod.php @@ -1,284 +1,309 @@ -wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod"); - - } else if (!empty($update)) { - if (!$cm = get_coursemodule_from_id('', $update, 0, true)) { - print_error('invalidcoursemodule'); - } - $returntomod = optional_param('return', 0, PARAM_BOOL); - redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod"); +. + +/** + * Moves, adds, updates, duplicates or deletes modules in a course + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require("../config.php"); +require_once("lib.php"); + +require_login(); + +$sectionreturn = optional_param('sr', '', PARAM_INT); +$add = optional_param('add', '', PARAM_ALPHA); +$type = optional_param('type', '', PARAM_ALPHA); +$indent = optional_param('indent', 0, PARAM_INT); +$update = optional_param('update', 0, PARAM_INT); +$hide = optional_param('hide', 0, PARAM_INT); +$show = optional_param('show', 0, PARAM_INT); +$copy = optional_param('copy', 0, PARAM_INT); +$moveto = optional_param('moveto', 0, PARAM_INT); +$movetosection = optional_param('movetosection', 0, PARAM_INT); +$delete = optional_param('delete', 0, PARAM_INT); +$course = optional_param('course', 0, PARAM_INT); +$groupmode = optional_param('groupmode', -1, PARAM_INT); +$cancelcopy = optional_param('cancelcopy', 0, PARAM_BOOL); +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +// This page should always redirect +$PAGE->set_url($FULLME); + +//check if we are adding / editing a module that has new forms using formslib +if (!empty($add)) { + $id = required_param('id', PARAM_INT); + $section = required_param('section', PARAM_INT); + $type = optional_param('type', '', PARAM_ALPHA); + $returntomod = optional_param('return', 0, PARAM_BOOL); + + redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod"); + +} else if (!empty($update)) { + if (!$cm = get_coursemodule_from_id('', $update, 0, true)) { + print_error('invalidcoursemodule'); + } + $returntomod = optional_param('return', 0, PARAM_BOOL); + redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod"); - } else if (!empty($delete)) { - if (!$cm = get_coursemodule_from_id('', $delete, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if (!empty($delete)) { + if (!$cm = get_coursemodule_from_id('', $delete, 0, true)) { + print_error('invalidcoursemodule'); + } - if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { - print_error('invalidcourseid'); - } - require_login($course->id); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_COURSE, $course->id); - $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('moodle/course:manageactivities', $context); + if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { + print_error('invalidcourseid'); + } + require_login($course->id); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $course->id); + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:manageactivities', $context); - $return = "$CFG->wwwroot/course/view.php?id=$cm->course#section-$cm->sectionnum"; + $return = "$CFG->wwwroot/course/view.php?id=$cm->course#section-$cm->sectionnum"; - if (!$confirm or !confirm_sesskey()) { - $fullmodulename = get_string('modulename', $cm->modname); + if (!$confirm or !confirm_sesskey()) { + $fullmodulename = get_string('modulename', $cm->modname); - $optionsyes = array('confirm'=>1, 'delete'=>$cm->id, 'sesskey'=>sesskey()); - $optionsno = array('id'=>$cm->course); + $optionsyes = array('confirm'=>1, 'delete'=>$cm->id, 'sesskey'=>sesskey()); + $optionsno = array('id'=>$cm->course); - $strdeletecheck = get_string('deletecheck', '', $fullmodulename); - $strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'"); + $strdeletecheck = get_string('deletecheck', '', $fullmodulename); + $strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'"); - $PAGE->set_pagetype('mod-' . $cm->modname . '-delete'); - $PAGE->set_title($strdeletecheck); - $PAGE->navbar->add($strdeletecheck); - echo $OUTPUT->header(); + $PAGE->set_pagetype('mod-' . $cm->modname . '-delete'); + $PAGE->set_title($strdeletecheck); + $PAGE->navbar->add($strdeletecheck); + echo $OUTPUT->header(); - // print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox'); - echo $OUTPUT->box_start('noticebox'); - $formcontinue = html_form::make_button('mod.php', $optionsyes, get_string('yes')); - $formcancel = html_form::make_button($return, $optionsno, get_string('no'), 'get'); - echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel); - echo $OUTPUT->box_end(); - echo $OUTPUT->footer(); + // print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox'); + echo $OUTPUT->box_start('noticebox'); + $formcontinue = html_form::make_button('mod.php', $optionsyes, get_string('yes')); + $formcancel = html_form::make_button($return, $optionsno, get_string('no'), 'get'); + echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel); + echo $OUTPUT->box_end(); + echo $OUTPUT->footer(); - exit; - } + exit; + } - $modlib = "$CFG->dirroot/mod/$cm->modname/lib.php"; + $modlib = "$CFG->dirroot/mod/$cm->modname/lib.php"; - if (file_exists($modlib)) { - require_once($modlib); - } else { - print_error('modulemissingcode', '', '', $modlib); - } + if (file_exists($modlib)) { + require_once($modlib); + } else { + print_error('modulemissingcode', '', '', $modlib); + } - $deleteinstancefunction = $cm->modname."_delete_instance"; + $deleteinstancefunction = $cm->modname."_delete_instance"; - if (!$deleteinstancefunction($cm->instance)) { - echo $OUTPUT->notification("Could not delete the $cm->modname (instance)"); - } + if (!$deleteinstancefunction($cm->instance)) { + echo $OUTPUT->notification("Could not delete the $cm->modname (instance)"); + } - // remove all module files in case modules forget to do that - $fs = get_file_storage(); - $fs->delete_area_files($modcontext->id); + // remove all module files in case modules forget to do that + $fs = get_file_storage(); + $fs->delete_area_files($modcontext->id); - if (!delete_course_module($cm->id)) { - echo $OUTPUT->notification("Could not delete the $cm->modname (coursemodule)"); - } - if (!delete_mod_from_section($cm->id, $cm->section)) { - echo $OUTPUT->notification("Could not delete the $cm->modname from that section"); - } + if (!delete_course_module($cm->id)) { + echo $OUTPUT->notification("Could not delete the $cm->modname (coursemodule)"); + } + if (!delete_mod_from_section($cm->id, $cm->section)) { + echo $OUTPUT->notification("Could not delete the $cm->modname from that section"); + } + + add_to_log($course->id, 'course', "delete mod", + "view.php?id=$cm->course", + "$cm->modname $cm->instance", $cm->id); - add_to_log($course->id, 'course', "delete mod", - "view.php?id=$cm->course", - "$cm->modname $cm->instance", $cm->id); + rebuild_course_cache($course->id); - rebuild_course_cache($course->id); + redirect($return); +} - redirect($return); + +if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { + if (!$cm = get_coursemodule_from_id('', $USER->activitycopy, 0, true)) { + print_error('invalidcoursemodule'); } + if (!empty($movetosection)) { + if (!$section = $DB->get_record('course_sections', array('id'=>$movetosection, 'course'=>$cm->course))) { + print_error('sectionnotexist'); + } + $beforecm = NULL; - if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { - if (!$cm = get_coursemodule_from_id('', $USER->activitycopy, 0, true)) { + } else { // normal moveto + if (!$beforecm = get_coursemodule_from_id('', $moveto, $cm->course, true)) { print_error('invalidcoursemodule'); } - - if (!empty($movetosection)) { - if (!$section = $DB->get_record('course_sections', array('id'=>$movetosection, 'course'=>$cm->course))) { - print_error('sectionnotexist'); - } - $beforecm = NULL; - - } else { // normal moveto - if (!$beforecm = get_coursemodule_from_id('', $moveto, $cm->course, true)) { - print_error('invalidcoursemodule'); - } - if (!$section = $DB->get_record('course_sections', array('id'=>$beforecm->section, 'course'=>$cm->course))) { - print_error('sectionnotexist'); - } + if (!$section = $DB->get_record('course_sections', array('id'=>$beforecm->section, 'course'=>$cm->course))) { + print_error('sectionnotexist'); } + } - require_login($section->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_COURSE, $section->course); - require_capability('moodle/course:manageactivities', $context); + require_login($section->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $section->course); + require_capability('moodle/course:manageactivities', $context); - if (!ismoving($section->course)) { - print_error('needcopy', '', "view.php?id=$section->course"); - } + if (!ismoving($section->course)) { + print_error('needcopy', '', "view.php?id=$section->course"); + } - moveto_module($cm, $section, $beforecm); + moveto_module($cm, $section, $beforecm); - unset($USER->activitycopy); - unset($USER->activitycopycourse); - unset($USER->activitycopyname); + unset($USER->activitycopy); + unset($USER->activitycopycourse); + unset($USER->activitycopyname); - rebuild_course_cache($section->course); + rebuild_course_cache($section->course); - if (SITEID == $section->course) { - redirect($CFG->wwwroot); - } else { - redirect("view.php?id=$section->course#section-$sectionreturn"); - } + if (SITEID == $section->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$section->course#section-$sectionreturn"); + } - } else if (!empty($indent) and confirm_sesskey()) { - $id = required_param('id', PARAM_INT); - if (!$cm = get_coursemodule_from_id('', $id, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if (!empty($indent) and confirm_sesskey()) { + $id = required_param('id', PARAM_INT); + if (!$cm = get_coursemodule_from_id('', $id, 0, true)) { + print_error('invalidcoursemodule'); + } - require_login($cm->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_COURSE, $cm->course); - require_capability('moodle/course:manageactivities', $context); + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $cm->course); + require_capability('moodle/course:manageactivities', $context); - $cm->indent += $indent; + $cm->indent += $indent; - if ($cm->indent < 0) { - $cm->indent = 0; - } + if ($cm->indent < 0) { + $cm->indent = 0; + } - $DB->set_field('course_modules', 'indent', $cm->indent, array('id'=>$cm->id)); + $DB->set_field('course_modules', 'indent', $cm->indent, array('id'=>$cm->id)); - rebuild_course_cache($cm->course); + rebuild_course_cache($cm->course); - if (SITEID == $cm->course) { - redirect($CFG->wwwroot); - } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); - } + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + } - } else if (!empty($hide) and confirm_sesskey()) { - if (!$cm = get_coursemodule_from_id('', $hide, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if (!empty($hide) and confirm_sesskey()) { + if (!$cm = get_coursemodule_from_id('', $hide, 0, true)) { + print_error('invalidcoursemodule'); + } - require_login($cm->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('moodle/course:activityvisibility', $context); + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:activityvisibility', $context); - set_coursemodule_visible($cm->id, 0); + set_coursemodule_visible($cm->id, 0); - rebuild_course_cache($cm->course); + rebuild_course_cache($cm->course); - if (SITEID == $cm->course) { - redirect($CFG->wwwroot); - } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); - } + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + } - } else if (!empty($show) and confirm_sesskey()) { - if (!$cm = get_coursemodule_from_id('', $show, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if (!empty($show) and confirm_sesskey()) { + if (!$cm = get_coursemodule_from_id('', $show, 0, true)) { + print_error('invalidcoursemodule'); + } - require_login($cm->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_COURSE, $cm->course); - require_capability('moodle/course:activityvisibility', $context); + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $cm->course); + require_capability('moodle/course:activityvisibility', $context); - if (!$section = $DB->get_record('course_sections', array('id'=>$cm->section))) { - print_error('sectionnotexist'); - } + if (!$section = $DB->get_record('course_sections', array('id'=>$cm->section))) { + print_error('sectionnotexist'); + } - if (!$module = $DB->get_record('modules', array('id'=>$cm->module))) { - print_error('moduledoesnotexist'); - } + if (!$module = $DB->get_record('modules', array('id'=>$cm->module))) { + print_error('moduledoesnotexist'); + } - if ($module->visible and ($section->visible or (SITEID == $cm->course))) { - set_coursemodule_visible($cm->id, 1); - rebuild_course_cache($cm->course); - } + if ($module->visible and ($section->visible or (SITEID == $cm->course))) { + set_coursemodule_visible($cm->id, 1); + rebuild_course_cache($cm->course); + } - if (SITEID == $cm->course) { - redirect($CFG->wwwroot); - } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); - } + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + } - } else if ($groupmode > -1 and confirm_sesskey()) { - $id = required_param('id', PARAM_INT); - if (!$cm = get_coursemodule_from_id('', $id, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if ($groupmode > -1 and confirm_sesskey()) { + $id = required_param('id', PARAM_INT); + if (!$cm = get_coursemodule_from_id('', $id, 0, true)) { + print_error('invalidcoursemodule'); + } - require_login($cm->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('moodle/course:manageactivities', $context); + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:manageactivities', $context); - set_coursemodule_groupmode($cm->id, $groupmode); + set_coursemodule_groupmode($cm->id, $groupmode); - rebuild_course_cache($cm->course); + rebuild_course_cache($cm->course); - if (SITEID == $cm->course) { - redirect($CFG->wwwroot); - } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); - } + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + } - } else if (!empty($copy) and confirm_sesskey()) { // value = course module - if (!$cm = get_coursemodule_from_id('', $copy, 0, true)) { - print_error('invalidcoursemodule'); - } +} else if (!empty($copy) and confirm_sesskey()) { // value = course module + if (!$cm = get_coursemodule_from_id('', $copy, 0, true)) { + print_error('invalidcoursemodule'); + } - require_login($cm->course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_COURSE, $cm->course); - require_capability('moodle/course:manageactivities', $context); + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_COURSE, $cm->course); + require_capability('moodle/course:manageactivities', $context); - if (!$section = $DB->get_record('course_sections', array('id'=>$cm->section))) { - print_error('sectionnotexist'); - } + if (!$section = $DB->get_record('course_sections', array('id'=>$cm->section))) { + print_error('sectionnotexist'); + } - $USER->activitycopy = $copy; - $USER->activitycopycourse = $cm->course; - $USER->activitycopyname = $cm->name; + $USER->activitycopy = $copy; + $USER->activitycopycourse = $cm->course; + $USER->activitycopyname = $cm->name; - redirect("view.php?id=$cm->course#section-$sectionreturn"); + redirect("view.php?id=$cm->course#section-$sectionreturn"); - } else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module +} else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module - $courseid = $USER->activitycopycourse; + $courseid = $USER->activitycopycourse; - unset($USER->activitycopy); - unset($USER->activitycopycourse); - unset($USER->activitycopyname); + unset($USER->activitycopy); + unset($USER->activitycopycourse); + unset($USER->activitycopyname); - redirect("view.php?id=$courseid"); + redirect("view.php?id=$courseid"); - } else { - print_error('unknowaction'); - } -?> +} else { + print_error('unknowaction'); +} + +?> \ No newline at end of file diff --git a/course/recent.php b/course/recent.php index 4311208821..2c0ab507b2 100644 --- a/course/recent.php +++ b/course/recent.php @@ -1,265 +1,288 @@ -. + +/** + * Display all recent activity in a flexible way + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once('../config.php'); +require_once('lib.php'); +require_once('recent_form.php'); + +$id = required_param('id', PARAM_INT); + +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/recent.php', array('id'=>$id))); + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error("That's an invalid course id"); +} -// Display all recent activity in a flexible way +require_login($course); - require_once('../config.php'); - require_once('lib.php'); - require_once('recent_form.php'); +add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id); - $id = required_param('id', PARAM_INT); +$context = get_context_instance(CONTEXT_COURSE, $course->id); - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error("That's an invalid course id"); +$lastlogin = time() - COURSE_MAX_RECENT_PERIOD; +if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) { + if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) { + $lastlogin = $USER->lastcourseaccess[$COURSE->id]; } +} - require_login($course); - - add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id); +$param = new object(); +$param->user = 0; +$param->modid = 'all'; +$param->group = 0; +$param->sortby = 'default'; +$param->date = $lastlogin; +$param->id = $COURSE->id; + +$mform = new recent_form(); +$mform->set_data($param); +if ($formdata = $mform->get_data()) { + $param = $formdata; +} - $context = get_context_instance(CONTEXT_COURSE, $course->id); +$userinfo = get_string('allparticipants'); +$dateinfo = get_string('alldays'); - $lastlogin = time() - COURSE_MAX_RECENT_PERIOD; - if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) { - if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) { - $lastlogin = $USER->lastcourseaccess[$COURSE->id]; - } - } - - $param = new object(); - $param->user = 0; - $param->modid = 'all'; - $param->group = 0; - $param->sortby = 'default'; - $param->date = $lastlogin; - $param->id = $COURSE->id; - - $mform = new recent_form(); - $mform->set_data($param); - if ($formdata = $mform->get_data()) { - $param = $formdata; +if (!empty($param->user)) { + if (!$u = $DB->get_record('user', array('id'=>$param->user))) { + print_error("That's an invalid user!"); } + $userinfo = fullname($u); +} - $userinfo = get_string('allparticipants'); - $dateinfo = get_string('alldays'); +$strrecentactivity = get_string('recentactivity'); +$PAGE->navbar->add($strrecentactivity, new moodle_url($CFG->wwwroot.'/course/recent.php', array('id'=>$course->id))); +$PAGE->navbar->add($userinfo); +$PAGE->set_title("$course->shortname: $strrecentactivity"); +$PAGE->set_heading($course->fullname); +echo $OUTPUT->header(); +echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo", 3); - if (!empty($param->user)) { - if (!$u = $DB->get_record('user', array('id'=>$param->user))) { - print_error("That's an invalid user!"); - } - $userinfo = fullname($u); - } +$mform->display(); - $strrecentactivity = get_string('recentactivity'); - $PAGE->navbar->add($strrecentactivity, new moodle_url($CFG->wwwroot.'/course/recent.php', array('id'=>$course->id))); - $PAGE->navbar->add($userinfo); - $PAGE->set_title("$course->shortname: $strrecentactivity"); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo", 3); +$modinfo =& get_fast_modinfo($course); +get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); - $mform->display(); +if (has_capability('moodle/course:viewhiddensections', $context)) { + $hiddenfilter = ""; +} else { + $hiddenfilter = "AND cs.visible = 1"; +} +$sections = array(); +if ($ss = $DB->get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible + FROM {course_sections} cs + WHERE cs.course = ? AND cs.section <= ? + $hiddenfilter + ORDER BY section", array($course->id, $course->numsections))) { + foreach ($ss as $section) { + $sections[$section->section] = $section; + } +} - $modinfo =& get_fast_modinfo($course); - get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); +if ($param->modid === 'all') { + // ok - if (has_capability('moodle/course:viewhiddensections', $context)) { - $hiddenfilter = ""; - } else { - $hiddenfilter = "AND cs.visible = 1"; +} else if (strpos($param->modid, 'mod/') === 0) { + $modname = substr($param->modid, strlen('mod/')); + if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) { + $filter = $modname; } - $sections = array(); - if ($ss = $DB->get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible - FROM {course_sections} cs - WHERE cs.course = ? AND cs.section <= ? - $hiddenfilter - ORDER BY section", array($course->id, $course->numsections))) { - foreach ($ss as $section) { - $sections[$section->section] = $section; - } + +} else if (strpos($param->modid, 'section/') === 0) { + $sectionid = substr($param->modid, strlen('section/')); + if (isset($sections[$sectionid])) { + $sections = array($sectionid=>$sections[$sectionid]); } - if ($param->modid === 'all') { - // ok +} else if (is_numeric($param->modid)) { + $section = $sections[$modinfo->cms[$param->modid]->sectionnum]; + $section->sequence = $param->modid; + $sections = array($section->sequence=>$section); +} - } else if (strpos($param->modid, 'mod/') === 0) { - $modname = substr($param->modid, strlen('mod/')); - if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) { - $filter = $modname; - } +switch ($course->format) { + case 'weeks': $sectiontitle = get_string('week'); break; + case 'topics': $sectiontitle = get_string('topic'); break; + default: $sectiontitle = get_string('section'); break; +} - } else if (strpos($param->modid, 'section/') === 0) { - $sectionid = substr($param->modid, strlen('section/')); - if (isset($sections[$sectionid])) { - $sections = array($sectionid=>$sections[$sectionid]); - } +if (is_null($modinfo->groups)) { + $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo +} - } else if (is_numeric($param->modid)) { - $section = $sections[$modinfo->cms[$param->modid]->sectionnum]; - $section->sequence = $param->modid; - $sections = array($section->sequence=>$section); - } +$activities = array(); +$index = 0; - switch ($course->format) { - case 'weeks': $sectiontitle = get_string('week'); break; - case 'topics': $sectiontitle = get_string('topic'); break; - default: $sectiontitle = get_string('section'); break; - } +foreach ($sections as $section) { - if (is_null($modinfo->groups)) { - $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo + $activity = new object(); + $activity->type = 'section'; + if ($section->section > 0) { + $activity->name = $sectiontitle.' '.$section->section; + } else { + $activity->name = ''; } - $activities = array(); - $index = 0; - - foreach ($sections as $section) { + $activity->visible = $section->visible; + $activities[$index++] = $activity; - $activity = new object(); - $activity->type = 'section'; - if ($section->section > 0) { - $activity->name = $sectiontitle.' '.$section->section; - } else { - $activity->name = ''; - } + if (empty($section->sequence)) { + continue; + } - $activity->visible = $section->visible; - $activities[$index++] = $activity; + $sectionmods = explode(",", $section->sequence); - if (empty($section->sequence)) { + foreach ($sectionmods as $cmid) { + if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) { continue; } - $sectionmods = explode(",", $section->sequence); - - foreach ($sectionmods as $cmid) { - if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) { - continue; - } - - $cm = $modinfo->cms[$cmid]; + $cm = $modinfo->cms[$cmid]; - if (!$cm->uservisible) { - continue; - } + if (!$cm->uservisible) { + continue; + } - if (!empty($filter) and $cm->modname != $filter) { - continue; - } + if (!empty($filter) and $cm->modname != $filter) { + continue; + } - $libfile = "$CFG->dirroot/mod/$cm->modname/lib.php"; + $libfile = "$CFG->dirroot/mod/$cm->modname/lib.php"; - if (file_exists($libfile)) { - require_once($libfile); - $get_recent_mod_activity = $cm->modname."_get_recent_mod_activity"; + if (file_exists($libfile)) { + require_once($libfile); + $get_recent_mod_activity = $cm->modname."_get_recent_mod_activity"; - if (function_exists($get_recent_mod_activity)) { - $activity = new object(); - $activity->type = 'activity'; - $activity->cmid = $cmid; - $activities[$index++] = $activity; - $get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group); - } + if (function_exists($get_recent_mod_activity)) { + $activity = new object(); + $activity->type = 'activity'; + $activity->cmid = $cmid; + $activities[$index++] = $activity; + $get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group); } } } +} - $detail = true; +$detail = true; - switch ($param->sortby) { - case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break; - case 'dateasc' : usort($activities, 'compare_activities_by_time_asc'); break; - case 'default' : - default : $detail = false; $param->sortby = 'default'; +switch ($param->sortby) { + case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break; + case 'dateasc' : usort($activities, 'compare_activities_by_time_asc'); break; + case 'default' : + default : $detail = false; $param->sortby = 'default'; - } +} - if (!empty($activities)) { +if (!empty($activities)) { - $newsection = true; - $lastsection = ''; - $newinstance = true; - $lastinstance = ''; - $inbox = false; + $newsection = true; + $lastsection = ''; + $newinstance = true; + $lastinstance = ''; + $inbox = false; - $section = 0; + $section = 0; - $activity_count = count($activities); - $viewfullnames = array(); + $activity_count = count($activities); + $viewfullnames = array(); - foreach ($activities as $key => $activity) { + foreach ($activities as $key => $activity) { - if ($activity->type == 'section') { - if ($param->sortby != 'default') { - continue; // no section if ordering by date - } - if ($activity_count == ($key + 1) or $activities[$key+1]->type == 'section') { - // peak at next activity. If it's another section, don't print this one! - // this means there are no activities in the current section - continue; - } + if ($activity->type == 'section') { + if ($param->sortby != 'default') { + continue; // no section if ordering by date + } + if ($activity_count == ($key + 1) or $activities[$key+1]->type == 'section') { + // peak at next activity. If it's another section, don't print this one! + // this means there are no activities in the current section + continue; } + } - if (($activity->type == 'section') && ($param->sortby == 'default')) { - if ($inbox) { - echo $OUTPUT->box_end(); - $spacer = new html_image(); - $spacer->height = 30; - echo $OUTPUT->spacer($spacer) . '
'; - } - echo $OUTPUT->box_start(); - echo "

$activity->name

"; - $inbox = true; + if (($activity->type == 'section') && ($param->sortby == 'default')) { + if ($inbox) { + echo $OUTPUT->box_end(); + $spacer = new html_image(); + $spacer->height = 30; + echo $OUTPUT->spacer($spacer) . '
'; + } + echo $OUTPUT->box_start(); + echo "

$activity->name

"; + $inbox = true; - } else if ($activity->type == 'activity') { + } else if ($activity->type == 'activity') { - if ($param->sortby == 'default') { - $cm = $modinfo->cms[$activity->cmid]; + if ($param->sortby == 'default') { + $cm = $modinfo->cms[$activity->cmid]; - if ($cm->visible) { - $linkformat = ''; - } else { - $linkformat = 'class="dimmed"'; - } - $name = format_string($cm->name); - $modfullname = $modnames[$cm->modname]; + if ($cm->visible) { + $linkformat = ''; + } else { + $linkformat = 'class="dimmed"'; + } + $name = format_string($cm->name); + $modfullname = $modnames[$cm->modname]; - $image = "mod_icon_url('icon', $cm->modname) . "\" class=\"icon\" alt=\"$modfullname\" />"; - echo "

$image $modfullname". - " wwwroot/mod/$cm->modname/view.php?id=$cm->id\" $linkformat>$name

"; - } + $image = "mod_icon_url('icon', $cm->modname) . "\" class=\"icon\" alt=\"$modfullname\" />"; + echo "

$image $modfullname". + " wwwroot/mod/$cm->modname/view.php?id=$cm->id\" $linkformat>$name

"; + } - } else { + } else { - if (!isset($viewfullnames[$activity->cmid])) { - $cm_context = get_context_instance(CONTEXT_MODULE, $activity->cmid); - $viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context); - } + if (!isset($viewfullnames[$activity->cmid])) { + $cm_context = get_context_instance(CONTEXT_MODULE, $activity->cmid); + $viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context); + } - if (!$inbox) { - echo $OUTPUT->box_start(); - $inbox = true; - } + if (!$inbox) { + echo $OUTPUT->box_start(); + $inbox = true; + } - $print_recent_mod_activity = $activity->type.'_print_recent_mod_activity'; + $print_recent_mod_activity = $activity->type.'_print_recent_mod_activity'; - if (function_exists($print_recent_mod_activity)) { - $print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]); - } + if (function_exists($print_recent_mod_activity)) { + $print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]); } } + } - if ($inbox) { - echo $OUTPUT->box_end(); - } + if ($inbox) { + echo $OUTPUT->box_end(); + } - } else { +} else { - echo '

' . get_string('norecentactivity') . '

'; + echo '

' . get_string('norecentactivity') . '

'; - } +} - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); function compare_activities_by_time_desc($a, $b) { // make sure the activities actually have a timestamp property @@ -280,4 +303,5 @@ function compare_activities_by_time_asc($a, $b) { return 0; return ($a->timestamp < $b->timestamp) ? -1 : 1; } -?> + +?> \ No newline at end of file diff --git a/course/recent_form.php b/course/recent_form.php index dde3dbe45c..c3cf6f4291 100644 --- a/course/recent_form.php +++ b/course/recent_form.php @@ -1,4 +1,27 @@ -. + +/** + * Display all recent activity in a flexible way + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require_once($CFG->libdir.'/formslib.php'); @@ -23,7 +46,7 @@ class recent_form extends moodleform { if ($viewparticipants) { $options = array(); $options[0] = get_string('allparticipants'); - if ($guest = get_guest()) { + if ($guest = get_complete_user_data('username', 'guest')) { $options[$guest->id] = fullname($guest); } diff --git a/course/report/log/graph.php b/course/report/log/graph.php index c317bd3649..59a9cd3ab9 100644 --- a/course/report/log/graph.php +++ b/course/report/log/graph.php @@ -1,184 +1,215 @@ -libdir/graphlib.php"); - - $id = required_param('id', PARAM_INT); // Course ID - $type = required_param('type', PARAM_FILE); // Graph Type - $user = optional_param('user', 0, PARAM_INT); // Student ID - $date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT) - - if (! $course = $DB->get_record("course", array("id"=>$id))) { - print_error('invalidcourseid'); +. + +/** + * Produces a graph of log accesses + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../../../config.php"); +require_once("../../lib.php"); +require_once("$CFG->libdir/graphlib.php"); + +$id = required_param('id', PARAM_INT); // Course ID +$type = required_param('type', PARAM_FILE); // Graph Type +$user = optional_param('user', 0, PARAM_INT); // Student ID +$date = optional_param('date', 0, PARAM_INT); // A time of a day (in GMT) + +$url = new moodle_url($CFG->wwwroot.'/course/report/log/graph.php', array('id'=>$id,'type'=>$type)); +if ($user !== 0) { + $url->param('user', $user); +} +if ($date !== 0) { + $url->param('date', $date); +} +$PAGE->set_url($url); + +if (! $course = $DB->get_record("course", array("id"=>$id))) { + print_error('invalidcourseid'); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $course->id); + +if (!$course->showreports or $USER->id != $user) { + require_capability('coursereport/log:view', $context); +} + +if ($user) { + if (! $user = $DB->get_record("user", array("id"=>$user))) { + print_error("nousers"); } +} - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - - if (!$course->showreports or $USER->id != $user) { - require_capability('coursereport/log:view', $context); - } +$logs = array(); - if ($user) { - if (! $user = $DB->get_record("user", array("id"=>$user))) { - print_error("nousers"); - } - } +$timenow = time(); - $logs = array(); +switch ($type) { + case "usercourse.png": - $timenow = time(); + $site = get_site(); - switch ($type) { - case "usercourse.png": + if ($course->id == $site->id) { + $courseselect = 0; + } else { + $courseselect = $course->id; + } - $site = get_site(); - - if ($course->id == $site->id) { - $courseselect = 0; - } else { - $courseselect = $course->id; - } + $maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds + //$maxseconds = 60 * 3600 * 24; // seconds + if ($timenow - $course->startdate > $maxseconds) { + $course->startdate = $timenow - $maxseconds; + } - $maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds - //$maxseconds = 60 * 3600 * 24; // seconds + if (!empty($CFG->loglifetime)) { + $maxseconds = $CFG->loglifetime * 3600 * 24; // seconds if ($timenow - $course->startdate > $maxseconds) { $course->startdate = $timenow - $maxseconds; } + } - if (!empty($CFG->loglifetime)) { - $maxseconds = $CFG->loglifetime * 3600 * 24; // seconds - if ($timenow - $course->startdate > $maxseconds) { - $course->startdate = $timenow - $maxseconds; - } - } - - $timestart = $coursestart = usergetmidnight($course->startdate); + $timestart = $coursestart = usergetmidnight($course->startdate); - if ((($timenow - $timestart)/86400.0) > 40) { - $reducedays = 7; - } else { - $reducedays = 0; - } + if ((($timenow - $timestart)/86400.0) > 40) { + $reducedays = 7; + } else { + $reducedays = 0; + } - $i = 0; - while ($timestart < $timenow) { - $timefinish = $timestart + 86400; - if ($reducedays) { - if ($i % $reducedays) { - $days[$i] = ""; - } else { - $days[$i] = userdate($timestart, "%a %d %b"); - } + $i = 0; + while ($timestart < $timenow) { + $timefinish = $timestart + 86400; + if ($reducedays) { + if ($i % $reducedays) { + $days[$i] = ""; } else { $days[$i] = userdate($timestart, "%a %d %b"); } - $logs[$i] = 0; - $i++; - $timestart = $timefinish; + } else { + $days[$i] = userdate($timestart, "%a %d %b"); } + $logs[$i] = 0; + $i++; + $timestart = $timefinish; + } - if ($rawlogs = get_logs_usercourse($user->id, $courseselect, $coursestart)) { - foreach ($rawlogs as $rawlog) { - $logs[$rawlog->day] = $rawlog->num; - } + if ($rawlogs = get_logs_usercourse($user->id, $courseselect, $coursestart)) { + foreach ($rawlogs as $rawlog) { + $logs[$rawlog->day] = $rawlog->num; } + } - $graph = new graph(750, 400); + $graph = new graph(750, 400); - $a->coursename = $course->shortname; - $a->username = fullname($user, true); - $graph->parameter['title'] = get_string("hitsoncourse", "", $a); + $a->coursename = $course->shortname; + $a->username = fullname($user, true); + $graph->parameter['title'] = get_string("hitsoncourse", "", $a); - $graph->x_data = $days; + $graph->x_data = $days; - $graph->y_data['logs'] = $logs; - $graph->y_order = array('logs'); + $graph->y_data['logs'] = $logs; + $graph->y_order = array('logs'); - if (!empty($CFG->preferlinegraphs)) { - $graph->y_format['logs'] = array('colour' => 'blue','line' => 'line'); - } else { - $graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.6); - $graph->parameter['bar_spacing'] = 0; - } + if (!empty($CFG->preferlinegraphs)) { + $graph->y_format['logs'] = array('colour' => 'blue','line' => 'line'); + } else { + $graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.6); + $graph->parameter['bar_spacing'] = 0; + } - $graph->parameter['y_label_left'] = get_string("hits"); - $graph->parameter['label_size'] = "12"; - $graph->parameter['x_axis_angle'] = 90; - $graph->parameter['x_label_angle'] = 0; - $graph->parameter['tick_length'] = 0; + $graph->parameter['y_label_left'] = get_string("hits"); + $graph->parameter['label_size'] = "12"; + $graph->parameter['x_axis_angle'] = 90; + $graph->parameter['x_label_angle'] = 0; + $graph->parameter['tick_length'] = 0; - - $graph->parameter['shadow'] = 'none'; - error_reporting(5); // ignore most warnings such as font problems etc - $graph->draw_stack(); + $graph->parameter['shadow'] = 'none'; - break; + error_reporting(5); // ignore most warnings such as font problems etc + $graph->draw_stack(); - case "userday.png": + break; - $site = get_site(); - - if ($course->id == $site->id) { - $courseselect = 0; - } else { - $courseselect = $course->id; - } + case "userday.png": - if ($date) { - $daystart = usergetmidnight($date); - } else { - $daystart = usergetmidnight(time()); - } - $dayfinish = $daystart + 86400; + $site = get_site(); - for ($i=0; $i<=23; $i++) { - $logs[$i] = 0; - $hour = $daystart + $i * 3600; - $hours[$i] = $i; - } + if ($course->id == $site->id) { + $courseselect = 0; + } else { + $courseselect = $course->id; + } - if ($rawlogs = get_logs_userday($user->id, $courseselect, $daystart)) { - foreach ($rawlogs as $rawlog) { - $logs[$rawlog->hour] = $rawlog->num; - } + if ($date) { + $daystart = usergetmidnight($date); + } else { + $daystart = usergetmidnight(time()); + } + $dayfinish = $daystart + 86400; + + for ($i=0; $i<=23; $i++) { + $logs[$i] = 0; + $hour = $daystart + $i * 3600; + $hours[$i] = $i; + } + + if ($rawlogs = get_logs_userday($user->id, $courseselect, $daystart)) { + foreach ($rawlogs as $rawlog) { + $logs[$rawlog->hour] = $rawlog->num; } + } - $graph = new graph(750, 400); + $graph = new graph(750, 400); - $a->coursename = $course->shortname; - $a->username = fullname($user, true); - $graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a); + $a->coursename = $course->shortname; + $a->username = fullname($user, true); + $graph->parameter['title'] = get_string("hitsoncoursetoday", "", $a); - $graph->x_data = $hours; + $graph->x_data = $hours; - $graph->y_data['logs'] = $logs; - $graph->y_order = array('logs'); + $graph->y_data['logs'] = $logs; + $graph->y_order = array('logs'); - if (!empty($CFG->preferlinegraphs)) { - $graph->y_format['logs'] = array('colour' => 'blue','line' => 'line'); - } else { - $graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.9); - } + if (!empty($CFG->preferlinegraphs)) { + $graph->y_format['logs'] = array('colour' => 'blue','line' => 'line'); + } else { + $graph->y_format['logs'] = array('colour' => 'blue','bar' => 'fill','bar_size' => 0.9); + } - $graph->parameter['y_label_left'] = get_string("hits"); - $graph->parameter['label_size'] = "12"; - $graph->parameter['x_axis_angle'] = 0; - $graph->parameter['x_label_angle'] = 0; + $graph->parameter['y_label_left'] = get_string("hits"); + $graph->parameter['label_size'] = "12"; + $graph->parameter['x_axis_angle'] = 0; + $graph->parameter['x_label_angle'] = 0; - $graph->parameter['shadow'] = 'none'; + $graph->parameter['shadow'] = 'none'; - error_reporting(5); // ignore most warnings such as font problems etc - $graph->draw_stack(); + error_reporting(5); // ignore most warnings such as font problems etc + $graph->draw_stack(); - break; + break; - default: - break; - } + default: + break; +} -?> +?> \ No newline at end of file diff --git a/course/report/log/lib.php b/course/report/log/lib.php index a218a60092..60e4347659 100644 --- a/course/report/log/lib.php +++ b/course/report/log/lib.php @@ -18,7 +18,7 @@ /** * This file contains functions used by the log reports * - * @package course-report + * @package course * @copyright 1999 onwards Martin Dougiamas http://moodle.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -93,7 +93,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } - if ($guest = get_guest()) { + if ($guest = get_complete_user_data('username', 'guest')) { $users[$guest->id] = fullname($guest); } } @@ -356,7 +356,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today' $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } - if ($guest = get_guest()) { + if ($guest = get_complete_user_data('username', 'guest')) { $users[$guest->id] = fullname($guest); } } diff --git a/course/report/stats/graph.php b/course/report/stats/graph.php index 1488eda379..0297de7ca3 100644 --- a/course/report/stats/graph.php +++ b/course/report/stats/graph.php @@ -1,154 +1,177 @@ -. + +/** + * This file is part of the User section Moodle + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once('../../../config.php'); +require_once($CFG->dirroot.'/lib/statslib.php'); +require_once($CFG->dirroot.'/lib/graphlib.php'); + +$courseid = required_param('course', PARAM_INT); +$report = required_param('report', PARAM_INT); +$time = required_param('time', PARAM_INT); +$mode = required_param('mode', PARAM_INT); +$userid = optional_param('userid', 0, PARAM_INT); +$roleid = optional_param('roleid',0,PARAM_INT); + + + +if (!$course = $DB->get_record("course", array("id"=>$courseid))) { + print_error("invalidcourseid"); +} + +if (!empty($userid)) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { + print_error("nousers"); + } +} - require_once('../../../config.php'); - require_once($CFG->dirroot.'/lib/statslib.php'); - require_once($CFG->dirroot.'/lib/graphlib.php'); +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $course->id); - $courseid = required_param('course', PARAM_INT); - $report = required_param('report', PARAM_INT); - $time = required_param('time', PARAM_INT); - $mode = required_param('mode', PARAM_INT); - $userid = optional_param('userid', 0, PARAM_INT); - $roleid = optional_param('roleid',0,PARAM_INT); +if (!$course->showreports or $USER->id != $userid) { + require_capability('coursereport/stats:view', $context); +} - if (!$course = $DB->get_record("course", array("id"=>$courseid))) { - print_error("invalidcourseid"); - } +stats_check_uptodate($course->id); - if (!empty($userid)) { - if (!$user = $DB->get_record('user', array('id'=>$userid))) { - print_error("nousers"); - } - } +$param = stats_get_parameters($time,$report,$course->id,$mode); - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); +if (!empty($userid)) { + $param->table = 'user_'.$param->table; +} - if (!$course->showreports or $USER->id != $userid) { - require_capability('coursereport/stats:view', $context); - } +// TODO: cleanup this ugly mess! +$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields +.' FROM {stats_'.$param->table.'} WHERE ' +.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') + .((!empty($userid)) ? ' userid = '.$userid.' AND ' : '') + .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '') + . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') + .' timeend >= '.$param->timeafter +.' '.$param->extras +.' ORDER BY timeend DESC'; - stats_check_uptodate($course->id); +$stats = $DB->get_records_sql($sql, $param->params); - $param = stats_get_parameters($time,$report,$course->id,$mode); +$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); - if (!empty($userid)) { - $param->table = 'user_'.$param->table; - } +$stats = array_reverse($stats); - // TODO: cleanup this ugly mess! - $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields - .' FROM {stats_'.$param->table.'} WHERE ' - .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') - .((!empty($userid)) ? ' userid = '.$userid.' AND ' : '') - .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '') - . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') - .' timeend >= '.$param->timeafter - .' '.$param->extras - .' ORDER BY timeend DESC'; - - $stats = $DB->get_records_sql($sql, $param->params); - - $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); - - $stats = array_reverse($stats); - - $graph = new graph(750,400); - - $graph->parameter['legend'] = 'outside-right'; - $graph->parameter['legend_size'] = 10; - $graph->parameter['x_axis_angle'] = 90; - $graph->parameter['title'] = false; // moodle will do a nicer job. - $graph->y_tick_labels = null; - - if (empty($param->crosstab)) { - foreach ($stats as $stat) { - $graph->x_data[] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); - $graph->y_data['line1'][] = $stat->line1; - if (isset($stat->line2)) { - $graph->y_data['line2'][] = $stat->line2; - } - if (isset($stat->line3)) { - $graph->y_data['line3'][] = $stat->line3; - } - } - $graph->y_order = array('line1'); - $graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1); - if (!empty($param->line2)) { - $graph->y_order[] = 'line2'; - $graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2); +$graph = new graph(750,400); + +$graph->parameter['legend'] = 'outside-right'; +$graph->parameter['legend_size'] = 10; +$graph->parameter['x_axis_angle'] = 90; +$graph->parameter['title'] = false; // moodle will do a nicer job. +$graph->y_tick_labels = null; + +if (empty($param->crosstab)) { + foreach ($stats as $stat) { + $graph->x_data[] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); + $graph->y_data['line1'][] = $stat->line1; + if (isset($stat->line2)) { + $graph->y_data['line2'][] = $stat->line2; } - if (!empty($param->line3)) { - $graph->y_order[] = 'line3'; - $graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3); + if (isset($stat->line3)) { + $graph->y_data['line3'][] = $stat->line3; } - $graph->y_tick_labels = false; - - } else { - $data = array(); - $times = array(); - $roles = array(); - $missedlines = array(); - $rolenames = get_all_roles(); - foreach ($rolenames as $r) { - $rolenames[$r->id] = $r->name; + } + $graph->y_order = array('line1'); + $graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1); + if (!empty($param->line2)) { + $graph->y_order[] = 'line2'; + $graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2); + } + if (!empty($param->line3)) { + $graph->y_order[] = 'line3'; + $graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3); + } + $graph->y_tick_labels = false; + +} else { + $data = array(); + $times = array(); + $roles = array(); + $missedlines = array(); + $rolenames = get_all_roles(); + foreach ($rolenames as $r) { + $rolenames[$r->id] = $r->name; + } + $rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id)); + foreach ($stats as $stat) { + $data[$stat->roleid][$stat->timeend] = $stat->line1; + if (!empty($stat->zerofixed)) { + $missedlines[] = $stat->timeend; } - $rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id)); - foreach ($stats as $stat) { - $data[$stat->roleid][$stat->timeend] = $stat->line1; - if (!empty($stat->zerofixed)) { - $missedlines[] = $stat->timeend; + if ($stat->roleid != 0) { + if (!array_key_exists($stat->roleid,$roles)) { + $roles[$stat->roleid] = $rolenames[$stat->roleid]; } - if ($stat->roleid != 0) { - if (!array_key_exists($stat->roleid,$roles)) { - $roles[$stat->roleid] = $rolenames[$stat->roleid]; - } - } else { - if (!array_key_exists($stat->roleid,$roles)) { - $roles[$stat->roleid] = get_string('all'); - } - } - if (!array_key_exists($stat->timeend,$times)) { - $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); + } else { + if (!array_key_exists($stat->roleid,$roles)) { + $roles[$stat->roleid] = get_string('all'); } } - foreach (array_keys($times) as $t) { - foreach ($data as $roleid => $stuff) { - if (!array_key_exists($t, $stuff)) { - $data[$roleid][$t] = 0; - } + if (!array_key_exists($stat->timeend,$times)) { + $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); + } + } + foreach (array_keys($times) as $t) { + foreach ($data as $roleid => $stuff) { + if (!array_key_exists($t, $stuff)) { + $data[$roleid][$t] = 0; } } + } - $roleid = 0; - krsort($roles); // the same sorting as in table bellow graph + $roleid = 0; + krsort($roles); // the same sorting as in table bellow graph - $colors = array('green', 'blue', 'red', 'purple', 'yellow', 'olive', 'navy', 'maroon', 'gray', 'ltred', 'ltltred', 'ltgreen', 'ltltgreen', 'orange', 'ltorange', 'ltltorange', 'lime', 'ltblue', 'ltltblue', 'fuchsia', 'aqua', 'grayF0', 'grayEE', 'grayDD', 'grayCC', 'gray33', 'gray66', 'gray99'); - $colorindex = 0; + $colors = array('green', 'blue', 'red', 'purple', 'yellow', 'olive', 'navy', 'maroon', 'gray', 'ltred', 'ltltred', 'ltgreen', 'ltltgreen', 'orange', 'ltorange', 'ltltorange', 'lime', 'ltblue', 'ltltblue', 'fuchsia', 'aqua', 'grayF0', 'grayEE', 'grayDD', 'grayCC', 'gray33', 'gray66', 'gray99'); + $colorindex = 0; - foreach ($roles as $roleid=>$rname) { - ksort($data[$roleid]); - $graph->y_order[] = $roleid+1; - if ($roleid) { - $color = $colors[$colorindex++]; - $colorindex = $colorindex % count($colors); - } else { - $color = 'black'; - } - $graph->y_format[$roleid+1] = array('colour' => $color, 'line' => 'line','legend' => $rname); + foreach ($roles as $roleid=>$rname) { + ksort($data[$roleid]); + $graph->y_order[] = $roleid+1; + if ($roleid) { + $color = $colors[$colorindex++]; + $colorindex = $colorindex % count($colors); + } else { + $color = 'black'; } - foreach (array_keys($data[$roleid]) as $time) { - $graph->x_data[] = $times[$time]; - } - foreach ($data as $roleid => $t) { - foreach ($t as $time => $data) { - $graph->y_data[$roleid+1][] = $data; - } + $graph->y_format[$roleid+1] = array('colour' => $color, 'line' => 'line','legend' => $rname); + } + foreach (array_keys($data[$roleid]) as $time) { + $graph->x_data[] = $times[$time]; + } + foreach ($data as $roleid => $t) { + foreach ($t as $time => $data) { + $graph->y_data[$roleid+1][] = $data; } } +} - $graph->draw_stack(); - - +$graph->draw_stack(); -?> +?> \ No newline at end of file diff --git a/course/request.php b/course/request.php index 3e9b69659b..d7b52c002f 100644 --- a/course/request.php +++ b/course/request.php @@ -1,108 +1,103 @@ -. /** * Allows a user to request a course be created for them. * - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package course - *//** */ + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->dirroot . '/course/request_form.php'); - require_once(dirname(__FILE__) . '/../config.php'); - require_once($CFG->dirroot . '/course/request_form.php'); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/request.php')); /// Where we came from. Used in a number of redirects. - $returnurl = $CFG->wwwroot . '/course/index.php'; +$returnurl = $CFG->wwwroot . '/course/index.php'; /// Check permissions. - require_login(); - if (isguestuser()) { - print_error('guestsarenotallowed', '', $returnurl); - } - if (empty($CFG->enablecourserequests)) { - print_error('courserequestdisabled', '', $returnurl); - } - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - require_capability('moodle/course:request', $systemcontext); +require_login(); +if (isguestuser()) { + print_error('guestsarenotallowed', '', $returnurl); +} +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'); +$requestform = new course_request_form($CFG->wwwroot . '/course/request.php'); - $strtitle = get_string('courserequest'); +$strtitle = get_string('courserequest'); /// Standard form processing if statement. - if ($requestform->is_cancelled()){ - redirect($returnurl); - - } else if ($data = $requestform->get_data()) { - $PAGE->set_title($strtitle); - $PAGE->set_heading($strtitle); - $PAGE->navbar->add($strtitle); - $PAGE->set_focuscontrol($requestform->focus()); - echo $OUTPUT->header(); - echo $OUTPUT->heading($strtitle); - - /// Record the request. - $data->requester = $USER->id; - $DB->insert_record('course_request', $data); - - /// Notify the admin if required. - if ($CFG->courserequestnotify) { - $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse'); - foreach ($users as $user) { - $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. +if ($requestform->is_cancelled()){ + redirect($returnurl); +} else if ($data = $requestform->get_data()) { $PAGE->set_title($strtitle); $PAGE->set_heading($strtitle); $PAGE->navbar->add($strtitle); $PAGE->set_focuscontrol($requestform->focus()); echo $OUTPUT->header(); echo $OUTPUT->heading($strtitle); - $requestform->display(); - echo $OUTPUT->footer(); -?> +/// Record the request. + $data->requester = $USER->id; + $DB->insert_record('course_request', $data); + +/// Notify the admin if required. + if ($CFG->courserequestnotify) { + $users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse'); + foreach ($users as $user) { + $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. + +$PAGE->set_title($strtitle); +$PAGE->set_heading($strtitle); +$PAGE->navbar->add($strtitle); +$PAGE->set_focuscontrol($requestform->focus()); +echo $OUTPUT->header(); +echo $OUTPUT->heading($strtitle); +$requestform->display(); +echo $OUTPUT->footer(); + +?> \ No newline at end of file diff --git a/course/reset.php b/course/reset.php index 8de087423d..56088f35f8 100755 --- a/course/reset.php +++ b/course/reset.php @@ -1,12 +1,31 @@ -. + +/** + * The purpose of this feature is to quickly remove all user related data from a course + * in order to make it available for a new semester. This feature can handle the removal + * of general course data like students, teachers, logs, events and groups as well as module + * specific data. Each module must be modified to take advantage of this new feature. + * The feature will also reset the start date of the course if necessary. + * + * @copyright Mark Flach and moodle.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require('../config.php'); require_once('reset_form.php'); @@ -17,6 +36,8 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("invalidcourseid"); } +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/reset.php', array('id'=>$id))); + require_login($course); require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id)); diff --git a/course/rest.php b/course/rest.php index 562af297bd..a0d766bb12 100644 --- a/course/rest.php +++ b/course/rest.php @@ -1,5 +1,27 @@ -. + +/** + * Provide interface for topics AJAX course formats + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require_once('../config.php'); require_once($CFG->dirroot.'/course/lib.php'); @@ -18,6 +40,7 @@ $summary = optional_param('summary', '', PARAM_RAW); $sequence = optional_param('sequence', '', PARAM_SEQUENCE); $visible = optional_param('visible', 0, PARAM_INT); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/rest.php', array('courseId'=>$courseId,'class'=>$class))); // Authorise the user and verify some incoming data if (!$course = $DB->get_record('course', array('id'=>$courseid))) { diff --git a/course/scales.php b/course/scales.php index 11d3968f5e..d93415c57a 100644 --- a/course/scales.php +++ b/course/scales.php @@ -1,64 +1,66 @@ -. + +/** + * Allows a creator to edit custom scales, and also display help about scales + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../config.php"); +require_once("lib.php"); + +$id = required_param('id', PARAM_INT); // course id +$scaleid = optional_param('scaleid', 0, PARAM_INT); // scale id (show only this one) + +$url = new moodle_url($CFG->wwwroot.'/course/scales.php', array('id'=>$id)); +if ($scaleid !== 0) { + $url->param('scaleid', $scaleid); +} +$PAGE->set_url($url); + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error("invalidcourseid"); +} + +require_login($course); +$context = get_context_instance(CONTEXT_COURSE, $course->id); +require_capability('moodle/course:viewscales', $context); + +$strscale = get_string("scale"); +$strscales = get_string("scales"); +$strcustomscale = get_string("scalescustom"); +$strstandardscale = get_string("scalesstandard"); +$strcustomscales = get_string("scalescustom"); +$strstandardscales = get_string("scalesstandard"); +$strname = get_string("name"); +$strdescription = get_string("description"); +$strhelptext = get_string("helptext"); +$stractivities = get_string("activities"); + +$PAGE->set_title($strscales); +echo $OUTPUT->header(); + +if ($scaleid) { + if ($scale = $DB->get_record("scale", array('id'=>$scaleid))) { + if ($scale->courseid == 0 || $scale->courseid == $course->id) { - require_once("../config.php"); - require_once("lib.php"); - - $id = required_param('id', PARAM_INT); // course id - $scaleid = optional_param('scaleid', 0, PARAM_INT); // scale id (show only this one) - - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error("invalidcourseid"); - } - - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/course:viewscales', $context); - - $strscale = get_string("scale"); - $strscales = get_string("scales"); - $strcustomscale = get_string("scalescustom"); - $strstandardscale = get_string("scalesstandard"); - $strcustomscales = get_string("scalescustom"); - $strstandardscales = get_string("scalesstandard"); - $strname = get_string("name"); - $strdescription = get_string("description"); - $strhelptext = get_string("helptext"); - $stractivities = get_string("activities"); - - $PAGE->set_title($strscales); - echo $OUTPUT->header(); - - if ($scaleid) { - if ($scale = $DB->get_record("scale", array('id'=>$scaleid))) { - if ($scale->courseid == 0 || $scale->courseid == $course->id) { - - $scalemenu = make_menu_from_list($scale->scale); - - echo $OUTPUT->box_start(); - echo $OUTPUT->heading($scale->name); - echo "
"; - echo $OUTPUT->select(html_select::make($scalemenu)); - echo "
"; - echo text_to_html($scale->description); - echo $OUTPUT->box_end(); - echo $OUTPUT->close_window_button(); - echo $OUTPUT->footer(); - exit; - } - } - } - - if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name ASC")) { - echo $OUTPUT->heading($strcustomscales); - - if (has_capability('moodle/course:managescales', $context)) { - echo "

("; - print_string('scalestip2'); - echo ")

"; - } - - foreach ($scales as $scale) { $scalemenu = make_menu_from_list($scale->scale); echo $OUTPUT->box_start(); @@ -68,34 +70,60 @@ echo ""; echo text_to_html($scale->description); echo $OUTPUT->box_end(); - echo "
"; + echo $OUTPUT->close_window_button(); + echo $OUTPUT->footer(); + exit; } + } +} - } else { - if (has_capability('moodle/course:managescales', $context)) { - echo "

("; - print_string("scalestip"); - echo ")

"; - } +if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name ASC")) { + echo $OUTPUT->heading($strcustomscales); + + if (has_capability('moodle/course:managescales', $context)) { + echo "

("; + print_string('scalestip2'); + echo ")

"; } - if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) { - echo $OUTPUT->heading($strstandardscales); - foreach ($scales as $scale) { - $scalemenu = make_menu_from_list($scale->scale); + foreach ($scales as $scale) { + $scalemenu = make_menu_from_list($scale->scale); + + echo $OUTPUT->box_start(); + echo $OUTPUT->heading($scale->name); + echo "
"; + echo $OUTPUT->select(html_select::make($scalemenu)); + echo "
"; + echo text_to_html($scale->description); + echo $OUTPUT->box_end(); + echo "
"; + } - echo $OUTPUT->box_start(); - echo $OUTPUT->heading($scale->name); - echo "
"; - echo $OUTPUT->select(html_select::make($scalemenu, '')); - echo "
"; - echo text_to_html($scale->description); - echo $OUTPUT->box_end(); - echo "
"; - } +} else { + if (has_capability('moodle/course:managescales', $context)) { + echo "

("; + print_string("scalestip"); + echo ")

"; + } +} + +if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) { + echo $OUTPUT->heading($strstandardscales); + foreach ($scales as $scale) { + $scalemenu = make_menu_from_list($scale->scale); + + echo $OUTPUT->box_start(); + echo $OUTPUT->heading($scale->name); + echo "
"; + echo $OUTPUT->select(html_select::make($scalemenu, '')); + echo "
"; + echo text_to_html($scale->description); + echo $OUTPUT->box_end(); + echo "
"; } +} - echo $OUTPUT->close_window_button(); - echo $OUTPUT->footer(); +echo $OUTPUT->close_window_button(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/course/switchrole.php b/course/switchrole.php index 5ed7b53130..739704d249 100644 --- a/course/switchrole.php +++ b/course/switchrole.php @@ -1,4 +1,5 @@ set_url(new moodle_url($CFG->wwwroot.'/course/switchrole.php', array('id'=>$id))); + if (!confirm_sesskey()) { print_error('confirmsesskeybad', 'error'); } @@ -81,4 +83,4 @@ if ($returnurl===false) { } redirect($returnurl); -?> +?> \ No newline at end of file diff --git a/course/togglecompletion.php b/course/togglecompletion.php index 44a72c83d8..5a72f5f4d8 100644 --- a/course/togglecompletion.php +++ b/course/togglecompletion.php @@ -1,6 +1,26 @@ . + +/** + * Toggles the manual completion flag for a particular activity and the current user. + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ require_once('../config.php'); require_once($CFG->libdir.'/completionlib.php'); @@ -8,6 +28,9 @@ require_once($CFG->libdir.'/completionlib.php'); // Parameters $cmid=required_param('id',PARAM_INT); $targetstate=required_param('completionstate',PARAM_INT); + +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/togglecompletion.php', array('id'=>$id,'completionstate'=>$targetstate))); + switch($targetstate) { case COMPLETION_COMPLETE: case COMPLETION_INCOMPLETE: @@ -57,4 +80,5 @@ if($fromajax) { $backto=optional_param('backto','view.php?id='.$course->id,PARAM_URL); redirect($backto); } -?> + +?> \ No newline at end of file diff --git a/course/unenrol.php b/course/unenrol.php index 92b23eadec..04453d3fc8 100644 --- a/course/unenrol.php +++ b/course/unenrol.php @@ -1,103 +1,124 @@ -id){ - // the rest of this code assumes $userid=0 means - // you are unassigning yourself, so set this for the - // correct capabiliy checks & language later - $userid = 0; - } - - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error('invalidcourseid'); - } - - if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { - print_error('invalidcontext'); - } - - require_login($course->id); - - if ($course->metacourse) { - print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id); +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Remove oneself or someone else from a course, unassigning all roles one might have + * + * This will not delete any of their data from the course, but will remove them + * from the participant list and prevent any course email being sent to them. + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../config.php"); +require_once("lib.php"); + +$id = required_param('id', PARAM_INT); //course +$userid = optional_param('user', 0, PARAM_INT); //course +$confirm = optional_param('confirm', 0, PARAM_BOOL); + +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/unenrol.php', array('id'=>$id))); + +if($userid == $USER->id){ + // the rest of this code assumes $userid=0 means + // you are unassigning yourself, so set this for the + // correct capabiliy checks & language later + $userid = 0; +} + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error('invalidcourseid'); +} + +if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { + print_error('invalidcontext'); +} + +require_login($course->id); + +if ($course->metacourse) { + print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id); +} + +if ($userid) { // Unenrolling someone else + require_capability('moodle/role:assign', $context, NULL, false); + + $roles = get_user_roles($context, $userid, false); + + // verify user may unassign all roles at course context + foreach($roles as $role) { + if (!user_can_assign($context, $role->roleid)) { + print_error('cannotunassignrolefrom', '', '', + $role->roleid); + } } - if ($userid) { // Unenrolling someone else - require_capability('moodle/role:assign', $context, NULL, false); +} else { // Unenrol yourself + require_capability('moodle/role:unassignself', $context, NULL, false); +} - $roles = get_user_roles($context, $userid, false); +if (!empty($USER->access['rsw'][$context->path])) { + print_error('cantunenrollinthisrole', '', + $CFG->wwwroot.'/course/view.php?id='.$course->id); +} - // verify user may unassign all roles at course context - foreach($roles as $role) { - if (!user_can_assign($context, $role->roleid)) { - print_error('cannotunassignrolefrom', '', '', - $role->roleid); - } +if ($confirm and confirm_sesskey()) { + if ($userid) { + if (! role_unassign(0, $userid, 0, $context->id)) { + print_error("unenrolerror"); } - } else { // Unenrol yourself - require_capability('moodle/role:unassignself', $context, NULL, false); - } - - if (!empty($USER->access['rsw'][$context->path])) { - print_error('cantunenrollinthisrole', '', - $CFG->wwwroot.'/course/view.php?id='.$course->id); - } + add_to_log($course->id, 'course', 'unenrol', + "view.php?id=$course->id", $course->id); + redirect($CFG->wwwroot.'/user/index.php?id='.$course->id); - if ($confirm and confirm_sesskey()) { - if ($userid) { - if (! role_unassign(0, $userid, 0, $context->id)) { - print_error("unenrolerror"); - } - - add_to_log($course->id, 'course', 'unenrol', - "view.php?id=$course->id", $course->id); - redirect($CFG->wwwroot.'/user/index.php?id='.$course->id); - - } else { - if (! role_unassign(0, $USER->id, 0, $context->id)) { - print_error("unenrolerror"); - } + } else { + if (! role_unassign(0, $USER->id, 0, $context->id)) { + print_error("unenrolerror"); + } - // force a refresh of mycourses - unset($USER->mycourses); - add_to_log($course->id, 'course', 'unenrol', - "view.php?id=$course->id", $course->id); + // force a refresh of mycourses + unset($USER->mycourses); + add_to_log($course->id, 'course', 'unenrol', + "view.php?id=$course->id", $course->id); - redirect($CFG->wwwroot); - } + redirect($CFG->wwwroot); } +} - $strunenrol = get_string('unenrol'); - $PAGE->navbar->add($strunenrol); - $PAGE->set_title("$course->shortname: $strunenrol"); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); - if ($userid) { - if (!$user = $DB->get_record('user', array('id'=>$userid))) { - print_error('nousers'); - } - $strunenrolsure = get_string('unenrolsure', '', fullname($user, true)); - echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&user=$user->id&confirm=yes", $PAGE->url); - } else { - $strunenrolsure = get_string('unenrolsure', '', get_string("yourself")); - echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&confirm=yes", $PAGE->url); +$strunenrol = get_string('unenrol'); +$PAGE->navbar->add($strunenrol); +$PAGE->set_title("$course->shortname: $strunenrol"); +$PAGE->set_heading($course->fullname); +echo $OUTPUT->header(); +if ($userid) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { + print_error('nousers'); } + $strunenrolsure = get_string('unenrolsure', '', fullname($user, true)); + echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&user=$user->id&confirm=yes", $PAGE->url); +} else { + $strunenrolsure = get_string('unenrolsure', '', get_string("yourself")); + echo $OUTPUT->confirm($strunenrolsure, "unenrol.php?id=$id&confirm=yes", $PAGE->url); +} - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/course/user.php b/course/user.php index b5172004d1..81c453c6e5 100644 --- a/course/user.php +++ b/course/user.php @@ -1,334 +1,367 @@ -. + +/** + * Display user activity reports for a course + * + * @copyright 1999 Martin Dougiamas http://dougiamas.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package course + */ + +require_once("../config.php"); +require_once("lib.php"); + +$id = required_param('id',PARAM_INT); // course id +$user = required_param('user',PARAM_INT); // user id +$mode = optional_param('mode', "todaylogs", PARAM_ALPHA); +$page = optional_param('page', 0, PARAM_INT); +$perpage = optional_param('perpage', 100, PARAM_INT); + +$url = new moodle_url($CFG->wwwroot.'/course/user.php', array('id'=>$id,'user'=>$user)); +if ($mode !== 'todaylogs') { + $url->param('mode', $mode); +} +if ($page !== 0) { + $url->param('page', $page); +} +if ($perpage !== 100) { + $url->param('perpage', $perpage); +} +$PAGE->set_url($url); - if (!$course = $DB->get_record('course', array('id'=>$id))) { - print_error('invalidcourseid', 'error'); - } +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error('invalidcourseid', 'error'); +} - if (! $user = $DB->get_record("user", array("id"=>$user))) { - print_error('invaliduserid', 'error'); - } +if (! $user = $DB->get_record("user", array("id"=>$user))) { + print_error('invaliduserid', 'error'); +} - require_login(); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - $personalcontext = get_context_instance(CONTEXT_USER, $user->id); +require_login(); +$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); +$personalcontext = get_context_instance(CONTEXT_USER, $user->id); - require_login(); - if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !has_capability('moodle/course:view', $coursecontext)) { - // do not require parents to be enrolled in courses ;-) - $PAGE->set_course($course); - } else { - require_login($course); - } +require_login(); +if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !has_capability('moodle/course:view', $coursecontext)) { + // do not require parents to be enrolled in courses ;-) + $PAGE->set_course($course); +} else { + require_login($course); +} - if ($user->deleted) { - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('userdeleted')); - echo $OUTPUT->footer(); - die; - } +if ($user->deleted) { + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('userdeleted')); + echo $OUTPUT->footer(); + die; +} - // prepare list of allowed modes - $myreports = ($course->showreports and $USER->id == $user->id); - $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext); +// prepare list of allowed modes +$myreports = ($course->showreports and $USER->id == $user->id); +$anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext); - $modes = array(); +$modes = array(); - if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { - $modes[] = 'outline'; - } +if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { + $modes[] = 'outline'; +} - if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { - $modes[] = 'complete'; - } +if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) { + $modes[] = 'complete'; +} - if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) { - $modes[] = 'todaylogs'; - } +if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) { + $modes[] = 'todaylogs'; +} - if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) { - $modes[] = 'alllogs'; - } +if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) { + $modes[] = 'alllogs'; +} - if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) { - $modes[] = 'stats'; - } +if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) { + $modes[] = 'stats'; +} - if (has_capability('moodle/grade:viewall', $coursecontext)) { - //ok - can view all course grades - $modes[] = 'grade'; +if (has_capability('moodle/grade:viewall', $coursecontext)) { + //ok - can view all course grades + $modes[] = 'grade'; - } else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) { - //ok - can view own grades - $modes[] = 'grade'; +} else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) { + //ok - can view own grades + $modes[] = 'grade'; - } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) { - // ok - can view grades of this user - parent most probably - $modes[] = 'grade'; +} else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) { + // ok - can view grades of this user - parent most probably + $modes[] = 'grade'; - } else if ($course->showgrades and $anyreport) { - // ok - can view grades of this user - parent most probably - $modes[] = 'grade'; - } +} else if ($course->showgrades and $anyreport) { + // ok - can view grades of this user - parent most probably + $modes[] = 'grade'; +} - if (empty($modes)) { - require_capability('moodle/user:viewuseractivitiesreport', $personalcontext); - } +if (empty($modes)) { + require_capability('moodle/user:viewuseractivitiesreport', $personalcontext); +} - if (!in_array($mode, $modes)) { - // forbidden or non-exitent mode - $mode = reset($modes); - } +if (!in_array($mode, $modes)) { + // forbidden or non-exitent mode + $mode = reset($modes); +} - add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id"); +add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id"); - $stractivityreport = get_string("activityreport"); - $strparticipants = get_string("participants"); - $stroutline = get_string("outline"); - $strcomplete = get_string("complete"); - $stralllogs = get_string("alllogs"); - $strtodaylogs = get_string("todaylogs"); - $strmode = get_string($mode); - $fullname = fullname($user, true); +$stractivityreport = get_string("activityreport"); +$strparticipants = get_string("participants"); +$stroutline = get_string("outline"); +$strcomplete = get_string("complete"); +$stralllogs = get_string("alllogs"); +$strtodaylogs = get_string("todaylogs"); +$strmode = get_string($mode); +$fullname = fullname($user, true); - $link = null; - if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) { - $link = new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$course->id)); - } - $PAGE->navbar->add($strparticipants, $link); - $PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id, 'course'=>$course->id))); - $PAGE->navbar->add($stractivityreport); - $PAGE->navbar->add($strmode); - $PAGE->set_title("$course->shortname: $stractivityreport ($mode)"); - $PAGE->set_heading($course->fullname); - echo $OUTPUT->header(); +$link = null; +if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) { + $link = new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$course->id)); +} +$PAGE->navbar->add($strparticipants, $link); +$PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id, 'course'=>$course->id))); +$PAGE->navbar->add($stractivityreport); +$PAGE->navbar->add($strmode); +$PAGE->set_title("$course->shortname: $stractivityreport ($mode)"); +$PAGE->set_heading($course->fullname); +echo $OUTPUT->header(); /// Print tabs at top /// This same call is made in: /// /user/view.php /// /user/edit.php /// /course/user.php - $currenttab = $mode; - $showroles = 1; - include($CFG->dirroot.'/user/tabs.php'); - - switch ($mode) { - case "grade": - if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) { - $CFG->grade_profilereport = 'user'; - } - require_once $CFG->libdir.'/gradelib.php'; - require_once $CFG->dirroot.'/grade/lib.php'; - require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; - - $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; - if (function_exists($functionname)) { - $functionname($course, $user); - } - break; - - case "todaylogs" : - echo '
'; - print_log_graph($course, $user->id, "userday.png"); - echo '
'; - print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage, - "user.php?id=$course->id&user=$user->id&mode=$mode"); - break; - - case "alllogs" : - echo '
'; - print_log_graph($course, $user->id, "usercourse.png"); - echo '
'; - print_log($course, $user->id, 0, "l.time DESC", $page, $perpage, - "user.php?id=$course->id&user=$user->id&mode=$mode"); - break; - case 'stats': - - if (empty($CFG->enablestats)) { - print_error('statsdisable', 'error'); +$currenttab = $mode; +$showroles = 1; +include($CFG->dirroot.'/user/tabs.php'); + +switch ($mode) { + case "grade": + if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) { + $CFG->grade_profilereport = 'user'; + } + require_once $CFG->libdir.'/gradelib.php'; + require_once $CFG->dirroot.'/grade/lib.php'; + require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; + + $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; + if (function_exists($functionname)) { + $functionname($course, $user); + } + break; + + case "todaylogs" : + echo '
'; + print_log_graph($course, $user->id, "userday.png"); + echo '
'; + print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage, + "user.php?id=$course->id&user=$user->id&mode=$mode"); + break; + + case "alllogs" : + echo '
'; + print_log_graph($course, $user->id, "usercourse.png"); + echo '
'; + print_log($course, $user->id, 0, "l.time DESC", $page, $perpage, + "user.php?id=$course->id&user=$user->id&mode=$mode"); + break; + case 'stats': + + if (empty($CFG->enablestats)) { + print_error('statsdisable', 'error'); + } + + require_once($CFG->dirroot.'/lib/statslib.php'); + + $statsstatus = stats_check_uptodate($course->id); + if ($statsstatus !== NULL) { + echo $OUTPUT->notification($statsstatus); + } + + $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend'); + $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend'); + $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend'); + + if (empty($earliestday)) $earliestday = time(); + if (empty($earliestweek)) $earliestweek = time(); + if (empty($earliestmonth)) $earliestmonth = time(); + + $now = stats_get_base_daily(); + $lastweekend = stats_get_base_weekly(); + $lastmonthend = stats_get_base_monthly(); + + $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); + + if (empty($timeoptions)) { + print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); + } + + // use the earliest. + $time = array_pop(array_keys($timeoptions)); + + $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED); + $params = $param->params; + + $param->table = 'user_'.$param->table; + + $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE ' + .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') + .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras + .' ORDER BY timeend DESC'; + $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!! + + if (empty($stats)) { + print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); + } + + // MDL-10818, do not display broken graph when user has no permission to view graph + if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) { + echo '
'.get_string('statisticsgraph').'
'; + } + + // What the heck is this about? -- MD + $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); + + $table = new html_table(); + $table->align = array('left','center','center','center'); + $param->table = str_replace('user_','',$param->table); + switch ($param->table) { + case 'daily' : $period = get_string('day'); break; + case 'weekly' : $period = get_string('week'); break; + case 'monthly': $period = get_string('month', 'form'); break; + default : $period = ''; + } + $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3); + foreach ($stats as $stat) { + if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD + continue; } + $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1); + $a[] = $stat->line2; + $a[] = $stat->line3; + $table->data[] = $a; + } + echo $OUTPUT->table($table); + break; + + case "outline" : + case "complete" : + get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); + $sections = get_all_sections($course->id); + + for ($i=0; $i<=$course->numsections; $i++) { + + if (isset($sections[$i])) { // should always be true + + $section = $sections[$i]; + $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections); + + if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert! + + if ($section->sequence) { + echo '
'; + echo '

'; + switch ($course->format) { + case "weeks": print_string("week"); break; + case "topics": print_string("topic"); break; + default: print_string("section"); break; + } + echo " $i

"; - require_once($CFG->dirroot.'/lib/statslib.php'); - - $statsstatus = stats_check_uptodate($course->id); - if ($statsstatus !== NULL) { - echo $OUTPUT->notification($statsstatus); - } - - $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend'); - $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend'); - $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend'); - - if (empty($earliestday)) $earliestday = time(); - if (empty($earliestweek)) $earliestweek = time(); - if (empty($earliestmonth)) $earliestmonth = time(); - - $now = stats_get_base_daily(); - $lastweekend = stats_get_base_weekly(); - $lastmonthend = stats_get_base_monthly(); - - $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); - - if (empty($timeoptions)) { - print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); - } - - // use the earliest. - $time = array_pop(array_keys($timeoptions)); - - $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED); - $params = $param->params; - - $param->table = 'user_'.$param->table; - - $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE ' - .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') - .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras - .' ORDER BY timeend DESC'; - $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!! - - if (empty($stats)) { - print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); - } - - // MDL-10818, do not display broken graph when user has no permission to view graph - if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) { - echo '
'.get_string('statisticsgraph').'
'; - } - - // What the heck is this about? -- MD - $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); - - $table = new html_table(); - $table->align = array('left','center','center','center'); - $param->table = str_replace('user_','',$param->table); - switch ($param->table) { - case 'daily' : $period = get_string('day'); break; - case 'weekly' : $period = get_string('week'); break; - case 'monthly': $period = get_string('month', 'form'); break; - default : $period = ''; - } - $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3); - foreach ($stats as $stat) { - if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD - continue; - } - $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1); - $a[] = $stat->line2; - $a[] = $stat->line3; - $table->data[] = $a; - } - echo $OUTPUT->table($table); - break; - - case "outline" : - case "complete" : - get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); - $sections = get_all_sections($course->id); - - for ($i=0; $i<=$course->numsections; $i++) { - - if (isset($sections[$i])) { // should always be true - - $section = $sections[$i]; - $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections); + echo '
'; - if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert! + if ($mode == "outline") { + echo ""; + } - if ($section->sequence) { - echo '
'; - echo '

'; - switch ($course->format) { - case "weeks": print_string("week"); break; - case "topics": print_string("topic"); break; - default: print_string("section"); break; + $sectionmods = explode(",", $section->sequence); + foreach ($sectionmods as $sectionmod) { + if (empty($mods[$sectionmod])) { + continue; } - echo " $i

"; - - echo '
'; + $mod = $mods[$sectionmod]; - if ($mode == "outline") { - echo "
"; + if (empty($mod->visible)) { + continue; } - $sectionmods = explode(",", $section->sequence); - foreach ($sectionmods as $sectionmod) { - if (empty($mods[$sectionmod])) { - continue; - } - $mod = $mods[$sectionmod]; + $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance)); + $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; - if (empty($mod->visible)) { - continue; - } + if (file_exists($libfile)) { + require_once($libfile); - $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance)); - $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; - - if (file_exists($libfile)) { - require_once($libfile); - - switch ($mode) { - case "outline": - $user_outline = $mod->modname."_user_outline"; - if (function_exists($user_outline)) { - $output = $user_outline($course, $user, $mod, $instance); - print_outline_row($mod, $instance, $output); - } - break; - case "complete": - $user_complete = $mod->modname."_user_complete"; - if (function_exists($user_complete)) { - $image = "modname/icon.gif\" ". - "class=\"icon\" alt=\"$mod->modfullname\" />"; - echo "

$image $mod->modfullname: ". - "wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". - format_string($instance->name,true)."

"; - - ob_start(); - - echo "
    "; - $user_complete($course, $user, $mod, $instance); - echo "
"; - - $output = ob_get_contents(); - ob_end_clean(); - - if (str_replace(' ', '', $output) != '
    ') { - echo $output; - } + switch ($mode) { + case "outline": + $user_outline = $mod->modname."_user_outline"; + if (function_exists($user_outline)) { + $output = $user_outline($course, $user, $mod, $instance); + print_outline_row($mod, $instance, $output); + } + break; + case "complete": + $user_complete = $mod->modname."_user_complete"; + if (function_exists($user_complete)) { + $image = "modname/icon.gif\" ". + "class=\"icon\" alt=\"$mod->modfullname\" />"; + echo "

    $image $mod->modfullname: ". + "wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". + format_string($instance->name,true)."

    "; + + ob_start(); + + echo "
      "; + $user_complete($course, $user, $mod, $instance); + echo "
    "; + + $output = ob_get_contents(); + ob_end_clean(); + + if (str_replace(' ', '', $output) != '
      ') { + echo $output; } - break; } + break; } } - - if ($mode == "outline") { - echo "
      "; } - echo '
      '; // content - echo '
      '; // section + + if ($mode == "outline") { + echo ""; } + echo ''; // content + echo ''; // section } } } - break; - default: - // can not be reached ;-) - } + } + break; + default: + // can not be reached ;-) +} - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); function print_outline_row($mod, $instance, $result) { @@ -357,4 +390,4 @@ function print_outline_row($mod, $instance, $result) { echo ""; } -?> +?> \ No newline at end of file