<commit_before><?php //  $Id$
// 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");

    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;

    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);
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('moodle/course:managemetacourse', $context);

    if (!$course->metacourse) {
        redirect("$CFG->wwwroot/course/view.php?id=$course->id");
    }

    $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",
                 "studentform.searchtext");


/// Print a help notice about the need to use this page

    if (!$frm = data_submitted()) {
        $note = get_string("importmetacoursenote");
        print_simple_box($note, "center", "50%");

/// A form was submitted so process the input

    } else {
        if ($add and !empty($frm->addselect) and confirm_sesskey()) {
            $timestart = $timeend = 0;
            foreach ($frm->addselect as $addcourse) {
                $addcourse = clean_param($addcourse, PARAM_INT);
                set_time_limit(10);
                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()) {
            foreach ($frm->removeselect as $removecourse) {
                set_time_limit(10);
                $removecourse = clean_param($removecourse, PARAM_INT);
                if (! remove_from_metacourse($course->id,$removecourse)) {
                    error("Could not remove the selected course from this meta course!");
                }
            }<commit_msg>MDL-7344 Change 'import child course' timeout to 180 seconds per course because role creation takes a while for thousands of users. (Merge from STABLE)<commit_after><?php //  $Id$
// 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");

    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;

    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);
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('moodle/course:managemetacourse', $context);

    if (!$course->metacourse) {
        redirect("$CFG->wwwroot/course/view.php?id=$course->id");
    }

    $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",
                 "studentform.searchtext");


/// Print a help notice about the need to use this page

    if (!$frm = data_submitted()) {
        $note = get_string("importmetacoursenote");
        print_simple_box($note, "center", "50%");

/// A form was submitted so process the input

    } else {
        if ($add and !empty($frm->addselect) and confirm_sesskey()) {
            $timestart = $timeend = 0;
            foreach ($frm->addselect as $addcourse) {
                $addcourse = clean_param($addcourse, PARAM_INT);
                set_time_limit(180);
                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()) {
            foreach ($frm->removeselect as $removecourse) {
                set_time_limit(180);
                $removecourse = clean_param($removecourse, PARAM_INT);
                if (! remove_from_metacourse($course->id,$removecourse)) {
                    error("Could not remove the selected course from this meta course!");
                }
            }
{'fraction_non_alphanumeric': 0.13952793546459516, 'fraction_numerical': 0.006423662981774723, 'mean_word_length': 2.8789107763615296, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '325054', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1939, 'n_words': 425}