- GLOBAL $G_false;
-
- $ret = &$G_false;
-
- log_main("login_verify: ".$login);
-
- /* check the existence of the nick in the LoginDB */
- for ($i = 0 ; $i < $this->item_n ; $i++) {
- log_main("login_verify: LOOP");
- if (strcasecmp($this->item[$i]->login, $login) == 0) {
- log_main("login[".$i."]: ".$this->item[$i]->login);
-
- /* if it exists check for a valid challenge */
- if (($a_sem = Challenges::lock_data()) != FALSE) {
-
- if (($chals = &Challenges::load_data()) != FALSE) {
- for ($e = 0 ; $e < $chals->item_n ; $e++) {
-
- log_main("challenge[".$i."]: ".$chals->item[$e]->login);
- if (strcmp($login, $chals->item[$e]->login) == 0) {
- log_main("login_verify [".$pass."] with [".md5($chals->item[$e]->token.$this->item[$i]->pass)."]");
-
- if (strcmp($pass , md5($chals->item[$e]->token.$this->item[$i]->pass)) == 0) {
- log_main("login_verify SUCCESS for ".$login);
-
- $chals->rem($login);
- $ret = &$this->item[$i];
- break;
- }
- }
- } // end for ($e = 0 ...
- }
-
- if ($chals->ismod()) {
- Challenges::save_data(&$chals);
+ GLOBAL $G_dbpfx;
+ $sql_ttok = escsql($table->table_token);
+
+ $is_trans = FALSE;
+ $ret = FALSE;
+
+ $n = count($ucodes);
+ /* check the existence of the nick in the BriskDB */
+ log_main("bin5_points_save: ");
+
+ do {
+ if ($this->query("BEGIN") == FALSE) {
+ break;
+ }
+ $is_trans = TRUE;
+
+ /*
+ * matches management
+ */
+ $mtc_sql = sprintf("UPDATE %sbin5_matches SET (mazzo_next, mult_next) = (%d, %d) WHERE ttok = '%s' RETURNING *;",
+ $G_dbpfx, $table->mazzo, $table->mult, $sql_ttok);
+ 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);
+ 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;
+ }
+ $mtc_obj = pg_fetch_object($mtc_pg, 0);
+
+ for ($i = 0 ; $i < $n ; $i++) {
+ $ord_sql = sprintf("INSERT INTO %sbin5_table_orders (mcode, ucode, pos) VALUES (%d, %d, %d);",
+ $G_dbpfx, $mtc_obj->code, $ucodes[$i], $i);
+ if (($ord_pg = $this->query($ord_sql)) == FALSE || pg_affected_rows($ord_pg) != 1 ) {
+ log_crit(sprintf("bin5_points_save: failed at insert table order [%s]", $ord_sql));
+ break;