+ // return array of array('code', 'login' [, 'first', 'last', 'tidx']) ordered by table position
+ function users_get($match_code, $with_minmaxtidx, $is_newmatch)
+ {
+ GLOBAL $G_dbpfx;
+
+ if ($is_newmatch) { // is new
+ $usr_sql = sprintf("SELECT u.code AS code, u.login AS login%s
+ FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_points AS p,
+ %susers AS u, %sbin5_table_orders AS o
+ WHERE m.code = g.mcode AND g.code = p.gcode AND u.code = p.ucode
+ AND m.code = o.mcode AND u.code = o.ucode AND m.code = %d
+ GROUP BY u.code, u.login%s, o.pos
+ ORDER BY o.pos;",
+ ($with_minmaxtidx ? ", min(g.tstamp) AS first, max(g.tstamp) AS last, m.tidx AS tidx" : ""),
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $match_code,
+ ($with_minmaxtidx ? ", m.tidx" : ""));
+ }
+ else { // is old
+ $usr_sql = sprintf("SELECT u.code AS code, u.login AS login%s
+ FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_points AS p, %susers AS u
+ WHERE m.code = g.mcode AND g.code = p.gcode AND u.code = p.ucode AND m.code = %d
+ GROUP BY u.code, u.login%s;",
+ ($with_minmaxtidx ? ", min(g.tstamp) AS first, max(g.tstamp) AS last, m.tidx AS tidx" : ""),
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $match_code,
+ ($with_minmaxtidx ? ", m.tidx" : ""));
+ }
+
+ if (($usr_pg = pg_query($this->dbconn->db(), $usr_sql)) == FALSE ) {
+ log_crit(sprintf("%s::%s: pg_query usr_sql failed [%s]", __CLASS__, __FUNCTION__, $usr_sql));
+ return (FALSE);
+ }
+ $usr_n = pg_numrows($usr_pg);
+ if ($usr_n != BIN5_PLAYERS_N) {
+ log_crit(sprintf("%s::%s: wrong number of players [%s] %d", __CLASS__, __FUNCTION__, $usr_sql, $usr_n));
+ return (FALSE);
+ }
+ $users = array();
+
+ if ($with_minmaxtidx)
+ $fields = array('code', 'login', 'first', 'last', 'tidx');
+ else
+ $fields = array('code', 'login');
+
+ for ($u = 0 ; $u < $usr_n ; $u++) {
+ $usr_obj = pg_fetch_object($usr_pg, $u);
+ $users[$u] = array();
+ foreach($fields as $field) {
+ $users[$u][$field] = $usr_obj->$field;