// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////////////// // Last modified 05/aug/2012 by cassio@ime.usp.br //Change list: // 02/jul/2006 by cassio@ime.usp.br // 25/aug/2007 by cassio@ime.usp.br: php initial tag changed to complete form require 'header.php'; if (isset($_GET["new"]) && $_GET["new"] == "1") { $n = DBNewContest(); ForceLoad("contest.php?contest={$n}"); } if (isset($_GET["contest"]) && is_numeric($_GET["contest"])) { $contest = $_GET["contest"]; } else { $contest = $_SESSION["usertable"]["contestnumber"]; } if (($ct = DBContestInfo($contest)) == null) { ForceLoad("../index.php"); } if ($ct["contestlocalsite"] == $ct["contestmainsite"]) { $main = true; } else { $main = false; }
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; }
if (($ar = file($temp)) === false) { IntrusionNotify("Unable to open the uploaded file."); ForceLoad("../index.php"); } echo "<br>Starting to create the contest<br>"; $asep = trim($ar[0]); $i = 1; for (; $i < count($ar) && strpos($ar[$i], "[contest]") === false; $i++) { } for ($i++; $i < count($ar) && $ar[$i][0] != "["; $i++) { $x = trim($ar[$i]); //contestname, startdate, duration, lastmileanswer, lastmilescore, penalty, contestactive $tmp = explode("=", $x, 2); $param[trim($tmp[0])] = trim($tmp[1]); } $nc = DBNewContest($param); echo "<br>Contest {$nc} created<br>"; for (; $i < count($ar) && strpos($ar[$i], "[site]") === false; $i++) { } while (strpos($ar[$i], "[site]") === true) { for ($i++; $i < count($ar) && $ar[$i][0] != "["; $i++) { $x = trim($ar[$i]); // sitenumber, siteip, sitename, scorelevel $tmp = explode("=", $x, 2); $param[trim($tmp[0])] = trim($tmp[1]); } DBNewSite($nc, null, $param); echo "New site created<br>"; } for (; $i < count($ar) && strpos($ar[$i], "[answer]") === false; $i++) { }