function update_assignments_max_grade($scale_id) { $max_grade = max_grade_from_scale($scale_id); Database::get()->query("UPDATE assignment SET max_grade = ?f WHERE grading_scale_id = ?d", $max_grade, $scale_id); }
function edit_assignment($id) { global $tool_content, $langBackAssignment, $langEditSuccess, $m, $langTheField, $langEditError, $course_code, $works_url, $course_id, $uid, $workPath, $langFormErrors, $langScales; $v = new Valitron\Validator($_POST); $v->rule('required', array('title')); $v->rule('integer', array('group_submissions', 'assign_to_specific')); if (isset($_POST['max_grade'])) { $v->rule('required', array('max_grade')); $v->rule('numeric', array('max_grade')); $v->labels(array('max_grade' => "$langTheField $m[max_grade]")); } if (isset($_POST['scale'])) { $v->rule('required', array('scale')); $v->rule('numeric', array('scale')); $v->labels(array('scale' => "$langTheField $langScales")); } $v->labels(array('title' => "$langTheField $m[title]")); if($v->validate()) { $row = Database::get()->querySingle("SELECT * FROM assignment WHERE id = ?d", $id); $title = $_POST['title']; $desc = purify($_POST['desc']); $submission_type = $_POST['submission_type']; $submission_date = isset($_POST['WorkStart']) && !empty($_POST['WorkStart']) ? DateTime::createFromFormat('d-m-Y H:i', $_POST['WorkStart'])->format('Y-m-d H:i:s') : (new DateTime('NOW'))->format('Y-m-d H:i:s'); $deadline = isset($_POST['WorkEnd']) && !empty($_POST['WorkEnd']) ? DateTime::createFromFormat('d-m-Y H:i', $_POST['WorkEnd'])->format('Y-m-d H:i:s') : NULL; $late_submission = isset($_POST['late_submission']) ? 1 : 0; $group_submissions = $_POST['group_submissions']; if (isset($_POST['scale'])) { $max_grade = max_grade_from_scale($_POST['scale']); $grading_scale_id = $_POST['scale']; } else { $max_grade = $_POST['max_grade']; $grading_scale_id = 0; } $assign_to_specific = filter_input(INPUT_POST, 'assign_to_specific', FILTER_VALIDATE_INT); $assigned_to = filter_input(INPUT_POST, 'ingroup', FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY); $auto_judge = isset($_POST['auto_judge']) ? filter_input(INPUT_POST, 'auto_judge', FILTER_VALIDATE_INT) : 0; $auto_judge_scenarios = isset($_POST['auto_judge_scenarios']) ? serialize($_POST['auto_judge_scenarios']) : ""; $lang = isset($_POST['lang']) ? filter_input(INPUT_POST, 'lang') : ''; if ($assign_to_specific == 1 && empty($assigned_to)) { $assign_to_specific = 0; } if (!isset($_POST['comments'])) { $comments = ''; } else { $comments = purify($_POST['comments']); } if (!isset($_FILES) || !$_FILES['userfile']['size']) { $_FILES['userfile']['name'] = ''; $_FILES['userfile']['tmp_name'] = ''; $filename = $row->file_path; $file_name = $row->file_name; } else { validateUploadedFile($_FILES['userfile']['name'], 2); if (preg_match('/\.(ade|adp|bas|bat|chm|cmd|com|cpl|crt|exe|hlp|hta|' . 'inf|ins|isp|jse|lnk|mdb|mde|msc|msi|msp|mst|pcd|pif|reg|scr|sct|shs|' . 'shb|url|vbe|vbs|wsc|wsf|wsh)$/', $_FILES['userfile']['name'])) { $tool_content .= "<p class=\"caution\">$langUnwantedFiletype: {$_FILES['userfile']['name']}<br />"; $tool_content .= "<a href=\"$_SERVER[SCRIPT_NAME]?course=$course_code&id=$id\">$langBack</a></p><br />"; return; } $student_name = trim(uid_to_name($user_id)); $local_name = !empty($student_name)? $student_name : uid_to_name($user_id, 'username'); $am = Database::get()->querySingle("SELECT am FROM user WHERE id = ?d", $uid)->am; if (!empty($am)) { $local_name .= $am; } $local_name = greek_to_latin($local_name); $local_name = replace_dangerous_char($local_name); $secret = $row->secret_directory; $ext = get_file_extension($_FILES['userfile']['name']); $filename = "$secret/$local_name" . (empty($ext) ? '' : '.' . $ext); if (move_uploaded_file($_FILES['userfile']['tmp_name'], "$workPath/admin_files/$filename")) { @chmod("$workPath/admin_files/$filename", 0644); $file_name = $_FILES['userfile']['name']; } } Database::get()->query("UPDATE assignment SET title = ?s, description = ?s, group_submissions = ?d, comments = ?s, submission_type = ?d, deadline = ?t, late_submission = ?d, submission_date = ?t, max_grade = ?f, grading_scale_id = ?d, assign_to_specific = ?d, file_path = ?s, file_name = ?s, auto_judge = ?d, auto_judge_scenarios = ?s, lang = ?s WHERE course_id = ?d AND id = ?d", $title, $desc, $group_submissions, $comments, $submission_type, $deadline, $late_submission, $submission_date, $max_grade, $grading_scale_id, $assign_to_specific, $filename, $file_name, $auto_judge, $auto_judge_scenarios, $lang, $course_id, $id); Database::get()->query("DELETE FROM assignment_to_specific WHERE assignment_id = ?d", $id); //tags if (isset($_POST['tags'])) { $tagsArray = explode(',', $_POST['tags']); $moduleTag = new ModuleElement($id); $moduleTag->syncTags($tagsArray); } if ($assign_to_specific && !empty($assigned_to)) { if ($group_submissions == 1) { $column = 'group_id'; $other_column = 'user_id'; } else { $column = 'user_id'; $other_column = 'group_id'; } foreach ($assigned_to as $assignee_id) { Database::get()->query("INSERT INTO assignment_to_specific ({$column}, {$other_column}, assignment_id) VALUES (?d, ?d, ?d)", $assignee_id, 0, $id); } } Log::record($course_id, MODULE_ID_ASSIGN, LOG_MODIFY, array('id' => $id, 'title' => $title, 'description' => $desc, 'deadline' => $deadline, 'group' => $group_submissions)); \ Session::Messages($langEditSuccess,'alert-success'); redirect_to_home_page("modules/work/index.php?course=$course_code"); } else { Session::flashPost()->Messages($langFormErrors)->Errors($v->errors()); redirect_to_home_page("modules/work/index.php?course=$course_code&id=$id&choice=edit"); } }