function clearByes($tid)
{
    $bye = bye();
    $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $tid . "' AND player_checkin='1'");
    $max = getMaxPl($pl);
    $rounds = log($max) / log(2);
    for ($i = 1; $i <= $rounds; $i++) {
        for ($j = 1; $j <= $max / pow(2, $i); $j++) {
            $result = dbquery("SELECT * FROM " . DB_T_MATCHES . " WHERE match_round='" . $i . "' AND match_match='" . $j . "' AND match_tour='" . $tid . "'");
            $data = dbarray($result);
            if ($data['match_pl1'] == $bye && $data['match_pl2'] == $bye) {
                EnterResult($tid, $i, $j, 1, 0);
            }
            if ($data['match_pl1'] == $bye && $data['match_pl2'] != $bye && $data['match_pl2'] != 0) {
                EnterResult($tid, $i, $j, 0, 1);
            }
            if ($data['match_pl1'] != $bye && $data['match_pl2'] == $bye && $data['match_pl1'] != 0) {
                EnterResult($tid, $i, $j, 1, 0);
            }
        }
    }
    $x = $rounds + 1;
    $result2 = dbquery("SELECT * FROM " . DB_T_MATCHES . " WHERE match_round='" . $x . "' AND match_match='1' AND match_tour='" . $tid . "'");
    $data2 = dbarray($result);
    if ($data2['match_pl1'] == $bye && $data2['match_pl2'] == $bye) {
        EnterResult($tid, $x, 1, 1, 0);
    }
    if ($data2['match_pl1'] == $bye && $data2['match_pl2'] != $bye && $data2['match_pl2'] != 0) {
        EnterResult($tid, $x, 1, 0, 1);
    }
    if ($data2['match_pl1'] != $bye && $data2['match_pl2'] == $bye && $data2['match_pl1'] != 0) {
        EnterResult($tid, $x, 1, 1, 0);
    }
}
                 }
             }
             $mres = "Your next match: \n" . $opp_link . " - <a href='" . BASEDIR . "tourney.php?p=result&id=" . $nm['match_id'] . "'>go to match</a>";
         } else {
             $mres = "No more matches to play for you.";
         }
     } else {
         $mres = "You don't take part in this tourney.";
     }
 }
 opentable("Tourney info");
 echo "<table width='100%'><tr><td class='tbl2' width='50%'><strong>" . $tour['tour_name'] . "</strong> - <a href='" . BASEDIR . "tourney.php?p=viewtour&id=" . $tour['tour_id'] . "'>view more</a></td><td class='tbl2'>" . $mres . "</td></tr></table>";
 closetable();
 opentable("Brackets");
 //mini info
 $bye = bye();
 $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $tid . "' AND player_checkin='1'");
 $max = getMaxPl($pl);
 $rounds = log($max) / log(2);
 $f_heigth = array(1 => 0, 33, 98, 227, 482);
 $m_heigth = array(1 => 30, 94, 222, 478, 990);
 $wi = 100 / ($rounds + 1);
 $ro = $max;
 echo "<table width='100%'><tr>";
 for ($x = 1; $x <= $rounds; $x++) {
     echo "<td class='tbl2' align='center' width='" . $wi . "%'><strong>1/" . $ro . "</strong></td>";
     $ro = $ro / 2;
 }
 echo "<td class='tbl2' align='center' width='" . $wi . "'><strong>winner</strong></td>";
 echo "</tr></table>";
 echo "<table><tr valign='top'>";
Example #3
0
<?php

/*
 *	Check for availability of PREG-functions.
 */
