Exemple #1
0
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;
}
Exemple #2
0
//    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
require 'header.php';
if (isset($_POST["message"]) && isset($_POST["problem"]) && isset($_POST["Submit"])) {
    if ($_POST["confirmation"] == "confirm") {
        $param['contest'] = $_SESSION["usertable"]["contestnumber"];
        $param['site'] = $_SESSION["usertable"]["usersitenumber"];
        $param['user'] = $_SESSION["usertable"]["usernumber"];
        $param['problem'] = htmlspecialchars($_POST["problem"]);
        $param['question'] = htmlspecialchars($_POST["message"]);
        DBNewClar($param);
    }
    ForceLoad("clar.php");
}
?>
<br>
<table width="100%" border=1>
 <tr>
  <td><b>Clar #</b></td>
  <td><b>Site</b></td>
  <td><b>Time</b></td>
  <td><b>Problem</b></td>
  <td><b>Status</b></td>
  <td><b>Question</b></td>
 </tr>
<?php