retrieve win and friend login name when id isn't -1 only
[brisk.git] / web / briskin5 / stat-day.php
index be148cf..cc54e9c 100644 (file)
@@ -305,10 +305,11 @@ function main_pgsql($from, $to)
                 $gam_sql = sprintf("SELECT g.* FROM %sbin5_tournaments as t, %sbin5_matches AS m, %sbin5_games AS g WHERE t.code = m.tcode AND m.code = g.mcode AND m.code = %d ORDER BY g.tstamp;",
                                    $G_dbpfx, $G_dbpfx, $G_dbpfx, $tmt_obj->code);
                 if (($gam_pg = pg_query($bdb->dbconn->db(), $gam_sql)) == FALSE ) {
+                    log_crit("stat-day: gam_sql failed");
                     break;
                 }
 
-                for ($u = 0 ; $u < $usr_n ; $u++) {
+                for ($u = 0 ; $u < count($users) ; $u++) {
                     if ($u == 0) {
                         fprintf($fpexp, "<h3>Codice: %d (%s - %s), Tavolo: %s</h3>\n", $tmt_obj->code, $users[$u]['first'], $users[$u]['last'], $users[$u]['tidx']);
                         fprintf($fpexp, "<table align='center' class='placing'><tr>\n");
@@ -316,11 +317,12 @@ function main_pgsql($from, $to)
                     fprintf($fpexp, "<th>%s</th>", $users[$u]['login']);
                     // note: we are looping on users, order on them not needed
                     $pts_sql = sprintf("SELECT p.pts as pts from %sbin5_games as g, %sbin5_points as p WHERE g.code = p.gcode AND g.mcode = %d AND p.ucode = %d ORDER BY g.code",
-                                       $G_dbpfx, $G_dbpfx, $G_dbpfx,
+                                       $G_dbpfx, $G_dbpfx,
                                        $tmt_obj->code, $users[$u]['code']);
 
                     // points of the match for each user
                     if (($pts_pg[$u] = pg_query($bdb->dbconn->db(), $pts_sql)) == FALSE) {
+                        log_crit("stat-day: pts_sql failed");
                         break;
                     }
                     if ($u == 0) {
@@ -328,11 +330,13 @@ function main_pgsql($from, $to)
                     }
                     else {
                         if ($num_games != pg_numrows($pts_pg[$u])) {
+                            log_crit("stat-day: num_games != pg_numrows");
                             break;
                         }
                     }
                 }
                 if ($u != BIN5_PLAYERS_N) {
+                    log_crit("stat-day: u != BIN5_PLAYERS_N");
                     break;
                 }
 
@@ -353,8 +357,12 @@ function main_pgsql($from, $to)
                     if ($tmt_obj->minus_one_is_old != -1) {
                         fprintf($fpexp, "<td>%s</td><td>%s</td>", $users[$gam_obj->mazzo]['login'],
                                 xcape( game_description($gam_obj->act, 'plain', $gam_obj->mult,
-                                                        $gam_obj->asta_win, $users[$gam_obj->asta_win]['login'],
-                                                        $gam_obj->friend, $users[$gam_obj->friend]['login'],
+                                                        $gam_obj->asta_win,
+                                                        ($gam_obj->asta_win != -1 ?
+                                                         $users[$gam_obj->asta_win]['login'] : ""),
+                                                        $gam_obj->friend,
+                                                        ($gam_obj->friend != -1 ?
+                                                         $users[$gam_obj->friend]['login'] : ""),
                                                         $gam_obj->pnt, $gam_obj->asta_pnt) )
                                 );
                     }