From: Matteo Nastasi (mop) Date: Fri, 11 Feb 2011 07:25:12 +0000 (+0100) Subject: bin5_points_save function added X-Git-Tag: 3.1.0~6 X-Git-Url: http://mop.ddnsfree.com/gitweb/?p=brisk.git;a=commitdiff_plain;h=05ed776e8b692bcd0dd708ea639f0e93dadb55c5 bin5_points_save function added --- diff --git a/web/Obj/dbase_file.phh b/web/Obj/dbase_file.phh index 12ae750..6801031 100644 --- a/web/Obj/dbase_file.phh +++ b/web/Obj/dbase_file.phh @@ -174,7 +174,11 @@ class BriskDB { return ($ret); } - -} // End class LoginDB + + function bin5_points_save($date, $ttok, $tidx, $codes, $pts) + { + return TRUE; + } +} // End class BriskDB ?> \ No newline at end of file diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index b91d932..5da9207 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -208,7 +208,96 @@ class BriskDB } return TRUE; } -} // End class LoginDB + + function &getdbconn() + { + $ret = $this->dbconn; + return ($ret); + } + + // ttok text UNIQUE, + // tidx + function bin5_points_save($date, $ttok, $tidx, $ucodes, $pts) + { + GLOBAL $G_dbpfx; + + $is_trans = FALSE; + $ret = FALSE; + + $n = count($ucodes); + /* check the existence of the nick in the BriskDB */ + log_main("bin5_points_save: "); + + do { + if (pg_query($this->dbconn->db(), "BEGIN") == FALSE) { + break; + } + $is_trans = TRUE; + + /* + * matches management + */ + $mtc_sql = sprintf("SELECT * FROM %sbin5_matches WHERE ttok = '%s';", $G_dbpfx, escsql($ttok)); + if (($mtc_pg = pg_query($this->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($ttok), $tidx); + if ( ! (($mtc_pg = pg_query($this->dbconn->db(), $mtc_sql)) != FALSE && + pg_affected_rows($mtc_pg) == 1) ) { + log_crit(sprintf("bin5_points_save: failed at insert match [%s]", $mtc_sql)); + break; + } + } + $mtc_obj = pg_fetch_object($mtc_pg,0); + + /* + * games management + */ + $gam_sql = sprintf("INSERT INTO %sbin5_games (mcode, tstamp) + VALUES (%d, to_timestamp(%d)) RETURNING *;", + $G_dbpfx, $mtc_obj->code, $date); + if ( ! (($gam_pg = pg_query($this->dbconn->db(), $gam_sql)) != FALSE && + pg_affected_rows($gam_pg) == 1) ) { + log_crit(sprintf("bin5_points_save: failed at insert game [%s]", $gam_sql)); + break; + } + + $gam_obj = pg_fetch_object($gam_pg,0); + + /* + * points management + */ + for ($i = 0 ; $i < $n ; $i++) { + /* put points */ + $pts_sql = sprintf("INSERT INTO %sbin5_points (gcode, ucode, pts) + VALUES (%d, %d, %d);", + $G_dbpfx, $gam_obj->code, $ucodes[$i], $pts[$i]); + if ( ! (($pts_pg = pg_query($this->dbconn->db(), $pts_sql)) != FALSE && + pg_affected_rows($pts_pg) == 1) ) { + log_crit(sprintf("bin5_points_save: failed at insert point [%s]", $pts_sql)); + break; + } + } + + if ($i < $n) + break; + + if (pg_query($this->dbconn->db(), "COMMIT") == FALSE) { + break; + } + + $is_trans = FALSE; + + $ret = TRUE; + } while (0); + + if ($is_trans) + pg_query($this->dbconn-db(), "ROLLBACK"); + + return $ret; + } + +} // End class BriskDB class LoginDBOld { diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index 9b269f7..5045a54 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -481,13 +481,24 @@ else if ($user->stat == 'table') { $plist = "$table->table_token|$user->table_orig|$table->player_n"; $curtime = time(); + $ucodes = array(); for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) { $user_cur = &$bri->user[$table->player[$i]]; $plist .= '|'.xcapelt($user_cur->name).'|'.$pt_cur[$i]; + $ucodes[$i] = $user_cur->code_get(); + } + for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) { + $plist .= '|'.xcapelt($ucodes[$i]); } log_legal($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist); - if ($user->table_orig < TABLES_AUTH_N) - log_points($curtime, xcapelt($user->name), "STAT:BRISKIN5:FINISH_GAME", $plist); + if ($user->table_orig < TABLES_AUTH_N) { + require_once("../Obj/dbase_".$G_dbasetype.".phh"); + + log_points($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist); + $bdb = new BriskDB(); + $bdb->bin5_points_save($curtime, $table->table_token, $user->table_orig, $ucodes, $pt_cur); + unset($bdb); + } $table->game_next(); $table->game_init(&$bri->user);