function test_auto_marking_sc($request) { Authenticator::assert_manager_or_professor($request->cookies['authToken']); $msg = new Messages($GLOBALS['locale'], '/new-question/errors'); try { $model = new Model(); $raw_input = $request->getBody(); $content_type = explode(';', $request->type)[0]; if ($content_type !== 'application/json') { Util::output_errors_and_die($msg->_('invalid-format'), 415); } $input_data = json_decode($raw_input, true); if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['source-code']) || !is_string($input_data['source-code'])) { Util::output_errors_and_die($msg->_('invalid-format'), 400); } $extra = !empty($input_data['extra']) ? $input_data['extra'] : []; $qd = $input_data['question']; set_empty_if_undefined($qd['type']); if ($qd['type'] != 'source-code') { Util::output_errors_and_die('', 400); } $q = new QuestionSC($qd, Question::FROM_USER, $extra); $q->mark_automatically(array('source-code' => $input_data['source-code']), $log, $result); http_response_code(200); header('Content-Type: application/json'); echo my_json_encode($result); } catch (DatabaseException $e) { Util::output_errors_and_die($e->getMessage(), 503); } catch (Exception $e) { Util::output_errors_and_die($e->getMessage(), 400); } }
function test_auto_marking($request) { Authenticator::assert_manager_or_professor($request->cookies['authToken']); $msg = new Messages($GLOBALS['locale'], '/new-question/errors'); try { $model = new Model(); $raw_input = $request->getBody(); $content_type = explode(';', $request->type)[0]; if ($content_type !== 'application/json') { Util::output_errors_and_die($msg->_('invalid-format'), 415); } $input_data = json_decode($raw_input, true); if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['studentAnswer'])) { Util::output_errors_and_die($msg->_('invalid-format'), 400); } $extra = !empty($input_data['extra']) ? $input_data['extra'] : []; $qd = $input_data['question']; set_empty_if_undefined($qd['type']); if (!Validator::validate_question_type($qd['type'])) { Util::output_errors_and_die($msg->_('invalid-type'), 400); } switch ($qd['type']) { case 'short-answer': $q = new QuestionSA($qd, Question::FROM_USER, $extra); break; case 'essay': $q = new QuestionES($qd, Question::FROM_USER, $extra); break; case 'multiple-choice': $q = new QuestionMC($qd, Question::FROM_USER, $extra); break; case 'matching': $q = new QuestionMA($qd, Question::FROM_USER, $extra); break; case 'fitb-type': $q = new QuestionFT($qd, Question::FROM_USER, $extra); break; case 'fitb-select': $q = new QuestionFS($qd, Question::FROM_USER, $extra); break; case 'source-code': $q = new QuestionSC($qd, Question::FROM_USER, $extra); break; } http_response_code(200); header('Content-Type: application/json'); $mark = $q->mark_automatically($input_data['studentAnswer'], $log); foreach ($log as $i => $line) { $log[$i] = $msg->_('/auto-marking/' . $line[0], $line[1]); } $log = implode('<br/>', $log); echo my_json_encode(array('log' => $log, 'mark' => $mark)); } catch (DatabaseException $e) { Util::output_errors_and_die($e->getMessage(), 503); } catch (Exception $e) { Util::output_errors_and_die($e->getMessage(), 400); } }
function create_session($request) { $raw_input = $request->getBody(); $content_type = explode(';', $request->type)[0]; switch ($content_type) { case 'application/json': $input_data = json_decode($raw_input, true); break; case 'application/x-www-form-urlencoded': $input_data = array(); parse_str($raw_input, $input_data); break; default: Util::output_errors_and_die('', 415); } if ($input_data === null) { Util::output_errors_and_die('', 400); } set_empty_if_undefined($input_data['username_or_email']); set_empty_if_undefined($input_data['password']); $msg = new Messages($GLOBALS['locale'], '/signin'); try { $model = new Model(); $user_data = $model->is_valid_user($input_data['username_or_email'], $input_data['password']); if (!$user_data) { Util::output_errors_and_die($msg->_('invalid-username-pw'), 403); } switch ($user_data['status']) { case 'pending-activation': Util::output_errors_and_die($msg->_('pending-activation'), 403); break; case 'pending-approval': Util::output_errors_and_die($msg->_('pending-approval'), 403); break; case 'banned': Util::output_errors_and_die($msg->_('banned'), 403); break; case 'active': $token = generate_token($user_data); $now = new DateTime('now'); $expires_at = clone $now; $expires_at->add(new DateInterval('P7D')); $model->insert_auth_token($user_data['user_id'], $token, $now, $expires_at); http_response_code(201); $output = array('token' => $token, 'expires_at' => $expires_at->format('Y-m-d H:i:s')); setcookie('authToken', $token, $expires_at->getTimestamp(), '/', '', $secure = true, $httponly = true); header('Content-Type: application/json'); echo my_json_encode($output); die; break; } } catch (DatabaseException $e) { Util::output_errors_and_die($e->getMessage(), 503); } catch (Exception $e) { Util::output_errors_and_die($e->getMessage(), 400); } }
function test_question($request) { Authenticator::assert_manager_or_professor($request->cookies['authToken']); $msg = new Messages($GLOBALS['locale'], '/new-question/errors'); try { $model = new Model(); $raw_input = $request->getBody(); $content_type = explode(';', $request->type)[0]; if ($content_type !== 'application/json') { Util::output_errors_and_die($msg->_('invalid-format'), 415); } $input_data = json_decode($raw_input, true); if (empty($input_data)) { Util::output_errors_and_die($msg->_('invalid-format'), 400); } set_empty_if_undefined($input_data['type']); if (!Validator::validate_question_type($input_data['type'])) { Util::output_errors_and_die($msg->_('invalid-type'), 400); } switch ($input_data['type']) { case 'short-answer': $q = new QuestionSA($input_data, Question::FROM_USER); break; case 'essay': $q = new QuestionES($input_data, Question::FROM_USER); break; case 'multiple-choice': $q = new QuestionMC($input_data, Question::FROM_USER); break; case 'matching': $q = new QuestionMA($input_data, Question::FROM_USER); break; case 'fitb-type': $q = new QuestionFT($input_data, Question::FROM_USER); break; case 'fitb-select': $q = new QuestionFS($input_data, Question::FROM_USER); break; case 'source-code': $q = new QuestionSC($input_data, Question::FROM_USER); break; } http_response_code(200); header('Content-Type: application/json'); echo my_json_encode($q->to_auto_marking_test(true, true)); } catch (DatabaseException $e) { Util::output_errors_and_die($e->getMessage(), 503); } catch (Exception $e) { Util::output_errors_and_die($e->getMessage(), 400); } }
public static function assert_manager($token) { $user_data = self::assert_user($token); if ($user_data['role'] !== 'manager') { $msg = new Messages($GLOBALS['locale']); Util::output_errors_and_die($msg->_('/authentication/only-managers'), 403); } return $user_data; }
public function __construct($message = null, $code = 0) { if ($message) { $msg = new Messages($GLOBALS['locale']); $err = array('DATABASE-ERROR' => $msg->_('/showmsg/database-error')); // discard original message $message = my_json_encode($err); } parent::__construct($message, $code); }
function create_question($request, $assignment_id = null) { Authenticator::assert_manager_or_professor($request->cookies['authToken']); $msg = new Messages($GLOBALS['locale']); try { $model = new Model(); $raw_input = $request->getBody(); $content_type = explode(';', $request->type)[0]; if ($content_type !== 'application/json') { Util::output_errors_and_die('', 415); } $input_data = json_decode($raw_input, true); if (empty($input_data)) { Util::output_errors_and_die('', 400); } set_empty_if_undefined($input_data['type']); if (!Validator::validate_question_type($input_data['type'])) { Util::output_errors_and_die($msg->_('invalid-type'), 400); } switch ($input_data['type']) { case 'short-answer': $q = new QuestionSA($input_data, Question::FROM_USER); break; case 'essay': $q = new QuestionES($input_data, Question::FROM_USER); break; case 'multiple-choice': $q = new QuestionMC($input_data, Question::FROM_USER); break; case 'matching': $q = new QuestionMA($input_data, Question::FROM_USER); break; case 'fitb-type': $q = new QuestionFT($input_data, Question::FROM_USER); break; case 'fitb-select': $q = new QuestionFS($input_data, Question::FROM_USER); break; case 'source-code': $q = new QuestionSC($input_data, Question::FROM_USER); break; } $qid = $model->create_question($q); header('Content-Type: text/plain'); echo '/question_bank/questions/' . $qid; http_response_code(201); die; } catch (ConflictException $e) { Util::output_errors_and_die($e->getMessage(), 409); } catch (DatabaseException $e) { Util::output_errors_and_die($e->getMessage(), 503); } catch (Exception $e) { Util::output_errors_and_die($e->getMessage(), 400); } }
htmlout($GLOBALS['system-name']); ?> </h1> </div> <?php $msg = new Messages($GLOBALS['locale'], 'signin'); include 'login-form.html.php'; ?> <div class="container"> <form action="signup" method="post"> <div class="form-group centre"> <input type="submit" class="btn btn-primary" value="<?php htmlout($msg->_('new-user')); ?> " /> <input type="hidden" name="action" value="newuser"/> </div> </form> <form action="forgotpw" method="get"> <div class="form-group centre"> <input type="submit" class="btn btn-secondary" value="<?php htmlout($msg->_('forgot-password')); ?>
<?php $msg = new Messages($GLOBALS['locale']); Authenticator::assert_manager($_COOKIE['authToken']); try { $model = new Model(); $q = array('fields' => 'username,email,full_name,role,created_at', 'status' => 'pending-approval'); $pending_users = $model->get_users($q); } catch (DatabaseException $e) { Util::output_errors_and_die($msg->_('/showmsg/database-error'), 503); } include 'page.html.php';
<?php $msg = new Messages($GLOBALS['locale'], '/question-student'); ?> <div class="qSt-fs-field-container hidden-template"></div> <div class="qSt-fs-answers-container"> <div> <label> <?php htmlout($msg->_('/question-student/fs-choose')); ?> </label> <div class="help-block qSt-fs-dummy-help" style="display: none"> <?php htmlout($msg->_('/question-student/fs-dummy')); ?> </div> </div> <div class="qSt-fs-field hidden-template"> <span class="qSt-fs-answer-text"> </span> <span class="qSt-fs-answer-remove" title="<?php htmlout($msg->_('/question-student/fs-remove')); ?> " >
<?php $msg = new Messages($GLOBALS['locale'], '/question-student'); ?> <div class="form-group"> <label> <?php htmlout($msg->_('sa-answer')); ?> </label> <input type="text" class="form-control qSt-sa-answer" maxlength="1048576" /> </div>
<?php $msg = new Messages($GLOBALS['locale']); $db_created = file_exists(get_config_dir() . '/dbsettings.ini'); try { $model = new Model($first_run = !$db_created); } catch (DatabaseException $e) { exit_with_message($msg->_('/showmsg/database-error')); die; } $has_manager = ($db_created and $model->has_manager()); if (!$has_manager) { header('Location: firstrun'); die; } if (isset($_COOKIE['authToken'])) { $user_data = $model->is_valid_auth_token($_COOKIE['authToken']); if ($user_data) { include 'home.html.php'; die; } } // not logged in include 'login.html.php';
<!DOCTYPE html> <?php $msg = new Messages($GLOBALS['locale'], 'signup'); ?> <html lang="<?php htmlout($msg->get_short_language_code()); ?> "> <head> <meta charset="utf-8"> <title><?php htmlout($msg->_('signup')); ?> </title> <?php include_headers(); ?> <link href="/static/css/main.css" rel="stylesheet" /> <link href="/static/css/signup.css" rel="stylesheet" /> </head> <body> <div class="container"> <p class="text-center"> <?php htmlout($msg->_('pleasefillform')); ?> </p> <p class="text-center"> <?php htmlout($msg->_('asterisk-required'));
<!DOCTYPE html> <?php $msg = new Messages($GLOBALS['locale'], 'home'); $user_data; $role = $user_data['role']; $show_courses = true; $show_question_bank = ($role === 'professor' or $role === 'manager'); $show_users = $role === 'manager'; $show_programming_languages = ($role === 'professor' or $role === 'manager'); $msg = new Messages($GLOBALS['locale'], 'home'); $greeting = $msg->_('greetings/hello'); ?> <html lang="<?php htmlout($msg->get_short_language_code()); ?> "> <head> <meta charset="utf-8"> <title><?php htmlout($GLOBALS['system-name']); ?> </title> <?php include_headers(); ?> <link rel="stylesheet" type="text/css" href="/static/css/main.css" /> <link rel="stylesheet" type="text/css" href="/static/css/navbar.css" /> <?php echo '<script> var acceptLanguages = ' . json_encode(accept_languages()); echo '; </script>'; ?>
<?php $msg = new Messages($GLOBALS['locale']); ?> <div class="qSt-container"> <div class="qSt-title-wrapper"> <h3 class="qSt-title"> </h3> <span class="label label-primary qSt-level" data-msg-easy = "<?php htmlout($msg->_('/levels/easy')); ?> " data-msg-intermediate = "<?php htmlout($msg->_('/levels/intermediate')); ?> " data-msg-hard = "<?php htmlout($msg->_('/levels/hard')); ?> " data-msg-very-hard = "<?php htmlout($msg->_('/levels/very-hard')); ?> " > </span> <span class="label label-default qSt-pl">
<?php $msg = new Messages($GLOBALS['locale'], 'signin'); ?> <div class="container"> <form class="not-wide" action="#" id="signin-form" method="post" onsubmit="submitSignIn(); return false;"> <div class="form-group"> <label for="username_or_email"> <?php htmlout($msg->_('username-or-email')); ?> </label> <input type="text" id="username_or_email" name="username_or_email" required class="form-control" value="<?php isset($GLOBALS['username']) && htmlout($GLOBALS['username']); ?> " /> </div> <div class="form-group"> <label for="password"> <?php htmlout($msg->_('password')); ?> </label> <input type="password" class="form-control" id="password" name="password" required value="" />
<?php $msg = new Messages($GLOBALS['locale'], '/question-student'); ?> <div> <label class="qSt-ma-help" data-left="<?php htmlout($msg->_('ma-reorder-left')); ?> " data-right="<?php htmlout($msg->_('ma-reorder-right')); ?> " data-both="<?php htmlout($msg->_('ma-reorder-both')); ?> " > </label> </div> <div class="qSt-ma-columns-container container"> <div class="qSt-ma-column-left col-xs-6 col-lg-6"> <div class="qSt-ma-item hidden-template"> <span class="qSt-ma-item-text"> </span> </div>
<!DOCTYPE html> <?php $msg = new Messages($GLOBALS['locale'], 'signup/confirmation-ui'); ?> <html lang="<?php htmlout($msg->get_short_language_code()); ?> "> <head> <meta charset="utf-8"> <title><?php htmlout($msg->_('confirmation')); ?> </title> <?php include_headers(); ?> <link href="/static/css/main.css" rel="stylesheet" /> <link href="/static/css/signup.css" type="text/css" rel="stylesheet"> </head> <body> <div class="container text-center" id="confirm-container"> <p> <?php htmlout($msg->_('please-wait')); ?> </p>
if (req_data('POST', 'action') === 'addfirstmanager') { $manager_data = array(); foreach ($fields as $f => $v) { $manager_data[$f] = $fields[$f] = trim(req_data('POST', $f)); } // password: do not trim $manager_data['password'] = req_data('POST', 'password'); $manager_data['password2'] = req_data('POST', 'password2'); try { $model->add_first_manager($manager_data); } catch (Exception $e) { $GLOBALS['newmanagererror'] = $e->getMessage(); include 'newmanager.html.php'; exit; } exit_with_message($msg->_('first-manager-created')); } else { include 'newmanager.html.php'; } } else { // database hasn't been created yet $fields = array('root_username' => '', 'db_name' => '', 'db_username' => ''); if (req_data('POST', 'action') === 'setupdb') { $model = new Model($first_run = true); $GLOBALS['dbsetuperror'] = ''; $db_data = array(); foreach ($fields as $f => $v) { $db_data[$f] = $fields[$f] = trim(req_data('POST', $f)); } $db_data['db_password'] = req_data('POST', 'db_password'); $db_data['root_password'] = req_data('POST', 'root_password');
<?php $msg = new Messages($GLOBALS['locale'], '/question-student'); ?> <div class="form-group"> <label> <?php htmlout($msg->_('es-answer')); ?> </label> <textarea class="form-control qSt-es-answer" cols="85" rows="10" maxlength="1048576" ></textarea> </div>
public static function loadRichTextEditorJS($locales) { $msg = new Messages($GLOBALS['locale']); // try to find a desired language $lang = null; if ($locales[0] != 'en-US') { // TinyMCE locale defaults to en-US $dir = '/static/js/TinyMCE/lang/'; foreach ($locales as $l) { $l = str_replace('-', '_', $l); $underscore = strpos($l, '_'); if ($underscore !== false) { $l = substr($l, 0, $underscore) . strtoupper(substr($l, $underscore)); } if (file_exists("{$dir}{$l}.js")) { $lang = $l; break; } } } ?> <script src='//cdn.tinymce.com/4/tinymce.min.js'> </script> <?php echo '<script>'; echo "var tinymceLanguageURL = "; if ($lang) { echo "'/static/js/TinyMCE/lang/{$lang}.js'"; } else { echo 'false'; } echo '; </script>'; ?> <script> "use strict"; /* global tinymce, $, tinymceLanguageURL*/ function loadRichTextEditorJS(selector) { tinymce.PluginManager.add('codetag', function(ed, url) { ed.addButton("codetag", { tooltip: "<?php htmlout($msg->_('/etc/code')); ?> ", text: "{ ... }", onClick: function() { ed.execCommand('mceToggleFormat', false, 'code'); }, }) }); var options = { 'selector': selector, 'plugins': 'link paste code codetag', 'toolbar': 'fontsizeselect | ' + 'bold italic underline | link | strikethrough | ' + 'codetag | ' + 'bullist numlist | code' , 'menubar': false, 'statusbar': false, 'setup' : function(ed) { ed.on('init', function() { var doc = this.getDoc(); doc.body.style.fontSize = '14px'; doc.body.style.fontFamily = $('body').css('font-family'); }); ed.pasteAsPlainText = true; }, 'valid_elements': 'a[!href|target|title],strong/b,em/i,ul,ol,li,' + 'br,-code,' + 'span[style]', 'valid_styles': 'font-size, text-decoration', 'forced_root_block': false, 'preformatted': true, 'content_css': '//fonts.googleapis.com/css?family=PT+Sans' }; if (tinymceLanguageURL) { options['language_url'] = tinymceLanguageURL; } tinymce.EditorManager.editors = []; tinymce.init(options); $('body > .mce-widget').remove(); return tinymce.activeEditor; } </script> <?php }
<title><?php echo $GLOBALS['system-name']; ?> </title> <?php include_headers(); ?> <link href="/static/css/main.css" rel="stylesheet" /> </head> <body> <div class="container text-center"> <p> <?php if (isset($message)) { echo $message; } ?> </p> <form action="/" method="get"> <input type="submit" class="btn btn-link" value="<?php htmlout($msg->_('showmsg/go-to-homepage')); ?> " /> </form> </div> </body> </html>