Example #1
0
function saveOrderedImages($uid, $type, $category, $name)
{
    $query = "select * from orders where deleted = 0 and fk_user_id = :uid and type=:type and category = :category and name = :name";
    $res = DB::findOneFromQuery($query, array(":uid" => $uid, ":type" => $type, ":category" => $category, ":name" => $name));
    if (!($res && count($res) > 0)) {
        return DB::insert("orders", array("fk_user_id" => $uid, "type" => $type, "category" => $category, "name" => $name));
    }
    return -1;
}
function liveContestRanking($contestCode, $limit)
{
    $query = "SELECT ranktable FROM contest WHERE code = '{$contestCode}'";
    $table = '<table class="table table-striped table-bordered table-condensed">';
    $result = DB::findOneFromQuery($query);
    $rankTable = json_decode($result['ranktable'], true);
    $rank = 1;
    foreach ($rankTable as $row) {
        $table .= '<tr>';
        $table .= '<td align = "center">' . $rank . '</td><td align="center"><a href="' . SITE_URL . '/teams/' . $row['teamname'] . '">' . $row['teamname'] . '</a></td><td align="center">' . $row['score'] . '</td>';
        $table .= '</tr>';
        if ($rank >= $limit) {
            break;
        }
        $rank++;
    }
    $table .= '</table>';
    return $table;
}
Example #3
0
    $a -= $min;
    $hr = $a / 60;
    $str = "";
    if ($hr > 0) {
        $str .= $hr . ":";
    }
    if ($min > 0) {
        $str .= $min . ":";
    }
    $str .= $sec;
    return $str;
}
if (isset($_GET['code'])) {
    $_GET['code'] = addslashes($_GET['code']);
    $query = "select * from contest where code = '{$_GET['code']}'";
    $contest = DB::findOneFromQuery($query);
    ?>
    <center><h1>Rankings - <?php 
    echo $contest['name'];
    ?>
</h1></center>
    <?php 
    $query = "select teams.tid, teamname, group_concat(distinct(problems.pid) SEPARATOR ',') as pids\nfrom problems, teams, runs \nwhere \nruns.result = 'AC' and\nproblems.pid = runs.pid and \nproblems.contest = 'contest' and\nruns.access != 'deleted' and\nteams.tid = runs.tid and \nproblems.pgroup = '{$_GET['code']}' and \n(problems.status = 'Active' or problems.status = 'Inactive' or problems.status ='deleted') and\nteams.status != 'Admin'\ngroup by teams.tid";
    $res = DB::findAllFromQuery($query);
    foreach ($res as $row) {
        $rank[$row['tid']]['teamname'] = $row['teamname'];
        $rank[$row['tid']]['time'] = 0;
        $rank[$row['tid']]['score'] = 0;
        $rank[$row['tid']]['penalty'] = 0;
        $rank[$row['tid']]['solved'] = count(explode(',', $row['pids']));
        $query = "select \n                r.pid as pid, \n                min(submittime) as time, \n                score, \n                (select count(pid) from runs where tid = {$row['tid']} and pid = problems.pid and submittime < r.submittime and runs.access != 'deleted' and result != 'AC') as penalty \n                from runs r, problems where \n                r.access != 'deleted' and \n                tid = {$row['tid']} and \n                problems.pid in ({$row['pids']}) and \n                result = 'AC' and \n                r.pid = problems.pid \n                group by pid";
Example #4
0
function getCurrentContest()
{
    $result = DB::findOneFromQuery("SELECT value from admin where variable = 'currentContest'");
    $contestCode = $result['value'];
    return $contestCode;
}
Example #5
0
         echo "<input type='submit' name='rejudge' class='btn btn-danger' value='Rejudge All Selected Submisssions'/>\n            </form></center>";
     }
     $resopt = array('AC', 'RTE', 'WA', 'TLE', 'CE', 'DQ', 'PE');
     echo "<div class='breadcrumb' align='center'>";
     echo "Filter : <a class='label label-primary' href='" . SITE_URL . "/submissions/{$_GET['code']}'>ALL</a> ";
     foreach ($resopt as $val) {
         echo "<a class='label label-primary' href='" . SITE_URL . "/submissions/{$_GET['code']}&filter={$val}'>{$val}</a> ";
     }
     echo "</div>";
     $select = "Select *";
     $query = "from runs where access!='deleted' and tid in (SELECT tid FROM teams WHERE teamname='{$_GET['code']}') AND pid in (SELECT pid FROM problems WHERE status='Active' or status='Inactive')" . (isset($_GET['filter']) ? " and result='{$_GET['filter']}' " : "") . " order by rid desc";
     $result = DB::findAllWithCount($select, $query, $page, 25);
     $data = $result['data'];
     echo "<table class='table table-hover'><tr><th>Run ID</ht><th>Team</th><th>Problem</th><th>Language</th><th>Time</th><th>Result</th><th>Options</th></tr>";
     foreach ($data as $row) {
         $prob = DB::findOneFromQuery("Select name, code from problems where pid = {$row['pid']}");
         echo "<tr" . ($row['result'] == "AC" ? " class='success'>" : ">") . "<td>" . ($row['access'] == 'public' || isset($_SESSION['loggedin']) && ($_SESSION['team']['status'] == "Admin" || $_SESSION['team']['id'] == $row['tid']) ? "<a href='" . SITE_URL . "/viewsolution/{$row['rid']}'>{$row['rid']}</a>" : "{$row['rid']}") . "</td><td><a href='" . SITE_URL . "/teams/{$_GET['code']}'>{$_GET['code']}</a></td><td><a href='" . SITE_URL . "/problems/{$prob['code']}'>{$prob['name']}</a></td><td>{$row['language']}</td><td>{$row['time']}</td><td>{$row['result']}</td><td>" . ($row['access'] == 'public' || isset($_SESSION['loggedin']) && ($_SESSION['team']['status'] == "Admin" || $_SESSION['team']['id'] == $row['tid']) ? "<a class='btn btn-primary' href='" . SITE_URL . "/viewsolution/{$row['rid']}'>Code</a>" : "") . "</td></tr>";
     }
     echo "</table>";
     pagination($result['noofpages'], SITE_URL . "/submissions/{$_GET['code']}" . (isset($_GET['filter']) ? "&filter={$_GET['filter']}" : ""), $page, 10);
 } else {
     ?>
     <center><h1>Submissions</h1></center>
     <?php 
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
     } else {
         $page = 1;
     }
     $select = "Select *";
     if (isset($_SESSION['loggedin']) && $_SESSION['team']['status'] == 'Admin') {
Example #6
0
<?php

if (isset($_SESSION['loggedin']) && $_SESSION['team']['status'] == 'Admin') {
    if (isset($_GET['code'])) {
        $_GET['code'] = addslashes($_GET['code']);
        $query = "select * from teams where teamname='{$_GET['code']}'";
        $res = DB::findOneFromQuery($query);
        ?>
        <script type='text/javascript'>
            $(document).ready(function() {
                $('#teamname').focus(function() {
                    $('#teamname').tooltip('show');
                });
                $('#teamname').blur(function() {
                    $('#teamname').tooltip('hide');
                });
            });
        </script>
        <h1>Team Settings - <?php 
        echo $_GET['code'];
        ?>
</h1>
        <form method='post' class='form-horizontal' action='<?php 
        echo SITE_URL;
        ?>
/process.php'>
            <input type="hidden" value="<?php 
        echo $res['tid'];
        ?>
" name="tid" />
            <div class='form-group'>
Example #7
0
<?php

include_once '../functions.php';
include_once '../components.php';
function timeformating($a)
{
    return gmdate("H:i:s", $a);
}
if (isset($_GET['code'])) {
    $_GET['code'] = addslashes($_GET['code']);
    $query = "select * from contest where code = '{$_GET['code']}'";
    $contest = DB::findOneFromQuery($query);
    $query = "select value from admin where variable = 'penalty'";
    $admin = DB::findOneFromQuery($query);
    $query = "select * from problems where pgroup = '{$_GET['code']}' and status != 'Deleted'";
    $problems = DB::findAllFromQuery($query);
    $pidToProbCode = array();
    foreach ($problems as $prob) {
        $pidToProbCode[$prob['pid']] = $prob['code'];
    }
    ?>
<center><?php 
    if (isset($_SESSION['loggedin']) && $_SESSION['team']['status'] == "Admin") {
    }
    ?>
<h1>Rankings - <?php 
    echo $contest['name'];
    ?>
</h1></center>
    <?php 
    if ($contest['ranktable'] != "") {
Example #8
0
<?php

require_once 'config.php';
require_once 'components.php';
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
// used by process.php to send to last visited page
$query = "select value from admin where variable='mode'";
$judge = DB::findOneFromQuery($query);
if ($judge['value'] == 'Lockdown' && isset($_SESSION['loggedin']) && !isAdmin()) {
    session_destroy();
    session_regenerate_id(true);
    session_start();
    $_SESSION['msg'] = "Judge is in Lockdown mode and so you have been logged out.";
    redirectTo(SITE_URL);
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link type="text/css" rel="stylesheet" href="<?php 
echo CSS_URL;
?>
/bootstrap.css" media="screen" />
        <link type="text/css" rel="stylesheet" href="<?php 
echo CSS_URL;
?>
/style.css" media="screen" />
        <script type="text/javascript" src="<?php 
Example #9
0
            $result = DB::findOneFromQuery($query);
            echo $result['rank'];
            ?>
</td>
                </tr>
                <tr>
                    <th>Score</th><td><?php 
            echo $res['score'];
            ?>
</td>
                </tr>
                <tr>
                    <th>Practice Score</th><td>
                        <?php 
            $query = "select sum(score) as tot from (select distinct(pid), (select score from problems where pid = runs.pid and contest = 'practice') as score from runs where pid in (select pid from problems where contest = 'practice' and status = 'Active') and result = 'AC' and tid = {$res['tid']})t";
            $sco = DB::findOneFromQuery($query);
            echo $sco['tot'];
            ?>
</td>
                </tr>
            </table>
            <center><a href="<?php 
            echo SITE_URL . "/submissions/{$_GET['code']}";
            ?>
"><?php 
            echo $_GET['code'] . "'s ";
            ?>
Submissions</a></center>
            <h3>Practice Problems Solved</h3>
            <div class='row'>
                <?php 
Example #10
0
    <center><h1>Contact Us</h1></center>
    <?php 
    if (isset($_GET['page'])) {
        $page = $_GET['page'];
    } else {
        $page = 1;
    }
    $select = "Select *";
    $query = "from clar where access = 'Public' and pid='0' order by time desc";
    $result = DB::findAllWithCount($select, $query, $page, 10);
    $data = $result['data'];
    foreach ($data as $row) {
        $row['query'] = htmlentities(preg_replace("/\n/", "<br>", $row['query']));
        $row['reply'] = htmlentities(preg_replace("/\n/", "<br>", $row['reply']));
        $query = "Select teamname from teams where tid = {$row['tid']}";
        $team = DB::findOneFromQuery($query);
        echo "<div class='post'><b><a href='" . SITE_URL . "/teams/{$team['teamname']}'>{$team['teamname']}</a> : {$row['query']}</b>" . ($row['reply'] != "" ? "<hr/>A. {$row['reply']}<br/>" : '') . "</div>";
    }
    if (isset($_SESSION['loggedin'])) {
        ?>
        <hr/>
        <h4>Please feel free to post your queries/doubts/praise/criticism/feedback.<br/>We will reply as soon as we can!</h4>
        <form action="<?php 
        echo SITE_URL;
        ?>
/process.php" method="post">
            <input type="hidden" value="0" name="pid" />
            <textarea class='form-control' style="width: 500px; height: 200px;" name="query"></textarea><br/>
            <input name="clar" type="submit" class="btn btn-primary" />
        </form>
        <?php 
Example #11
0
<?php

if (isset($_SESSION['loggedin'])) {
    $level = DB::findOneFromQuery("select * from level where levelcode = (select level from users where id = " . $_SESSION['team']['id'] . ")");
    //  if($level['level']==16) {
    //
    //        <div class='wrap-box'>
    //          <div style='padding: 10px;'>
    //          Congratulations. You are now a pR0_H@ck3R!
    //          </div>
    //          </div>
    //<?php
    //  }
    // else
    if (isset($_GET['tab']) && $level['url'] == $_GET['tab']) {
        if ($level['content'] == "") {
            require 'files/' . $level['url'] . '.php';
        } else {
            foreach ($_COOKIE as $k => $value) {
                if ($k == "PHPSESSID") {
                    continue;
                }
                setcookie($k, null, -1);
            }
            if ($level['cookie'] != "") {
                foreach (explode(";", $level['cookie']) as $value) {
                    $r = explode("=", $value);
                    setcookie($r[0], $r[1], time() + 1000);
                }
            }
            ?>
Example #12
0
        $result = DB::findOneFromQuery("select * from editorials where pid = '{$pid}'");
        if ($result == NULL) {
            $data['pid'] = $pid;
            $data['content'] = $_POST['statement'];
            DB::query("INSERT into editorials VALUES ( {$pid}, '{$_POST['statement']}' )");
        } else {
            DB::query("update editorials set content = '{$_POST['statement']}' where pid = '{$pid}'");
        }
        //        $_SESSION['msg'] = 'Editorial Updated';
    }
    if (isset($_GET['code'])) {
        $_GET['code'] = addslashes($_GET['code']);
        $query = "select pid, code from problems where code = '{$_GET['code']}'";
        $res = DB::findOneFromQuery($query);
        if ($res != NULL) {
            $result = DB::findOneFromQuery("select content from editorials where pid = '{$res['pid']}'");
        }
        ?>

        <center><h1>Editorial Settings - <?php 
        echo "<a class='btn btn-primary' href='" . SITE_URL . "/editorial/{$_GET['code']}'>{$_GET['code']} Editorial</a>";
        ?>
</h1></center>
        <form class='form-horizontal' role='form' method='post' action='<?php 
        echo SITE_URL . "/admineditorial/{$_GET['code']}'";
        ?>
 enctype='multipart/form-data'>
            <div class='form-group'>
                <label class='control-label col-sm-2' for='code'>Code</label>
                <div class='col-sm-4'>
                    <input class='form-control' type='text' name='code' id='code' value='<?php 
Example #13
0
if ($judge['value'] != "Lockdown" || isset($_SESSION['loggedin']) && $_SESSION['team']['status'] == 'Admin') {
    if (isset($_GET['code'])) {
        $_GET['code'] = addslashes($_GET['code']);
        if (isset($_SESSION['loggedin']) && $_SESSION['team']['status'] == "Admin") {
            $query = "select * from problems where code = '{$_GET['code']}'";
            $result = DB::findOneFromQuery($query);
            if ($result != NULL) {
                echo "<a class='btn btn-primary pull-right' style='margin-top: 10px;' href='" . SITE_URL . "/admineditorial/{$_GET['code']}'><i class='glyphicon glyphicon-edit'></i> Edit</a>";
            }
        } else {
            $query = "select * from problems where code = '{$_GET['code']}' and status != 'Deleted'";
            $result = DB::findOneFromQuery($query);
        }
        if ($result == NULL) {
            echo "<br/><br/><br/><div style='padding: 10px;'><h1>Problem not Found :(</h1>The problem you are looking for doesn't exsits.</div><br/><br/><br/>";
        } else {
            $contentRes = DB::findOneFromQuery("select content from editorials where pid = " . $result['pid']);
            if ($contentRes == NULL) {
                echo "<br/><br/><br/><div style='padding: 10px;'><h1>Editorial not Found :(</h1>The editorial you are looking for doesn't exsits.</div><br/><br/><br/>";
            } else {
                $content = stripslashes($contentRes["content"]);
                echo "<center><h1>{$result['name']} - Editorial</h1></center><div class='btn-group'><a class='btn btn-primary' href='" . SITE_URL . "/problems/{$result['code']}'>Problem</a></div>\n            <br/><br/>" . $content . "<br/>";
            }
        }
    } else {
        echo "<br/><br/><br/><div style='padding: 10px;'><h1>Problem not Found :(</h1>The problem you are looking for doesn't exsits.</div><br/><br/><br/>";
    }
} else {
    echo "<br/><br/><br/><div style='padding: 10px;'><h1>Lockdown Mode :(</h1>This feature is now offline as Judge is in Lockdown mode.</div><br/><br/><br/>";
}
Example #14
0
<?php

require "config.php";
if (isset($_POST['username'])) {
    $res = DB::findOneFromQuery("select * from users where urname=" . DB::escape($_POST['username']) . " and (password='******'password'] . "')");
    if ($res) {
        $_SESSION['id'] = $res['id'];
        redirectTo("user.php");
    } else {
        redirectTo("index.php");
    }
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Signin</title>

    <link href="bootstrap.min.css" rel="stylesheet">

    <link href="signin.css" rel="stylesheet">
  </head>

  <body>

    <div class="container">
Example #15
0
 public static function getStaticRankTableInJSON($contestCode)
 {
     $query = "SELECT ranktable FROM contest WHERE code = '{$contestCode}'";
     return DB::findOneFromQuery($query);
 }
Example #16
0
    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="../../assets/js/html5shiv.js"></script>
      <script src="../../assets/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">
      <?php 
include 'config.php';
$re = DB::findOneFromQuery("select * from login where id=2");
if (isset($_GET['id']) && $_GET['id'] == $re['sessionid']) {
    $_SESSION['allowed'] = true;
    redirectTo('answer.php');
} else {
    echo "You have reached here. You'll go no far.";
}
?>

    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
  </body>
Example #17
0
            $query .= " where access = 'deleted'";
        }
    }
    $query .= " order by time desc";
    echo "<h1>Clarifications</h1>\n        <ul class='nav nav-tabs'>\n            <li " . ($tab == 'pending' ? "class='active'" : "") . "><a href='" . SITE_URL . "/adminclar&group=pending'>Pending</a></li>\n            <li " . ($tab == 'replied' ? "class='active'" : "") . "><a href='" . SITE_URL . "/adminclar&group=replied'>Replied</a></li>\n            <li " . ($tab == 'deleted' ? "class='active'" : "") . "><a href='" . SITE_URL . "/adminclar&group=deleted'>Deleted</a></li>\n        </ul>";
    $data = DB::findAllWithCount("select * ", $query, $page, 10);
    $result = $data['data'];
    foreach ($result as $row) {
        $save = $row['reply'];
        $row['query'] = preg_replace("/\n/", "<br>", $row['query']);
        $row['reply'] = preg_replace("/\n/", "<br>", $row['reply']);
        $query = "select teamname from teams where tid='{$row['tid']}'";
        $team = DB::findOneFromQuery($query);
        if ($row['pid'] != '0') {
            $query = "select name, code from problems where pid='{$row['pid']}'";
            $prob = DB::findOneFromQuery($query);
            $prob['code'] = "problems/" . $prob['code'];
        } else {
            $prob['name'] = 'Feedback';
            $prob['code'] = 'contact';
        }
        echo "<a href='" . SITE_URL . "/teams/{$team['teamname']}'>{$team['teamname']}</a> (<a href='" . SITE_URL . "/{$prob['code']}'>{$prob['name']}</a>):<br/>\n                <b>Q. " . htmlspecialchars($row[query]) . "</b><br/>";
        if ($row['reply'] != "") {
            echo "A. " . htmlspecialchars($row[reply]) . "<br/><br/>";
        }
        echo "<form class='form-inline' role='form' method='post' action='" . SITE_URL . "/process.php'>";
        echo "<div class='form-group'>Access:</div><div class='form-group'><select class='form-control'  name='access'><option value='public' " . ($row['access'] == "public" ? "selected='selected' " : "") . ">Public</option><option value='deleted' " . ($row['access'] == "deleted" ? "selected='selected' " : "") . ">Deleted</option></select></div><br/><br/>";
        echo "<input type='hidden' name='tid' value='{$row['tid']}' /><input type='hidden' name='pid' value='{$row['pid']}' /><input type='hidden' name='time' value='{$row['time']}' />\n<textarea class='form-control' name='reply' style='width: 450px; height: 100px;'>{$save}</textarea><br/><br/>\n<input type='submit' class='btn btn-primary' name='clarreply' value='Reply / Change Reply'/>\n</form><hr/>";
    }
    pagination($data['noofpages'], SITE_URL . "/adminclar" . "&group={$tab}", $page, 10);
} else {
Example #18
0
     }
     DB::update('users', array('mcq_answer' => $mcqans), "id = " . $_SESSION['team']['id']);
 } else {
     if (isset($_POST['mcqans'])) {
         $ans = $_POST;
         $question = DB::findOneFromQuery("select count(id) as total from mcq");
         unset($ans['save']);
         $mcqans = "";
         for ($i = 1; $i <= $question['total']; $i++) {
             if (isset($ans[$i])) {
                 $mcqans .= $ans[$i];
             }
             $mcqans .= ",";
         }
         $correct = DB::findAllFromQuery("select correct from mcq");
         $user = DB::findOneFromQuery("select cheat from users where id = " . $_SESSION['team']['id']);
         $i = 1;
         $score = 0;
         foreach ($correct as $val) {
             if (isset($ans[$i]) && $ans[$i] == $val['correct']) {
                 $score += 4 * $user['cheat'];
             } else {
                 if (isset($ans[$i]) && $ans[$i] != $val['correct']) {
                     $score -= 1;
                 }
             }
             $i++;
         }
         $_SESSION['team']['score'] = $score;
         DB::update('users', array('mcq_answer' => $mcqans, 'score' => $score, 'level' => 1), "id = " . $_SESSION['team']['id']);
     } else {