function pyRecallHandler($options, $content)
{
    if (!array_key_exists('slug', $options)) {
        return "[pyRecall error: no slug given]";
    }
    global $wpdb;
    $problem = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "pb_problems WHERE slug = %s AND lang = %s", $options['slug'], 'en'), ARRAY_A);
    if ($problem == NULL) {
        return "[pyRecall error: slug " . $options['slug'] . " not found]";
    }
    if (trim($content) == "") {
        $content = $problem['content'];
    }
    $mergedOptions = json_decode($problem['shortcodeArgs'], TRUE);
    if (array_key_exists('translate', $options)) {
        $GLOBALS['pb_translation'] = $options['translate'];
        foreach ($mergedOptions as $key => $value) {
            $mergedOptions[$key] = translateOf($mergedOptions[$key], $options['translate']);
        }
    }
    foreach ($options as $o => $v) {
        $mergedOptions[$o] = $v;
    }
    $result = NULL;
    if ($problem['type'] == "code") {
        $result = pyBoxHandler($mergedOptions, $content);
    }
    if ($problem['type'] == "scramble") {
        $result = pyBoxHandler($mergedOptions, $content);
    }
    if ($problem['type'] == "short answer") {
        $result = pyShortHandler($mergedOptions, $content);
    }
    if ($problem['type'] == "multiple choice") {
        $result = pyMultiHandler($mergedOptions, $content);
    }
    if ($problem['type'] == "multichoice scramble") {
        $result = pyMultiScrambleHandler($mergedOptions, $content);
    }
    $GLOBALS['pb_translation'] = NULL;
    if ($result == NULL) {
        return "[pyRecall error: unknown type " . $problem['type'] . "]";
    }
    return $result;
}
function pbmailpage($options, $content)
{
    if (!is_user_logged_in()) {
        return __t("You must login to view the mail page.");
    }
    $v = validate();
    if ($v[0] != 'success') {
        return $v[1];
    }
    // error message
    extract($v[1]);
    // $student, $problem, $focus, $sid
    $name = nicefiedUsername($sid, FALSE);
    $r = '';
    global $wpdb;
    $students = getStudents();
    $cstudents = count($students);
    $r .= reselector($students, $cstudents);
    $r .= '<hr style="width:80%;align:center;">';
    if ($problem !== NULL) {
        $finished = $wpdb->get_var($wpdb->prepare("SELECT time FROM " . $wpdb->prefix . "pb_completed WHERE userid = %d AND problem = %s", $sid, $problem['slug']));
        $r .= '<div class="history-note">' . sprintf(__t('Mail about %1$s [%3$s] for %2$s'), $problem['publicname'], userString($sid), '<a href="' . $problem['url'] . '">' . __t('link to original page') . '</a>');
        $r .= '</div>';
        if ($finished !== NULL) {
            $r .= "<img title='" . $student->user_login . __t(" has completed this problem.") . "' src='" . UFILES . "checked.png' class='pycheck'/>";
        } else {
            $r .= "<img title='" . $student->user_login . __t(" has not completed this problem.") . "' src='" . UFILES . "icon.png' class='pycheck'/>";
        }
        if ($finished !== NULL) {
            $r .= "<div class='history-prenote'>" . sprintf(__t('Note: this student completed the problem at %s'), $finished) . "</div>";
        }
        $r .= '<i>' . __t('Click on a message title to toggle the message open or closed.') . '</i>';
        global $mailcond;
        $messages = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "pb_mail WHERE ustudent = %d AND problem = %s AND {$mailcond} ORDER BY ID desc", $sid, $problem['slug']), ARRAY_A);
        foreach ($messages as $i => $message) {
            $c = $message['ID'] == $focus ? " showing" : " hiding";
            $idp = $message['ID'] == $focus ? " id='m' " : '';
            $r .= "<div {$idp} class='collapseContain{$c}' style='border-radius: 5px;'>";
            $title = __t("From") . " " . nicefiedUsername($message['ufrom'], FALSE) . ' ' . __t('to') . ' ' . nicefiedUsername($message['uto'], FALSE) . ', ' . $message['time'];
            if (count($messages) > 1 && $i == 0) {
                $title .= " " . __t("(newest)");
            }
            if (count($messages) > 1 && $i == count($messages) - 1) {
                $title .= " " . __t("(oldest)");
            }
            $r .= "<div class='collapseHead'><span class='icon'></span>{$title}</div>";
            $r .= "<div class='collapseBody'><span class='quoth'>" . __t("Quote/<br/>Reply") . "</span>" . preBox($message['body'], -1, 10000, "font-size:12px; line-height:14px; white-space: pre-wrap;") . '</div>';
            $r .= '</div>';
        }
        $to = "";
        if (getUserID() == $sid) {
            $guru_login = get_the_author_meta('pbguru', get_current_user_id());
            $guru = get_user_by('login', $guru_login);
            // FALSE if does not exist
            $to .= '<div style="text-align: center">';
            $to .= __t('Send a question by e-mail to: ');
            if ($guru !== FALSE) {
                $to .= "<select class='recipient'>\n<option value='1'>" . __t("My guru") . " ({$guru_login})</option>\n<option value='-1'>" . __t("CS Circles Assistant") . "</option>\n</select></div>";
            } else {
                $to .= "<select class='recipient'>\n<option value='-1'>" . __t("CS Circles Assistant") . "</option>\n<option value='0'>" . __t("(No guru is specified)") . "</option>\n</select>";
                $to .= '<br/></div>';
            }
        }
        $r .= '<div class="pybox fixsresize mailform" id="mailform">
