MDL-10870 A few more fixes to the file.php page's navigation
[moodle-pu.git] / course / importstudents.php
blobd182dde227ddbaf9d217855404ba1a88bcb58240
1 <?php // $Id$
2 // script to assign students to a meta course by selecting which courses the meta course comprises.
3 // this is basically a hack of student.php that uses courses instead.
5 require_once("../config.php");
6 require_once("lib.php");
8 define("MAX_COURSES_PER_PAGE", 1000);
10 $id = required_param('id',PARAM_INT); // course id
11 $add = optional_param('add', 0, PARAM_BOOL);
12 $remove = optional_param('remove', 0, PARAM_BOOL);
13 $showall = optional_param('showall', 0, PARAM_BOOL);
14 $searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
15 $previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
16 $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
18 if (! $site = get_site()) {
19 redirect("$CFG->wwwroot/$CFG->admin/index.php");
22 if (! $course = get_record("course", "id", $id)) {
23 error("Course ID was incorrect (can't find it)");
26 require_login($course->id);
27 $context = get_context_instance(CONTEXT_COURSE, $course->id);
28 require_capability('moodle/course:managemetacourse', $context);
30 if (!$course->metacourse) {
31 redirect("$CFG->wwwroot/course/view.php?id=$course->id");
34 $strassigncourses = get_string('metaassigncourses');
35 $stralreadycourses = get_string('metaalreadycourses');
36 $strnoalreadycourses = get_string('metanoalreadycourses');
37 $strpotentialcourses = get_string('metapotentialcourses');
38 $strnopotentialcourses = get_string('metanopotentialcourses');
39 $straddcourses = get_string('metaaddcourse');
40 $strremovecourse = get_string('metaremovecourse');
41 $strsearch = get_string("search");
42 $strsearchresults = get_string("searchresults");
43 $strcourses = get_string("courses");
44 $strshowall = get_string("showall");
46 print_header("$course->shortname: $strassigncourses",
47 $site->fullname,
48 "<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strassigncourses",
49 "searchtext");
52 /// Print a help notice about the need to use this page
54 print_heading(get_string('childcourses'));
56 if (!$frm = data_submitted()) {
57 $note = get_string("importmetacoursenote");
58 print_simple_box($note, "center", "50%");
60 /// A form was submitted so process the input
62 } else {
63 if ($add and !empty($frm->addselect) and confirm_sesskey()) {
64 $timestart = $timeend = 0;
65 foreach ($frm->addselect as $addcourse) {
66 $addcourse = clean_param($addcourse, PARAM_INT);
67 set_time_limit(180);
68 if (!add_to_metacourse($course->id,$addcourse)) {
69 error("Could not add the selected course to this meta course!");
72 } else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
73 foreach ($frm->removeselect as $removecourse) {
74 set_time_limit(180);
75 $removecourse = clean_param($removecourse, PARAM_INT);
76 if (! remove_from_metacourse($course->id,$removecourse)) {
77 error("Could not remove the selected course from this meta course!");
80 } else if ($showall and confirm_sesskey()) {
81 $searchtext = '';
82 $previoussearch = 0;
87 /// Get all existing students and teachers for this course.
88 if(! $alreadycourses = get_courses_in_metacourse($course->id)) {
89 $alreadycourses = array();
92 $numcourses = 0;
95 /// Get search results excluding any users already in this course
96 if (($searchtext != '') and $previoussearch and confirm_sesskey()) {
97 if ($searchcourses = get_courses_search(explode(" ",$searchtext),'fullname ASC',0,99999,$numcourses)) {
98 foreach ($searchcourses as $tmp) {
99 if (array_key_exists($tmp->id,$alreadycourses)) {
100 unset($searchcourses[$tmp->id]);
102 if (!empty($tmp->metacourse)) {
103 unset($searchcourses[$tmp->id]);
106 if (array_key_exists($course->id,$searchcourses)) {
107 unset($searchcourses[$course->id]);
109 $numcourses = count($searchcourses);
113 /// If no search results then get potential students for this course excluding users already in course
114 if (empty($searchcourses)) {
115 $numcourses = count_courses_notin_metacourse($course->id);
117 if ($numcourses > 0 and $numcourses <= MAX_COURSES_PER_PAGE) {
118 $courses = get_courses_notin_metacourse($course->id);
119 } else {
120 $courses = array();
124 print_simple_box_start("center");
126 include('importstudents.html');
128 print_simple_box_end();
130 print_footer();