X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fadmin.php;h=c3428e663353048111eda4bc3a5147a016bfbc74;hb=484a365c1e66ba4b878117275423a1594c209960;hp=a3857acfd95390fbf9bc127a593902c27378410e;hpb=1e77a6539b5df73e362c36c11df1b0e3696c1647;p=brisk.git diff --git a/web/admin.php b/web/admin.php index a3857ac..c3428e6 100644 --- a/web/admin.php +++ b/web/admin.php @@ -2,7 +2,7 @@ /* * brisk - admin.php * - * Copyright (C) 2006-2011 Matteo Nastasi + * Copyright (C) 2011-2015 Matteo Nastasi * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it @@ -21,46 +21,230 @@ * Suite 330, Boston, MA 02111-1307, USA. * */ - + +$G_base = ""; + require_once("Obj/brisk.phh"); require_once("Obj/dbase_pgsql.phh"); +ini_set("max_execution_time", "300"); + +class ImpPoints +{ + var $time; + var $tsess; + var $user_sess; + var $isauth; + var $username; + var $useraddr; + var $where; + var $ttok; + var $tidx; + var $nplayers; + var $logins; + var $pts; + + function ImpPoints($s) + { + $arr = explode('|', $s); + + if (count($arr) != 20) { + return FALSE; + } + + + $this->time = $arr[0]; + $this->usess = $arr[1]; + $this->isauth = $arr[2]; + $this->username = $arr[3]; + $this->useraddr = $arr[4]; + $this->where = $arr[5]; + $this->ttok = $arr[6]; + $this->tidx = $arr[7]; + $this->nplayers = $arr[8]; + + $this->logins = array(); + $this->pts = array(); + + for ($i = 9 ; $i < 19 ; $i+=2) { + $idx = ($i - 9) / 2; + $this->logins[$idx] = strtolower($arr[$i]); + $this->pts[$idx] = $arr[$i+1]; + } + } +} + $cont = ""; function main() { - GLOBAL $cont, $G_alarm_passwd, $F_pass_private, $F_ACT, $F_filename; + GLOBAL $cont, $G_dbpfx, $G_alarm_passwd, $F_pass_private, $F_ACT, $F_filename; + + + if (FALSE && $F_pass_private != $G_alarm_passwd) { + $cont .= sprintf("Wrong password, operation aborted.
\n"); + return; + } if ($F_ACT == "append") { do { - if ($F_pass_private != $G_alarm_passwd) { - $cont .= sprintf("Wrong password, operation aborted.
\n"); - break; - } + /* + if ($F_pass_private != $G_alarm_passwd) { + $cont .= sprintf("Wrong password, operation aborted.
\n"); + break; + }*/ $cont .= sprintf("FILENAME: %s
\n", $F_filename); if (($olddb = new LoginDBOld($F_filename)) == FALSE) { $cont .= sprintf("Loading failed.
\n"); break; } - $newdb = new LoginDB(); + + if (($newdb = BriskDB::create()) == FALSE) { + $cont .= sprintf("Database connection failed.
\n"); + break; + } + $newdb->users_load(); if ($newdb->addusers_from_olddb($olddb, $cont) == FALSE) { $cont .= sprintf("Insert failed.
\n"); } - $cont .= sprintf("Item number: %d
\n", $olddb->count()); + $cont .= sprintf("SUCCESS
Item number: %d
\n", $olddb->count()); } while (0); } + else if ($F_ACT == "pointsimp") { + do { + if (!file_exists($F_filename)) { + $cont .= sprintf("File [%s] not exists.
\n", $F_filename); + break; + } + + $cont .= sprintf("FILENAME: %s
\n", $F_filename); + + if (!($fp = @fopen($F_filename, "r"))) { + $cont .= sprintf("Open file [%s] failed.
\n", $F_filename); + break; + } + + if (($newdb = BriskDB::create()) == FALSE) { + $cont .= sprintf("Database connection failed.
\n"); + break; + } + + $newdb->users_load(); + $dbconn = $newdb->getdbconn(); + for ($pts_n = 0 ; !feof($fp) ; $pts_n++) { + $bf = fgets($fp, 4096); + if ($bf == FALSE) + break; + + if (($pts = new ImpPoints($bf)) == FALSE) { + $cont .= sprintf("Import failed at line [%s]
\n", eschtml($bf)); + break; + } + if ($pts->time < 1285884000) { + continue; + } + // else { + // $cont .= sprintf("ttok: %s
\n", $pts->ttok); + // } + + /* + * matches management + */ + $mtc_sql = sprintf("SELECT * FROM %sbin5_matches WHERE ttok = '%s';", $G_dbpfx, escsql($pts->ttok)); + if (($mtc_pg = pg_query($dbconn->db(), $mtc_sql)) == FALSE || pg_numrows($mtc_pg) != 1) { + // match not exists, insert it + $mtc_sql = sprintf("INSERT INTO %sbin5_matches (ttok, tidx) VALUES ('%s', %d) RETURNING *;", + $G_dbpfx, escsql($pts->ttok), $pts->tidx); + if ( ! (($mtc_pg = pg_query($dbconn->db(), $mtc_sql)) != FALSE && + pg_affected_rows($mtc_pg) == 1) ) { + $cont .= sprintf("Matches insert failed at line [%s] [%s]
\n", + eschtml($bf), eschtml($mtc_sql)); + break; + } + + } + $mtc_obj = pg_fetch_object($mtc_pg,0); + // $cont .= sprintf("MTC: %s
\n", esclfhtml(print_r($mtc_obj, TRUE))); + // $cont .= sprintf("pts_n: %d mtc_match_code: %d
\n", $pts_n, $mtc_obj->code); + + /* + * games management + */ + $gam_sql = sprintf("SELECT * FROM %sbin5_games WHERE mcode = %d and tstamp = to_timestamp(%d);", + $G_dbpfx, $mtc_obj->code, $pts->time); + if (($gam_pg = pg_query($dbconn->db(), $gam_sql)) == FALSE || pg_numrows($gam_pg) != 1) { + // match not exists, insert it + $gam_sql = sprintf("INSERT INTO %sbin5_games (mcode, tstamp) + VALUES (%d, to_timestamp(%d)) RETURNING *;", + $G_dbpfx, $mtc_obj->code, $pts->time); + if ( ! (($gam_pg = pg_query($dbconn->db(), $gam_sql)) != FALSE && + pg_affected_rows($gam_pg) == 1) ) { + $cont .= sprintf("Games insert failed at line [%s] [%s]
\n", + eschtml($bf), eschtml($gam_sql)); + break; + } + } + $gam_obj = pg_fetch_object($gam_pg,0); + // $cont .= sprintf("GAM: %s
\n", esclfhtml(print_r($gam_obj, TRUE))); + // $cont .= sprintf("pts_n: %d mtc_match_code: %d
\n", $pts_n, $gam_obj->code); + + /* + * points management + */ + for ($i = 0 ; $i < 5 ; $i++) { + /* get the login associated code */ + $usr_sql = sprintf("SELECT * FROM %susers WHERE login = '%s';", + $G_dbpfx, escsql($pts->logins[$i])); + if (($usr_pg = pg_query($dbconn->db(), $usr_sql)) == FALSE || pg_numrows($usr_pg) != 1) { + $cont .= sprintf("User [%s] not found [%s]
\n", eschtml($pts->logins[$i]), eschtml($usr_sql)); + save_rej($pts->logins[$i]); + continue; + } + $usr_obj = pg_fetch_object($usr_pg,0); + + /* put points */ + $pts_sql = sprintf("INSERT INTO %sbin5_points (gcode, ucode, pts) + VALUES (%d, %d, %d) RETURNING *;", + $G_dbpfx, $gam_obj->code, $usr_obj->code, $pts->pts[$i]); + if ( ! (($pts_pg = pg_query($dbconn->db(), $pts_sql)) != FALSE && + pg_affected_rows($pts_pg) == 1) ) { + $cont .= sprintf("Point insert failed at line [%s] [%s] idx: [%d]
\n", + eschtml($bf), eschtml($gam_sql), $i); + break; + } + + } + + } + fclose($fp); + } while (0); + $cont .= sprintf("FINE FILE
\n"); + } +} + +function save_rej($s) +{ + if (($fp = fopen(LEGAL_PATH."/rej.txt", "a+")) == FALSE) + return; + + fwrite($fp, sprintf("%s\n", $s)); + fclose($fp); } main(); ?> + + + + Append users from a file
-
+ @@ -69,5 +253,18 @@ echo "$cont";
Admin Password:
+
+Points importer from file to db
+
+ + + + + + +
Admin Password:
Filename:
+
+ + - \ No newline at end of file +