<div id="bodyarea" class="pyboxTextwrap">
<textarea name="body" class="resizy" placeholder="' . __t('Type here to send a reply about this problem') . '" style="width:100%; white-space: pre-wrap; font-size: 11px; line-height:13px" rows=12></textarea>
</div>
' . $to;
        if (getUserID() != $sid) {
            $r .= '<input style="position:relative; top:2px" type="checkbox" id="noreply" onclick="toggleVisibility(\'bodyarea\')">' . ' <label style="font-size:75%" for="noreply">' . __t('Just mark as read without replying') . '</label><br>';
        }
        $r .= '<button onclick="mailReply(' . $sid . ',\'' . $problem['slug'] . '\');">' . __t('Send this message!') . '</button>
</div>';
        $problemname = $problem['publicname'];
        $r .= '<hr style="width:80%;align:center;">';
        if (getUserID() != $sid) {
            $r .= "<div class='history-note'><a href='" . cscurl('progress') . '?user='******'>" . sprintf(__t("%s's progress page (new window)"), $name) . "</a></div>";
        }
        $r .= "\n<div class='collapseContain hiding'>\n<div class='collapseHead'><span class='icon'></span>" . __t("Problem description for") . " " . $problem['publicname'] . "</div>\n<div class='collapseBody'>" . apply_filters('the_content', pyBoxHandler(json_decode($problem['shortcodeArgs'], TRUE), $problem['content'])) . "</div>\n</div>";
        if (getUserID() != $sid) {
            $r .= niceFlex('us', sprintf(__t('%1$s\'s submissions for %2$s'), $name, $problemname), 'problem-history', 'dbProblemHistory', array('user' => $sid, 'p' => $problem['slug']));
        }
        $r .= niceFlex('ms', sprintf(__t("My previous submissions for %s"), $problemname), 'problem-history', 'dbProblemHistory', array('p' => $problem['slug']));
        if (getUserID() != $sid) {
            $r .= niceFlex('omp', sprintf(__t("My other messages about %s"), $problemname), 'mail', 'dbMail', array('what' => $problem['slug'], 'xwho' => $sid));
        }
        $r .= niceFlex('oms', getUserID() == $sid ? __t("My messages for other programs") : sprintf(__t("Messages to/from %s for other problems"), $name), 'mail', 'dbMail', array('who' => $sid, 'xwhat' => $problem['slug']));
    }
    if ($cstudents > 0 || userIsAssistant()) {
        $r .= niceFlex('allstu', sprintf(__t("All messages ever about %s's work"), $name), 'mail', 'dbMail', array('who' => $sid));
    }
    $r .= niceFlex('allme', __t("All messages ever to or from me"), 'mail', 'dbMail', array());
    return $r;
}
<?php

header("Content-Type: text/plain");
require_once "include-to-load-wp.php";
global $pyRenderCount;
$pyRenderCount = rand(1000, 9999);
echo pyBoxHandler(json_decode('{"showonly":"output","grader":"*nograder*","console":"Y","slug":"console","title":"Console","showeditortoggle":"Y","allowinput":"Y"}', TRUE), "An altenative console.");
// end of file!