- // if deletable old matches exists then ...
- if (($tmt_pg = pg_query($bdb->dbconn->db(), $tmt_sql)) != FALSE) {
+ // retrieve list of active tournaments
+ $trn_sql = sprintf("SELECT * FROM %sbin5_tournaments WHERE active = 1;", $G_dbpfx);
+ if (($trn_pg = pg_query($bdb->dbconn->db(), $trn_sql)) == FALSE) {
+ log_crit("stat-day: select from tournaments failed");
+ break;
+ }
+
+ $trn_n = pg_numrows($trn_pg);
+
+ for ($t = 0 ; $t < $trn_n ; $t++) {
+ $trn_obj = pg_fetch_object($trn_pg, $t);
+
+ $tmt_sql = sprintf("SELECT m.code AS code FROM %sbin5_matches AS m, %sbin5_games AS g, %sbin5_tournaments as t WHERE t.code = m.tcode AND m.code = g.mcode AND g.tstamp >= '%s' AND g.tstamp < '%s' GROUP BY m.code;",
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $from, $to);
+
+ // if deletable old matches exists then ...
+ if (($tmt_pg = pg_query($bdb->dbconn->db(), $tmt_sql)) == FALSE) {
+ log_crit("stat-day: select from matches failed");
+ break;
+ }
+