[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/course/ -> importstudents.php (source)

   1  <?php //  $Id: importstudents.php,v 1.24 2007/08/17 19:09:11 nicolasconnault Exp $
   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.
   4  
   5      require_once("../config.php");
   6      require_once ("lib.php");
   7  
   8      define("MAX_COURSES_PER_PAGE", 1000);
   9  
  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;
  17  
  18      if (! $site = get_site()) {
  19          redirect("$CFG->wwwroot/$CFG->admin/index.php");
  20      }
  21  
  22      if (! $course = get_record("course", "id", $id)) {
  23          error("Course ID was incorrect (can't find it)");
  24      }
  25  
  26      require_login($course->id);
  27      $context = get_context_instance(CONTEXT_COURSE, $course->id);
  28      require_capability('moodle/course:managemetacourse', $context);
  29  
  30      if (!$course->metacourse) {
  31          redirect("$CFG->wwwroot/course/view.php?id=$course->id");
  32      }
  33  
  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");
  45  
  46      print_header("$course->shortname: $strassigncourses",
  47                   $site->fullname,
  48                   build_navigation(array(array('name' => $strassigncourses, 'link' => null, 'type' => 'misc'))), "searchtext");
  49  
  50  
  51  /// Print a help notice about the need to use this page
  52  
  53      print_heading(get_string('childcourses'));
  54  
  55      if (!$frm = data_submitted()) {
  56          $note = get_string("importmetacoursenote");
  57          print_simple_box($note, "center", "50%");
  58  
  59  /// A form was submitted so process the input
  60  
  61      } else {
  62          if ($add and !empty($frm->addselect) and confirm_sesskey()) {
  63              $timestart = $timeend = 0;
  64              foreach ($frm->addselect as $addcourse) {
  65                  $addcourse = clean_param($addcourse, PARAM_INT);
  66                  set_time_limit(180);
  67                  if (!add_to_metacourse($course->id,$addcourse)) {
  68                      error("Could not add the selected course to this meta course!");
  69                  }
  70              }
  71          } else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
  72              foreach ($frm->removeselect as $removecourse) {
  73                  set_time_limit(180);
  74                  $removecourse = clean_param($removecourse, PARAM_INT);
  75                  if (! remove_from_metacourse($course->id,$removecourse)) {
  76                      error("Could not remove the selected course from this meta course!");
  77                  }
  78              }
  79          } else if ($showall and confirm_sesskey()) {
  80              $searchtext = '';
  81              $previoussearch = 0;
  82          }
  83      }
  84  
  85  
  86  /// Get all existing students and teachers for this course.
  87      if(! $alreadycourses = get_courses_in_metacourse($course->id)) {
  88          $alreadycourses = array();
  89      }
  90  
  91      $numcourses = 0;
  92  
  93  
  94  /// Get search results excluding any users already in this course
  95      if (($searchtext != '') and $previoussearch and confirm_sesskey()) {
  96          if ($searchcourses = get_courses_search(explode(" ",$searchtext),'fullname ASC',0,99999,$numcourses)) {
  97              foreach ($searchcourses as $tmp) {
  98                  if (array_key_exists($tmp->id,$alreadycourses)) {
  99                      unset($searchcourses[$tmp->id]);
 100                  }
 101                  if (!empty($tmp->metacourse)) {
 102                      unset($searchcourses[$tmp->id]);
 103                  }
 104              }
 105              if (array_key_exists($course->id,$searchcourses)) {
 106                  unset($searchcourses[$course->id]);
 107              }
 108              $numcourses = count($searchcourses);
 109          }
 110      }
 111  
 112  /// If no search results then get potential students for this course excluding users already in course
 113      if (empty($searchcourses)) {
 114          $numcourses = count_courses_notin_metacourse($course->id);
 115  
 116          if ($numcourses > 0 and $numcourses <= MAX_COURSES_PER_PAGE) {
 117              $courses = get_courses_notin_metacourse($course->id);
 118          } else {
 119              $courses = array();
 120          }
 121      }
 122  
 123      print_simple_box_start("center");
 124  
 125      include ('importstudents.html');
 126  
 127      print_simple_box_end();
 128  
 129      print_footer();
 130  
 131  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7