X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=db.php;h=75cd8a0e83bcdcdeb77abab0d013c66450070fa5;hp=a19242cacba7613f304dc9a687ae7325e07b0b20;hb=9bceb4f3447a82affb63b4994bf3509f2e6758d4;hpb=9db97c855d40d089037410aad3595893f68f6d6a diff --git a/db.php b/db.php index a19242c..75cd8a0 100644 --- a/db.php +++ b/db.php @@ -134,6 +134,17 @@ function DB_get_userid_by_email_and_password($email,$password) $result = mysql_query("SELECT id FROM User WHERE email=".DB_quote_smart($email)." AND password=".DB_quote_smart($password)); $r = mysql_fetch_array($result,MYSQL_NUM); + /* test if a recovery password has been set */ + if(!$r) + { + $result = mysql_query("SELECT User.id FROM User". + " LEFT JOIN Recovery ON User.id=Recovery.user_id". + " WHERE email=".DB_quote_smart($email). + " AND Recovery.password=".DB_quote_smart($password). + " AND DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= Recovery.create_date"); + $r = mysql_fetch_array($result,MYSQL_NUM); + } + if($r) return $r[0]; else @@ -163,6 +174,20 @@ function DB_get_handid_by_gameid_and_position($gameid,$pos) else return -1; } +function DB_get_userid_by_gameid_and_position($gameid,$pos) +{ + $result = mysql_query("SELECT user_id FROM Hand WHERE game_id=". + DB_quote_smart($gameid)." AND position=". + DB_quote_smart($pos)); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return -1; +} + + function DB_get_handid_by_gameid_and_userid($gameid,$userid) { $result = mysql_query("SELECT id FROM Hand WHERE game_id=". @@ -426,6 +451,7 @@ function DB_get_current_trickid($gameid) { $trickid = NULL; $sequence = NULL; + $number = 0; $result = mysql_query("SELECT Trick.id,MAX(Play.sequence) FROM Play ". "LEFT JOIN Trick ON Play.trick_id=Trick.id ". @@ -435,6 +461,7 @@ function DB_get_current_trickid($gameid) { $trickid = $r[0]; $sequence = $r[1]; + $number++; }; if(!$sequence || $sequence==4) @@ -442,13 +469,14 @@ function DB_get_current_trickid($gameid) mysql_query("INSERT INTO Trick VALUES (NULL,NULL,NULL, ".DB_quote_smart($gameid).")"); $trickid = mysql_insert_id(); $sequence = 1; + $number++; } else { $sequence++; } - return array($trickid,$sequence); + return array($trickid,$sequence,$number); } function DB_get_max_trickid($gameid) @@ -612,6 +640,24 @@ function DB_set_startplayer_by_gameid($id,$p) return; } +function DB_get_player_by_gameid($id) +{ + $result = mysql_query("SELECT player FROM Game WHERE id=".DB_quote_smart($id)); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return 0; +} +function DB_set_player_by_gameid($id,$p) +{ + mysql_query("UPDATE Game SET player='".DB_quote_smart($p)."' WHERE id=".DB_quote_smart($id)); + return; +} + + + function DB_get_ruleset_by_gameid($id) { $result = mysql_query("SELECT ruleset FROM Game WHERE id=".DB_quote_smart($id)); @@ -645,6 +691,20 @@ function DB_get_max_session() return 0; } +function DB_get_hashes_by_session($session,$user) +{ + $r = array(); + + $result = mysql_query("SELECT Hand.hash FROM Hand". + " LEFT JOIN Game ON Game.id=Hand.game_id ". + " WHERE Game.session=".DB_quote_smart($session). + " AND Hand.user_id=".DB_quote_smart($user)); + while($t = mysql_fetch_array($result,MYSQL_NUM)) + $r[] = $t[0]; + + return $r; +} + function DB_get_ruleset($dullen,$schweinchen) { $r = array(); @@ -687,5 +747,72 @@ function DB_set_party_by_hash($hash,$party) return; } +function DB_get_PREF($myid) +{ + global $PREF; + + $result = mysql_query("SELECT value from User_Prefs". + " WHERE user_id='$myid' AND pref_key='cardset'" ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if($r) + { + if($r[0]=="germancards" && (time()-strtotime( "2009-12-31 23:59:59")<0) ) /* licence only valid until then */ + $PREF["cardset"]="altenburg"; + else + $PREF["cardset"]="english"; + } + else + $PREF["cardset"]="english"; + + return; +} + +function DB_get_unused_randomnumbers($userstr) +{ + $queryresult = mysql_query("SELECT randomnumbers,Game.id FROM Game ". + " LEFT JOIN Hand ON Hand.game_id=Game.id ". + " AND user_id not in (".$userstr.")". + " GROUP BY Game.id ". + " HAVING num=4"); + + $r = mysql_fetch_array($queryresult,MYSQL_NUM); + if($r) + return $r[0]; + else + return ""; +} + +function DB_get_number_of_passwords_recovery($user) +{ + $queryresult = mysql_query("SELECT COUNT(*) FROM Recovery ". + " WHERE user_id=$user ". + " AND DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= create_date". + " GROUP BY user_id " ); + + $r = mysql_fetch_array($queryresult,MYSQL_NUM); + if($r) + return $r[0]; + else + return 0; +} + +function DB_set_recovery_password($user,$newpw) +{ + mysql_query("INSERT INTO Recovery VALUES(NULL,".DB_quote_smart($user). + ",".DB_quote_smart($newpw).",NULL)"); + + return; +} + +function DB_get_card_name($card) +{ + $queryresult = mysql_query("SELECT strength,suite FROM Card WHERE id='$card'"); + + $r = mysql_fetch_array($queryresult,MYSQL_NUM); + if($r) + return $r[0]." of ".$r[1]; + else + return "Error during get_card_name ".$card; +} ?> \ No newline at end of file