예제 #1
0
파일: news.php 프로젝트: AnnaOzer/php1_2015
function publishArticle($article)
{
    $res = DBExec('
    INSERT INTO `news`(`title`, `text`, `created`) VALUES (\'' . $article['title'] . '\', \'' . $article['text'] . '\', NOW())
    ');
    return $res;
}
예제 #2
0
        DBExec($c, "rollback work");
        LOGError("Unable to open file (" . basename($fname) . ")");
        MSGError("Unable to open file (" . basename($fname) . ")");
        echo "<script>window.close();</script></html>";
        exit;
    }
    ob_end_flush();
    //  echo "</pre>\n";
    DB_lo_close($lo);
    if ($msg != '') {
        //    echo " <a href=\"#\" onClick=\"window.print()\"><h1>".$_GET["msg"]."</h1></a>";
        echo "\n\n\n" . $msg . "\n";
        echo $msg . "\n";
        echo $msg . "\n";
    }
    DBExec($c, "commit work");
    DBClose($c);
} else {
    header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    if (($str = file_get_contents($fname)) === false) {
        header("Content-type: text/html");
        echo "<html><head><title>View Page</title>";
        MSGError("Unable to open file (" . basename($fname) . ")");
        LOGError("Unable to open file (" . basename($fname) . ")");
        echo "<script>window.close();</script></html>";
        exit;
    }
    header("Content-type: text/plain");
예제 #3
0
     DBExec($c, "commit", "Autojudging(exportcommit)");
     echo "Getting problem package file from local cache: " . $cache . $ds . $run["inputoid"] . "." . $run["inputname"] . "\n";
     $s = file_get_contents($cache . $ds . $run["inputoid"] . "." . $run["inputname"]);
     file_put_contents($dir . $ds . $run["inputname"], decryptData($s, $key));
     $basename = $basenames[$run['inputoid'] . "." . $run["inputname"]];
 } else {
     echo "Downloading problem package file from db into: " . $dir . $ds . $run["inputname"] . "\n";
     if (DB_lo_export($contest, $c, $run["inputoid"], $dir . $ds . $run["inputname"]) === false) {
         DBExec($c, "rollback work", "Autojudging(rollback-input)");
         LogLevel("Autojudging: Unable to export problem package file (run={$number}, site={$site}, contest={$contest})", 1);
         echo "Error exporting problem package file {$run["inputname"]} (contest={$contest}, site={$site}, run={$number})\n";
         DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: unable to export problem package file");
         DBExec($c, "commit", "Autojudging(exportcommit)");
         continue;
     }
     DBExec($c, "commit", "Autojudging(exportcommit)");
     @chmod($dir . $ds . $run["inputname"], 0600);
     @chown($dir . $ds . $run["inputname"], "root");
     echo "Problem package downloaded -- running init scripts to obtain limits and other information\n";
     $zip = new ZipArchive();
     if ($zip->open($dir . $ds . $run["inputname"]) === true) {
         $zip->extractTo($dir . $ds . "problemdata");
         $zip->close();
     } else {
         echo "Failed to unzip the package file -- please check the problem package (maybe it is encrypted?)\n";
         DBGiveUpRunAutojudging($contest, $site, $number, $ip, "error: problem package file is invalid (1)");
         cleardir($dir . $ds . "problemdata");
         continue;
     }
     if (($info = @parse_ini_file($dir . $ds . "problemdata" . $ds . "description" . $ds . 'problem.info')) === false) {
         echo "Problem content missing (description/problem.info) -- please check the problem package\n";
예제 #4
0
function DBNewLanguage($contestnumber, $param, $c = null)
{
    if (isset($param["action"]) && $param["action"] == "delete") {
        return DBDeleteLanguage($contestnumber, $param, $c);
    }
    $ac = array('number', 'name');
    $ac1 = array('updatetime', 'extension');
    $type['number'] = 1;
    $type['updatetime'] = 1;
    $extension = '';
    foreach ($ac as $key) {
        if (!isset($param[$key]) || $param[$key] == "") {
            MSGError("DBNewLanguage param error: {$key} not found");
            return false;
        }
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewLanguage param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $updatetime = -1;
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewLanguage param error: {$key} is not numeric");
                return false;
            }
        }
    }
    $t = time();
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewLanguage(transaction)");
    }
    $sql2 = "select * from langtable where contestnumber={$contestnumber} and langnumber={$number}";
    $r = DBExec($c, $sql2 . " for update", "DBNewLanguage(get lang)");
    $n = DBnlines($r);
    $ret = 1;
    if ($n == 0) {
        DBExec($c, "insert into langtable (contestnumber,langnumber, langname,langextension) values " . "({$contestnumber}, {$number}, '{$name}','{$extension}')", "DBNewLanguage(insert lang)");
        $s = "created";
    } else {
        $lr = DBRow($r, 0);
        $t = $lr['updatetime'];
        if ($updatetime > $t) {
            if ($name != "") {
                DBExec($c, "update langtable set langname='{$name}', updatetime={$updatetime} where contestnumber={$contestnumber} " . "and langnumber={$number}", "DBNewLanguage(update lang)");
            }
            if ($extension != "") {
                DBExec($c, "update langtable set langextension='{$extension}', updatetime={$updatetime} where contestnumber={$contestnumber} " . "and langnumber={$number}", "DBNewLanguage(update lang)");
            }
        }
        $s = "updated";
    }
    if ($cw) {
        DBExec($c, "commit work", "DBNewLanguage(commit)");
    }
    if ($s == "created" || $updatetime > $t) {
        LOGLevel("Language {$number} updated (user="******"usertable"]["usernumber"] . ",site=" . $_SESSION["usertable"]["usersitenumber"] . ",contest={$contestnumber})", 2);
        $ret = 2;
    }
    return $ret;
}
예제 #5
0
파일: flog.php 프로젝트: justomiguel/boca
function DBLogOut($contest, $site, $user, $isadmin = false)
{
    $c = DBConnect();
    $r = DBExec($c, "update usertable set usersession='',usersessionextra='', updatetime=" . time() . ", " . "userlastlogout=" . time() . " where usernumber={$user} and " . "contestnumber={$contest} and usersitenumber={$site}", "DBLogOut(update user)");
    if ($isadmin) {
        list($clockstr, $clocktime) = siteclock();
        if ($clocktime < -600) {
            DBExec($c, "update contesttable set contestunlockkey='' where contestnumber={$contest}", "DBLogOut(update contest)");
            DBExec($c, "update problemtable set problemfullname='', problembasefilename='' where problemfullname !~ '(DEL)' and contestnumber={$contest}", "DBLogOut(update problems)");
            $ds = DIRECTORY_SEPARATOR;
            if ($ds == "") {
                $ds = "/";
            }
            $dir = $_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds;
            foreach (glob($dir . '*') as $file) {
                cleardir($file, false, true);
            }
        }
    }
    LOGLevel("User {$user} (contest={$contest},site={$site}) logged out.", 2);
}
예제 #6
0
파일: fclar.php 프로젝트: sbaldrich/boca
function DBOpenClarsSNS($contest, $site, $st, $order = 'clar')
{
    $c = DBConnect();
    $sql = "select distinct c.clarnumber as number, c.clardatediff as timestamp, c.claranswer as answer, " . "p.problemname as problem, c.clarstatus as status, c.clardata as question, " . "c.clarsitenumber as site, c.clarjudge as judge, c.clarjudgesite as judgesite, " . "c.usernumber as user " . "from clartable as c, problemtable as p " . "where c.contestnumber={$contest} and p.contestnumber=c.contestnumber and " . "c.clarproblem=p.problemnumber";
    if ($site != "x") {
        $str = explode(",", $site);
        $sql .= " and (c.clarstatus='answeredall'";
        for ($i = 0; $i < count($str); $i++) {
            if (is_numeric($str[$i])) {
                $sql .= " or c.clarsitenumber=" . $str[$i];
            }
        }
        $sql .= ")";
    }
    if ($st == 1) {
        $sql .= " and not c.clarstatus ~ 'answered' and not c.clarstatus ~ 'deleted' order by ";
    } else {
        $sql .= " order by ";
    }
    if ($order == "site") {
        $sql .= "c.clarsitenumber,";
    } else {
        if ($order == "status") {
            $sql .= "c.clarstatus,";
        } else {
            if ($order == "judge") {
                $sql .= "c.clarjudge,c.clarjudgesite,";
            } else {
                if ($order == "problem") {
                    $sql .= "p.problemname,";
                } else {
                    if ($order == "user") {
                        $sql .= "c.usernumber,c.clarsitenumber,";
                    }
                }
            }
        }
    }
    if ($st == 1 || $order == "report") {
        $sql .= "c.clarnumber";
    } else {
        $sql .= "c.clardatediff desc";
    }
    $r = DBExec($c, $sql, "DBOpenClarsSNS(get clar/prob)");
    $n = DBnlines($r);
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = DBRow($r, $i);
    }
    return $a;
}
예제 #7
0
파일: fextdata.php 프로젝트: joffilyfe/boca
function generateXML($contest, $localsite = 0, $sites = null, $reduced = false)
{
    $str = "<XML>\n";
    $ac['CONTESTREC'] = array('number' => 'contestnumber', 'name' => 'contestname', 'startdate' => 'conteststartdate', 'duration' => 'contestduration', 'lastmileanswer' => 'contestlastmileanswer', 'lastmilescore' => 'contestlastmilescore', 'penalty' => 'contestpenalty', 'maxfilesize' => 'contestmaxfilesize', 'updatetime' => 'updatetime', 'mainsite' => 'contestmainsite', 'mainsiteurl' => 'contestmainsiteurl', 'keys' => 'contestkeys', 'unlockkey' => 'contestunlockkey', 'updatetime' => 'updatetime');
    if ($localsite > 0) {
        $ac['CONTESTREC']['localsite'] = array($localsite, 2);
    }
    $sql['CONTESTREC'] = "select * from contesttable where contestnumber={$contest}";
    $ac['ANSWERREC'] = array('number' => 'answernumber', 'name' => 'runanswer', 'yes' => 'yes', 'updatetime' => 'updatetime');
    $sql['ANSWERREC'] = "select * from answertable where contestnumber={$contest} and fake='f'";
    $ac['LANGUAGEREC'] = array('number' => 'langnumber', 'name' => 'langname', 'updatetime' => 'updatetime');
    $sql['LANGUAGEREC'] = "select * from langtable where contestnumber={$contest}";
    $ac['PROBLEMREC'] = array('number' => 'problemnumber', 'name' => 'problemname', 'fullname' => 'problemfullname', 'basename' => 'problembasefilename', 'inputfilename' => 'probleminputfilename', 'inputfilepath' => array('probleminputfile', 1), 'solfilename' => 'problemsolfilename', 'solfilepath' => array('problemsolfile', 1), 'descfilename' => 'problemdescfilename', 'descfilepath' => array('problemdescfile', 1), 'tl' => 'problemtimelimit', 'colorname' => 'problemcolorname', 'color' => 'problemcolor', 'fake' => 'fake', 'updatetime' => 'updatetime');
    $sql['PROBLEMREC'] = "select * from problemtable where contestnumber={$contest} and fake='f'";
    $sql['SITEREC'] = "select * from sitetable where contestnumber={$contest}";
    $ac['SITEREC'] = array('sitenumber' => 'sitenumber', 'site' => 'sitenumber', 'number' => 'sitenumber', 'sitename' => 'sitename', 'siteip' => 'siteip', 'siteduration' => 'siteduration', 'sitelastmileanswer' => 'sitelastmileanswer', 'sitelastmilescore' => 'sitelastmilescore', 'sitejudging' => 'sitejudging', 'sitetasking' => 'sitetasking', 'siteautoend' => 'siteautoend', 'siteglobalscore' => 'siteglobalscore', 'siteactive' => 'siteactive', 'sitescorelevel' => 'sitescorelevel', 'sitepermitlogins' => 'sitepermitlogins', 'siteautojudge' => 'siteautojudge', 'sitenextuser' => 'sitenextuser', 'sitenextclar' => 'sitenextclar', 'sitenextrun' => 'sitenextrun', 'sitenexttask' => 'sitenexttask', 'sitemaxtask' => 'sitemaxtask', 'sitechiefname' => 'sitechiefname', 'updatetime' => 'updatetime');
    $sql['SITETIME'] = "select * from sitetimetable where contestnumber={$contest}";
    $ac['SITETIME'] = array('site' => 'sitenumber', 'number' => 'sitenumber', 'start' => 'sitestartdate', 'enddate' => 'siteenddate', 'updatetime' => 'updatetime');
    $sql['USERREC'] = "select * from usertable where contestnumber={$contest}";
    $ac['USERREC'] = array('site' => 'usersitenumber', 'user' => 'usernumber', 'number' => 'usernumber', 'username' => 'username', 'updatetime' => 'updatetime', 'usericpcid' => 'usericpcid', 'userfull' => 'userfullname', 'userdesc' => 'userdesc', 'type' => 'usertype', 'enabled' => 'userenabled', 'multilogin' => 'usermultilogin', 'userip' => 'userip', 'userlastlogin' => 'userlastlogin', 'userlastlogout' => 'userlastlogout', 'permitip' => 'userpermitip', 'updatetime' => 'updatetime');
    if (!$reduced) {
        $sql['CLARREC'] = "select * from clartable where contestnumber={$contest}";
        $ac['CLARREC'] = array('site' => 'clarsitenumber', 'user' => 'usernumber', 'number' => 'clarnumber', 'problem' => 'clarproblem', 'question' => 'clardata', 'clarnumber' => 'clarnumber', 'clardate' => 'clardate', 'clardatediff' => 'clardatediff', 'clardatediffans' => 'clardatediffans', 'claranswer' => 'claranswer', 'clarstatus' => 'clarstatus', 'clarjudge' => 'clarjudge', 'clarjudgesite' => 'clarjudgesite', 'updatetime' => 'updatetime');
        $sql['RUNREC'] = "select * from runtable where contestnumber={$contest}";
        if (is_array($sites)) {
            $sql['RUNREC'] .= " and (1=0";
            foreach ($sites as $k => $v) {
                $sql['RUNREC'] .= " or runsitenumber={$v}";
            }
            $sql['RUNREC'] .= ")";
        }
        $ac['RUNREC'] = array('site' => 'runsitenumber', 'user' => 'usernumber', 'number' => 'runnumber', 'runnumber' => 'runnumber', 'problem' => 'runproblem', 'lang' => 'runlangnumber', 'filename' => 'runfilename', 'filepath' => array('rundata', 1), 'rundate' => 'rundate', 'rundatediff' => 'rundatediff', 'rundatediffans' => 'rundatediffans', 'runanswer' => 'runanswer', 'runstatus' => 'runstatus', 'runjudge' => 'runjudge', 'runjudgesite' => 'runjudgesite', 'runjudge1' => 'runjudge1', 'runjudgesite1' => 'runjudgesite1', 'runanswer1' => 'runanswer1', 'runjudge2' => 'runjudge2', 'runjudgesite2' => 'runjudgesite2', 'runanswer2' => 'runanswer2', 'autoip' => 'autoip', 'autobegindate' => 'autobegindate', 'autoenddate' => 'autoenddate', 'autoanswer' => 'autoanswer', 'autostdout' => array('autostdout', 1), 'autostderr' => array('autostderr', 1), 'updatetime' => 'updatetime');
        $sql['TASKREC'] = "select * from tasktable where contestnumber={$contest}";
        if (is_array($sites)) {
            $sql['TASKREC'] .= " and (1=0";
            foreach ($sites as $k => $v) {
                $sql['TASKREC'] .= " or sitenumber={$v}";
            }
            $sql['TASKREC'] .= ")";
        }
        $ac['TASKREC'] = array('site' => 'sitenumber', 'user' => 'usernumber', 'desc' => 'taskdesc', 'number' => 'tasknumber', 'tasknumber' => 'tasknumber', 'color' => 'color', 'colorname' => 'colorname', 'updatetime' => 'updatetime', 'filename' => 'taskfilename', 'filepath' => array('taskdata', 1), 'sys' => 'tasksystem', 'status' => 'taskstatus', 'taskdate' => 'taskdate', 'taskdatediff' => 'taskdatediff', 'taskdatediffans' => 'taskdatediffans', 'taskstaffnumber' => 'taskstaffnumber', 'taskstaffsite' => 'taskstaffsite');
    }
    $c = DBConnect();
    if ($c == null) {
        return null;
    }
    DBExec($c, "begin work");
    foreach ($ac as $kk => $vv) {
        $r = DBExec($c, $sql[$kk], "generateXML({$kk})");
        $n = DBnLines($r);
        for ($i = 0; $i < $n; $i++) {
            $atual = DBRow($r, $i);
            $str .= "<" . $kk . ">\n";
            foreach ($vv as $key => $val) {
                if (is_array($val)) {
                    if (is_array($val[0])) {
                        if (!isset($atual['site']) || in_array($atual['site'], $val[0])) {
                            if (isset($atual[$val[1]])) {
                                $str .= "  <" . $key . ">" . $atual[$val[1]] . "</" . $key . ">\n";
                            }
                        }
                    }
                    if ($val[1] == 2) {
                        $str .= "  <" . $key . ">" . $val[0] . "</" . $key . ">\n";
                    }
                    if ($val[1] == 1) {
                        if (isset($atual[$val[0]]) && $atual[$val[0]] != '') {
                            if (($lo = DB_lo_open($c, $atual[$val[0]], "r")) !== false) {
                                $str .= "  <" . $key . ">base64:" . base64_encode(DB_lo_read($contest, $lo)) . "</" . $key . ">\n";
                                DB_lo_close($lo);
                            }
                        }
                    }
                } else {
                    if (isset($atual[$val])) {
                        $str .= "  <" . $key . ">" . $atual[$val] . "</" . $key . ">\n";
                    }
                }
            }
            $str .= "</" . $kk . ">\n";
        }
    }
    $str .= "</XML>\n";
    DBExec($c, "commit work", "generateXML(commit)");
    return $str;
}
예제 #8
0
파일: freport.php 프로젝트: sbaldrich/boca
function DBRunReport($contest, $site)
{
    $c = DBConnect();
    $sql = "select r.runnumber as number, u.usernumber as un, u.username as user, r.rundatediff as timestamp, " . "p.problemname as problem, l.langname as language, a.runanswer as answer, a.yes as yes " . "from runtable as r, problemtable as p, langtable as l, answertable as a, usertable as u " . "where r.contestnumber={$contest} and p.contestnumber=r.contestnumber and " . "r.runproblem=p.problemnumber and l.contestnumber=r.contestnumber and " . "l.langnumber=r.runlangnumber and a.answernumber=r.runanswer and " . "a.contestnumber=r.contestnumber and (r.runstatus = 'judged' or r.runstatus = 'judged+') and " . "u.usernumber=r.usernumber and u.contestnumber={$contest} and " . "u.usersitenumber=r.runsitenumber and u.usertype='team'";
    if ($site != "") {
        $sql .= " and r.runsitenumber={$site}";
    }
    $xdados = array();
    $xuser = array();
    $xuserfull = array();
    $xuseryes = array();
    $xproblem = array();
    $xproblemyes = array();
    $xusername = array();
    $r = DBExec($c, "select usernumber as un, username as name, userfullname as fullname " . "from usertable where contestnumber={$contest} " . "and usersitenumber={$site} and " . "usertype='team' and userlastlogin is not null and userenabled='t'", "DBRunReport(get users)");
    $n = DBnlines($r);
    for ($i = 0; $i < $n; $i++) {
        $a = DBRow($r, $i);
        $xusername[$a['un']] = $a['name'];
        $xuserfull[$a['name']] = $a['fullname'];
    }
    ksort($xusername);
    $pr = DBGetProblems($contest);
    for ($i = 0; $i < count($pr); $i++) {
        $xproblem[$pr[$i]['problem']] = 0;
        $xproblemyes[$pr[$i]['problem']] = 0;
        $xcolor[$pr[$i]['problem']] = $pr[$i]['color'];
    }
    $xlanguage = array();
    $xlanguageyes = array();
    $xanswer = array();
    $xtimestamp = array();
    $xtimestampyes = array();
    $r = DBExec($c, $sql, "DBRunReport(get runs)");
    $n = DBnlines($r);
    for ($i = 0; $i < $n; $i++) {
        $a = DBRow($r, $i);
        $xdados[$i] = $a;
        // # of runs by team
        if (isset($xuser[$a['user']])) {
            $xuser[$a['user']]++;
        } else {
            $xuser[$a['user']] = 1;
        }
        // # of runs by problem
        if (isset($xproblem[$a['problem']])) {
            $xproblem[$a['problem']]++;
        } else {
            $xproblem[$a['problem']] = 1;
        }
        if ($a['yes'] == 't') {
            if (isset($xuseryes[$a['user']])) {
                $xuseryes[$a['user']]++;
            } else {
                $xuseryes[$a['user']] = 1;
            }
            $xproblemyes[$a['problem']]++;
        }
        // # of runs by language
        if (isset($xlanguage[$a['language']])) {
            $xlanguage[$a['language']]++;
        } else {
            $xlanguage[$a['language']] = 1;
        }
        if ($a['yes'] == 't') {
            if (isset($xlanguageyes[$a['language']])) {
                $xlanguageyes[$a['language']]++;
            } else {
                $xlanguageyes[$a['language']] = 1;
            }
        }
        // # of runs by answer
        if (isset($xanswer[$a['answer']])) {
            $xanswer[$a['answer']]++;
        } else {
            $xanswer[$a['answer']] = 1;
        }
        // time of the runs
        array_push($xtimestamp, $a['timestamp']);
        if ($a['yes'] == 't') {
            array_push($xtimestampyes, $a['timestamp']);
        }
        // # of runs by answer by problem
        if (isset($xpa[$a['problem']][$a['answer']])) {
            $xpa[$a['problem']][$a['answer']]++;
        } else {
            $xpa[$a['problem']][$a['answer']] = 1;
        }
        // # of runs by language by problem
        if (isset($xpl[$a['problem']][$a['language']])) {
            $xpl[$a['problem']][$a['language']]++;
        } else {
            $xpl[$a['problem']][$a['language']] = 1;
        }
        // # of runs by answer by language
        if (isset($xla[$a['language']][$a['answer']])) {
            $xla[$a['language']][$a['answer']]++;
        } else {
            $xla[$a['language']][$a['answer']] = 1;
        }
        // # of runs by problem by user
        // negative sign means team got an yes for the problem
        if (!isset($xup[$a['user']][$a['problem']])) {
            $xup[$a['user']][$a['problem']] = 0;
        }
        if ($xup[$a['user']][$a['problem']] < 0) {
            $xup[$a['user']][$a['problem']]--;
        } else {
            $xup[$a['user']][$a['problem']]++;
            if ($a['yes'] == 't') {
                $xup[$a['user']][$a['problem']] = -$xup[$a['user']][$a['problem']];
            }
        }
    }
    ksort($xuser);
    ksort($xuseryes);
    ksort($xproblem);
    ksort($xproblemyes);
    ksort($xlanguage);
    ksort($xlanguageyes);
    ksort($xanswer);
    sort($xtimestamp);
    sort($xtimestampyes);
    $x = array('color' => $xcolor, 'user' => $xuser, 'useryes' => $xuseryes, 'username' => $xusername, 'userfull' => $xuserfull, 'problem' => $xproblem, 'problemyes' => $xproblemyes, 'language' => $xlanguage, 'languageyes' => $xlanguageyes, 'answer' => $xanswer, 'timestamp' => $xtimestamp, 'timestampyes' => $xtimestampyes, 'pa' => $xpa, 'pl' => $xpl, 'la' => $xla, 'up' => $xup);
    return $x;
}
예제 #9
0
파일: ftask.php 프로젝트: sbaldrich/boca
function DBJudgedTasks($contest, $site, $user)
{
    $c = DBConnect();
    $r = DBExec($c, "select distinct t.sitenumber as site, t.tasknumber as number, " . "t.taskdatediff as timestamp, t.taskstatus as status, t.taskfilename as filename, " . "t.taskdesc as description, t.updatetime " . "from tasktable as t " . "where t.contestnumber={$contest} and t.taskstaffsite={$site} and " . "t.taskstaffnumber={$user} order by t.updatetime", "DBJudgedTasks(get tasks)");
    $n = DBnlines($r);
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = DBRow($r, $i);
    }
    return $a;
}
예제 #10
0
파일: fbkp.php 프로젝트: sbaldrich/boca
function DBUserBkps($contest, $site, $user)
{
    $c = DBConnect();
    $st = "select distinct r.bkpnumber as number, r.usernumber as usernumber, r.sitenumber as usersitenumber, r.bkpdate as timestamp, " . "r.bkpstatus as status, r.bkpfilename as filename, r.bkpdata as oid, r.bkpsize as size " . "from bkptable as r " . "where r.contestnumber={$contest}";
    if ($site > 0 || $user > 0) {
        $st = $st . " and r.sitenumber={$site} and r.usernumber={$user} and r.bkpstatus='active'";
    }
    $st = $st . " order by r.bkpnumber";
    $r = DBExec($c, $st, "DBUserBkps(get bkps)");
    $n = DBnlines($r);
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = DBRow($r, $i);
    }
    return $a;
}
예제 #11
0
파일: fproblem.php 프로젝트: sbaldrich/boca
function DBGetAllProblems($contest)
{
    if (($b = DBSiteInfo($contest, $_SESSION["usertable"]["usersitenumber"])) == null) {
        return array();
    }
    $c = DBConnect();
    $sql = "select distinct p.problemnumber as number, p.problemname as problem, " . "p.problemcolor as color, p.problemcolorname as colorname " . "from problemtable as p " . "where p.contestnumber={$contest} and p.problemfullname !~ '(DEL)' ";
    if ($b["currenttime"] < 0) {
        $sql .= "and p.fake='t' ";
    }
    $sql .= " order by p.problemnumber";
    $r = DBExec($c, $sql, "DBGetAllProblems(get problems)");
    $n = DBnlines($r);
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = DBRow($r, $i);
    }
    return $a;
}
예제 #12
0
function DBGetTypeProblem($contest, $problemnumber)
{
    /*if (($b = DBSiteInfo($contest,$_SESSION["usertable"]["usersitenumber"])) == null)
    		return array();
    */
    $c = DBConnect();
    $sql = "select p.problemtype as type from problemtable as p where p.problemnumber = {$problemnumber} AND p.contestnumber  = {$contest}";
    /*	$sql = "select distinct p.problemnumber as number, p.problemtype as type " .
    			"from problemtable as p " .
    			"where p.contestnumber=$contest and p.problemfullname !~ '(DEL)' ";
    	if ($b["currenttime"] < 0) $sql .= "and p.fake='t' ";
    	$sql .= " order by p.problemnumber";*/
    $r = DBExec($c, $sql, "DBGetTypeProblem(get problemtype)");
    $n = DBnlines($r);
    $a = array();
    $num = DBRow($r, 0);
    return $num['type'];
}
예제 #13
0
파일: fanswer.php 프로젝트: sbaldrich/boca
function DBNewAnswer($contest, $param, $c = null)
{
    if (isset($param["action"]) && $param["action"] == "delete") {
        return DBDeleteAnswer($contestnumber, $param, $c);
    }
    $ac = array('number', 'name', 'yes');
    $type['number'] = 1;
    foreach ($ac as $key) {
        if (!isset($param[$key])) {
            MSGError("DBNewAnswer param error: {$key} is not set");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewAnswer param error: {$key} is not numeric");
            return false;
        }
    }
    $t = time();
    $updatetime = $t;
    if (isset($param['updatetime']) && is_numeric($param["updatetime"])) {
        $updatetime = $param["updatetime"];
    }
    if ($yes != "t") {
        $y = "f";
    } else {
        $y = "t";
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewAnswer(transaction)");
    }
    $r = DBExec($c, "select * from answertable as a where a.contestnumber={$contest} and a.answernumber={$number} for update", "DBNewAnswer(get answer)");
    $n = DBnlines($r);
    $ret = 1;
    if ($n == 0) {
        $ret = 2;
        DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, updatetime) values " . "({$contest}, {$number}, '{$name}', '{$y}', {$t})", "DBNewAnswer(insert answer)");
        if ($cw) {
            DBExec($c, "commit work", "DBNewAnswer(commit)");
        }
        LOGLevel("Answer {$number} inserted (contest={$contest},user="******"usertable"]["username"] . "/" . $_SESSION["usertable"]["usersitenumber"] . ")", 2);
    } else {
        $lr = DBRow($r, 0);
        if ($updatetime > $lr['updatetime']) {
            $ret = 2;
            DBExec($c, "update answertable set runanswer='{$name}', yes='{$y}', updatetime=" . $updatetime . " where " . "contestnumber={$contest} and answernumber={$number} and fake='f'", "DBNewAnswer(update answer)");
            if ($cw) {
                DBExec($c, "commit work", "DBNewAnswer(commit)");
            }
            LOGLevel("Answer {$number} updated (contest={$contest},user="******"usertable"]["username"] . "/" . $_SESSION["usertable"]["usersitenumber"] . ")", 2);
        } else {
            if ($cw) {
                DBExec($c, "commit work", "DBNewAnswer(commit)");
            }
        }
    }
    return $ret;
}
예제 #14
0
파일: news.php 프로젝트: AnnaOzer/shp-php2
function News_updateOneById($article)
{
    return DBExec("\n    UPDATE `news` SET `title`='" . $article['title'] . "', `text`='" . $article['text'] . "'  WHERE id='" . $article['id'] . "'\n    ");
}
예제 #15
0
파일: index.php 프로젝트: sbaldrich/boca
<?php

