Exemplo n.º 1
0
//
//    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
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">
Exemplo n.º 2
0
function DBNewLanguage($contestnumber, $param, $c = null)
{
    if (isset($param["action"]) && $param["action"] == "delete") {
        return DBDeleteLanguage($contestnumber, $param, $c);
    }
    $ac = array('number', 'name');
    $ac1 = array('updatetime', 'extension');
    $type['number'] = 1;
    $type['updatetime'] = 1;
    $extension = '';
    foreach ($ac as $key) {
        if (!isset($param[$key]) || $param[$key] == "") {
            MSGError("DBNewLanguage param error: {$key} not found");
            return false;
        }
        if (isset($type[$key]) && !is_numeric($param[$key])) {
            MSGError("DBNewLanguage param error: {$key} is not numeric");
            return false;
        }
        ${$key} = sanitizeText($param[$key]);
    }
    $updatetime = -1;
    foreach ($ac1 as $key) {
        if (isset($param[$key])) {
            ${$key} = sanitizeText($param[$key]);
            if (isset($type[$key]) && !is_numeric($param[$key])) {
                MSGError("DBNewLanguage param error: {$key} is not numeric");
                return false;
            }
        }
    }
    $t = time();
    if ($updatetime <= 0) {
        $updatetime = $t;
    }
    $cw = false;
    if ($c == null) {
        $cw = true;
        $c = DBConnect();
        DBExec($c, "begin work", "DBNewLanguage(transaction)");
    }
    $sql2 = "select * from langtable where contestnumber={$contestnumber} and langnumber={$number}";
    $r = DBExec($c, $sql2 . " for update", "DBNewLanguage(get lang)");
    $n = DBnlines($r);
    $ret = 1;
    if ($n == 0) {
        DBExec($c, "insert into langtable (contestnumber,langnumber, langname,langextension) values " . "({$contestnumber}, {$number}, '{$name}','{$extension}')", "DBNewLanguage(insert lang)");
        $s = "created";
    } else {
        $lr = DBRow($r, 0);
        $t = $lr['updatetime'];
        if ($updatetime > $t) {
            if ($name != "") {
                DBExec($c, "update langtable set langname='{$name}', updatetime={$updatetime} where contestnumber={$contestnumber} " . "and langnumber={$number}", "DBNewLanguage(update lang)");
            }
            if ($extension != "") {
                DBExec($c, "update langtable set langextension='{$extension}', updatetime={$updatetime} where contestnumber={$contestnumber} " . "and langnumber={$number}", "DBNewLanguage(update lang)");
            }
        }
        $s = "updated";
    }
    if ($cw) {
        DBExec($c, "commit work", "DBNewLanguage(commit)");
    }
    if ($s == "created" || $updatetime > $t) {
        LOGLevel("Language {$number} updated (user="******"usertable"]["usernumber"] . ",site=" . $_SESSION["usertable"]["usersitenumber"] . ",contest={$contestnumber})", 2);
        $ret = 2;
    }
    return $ret;
}