$GLOBALS['pie']['log'] = 'PREG checking';
if (!function_exists('preg_match')) {
    bye("Your version of PHP does not seem to support Perl-compatible regular expressions.");
}
    }
    $x = $rounds + 1;
    $final34 = dbquery("INSERT INTO " . DB_T_MATCHES . " (match_tour, match_round, match_match) VALUES ('" . $tid . "', '" . $x . "', '1')");
    for ($i = 1; $i <= $max; $i++) {
        //1- 1,2; 2 - 3,4; 3 - 5,6; 4 - 7,8
        $n1 = 2 * $i - 1;
        $n2 = 2 * $i;
        $pl1 = $_POST['pl' . $n1];
        $pl2 = $_POST['pl' . $n2];
        if ($pl1 == "0") {
            $byete = dbquery("INSERT INTO " . DB_T_PLAYERS . " (player_user, player_tour, player_checkin) VALUES ('" . bye() . "', '" . $tid . "', '1')");
            $pl1 = bye();
        }
        if ($pl2 == "0") {
            $byete = dbquery("INSERT INTO " . DB_T_PLAYERS . " (player_user, player_tour, player_checkin) VALUES ('" . bye() . "', '" . $tid . "', '1')");
            $pl2 = bye();
        }
        $ins_pl = dbquery("UPDATE " . DB_T_MATCHES . " SET match_pl1='" . $pl1 . "', match_pl2='" . $pl2 . "' WHERE match_tour='" . $tid . "' AND match_round='1' AND match_match='" . $i . "'");
    }
    $upd_t = dbquery("UPDATE " . DB_T_TOURS . " SET tour_grid='1' WHERE tour_id='" . $tid . "'");
    clearByes($tid);
}
$result = dbquery("SELECT * FROM " . DB_T_TOURS . " WHERE tour_id='" . $_GET['id'] . "'");
if (dbrows($result)) {
    $tour = dbarray($result);
    $now = time() + ($settings['timeoffset'] + $settings['serveroffset']) * 3600;
    if ($tour['tour_date'] < $now) {
        $pl = dbcount("(player_id)", DB_T_PLAYERS, "player_tour='" . $_GET['id'] . "' AND player_checkin='1'");
        if ($pl > 0) {
            $max = getMaxPl($pl, $tour['tour_maxpl']);
            $free = $max - $pl;
Example #5
0
<?php

/*
 *	Create the local logging facilities below ${run_path}.
 */
$GLOBALS['pie']['log'] = 'Logging';
if (!file_exists("{$lib}/share/log.php")) {
    bye("The log library ({$lib}/share/log.php) could not be found.");
}
include_once "{$lib}/share/log.php";
if (!is_dir("{$run}/log")) {
    if (!mkdir("{$run}/log")) {
        bye("The directory for the log file(s) ({$run}/log) could not be created.");
    }
}
if (!touch("{$run}/log/pie.log")) {
    bye("The initial log file could not be created.");
}
pieLog('setup');
Example #6
0
<?php

/*
 *	Check for availability of the hashing functions.
 */
$GLOBALS['pie']['log'] = 'Validate hashing';
if (!function_exists('md5')) {
    bye("Your version of PHP does not seem to support MD5-hashing.");
}
if (!function_exists('sha1')) {
    bye("Your version of PHP does not seem to support SHA-1-hashing.");
}
Example #7
0
<?php

/*
 *	Set up the file archive environment.
 */
$GLOBALS['pie']['log'] = 'File Archive';
if (!file_exists("{$lib}/class/file.php")) {
    bye("The file class library could not be found.");
}
include_once "{$lib}/class/file.php";
$file = new File();
if (!$file->initialize()) {
    bye("The file database could not be initialized.");
}
Example #8
0
<?php

/*
 *	Create the directory for temporal files.
 */
$GLOBALS['pie']['log'] = 'Temporal Files';
if (!is_dir("{$run}/temp")) {
    if (!mkdir("{$run}/temp")) {
        bye("The directory for temporal files ({$run}/temp) could not be created.");
    }
}
if (!touch("{$run}/temp/setup.tmp")) {
    bye("Temporal files can not be written.");
}
if (!unlink("{$run}/temp/setup.tmp")) {
    bye("Temporal files can not be accessed.");
}
Example #9
0
<?php

/*
 *	Create the user database.
 */
$GLOBALS['pie']['log'] = 'User Database';
if (!file_exists("{$lib}/class/user.php")) {
    bye("The user class library could not be found.");
}
include_once "{$lib}/class/user.php";
$user = new User();
if (!$user->initialize()) {
    bye("The user database could not be initialized.");
}
if (!is_dir("{$run}/user")) {
    if (!mkdir("{$run}/user")) {
        bye("The user file directory ({$run}/user) could not be created.");
    }
}
Example #10
0
<?php

/*
 *	Check for PHP version 4.3+
 */
$GLOBALS['pie']['log'] = 'Version checking';
if (version_compare('4.3', PHP_VERSION) > 0) {
    bye("You need PHP version 4.3 or later to run this software.");
}
Example #11
0
<?php

/*
 *	Check for an already installed system.
 *	In such case, the setup/upgrade must be explicitly enabled.
 */
$GLOBALS['pie']['log'] = 'Verifying permission to setup/upgrade';
if (file_exists("{$run}/user") && !file_exists("{$run}/user/enable_setup")) {
    bye("You are trying to setup/upgrade a system that is already installed.</p>\n" . "<p>To upgrade an existing system you must log in as a administrator and explicitly enable the upgrade.");
}
Example #12
0
<?php

/*
 *	Set up the environment for the source database.
 */
$GLOBALS['pie']['log'] = 'Source Database';
if (!file_exists("{$lib}/class/page.php")) {
    bye("The page class library could not be found.");
}
include_once "{$lib}/class/page.php";
$page = new Page();
if (!$page->initialize()) {
    bye("The source database could not be initialized.");
}
Example #13
0
<?php

/*
 *	Validate the existence and writability of the working directory.
 */
$GLOBALS['pie']['log'] = "Working Directory";
if (!is_dir($run)) {
    bye("The specified working directory ({$run}) does not exist.");
}
if (!is_writable($run)) {
    bye("The specified working directory ({$run}) is not accessible in write mode.");
}
if (!touch("{$run}/test")) {
    bye("The specified working directory ({$run}) cannot be written.");
}
if (!unlink("{$run}/test")) {
    bye("The specified working directory ({$run}) cannot be worked with.");
}
Example #14
0
<?php

/*
 *	Create superuser account for user "admin", password "secret".
 */
$GLOBALS['pie']['log'] = 'Superuser Account';
if (!file_exists("{$lib}/class/user.php")) {
    bye("The user class library could not be found.");
}
include_once "{$lib}/class/user.php";
$user = new User();
if (!$user->exists("admin")) {
    if (!$user->write('admin', $user->encrypt('secret'))) {
        bye("The superuser account could not be created.");
    }
}
Example #15
0
<?php

/*
 *	Set up the session handling environment.
 */
$GLOBALS['pie']['log'] = 'Session Handling';
if (!file_exists("{$lib}/class/session.php")) {
    bye("The session handler library could not be found.");
}
include_once "{$lib}/class/session.php";
$session = new Session();
if (!$session->initialize()) {
    bye("The session sub system could not be initialized.");
}
                $acnastr = $vvv->score == 100 ? 'AC' : 'NA';
                $acnaclr = $acnastr == 'AC' ? 32 : 31;
                echo exec("echo \"[\\033[0;{$acnaclr};49m{$acnastr}\\033[0;0;0m]\"");
                printf("  %05d  %3d  %s\n", $vvv->id, $vvv->score, $vvv->title);
            }
        }
        echo "Press Enter/Return to continue, or 'exit' and RET for exit!\n";
        if (waitforret()) {
            bye();
            exit(0);
        }
    }
    echo "Everything is OK!\n";
    echo "Author: Senorsen sen@senorsen.com\n";
}
bye();
function bye()
{
    global $tmp_file;
    echo "Bye~~\n";
    unlink($tmp_file);
}
function uploadsrc($prob_id, $file)
{
    $cfile = new CURLFile($file, 'application/octet-stream', "{$prob_id}.c");
    $data = array('MAX_FILE_SIZE' => '81920000', 'prob_id' => $prob_id, 'langn' => 0, 'flagn' => 1, 'sub1' => 'Senorsen', 'userfile' => $cfile);
    $ret = curlf('student/submit_process.php', $data, 1);
    echo $ret;
    if (preg_match('/解答已经提交/', $ret)) {
        preg_match('/url=(.+?)"/', $ret, $matches);
        sleep(2);
Example #17
0
    if (!is_dir("{$lib}/setup")) {
        bye("The setup directory does not exist.");
    }
    // Build a list of the setup scripts.
    if (!($dh = opendir("{$lib}/setup"))) {
        bye("Unable to open setup directory.");
    }
    $scripts = array();
    while (($file = readdir($dh)) !== false) {
        if (preg_match('/^\\d\\d\\w+\\.php$/', $file)) {
            $scripts[] = $file;
        }
    }
    closedir($dh);
    if (!count($scripts)) {
        bye('The setup directory does not contain any valid scripts.');
    }
    sort($scripts);
    foreach ($scripts as $current) {
        include_once "{$lib}/setup/{$current}";
    }
} else {
    message('<h1>Welcome to Pie!</h1>
<p>This process is going to set up a new working environment for you, or, in case of an already existing environment, will try to upgrade your system to the version at hand. The necessary procedure will take just a couple of moments.</p>
<p>Please make sure that directory <samp>' . $run . '</samp> (the directory you specified as your run-time working directory) exists and is writable by the web server.</p>
<p>If you want to fine-tune your configuration before starting the setup process, please make the necessary changes to file <samp>' . $config . '</samp> (the file that is set as your configuration file). If you want to modify the location of the configuration file, please do so by editing <samp>' . $_SERVER['SCRIPT_FILENAME'] . '</samp>.</p>
</div>
<div class="centered">
<form action="' . $_SERVER['PHP_SELF'] . '">
<input type="hidden" name="action" value="setup" />
<input type="hidden" name="go" value="1" />