function importFromXML($ar, $acr, $contest = 0, $localsite = 0) { $data = implode("", explode("\n", $ar)); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $values, $tags); xml_parser_free($parser); // print_r($tags); // print_r($values); $orderkeys = array('CONTESTREC', 'SITETIME', 'SITEREC', 'USERREC', 'ANSWERREC', 'LANGUAGEREC', 'PROBLEMREC', 'CLARREC', 'RUNREC', 'TASKREC'); $norderkeys = 10; $nc = 0; unset($sitetime); unset($nsitetime); $conn = DBConnect(); if ($conn == null) { return false; } // DBExec($conn,"begin work","importFromXML(begin)"); // DBExec($conn,"lock","importFromXML(lock)"); if ($contest != 0) { $r = DBExec($conn, "select * from contesttable where contestnumber={$contest}"); if (DBnLines($r) == 0) { echo "Unable to find the contest {$contest} in the database.\n"; DBExec($conn, "rollback work"); return false; } $ct = DBRow($r, 0); if ($localsite == 0) { $localsite = $ct["contestlocalsite"]; } } else { if ($localsite == 0) { $localsite = 1; } } // $mainsite = $ct["contestmainsite"]; DBClose($conn); $conn = null; for ($keyindex = 0; $keyindex < $norderkeys; $keyindex++) { foreach ($tags as $key => $val) { if ($values[$val[0]]['type'] != 'open') { continue; } if ($key == "XML") { continue; } if ($key != $orderkeys[$keyindex]) { continue; } if (isset($acr[$key])) { $ac = $acr[$key]; } else { continue; } foreach ($val as $k => $v) { if ($values[$v]['type'] != 'open') { continue; } if (count($val) > $k + 1) { $param = array(); if (isset($ac['site'])) { for ($i = $v; $i < $val[$k + 1]; $i++) { $p = strtolower($values[$i]["tag"]); if ($p == 'site') { if ($values[$i]["type"] == "complete" && isset($values[$i]["value"])) { $tmp = sanitizeText(trim(implode('', explode('\\n', $values[$i]["value"])))); if (is_array($ac['site']) && in_array($tmp, $ac['site'])) { $param['site'] = $tmp; } else { if ($ac['site'] == -1 || $ac['site'] == -2 && $tmp == $localsite || $ac['site'] == -3 && $tmp != $localsite || $ac['site'] > 0 && $ac['site'] == $tmp) { $param['site'] = $tmp; } } } } } } for ($i = $v; $i < $val[$k + 1]; $i++) { $p = strtolower($values[$i]["tag"]); if (isset($ac[$p]) && $p != 'site') { if ($values[$i]["type"] == "complete" && isset($values[$i]["value"])) { if (is_string($ac[$p])) { $param[$p] = $ac[$p]; } else { $tmp = sanitizeText(trim(implode('', explode('\\n', $values[$i]["value"])))); if (is_array($ac[$p]) && in_array($tmp, $ac[$p])) { $param[$p] = $tmp; } else { if ($ac[$p] == -1 || $ac[$p] == -2 && $tmp == $localsite || $ac[$p] == -3 && $tmp != $localsite || $ac[$p] == 0 && isset($param['site']) || $ac[$p] > 0 && $ac[$p] == $tmp) { $param[$p] = $tmp; } } } } } } // echo "\nKEY KEY KEY\n"; // print_r($key); // echo "\nVAL VAL VAL\n"; // print_r($val); // echo "\n"; // print_r($param); $param['contestnumber'] = $contest; if ($key == "CONTESTREC") { $param['number'] = $contest; if ($contest == 0) { $nc = 1; $contest = DBNewContest($param, $conn); if ($contest > 0) { echo "<br><u>Contest {$contest} created</u> (not active by default)<br>"; } else { echo "<br>Error creating contest<br>"; if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } $param['number'] = $contest; $param['contestnumber'] = $contest; if ($ret = DBUpdateContest($param, $conn)) { if ($ret == 2) { echo "<br>Contest {$contest} updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if (!isset($param['number']) || count($param) < 2) { continue; } if ($key == "SITEREC") { if (!DBNewSite($contest, $conn, $param)) { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } if ($ret = DBUpdateSite($param, $conn)) { if ($ret == 2) { echo "Site " . $param["number"] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } if (isset($nsitetime[$param["number"]])) { if ($qtd = DBRenewSiteTime($sitetime[$param["number"]], $conn)) { if ($qtd == 2) { echo "Time for site " . $param["number"] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } } if ($key == "SITETIME") { if (isset($param['site']) && is_numeric($param['site'])) { $s = $param['site']; if (!isset($nsitetime[$s])) { $nsitetime[$s] = 0; } $sitetime[$s][$nsitetime[$s]] = $param; $nsitetime[$s]++; } } if ($key == "USERREC") { if ($ret = DBNewUser($param, $conn)) { if ($ret == 2) { echo "User " . $param["number"] . "/" . $param['site'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "ANSWERREC") { if ($ret = DBNewAnswer($contest, $param, $conn)) { if ($ret == 2) { echo "Answer " . $param["number"] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "LANGUAGEREC") { if ($ret = DBNewLanguage($contest, $param, $conn)) { if ($ret == 2) { echo "Language " . $param['number'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "PROBLEMREC") { if ($ret = DBNewProblem($contest, $param, $conn)) { if ($ret == 2) { echo "Problem " . $param['number'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "TASKREC") { if ($ret = DBNewTask($param, $conn)) { if ($ret == 2) { echo "Task " . $param['number'] . "/" . $param['site'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "CLARREC") { if ($ret = DBNewClar($param, $conn)) { if ($ret == 2) { echo "Clarification " . $param['number'] . "/" . $param['site'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } if ($key == "RUNREC") { if ($ret = DBNewRun($param, $conn)) { if ($ret == 2) { echo "Run " . $param['number'] . "/" . $param['site'] . " updated<br>"; } } else { if ($conn != null) { DBExec($conn, "rollback work"); } return false; } } } } } } // DBExec($conn,"commit work","importFromXML(commit)"); return true; }
require 'header.php'; if (($ct = DBContestInfo($_SESSION["usertable"]["contestnumber"])) == null) { ForceLoad("../index.php"); } if (isset($_GET["delete"]) && is_numeric($_GET["delete"])) { $param["number"] = $_GET["delete"]; DBDeleteLanguage($_SESSION["usertable"]["contestnumber"], $param); ForceLoad("language.php"); } if (isset($_POST["Submit3"]) && isset($_POST["langnumber"]) && is_numeric($_POST["langnumber"]) && isset($_POST["langname"]) && $_POST["langname"] != "") { if ($_POST["confirmation"] == "confirm") { $param = array(); $param['number'] = $_POST['langnumber']; $param['name'] = $_POST['langname']; $param['extension'] = $_POST['langextension']; DBNewLanguage($_SESSION["usertable"]["contestnumber"], $param); } ForceLoad("language.php"); } ?> <br> <script language="javascript"> function conf2(url) { if (confirm("Confirm the DELETION of the LANGUAGE and ALL data associated to it (including the SUBMISSIONS)?")) { if (confirm("Are you REALLY sure about what you are doing? DATA CANNOT BE RECOVERED!")) { document.location=url; } else { document.location='language.php'; } } else { document.location='language.php';
function insertlanguages($n, $c = null) { $ok = false; $param = null; $param['number'] = 1; $param['name'] = 'C'; $param['extension'] = 'c'; DBNewLanguage($n, $param, $c); $param['number'] = 2; $param['name'] = 'C++'; $param['extension'] = 'cpp'; DBNewLanguage($n, $param, $c); $param['number'] = 3; $param['name'] = 'Java'; $param['extension'] = 'java'; DBNewLanguage($n, $param, $c); // $param['number']=4; // $param['name']='C++11'; // $param['extension']='cc'; // DBNewLanguage($n, $param, $c); }
$langcompscript = substr($langcompscript, 7); $compscript = base64_decode($compscript); } if (trim($langcompscripthash) != "" && myshorthash($compscript) != trim($langcompscripthash)) { echo "ERROR: Hash of {$langcompscript} does not match<br>\n"; } break; } $i++; if ($i >= count($ar)) { break; } $x = trim($ar[$i]); } if (isset($langnumber) && is_numeric($langnumber) && isset($langname)) { DBNewLanguage($nc, $langnumber, $langname, $langproblem, '', '', $langshowingoutput, $script, $langscript, $compscript, $langcompscript, 1, 1); echo "Language {$langnumber} created<br>"; } } } for (; $i < count($ar) && strpos($ar[$i], "[problem]") === false; $i++) { } for ($i++; $i < count($ar) && $ar[$i][0] != "["; $i++) { echo "<br>Searching for problems<br>\n"; $x = trim($ar[$i]); if (strpos($x, "prob") !== false && strpos($x, "prob") == 0) { unset($probnumber); unset($probname); unset($probfullname); unset($probbasename); unset($probinputfile);