Example #1
0
            }
        }
    }
}
if (isset($_GET["remote"])) {
    if (is_numeric($_GET["remote"])) {
        if ($_GET["remote"] == -42) {
            echo file_get_contents($destination);
        } else {
            if (($s = DBSiteInfo($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"])) == null) {
                ForceLoad("index.php");
            }
            $level = $s["sitescorelevel"];
            $score = array();
            if ($level > 0) {
                list($score, $data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], 1, -1, $_GET["remote"]);
            }
            echo base64_encode(serialize($score));
        }
    } else {
        echo base64_encode(serialize(array()));
    }
    exit;
}
if (!$redo) {
    $conf = globalconf();
    $strtmp = decryptData(substr($strtmp, strpos($strtmp, "\n")), $conf["key"], 'score');
    if ($strtmp == "") {
        $redo = TRUE;
    }
}
Example #2
0
function DBScore($contest, $verifylastmile, $hor = -1, $globalsite = '0')
{
    $c = DBConnect();
    $r = DBExec($c, "select sitenumber as number from sitetable where contestnumber={$contest} and siteactive='t'", "DBScore(get site)");
    $n = DBnlines($r);
    if ($n == 0) {
        LOGError("Unable to get site information. No active sites available (contest={$contest})");
        MSGError("Unable to get site information. No active sites available. Contact an admin now!");
        exit;
    }
    $a = array();
    $resp = array();
    $whichsites = explode(',', $globalsite);
    for ($i = 0; $i < $n; $i++) {
        $a = DBRow($r, $i);
        if (in_array($a["number"], $whichsites) || in_array(0, $whichsites)) {
            list($resp1, $data0) = DBScoreSite($contest, $a["number"], $verifylastmile, $hor);
            $resp = array_merge($resp, $resp1);
        }
    }
    $ds = DIRECTORY_SEPARATOR;
    if ($ds == "") {
        $ds = "/";
    }
    $probs = DBGetProblems($contest);
    $nprobs = count($probs);
    $scoreitems = glob($_SESSION['locr'] . $ds . "private" . $ds . "remotescores" . $ds . "score*.dat", GLOB_NOSORT);
    array_multisort(array_map('filemtime', $scoreitems), SORT_NUMERIC, SORT_DESC, $scoreitems);
    foreach ($scoreitems as $fname) {
        $namear = explode('_', $fname);
        $overloadsite = -1;
        if (isset($namear[3]) && trim($namear[2]) != '' && is_numeric($namear[2])) {
            $overloadsite = $namear[2];
        }
        $fc = file_get_contents($fname);
        if (($arr = unserialize(base64_decode($fc))) === false) {
            LOGError("File " . sanitizeText($fname) . " is not compatible");
        } else {
            if (is_array($arr)) {
                if (isset($arr['site'])) {
                    $site = $arr['site'];
                    if ($overloadsite > 0) {
                        $site = $overloadsite;
                    }
                    if (!in_array($site, $whichsites) && !in_array(0, $whichsites)) {
                        continue;
                    }
                    $fine = 1;
                    reset($resp);
                    while (list($e, $c) = each($resp)) {
                        if ($resp[$e]['site'] == $site) {
                            $fine = 0;
                            break;
                        }
                    }
                    if ($fine) {
                        list($arr, $data0) = DBScoreSite($contest, $site, $verifylastmile, $hor, $arr);
                        reset($arr);
                        while (list($ee, $cc) = each($arr)) {
                            if ($site != $arr[$ee]['site']) {
                                $arr[$ee] = null;
                                unset($arr[$ee]);
                            } else {
                                // just to make the color of the other site changed to the color of the problem in this site
                                while (list($e2, $c2) = each($arr[$ee]["problem"])) {
                                    for ($prob = 0; $prob < $nprobs; $prob++) {
                                        if ($probs[$prob]['number'] == $e2) {
                                            $arr[$ee]['problem'][$e2]['color'] = $probs[$prob]['color'];
                                            $arr[$ee]['problem'][$e2]['colorname'] = $probs[$prob]['colorname'];
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        $resp = array_merge($resp, $arr);
                    }
                } else {
                    // old version -- just for compatibility ---
                    while (list($ee, $cc) = each($arr)) {
                        $fine = 1;
                        reset($resp);
                        while (list($e, $c) = each($resp)) {
                            if ($resp[$e]['site'] == $arr[$ee]['site']) {
                                $fine = 0;
                                break;
                            }
                        }
                        if ($fine == 0) {
                            $arr[$ee] = null;
                        } else {
                            // just to make the color of the other site changed to the color of the problem in this site
                            while (list($e2, $c2) = each($arr[$ee]["problem"])) {
                                for ($prob = 0; $prob < $nprobs; $prob++) {
                                    if ($probs[$prob]['number'] == $e2) {
                                        $arr[$ee]['problem'][$e2]['color'] = $probs[$prob]['color'];
                                        $arr[$ee]['problem'][$e2]['colorname'] = $probs[$prob]['colorname'];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    $resp = array_merge($resp, $arr);
                    // ---- end of old version ---
                }
            }
            //		MSGError("got scores from $fname");
        }
    }
    if (($result = ordena($resp)) === false) {
        LOGError("Error while sorting scores (contest={$contest}).");
        MSGError("Error while sorting scores. Contact an admin now!");
    }
    return $result;
}