function php_syntax($output)
{
    $ret = $output[1];
    $ret = wordwrap($ret, 120, "\n", 0);
    $ret = highlight_syntax(unhtmlentities($ret));
    return "<pre>" . $ret . "</pre>";
}
    function view()
    {
        global $USER;
        //echo "beginning of view";
        $edit = optional_param('edit', 0, PARAM_BOOL);
        $saved = optional_param('saved', 0, PARAM_BOOL);
        $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
        require_capability('mod/problemstatement:view', $context);
        $submission = $this->get_submission();
        //var_dump($this->problemstatement);
        //Guest can not submit nor edit an problemstatement (bug: 4604)
        if (!has_capability('mod/problemstatement:submit', $context)) {
            $editable = null;
        } else {
            $editable = $this->isopen() && (!$submission || $this->problemstatement->allowresubmit || !$submission->timemarked);
        }
        $editmode = ($editable and $edit);
        if ($editmode) {
            //guest can not edit or submit problemstatement
            if (!has_capability('mod/problemstatement:submit', $context)) {
                print_error('guestnosubmit', 'problemstatement');
            }
        }
        add_to_log($this->course->id, "problemstatement", "view", "view.php?id={$this->cm->id}", $this->problemstatement->id, $this->cm->id);
        /// prepare form and process submitted data
        $mform = new mod_problemstatement_online_edit_form();
        $defaults = new object();
        $defaults->id = $this->cm->id;
        if (!empty($submission)) {
            $defaults->programtext = $submission->programtext;
            $defaults->langid = $submission->langid;
        }
        /*if (!empty($submission)) {
                    if ($this->usehtmleditor) {
                        $options = new object();
                        $options->smiley = false;
                        $options->filter = false;
        
                        //$defaults->text   = format_text($submission->data1, $submission->data2, $options);
                        $defaults->text   = $submission->programtext;
                        //$defaults->format = FORMAT_TEXT;
                    } else {
                        $defaults->text   = $submission->programtext;
                        //$defaults->format = 0;
                    }
                }*/
        $mform->set_data($defaults);
        if ($mform->is_cancelled()) {
            redirect('view.php?id=' . $this->cm->id);
        }
        if ($data = $mform->get_data()) {
            // No incoming data?
            if ($editable && $this->update_submission($data)) {
                //TODO fix log actions - needs db upgrade
                $submission = $this->get_submission();
                add_to_log($this->course->id, 'problemstatement', 'upload', 'view.php?a=' . $this->problemstatement->id, $this->problemstatement->id, $this->cm->id);
                //$this->email_teachers($submission);
                //redirect to get updated submission date and word count
                redirect('view.php?id=' . $this->cm->id . '&saved=1');
            } else {
                // TODO: add better error message
                notify(get_string("error"));
                //submitting not allowed!
            }
        }
        /// print header, etc. and display form if needed
        if ($editmode) {
            $this->view_header(get_string('editmysubmission', 'problemstatement'));
        } else {
            $this->view_header();
        }
        if ($editmode) {
            echo '
<script language="javascript" type="text/javascript" src="editarea/edit_area/edit_area_compressor.php?plugins"></script>
<script language="javascript" type="text/javascript">
var _onload=null;

function change_style(sender)
{
	val=sender.options[sender.selectedIndex].value;
	lang="";

	if (val=="1") lang="pas"; else
	if (val=="0") lang="cpp"; else
	if (val=="2") lang="java"; else
	if (val=="3") lang="python"; else
	if (val=="4") lang="cpp"
	editAreaLoader.execCommand(\'id_programtext\',"change_syntax",lang);
	return lang;
};
function add_onchange()
{
	sel=document.getElementById(\'id_langid\')
	sel.onchange=function(){change_style(this)};
	lang=change_style(sel)
editAreaLoader.init({
        id : "id_programtext"        // textarea id
        ,syntax: lang          // syntax to be uses for highlight mode on start-up
        ,start_highlight: true  // to display with highlight mode on start-up
});
	if (_onload!=null) _onload();
};
_onload=window.onload;
window.onload=add_onchange;
</script>
';
        }
        $this->view_intro();
        $this->view_dates();
        if ($saved) {
            notify(get_string('submissionsaved', 'problemstatement'), 'notifysuccess');
        }
        if (has_capability('mod/problemstatement:submit', $context)) {
            if ($editmode) {
                print_box_start('generalbox', 'online');
                $mform->display();
            } else {
                print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
                if ($submission) {
                    echo highlight_syntax($submission->programtext, $submission->langid);
                    $msg = "";
                    switch ($submission->processed) {
                        case "0":
                            $msg .= get_string("unprocessed", "problemstatement");
                            break;
                        case "1":
                            switch ($submission->succeeded) {
                                case "0":
                                    $msg .= get_string("unsuccess", "problemstatement");
                                    break;
                                case "1":
                                    $msg .= get_string("success", "problemstatement");
                                    break;
                                case "2":
                                    $msg .= get_string("compilationerror", "problemstatement") . "\n" . $submission->submissioncomment;
                                    break;
                                case "3":
                                    $msg .= get_string("internalerror", "problemstatement");
                                    break;
                                case "4":
                                    $msg .= get_string("timeout", "problemstatement");
                                    break;
                                case "5":
                                    $msg .= get_string("memoryout", "problemstatement");
                                    break;
                                case "6":
                                    $msg .= get_string("runtimeerror", "problemstatement") . "\n" . $submission->submissioncomment;
                                    break;
                            }
                            break;
                        case "2":
                            $msg .= get_string("inprocess", "problemstatement");
                            break;
                    }
                    echo "<div style='text-align:left'>" . nl2br($msg) . "</div>";
                    //echo format_text($submission->programtext, 0);//$submission->data2);
                } else {
                    if (!has_capability('mod/problemstatement:submit', $context)) {
                        //fix for #4604
                        echo '<div style="text-align:center">' . get_string('guestnosubmit', 'problemstatement') . '</div>';
                    } else {
                        if ($this->isopen()) {
                            //fix for #4206
                            echo '<div style="text-align:center">' . get_string('emptysubmission', 'problemstatement') . '</div>';
                        }
                    }
                }
            }
            print_box_end();
            if (!$editmode && $editable) {
                echo "<div style='text-align:center'>";
                print_single_button('view.php', array('id' => $this->cm->id, 'edit' => '1'), get_string('editmysubmission', 'problemstatement'));
                echo "</div>";
            }
        }
        $this->view_feedback();
        $this->view_footer();
        //echo "end of view";
    }
Beispiel #3
0
}
require_login($course->id, false, $cm);
if ($USER->id != $user->id && !has_capability('mod/problemstatement:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
    error("You can not view this problemstatement");
}
$problemstatementinstance = new problemstatement($cm->id, $problemstatement, $cm, $course);
if ($submission = $problemstatementinstance->get_submission($user->id)) {
    print_header(fullname($user, true) . ': ' . $problemstatement->name);
    print_simple_box_start('center', '', '', '', 'generalbox', 'dates');
    echo '<table>';
    if ($problemstatement->timedue) {
        echo '<tr><td class="c0">' . get_string('duedate', 'problemstatement') . ':</td>';
        echo '    <td class="c1">' . userdate($problemstatement->timedue) . '</td></tr>';
    }
    echo '<tr><td class="c0">' . get_string('lastedited') . ':</td>';
    echo '    <td class="c1">' . userdate($submission->timemodified);
    /// Decide what to count
    //if ($CFG->problemstatement_itemstocount == ASSIGNMENT_COUNT_WORDS) {
    echo ' (' . get_string('numwords', '', count_words($submission->programtext)) . ')</td></tr>';
    //} else if ($CFG->problemstatement_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
    echo ' (' . get_string('numletters', '', count_letters($submission->programtext)) . ')</td></tr>';
    //}
    echo '</table>';
    print_simple_box_end();
    print_simple_box(highlight_syntax($submission->programtext, $submission->langid), 'center', '100%');
    print_simple_box(format_text($submission->submissioncomment, 0), 'center', '100%');
    close_window_button();
    print_footer('none');
} else {
    print_string('emptysubmission', 'problemstatement');
}