예제 #1
0
파일: fcontest.php 프로젝트: sbaldrich/boca
function DBUpdateSite($param, $c = null)
{
    $ac = array('contestnumber', 'sitenumber', 'sitename', 'sitepermitlogins', 'sitescorelevel');
    $ac1 = array('updatetime', 'siteautoend', 'siteglobalscore', 'siteip', 'siteactive', 'siteduration', 'sitelastmileanswer', 'sitelastmilescore', 'siteautojudge', 'sitenextuser', 'sitenextclar', 'sitenextrun', 'sitenexttask', 'sitemaxtask', 'sitechiefname', 'sitejudging', 'sitetasking');
    if (isset($param['number']) && !isset($param['sitenumber'])) {
        $param['sitenumber'] = $param['number'];
    }
    $type['contestnumber'] = 1;
    $type['sitenumber'] = 1;
    $type['updatetime'] = 1;
    $type['siteduration'] = 1;
    $type['sitelastmilescore'] = 1;
    $type['sitelastmileanswer'] = 1;
    $type['sitenextuser'] = 1;
    $type['sitenextclar'] = 1;
    $type['sitenextrun'] = 1;
    $type['sitenexttask'] = 1;
    $type['sitemaxtask'] = 1;
    $type['sitescorelevel'] = 1;
    foreach ($ac as $key) {
        if (!isset($param[$key])) {
            MSGError("DBUpdateSite param error: {$key} is not set");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBUpdateSite param error: {$key} is not numeric");
            return false;
        }
    }
    $siteduration = -1;
    $sitelastmileanswer = -1;
    $sitelastmilescore = -1;
    $sitenextuser = -1;
    $sitenextclar = -1;
    $sitenextrun = -1;
    $sitenexttask = -1;
    $sitemaxtask = -1;
    $sitejudging = '';
    $sitetasking = '';
    $sitechiefname = '';
    $siteip = '';
    $updatetime = -1;
    $siteautojudge = 'f';
    $siteautoend = 'f';
    $siteglobalscore = '';
    $siteactive = 'f';
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBUpdateSite param error: {$key} is not numeric");
                return false;
            }
        }
    }
    if ($siteautoend != "t" && $siteautoend != "") {
        $siteautoend = "f";
    }
    if ($siteactive != "t" && $siteactive != "") {
        $siteactive = "f";
    }
    if ($siteautojudge != "t" && $siteautojudge != "") {
        $siteautojudge = "f";
    }
    if ($sitescorelevel == "" || !is_numeric($sitescorelevel)) {
        $sitescorelevel = -10;
    } else {
        if ($sitescorelevel < -3) {
            $sitescorelevel = -4;
        }
        if ($sitescorelevel > 3) {
            $sitescorelevel = 4;
        }
    }
    $docommit = false;
    if ($c == null) {
        $c = DBConnect();
        DBExec($c, "begin work", "DBUpdateSite(begin)");
        $docommit = true;
    }
    $a = DBGetRow("select * from sitetable where contestnumber={$contestnumber} and sitenumber={$sitenumber}", 0, $c);
    if ($a == null) {
        $ret = 2;
        $param['number'] = $sitenumber;
        DBNewSite($contestnumber, $c, $param);
        $a = DBGetRow("select * from sitetable where contestnumber={$contestnumber} and sitenumber={$sitenumber}", 0, $c);
        if ($a == null) {
            DBExec($c, "rollback work", "DBUpdateSite(rollback-errorsite)");
            MSGError("DBUpdateSite update error: impossible to create a site in the DB");
            LOGLevel("DBUpdateSite update error: impossible to create a site in the DB", 0);
            return false;
        }
    }
    $t = time();
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    $ret = 1;
    if ($updatetime > $a['updatetime']) {
        $ret = 2;
        if ($sitenextrun == 0) {
            DBSiteDeleteAllRuns($contestnumber, $sitenumber, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"], $c);
        }
        if ($sitenextclar == 0) {
            DBSiteDeleteAllClars($contestnumber, $sitenumber, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"], $c);
        }
        if ($sitenexttask == 0) {
            DBSiteDeleteAllTasks($contestnumber, $sitenumber, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"], $c);
        }
        $sql = "update sitetable set sitename='{$sitename}', ";
        if ($sitepermitlogins != "") {
            $sql .= "sitepermitlogins='{$sitepermitlogins}', ";
        }
        if ($siteduration > 0) {
            $sql .= "siteduration={$siteduration}, ";
        }
        if ($siteip != '') {
            $sql .= "siteip='{$siteip}',";
        }
        if ($siteautoend != "") {
            $sql .= "siteautoend='{$siteautoend}', ";
        }
        if ($siteactive != "") {
            $sql .= "siteactive='{$siteactive}', ";
        }
        if ($siteglobalscore != "") {
            $sql .= "siteglobalscore='{$siteglobalscore}', ";
        }
        if ($sitenextuser >= 0) {
            $sql .= "sitenextuser={$sitenextuser}, ";
        }
        if ($sitenextclar >= 0) {
            $sql .= "sitenextclar={$sitenextclar}, ";
        }
        if ($sitenextrun >= 0) {
            $sql .= "sitenextrun={$sitenextrun}, ";
        }
        if ($sitenexttask >= 0) {
            $sql .= "sitenexttask={$sitenexttask}, ";
        }
        if ($sitemaxtask >= 0) {
            $sql .= "sitemaxtask={$sitemaxtask}, ";
        }
        if ($sitechiefname != '') {
            $sql .= "sitechiefname='{$sitechiefname}', ";
        }
        if ($siteautojudge != '') {
            $sql .= "siteautojudge='{$siteautojudge}', ";
        }
        if ($sitejudging != '') {
            $sql .= "sitejudging='{$sitejudging}', ";
        }
        if ($sitetasking != '') {
            $sql .= "sitetasking='{$sitetasking}', ";
        }
        if ($sitelastmileanswer > 0) {
            $sql .= " sitelastmileanswer={$sitelastmileanswer}, ";
        }
        if ($sitelastmilescore > 0) {
            $sql .= " sitelastmilescore={$sitelastmilescore}, ";
        }
        if ($sitescorelevel > -5) {
            $sql .= " sitescorelevel={$sitescorelevel}, ";
        }
        $sql .= " updatetime=" . $updatetime . " where contestnumber={$contestnumber} and sitenumber={$sitenumber} ";
        //. "and updatetime < $updatetime";
        DBExec($c, $sql, "DBUpdateSite(update site)");
        if ($docommit) {
            DBExec($c, "commit work", "DBUpdateSite(commit-update)");
            LOGLevel("User " . $_SESSION["usertable"]["username"] . "/" . $_SESSION["usertable"]["usersitenumber"] . " changed the site {$sitenumber} (contest={$contestnumber}) settings.", 2);
        }
    } else {
        if ($docommit) {
            DBExec($c, "commit work", "DBUpdateSite(commit-noupdate)");
        }
    }
    return $ret;
}
예제 #2
0
파일: site.php 프로젝트: sbaldrich/boca
    if ($_POST["confirmation"] == "confirm") {
        DBSiteLogins($_SESSION["usertable"]["contestnumber"], $site, "f");
    }
    ForceLoad("site.php?site={$site}");
}
if (isset($_POST["Submit2"]) && $_POST["Submit2"] == "Start Now") {
    if ($_POST["confirmation"] == "confirm") {
        if (!DBSiteStartNow($_SESSION["usertable"]["contestnumber"], $site)) {
            MSGError("Site is already running");
        }
    }
    ForceLoad("site.php?site={$site}");
}
if (isset($_POST["SubmitDC"]) && $_POST["SubmitDC"] == "Delete ALL site clars") {
    if ($_POST["confirmation"] == "confirm") {
        DBSiteDeleteAllClars($_SESSION["usertable"]["contestnumber"], $site, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"]);
    }
    ForceLoad("site.php?site={$site}");
}
if (isset($_POST["SubmitDR"]) && $_POST["SubmitDR"] == "Delete ALL site runs") {
    if ($_POST["confirmation"] == "confirm") {
        DBSiteDeleteAllRuns($_SESSION["usertable"]["contestnumber"], $site, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"]);
    }
    ForceLoad("site.php?site={$site}");
}
if (isset($_POST["SubmitDT"]) && $_POST["SubmitDT"] == "Delete ALL site tasks") {
    if ($_POST["confirmation"] == "confirm") {
        DBSiteDeleteAllTasks($_SESSION["usertable"]["contestnumber"], $site, $_SESSION["usertable"]["usernumber"], $_SESSION["usertable"]["usersitenumber"]);
    }
    ForceLoad("site.php?site={$site}");
}