username = $_POST["authusername"]; $this->password = $_POST["authpassword"]; $this->savepass = $_POST["authsavepass"]; $this->sessionStart = 0; # clear POST vars so as not to confuse the receiving page $_POST = array(); $this->session = false; $this->checkPass(); } elseif ($_COOKIE["authusername"]) { $this->username = $_COOKIE["authusername"]; $this->password = $_COOKIE["authpassword"]; $this->savepass = $_COOKIE["authsavepass"]; $this->sessionStart = $_COOKIE["authsessionStart"]; $this->session = true; $this->checkPass(); } else { $this->ok = false; $this->error = false; $this->session = false; $this->printAuth(); } } function checkPass() { global $db; $db->query(" SELECT * FROM hlstats_Users WHERE username='$this->username' "); if ($db->num_rows() == 1) { // The username is OK $this->userdata = $db->fetch_array(); $db->free_result(); if (md5($this->password) == $this->userdata["password"]) { // The username and the password are OK $this->ok = true; $this->error = false; if ($this->sessionStart > (time()-3600)) { // Valid session, update session time & display the page $this->doCookies(); return true; } elseif ($this->sessionStart) { // A session exists but has expired if ($this->savepass) { // They selected 'Save my password' so we just // generate a new session and show the page. $this->doCookies(); return true; } else { $this->ok = false; $this->error = "Your session has expired. Please try again."; $this->password = ""; $this->printAuth(); return false; } } elseif (!$this->session) { // No session and no cookies, but the user/pass was // POSTed, so we generate cookies. $this->doCookies(); return true; } else { // No session, user/pass from a cookie, so we force auth $this->printAuth(); return false; } } else { // The username is OK but the password is wrong $this->ok = false; if ($this->session) { // Cookie without 'Save my password' - not an error $this->error = false; } else { $this->error = "The password you supplied is incorrect."; } $this->password = ""; $this->printAuth(); } } else { // The username is wrong $this->ok = false; $this->error = "The username you supplied is not valid."; $this->printAuth(); } } function doCookies() { setCookie("authusername", $this->username, time()+31536000, "", "", 0); if ($this->savepass) { setCookie("authpassword", $this->password, time()+31536000, "", "", 0); } else { setCookie("authpassword", $this->password, 0, "", "", 0); } setCookie("authsavepass", $this->savepass, time()+31536000, "", "", 0); setCookie("authsessionStart", time(), 0, "", "", 0); } function printAuth() { global $g_options; include(INCLUDE_PATH . "/adminauth.inc"); exit(); } } class AdminTask { var $title = ""; var $acclevel = 0; var $type = ""; var $description = ""; function AdminTask ($title, $acclevel, $type="general", $description="") { $this->title = $title; $this->acclevel = $acclevel; $this->type = $type; $this->description = $description; } } class EditList { var $columns; var $keycol; var $table; var $icon; var $showid; var $errors; var $newerror; function EditList ($keycol, $table, $icon, $showid=true) { $this->keycol = $keycol; $this->table = $table; $this->icon = $icon; $this->showid = $showid; } function update () { global $HTTP_POST_VARS, $db; $okcols = 0; foreach ($this->columns as $col) { $value = $HTTP_POST_VARS["new_$col->name"]; if ($value != "") { if ($col->type == "ipaddress" && !ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $value)) { $this->errors[] = "Column '$col->title' requires a valid IP address for new row"; $this->newerror = true; $okcols++; } else { if ($qcols) $qcols .= ", "; $qcols .= $col->name; if ($qvals) $qvals .= ", "; if ($col->type == "password") { $qvals .= "MD5('$value')"; } else { $qvals .= "'$value'"; } if ($col->type != "select" && $col->type != "hidden" && $value != $col->datasource) $okcols++; } } elseif ($col->required) { $this->errors[] = "Required column '$col->title' must have a value for new row"; $this->newerror = true; } } if ($okcols > 0 && !$this->errors) { $db->query(" INSERT INTO $this->table ( $qcols ) VALUES ( $qvals )", false ); if ($db->dberror()) { $this->errors[] = "DB Error: " . $db->dberror(); } } elseif ($okcols == 0) { $this->errors = array(); $this->newerror = false; } if (!is_array($HTTP_POST_VARS["rows"])) return true; foreach ($HTTP_POST_VARS["rows"] as $row) { $row = stripslashes($row); if ($HTTP_POST_VARS[$row . "_delete"]) { $db->query(" DELETE FROM $this->table WHERE $this->keycol='" . addslashes($row) . "' "); } else { $rowerror = false; $query = "UPDATE $this->table SET "; $i=0; foreach ($this->columns as $col) { $value = $HTTP_POST_VARS[$row . "_" . $col->name]; if ($col->type == "password" && $value == "(encrypted)") continue; if ($value == "" && $col->required) { $this->errors[] = "Required column '$col->title' must have a value for row '$row'"; $rowerror = true; } elseif ($col->type == "ipaddress" && !ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $value)) { $this->errors[] = "Column '$col->title' requires a valid IP address for row '$row'"; $rowerror = true; } if ($i > 0) $query .= ", "; if ($col->type == "password") { $query .= $col->name . "=MD5('$value')"; } else { $query .= $col->name . "='$value'"; } $i++; } $query .= " WHERE $this->keycol='" . addslashes($row) . "'"; if (!$rowerror) { $db->query($query); } } } if ($this->error()) { return false; } else { return true; } } function draw ($result) { global $g_options, $HTTP_POST_VARS, $db; ?> ">
"; if ($this->showid) { ?> columns as $col) { if ($col->type == "hidden") continue; echo "\n"; } ?> fetch_array($result)) { echo "\n\n"; echo "\n"; if ($this->showid) { echo "\n"; } $this->drawfields($rowdata, false, false); ?> \n\n"; } ?> " . $g_options["font_small"] . "new" . $g_options["fontend_small"] . "\n"; if ($this->showid) echo "\n"; if ($this->newerror) { $this->drawfields($HTTP_POST_VARS, true, true); } else { $this->drawfields(array(), true); } echo "\n"; ?>
"> " . $g_options["font_small"] . "" . $col->title . "" . $g_options["fontend_small"] . "">
"; echo "icon.gif\" width=16 height=16 border=0>" . $g_options["font_small"] . $rowdata[$this->keycol] . $g_options["fontend_small"] . "">
" . $g_options["font_small"] . " " . $g_options["fontend_small"] . "

