<commit_before><?PHP  // $Id$

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

    require_variable($id);    // Assignment

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

    require_login($course->id);

    if (!isteacher($course->id)) {
        error("Only teachers can look at this page");
    }


    if ($course->category) {
        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
    }

    $strassignments = get_string("modulenameplural", "assignment");
    $strassignment  = get_string("modulename", "assignment");
    $strsubmissions = get_string("submissions", "assignment");
    $strsaveallfeedback = get_string("saveallfeedback", "assignment");

    print_header("$course->shortname: $assignment->name", "$course->fullname",
                 "$navigation <A HREF=index.php?id=$course->id>$strassignments</A> -> 
                  <A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $strsubmissions", 
                  "", "", true);

/// Get all teachers and students
    $teachers = get_course_teachers($course->id);

    if (!$users = get_course_students($course->id)) {
        print_heading(get_string("nostudentsyet"));
        print_footer($course);
        exit;
    }

/// Make some easy ways to reference submissions
    if ($submissions = assignment_get_all_submissions($assignment)) {
        foreach ($submissions as $submission) {
            $submissionbyuser[$submission->userid] = $submission;
        }
    }

/// Get all existing submissions and check for missing ones
    foreach($users as $user) {
        if (!isset($submissionbyuser[$user->id])) {  // Need to create empty entry
            $newsubmission->assignment = $assignment->id;
            $newsubmission->userid = $user->id;
            $newsubmission->timecreated = time();
            if (!insert_record("assignment_submissions", $newsubmission)) {
                error("Could not insert a new empty submission");
            }
        }
    }

    if (isset($newsubmission)) {   // Get them all out again to be sure
        $submissions = assignment_get_all_submissions($assignment);
    }


/// If data is being submitted, then process it
    if ($data = data_submitted()) {
       
        $feedback = array();

        // Peel out all the data from variable names.
        foreach ($data as $key => $val) {
            if ($key <> "id") {
                $type = substr($key,0,1);
                $num  = substr($key,1); 
                $feedback[$num][$type] = $val;
            }
        }

        $timenow = time();
        $count = 0;
        foreach ($feedback as $num => $vals) {
            $submission = $submissions[$num];
            // Only update entries where feedback has actually changed.
            if (($vals['g'] <> $submission->grade) || ($vals['c'] <> addslashes($submission->comment))) {
                unset($newsubmission);
                $newsubmission->grade      = $vals['g'];
                $newsubmission->comment    = $vals['c'];
                $newsubmission->teacher    = $USER->id;
                $newsubmission->timemarked = $timenow;
                $newsubmission->mailed     = 0;           // Make sure mail goes out (again, even)
                $newsubmission->id         = $num;
                if (! update_record("assignment_submissions", $newsubmission)) {
                    notify(get_string("failedupdatefeedback", "assignment", $submission->userid));
                } else {
                    $count++;<commit_msg>For assignments without a timemodified stamp, add one when graded<commit_after><?PHP  // $Id$

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

    require_variable($id);    // Assignment

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

    require_login($course->id);

    if (!isteacher($course->id)) {
        error("Only teachers can look at this page");
    }


    if ($course->category) {
        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
    }

    $strassignments = get_string("modulenameplural", "assignment");
    $strassignment  = get_string("modulename", "assignment");
    $strsubmissions = get_string("submissions", "assignment");
    $strsaveallfeedback = get_string("saveallfeedback", "assignment");

    print_header("$course->shortname: $assignment->name", "$course->fullname",
                 "$navigation <A HREF=index.php?id=$course->id>$strassignments</A> -> 
                  <A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $strsubmissions", 
                  "", "", true);

/// Get all teachers and students
    $teachers = get_course_teachers($course->id);

    if (!$users = get_course_students($course->id)) {
        print_heading(get_string("nostudentsyet"));
        print_footer($course);
        exit;
    }

/// Make some easy ways to reference submissions
    if ($submissions = assignment_get_all_submissions($assignment)) {
        foreach ($submissions as $submission) {
            $submissionbyuser[$submission->userid] = $submission;
        }
    }

/// Get all existing submissions and check for missing ones
    foreach($users as $user) {
        if (!isset($submissionbyuser[$user->id])) {  // Need to create empty entry
            $newsubmission->assignment = $assignment->id;
            $newsubmission->userid = $user->id;
            $newsubmission->timecreated = time();
            if (!insert_record("assignment_submissions", $newsubmission)) {
                error("Could not insert a new empty submission");
            }
        }
    }

    if (isset($newsubmission)) {   // Get them all out again to be sure
        $submissions = assignment_get_all_submissions($assignment);
    }


/// If data is being submitted, then process it
    if ($data = data_submitted()) {
       
        $feedback = array();

        // Peel out all the data from variable names.
        foreach ($data as $key => $val) {
            if ($key <> "id") {
                $type = substr($key,0,1);
                $num  = substr($key,1); 
                $feedback[$num][$type] = $val;
            }
        }

        $timenow = time();
        $count = 0;
        foreach ($feedback as $num => $vals) {
            $submission = $submissions[$num];
            // Only update entries where feedback has actually changed.
            if (($vals['g'] <> $submission->grade) || ($vals['c'] <> addslashes($submission->comment))) {
                unset($newsubmission);
                $newsubmission->grade      = $vals['g'];
                $newsubmission->comment    = $vals['c'];
                $newsubmission->teacher    = $USER->id;
                $newsubmission->timemarked = $timenow;
                $newsubmission->mailed     = 0;           // Make sure mail goes out (again, even)
                $newsubmission->id         = $num;
                if (empty($submission->timemodified)) {   // eg for offline assignments
                    $newsubmission->timemodified = $timenow;
                }
                if (! update_record("assignment_submissions", $newsubmission)) {
                    notify(get_string("failedupdatefeedback", "assignment", $submission->userid));
                } else {
                    $count++;
{'fraction_non_alphanumeric': 0.15517457139281693, 'fraction_numerical': 0.0012514078338130396, 'mean_word_length': 2.2461413484971566, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2110840', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2228, 'n_words': 482}