Ejemplo n.º 1
0
function DBNewRun($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['runnumber'])) {
        $param['runnumber'] = $param['number'];
    }
    if (isset($param['runlangnumber']) && !isset($param['lang'])) {
        $param['lang'] = $param['runlangnumber'];
    }
    if (isset($param['runproblem']) && !isset($param['problem'])) {
        $param['problem'] = $param['runproblem'];
    }
    $ac = array('contest', 'site', 'user', 'problem', 'lang', 'filename', 'filepath');
    $ac1 = array('runnumber', 'rundate', 'rundatediff', 'rundatediffans', 'runanswer', 'runstatus', 'runjudge', 'runjudgesite', 'runjudge1', 'runjudgesite1', 'runanswer1', 'runjudge2', 'runjudgesite2', 'runanswer2', 'autoip', 'autobegindate', 'autoenddate', 'autoanswer', 'autostdout', 'autostderr', 'updatetime');
    $type['contest'] = 1;
    $type['autobegindate'] = 1;
    $type['autoenddate'] = 1;
    $type['problem'] = 1;
    $type['updatetime'] = 1;
    $type['site'] = 1;
    $type['user'] = 1;
    $type['runnumber'] = 1;
    $type['rundatediffans'] = 1;
    $type['rundatediff'] = 1;
    $type['rundate'] = 1;
    $type['runanswer'] = 1;
    $type['runjudge'] = 1;
    $type['runjudgesite'] = 1;
    $type['runjudge1'] = 1;
    $type['runjudgesite1'] = 1;
    $type['runanswer1'] = 1;
    $type['runjudge2'] = 1;
    $type['runjudgesite2'] = 1;
    $type['runanswer2'] = 1;
    foreach ($ac as $key) {
        if (!isset($param[$key]) || $param[$key] == "") {
            MSGError("DBNewRun param error: {$key} not found");
            return false;
        }
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewRun param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $t = time();
    $autoip = '';
    $autobegindate = 'NULL';
    $autoenddate = 'NULL';
    $autoanswer = '';
    $autostdout = '';
    $autostderr = '';
    $runjudge = 'NULL';
    $runjudgesite = 'NULL';
    $runjudge1 = 'NULL';
    $runjudgesite1 = 'NULL';
    $runanswer1 = 0;
    $runjudge2 = 'NULL';
    $runjudgesite2 = 'NULL';
    $runanswer2 = 0;
    $runnumber = -1;
    $updatetime = -1;
    $rundatediff = -1;
    $rundate = $t;
    $runanswer = 0;
    $rundatediffans = 999999999;
    $runstatus = 'openrun';
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewRun param error: {$key} is not numeric");
                return false;
            }
        }
    }
    if ($updatetime < 0) {
        $updatetime = $t;
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewRun(transaction)");
    }
    $insert = true;
    $oid1 = '';
    $oid2 = '';
    $oldold1 = '';
    $oldold2 = '';
    $sql = "select sitenextrun as nextrun from " . "sitetable where sitenumber={$site} and contestnumber={$contest} for update";
    $r = DBExec($c, $sql, "DBNewRun(get site for update)");
    if (DBnlines($r) != 1) {
        DBExec($c, "rollback work", "DBNewRun(rollback-site)");
        LOGError("Unable to find a unique site/contest in the database. SQL=(" . $sql . ")");
        MSGError("Unable to find a unique site/contest in the database.");
        return false;
    }
    $a = DBRow($r, 0);
    $n = $a["nextrun"] + 1;
    if ($runnumber > 0) {
        $sql = "select * from runtable as t where t.contestnumber={$contest} and " . "t.runsitenumber={$site} and t.runnumber={$runnumber}";
        $r = DBExec($c, $sql . " for update", "DBNewRun(get run for update)");
        $n = DBnlines($r);
        if ($n > 0) {
            $insert = false;
            $lr = DBRow($r, 0);
            $t = $lr['updatetime'];
            if (isset($lr['autostdout'])) {
                $oid1 = $lr['autostdout'];
            }
            if (isset($lr['autostderr'])) {
                $oid2 = $lr['autostderr'];
            }
        }
        $n = $runnumber;
    } else {
        $runnumber = $n;
    }
    if ($rundatediff < 0) {
        $b = DBSiteInfo($contest, $site, $c);
        $dif = $b["currenttime"];
        $rundatediff = $dif;
        if ($dif < 0) {
            if (!isset($param['allowneg'])) {
                DBExec($c, "rollback work", "DBNewRun(rollback-started)");
                LOGError("Tried to submit a run but the contest is not started. SQL=(" . $sql . ")");
                MSGError("The contest is not started yet!");
                return 0;
            }
        }
        if (!$b["siterunning"]) {
            DBExec($c, "rollback work", "DBNewRun(rollback-over)");
            LOGError("Tried to submit a run but the contest is over. SQL=(" . $sql . ")");
            MSGError("The contest is over!");
            return 0;
        }
    } else {
        $dif = $rundatediff;
    }
    if ($updatetime > $t || $insert) {
        DBExec($c, "update sitetable set sitenextrun={$runnumber}, updatetime=" . $t . " where sitenumber={$site} and contestnumber={$contest} and sitenextrun<{$runnumber}", "DBNewRun(update site)");
        //	LOGError($autostdout);
        if (substr($autostdout, 0, 7) == "base64:") {
            $autostdout = base64_decode(substr($autostdout, 7));
            $oldoid1 = $oid1;
            if (($oid1 = DB_lo_import_text($c, $autostdout)) == null) {
                DBExec($c, "rollback work", "DBNewRun(rollback-import stdout)");
                LOGError("Unable to create a large object for file stdout (run={$runnumber},site={$site},contest={$contest}).");
                MSGError("problem importing stdout to database. Contact an admin now!");
                return false;
            }
        } else {
            if ($autostdout != '') {
                DBExec($c, "rollback work", "DBNewRun(rollback-import stderr)");
                LOGError("Unable to create a large object for file stdout that is not BASE64 (run={$runnumber},site={$site},contest={$contest}).");
                MSGError("problem importing stdout (not BASE64) to database. Contact an admin now!");
                return false;
            }
            $oid1 = 'NULL';
        }
        if (substr($autostderr, 0, 7) == "base64:") {
            //		LOGError($autostderr);
            $autostderr = base64_decode(substr($autostderr, 7));
            $oldoid2 = $oid2;
            if (($oid2 = DB_lo_import_text($c, $autostderr)) == null) {
                DBExec($c, "rollback work", "DBNewRun(rollback-import stderr)");
                LOGError("Unable to create a large object for file stderr (run={$runnumber},site={$site},contest={$contest}).");
                MSGError("problem importing stderr to database. Contact an admin now!");
                return false;
            }
        } else {
            if ($autostderr != '') {
                DBExec($c, "rollback work", "DBNewRun(rollback-import stderr)");
                LOGError("Unable to create a large object for file stderr that is not BASE64 (run={$runnumber},site={$site},contest={$contest}).");
                MSGError("problem importing stderr (not BASE64) to database. Contact an admin now!");
                return false;
            }
            $oid2 = 'NULL';
        }
    }
    $ret = 1;
    if ($insert) {
        if (substr($filepath, 0, 7) != "base64:") {
            if (($oid = DB_lo_import($c, $filepath)) === false) {
                DBExec($c, "rollback work", "DBNewRun(rollback-import)");
                LOGError("DBNewRun: Unable to create a large object for file {$filepath}.");
                MSGError("problem importing file {$filepath} to database. Contact an admin now!");
                return false;
            }
        } else {
            $filepath = base64_decode(substr($filepath, 7));
            if (($oid = DB_lo_import_text($c, $filepath)) == null) {
                DBExec($c, "rollback work", "DBNewRun(rollback-import)");
                LOGError("DBNewRun: Unable to create a large object for file.");
                MSGError("problem importing file to database. Contact an admin now!");
                return false;
            }
        }
        DBExec($c, "INSERT INTO runtable (contestnumber, runsitenumber, runnumber, usernumber, rundate, " . "rundatediff, rundatediffans, runproblem, runfilename, rundata, runanswer, runstatus, runlangnumber, " . "runjudge, runjudgesite, runanswer1, runjudge1, runjudgesite1, runanswer2, runjudge2, runjudgesite2, " . "autoip, autobegindate, autoenddate, autoanswer, autostdout, autostderr, updatetime) " . "VALUES ({$contest}, {$site}, {$n}, {$user}, {$rundate}, {$rundatediff}, {$rundatediffans}, {$problem}, '{$filename}', {$oid}, {$runanswer}, " . "'{$runstatus}', {$lang}, {$runjudge}, {$runjudgesite}, {$runanswer1}, {$runjudge1}, {$runjudgesite1}, {$runanswer2}, {$runjudge2}, " . "{$runjudgesite2}, '{$autoip}', {$autobegindate}, {$autoenddate}, '{$autoanswer}', {$oid1}, {$oid2}, {$updatetime})", "DBNewRun(insert run)");
        if ($cw) {
            DBExec($c, "commit work", "DBNewRun(commit)");
            LOGLevel("User {$user} submitted a run (#{$n}) on site #{$site} " . "(problem={$problem},filename={$filename},lang={$lang},contest={$contest},date={$t},datedif={$dif},oid={$oid}).", 2);
        }
        $ret = 2;
    } else {
        if ($updatetime > $t) {
            $ret = 2;
            DBExec($c, "update runtable set rundate={$rundate}, rundatediff={$rundatediff}, " . "rundatediffans={$rundatediffans}, runanswer={$runanswer}, runanswer1={$runanswer1}, runanswer2={$runanswer2}, runstatus='{$runstatus}', " . "runjudge1={$runjudge1}, runjudgesite1={$runjudgesite1}, runjudge2={$runjudge2}, runjudgesite2={$runjudgesite2}, " . "runjudge={$runjudge}, runjudgesite={$runjudgesite}, updatetime={$updatetime}, " . "autoip='{$autoip}', autobegindate={$autobegindate}, autoenddate={$autoenddate}, autoanswer='{$autoanswer}', " . "autostdout={$oid1}, autostderr={$oid2} " . "where runnumber={$runnumber} and contestnumber={$contest} and runsitenumber={$site}", "DBNewRun(update run)");
            if (is_numeric($oldoid1)) {
                DB_lo_unlink($c, $oldoid1);
            }
            if (is_numeric($oldoid2)) {
                DB_lo_unlink($c, $oldoid2);
            }
        }
        if ($cw) {
            DBExec($c, "commit work", "DBNewRun(commit-update)");
        }
    }
    return $ret;
    /* // isso gera problemas de portabilidade e de seguranca (quando outros usuarios tambem tem shell
       // no servidor e podem construir paginas web. Eles podem usar essas paginas para acessar esses arquivos,
       // pois os mesmos ficaram com dono apache/www-data/etc)
       umask(0077);
       @mkdir("/tmp/boca");
       if (!move_uploaded_file ($filepath,
       "/tmp/boca/contest${contest}.site${site}.run${n}.user${user}.problem${problem}.time${t}.${filename}"))
       LOGLevel("Run not saved as file (run=$n,site=$site,contest=$contest", 1);
    */
}
Ejemplo n.º 2
0
function DBNewProblem($contestnumber, $param, $c = null)
{
    if (isset($param["action"]) && $param["action"] == "delete") {
        return DBDeleteProblem($contestnumber, $param);
    }
    $ac = array('number', 'name');
    $type['number'] = 1;
    $type['updatetime'] = 1;
    $ac1 = array('colorname', 'fake', 'color', 'updatetime', 'fullname', 'basename', 'inputfilename', 'inputfilepath');
    $colorname = '';
    $color = '';
    $fake = 'f';
    foreach ($ac as $key) {
        if (!isset($param[$key])) {
            MSGError("DBNewProblem param error: {$key} is not set");
            return false;
        }
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewProblem param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $basename = '';
    $inputfilename = '';
    $inputfilepath = '';
    $fullname = '';
    $updatetime = -1;
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewProblem param error: {$key} is not numeric");
                return false;
            }
            ${$key} = sanitizeText($param[$key]);
        }
    }
    $t = time();
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    $inputhash = '';
    $sql2 = "select * from problemtable where contestnumber={$contestnumber} and problemnumber={$number} for update";
    // "select * from problemtable where contestnumber=$contestnumber and problemnumber=$number " .
    // "and probleminputfilename='$inputfilename'";
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewProblem(transaction)");
    }
    $r = DBExec($c, $sql2, "DBNewProblem(get problem for update)");
    $n = DBnlines($r);
    $ret = 1;
    $oldfullname = '';
    $deservesupdatetime = false;
    if ($n == 0) {
        DBExec($c, "insert into problemtable (contestnumber, problemnumber, problemname, problemcolor) values " . "({$contestnumber}, {$number}, '{$name}','-1')", "DBNewProblem(insert problem)");
        $deservesupdatetime = true;
        $s = "created";
    } else {
        $lr = DBRow($r, 0);
        $t = $lr['updatetime'];
        $oldfullname = $lr['problemfullname'];
        $s = "updated";
        $inputhash = $lr['probleminputfilehash'];
    }
    if ($s == "created" || $updatetime > $t) {
        if (substr($inputfilepath, 0, 7) != "base64:") {
            if ($inputfilepath != "") {
                $hash = myshorthash(file_get_contents($inputfilepath));
                if ($hash != $inputhash) {
                    $oldoid = '';
                    if (isset($lr)) {
                        $oldoid = $lr['probleminputfile'];
                    }
                    if (($oid1 = DB_lo_import($c, $inputfilepath)) === false) {
                        DBExec($c, "rollback work", "DBNewProblem(rollback-input)");
                        LOGError("Unable to create a large object for file {$inputfilename}.");
                        MSGError("problem importing file to database. See log for details!");
                        exit;
                    }
                    if ($oldoid != '') {
                        DB_lo_unlink($c, $oldoid);
                    }
                    $inputhash = DBcrc($contestnumber, $oid1, $c);
                } else {
                    $oid1 = $lr['probleminputfile'];
                }
            }
        } else {
            $inputfilepath = base64_decode(substr($inputfilepath, 7));
            $hash = myshorthash($inputfilepath);
            if ($hash != $inputhash) {
                $oldoid = '';
                if (isset($lr)) {
                    $oldoid = $lr['probleminputfile'];
                }
                if (($oid1 = DB_lo_import_text($c, $inputfilepath)) == null) {
                    DBExec($c, "rollback work", "DBNewProblem(rollback-i-import)");
                    LOGError("Unable to import the large object for file {$inputfilename}.");
                    MSGError("problem importing file to database. See log for details!");
                    exit;
                }
                if ($oldoid != '') {
                    DB_lo_unlink($c, $oldoid);
                }
                $inputhash = DBcrc($contestnumber, $oid1, $c);
            } else {
                $oid1 = $lr['probleminputfile'];
            }
        }
        if ($name != "") {
            DBExec($c, "update problemtable set problemname='{$name}' where contestnumber={$contestnumber} " . "and problemnumber={$number}", "DBNewProblem(update name)");
        }
        if ($fullname != "" || strpos($oldfullname, '(DEL)') !== false) {
            $deservesupdatetime = true;
            DBExec($c, "update problemtable set problemfullname='{$fullname}' where contestnumber={$contestnumber} " . "and problemnumber={$number}", "DBNewProblem(update fullname)");
        }
        if ($basename != "") {
            $deservesupdatetime = true;
            DBExec($c, "update problemtable set problembasefilename='{$basename}' where contestnumber={$contestnumber} " . "and problemnumber={$number}", "DBNewProblem(update basename)");
        }
        if ($colorname != "") {
            DBExec($c, "update problemtable set problemcolorname='{$colorname}' where contestnumber={$contestnumber} " . "and problemnumber={$number}", "DBNewProblem(update colorname)");
        }
        if ($color != "") {
            DBExec($c, "update problemtable set problemcolor='{$color}' where contestnumber={$contestnumber} " . "and problemnumber={$number}", "DBNewProblem(update color)");
        }
        if ($inputfilename != "") {
            $deservesupdatetime = true;
            DBExec($c, "update problemtable set probleminputfilename='{$inputfilename}' where " . "contestnumber={$contestnumber} and problemnumber={$number} ", "DBNewProblem(update inputfilename)");
        }
        if ($inputfilepath != "") {
            $deservesupdatetime = true;
            DBExec($c, "update problemtable set probleminputfile={$oid1},probleminputfilehash='{$inputhash}' where contestnumber={$contestnumber} and " . "problemnumber={$number} ", "DBNewProblem(update inputfile)");
        }
        if ($fake == "t") {
            $deservesupdatetime = true;
            DBExec($c, "update problemtable set fake='{$fake}' where contestnumber={$contestnumber} and " . "problemnumber={$number}", "DBNewProblem(update fake)");
        }
        if ($deservesupdatetime) {
            $ds = DIRECTORY_SEPARATOR;
            if ($ds == "") {
                $ds = "/";
            }
            @unlink($_SESSION["locr"] . $ds . "private" . $ds . "problemtmp" . $ds . "contest" . $contestnumber . "-problem" . $number . '.name');
            DBExec($c, "update problemtable set updatetime=" . $updatetime . " where contestnumber={$contestnumber} and problemnumber={$number}", "DBNewProblem(time)");
        }
        if ($cw) {
            DBExec($c, "commit work", "DBNewProblem(commit)");
        }
        LOGLevel("Problem {$number} (inputfile={$inputfilename}) {$s} (user="******"usertable"]["usernumber"] . ",site=" . $_SESSION["usertable"]["usersitenumber"] . ",contest={$contestnumber})", 2);
        $ret = 2;
    } else {
        if ($cw) {
            DBExec($c, "commit work", "DBNewProblem(commit)");
        }
    }
    return $ret;
}
Ejemplo n.º 3
0
function DBNewTask($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['tasknumber'])) {
        $param['tasknumber'] = $param['number'];
    }
    $ac = array('contest', 'site', 'user', 'desc');
    $ac1 = array('color', 'colorname', 'updatetime', 'filename', 'filepath', 'sys', 'tasknumber', 'status', 'taskdate', 'taskdatediff', 'taskdatediffans', 'taskstaffnumber', 'taskstaffsite');
    $type['contest'] = 1;
    $type['updatetime'] = 1;
    $type['site'] = 1;
    $type['user'] = 1;
    $type['tasknumber'] = 1;
    $type['taskdate'] = 1;
    $type['taskdatediff'] = 1;
    $type['taskdatediffans'] = 1;
    $type['taskstaffnumber'] = 1;
    $type['taskstaffsite'] = 1;
    foreach ($ac as $key) {
        if (!isset($param[$key]) || $param[$key] == "") {
            MSGError("DBNewTask param error: {$key} not found");
            return false;
        }
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewTask param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $taskstaffnumber = -1;
    $taskstaffsite = -1;
    $t = time();
    $taskdate = $t;
    $sys = 'f';
    $filename = '';
    $filepath = '';
    $color = '';
    $colorname = '';
    $tasknumber = -1;
    $taskdatediffans = 999999999;
    $updatetime = -1;
    $status = 'opentask';
    $taskdatediff = -1;
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewTask param error: {$key} is not numeric");
                return false;
            }
        }
    }
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    if ($sys != 't') {
        $sys = 'f';
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewTask(transaction)");
    }
    $insert = true;
    if ($tasknumber < 0) {
        $sql = "select sitenexttask as nexttask, sitemaxtask as maxtask from " . "sitetable where sitenumber={$site} and contestnumber={$contest} for update";
        $r = DBExec($c, $sql, "DBNewTask(get site for update)");
        if (DBnlines($r) != 1) {
            DBExec($c, "rollback work", "DBNewTask(rollback-site)");
            LOGError("Unable to find a unique site/contest in the database. SQL=(" . $sql . ")");
            MSGError("Unable to find a unique site/contest in the database.");
            exit;
        }
        $a = DBRow($r, 0);
        $b = DBSiteInfo($contest, $site, $c);
        $dif = $b["currenttime"];
        if ($taskdatediff < 0) {
            $taskdatediff = $dif;
        }
        if ($sys != 't' && DBCountOpenTasks($contest, $site, $user) > $a["maxtask"]) {
            DBExec($c, "rollback work", "DBNewTask(rollback-maxtask)");
            LOGError("Too many open tasks for user={$user}, site={$site}, contest={$contest}");
            MSGError("Too many open tasks! Task not included.");
            exit;
        }
        if ($sys != 't' && $dif < 0) {
            DBExec($c, "rollback work", "DBNewTask(rollback-started)");
            LOGError("Tried to submit a task but the contest is not started. SQL=(" . $sql . ")");
            MSGError("The contest is not started yet!");
            exit;
        }
        if ($sys != 't' && !$b["siterunning"]) {
            DBExec($c, "rollback work", "DBNewTask(rollback-over)");
            LOGError("Tried to submit a task but the contest is over. SQL=(" . $sql . ")");
            MSGError("The contest is over!");
            exit;
        }
        $tasknumber = $a["nexttask"] + 1;
    } else {
        $sql = "select * from tasktable as t where t.contestnumber={$contest} and " . "t.sitenumber={$site} and t.tasknumber={$tasknumber}";
        $r = DBExec($c, $sql . " for update", "DBNewTask(get task for update)");
        $n = DBnlines($r);
        if ($n > 0) {
            $insert = false;
            $lr = DBRow($r, 0);
            $t = $lr['updatetime'];
        }
    }
    DBExec($c, "update sitetable set sitenexttask={$tasknumber}, updatetime=" . $t . " where sitenumber={$site} and contestnumber={$contest} and sitenexttask<{$tasknumber}", "DBNewTask(update site)");
    $ret = 1;
    if ($insert) {
        if ($filename != "" && $filepath != "") {
            if (substr($filepath, 0, 7) != "base64:") {
                if (($oid = DB_lo_import($c, $filepath)) === false) {
                    DBExec($c, "rollback work", "DBNewTask(rollback-import)");
                    LOGError("DBNewTask: Unable to create a large object for file {$filepath}.");
                    MSGError("problem importing file to database. Contact an admin now!");
                    exit;
                }
            } else {
                $filepath = base64_decode(substr($filepath, 7));
                if (($oid = DB_lo_import_text($c, $filepath)) == null) {
                    DBExec($c, "rollback work", "DBNewTask(rollback-import)");
                    LOGError("DBNewTask: Unable to create a large object for file.");
                    MSGError("problem importing file to database. Contact an admin now!");
                    exit;
                }
            }
        } else {
            $oid = "NULL";
        }
        DBExec($c, "INSERT INTO tasktable (contestnumber, sitenumber, tasknumber, usernumber, taskdate, " . "taskdatediff, taskdatediffans, taskfilename, taskdata, taskstatus, taskdesc, tasksystem, " . "color, colorname, updatetime) " . "VALUES ({$contest}, {$site}, {$tasknumber}, {$user}, {$taskdate}, {$taskdatediff}, {$taskdatediffans}, '{$filename}', {$oid}, '{$status}', " . "'{$desc}', '{$sys}', '{$color}', '{$colorname}', {$updatetime})", "DBNewTask(insert task)");
        if ($sys == "t") {
            $u = "System";
        } else {
            $u = "User {$user}";
        }
        if ($cw) {
            DBExec($c, "commit work", "DBNewTask(commit-insert)");
            LOGLevel("{$u} submitted a task (#{$tasknumber}) on site #{$site} " . "(filename={$filename}, contest={$contest}).", 2);
        }
        $ret = 2;
    } else {
        if ($updatetime > $t) {
            $ret = 2;
            $sql = "update tasktable set usernumber={$user}, taskdesc='{$desc}', " . "color='{$color}',colorname='{$colorname}',taskstatus='{$status}',";
            if ($taskstaffnumber > 0) {
                $sql .= "taskstaffnumber={$taskstaffnumber}, ";
            }
            if ($taskstaffsite > 0) {
                $sql .= "taskstaffsite={$taskstaffsite}, ";
            }
            $sql .= "taskdatediffans={$taskdatediffans}, updatetime={$updatetime} where " . "contestnumber={$contest} and sitenumber={$site} and tasknumber={$tasknumber}";
            DBExec($c, $sql, "DBNewTask(update task)");
        }
        if ($cw) {
            DBExec($c, "commit work", "DBNewTask(commit-update)");
        }
    }
    return $ret;
}
Ejemplo n.º 4
0
function DBNewBkp($contest, $site, $user, $filename, $filepath, $size)
{
    $c = DBConnect();
    DBExec($c, "begin work", "DBNewBkp(transaction)");
    DBExec($c, "lock table bkptable");
    $sql = "select count(*) as n from " . "bkptable where sitenumber={$site} and contestnumber={$contest} and usernumber={$user} and bkpstatus='active'";
    $r = DBExec($c, $sql, "DBNewBkp(get bkp of user)");
    if (DBnlines($r) != 1) {
        DBExec($c, "rollback work", "DBNewBkp(rollback-toomanyerror)");
        LOGError("Error in bkp table. SQL=(" . $sql . ")");
        MSGError("Error in bkp table.");
        exit;
    }
    $a = DBRow($r, 0);
    if ($a['n'] > 100) {
        DBExec($c, "rollback work", "DBNewBkp(rollback-toomany)");
        LOGError("Too many bkps from user={$user}, site={$site}, contest={$contest}.", 2);
        MSGError("Too many bkp files. Try remove some of them before uploading another.");
        return false;
    }
    $sql = "select max(bkpnumber) as nextbkp from " . "bkptable where sitenumber={$site} and contestnumber={$contest}";
    $r = DBExec($c, $sql, "DBNewBkp(get bkp for update)");
    if (DBnlines($r) != 1) {
        DBExec($c, "rollback work", "DBNewBkp(rollback-max)");
        LOGError("Error in bkp table. SQL=(" . $sql . ")");
        MSGError("Error in bkp table.");
        exit;
    }
    $a = DBRow($r, 0);
    $t = time();
    $n = $a["nextbkp"] + 1;
    if (($oid = DB_lo_import($c, $filepath)) === false) {
        DBExec($c, "rollback work", "DBNewBkp(rollback-import)");
        LOGError("Unable to create a large object for file {$filepath}.");
        MSGError("problem importing bkp to database. Contact an admin now!");
        exit;
    }
    DBExec($c, "INSERT INTO bkptable (contestnumber, sitenumber, bkpnumber, usernumber, bkpdate, bkpfilename, bkpdata, bkpstatus, bkpsize) " . "VALUES ({$contest}, {$site}, {$n}, {$user}, {$t}, '{$filename}', {$oid}, 'active', {$size})", "DBNewBkp(insert bkp)");
    DBExec($c, "commit work", "DBNewBkp(commit)");
    LOGLevel("User {$user} submitted a bkp (#{$n}) on site #{$site} " . "(filename={$filename}, contest={$contest}).", 2);
    /* // isso gera problemas de portabilidade e de seguranca (quando outros usuarios tambem tem shell
       // no servidor e podem construir paginas web. Eles podem usar essas paginas para acessar esses arquivos,
       // pois os mesmos ficaram com dono apache/www-data/etc)
    	umask(0077);
    	@mkdir("/tmp/boca");
            if (!move_uploaded_file ($filepath,
    		"/tmp/boca/contest${contest}.site${site}.run${n}.user${user}.problem${problem}.time${t}.${filename}"))
    		LOGLevel("Run not saved as file (run=$n,site=$site,contest=$contest", 1);
    */
}