columns as $col) { if ($new) { $keyval = "new"; $rowdata[$col->name] = $rowdata["new_$col->name"]; if ($stripslashes) $rowdata[$col->name] = stripslashes($rowdata[$col->name]); } else { $keyval = $rowdata[$this->keycol]; if ($stripslashes) $keyval = stripslashes($keyval); } if ($col->type != "hidden") { echo ""; } if ($i == 0 && !$new) { echo ""; } if ($col->maxlength < 1) $col->maxlength = ""; switch ($col->type) { case "select": unset($coldata); if (ereg(";", $col->datasource)) { // for manual datasource in format "key/value;key/value" or "key;key" foreach (explode(";", $col->datasource) as $v) { if (ereg("/", $v)) { list($a, $b) = explode("/", $v); $coldata[$a] = $b; } else { $coldata[$v] = $v; } } } else { // for SQL datasource in format "table.column/keycolumn/where" list($col_table, $col_col) = explode(".", $col->datasource); list($col_col, $col_key, $col_where) = explode("/", $col_col); if ($col_where) $col_where = "WHERE $col_where"; $col_result = $db->query("SELECT $col_key, $col_col FROM $col_table $col_where ORDER BY $col_key"); $coldata = array(); while (list($k, $v) = $db->fetch_row($col_result)) { $coldata[$k] = $v; } } if ($col->width) $width = " style=\"width:" . $col->width*5 . "px\""; else $width = ""; echo ""; break; case "checkbox": $selectedval = "1"; $value = $rowdata[$col->name]; if ($value == $selectedval) $selected = " checked"; else $selected = ""; echo "

name\" value=\"$selectedval\"$selected>
"; break; case "hidden": echo "name\" value=\"" . htmlspecialchars($col->datasource) . "\">"; break; default: if ($col->datasource != "" && !isset($rowdata[$col->name])) $value = $col->datasource; else $value = $rowdata[$col->name]; echo "name\" size=$col->width " . "value=\"" . htmlspecialchars($value) . "\" class=\"textbox\"" . " maxlength=\"$col->maxlength\">"; } if ($col->type != "hidden") { echo "\n"; } $i++; } } function error() { if (is_array($this->errors)) { return implode("

\n\n", $this->errors); } else { return false; } } } class EditListColumn { var $name; var $title; var $width; var $required; var $type; var $datasource; var $maxlength; function EditListColumn ($name, $title, $width=20, $required=false, $type="text", $datasource="", $maxlength=0) { $this->name = $name; $this->title = $title; $this->width = $width; $this->required = $required; $this->type = $type; $this->datasource = $datasource; $this->maxlength = intval($maxlength); } } class PropertyPage { var $table; var $keycol; var $keyval; var $propertygroups = array(); function PropertyPage ($table, $keycol, $keyval, $groups) { $this->table = $table; $this->keycol = $keycol; $this->keyval = $keyval; $this->propertygroups = $groups; } function draw ($data) { foreach ($this->propertygroups as $group) { $group->draw($data); } } function update () { global $HTTP_POST_VARS, $db; $setstrings = array(); foreach ($this->propertygroups as $group) { foreach ($group->properties as $prop) { $setstrings[] = $prop->name . "='" . $HTTP_POST_VARS[$prop->name] . "'"; } } $db->query(" UPDATE " . $this->table . " SET " . implode(",\n", $setstrings) . " WHERE " . $this->keycol . "='" . $this->keyval . "' "); } } class PropertyPage_Group { var $title = ""; var $properties = array(); function PropertyPage_Group ($title, $properties) { $this->title = $title; $this->properties = $properties; } function draw ($data) { global $g_options; ?> title; ?>
">
properties as $prop) { $prop->draw($data[$prop->name]); } ?>

name = $name; $this->title = $title; $this->type = $type; $this->datasource = $datasource; } function draw ($value) { global $g_options; ?> ">title . ":"; echo $g_options["fontend_normal"]; ?> ">type) { case "textarea": echo ""; break; case "select": // for manual datasource in format "key/value;key/value" or "key;key" foreach (explode(";", $this->datasource) as $v) { if (ereg("/", $v)) { list($a, $b) = explode("/", $v); $coldata[$a] = $b; } else { $coldata[$v] = $v; } } echo getSelect($this->name, $coldata, $value); break; default: echo "name\" size=35 value=\"" . htmlspecialchars($value) . "\" class=\"textbox\">"; break; } ?>
.gif" width=16 height=16 border=0 hspace=5> $msg"; echo $g_options["fontend_normal"]; ?>

"")); $selTask = $HTTP_GET_VARS["task"]; $selGame = $HTTP_GET_VARS["admingame"]; ?>
type == "tool" || $admintasks[$selTask]->type == "subtool") { $task = $admintasks[$selTask]; $code = $selTask; ?>  /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> ?mode=admin">Tools
/spacer.gif" width=1 height=8 border=0>
 /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> General Settings

$task) { if ($auth->userdata["acclevel"] >= $task->acclevel && $task->type == "general") { if ($selTask == $code) { ?>     /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> ?mode=admin" name="">title; ?>

?mode=admin&task=#">
 


    /rightarrow.gif" width=6 height=9 border=0 align="middle" alt="rightarrow.gif"> ?mode=admin&task=#">title; ?>

 /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> Game Settings

query(" SELECT name, code FROM hlstats_Games "); while ($gamedata = $db->fetch_array($gamesresult)) { $gamename = $gamedata["name"]; $gamecode = $gamedata["code"]; if ($gamecode == $selGame) { ?>     /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> ?mode=admin" name="game_"> ()

$task) { if ($auth->userdata["acclevel"] >= $task->acclevel && $task->type == "game") { if ($selTask == $code) { ?>         /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> ?mode=admin&admingame=" name="">title; ?>

?mode=admin&admingame=&task=#">
 


        /rightarrow.gif" width=6 height=9 border=0 align="middle" alt="downarrow.gif"> ?mode=admin&admingame=&task=#">title; ?>

    /rightarrow.gif" width=6 height=9 border=0 align="middle" alt="rightarrow.gif"> ?mode=admin&admingame=#game_"> ()

\n"; if (!$selTask || !$admintasks[$selTask]) { echo "

"; echo $g_options["font_normal"]; ?>  /downarrow.gif" width=9 height=6 border=0 align="middle" alt="downarrow.gif"> Tools "; } ?>