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; }
$param['changepass'] = trim($tmp[1]); break; case "userip": $param['permitip'] = trim($tmp[1]); break; } $i++; if ($i >= count($ar)) { break; } $x = trim($ar[$i]); } $param['contest'] = $_SESSION["usertable"]["contestnumber"]; if ($_SESSION["usertable"]["usersitenumber"] == $param['site'] || $main) { if ($param['usernumber'] != 1000) { DBNewUser($param); } } } } } } if (count($userlist) > 0) { ?> <center> <br><u><b>TAKE NOTE OF THE USERS AND PASSWORDS AND KEEP THEM SECRET</b></u><br><br> <table border=1> <tr> <td nowrap><b>Site</b></td><td><b>User #</b></td> <td><b>Password</b></td> </tr>