moodle/course/importstudents.php

133 lines
4.7 KiB
PHP
Raw Normal View History

<?php // $Id$
2005-01-24 22:23:01 +00:00
// 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.
require_once("../config.php");
require_once("lib.php");
2005-01-24 22:23:01 +00:00
define("MAX_COURSES_PER_PAGE", 1000);
$id = required_param('id',PARAM_INT); // course id
$add = optional_param('add', 0, PARAM_BOOL);
$remove = optional_param('remove', 0, PARAM_BOOL);
$showall = optional_param('showall', 0, PARAM_BOOL);
$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
$previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
$previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
2005-01-24 22:23:01 +00:00
if (! $site = get_site()) {
redirect("$CFG->wwwroot/$CFG->admin/index.php");
}
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
require_login($course->id);
2006-09-18 08:20:01 +00:00
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managemetacourse', $context);
2005-01-24 22:23:01 +00:00
if (!$course->metacourse) {
2006-09-18 08:20:01 +00:00
redirect("$CFG->wwwroot/course/view.php?id=$course->id");
2005-01-24 22:23:01 +00:00
}
2005-01-24 22:23:01 +00:00
$strassigncourses = get_string('metaassigncourses');
$stralreadycourses = get_string('metaalreadycourses');
$strnoalreadycourses = get_string('metanoalreadycourses');
$strpotentialcourses = get_string('metapotentialcourses');
$strnopotentialcourses = get_string('metanopotentialcourses');
$straddcourses = get_string('metaaddcourse');
$strremovecourse = get_string('metaremovecourse');
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
$strcourses = get_string("courses");
$strshowall = get_string("showall");
print_header("$course->shortname: $strassigncourses",
"$site->fullname",
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strassigncourses",
2005-01-24 22:23:01 +00:00
"studentform.searchtext");
/// Print a help notice about the need to use this page
if (!$frm = data_submitted()) {
$note = get_string("importmetacoursenote");
2005-01-24 22:23:01 +00:00
print_simple_box($note, "center", "50%");
/// A form was submitted so process the input
} else {
if ($add and !empty($frm->addselect) and confirm_sesskey()) {
2005-01-24 22:23:01 +00:00
$timestart = $timeend = 0;
foreach ($frm->addselect as $addcourse) {
$addcourse = clean_param($addcourse, PARAM_INT);
set_time_limit(180);
2005-01-24 22:23:01 +00:00
if (!add_to_metacourse($course->id,$addcourse)) {
error("Could not add the selected course to this meta course!");
}
}
} else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
2005-01-24 22:23:01 +00:00
foreach ($frm->removeselect as $removecourse) {
set_time_limit(180);
$removecourse = clean_param($removecourse, PARAM_INT);
2005-01-24 22:23:01 +00:00
if (! remove_from_metacourse($course->id,$removecourse)) {
error("Could not remove the selected course from this meta course!");
2005-01-24 22:23:01 +00:00
}
}
} else if ($showall and confirm_sesskey()) {
$searchtext = '';
$previoussearch = 0;
2005-01-24 22:23:01 +00:00
}
}
/// Get all existing students and teachers for this course.
2005-01-24 22:23:01 +00:00
if(! $alreadycourses = get_courses_in_metacourse($course->id)) {
$alreadycourses = array();
}
$numcourses = 0;
/// Get search results excluding any users already in this course
if (($searchtext != '') and $previoussearch and confirm_sesskey()) {
if ($searchcourses = get_courses_search(explode(" ",$searchtext),'fullname ASC',0,99999,$numcourses)) {
foreach ($searchcourses as $tmp) {
if (array_key_exists($tmp->id,$alreadycourses)) {
unset($searchcourses[$tmp->id]);
}
if (!empty($tmp->metacourse)) {
unset($searchcourses[$tmp->id]);
}
2005-01-24 22:23:01 +00:00
}
if (array_key_exists($course->id,$searchcourses)) {
unset($searchcourses[$course->id]);
2005-05-16 19:38:21 +00:00
}
$numcourses = count($searchcourses);
2005-01-24 22:23:01 +00:00
}
}
2005-01-24 22:23:01 +00:00
/// If no search results then get potential students for this course excluding users already in course
if (empty($searchcourses)) {
2005-01-24 22:23:01 +00:00
$numcourses = get_courses_notin_metacourse($course->id,true);
$courses = array();
if ($numcourses <= MAX_COURSES_PER_PAGE) {
$courses = get_courses_notin_metacourse($course->id);
}
}
2005-01-25 14:03:43 +00:00
print_simple_box_start("center");
2005-01-24 22:23:01 +00:00
include('importstudents.html');
print_simple_box_end();
print_footer();
2005-01-25 14:03:43 +00:00
?>