示例#1
0
    }
}
if ($is_editor) {
    load_js('tools.js');
    global $themeimg, $m;
    $head_content .= "\n    <script type='text/javascript'>\n    function check_weights() {\n        /* function to check weight validity */\n        if(\$('#hidden-opt').is(':visible') && \$('#auto_judge').is(':checked')) {\n            var weights = document.getElementsByClassName('auto_judge_weight');\n            var weight_sum = 0;\n            var max_grade = parseFloat(document.getElementById('max_grade').value);\n            max_grade = Math.round(max_grade * 1000) / 1000;\n\n            for (i = 0; i < weights.length; i++) {\n                // match ints or floats\n                w = weights[i].value.match(/^\\d+\\.\\d+\$|^\\d+\$/);\n                if(w != null) {\n                    w = parseFloat(w);\n                    if(w >= 0  && w <= max_grade)  // 0->max_grade allowed\n                    {\n                        /* allow 3 decimal digits */\n                        weight_sum += w;\n                        continue;\n                    }\n                    else{\n                        alert('Weights must be between 1 and max_grade!');\n                        return false;\n                    }\n                }\n                else {\n                    alert('Only numbers as weights!');\n                    return false;\n                }\n            }\n            diff = Math.round((max_grade - weight_sum) * 1000) / 1000;\n            if (diff >= 0 && diff <= 0.001) {\n                return true;\n            }\n            else {\n                alert('Weights do not sum up to ' + max_grade +\n                    '!\\n(Remember, 3 decimal digits precision)');\n                return false;\n            }\n        }\n        else\n            return true;\n    }\n    function updateWeightsSum() {\n        var weights = document.getElementsByClassName('auto_judge_weight');\n        var weight_sum = 0;\n        var max_grade = parseFloat(document.getElementById('max_grade').value);\n        max_grade = Math.round(max_grade * 1000) / 1000;\n\n        for (i = 0; i < weights.length; i++) {\n            // match ints or floats\n            w = weights[i].value.match(/^\\d+\\.\\d+\$|^\\d+\$/);\n            if(w != null) {\n                w = parseFloat(w);\n                if(w >= 0  && w <= max_grade)  // 0->max_grade allowed\n                {\n                    /* allow 3 decimal digits */\n                    weight_sum += w;\n                    continue;\n                }\n                else{\n                    \$('#weights-sum').html('-');\n                    \$('#weights-sum').css('color', 'red');\n                    return;\n                }\n            }\n            else {\n                \$('#weights-sum').html('-');\n                \$('#weights-sum').css('color', 'red');\n                return;\n            }\n        }\n        \$('#weights-sum').html(weight_sum);\n        diff = Math.round((max_grade - weight_sum) * 1000) / 1000;\n        if (diff >= 0 && diff <= 0.001) {\n            \$('#weights-sum').css('color', 'green');\n        } else {\n            \$('#weights-sum').css('color', 'red');\n        }\n    }\n    \$(document).ready(function() {\n        updateWeightsSum();\n        \$('.auto_judge_weight').change(updateWeightsSum);\n        \$('#max_grade').change(updateWeightsSum);\n    });\n\n    \$(function() {\n        \$('input[name=group_submissions]').click(changeAssignLabel);\n        \$('input[id=assign_button_some]').click(ajaxAssignees);\n        \$('input[id=assign_button_all]').click(hideAssignees);\n        \$('input[name=auto_judge]').click(changeAutojudgeScenariosVisibility);\n        \$(document).ready(function() { changeAutojudgeScenariosVisibility.apply(\$('input[name=auto_judge]')); });\n\n        function hideAssignees()\n        {\n            \$('#assignees_tbl').addClass('hide');\n            \$('#assignee_box').find('option').remove();\n        }\n        function changeAssignLabel()\n        {\n            var assign_to_specific = \$('input:radio[name=assign_to_specific]:checked').val();\n            if(assign_to_specific==1){\n               ajaxAssignees();\n            }\n            if (this.id=='group_button') {\n               \$('#assign_button_all_text').text('{$m['WorkToAllGroups']}');\n               \$('#assign_button_some_text').text('{$m['WorkToGroup']}');\n               \$('#assignees').text('{$langGroups}');\n            } else {\n               \$('#assign_button_all_text').text('{$m['WorkToAllUsers']}');\n               \$('#assign_button_some_text').text('{$m['WorkToUser']}');\n               \$('#assignees').text('{$langStudents}');\n            }\n        }\n        function ajaxAssignees()\n        {\n            \$('#assignees_tbl').removeClass('hide');\n            var type = \$('input:radio[name=group_submissions]:checked').val();\n            \$.post('{$works_url['url']}',\n            {\n              assign_type: type\n            },\n            function(data,status){\n                var index;\n                var parsed_data = JSON.parse(data);\n                var select_content = '';\n                if(type==0){\n                    for (index = 0; index < parsed_data.length; ++index) {\n                        select_content += '<option value=\"' + parsed_data[index]['id'] + '\">' + parsed_data[index]['surname'] + ' ' + parsed_data[index]['givenname'] + '<\\/option>';\n                    }\n                } else {\n                    for (index = 0; index < parsed_data.length; ++index) {\n                        select_content += '<option value=\"' + parsed_data[index]['id'] + '\">' + parsed_data[index]['name'] + '<\\/option>';\n                    }\n                }\n                \$('#assignee_box').find('option').remove();\n                \$('#assign_box').find('option').remove().end().append(select_content);\n            });\n        }\n\n        function changeAutojudgeScenariosVisibility() {\n            if(\$(this).is(':checked')) {\n                \$(this).parent().parent().find('table').show();\n                \$('#lang').parent().parent().show();\n            } else {\n                \$(this).parent().parent().find('table').hide();\n                \$('#lang').parent().parent().hide();\n            }\n        }\n        \$('#autojudge_new_scenario').click(function(e) {\n            var rows = \$(this).parent().parent().parent().find('tr').size()-1;\n            // Clone the first line\n            var newLine = \$(this).parent().parent().parent().find('tr:first').clone();\n            // Replace 0 wth the line number\n            newLine.html(newLine.html().replace(/auto_judge_scenarios\\[0\\]/g, 'auto_judge_scenarios['+rows+']'));\n            // Initialize the remove event and show the button\n            newLine.find('.autojudge_remove_scenario').show();\n            newLine.find('.autojudge_remove_scenario').click(removeRow);\n            // Clear out any potential content\n            newLine.find('input').val('');\n            // Insert it just before the final line\n            newLine.insertBefore(\$(this).parent().parent().parent().find('tr:last'));\n            // Add the event handler\n            newLine.find('.auto_judge_weight').change(updateWeightsSum);\n            e.preventDefault();\n            return false;\n        });\n        // Remove row\n        function removeRow(e) {\n            \$(this).parent().parent().remove();\n            e.preventDefault();\n            return false;\n        }\n        \$('.autojudge_remove_scenario').click(removeRow);\n        \$(document).on('change', 'select.auto_judge_assertion', function(e) {\n            e.preventDefault();\n            var value = \$(this).val();\n\n            // Change selected attr.\n            \$(this).find('option').each(function() {\n                if (\$(this).attr('selected') == 'selected') {\n                    \$(this).removeAttr('selected');\n                } else if (\$(this).attr('value') == value) {\n                    \$(this).attr('selected', true);\n                }\n            });\n            var row       = \$(this).parent().parent();\n            var tableBody = \$(this).parent().parent().parent();\n            var indexNum  = row.index() + 1;\n\n            if (value === 'eq' ||\n                value === 'same' ||\n                value === 'notEq' ||\n                value === 'notSame' ||\n                value === 'startsWith' ||\n                value === 'endsWith' ||\n                value === 'contains'\n            ) {\n                tableBody.find('tr:nth-child('+indexNum+')').find('input.auto_judge_output').removeAttr('disabled');\n            } else {\n                tableBody.find('tr:nth-child('+indexNum+')').find('input.auto_judge_output').val('');\n                tableBody.find('tr:nth-child('+indexNum+')').find('input.auto_judge_output').attr('disabled', 'disabled');\n            }\n            return false;\n        });\n    });\n\n    </script>";
    $email_notify = isset($_POST['email']) && $_POST['email'];
    if (isset($_POST['grade_comments'])) {
        $work_title = Database::get()->querySingle("SELECT title FROM assignment WHERE id = ?d", intval($_POST['assignment']))->title;
        $pageName = $work_title;
        $navigation[] = $works_url;
        submit_grade_comments($_POST['assignment'], $_POST['submission'], $_POST['grade'], $_POST['comments'], $email_notify, null);
    } elseif (isset($_GET['add'])) {
        $pageName = $langNewAssign;
        $navigation[] = $works_url;
        new_assignment();
    } elseif (isset($_POST['assign_type'])) {
        if ($_POST['assign_type']) {
            $data = Database::get()->queryArray("SELECT name,id FROM `group` WHERE course_id = ?d", $course_id);
        } else {
            $data = Database::get()->queryArray("SELECT user.id AS id, surname, givenname\n                                    FROM user, course_user\n                                    WHERE user.id = course_user.user_id\n                                    AND course_user.course_id = ?d AND course_user.status = 5\n                                    AND user.id", $course_id);
        }
        echo json_encode($data);
        exit;
    } elseif (isset($_POST['new_assign'])) {
        add_assignment();
    } elseif (isset($_GET['as_id'])) {
        $as_id = intval($_GET['as_id']);
        $id = intval($_GET['id']);
        if (delete_user_assignment($as_id)) {
            Session::Messages($langDeleted, 'alert-success');
示例#2
0
<?php

require_once dirname(__FILE__) . "/includes/functions.php";
page_head("Pridanie zadania");
page_nav();
get_topright_form();
if (!isset($_SESSION["loggedUser"]) || $_SESSION["loggedUser"] == null) {
    dieWithError("err-not-logged-in");
}
if (get_class($_SESSION["loggedUser"]) == "Team") {
    dieWithError("err-add-assignment-rights");
}
if ($conn = db_connect()) {
    $id = new_assignment($conn, $_SESSION["loggedUser"]->getId());
    $assignment = new Assignment($conn, $id);
    if (isset($_POST['skName']) && $_POST['skName'] != $assignment->getSkName()) {
        $assignment->setSkName($conn, $_POST['skName']);
    }
    if (isset($_POST['engName']) && $_POST['engName'] != $assignment->getEngName()) {
        $assignment->setEngName($conn, $_POST['engName']);
    }
    if (isset($_POST['skTextPopis']) && $_POST['skTextPopis'] != $assignment->getSkTxt()) {
        $assignment->setSkTxt($conn, $_POST['skTextPopis']);
    }
    if (isset($_POST['engTextPopis']) && $_POST['engTextPopis'] != $assignment->getEngTxt()) {
        $assignment->setEngTxt($conn, $_POST['engTextPopis']);
    }
    if (isset($_POST['textVideo']) && $_POST['textVideo'] != "") {
        $assignment->uploadVideo($conn, $_POST['textVideo']);
    }
    if (isset($_FILES['uploadedFiles'])) {