示例#1
0
function status_draw_each_result()
{
    global $pro_id, $result_array;
    foreach ($result_array as $key => $val) {
        if ($val != 'All' && $val != 'Waiting') {
            $query = "select count(*) from submit_status where result={$key} and pro_id={$pro_id}";
            $ret = oj_query($query);
            $row = mysql_fetch_row($ret);
            if ($row[0] != 0) {
                status_draw_statistics($val, "<a href='status.php?pro_id={$pro_id}&result={$key}'>{$row[0]}</a>");
            }
        }
    }
}
示例#2
0
function draw_post_tree($parent)
{
    //不绘制自身
    $buff = '';
    $query = 'select discuss_info.*, LENGTH(discuss_info.content) as content_len, users.name ' . 'from discuss_info inner join users on discuss_info.user_id=users.user_id ' . "where discuss_info.topic_id={$parent['message_id']} and discuss_info.message_id<>{$parent['message_id']} " . 'order by discuss_info.reply_id desc ';
    $ret = oj_query($query);
    if ($row = mysql_fetch_assoc($ret)) {
        $buff = $buff . '<ul>';
        do {
            $buff = $buff . '<li>' . draw_single_post($row, 0) . draw_post_tree($row) . '</li>';
        } while ($row = mysql_fetch_assoc($ret));
        $buff = $buff . '</ul>';
    }
    return $buff;
}
示例#3
0
function get_contest_statistics()
{
    global $contest_id, $pro_count;
    //ret[pro_i]['result'][result]
    //ret[pro_i]['lang'][language]
    //ret[pro_i]['total']
    //ret[pro_i]['pro_id']
    //ret[pro_i]['new_id']
    //ret['total']['result'][result]
    //ret['total']['lang'][language]
    //ret['total']['total']
    //problems
    $query = "select pro_id,new_id from contest_problems where contest_id={$contest_id} order by new_id asc";
    $ret = oj_query($query);
    $pro_count = 0;
    while ($row = mysql_fetch_row($ret)) {
        $contest_stat[$pro_count]['pro_id'] = $row[0];
        $contest_stat[$pro_count]['new_id'] = $row[1];
        $pro_count++;
    }
    //each problem
    for ($i = 0; $i < $pro_count; $i++) {
        $pro_id = intval($contest_stat[$i]['pro_id']);
        //result
        $query = 'select result,count(result) from submit_status ' . "where contest_id={$contest_id} and pro_id=" . $pro_id . ' and result!=15 and result!=0 ' . 'group by result ';
        $ret = oj_query($query);
        while ($row = mysql_fetch_row($ret)) {
            $contest_stat[$i]['result'][$row[0]] = $row[1];
            $contest_stat[$i]['total'] += $row[1];
            $contest_stat['total']['result'][$row[0]] += $row[1];
            $contest_stat['total']['total'] += $row[1];
        }
        //language
        $query = 'select language,count(language) from submit_status ' . "where contest_id={$contest_id} and pro_id=" . $pro_id . ' group by language ';
        $ret = oj_query($query);
        while ($row = mysql_fetch_row($ret)) {
            $contest_stat[$i]['lang'][$row[0]] += $row[1];
            $contest_stat['total']['lang'][$row[0]] += $row[1];
        }
    }
    return $contest_stat;
}
示例#4
0
    $query = "insert into code_info(submit_id,code_content) values({$submit_id},'{$code}')";
    oj_query($query);
    $query = "insert into judge_queue(submit_id) values({$submit_id})";
    oj_query($query);
    $query = "update problems set submits=submits+1 where pro_id={$pro_id} ";
    oj_query($query);
    $query = "update users set submits=submits+1 where user_id={$user_id} ";
    oj_query($query);
    $query = "select result from user_submit where user_id={$user_id} and pro_id={$pro_id}";
    $ret = oj_query($query);
    $row = mysql_fetch_row($ret);
    if (!isset($row[0])) {
        $query = "insert into user_submit (user_id,pro_id,result) values ({$user_id},{$pro_id},0)";
        oj_query($query);
        $query = "update problems set submit_users=submit_users+1 where pro_id={$pro_id}";
        oj_query($query);
    }
    redirect("status.php");
}
set_ojinfo('title', 'ECUST Online Judge - Submit code');
include 'include/header.php';
if (isset($_POST['pro_id'])) {
    $_GET['pro_id'] = $_POST['pro_id'];
}
?>

<form name="form1" method="post" action="problemsubmit.php">
  <label>Problem ID:
  <input type="text" name="pro_id" value="<?php 
