refactorization to manage old rules with a separated class
[brisk.git] / web / Obj / dbase_pgsql.phh
index 8027377..a757c09 100644 (file)
@@ -628,12 +628,14 @@ class BriskDB
         }
         $gam_obj = pg_fetch_object($gam_pg, 0);
 
-        $table->old_reason = game_description($gam_obj->act, 'html', $gam_obj->mult,
+        // FIXME
+        $rules_name = "Rules_old_rules";
+        $table->old_reason = ${rules_name}::game_description($gam_obj->act, 'html', $gam_obj->mult,
                                               $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);
+                                              $gam_obj->pnt, $gam_obj->asta_pnt, $gam_obj->tourn_pts);
 
         // update matches with new ttok and table idx
         $mtc_sql = sprintf("UPDATE %sbin5_matches SET (ttok, tidx) = ('%s', %d) WHERE code = %d RETURNING *;",
@@ -712,8 +714,9 @@ class BriskDB
             if (($mtc_pg  = $this->query($mtc_sql)) == FALSE || pg_numrows($mtc_pg) != 1) {
 
                 // match not exists, insert it
-                $mtc_sql = sprintf("INSERT INTO %sbin5_matches (ttok, tidx, mazzo_next, mult_next) VALUES ('%s', %d, %d, %d) RETURNING *;",
-                                   $G_dbpfx, $sql_ttok, $tidx, $table->mazzo, $table->mult);
+                // , BIN5_TOURNAMENT_NO_DRAW
+                $mtc_sql = sprintf("INSERT INTO %sbin5_matches (ttok, tidx, mazzo_next, mult_next, tcode) VALUES ('%s', %d, %d, %d, %d) RETURNING *;",
+                                   $G_dbpfx, $sql_ttok, $tidx, $table->mazzo, $table->mult, BIN5_TOURNAMENT_OLDRULES);
                 if (($mtc_pg  = $this->query($mtc_sql)) == FALSE || pg_affected_rows($mtc_pg) != 1) {
                     log_crit(sprintf("bin5_points_save: failed at insert match [%s]", $mtc_sql));
                     break;
@@ -760,13 +763,14 @@ class BriskDB
             /*
              * games management
              */
-            $gam_sql = sprintf("INSERT INTO %sbin5_games (mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult)
-                                               VALUES (%d, to_timestamp(%d), %d, %d, %d, %d, %d, %d, %d) RETURNING *;",
+            $gam_sql = sprintf("INSERT INTO %sbin5_games (mcode, tstamp, act, asta_pnt, pnt, asta_win, friend, mazzo, mult, tourn_pts)
+                                               VALUES (%d, to_timestamp(%d), %d, %d, %d, %d, %d, %d, %d, %d) RETURNING *;",
                                $G_dbpfx, $mtc_obj->code, $date, $action,
                                $table->old_asta_pnt, $table->old_pnt,
                                $table->old_asta_win,
                                $table->old_friend,
-                               $table->old_mazzo, $table->old_mult);
+                               $table->old_mazzo, $table->old_mult,
+                               $table->old_tourn_pts);
             if (($gam_pg  = $this->query($gam_sql)) == FALSE || pg_affected_rows($gam_pg) != 1) {
                 log_crit(sprintf("bin5_points_save: failed at insert game [%s]", $gam_sql));
                 break;
@@ -1014,7 +1018,7 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
                         USING %susers as us
                         WHERE owner = %d AND us.login = '%s' AND target = us.code;",
                                    $G_dbpfx, $G_dbpfx,
-                                   $owner_id, escsql($json->login));
+                                   $owner_id, escsql(strtolower($json->login)));
 
                 if (($net_pg = $this->query($net_sql)) == FALSE) {
                     $ret = 5;
@@ -1031,7 +1035,7 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
                                    $G_dbpfx,
                                    $friend, $json->skill, $json->trust,
                                    $G_dbpfx,
-                                   $owner_id, escsql($json->login));
+                                   $owner_id, escsql(strtolower($json->login)));
                 if (($net_pg  = $this->query($net_sql)) == FALSE || pg_numrows($net_pg) == 0) {
                     $net_sql = sprintf("
                 INSERT INTO %susersnet SELECT %d AS owner, us.code as target,
@@ -1039,7 +1043,7 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
                     FROM %susers as us WHERE us.login = '%s' RETURNING *;",
                                        $G_dbpfx, $owner_id,
                                        $friend, $json->skill, $json->trust,
-                                       $G_dbpfx, $json->login);
+                                       $G_dbpfx, escsql(strtolower($json->login)));
                     if (($net_pg  = $this->query($net_sql)) == FALSE) {
                         log_wr('insert query failed');
                         $ret = 2;