Example #1
0
function folder_update($fid, $folder_data)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($fid)) {
        return false;
    }
    if (!is_array($folder_data)) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    $folder_data = array_merge(folder_get($fid), $folder_data);
    foreach ($folder_data as $key => $value) {
        if (!is_numeric($value)) {
            $folder_data[$key] = $db->escape($value);
        }
    }
    if (!isset($folder_data['TITLE'])) {
        return false;
    }
    if (!isset($folder_data['DESCRIPTION'])) {
        $folder_data['DESCRIPTION'] = '';
    }
    if (!isset($folder_data['PREFIX'])) {
        $folder_data['PREFIX'] = '';
    }
    if (!isset($folder_data['POSITION']) || !is_numeric($folder_data['POSITION'])) {
        $folder_data['POSITION'] = 0;
    }
    if (!isset($folder_data['ALLOWED_TYPES']) || !is_numeric($folder_data['ALLOWED_TYPES'])) {
        $folder_data['ALLOWED_TYPES'] = 3;
    }
    $sql = "UPDATE LOW_PRIORITY `{$table_prefix}FOLDER` SET TITLE = '{$folder_data['TITLE']}', ";
    $sql .= "DESCRIPTION = '{$folder_data['DESCRIPTION']}', MODIFIED = NOW(), ALLOWED_TYPES = '{$folder_data['ALLOWED_TYPES']}', ";
    $sql .= "POSITION = '{$folder_data['POSITION']}', PREFIX = '{$folder_data['PREFIX']}', ";
    $sql .= "PERM = '{$folder_data['PERM']}' WHERE FID = '{$fid}'";
    if (!$db->query($sql)) {
        return false;
    }
    return true;
}
Example #2
0
    $page = $_GET['page'] > 0 ? $_GET['page'] : 1;
} else {
    if (isset($_POST['page']) && is_numeric($_POST['page'])) {
        $page = $_POST['page'] > 0 ? $_POST['page'] : 1;
    } else {
        $page = 1;
    }
}
// Array to hold error messages
$error_msg_array = array();
// Delete folders.
if (isset($_POST['delete'])) {
    $valid = true;
    if (isset($_POST['t_delete']) && is_array($_POST['t_delete'])) {
        foreach ($_POST['t_delete'] as $fid => $delete_folder) {
            if ($valid && $delete_folder == "Y" && ($folder_data = folder_get($fid))) {
                if ($folder_data['THREAD_COUNT'] < 1) {
                    if (folder_delete($fid)) {
                        admin_add_log_entry(DELETE_FOLDER, array($folder_data['TITLE']));
                    } else {
                        $error_msg_array[] = gettext("Failed to delete folder.");
                        $valid = false;
                    }
                } else {
                    $error_msg_array[] = gettext("Cannot delete folders that still contain threads.");
                    $valid = false;
                }
            }
        }
        if ($valid) {
            header_redirect("admin_folders.php?webtag={$webtag}&page={$page}&deleted=true");
Example #3
0
// default to display most recent discussion for user
if (isset($_GET['msg']) && validate_msg($_GET['msg'])) {
    $msg = $_GET['msg'];
    list($tid, $pid) = explode('.', $msg);
} else {
    if (isset($_GET['print_msg']) && validate_msg($_GET['print_msg'])) {
        $msg = $_GET['print_msg'];
        list($tid, $pid) = explode('.', $msg);
    } else {
        html_draw_error(gettext("Invalid Message ID or no Message ID specified."));
    }
}
if (!($thread_data = thread_get($tid, session::check_perm(USER_PERM_ADMIN_TOOLS, 0)))) {
    html_draw_error(gettext("The requested thread could not be found or access was denied."));
}
if (!($folder_data = folder_get($thread_data['FID']))) {
    html_draw_error(gettext("The requested folder could not be found or access was denied."));
}
if (!($message = messages_get($tid, $pid, 1))) {
    html_draw_error(gettext("That post does not exist in this thread!"));
}
html_draw_top("title={$thread_data['TITLE']}", "post.js", "basetarget=_blank", 'class=window_title');
if (isset($thread_data['STICKY']) && isset($thread_data['STICKY_UNTIL'])) {
    if ($thread_data['STICKY'] == "Y" && $thread_data['STICKY_UNTIL'] != 0 && time() > $thread_data['STICKY_UNTIL']) {
        thread_set_sticky($tid, false);
        $thread_data['STICKY'] = "N";
    }
}
$show_sigs = session::get_value('VIEW_SIGS') == 'N' ? false : true;
echo "<div align=\"center\">\n";
echo "<table width=\"96%\" border=\"0\">\n";
Example #4
0
function light_draw_messages($tid, $pid)
{
    $webtag = get_webtag();
    if (!($thread_data = thread_get($tid, session::check_perm(USER_PERM_ADMIN_TOOLS, 0)))) {
        light_html_display_error_msg(gettext("The requested thread could not be found or access was denied."));
        return;
    }
    if (!folder_get($thread_data['FID'])) {
        light_html_display_error_msg(gettext("The requested folder could not be found or access was denied."));
        return;
    }
    if (!($messages = messages_get($tid, $pid, 10))) {
        light_html_display_error_msg(gettext("That post does not exist in this thread!"));
        return;
    }
    $msg_count = count($messages);
    light_messages_top($tid, $pid, $thread_data['TITLE'], $thread_data['INTEREST'], $thread_data['STICKY'], $thread_data['CLOSED'], $thread_data['ADMIN_LOCK'], $thread_data['DELETED'] == 'Y');
    if ($tracking_data_array = thread_get_tracking_data($tid)) {
        foreach ($tracking_data_array as $tracking_data) {
            if ($tracking_data['TRACK_TYPE'] == THREAD_TYPE_MERGE) {
                // Thread merged
                if ($tracking_data['TID'] == $tid) {
                    $thread_link = "<a href=\"lmessages.php?webtag={$webtag}&amp;msg=%s.1\" target=\"_self\">%s</a>";
                    $thread_link = sprintf($thread_link, $tracking_data['NEW_TID'], gettext("here"));
                    light_html_display_warning_msg(sprintf(gettext("<b>Threads Merged:</b> This thread has moved %s"), $thread_link));
                }
                if ($tracking_data['NEW_TID'] == $tid) {
                    $thread_link = "<a href=\"lmessages.php?webtag={$webtag}&amp;msg=%s.1\" target=\"_self\">%s</a>";
                    $thread_link = sprintf($thread_link, $tracking_data['TID'], gettext("here"));
                    light_html_display_warning_msg(sprintf(gettext("<b>Threads Merged:</b> This thread was merged from %s"), $thread_link));
                }
            } else {
                if ($tracking_data['TRACK_TYPE'] == THREAD_TYPE_SPLIT) {
                    // Thread Split
                    if ($tracking_data['TID'] == $tid) {
                        $thread_link = "<a href=\"lmessages.php?webtag={$webtag}&amp;msg=%s.1\" target=\"_self\">%s</a>";
                        $thread_link = sprintf($thread_link, $tracking_data['NEW_TID'], gettext("here"));
                        light_html_display_warning_msg(sprintf(gettext("<b>Thread Split:</b> Some posts in this thread have been moved %s"), $thread_link));
                    }
                    if ($tracking_data['NEW_TID'] == $tid) {
                        $thread_link = "<a href=\"lmessages.php?webtag={$webtag}&amp;msg=%s.1\" target=\"_self\">%s</a>";
                        $thread_link = sprintf($thread_link, $tracking_data['TID'], gettext("here"));
                        light_html_display_warning_msg(sprintf(gettext("<b>Thread Split:</b> Some posts in this thread were moved from %s"), $thread_link));
                    }
                }
            }
        }
    }
    if ($msg_count > 0) {
        foreach ($messages as $message_number => $message) {
            if (isset($message['RELATIONSHIP'])) {
                if ($message['RELATIONSHIP'] >= 0) {
                    // if we're not ignoring this user
                    $message['CONTENT'] = message_get_content($tid, $message['PID']);
                } else {
                    $message['CONTENT'] = gettext("Ignored");
                    // must be set to something or will show as deleted
                }
            } else {
                $message['CONTENT'] = message_get_content($tid, $message['PID']);
            }
            if ($thread_data['POLL_FLAG'] == 'Y') {
                if ($message['PID'] == 1) {
                    light_poll_display($tid, $thread_data['LENGTH'], $thread_data['FID'], true, $thread_data['CLOSED'], false, false);
                    $last_pid = $message['PID'];
                } else {
                    light_message_display($tid, $message, $thread_data['LENGTH'], $pid, $thread_data['FID'], true, $thread_data['CLOSED'], true, true, false);
                    $last_pid = $message['PID'];
                }
            } else {
                light_message_display($tid, $message, $thread_data['LENGTH'], $pid, $thread_data['FID'], true, $thread_data['CLOSED'], true, false, false);
                $last_pid = $message['PID'];
            }
            if (adsense_check_user() && adsense_check_page($message_number, 10, $thread_data['LENGTH'])) {
                adsense_output_html();
            }
        }
    }
    unset($messages, $message);
    echo "<div class=\"message_page_footer\">\n";
    echo "<ul>\n";
    if ($thread_data['CLOSED'] == 0 && session::check_perm(USER_PERM_POST_CREATE, $thread_data['FID']) || session::check_perm(USER_PERM_FOLDER_MODERATE, $thread_data['FID'])) {
        echo "<li><a href=\"lpost.php?webtag={$webtag}&amp;replyto={$tid}.0\" class=\"reply_all\">", gettext("Reply to All"), "</a></li>\n";
    }
    if ($last_pid < $thread_data['LENGTH']) {
        $npid = $last_pid + 1;
        echo "<li class=\"right_col\">", light_form_quick_button("lmessages.php", gettext("Keep reading&hellip;"), array('msg' => "{$tid}.{$npid}")), "</li>\n";
    }
    echo "</ul>\n";
    echo "</div>\n";
    echo "<a href=\"lthread_list.php?webtag={$webtag}\" class=\"thread_list_link\">", gettext("Back to thread list"), "</a>";
    light_messages_nav_strip($tid, $pid, $thread_data['LENGTH'], 10);
    if ($msg_count > 0 && session::logged_in()) {
        messages_update_read($tid, $last_pid, $thread_data['LAST_READ'], $thread_data['LENGTH'], $thread_data['MODIFIED']);
    }
}
function display_executionprotocol()
{
    global $admin, $fullresult, $extension;
    if ($_SESSION["status"] != "Admin") {
        $_SESSION["message"] = $currentmessage;
        $_SESSION["message"][] = "Access Denied : You need to be an Administrator to access that page.";
        echo "<script>window.location='?display=faq';</script>";
        return;
    }
    if (file_exists("env/lock.txt")) {
        echo "<center><h2>Execution Protocol</h2>Could not obtain a lock on Execution Protocol.<br><br><input type='button' id='gobackbutton' onClick='gobackin(0);'></center>";
        echo "<script>gobackin(5); function gobackin(sec){ document.getElementById(\"gobackbutton\").value=\"Going back in \"+sec+\" seconds ...\"; if(sec<=0) window.location = '?display=admincontest'; else window.setTimeout('gobackin('+(sec-1)+');',1000); }</script>";
        return;
    } else {
        file_set("env/lock.txt", "");
    }
    $admin["lastjudge"] = time();
    echo "<center><h2>Execution Protocol</h2></center>";
    echo "<table width=100%><tr><th>Run ID</th><th>Problem</th><th>Language</th><th>Team</th><th>File Name</th><th>Time</th><th>Result</th></tr>";
    $invalid = 0;
    if (!$invalid) {
        $temp = mysql_query("SELECT * FROM runs WHERE result is NULL ORDER BY rid ASC");
        if (!is_resource($temp) || mysql_num_rows($temp) == 0) {
            $invalid = 1;
        }
    }
    if (!$invalid) {
        $run = mysql_fetch_array($temp);
        $realname = $run["name"] . "." . $extension[$run["language"]];
        if ($run["language"] != "Java") {
            $run["name"] = "code";
        }
        mysql_query("UPDATE runs SET result='...' WHERE rid='{$run['rid']}'");
        $temp = mysql_query("SELECT * FROM problems WHERE pid='{$run['pid']}'");
        if (!is_resource($temp) || mysql_num_rows($temp) == 0) {
            $invalid = 1;
        }
    }
    if (!$invalid) {
        $problem = mysql_fetch_array($temp);
        $temp = mysql_query("SELECT * FROM teams WHERE tid='{$run['tid']}'");
        if (is_resource($temp) && mysql_num_rows($temp) > 0) {
            $temp = mysql_fetch_array($temp);
            $teamname = $temp["teamname"];
        } else {
            $teamname = "NA";
        }
        foreach (folder_get("env") as $file) {
            if ($file != "run.py" && $file != "lock.txt") {
                unlink("env/{$file}");
            }
        }
        if ($run["language"] == "PHP") {
            $prefix = "<?php ini_set('log_errors',1); ini_set('error_log','env/error.txt'); ?>";
        } else {
            $prefix = "";
        }
        file_set("env/{$run['name']}." . $extension[$run["language"]], $prefix . stripslashes($run["code"]));
        if ($run["language"] == "PHP") {
            $problem["timelimit"] += 5;
        }
        file_set("env/args.txt", "{$run['language']}\n{$run['name']}\n{$problem['timelimit']}\n");
        if ($run["language"] == "PHP") {
            $problem["timelimit"] -= 5;
        }
        file_set("env/input.txt", stripslashes($problem["input"]));
        echo "<!--";
        system("env\\run.py");
        echo "-->";
        $result = file_get("env/result.txt");
        if ($result == "CE") {
            $run["time"] = "-";
            $run["result"] = "CE";
        } else {
            if ($result == "TLE") {
                $run["time"] = "-";
                $run["result"] = "TLE";
            } else {
                if ($result != "-1") {
                    $run["time"] = $result . " s";
                    if (!file_exists("env/output.txt")) {
                        if ($run["language"] == "C" or $run["language"] == "C++") {
                            system("env\\{$run['name']}.exe <env\\input.txt> env\\output.txt");
                        } else {
                            if ($run["language"] == "Java") {
                                system("java -classfile env {$run['name']} <env\\input.txt> env\\output.txt");
                            } else {
                                if ($run["language"] == "Perl") {
                                    system("env\\{$run['name']}.pl <env\\input.txt> env\\output.txt");
                                } else {
                                    if ($run["language"] == "Python") {
                                        system("env\\{$run['name']}.py <env\\input.txt> env\\output.txt");
                                    }
                                }
                            }
                        }
                    }
                    $run["result"] = $problem["output"] == file_get("env/output.txt") ? "AC" : "WA";
                }
            }
        }
        if ($result != "-1") {
            mysql_query("UPDATE runs SET time='{$run['time']}' WHERE rid='{$run['rid']}'");
            mysql_query("UPDATE runs SET result='{$run['result']}' WHERE rid='{$run['rid']}'");
            if (file_exists("env/error.txt")) {
                $error = addslashes(addslashes(file_get("env/error.txt")));
            } else {
                $error = "";
            }
            mysql_query("UPDATE runs SET error='{$error}' WHERE rid='{$run['rid']}'");
        }
        // if solution is accepted
    }
    // if(!#invalid)
    if ($invalid) {
        echo "<tr><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td><td>NA</td></tr>";
        echo "<tr><td colspan=10 style='padding:30;'>Waiting For Submissions</td></tr>";
        echo "</table><br><center><input id='terminate' type='button' value='Terminate Execution Protocol' onClick=\"window.location='?display=admincontest'\"></center>";
        echo "<script>window.setTimeout(\"\$('input#terminate').css('display','none'); window.location = window.location;\",3000);</script>";
        unlink("env/lock.txt");
        return;
    }
    $code = filter($run["code"]);
    $code = eregi_replace("\n", "<br>", $code);
    $code = eregi_replace("\t", "    ", $code);
    $code = eregi_replace(" ", "&nbsp;", $code);
    $result = $run["result"];
    if (isset($fullresult[$result])) {
        $result = $fullresult[$result];
    }
    echo "<tr><td>{$run['rid']}</td><td>{$problem['name']}</td><td>{$run['language']}</td><td>{$teamname}</td><td>{$realname}</td><td>{$run['time']}</td><td>{$result}</td></tr>";
    echo "<tr><td colspan=10 style='text-align:left;padding:30;'><code>{$code}</code></td></tr>";
    if (file_exists("env/error.txt") && ($errormessage = file_get("env/error.txt")) != "") {
        $filename = "{$run['name']}." . $extension[$run["language"]];
        if ($run["language"] == "C" || $run["language"] == "C++" || $run["language"] == "Java") {
            $errormessage = eregi_replace("^[^ ]*" . addslashes($filename), "{$realname}", $errormessage);
            $errormessage = eregi_replace("\n[^ ]*" . addslashes($filename), "\n{$realname}", $errormessage);
        } else {
            if ($run["language"] == "Perl" || $run["language"] == "PHP") {
                $errormessage = eregi_replace(" [^ ]*" . addslashes($filename) . " ", " {$realname} ", $errormessage);
            } else {
                if ($run["language"] == "Python") {
                    $errormessage = eregi_replace("\"[^ ]*" . addslashes($filename) . "\"", "\"{$realname}\"", $errormessage);
                }
            }
        }
        echo "<tr><th colspan=10>Error Message</th></tr><tr><td colspan=10 style='text-align:left;padding:30;'><code>" . filter($errormessage) . "</code></td></tr>";
        mysql_query("UPDATE runs SET error='" . addslashes(addslashes($errormessage)) . "' WHERE rid='{$run['rid']}'");
    }
    echo "</table>";
    echo "<script>window.setTimeout('window.location = window.location;',500);</script>";
    unlink("env/lock.txt");
}
// Check we're logged in correctly
if (!session::logged_in()) {
    html_guest_error();
}
// Check that required variables are set
if (isset($_GET['fid']) && is_numeric($_GET['fid'])) {
    $fid = $_GET['fid'];
} else {
    if (isset($_POST['fid']) && is_numeric($_POST['fid'])) {
        $fid = $_POST['fid'];
    } else {
        html_draw_error(gettext("The requested folder could not be found or access was denied."));
    }
}
// Get the folder ID for the current message
if (!($folder_data = folder_get($fid))) {
    html_draw_error(gettext("The requested folder could not be found or access was denied."));
}
// UID of the current user.
$uid = session::get_value('UID');
// Get the existing thread data.
if (!folder_is_accessible($fid)) {
    html_draw_error(gettext("The requested folder could not be found or access was denied."));
}
// Array to hold error messages
$error_msg_array = array();
// Submit Code
if (isset($_POST['save'])) {
    $valid = true;
    if (isset($_POST['interest']) && is_numeric($_POST['interest'])) {
        $folder_data['INTEREST'] = $_POST['interest'];