if (isset($_GET['pro_id'])) {
    echo htmlspecialchars($_GET['pro_id']);
示例#5
0
    $contest_id = intval(get_to_mysql($_GET['contest_id']));
    $query = "select start_time>now() from contest where contest_id={$contest_id} ";
    $ret = oj_query($query);
    $row = mysql_fetch_row($ret);
    if (!isset($row[0]) || $row[0] && !$is_admin) {
        redirect('error.php?msg=' . urlencode('Hey, what are you doing?'));
    }
    $query = "select pro_id from contest_problems where contest_id={$contest_id} and pro_id={$pro_id}";
    $ret = oj_query($query);
    $row = mysql_fetch_row($ret);
    if (!isset($row[0])) {
        redirect('error.php?msg=' . urlencode('The contest does not include the problem.'));
    }
}
$query = "select title,description,input,output,sample_input,sample_output," . "hint,source,time_limit,case_time_limit,mem_limit,accepted,submits,banned,isspj from problems where pro_id={$pro_id}";
$ret = oj_query($query);
$row = mysql_fetch_row($ret);
if (!isset($row[0])) {
    redirect("error.php?msg=" . urlencode("Problem not found!"));
}
$title = htmlspecialchars($row[0]);
//$desc = htmlspecialchars($row[1]);
$desc = $row[1];
$input = $row[2];
$output = $row[3];
$sample_input = $row[4];
$sample_output = $row[5];
$hint = $row[6];
$source = htmlspecialchars($row[7]);
$time_limit = htmlspecialchars($row[8]);
$case_time_limit = htmlspecialchars($row[9]);
示例#6
0
    redirect('error.php?msg=' . urlencode('Access denied'));
}
if (isset($_POST['title'])) {
    $addc_title = get_to_mysql($_POST['title']);
    $addc_desc = get_to_mysql($_POST['description']);
    $addc_start = get_to_mysql($_POST['start_time']);
    $addc_end = get_to_mysql($_POST['end_time']);
    $addc_pwd = get_to_mysql($_POST['att_pwd']);
    if (empty($addc_pwd)) {
        $addc_pub = 1;
    } else {
        $addc_pub = 0;
    }
    $query = 'insert into contest (title,start_time,end_time,description,ispub,att_pwd) values ' . "('{$addc_title}','{$addc_start}','{$addc_end}','{$addc_desc}',{$addc_pub},'{$addc_pwd}') ";
    $ret = oj_query($query);
    $ret = oj_query('select last_insert_id()');
    $row = mysql_fetch_row($ret);
    redirect("showcontest.php?contest_id={$row[0]}");
}
set_ojinfo('title', 'ECUST Online Judge - Add contest');
include 'include/header.php';
function draw_fillin($left, $input, $name, $prop = '', $right = '')
{
    echo '<tr>';
    echo '<td>' . htmlspecialchars($left) . '</td>';
    echo "<td><{$input} name='{$name}' {$prop}></{$input}>{$right}</td>";
    echo '</tr>';
}
?>

<form method=post action="" onsubmit="return check_addc();">
示例#7
0
/**
 * log in.
 * if the user id and password is correct, return success
 * @param string $login_name The key of the option's name
 * @param string $login_pwd The key of the option's name
 * @return string return success if the user id and password is correct, or return error message
 * @example get_ojinfo('title');
 */