require '../../db.php';
require '../config.php';
header('Content-type: text/plain; encoding=utf-8');
$ct = DBContestInfo($contest);
echo $ct['contestname'] . "\n";
echo $ct['contestduration'] / 60 . '' . $ct['contestlastmileanswer'] / 60 . '' . $ct['contestlastmilescore'] / 60 . '' . $ct['contestpenalty'] / 60 . "\n";
$c = DBConnect();
$r = DBExec($c, 'SELECT problemnumber FROM problemtable' . ' WHERE contestnumber = ' . $contest . ' AND problemnumber > 0');
$numProblems = DBnlines($r);
$r = DBExec($c, 'SELECT username, userfullname FROM usertable' . ' WHERE contestnumber = ' . $contest . ' AND userenabled = \'t\' AND usersitenumber = ' . $site . ' AND usertype = \'team\'');
$numTeams = DBnlines($r);
echo $numTeams . '' . $numProblems . "\n";
for ($i = 0; $i < $numTeams; $i++) {
    $a = DBRow($r, $i);
    $teamID = $a['username'];
    if (isset($a['usershortname'])) {
        $teamName = $a['usershortname'];
    } else {
        $teamName = $a['userfullname'];
    }
    if (isset($a['usershortinstitution'])) {
        $teamUni = $a['usershortinstitution'];
    } else {
        $teamUni = $teamName;
    }
    echo $teamID . '' . $teamUni . '' . $teamName . "\n";
}
echo '1' . '' . '1' . "\n";
echo $numProblems . '' . 'Y' . "\n";
예제 #16
0
파일: db.php 프로젝트: joffilyfe/boca
function DBcrc($contest, $id, $c = null)
{
    $docommit = false;
    if ($c == null) {
        $docommit = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBcrc(begin)");
    }
    if (($f = DB_lo_open($c, $id, "r")) === false) {
        if ($docommit) {
            DBExec($c, "commit work", "DBcrc(commit)");
        }
        // just to return a unique string that will not match any other...
        return "no-HASH-" . rand() . "-" . rand() . "-" . time();
    }
    $str = DB_lo_read($contest, $f);
    DB_lo_close($f);
    if ($docommit) {
        DBExec($c, "commit work", "DBcrc(commit)");
    }
    return myshorthash($str);
}
예제 #17
0
파일: fcontest.php 프로젝트: sbaldrich/boca
function DBNewUser($param, $c = null)
{
    if (isset($param['contestnumber']) && !isset($param['contest'])) {
        $param['contest'] = $param['contestnumber'];
    }
    if (isset($param['sitenumber']) && !isset($param['site'])) {
        $param['site'] = $param['sitenumber'];
    }
    if (isset($param['usernumber']) && !isset($param['user'])) {
        $param['user'] = $param['usernumber'];
    }
    if (isset($param['number']) && !isset($param['user'])) {
        $param['user'] = $param['number'];
    }
    $ac = array('contest', 'site', 'user');
    $ac1 = array('updatetime', 'username', 'usericpcid', 'userfull', 'userdesc', 'type', 'enabled', 'multilogin', 'pass', 'permitip', 'changepass', 'userip', 'userlastlogin', 'userlastlogout', 'usersession', 'usersessionextra');
    $typei['contest'] = 1;
    $typei['updatetime'] = 1;
    $typei['site'] = 1;
    $typei['user'] = 1;
    foreach ($ac as $key) {
        if (!isset($param[$key]) || $param[$key] == "") {
            MSGError("DBNewUser param error: {$key} not found");
            return false;
        }
        if (isset($typei[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewUser param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $username = "******" . $user;
    $updatetime = -1;
    $pass = null;
    $usericpcid = '';
    $userfull = '';
    $userdesc = '';
    $type = 'team';
    $enabled = 'f';
    $changepass = '******';
    $multilogin = '******';
    $permitip = '';
    $usersession = null;
    $usersessionextra = null;
    $userip = null;
    $userlastlogin = null;
    $userlastlogout = null;
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($typei[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewUser param error: {$key} is not numeric");
                return false;
            }
        }
    }
    $t = time();
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    if ($type != "chief" && $type != "judge" && $type != "admin" && $type != "score" && $type != "staff" && $type != "site") {
        $type = "team";
    }
    if ($type == "admin") {
        $changepass = "******";
    }
    if ($enabled != "f") {
        $enabled = "t";
    }
    if ($multilogin != "t") {
        $multilogin = "******";
    }
    if ($changepass != "t") {
        $changepass = "******";
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewUser(begin)");
    }
    DBExec($c, "lock table usertable", "DBNewUser(lock)");
    $r = DBExec($c, "select * from sitetable where sitenumber={$site} and contestnumber={$contest}", "DBNewUser(get site)");
    $n = DBnlines($r);
    if ($n == 0) {
        DBExec($c, "rollback work", "DBNewUser(no-site)");
        MSGError("DBNewUser param error: site {$site} does not exist");
        return false;
    }
    if ($pass != myhash("") && $type != "admin" && $changepass != "t") {
        $pass = '******' . $pass;
    }
    $r = DBExec($c, "select * from usertable where username='******' and usernumber!={$user} and " . "usersitenumber={$site} and contestnumber={$contest}", "DBNewUser(get user)");
    $n = DBnlines($r);
    $ret = 1;
    if ($n == 0) {
        $sql = "select * from usertable where usernumber={$user} and usersitenumber={$site} and " . "contestnumber={$contest}";
        $a = DBGetRow($sql, 0, $c);
        if ($a == null) {
            $ret = 2;
            $sql = "select * from sitetable where sitenumber={$site} and contestnumber={$contest}";
            $aa = DBGetRow($sql, 0);
            if ($aa == null) {
                DBExec($c, "rollback work");
                MSGError("Site {$site} does not exist");
                return false;
            }
            $sql = "insert into usertable (contestnumber, usersitenumber, usernumber, username, usericpcid, userfullname, " . "userdesc, usertype, userenabled, usermultilogin, userpassword, userpermitip) values " . "({$contest}, {$site}, {$user}, '{$username}', '{$usericpcid}', '{$userfull}', '{$userdesc}', '{$type}', '{$enabled}', " . "'{$multilogin}', '{$pass}', '{$permitip}')";
            DBExec($c, $sql, "DBNewUser(insert)");
            if ($cw) {
                DBExec($c, "commit work");
            }
            LOGLevel("User {$user} (site={$site},contest={$contest}) included.", 2);
        } else {
            if ($updatetime > $a['updatetime']) {
                $ret = 2;
                $sql = "update usertable set username='******', usericpcid='{$usericpcid}', userdesc='{$userdesc}', updatetime={$updatetime}, " . "userfullname='{$userfull}', usertype='{$type}', userpermitip='{$permitip}', ";
                if ($pass != null && $pass != myhash("")) {
                    $sql .= "userpassword='******', ";
                }
                if ($usersession != null) {
                    $sql .= "usersession='{$usersession}', ";
                }
                if ($usersessionextra != null) {
                    $sql .= "usersessionextra='{$usersessionextra}', ";
                }
                if ($userip != null) {
                    $sql .= "userip='{$userip}', ";
                }
                if ($userlastlogin != null) {
                    $sql .= "userlastlogin='******', ";
                }
                if ($userlastlogout != null) {
                    $sql .= "userlastlogout='{$userlastlogout}', ";
                }
                $sql .= "userenabled='{$enabled}', usermultilogin='******'";
                $sql .= " where usernumber={$user} and usersitenumber={$site} and contestnumber={$contest}";
                $r = DBExec($c, $sql, "DBNewUser(update)");
                if ($cw) {
                    DBExec($c, "commit work");
                }
                LOGLevel("User {$user} (username={$username},site={$site},contest={$contest}) updated.", 2);
            }
        }
    } else {
        DBExec($c, "rollback work");
        LOGLevel("Update problem for user {$user} (site={$site},contest={$contest}) (maybe username already in use).", 1);
        MSGError("Update problem for user {$user}, site {$site} (maybe username already in use).");
        return false;
    }
    return $ret;
}
예제 #18
0
function GetExternalData($contest)
{
    $c = DBConnect();
    if ($c == null) {
        return;
    }
    $r = DBExec($c, "select * from contesttable where contestnumber={$contest}");
    if (DBnLines($r) == 0) {
        echo "Unable to find the contest {$contest} in the database.\n";
        exit;
    }
    $ct = DBRow($r, 0);
    $localsite = $ct["contestlocalsite"];
    $mainsite = $ct["contestmainsite"];
    if ($mainsite != $localsite) {
        $r = DBExec($c, "select * from sitetable where sitenumber=" . $ct["contestmainsite"] . " and contestnumber={$contest}");
        if (DBnLines($r) == 0) {
            echo "Unable to find the main site in the database (site={$site}, contest={$contest}).\n";
            exit;
        }
        $st = DBRow($r, 0);
        if (($t = DBExtConnect($c, $contest, $st["sitenumber"])) != null) {
            DBExec($c, "begin work");
            // sincronizando contest
            $r = DBExec($t, "select * from contesttable where contestnumber={$contest}");
            $n = DBnLines($r);
            $atual = DBRow($r, 0);
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            DBExec($c, "update contesttable set " . "contestduration=" . $atual["contestduration"] . "," . "conteststartdate=" . $atual["conteststartdate"] . "," . "contestmaxfilesize=" . $atual["contestmaxfilesize"] . "," . "contestactive='" . $atual["contestactive"] . "'," . "contestname='" . escape_string($atual["contestname"]) . "'," . "contestlastmileanswer=" . $atual["contestlastmileanswer"] . "," . "contestlastmilescore=" . $atual["contestlastmilescore"] . "," . "contestpenalty=" . $atual["contestpenalty"] . "," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and updatetime<" . $atual["updatetime"]);
            // sincronizando answers
            $r = DBExec($t, "select * from answertable where contestnumber={$contest}");
            $rr = DBExec($c, "select * from answertable where contestnumber={$contest} for update");
            $n = DBnLines($r);
            $nn = DBnLines($rr);
            echo "answers: external(site={$mainsite}, reading={$mainsite})={$n}, local={$nn}\n";
            for ($k = 0; $k < $nn; $k++) {
                $needed[$k] = false;
            }
            for ($j = 0; $j < $n; $j++) {
                $la = DBRow($r, $j);
                for ($k = 0; $k < $nn; $k++) {
                    $aqui = DBRow($rr, $k);
                    if ($la["answernumber"] == $aqui["answernumber"] && $la["contestnumber"] == $aqui["contestnumber"]) {
                        $needed[$k] = true;
                        if ($la["updatetime"] > $aqui["updatetime"]) {
                            $situacao[$j] = "atualizar";
                        } else {
                            $situacao[$j] = "ok";
                        }
                        break;
                    }
                }
                if ($k >= $nn) {
                    $situacao[$j] = "inserir";
                }
            }
            $del = 0;
            $upd = 0;
            $ins = 0;
            for ($k = 0; $k < $nn; $k++) {
                $atual = DBRow($rr, $k);
                if (!$needed[$k]) {
                    DBExec($c, "delete from answertable where contestnumber={$contest} and answernumber=" . $atual["answernumber"]);
                    $del++;
                }
            }
            for ($j = 0; $j < $n; $j++) {
                $atual = DBRow($r, $j);
                if ($atual["updatetime"] == "") {
                    $atual["updatetime"] = time();
                }
                if ($situacao[$j] == "atualizar") {
                    $upd++;
                    DBExec($c, "update answertable set " . "runanswer='" . $atual["runanswer"] . "'," . "yes='" . $atual["yes"] . "'," . "fake='" . $atual["fake"] . "'," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and answernumber=" . $atual["answernumber"] . " and updatetime<" . $atual["updatetime"]);
                } else {
                    if ($situacao[$j] == "inserir") {
                        $ins++;
                        DBExec($c, "insert into answertable (contestnumber, answernumber, runanswer, yes, fake, updatetime) values (" . $contest . "," . $atual["answernumber"] . ",'" . $atual["runanswer"] . "','" . $atual["yes"] . "'," . "'" . $atual["fake"] . "'," . $atual["updatetime"] . ")");
                    }
                }
            }
            echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
            // sincronizando languages
            $r = DBExec($t, "select * from langtable where contestnumber={$contest}");
            $rr = DBExec($c, "select * from langtable where contestnumber={$contest} for update");
            $n = DBnLines($r);
            $nn = DBnLines($rr);
            echo "languages: external(site={$mainsite}, reading={$mainsite})={$n}, local={$nn}\n";
            for ($k = 0; $k < $nn; $k++) {
                $needed[$k] = false;
            }
            for ($j = 0; $j < $n; $j++) {
                $la = DBRow($r, $j);
                for ($k = 0; $k < $nn; $k++) {
                    $aqui = DBRow($rr, $k);
                    if ($la["langnumber"] == $aqui["langnumber"] && $la["contestnumber"] == $aqui["contestnumber"]) {
                        $needed[$k] = true;
                        if ($la["updatetime"] > $aqui["updatetime"]) {
                            $situacao[$j] = "atualizar";
                        } else {
                            $situacao[$j] = "ok";
                        }
                        break;
                    }
                }
                if ($k >= $nn) {
                    $situacao[$j] = "inserir";
                }
            }
            $del = 0;
            $upd = 0;
            $ins = 0;
            for ($k = 0; $k < $nn; $k++) {
                $atual = DBRow($rr, $k);
                if (!$needed[$k]) {
                    DBExec($c, "delete from langtable where contestnumber={$contest} and langnumber=" . $atual["langnumber"]);
                    $del++;
                }
            }
            for ($j = 0; $j < $n; $j++) {
                $atual = DBRow($r, $j);
                if ($atual["updatetime"] == "") {
                    $atual["updatetime"] = time();
                }
                if ($situacao[$j] == "atualizar") {
                    $upd++;
                    DBExec($c, "update langtable set " . "langname='" . escape_string($atual["langname"]) . "'," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and langnumber=" . $atual["langnumber"] . " and updatetime<" . $atual["updatetime"]);
                } else {
                    if ($situacao[$j] == "inserir") {
                        $ins++;
                        DBExec($c, "insert into langtable (contestnumber, langnumber, langname, updatetime) values ({$contest}," . $atual["langnumber"] . ",'" . escape_string($atual["langname"]) . "'," . $atual["updatetime"] . ")");
                    }
                }
            }
            echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
            // sincronizando problems
            $r = DBExec($t, "select * from problemtable where contestnumber={$contest}");
            $rr = DBExec($c, "select * from problemtable where contestnumber={$contest} for update");
            $n = DBnLines($r);
            $nn = DBnLines($rr);
            echo "problems: external(site={$mainsite}, reading={$mainsite})={$n}, local={$nn}\n";
            for ($k = 0; $k < $nn; $k++) {
                $needed[$k] = false;
            }
            for ($j = 0; $j < $n; $j++) {
                $la = DBRow($r, $j);
                for ($k = 0; $k < $nn; $k++) {
                    $aqui = DBRow($rr, $k);
                    if ($la["problemnumber"] == $aqui["problemnumber"] && $la["contestnumber"] == $aqui["contestnumber"]) {
                        $needed[$k] = true;
                        if ($la["updatetime"] > $aqui["updatetime"]) {
                            $situacao[$j] = "atualizar";
                        } else {
                            $situacao[$j] = "ok";
                        }
                        break;
                    }
                }
                if ($k >= $nn) {
                    $situacao[$j] = "inserir";
                }
            }
            $del = 0;
            $upd = 0;
            $ins = 0;
            for ($k = 0; $k < $nn; $k++) {
                $atual = DBRow($rr, $k);
                if (!$needed[$k]) {
                    DBExec($c, "delete from problemtable where contestnumber={$contest} and problemnumber=" . $atual["problemnumber"]);
                    $del++;
                }
            }
            for ($j = 0; $j < $n; $j++) {
                $atual = DBRow($r, $j);
                if ($atual["updatetime"] == "") {
                    $atual["updatetime"] = time();
                }
                if ($situacao[$j] == "inserir") {
                    $ins++;
                    $upd--;
                    DBExec($c, "insert into problemtable (contestnumber, problemnumber, problemname, updatetime) values ({$contest}," . $atual["problemnumber"] . ",'" . escape_string($atual["problemname"]) . "', 0)");
                }
                if ($situacao[$j] == "atualizar" || $situacao[$j] == "inserir") {
                    $upd++;
                    $p = DBRow($r2, 0);
                    if ($p["probleminputfile"] > 0) {
                        DB_lo_unlink($c, $p["probleminputfile"]);
                    }
                    if ($p["problemsolfile"] > 0) {
                        DB_lo_unlink($c, $p["problemsolfile"]);
                    }
                    DBExec($t, "begin work");
                    if ($atual["probleminputfile"] == "") {
                        $inputfile = "null";
                    } else {
                        $in = DB_lo_open($t, $atual["probleminputfile"], "r");
                        if (!$in) {
                            $inputfile = "null";
                        } else {
                            $inputfile = DB_lo_create($c);
                            $out = DB_lo_open($c, $inputfile, "w");
                            while (($buf = DB_lo_read($in, 100000)) != false) {
                                DB_lo_write($out, $buf);
                            }
                            DB_lo_close($out);
                            DB_lo_close($in);
                        }
                    }
                    if ($atual["problemsolfile"] == "") {
                        $solfile = "null";
                    } else {
                        $in = DB_lo_open($t, $atual["problemsolfile"], "r");
                        if (!$in) {
                            $solfile = "null";
                        } else {
                            $solfile = DB_lo_create($c);
                            $out = DB_lo_open($c, $solfile, "w");
                            while (($buf = DB_lo_read($in, 100000)) != false) {
                                DB_lo_write($out, $buf);
                            }
                            DB_lo_close($out);
                            DB_lo_close($in);
                        }
                    }
                    DBExec($t, "commit work");
                    DBExec($c, "update problemtable set " . "problemname='" . escape_string($atual["problemname"]) . "'," . "problemfullname='" . escape_string($atual["problemfullname"]) . "'," . "problembasefilename='" . escape_string($atual["problembasefilename"]) . "'," . "probleminputfilename='" . escape_string($atual["probleminputfilename"]) . "'," . "problemsolfilename='" . escape_string($atual["problemsolfilename"]) . "'," . "fake='" . $atual["fake"] . "'," . "probleminputfile=" . $inputfile . "," . "problemsolfile=" . $solfile . "," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and problemnumber=" . $atual["problemnumber"] . " and updatetime<" . $atual["updatetime"]);
                }
            }
            echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
            DBExec($c, "commit work");
        }
    }
    $r = DBExec($c, "select * from sitetable where contestnumber={$contest}");
    $n = DBnlines($r);
    if ($n == 0) {
        echo "Unable to find sites in the database.\n";
        exit;
    }
    $st = array();
    for ($i = 0; $i < $n; $i++) {
        $st[$i] = DBRow($r, $i);
    }
    for ($i = 0; $i < count($st); $i++) {
        $site = $st[$i]["sitenumber"];
        if ($site == $ct["contestlocalsite"]) {
            continue;
        }
        if (($t = DBExtConnect($c, $contest, $site)) == null) {
            continue;
        }
        DBExec($c, "begin work");
        // sincronizando site
        $r = DBExec($t, "select * from sitetable where contestnumber={$contest} and sitenumber={$site}");
        $rr = DBExec($c, "select * from sitetable where contestnumber={$contest} and sitenumber={$site} for update");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        $atual = DBRow($r, 0);
        $p = DBRow($rr, 0);
        //		if ($p["updatetime"]<$atual["updatetime"]) {
        if ($atual["sitestartdate"] == "") {
            $atual["sitestartdate"] = "null";
        }
        if ($atual["sitelastmilescore"] == "") {
            $atual["sitelastmilescore"] = "null";
        }
        if ($atual["sitelastmileanswer"] == "") {
            $atual["sitelastmileanswer"] = "null";
        }
        if ($atual["siteenddate"] == "") {
            $atual["siteenddate"] = "null";
        }
        if ($atual["siteendeddate"] == "") {
            $atual["siteendeddate"] = "null";
        }
        if ($atual["siteautoend"] != "t") {
            $atual["siteautoend"] = "f";
        }
        if ($atual["updatetime"] == "") {
            $atual["updatetime"] = time();
        }
        DBExec($c, "update sitetable set " . "sitename='" . escape_string($atual["sitename"]) . "'," . "siteactive='" . escape_string($atual["siteactive"]) . "'," . "sitepermitlogins='" . escape_string($atual["sitepermitlogins"]) . "'," . "sitestartdate=" . $atual["sitestartdate"] . "," . "sitelastmilescore=" . $atual["sitelastmilescore"] . "," . "sitelastmileanswer=" . $atual["sitelastmileanswer"] . "," . "siteenddate=" . $atual["siteenddate"] . "," . "siteendeddate=" . $atual["siteendeddate"] . "," . "siteautoend='" . escape_string($atual["siteautoend"]) . "'," . "sitejudging='" . escape_string($atual["sitejudging"]) . "'," . "siteglobalscore='" . escape_string($atual["siteglobalscore"]) . "'," . "sitescorelevel=" . $atual["sitescorelevel"] . "," . "sitenextuser="******"sitenextuser"] . "," . "sitenextclar=" . $atual["sitenextclar"] . "," . "sitenextrun=" . $atual["sitenextrun"] . "," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and sitenumber=" . $atual["sitenumber"]);
        //				." and updatetime<".$atual["updatetime"]);
        //		}
        // sincronizando users
        $r = DBExec($t, "select * from usertable where contestnumber={$contest} and usersitenumber={$site}");
        $rr = DBExec($c, "select * from usertable where contestnumber={$contest} and usersitenumber={$site}");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        echo "users: external(site={$site}, reading={$site})={$n}, local={$nn}\n";
        for ($k = 0; $k < $nn; $k++) {
            $needed[$k] = false;
        }
        for ($j = 0; $j < $n; $j++) {
            $la = DBRow($r, $j);
            for ($k = 0; $k < $nn; $k++) {
                $aqui = DBRow($rr, $k);
                if ($la["usernumber"] == $aqui["usernumber"] && $la["contestnumber"] == $aqui["contestnumber"] && $la["usersitenumber"] == $aqui["usersitenumber"]) {
                    $needed[$k] = true;
                    if ($la["updatetime"] > $aqui["updatetime"]) {
                        $situacao[$j] = "atualizar";
                    } else {
                        $situacao[$j] = "ok";
                    }
                    break;
                }
            }
            if ($k >= $nn) {
                $situacao[$j] = "inserir";
            }
        }
        $del = 0;
        for ($k = 0; $k < $nn; $k++) {
            $atual = DBRow($rr, $k);
            if (!$needed[$k]) {
                DBExec($c, "delete from usertable where contestnumber={$contest} and usersitenumber={$site} and usernumber=" . $atual["usernumber"]);
                $del++;
            }
        }
        $upd = 0;
        $ins = 0;
        for ($j = 0; $j < $n; $j++) {
            $atual = DBRow($r, $j);
            if ($atual["userlastlogin"] == "") {
                $atual["userlastlogin"] = "******";
            }
            if ($atual["userlastlogout"] == "") {
                $atual["userlastlogout"] = "null";
            }
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            if ($situacao[$j] == "atualizar") {
                DBExec($c, "update usertable set " . "username='******'," . "userfullname='" . escape_string($atual["userfullname"]) . "'," . "userdesc='" . escape_string($atual["userdesc"]) . "'," . "usertype='" . escape_string($atual["usertype"]) . "'," . "userenabled='" . $atual["userenabled"] . "'," . "usermultilogin='******'," . "userpassword='******'," . "userip='" . $atual["userip"] . "'," . "userlastlogin="******"userlastlogin"] . "," . "userlastlogout=" . $atual["userlastlogout"] . "," . "usersession='" . $atual["usersession"] . "'," . "userpermitip='" . $atual["userpermitip"] . "'," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and usersitenumber=" . $atual["usersitenumber"] . " and usernumber=" . $atual["usernumber"] . " and updatetime<" . $atual["updatetime"]);
                $upd++;
            } else {
                if ($situacao[$j] == "inserir") {
                    DBExec($c, "insert into usertable (username, userfullname, userdesc, usertype, userenabled, usermultilogin, " . "userpassword, userip, userlastlogin, userlastlogout, usersession, userpermitip, updatetime, " . "contestnumber, usersitenumber, usernumber) values (" . "'" . escape_string($atual["username"]) . "'," . "'" . escape_string($atual["userfullname"]) . "'," . "'" . escape_string($atual["userdesc"]) . "'," . "'" . $atual["usertype"] . "'," . "'" . $atual["userenabled"] . "'," . "'" . $atual["usermultilogin"] . "'," . "'" . $atual["userpassword"] . "'," . "'" . $atual["userip"] . "'," . $atual["userlastlogin"] . "," . $atual["userlastlogout"] . "," . "'" . $atual["usersession"] . "'," . "'" . $atual["userpermitip"] . "'," . $atual["updatetime"] . ",{$contest}," . $atual["usersitenumber"] . "," . $atual["usernumber"] . ")");
                    $ins++;
                }
            }
        }
        echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
        // sincronizando clars
        $r = DBExec($t, "select * from clartable where contestnumber={$contest} and clarsitenumber={$site}");
        $rr = DBExec($c, "select * from clartable where contestnumber={$contest} and clarsitenumber={$site}");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        echo "clars: external(site={$site}, reading={$site})={$n}, local={$nn}\n";
        for ($k = 0; $k < $nn; $k++) {
            $needed[$k] = false;
        }
        for ($j = 0; $j < $n; $j++) {
            $la = DBRow($r, $j);
            for ($k = 0; $k < $nn; $k++) {
                $aqui = DBRow($rr, $k);
                if ($la["clarnumber"] == $aqui["clarnumber"] && $la["contestnumber"] == $aqui["contestnumber"] && $la["clarsitenumber"] == $aqui["clarsitenumber"]) {
                    $needed[$k] = true;
                    if ($la["updatetime"] > $aqui["updatetime"]) {
                        $situacao[$j] = "atualizar";
                    } else {
                        $situacao[$j] = "ok";
                    }
                    break;
                }
            }
            if ($k >= $nn) {
                $situacao[$j] = "inserir";
            }
        }
        $del = 0;
        for ($k = 0; $k < $nn; $k++) {
            $atual = DBRow($rr, $k);
            if (!$needed[$k]) {
                DBExec($c, "delete from clartable where contestnumber={$contest} and clarsitenumber={$site} and clarnumber=" . $atual["clarnumber"]);
                $del++;
            }
        }
        $upd = 0;
        $ins = 0;
        for ($j = 0; $j < $n; $j++) {
            $atual = DBRow($r, $j);
            if ($atual["claranswer"] == "") {
                $atual["claranswer"] = "null";
            } else {
                $atual["claranswer"] = "'" . escape_string($atual["claranswer"]) . "'";
            }
            if ($atual["clarjudge"] == "") {
                $atual["clarjudge"] = "null";
            }
            if ($atual["clarjudgesite"] == "") {
                $atual["clarjudgesite"] = "null";
            }
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            if ($situacao[$j] == "atualizar") {
                DBExec($c, "update clartable set " . "usernumber=" . $atual["usernumber"] . "," . "clardate=" . $atual["clardate"] . "," . "clardatediff=" . $atual["clardatediff"] . "," . "clardatediffans=" . $atual["clardatediffans"] . "," . "clarproblem=" . $atual["clarproblem"] . "," . "clardata='" . escape_string($atual["clardata"]) . "'," . "claranswer=" . $atual["claranswer"] . "," . "clarstatus='" . escape_string($atual["clarstatus"]) . "'," . "clarjudge=" . $atual["clarjudge"] . "," . "clarjudgesite=" . $atual["clarjudgesite"] . "," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and clarsitenumber=" . $atual["clarsitenumber"] . " and clarnumber=" . $atual["clarnumber"] . " and updatetime<" . $atual["updatetime"]);
                $upd++;
            } else {
                if ($situacao[$j] == "inserir") {
                    DBExec($c, "insert into clartable (contestnumber, clarsitenumber, clarnumber, usernumber, clardate," . "clardatediff, clardatediffans, clarproblem, clardata, claranswer, clarstatus, clarjudge, clarjudgesite, updatetime) " . "values (" . $contest . "," . $atual["clarsitenumber"] . "," . $atual["clarnumber"] . "," . $atual["usernumber"] . "," . $atual["clardate"] . "," . $atual["clardatediff"] . "," . $atual["clardatediffans"] . "," . $atual["clarproblem"] . "," . "'" . escape_string($atual["clardata"]) . "'," . $atual["claranswer"] . "," . "'" . escape_string($atual["clarstatus"]) . "'," . $atual["clarjudge"] . "," . $atual["clarjudgesite"] . "," . $atual["updatetime"] . ")");
                    $ins++;
                }
            }
        }
        echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
        // sincronizando clars
        $r = DBExec($t, "select * from clartable where contestnumber={$contest} and clarsitenumber={$localsite}");
        $rr = DBExec($c, "select * from clartable where contestnumber={$contest} and clarsitenumber={$localsite}");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        echo "clars: external(site={$site}, reading={$localsite})={$n}, local={$nn}\n";
        for ($k = 0; $k < $nn; $k++) {
            $needed[$k] = false;
        }
        for ($j = 0; $j < $n; $j++) {
            $la = DBRow($r, $j);
            for ($k = 0; $k < $nn; $k++) {
                $aqui = DBRow($rr, $k);
                if ($la["clarnumber"] == $aqui["clarnumber"] && $la["contestnumber"] == $aqui["contestnumber"] && $la["clarsitenumber"] == $aqui["clarsitenumber"]) {
                    $needed[$k] = true;
                    if ($la["updatetime"] > $aqui["updatetime"]) {
                        $situacao[$j] = "atualizar";
                    } else {
                        $situacao[$j] = "ok";
                    }
                    break;
                }
            }
            if ($k >= $nn) {
                $situacao[$j] = "inserir";
            }
        }
        $upd = 0;
        $ins = 0;
        for ($j = 0; $j < $n; $j++) {
            $atual = DBRow($r, $j);
            if ($atual["claranswer"] == "") {
                $atual["claranswer"] = "null";
            } else {
                $atual["claranswer"] = "'" . escape_string($atual["claranswer"]) . "'";
            }
            if ($atual["clarjudge"] == "") {
                $atual["clarjudge"] = "null";
            }
            if ($atual["clarjudgesite"] == "") {
                $atual["clarjudgesite"] = "null";
            }
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            if ($situacao[$j] == "atualizar") {
                DBExec($c, "update clartable set " . "usernumber=" . $atual["usernumber"] . "," . "clardate=" . $atual["clardate"] . "," . "clardatediff=" . $atual["clardatediff"] . "," . "clardatediffans=" . $atual["clardatediffans"] . "," . "clarproblem=" . $atual["clarproblem"] . "," . "clardata='" . escape_string($atual["clardata"]) . "'," . "claranswer=" . $atual["claranswer"] . "," . "clarstatus='" . escape_string($atual["clarstatus"]) . "'," . "clarjudge=" . $atual["clarjudge"] . "," . "clarjudgesite=" . $atual["clarjudgesite"] . "," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and clarsitenumber=" . $atual["clarsitenumber"] . " and clarnumber=" . $atual["clarnumber"] . " and updatetime<" . $atual["updatetime"]);
                $upd++;
            } else {
                if ($situacao[$j] == "inserir") {
                    $ins++;
                    echo "Clar inserts shouldn't exist (clarnumber=" . $atual["clarnumber"] . ")...\n";
                }
            }
        }
        echo "   updates={$upd}, insertions={$ins}\n\n";
        // sincronizando runs
        $r = DBExec($t, "select * from runtable where contestnumber={$contest} and runsitenumber={$site}");
        $rr = DBExec($c, "select * from runtable where contestnumber={$contest} and runsitenumber={$site}");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        echo "runs: external(site={$site}, reading={$site})={$n}, local={$nn}\n";
        for ($k = 0; $k < $nn; $k++) {
            $needed[$k] = false;
        }
        for ($j = 0; $j < $n; $j++) {
            $la = DBRow($r, $j);
            for ($k = 0; $k < $nn; $k++) {
                $aqui = DBRow($rr, $k);
                if ($la["runnumber"] == $aqui["runnumber"] && $la["contestnumber"] == $aqui["contestnumber"] && $la["runsitenumber"] == $aqui["runsitenumber"]) {
                    $needed[$k] = true;
                    if ($la["updatetime"] > $aqui["updatetime"]) {
                        $situacao[$j] = "atualizar";
                    } else {
                        $situacao[$j] = "ok";
                    }
                    break;
                }
            }
            if ($k >= $nn) {
                $situacao[$j] = "inserir";
            }
        }
        $del = 0;
        for ($k = 0; $k < $nn; $k++) {
            $atual = DBRow($rr, $k);
            if (!$needed[$k]) {
                $del++;
                DBExec($c, "delete from runtable where contestnumber={$contest} and runsitenumber={$site} and runnumber=" . $atual["runnumber"]);
            }
        }
        $upd = 0;
        $ins = 0;
        for ($j = 0; $j < $n; $j++) {
            $atual = DBRow($r, $j);
            /*
            			$r2 = DBExec ($c,"select * from runtable where contestnumber=$contest and runsitenumber=".$atual["runsitenumber"].
                                                    " and runnumber=".$atual["runnumber"]." for update");
            			if (DBnLines($r2)>0) {
            				$p = DBRow($r2, 0);
            				DB_lo_unlink($c, $p["rundata"]);
            			}
            */
            if ($atual["runjudge"] == "") {
                $atual["runjudge"] = "null";
            }
            if ($atual["runjudgesite"] == "") {
                $atual["runjudgesite"] = "null";
            }
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            if ($situacao[$j] == "atualizar") {
                $upd++;
                DBExec($c, "update runtable set " . "usernumber=" . $atual["usernumber"] . "," . "rundate=" . $atual["rundate"] . "," . "rundatediff=" . $atual["rundatediff"] . "," . "rundatediffans=" . $atual["rundatediffans"] . "," . "runproblem=" . $atual["runproblem"] . "," . "runlangnumber=" . $atual["runlangnumber"] . "," . "runanswer=" . $atual["runanswer"] . "," . "runstatus='" . escape_string($atual["runstatus"]) . "'," . "runjudge=" . $atual["runjudge"] . "," . "runjudgesite=" . $atual["runjudgesite"] . "," . "runfilename='" . escape_string($atual["runfilename"]) . "'," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and runsitenumber=" . $atual["runsitenumber"] . " and runnumber=" . $atual["runnumber"] . " and updatetime<" . $atual["updatetime"]);
            } else {
                if ($situacao[$j] == "inserir") {
                    $ins++;
                    DBExec($t, "begin work");
                    $in = DB_lo_open($t, $atual["rundata"], "r");
                    if (!$in) {
                        $o = "0";
                    } else {
                        $o = DB_lo_create($c);
                        $out = DB_lo_open($c, $o, "w");
                        while (($buf = DB_lo_read($in, 1000)) != false) {
                            DB_lo_write($out, $buf);
                        }
                        DB_lo_close($out);
                        DB_lo_close($in);
                        $in = DB_lo_open($t, $atual["rundata"], "r");
                        if (!$in) {
                            $o = "0";
                            LOGLevel("Run not saved as file (run=" . $atual["runnumber"] . ",site=" . $atual["runsitenumber"] . ",contest={$contest}", 1);
                        } else {
                            $sitess = $atual["runsitenumber"];
                            $nss = $atual["runnumber"];
                            $user = $atual["usernumber"];
                            $problem = $atual["runproblem"];
                            $filename = escape_string($atual["runfilename"]);
                            $ttimet = $atual["rundate"];
                            $fp = fopen("/tmp/boca/contest{$contest}.site{$sitess}.run{$nss}.user{$user}." . "problem{$problem}.time{$ttimet}.{$filename}", "w");
                            if ($fp) {
                                while (($buf = DB_lo_read($in, 1000)) != false) {
                                    fwrite($fp, $buf);
                                }
                                fclose($fp);
                                $fp = fopen("/tmp/check/contest{$contest}.site{$sitess}.run{$nss}.user{$user}." . "problem{$problem}.time{$ttimet}.{$filename}.check", "w");
                                if ($fp) {
                                    fwrite($fp, "1");
                                    fclose($fp);
                                } else {
                                    LOGLevel("Run not saved as check file (run=" . $atual["runnumber"] . ",site=" . $atual["runsitenumber"] . ",contest={$contest}", 1);
                                }
                            } else {
                                LOGLevel("Run not saved as file (run=" . $atual["runnumber"] . ",site=" . $atual["runsitenumber"] . ",contest={$contest}", 1);
                            }
                            DB_lo_close($out);
                        }
                    }
                    DBExec($c, "insert into runtable (contestnumber, runsitenumber, runnumber, usernumber, rundate," . "rundatediff, rundatediffans, runproblem, runfilename, rundata, runanswer, runstatus, runjudge," . "runjudgesite, runlangnumber, updatetime) " . "values (" . $contest . "," . $atual["runsitenumber"] . "," . $atual["runnumber"] . "," . $atual["usernumber"] . "," . $atual["rundate"] . "," . $atual["rundatediff"] . "," . $atual["rundatediffans"] . "," . $atual["runproblem"] . "," . "'" . escape_string($atual["runfilename"]) . "',{$o}," . $atual["runanswer"] . "," . "'" . escape_string($atual["runstatus"]) . "'," . $atual["runjudge"] . "," . $atual["runjudgesite"] . "," . $atual["runlangnumber"] . "," . $atual["updatetime"] . ")");
                    DBExec($t, "commit work");
                }
            }
        }
        echo "   deletions={$del}, updates={$upd}, insertions={$ins}\n\n";
        // sincronizando runs
        $r = DBExec($t, "select * from runtable where contestnumber={$contest} and runsitenumber={$localsite}");
        $rr = DBExec($c, "select * from runtable where contestnumber={$contest} and runsitenumber={$localsite}");
        $n = DBnLines($r);
        $nn = DBnLines($rr);
        echo "runs: external(site={$site}, reading={$localsite})={$n}, local={$nn}\n";
        for ($k = 0; $k < $nn; $k++) {
            $needed[$k] = false;
        }
        for ($j = 0; $j < $n; $j++) {
            $la = DBRow($r, $j);
            for ($k = 0; $k < $nn; $k++) {
                $aqui = DBRow($rr, $k);
                if ($la["runnumber"] == $aqui["runnumber"] && $la["contestnumber"] == $aqui["contestnumber"] && $la["runsitenumber"] == $aqui["runsitenumber"]) {
                    $needed[$k] = true;
                    if ($la["updatetime"] > $aqui["updatetime"]) {
                        $situacao[$j] = "atualizar";
                        if ($la["runanswer"] != "") {
                            $rrr = DBExec($c, "select * from answertable where answernumber=" . $la["runanswer"] . " and contestnumber=" . $la["contestnumber"]);
                            $ans = DBnLines($rrr) > 0 ? DBRow($rrr, 0) : null;
                            if ($ans == null) {
                                echo "Problem with the answer table. Unable to send balloon because the answer was " . "not found (run=" . $la["runnumber"] . ", site=" . $la["runsite"] . ", contest=" . $la["contestnumber"] . ", answer=" . $la["runanswer"] . ").";
                                $yesla = 'x';
                            } else {
                                $yesla = $ans["yes"];
                            }
                        } else {
                            $yesla = 'f';
                        }
                        if ($aqui["runanswer"] != "") {
                            $rrr = DBExec($c, "select * from answertable where answernumber=" . $aqui["runanswer"] . " and contestnumber=" . $aqui["contestnumber"]);
                            $ans = DBnLines($rrr) > 0 ? DBRow($rrr, 0) : null;
                            if ($ans == null) {
                                echo "Problem with the answer table. Unable to send balloon because the answer was " . "not found (run=" . $aqui["runnumber"] . ", site=" . $aqui["runsite"] . ", contest=" . $aqui["contestnumber"] . ", answer=" . $aqui["runanswer"] . ").";
                                $yesaqui = 'x';
                            } else {
                                $yesaqui = $ans["yes"];
                            }
                        } else {
                            $yesaqui = 'f';
                        }
                        if ($yesla == 't' && $yesaqui == 'f') {
                            $rrr = DBExec($c, "select * from sitetable where contestnumber=" . $aqui["contestnumber"] . " and sitenumber={$localsite}");
                            if (DBnLines($rrr) <= 0) {
                                echo "Site info not found (contest={$aqui["contestnumber"]}, site={$localsite}).";
                            } else {
                                $b = DBRow($rrr, 0);
                                $ti = $b["sitestartdate"];
                                $tempo = time();
                                $ta = $tempo - $ti;
                                $tf = $b["sitelastmileanswer"];
                                //						                if ($ta < $tf) {
                                $rrr = DBExec($c, "select * from usertable where contestnumber=" . $aqui["contestnumber"] . " and usersitenumber={$localsite} and usernumber=" . $aqui["usernumber"]);
                                if (DBnLines($rrr) <= 0) {
                                    echo "User info not found (contest={$aqui["contestnumber"]}, " . "site={$localsite}, user={$aqui["runusernumber"]}).";
                                } else {
                                    $u = DBRow($rrr, 0);
                                    $rrr = DBExec($c, "select * from problemtable where contestnumber=" . $aqui["contestnumber"] . " and problemnumber=" . $aqui["runproblem"]);
                                    if (DBnLines($rrr) <= 0) {
                                        echo "Problem info not found (contest={$aqui["contestnumber"]}, " . "problem={$aqui["runproblem"]}).";
                                    } else {
                                        $p = DBRow($rrr, 0);
                                        mail("balloon@mainserver", "YES: team=" . $u["username"] . ", problem=" . $p["problemname"], "User " . $u["username"] . " should receive a balloon for " . $p["problemfullname"] . "\n");
                                    }
                                }
                                //								}
                            }
                        } else {
                            if ($yesla == 'f' && $yesaqui == 't') {
                                $rrr = DBExec($c, "select * from usertable where contestnumber=" . $aqui["contestnumber"] . " and usersitenumber={$localsite} and usernumber=" . $aqui["usernumber"]);
                                if (DBnLines($rrr) <= 0) {
                                    echo "User info not found (contest={$aqui["contestnumber"]}, " . "site={$localsite}, user={$aqui["runusernumber"]}).";
                                } else {
                                    $u = DBRow($rrr, 0);
                                    $rrr = DBExec($c, "select * from problemtable where contestnumber=" . $aqui["contestnumber"] . " and problemnumber=" . $aqui["runproblem"]);
                                    if (DBnLines($rrr) <= 0) {
                                        echo "Problem info not found (contest={$aqui["contestnumber"]}, " . "problem={$aqui["runproblem"]}).";
                                    } else {
                                        $p = DBRow($rrr, 0);
                                        mail("balloon@mainserver", "NO: team=" . $u["username"] . ", problem=" . $p["problemname"], "Remove the balloon from user " . $u["username"] . " for " . $p["problemfullname"] . "\n");
                                    }
                                }
                            }
                        }
                    } else {
                        $situacao[$j] = "ok";
                    }
                    break;
                }
            }
            if ($k >= $nn) {
                $situacao[$j] = "inserir";
            }
        }
        $upd = 0;
        $ins = 0;
        for ($j = 0; $j < $n; $j++) {
            $atual = DBRow($r, $j);
            if ($atual["runjudge"] == "") {
                $atual["runjudge"] = "null";
            }
            if ($atual["runjudgesite"] == "") {
                $atual["runjudgesite"] = "null";
            }
            if ($atual["updatetime"] == "") {
                $atual["updatetime"] = time();
            }
            if ($situacao[$j] == "atualizar") {
                $upd++;
                DBExec($c, "update runtable set " . "usernumber=" . $atual["usernumber"] . "," . "rundate=" . $atual["rundate"] . "," . "rundatediff=" . $atual["rundatediff"] . "," . "rundatediffans=" . $atual["rundatediffans"] . "," . "runproblem=" . $atual["runproblem"] . "," . "runlangnumber=" . $atual["runlangnumber"] . "," . "runanswer=" . $atual["runanswer"] . "," . "runstatus='" . escape_string($atual["runstatus"]) . "'," . "runjudge=" . $atual["runjudge"] . "," . "runjudgesite=" . $atual["runjudgesite"] . "," . "runfilename='" . escape_string($atual["runfilename"]) . "'," . "updatetime=" . $atual["updatetime"] . " where contestnumber={$contest} and runsitenumber=" . $atual["runsitenumber"] . " and runnumber=" . $atual["runnumber"] . " and updatetime<" . $atual["updatetime"]);
            } else {
                if ($situacao[$j] == "inserir") {
                    $ins++;
                    echo "Run Inserts shouldn't exist (run=" . $atual["runnumber"] . ")...";
                }
            }
        }
        echo "   updates={$upd}, insertions={$ins}\n\n";
        DBExec($c, "commit work");
        DBClose($t);
    }
    DBClose($c);
}
예제 #19
0
파일: frun.php 프로젝트: sbaldrich/boca
function DBJudgedRuns($contest, $site, $user)
{
    $c = DBConnect();
    $r = DBExec($c, "select distinct r.runsitenumber as site, r.runnumber as number, r.rundatediff as timestamp, " . "p.problemname as problem, r.runstatus as status, l.langname as language, l.langextension as extension, " . "a.runanswer as answer, r.updatetime, r.runanswer1 as answer1, r.runanswer2 as answer2 " . "from runtable as r, problemtable as p, answertable as a, langtable as l " . "where r.contestnumber={$contest} and p.contestnumber=r.contestnumber and " . "l.contestnumber=r.contestnumber and l.langnumber=r.runlangnumber and " . "r.contestnumber=a.contestnumber and r.runproblem=p.problemnumber and " . "a.answernumber=r.runanswer and " . "((r.runjudgesite={$site} and r.runjudge={$user}) or " . " (r.runjudgesite1={$site} and r.runjudge1={$user}) or " . " (r.runjudgesite2={$site} and r.runjudge2={$user})) " . " order by r.updatetime", "DBJudgedRuns(get run/prob/ans/lang)");
    $n = DBnlines($r);
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = DBRow($r, $i);
    }
    return $a;
}
예제 #20
0
파일: fscore.php 프로젝트: sbaldrich/boca
function DBScoreSite($contest, $site, $verifylastmile, $hor = -1, $data = null)
{
    if (($blocal = DBSiteInfo($contest, $_SESSION["usertable"]["usersitenumber"])) == null) {
        exit;
    }
    if (($b = DBSiteInfo($contest, $site, null, false)) == null) {
        $b = $blocal;
    }
    if (($ct = DBContestInfo($contest)) == null) {
        exit;
    }
    $t = time();
    $ta = $blocal["currenttime"];
    if ($hor >= 0) {
        $ta = $hor;
    }
    if ($verifylastmile) {
        $tf = $b["sitelastmilescore"];
    } else {
        $tf = $b["siteduration"];
    }
    if ($data != null && is_numeric($data)) {
        if ($data < $ta) {
            $ta = $data;
        }
        $data = null;
    }
    $data0 = array();
    if ($data == null) {
        $c = DBConnect();
        $resp = array();
        $r = DBExec($c, "select * from usertable where contestnumber={$contest} and usersitenumber={$site} and " . "usertype='team' and userlastlogin is not null and userenabled='t'", "DBScoreSite(get users)");
        $n = DBnlines($r);
        for ($i = 0; $i < $n; $i++) {
            $a = DBRow($r, $i);
            $resp[$a["usernumber"]]["user"] = $a["usernumber"];
            $resp[$a["usernumber"]]["site"] = $a["usersitenumber"];
            $resp[$a["usernumber"]]["username"] = $a["username"];
            $resp[$a["usernumber"]]["usertype"] = $a["usertype"];
            $resp[$a["usernumber"]]["userfullname"] = $a["userfullname"];
            $resp[$a["usernumber"]]["totaltime"] = 0;
            $resp[$a["usernumber"]]["totalcount"] = 0;
            $resp[$a["usernumber"]]["problem"] = array();
        }
        $r = DBExec($c, "select r.usernumber as user, p.problemname as problemname, r.runproblem as problem, " . "p.problemcolor as color, p.problemcolorname as colorname, " . "r.rundatediff as time, r.rundatediffans as anstime, a.yes as yes, r.runanswer as answer from " . "runtable as r, answertable as a, problemtable as p where r.runanswer=a.answernumber and " . "a.contestnumber={$contest} and p.problemnumber=r.runproblem and p.contestnumber={$contest} and " . "r.contestnumber={$contest} and r.runsitenumber={$site} and (r.runstatus ~ 'judged' or r.runstatus ~ 'judged+') and " . "r.rundatediff>=0 and r.rundatediff<={$tf} and r.rundatediffans<={$ta} " . "order by r.usernumber, r.runproblem, r.rundatediff", "DBScoreSite(get runs)");
        $n = DBnlines($r);
        $a = array();
        for ($i = 0; $i < $n; $i++) {
            $a[$i] = DBRow($r, $i);
        }
        $data0['n'] = $n;
        $data0['resp'] = $resp;
        $data0['a'] = $a;
        $data0['site'] = $site;
    } else {
        $resp = $data['resp'];
        $n = $data['n'];
        $a = $data['a'];
    }
    $i = 0;
    while ($i < $n) {
        if ($a[$i]["anstime"] > $ta) {
            $i++;
            continue;
        }
        $user = $a[$i]["user"];
        $problem = $a[$i]["problem"];
        $time = 0;
        $k = 0;
        if (!isset($resp[$user])) {
            $i++;
            continue;
        }
        $resp[$user]["user"] = $user;
        $resp[$user]["site"] = $site;
        $resp[$user]["problem"][$problem]["name"] = $a[$i]["problemname"];
        $resp[$user]["problem"][$problem]["color"] = $a[$i]["color"];
        $resp[$user]["problem"][$problem]["colorname"] = $a[$i]["colorname"];
        $resp[$user]["problem"][$problem]["solved"] = false;
        $resp[$user]["problem"][$problem]["judging"] = false;
        $resp[$user]["problem"][$problem]["time"] = 0;
        $resp[$user]["problem"][$problem]["penalty"] = 0;
        $resp[$user]["problem"][$problem]["count"] = 0;
        while ($i < $n && $a[$i]["anstime"] <= $ta && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem && $a[$i]["yes"] != 't') {
            $time += (int) ($ct["contestpenalty"] / 60);
            $k++;
            $i++;
        }
        $resp[$user]["problem"][$problem]["count"] = $k;
        if ($i >= $n) {
            break;
        }
        if ($a[$i]["anstime"] <= $ta && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem && $a[$i]["yes"] == 't') {
            $timet = (int) ($a[$i]["time"] / 60);
            if (!isset($resp[$user]["first"]) || $timet < $resp[$user]["first"]) {
                $resp[$user]["first"] = $timet;
            }
            $time += $timet;
            $resp[$user]["problem"][$problem]["time"] = $timet;
            $resp[$user]["problem"][$problem]["penalty"] = $time;
            $resp[$user]["problem"][$problem]["solved"] = true;
            $resp[$user]["problem"][$problem]["count"]++;
            $resp[$user]["totaltime"] += $time;
            $resp[$user]["totalcount"]++;
        }
        while ($i < $n && $a[$i]["user"] == $user && $a[$i]["problem"] == $problem) {
            $i++;
        }
    }
    if ($data == null) {
        $aa = DBRecentNews($contest, $site, $verifylastmile, $ta);
        $data0['aa'] = $aa;
    } else {
        $aa = $data['aa'];
    }
    for ($i = 0; $i < count($aa); $i++) {
        if ($aa[$i]["fut"] == 't') {
            $resp[$aa[$i]["usernumber"]]["problem"][$aa[$i]["problemnumber"]]["judging"] = true;
        }
    }
    if (($result = ordena($resp)) === false) {
        LOGError("Error while sorting scores (contest={$contest}, site={$site}).");
        MSGError("Error while sorting scores. Contact an admin now!");
    }
    return array($result, $data0);
}