<commit_before><?PHP  // $Id$

// This script uses installed report plugins to print quiz reports

    require_once("../../config.php");
    require_once("lib.php");

    $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
    $hp = optional_param('hp', 0, PARAM_INT); // hotpot ID

    if ($id) {
        if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
            error("Course Module ID was incorrect");
        }
        if (! $course = get_record("course", "id", $cm->course)) {
            error("Course is misconfigured");
        }    
        if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
            error("Course module is incorrect");
        }

    } else {
        if (! $hotpot = get_record("hotpot", "id", $hp)) {
            error("Course module is incorrect");
        }
        if (! $course = get_record("course", "id", $hotpot->course)) {
            error("Course is misconfigured");
        }
        if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
            error("Course Module ID was incorrect");
        }
    }

    // get the roles context for this course
    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
    $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);

    // set homeurl of couse (for error messages)
    $course_homeurl = "$CFG->wwwroot/course/view.php?id=$course->id";

    require_login($course->id);

    // get report mode
    if (has_capability('mod/hotpot:viewreport',$modulecontext)) {
        $mode = optional_param('mode', 'overview', PARAM_ALPHA);
    } else {
        // ordinary students have no choice
        $mode = 'overview';
    }

    // assemble array of form data
    $formdata = array(
        'mode' => $mode,
        'reportusers'      => has_capability('mod/hotpot:viewreport',$modulecontext) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'allusers'), PARAM_ALPHA) : 'this',
        'reportattempts'   => optional_param('reportattempts', get_user_preferences('hotpot_reportattempts', 'all'), PARAM_ALPHA),
        'reportformat'     => optional_param('reportformat', 'htm', PARAM_ALPHA),
        'reportshowlegend' => optional_param('reportshowlegend', get_user_preferences('hotpot_reportshowlegend', '0'), PARAM_INT),
        'reportencoding'   => optional_param('reportencoding', get_user_preferences('hotpot_reportencoding', ''), PARAM_ALPHANUM),
        'reportwrapdata'   => optional_param('reportwrapdata', get_user_preferences('hotpot_reportwrapdata', '1'), PARAM_INT),
    );

    foreach ($formdata as $name=>$value) {
        set_user_preference("hotpot_$name", $value);
    }

/// Start the report

    add_to_log($course->id, "hotpot", "report", "report.php?id=$cm->id&mode=$mode", "$hotpot->id", "$cm->id");

    // print page header. if required
    if ($formdata['reportformat']=='htm') {
        hotpot_print_report_heading($course, $cm, $hotpot, $mode);
        if (has_capability('mod/hotpot:viewreport',$modulecontext)) {
            hotpot_print_report_selector($course, $hotpot, $formdata);
        }
    }

    // delete selected attempts, if any
    if (has_capability('mod/hotpot:deleteattempt',$modulecontext)) {
        $del = optional_param('del', '', PARAM_ALPHA);
        hotpot_delete_selected_attempts($hotpot, $del);
    }

    // check for groups
    if (preg_match('/^group(\d*)$/', $formdata['reportusers'], $matches)) {
        // validate groupid
        if (is_numeric($matches[1]) && get_field('groups', 'courseid', 'id', $matches[1])===$course->id) {
            $formdata['reportusers'] = 'group';
            $formdata['reportgroupid'] = $matches[1];
        } else {
            $formdata['reportgroupid'] = 0; // groupid is invalid
        }
    }

    $user_ids = '';<commit_msg>fix HotPot reports for groups (MDL-8944)<commit_after><?PHP  // $Id$

// This script uses installed report plugins to print quiz reports

    require_once("../../config.php");
    require_once("lib.php");

    $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
    $hp = optional_param('hp', 0, PARAM_INT); // hotpot ID

    if ($id) {
        if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
            error("Course Module ID was incorrect");
        }
        if (! $course = get_record("course", "id", $cm->course)) {
            error("Course is misconfigured");
        }    
        if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
            error("Course module is incorrect");
        }

    } else {
        if (! $hotpot = get_record("hotpot", "id", $hp)) {
            error("Course module is incorrect");
        }
        if (! $course = get_record("course", "id", $hotpot->course)) {
            error("Course is misconfigured");
        }
        if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
            error("Course Module ID was incorrect");
        }
    }

    // get the roles context for this course
    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
    $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);

    // set homeurl of couse (for error messages)
    $course_homeurl = "$CFG->wwwroot/course/view.php?id=$course->id";

    require_login($course->id);

    // get report mode
    if (has_capability('mod/hotpot:viewreport',$modulecontext)) {
        $mode = optional_param('mode', 'overview', PARAM_ALPHA);
    } else {
        // ordinary students have no choice
        $mode = 'overview';
    }

    // assemble array of form data
    $formdata = array(
        'mode' => $mode,
        'reportusers'      => has_capability('mod/hotpot:viewreport',$modulecontext) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'allusers'), PARAM_ALPHA) : 'this',
        'reportattempts'   => optional_param('reportattempts', get_user_preferences('hotpot_reportattempts', 'all'), PARAM_ALPHA),
        'reportformat'     => optional_param('reportformat', 'htm', PARAM_ALPHA),
        'reportshowlegend' => optional_param('reportshowlegend', get_user_preferences('hotpot_reportshowlegend', '0'), PARAM_INT),
        'reportencoding'   => optional_param('reportencoding', get_user_preferences('hotpot_reportencoding', ''), PARAM_ALPHANUM),
        'reportwrapdata'   => optional_param('reportwrapdata', get_user_preferences('hotpot_reportwrapdata', '1'), PARAM_INT),
    );

    foreach ($formdata as $name=>$value) {
        set_user_preference("hotpot_$name", $value);
    }

/// Start the report

    add_to_log($course->id, "hotpot", "report", "report.php?id=$cm->id&mode=$mode", "$hotpot->id", "$cm->id");

    // print page header. if required
    if ($formdata['reportformat']=='htm') {
        hotpot_print_report_heading($course, $cm, $hotpot, $mode);
        if (has_capability('mod/hotpot:viewreport',$modulecontext)) {
            hotpot_print_report_selector($course, $hotpot, $formdata);
        }
    }

    // delete selected attempts, if any
    if (has_capability('mod/hotpot:deleteattempt',$modulecontext)) {
        $del = optional_param('del', '', PARAM_ALPHA);
        hotpot_delete_selected_attempts($hotpot, $del);
    }

    // check for groups
    if (preg_match('/^group(\d*)$/', $formdata['reportusers'], $matches)) {
        $formdata['reportusers'] = 'group';
        $formdata['reportgroupid'] = 0;
        // validate groupid
        if ($groups = groups_get_groups_names($course->id)) {
            if (isset($groups[$matches[1]])) {
                $formdata['reportgroupid'] = $matches[1];
            }
        }
    }

    $user_ids = '';
{'fraction_non_alphanumeric': 0.16225772655840753, 'fraction_numerical': 0.00248821372446307, 'mean_word_length': 3.0861423220973783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5733366', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2337, 'n_words': 464}