function oj_login($login_name, $login_pwd)
{
    if (strlen($login_pwd) != 32) {
        return 'Please make sure that you have enabled the Javascript.';
    }
    $login_name = get_to_mysql($login_name);
    $login_pwd = get_to_mysql($login_pwd);
    $query = "select user_pwd,user_id,name from users where name='{$login_name}'";
    $ret = oj_query($query);
    $row = mysql_fetch_row($ret);
    if (empty($row[0])) {
        return 'Wrong User ID.';
    }
    if ($row[0] != $login_pwd) {
        return 'Wrong Password.';
    }
    // banned?
    $login_id = $row[1];
    $login_name = $row[2];
    $_SESSION['user_name'] = $login_name;
    $_SESSION['user_id'] = $login_id;
    $_SESSION['is_admin'] = permission_admin($login_id);
    $_SESSION['is_judger'] = permission_judger($login_id);
    $login_ip = get_ip();
    $query = "update users set last_login_ip='{$login_ip}', last_login_time=now() where user_id=" . intval($login_id);
    $ret = oj_query($query);
    return 'success';
}
示例#8
0
function get_contest_ranklist()
{
    global $contest_id, $contest_pro, $contest_start_time, $contest_summary;
    //ret[user_i]['user_id']
    //ret[user_i]['nick_name']
    //ret[user_i]['solved']
    //ret[user_i]['penalty']
    //ret[user_i][pro_i][0:is_accepted|1:failed_submissions|2:first_accepted]
    //contest_summary[pro_i][0:ac_count|1:submit_count|2:first_ac]
    //problems
    $query = "select pro_id,new_id from contest_problems where contest_id={$contest_id} order by new_id asc";
    $ret = oj_query($query);
    $pro_count = 0;
    while ($row = mysql_fetch_row($ret)) {
        $contest_pro[$pro_count] = $row;
        $pro_index[$row[0]] = $pro_count;
        $pro_count++;
    }
    //summary
    for ($i = 0; $i < $pro_count; $i++) {
        $contest_summary[$i][0] = 0;
        //ac_count
        $contest_summary[$i][1] = 0;
        //submit_count
        $contest_summary[$i][2] = -1;
        //first_ac
    }
    //each submitted users
    $user_count = 0;
    $query = "select distinct user_id from submit_status where contest_id=" . $contest_id;
    $ret = oj_query($query);
    while ($row = mysql_fetch_row($ret)) {
        //user_id,nick_name
        $user_id = $row[0];
        $query = "select name,nick_name from users where user_id={$user_id}";
        $ret2 = oj_query($query);
        $row2 = mysql_fetch_row($ret2);
        if (strlen($row2[1]) == 0) {
            $user_name = $row2[0];
        } else {
            $user_name = $row2[1];
        }
        $contest_rank[$user_count]['user_id'] = $user_id;
        $contest_rank[$user_count]['nick_name'] = $user_name;
        //init
        for ($i = 0; $i < $pro_count; $i++) {
            $contest_rank[$user_count][$i][0] = 0;
            //accept
            $contest_rank[$user_count][$i][1] = 0;
            //fails
            $contest_rank[$user_count]['solved'] = 0;
            $contest_rank[$user_count]['penalty'] = 0;
        }
        //submissions
        $query = "select pro_id,result,submit_time from submit_status " . "where contest_id={$contest_id} and user_id={$user_id} " . 'order by submit_id asc';
        $ret2 = oj_query($query);
        while ($row2 = mysql_fetch_assoc($ret2)) {
            $now_pro_index = $pro_index[$row2['pro_id']];
            if ($contest_rank[$user_count][$now_pro_index][0] == 0) {
                //submissions before accept
                if ($row2['result'] == 1) {
                    $contest_rank[$user_count][$now_pro_index][0] = 1;
                    $contest_rank[$user_count]['solved']++;
                    $now_ac_time = floor((strtotime($row2['submit_time']) - $contest_start_time) / 60);
                    $contest_rank[$user_count][$now_pro_index][2] = $now_ac_time;
                    if ($contest_summary[$now_pro_index][2] < 0 || $contest_summary[$now_pro_index][2] > $now_ac_time) {
                        $contest_summary[$now_pro_index][2] = $now_ac_time;
                    }
                } else {
                    $contest_rank[$user_count][$now_pro_index][1]++;
                }
            }
            if ($row2['result'] == 1) {
                $contest_summary[$now_pro_index][0]++;
            }
            $contest_summary[$now_pro_index][1]++;
        }
        //penalty
        for ($i = 0; $i < $pro_count; $i++) {
            if ($contest_rank[$user_count][$i][0] != 0) {
                $contest_rank[$user_count]['penalty'] += $contest_rank[$user_count][$i][2] + $contest_rank[$user_count][$i][1] * 20;
            }
        }
        $user_count++;
    }
    //sort
    if (isset($contest_rank)) {
        usort($contest_rank, 'contest_ranklist_cmp');
    }
    return $contest_rank;
}
示例#9
0
	<td>
