Example #1
0
function presentSource($sourcedata, $langid)
{
    $head = '<div class="tabbertab">' . '<h2 class="filename"><a id="source' . specialchars($sourcedata['rank']) . '"></a>' . specialchars($sourcedata['filename']) . "</h2> <a " . "href=\"show_source.php?id=" . urlencode($sourcedata['submitid']) . "&amp;fetch=" . urlencode($sourcedata['rank']) . "\"><img class=\"picto\" src=\"../images/b_save.png\" " . "alt=\"download\" title=\"download\" /></a> " . "<a href=\"edit_source.php?id=" . urlencode($sourcedata['submitid']) . "&amp;rank=" . urlencode($sourcedata['rank']) . "\">" . "<img class=\"picto\" src=\"../images/edit.png\" alt=\"edit\" title=\"edit\" />" . "</a>\n\n";
    $langid = langidToAce($langid);
    $ace = '<div class="editor" id="editor' . specialchars($sourcedata['rank']) . '">' . specialchars($sourcedata['sourcecode']) . '</div>' . '<script>' . 'var editor = ace.edit("editor' . specialchars($sourcedata['rank']) . '");' . 'editor.setTheme("ace/theme/eclipse");' . 'editor.setOptions({ maxLines: Infinity });' . 'editor.setReadOnly(true);' . 'editor.getSession().setMode("ace/mode/' . $langid . '");' . 'document.getElementById("editor' . specialchars($sourcedata['rank']) . '").editor = editor;' . '</script>';
    return $head . $ace . '</div>';
}
Example #2
0
}
$title = 'Edit Source: s' . $id;
require LIBWWWDIR . '/header.php';
echo '<h2><a id="source"></a>Edit submission ' . "<a href=\"submission.php?id={$id}\">s{$id}</a> source files</h2>\n\n";
echo addForm($pagename, 'post', null, 'multipart/form-data');
$sources = $DB->q('TABLE SELECT *
                   FROM submission_file
                   LEFT JOIN submission USING(submitid)
                   WHERE submitid = %i ORDER BY rank', $id);
echo '<script type="text/javascript" src="../js/tabber.js"></script>' . '<script src="../js/ace/ace.js" type="text/javascript" charset="utf-8"></script>' . '<div class="tabber">';
foreach ($sources as $sourcedata) {
    echo '<div class="tabbertab' . ($_GET['rank'] === $sourcedata['rank'] ? ' tabbertabdefault' : '') . '">';
    echo '<h2 class="filename">' . specialchars($sourcedata['filename']) . '</h2>';
    echo addTextArea('source' . $sourcedata['rank'], $sourcedata['sourcecode'], 120, 40) . "<br />\n";
    $editor = 'editor' . specialchars($sourcedata['rank']);
    $langid = langidToAce($submission['langid']);
    echo '<div class="editor" id="' . $editor . '"></div>';
    echo '<script>' . 'var textarea = document.getElementById("source' . specialchars($sourcedata['rank']) . '");' . 'textarea.style.display = \'none\';' . 'var ' . $editor . ' = ace.edit("' . $editor . '");' . $editor . '.setTheme("ace/theme/eclipse");' . $editor . '.getSession().setValue(textarea.value);' . $editor . '.getSession().on(\'change\', function(){' . 'var textarea = document.getElementById("source' . specialchars($sourcedata['rank']) . '");' . 'textarea.value = ' . $editor . '.getSession().getValue();' . '});' . $editor . '.setOptions({ maxLines: Infinity });' . $editor . '.setReadOnly(false);' . $editor . '.getSession().setMode("ace/mode/' . $langid . '");' . '</script>';
    echo "</div>\n";
}
echo "</div>\n";
$probs = $DB->q('KEYVALUETABLE SELECT probid, name FROM problem
                 INNER JOIN contestproblem USING (probid)
                 WHERE allow_submit = 1 AND cid = %i ORDER BY name', $submission['cid']);
$langs = $DB->q('KEYVALUETABLE SELECT langid, name FROM language
                 WHERE allow_submit = 1 ORDER BY name');
echo addSelect('probid', $probs, $submission['probid'], true);
echo addSelect('langid', $langs, $submission['langid'], true);
echo addHidden('teamid', $submission['teamid']);
echo addHidden('origsubmitid', $submission['origsubmitid'] === NULL ? $id : $submission['origsubmitid']);
echo addSubmit('submit');