<?php 
if (!isset($_SESSION['user_name']) && isset($_COOKIE['oj_user'])) {
    $usrInfo = explode('\\.', $_COOKIE['oj_user']);
    if (count($usrInfo) >= 3 && $usrInfo[0] == 'Y') {
        oj_login(str_replace('&DOT;', '.', $usrInfo[1]), str_replace('&DOT;', '.', $usrInfo[2]));
    }
}
if (isset($_SESSION['user_name'])) {
    echo "<a class='user' href='user.php?user_id={$_SESSION['user_id']}'>" . htmlspecialchars($_SESSION['user_name']) . "</a><br>";
    $h_query = "select count(*) from mails where to_user_id={$_SESSION['user_id']}";
    $h_ret = oj_query($h_query);
    $h_row = mysql_fetch_row($h_ret);
    $h_sum_mail = $h_row[0];
    $h_query = "select count(*) from mails where to_user_id={$_SESSION['user_id']} and readed=0";
    $h_ret = oj_query($h_query);
    $h_row = mysql_fetch_row($h_ret);
    $h_new_mail = $h_row[0];
    if ($h_new_mail > 0) {
        $h_new_mail = "<b>{$h_new_mail}</b>";
    }
    echo "<a href='maillist.php'>Mail:{$h_sum_mail}({$h_new_mail})</a><br>";
    ?>
<a href='modifyuser.php'>Update&nbsp;your&nbsp;Info</a><br />
<a href="logout.php?url=<?php 
    echo urlencode($_SERVER['REQUEST_URI']);
    ?>
">Logout</a>
<?php 
} else {
    ?>
示例#10
0
<?php 
$message_id = intval($_GET['message_id']);
$query = 'select discuss_info.*,users.name ' . 'from discuss_info inner join users on discuss_info.user_id=users.user_id ' . "where discuss_info.message_id={$message_id} ";
$ret = oj_query($query);
$row = mysql_fetch_assoc($ret);
echo '<center><h2>' . htmlspecialchars($row['title']) . '</h2></center>';
echo '<p>';
echo "Posted&nbsp;by&nbsp;<a class='user' href='user.php?user_id={$row['user_id']}'>" . htmlspecialchars($row['name']) . '</a>';
echo "&nbsp;at&nbsp;{$row['reply_time']}";
if ($row['pro_id'] != 0) {
    echo "&nbsp;on&nbsp;<a class='problem' href='problemshow.php?pro_id={$row['pro_id']}'>Problem&nbsp;{$row['pro_id']}</a>&nbsp;";
}
echo '<br>';
if ($row['topic_id'] != $row['message_id']) {
    $query = 'select discuss_info.title,discuss_info.reply_time,discuss_info.user_id,users.name ' . 'from discuss_info inner join users on discuss_info.user_id=users.user_id ' . "where discuss_info.message_id={$row['topic_id']}";
    $ret2 = oj_query($query);
    $row2 = mysql_fetch_assoc($ret2);
    echo 'In&nbsp;Reply&nbsp;To:';
    echo "<a href='showmessage?message_id={$row['topic_id']}'>" . htmlspecialchars($row2['title']) . '</a>';
    echo "Posted&nbsp;by&nbsp;<a class='user' href='user.php?user_id={$row2['user_id']}'>" . htmlspecialchars($row2['name']) . '</a>';
    echo "&nbsp;at&nbsp;{$row2['reply_time']}<br>";
}
echo '<hr><pre>';
echo htmlspecialchars($row['content']);
echo '</pre><hr><p>';
echo 'Followed&nbsp;by:<br>';
echo draw_post_tree($row);
echo '<hr>';
?>
</td></tr>
</table>
示例#11
0
        die('Contest has not ended!');
    }
    $readme = "Contest: \t{$contest['title']}\r\n\r\nStart time: \t{$contest['start_time']}\r\nEnd time: \t{$contest['end_time']}\r\n\r\nDescript:\r\n {$contest['description']}\r\n\r\nProblem List:\r\n";
    $res = oj_query('Select problems.pro_id, title, new_id From contest_problems, problems Where problems.pro_id=contest_problems.pro_id and contest_id=' . $cid);
    $contest_problem_map = array();
    while ($contest_problem = mysql_fetch_array($res)) {
        $contest_problem_map[$contest_problem['pro_id']] = chr(64 + intval($contest_problem['new_id'])) . '_' . $contest_problem['title'];
        $problems[$contest_problem_map[$contest_problem['pro_id']]] = array();
        $readme .= chr(64 + intval($contest_problem['new_id'])) . " {$contest_problem['title']}\r\n";
    }
    $res = oj_query('Select user_id, name, nick_name From users Where user_id in (Select user_id From submit_status Where result=1 and contest_id=' . $cid . ')');
    $user = array();
    while ($usr = mysql_fetch_array($res)) {
        $user[$usr['user_id']] = "{$usr['name']}_{$usr['nick_name']}";
    }
    $res = oj_query('Select submit_status.submit_id, user_id, pro_id, language, code_content From submit_status, code_info Where submit_status.submit_id=code_info.submit_id and result=1 and contest_id=' . $cid);
    while ($submit = mysql_fetch_array($res)) {
        $problems[$contest_problem_map[$submit['pro_id']]][$submit['submit_id'] . '_' . $user[$submit['user_id']] . $language_suffix[intval($submit['language'])]] = $submit['code_content'];
    }
    $dwn = new ZipArchive();
    $res = $dwn->open($basedir . $filename, ZIPARCHIVE::CREATE);
    $dwn->addFromString('readme.txt', $readme);
    foreach ($problems as $pid => $parr) {
        $dwn->addEmptyDir($pid);
        foreach ($parr as $sid => $source) {
            $dwn->addFromString("{$pid}/{$sid}", $source);
        }
    }
    $dwn->close();
}
header('Content-Type: application/zip');
示例#12
0
function HaveAC($pro_id, $user_id)
{
    $sql = "select result from user_submit where user_id=" . $user_id . " and pro_id=" . $pro_id;
    $ret = oj_query($sql);
    $row = mysql_fetch_array($ret);
    if ($row == null) {
        return -1;
    } else {
        return intval($row['result']);
    }
}