<?php
-/* make sure that we are not called from outside the scripts,
+/* make sure that we are not called from outside the scripts,
* use a variable defined in config.php to check this
*/
if(!isset($HOST))
{
$result = DB_query($query);
$return = DB_fetch_array($result);
-
+
return $return;
}
+function DB_query_array_all($query)
+{
+ $result = array();
+
+ $queryresult = DB_query($query);
+ while($row = DB_fetch_array($queryresult))
+ $result[] = $row;
+
+ return $result;
+}
+
function DB_get_passwd_by_name($name)
{
$r = DB_query_array("SELECT password FROM User WHERE fullname=".DB_quote_smart($name)."");
$result = DB_query("SELECT id FROM Rulesets WHERE".
" dullen=".DB_quote_smart($dullen)." AND ".
- " call=".DB_quote_smart($call)." AND ".
+ " Rulesets.call=".DB_quote_smart($call)." AND ".
" schweinchen=".DB_quote_smart($schweinchen));
if($result)
$r = DB_fetch_array($result);
if($r)
{
/* licence only valid until then */
- if($r[0]=="altenburg" && (time()-strtotime( "2009-12-31 23:59:59")<0) )
+ if($r[0]=="altenburg" && (time()-strtotime( "2009-12-31 23:59:59")<0) )
$PREF["cardset"]="altenburg";
else
$PREF["cardset"]="english";
else
$PREF["email"]="emailnonaddict";
+ /* Autosetup */
+ $r = DB_query_array("SELECT value FROM User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='autosetup'" );
+ if($r)
+ {
+ if($r[0]=='yes')
+ $PREF['autosetup']='yes';
+ else
+ $PREF['autosetup']='no';
+ }
+ else
+ $PREF['autosetup']='no';
+
+ /* Sorting */
+ $r = DB_query_array("SELECT value FROM User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='sorting'" );
+ if($r)
+ $PREF['sorting'] = $r[0];
+ else
+ $PREF['sorting']='high-low';
+
return $PREF;
}
$r = DB_query_array("SELECT * FROM Rulesets".
" LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
" WHERE Game.id='$gameid'" );
-
+
$RULES["dullen"] = $r[2];
$RULES["schweinchen"] = $r[3];
$RULES["call"] = $r[4];
-
+
return $RULES;
}
function DB_get_unused_randomnumbers($userstr)
{
- $r = DB_query_array(" SELECT randomnumbers FROM Game".
- " WHERE randomnumbers NOT IN".
- " (SELECT randomnumbers FROM Game".
- " LEFT JOIN Hand ON Game.id=Hand.game_id".
- " WHERE user_id IN (". $userstr .")".
- " GROUP BY randomnumbers".
- " )");
+ /* optimized version of this query using temporary tables (perhaps we should use a procedure here?).
+ First we create a copy of the Game table using just the gameid and the cards.
+ Then in a second round we delete all the gameids of games where our players are in.
+ At the end we return only the first entry in the temporary table.
+ */
+ DB_query("DROP TEMPORARY TABLE IF EXISTS gametmp;");
+ DB_query("CREATE TEMPORARY TABLE gametmp SELECT id,randomnumbers FROM Game;");
+ DB_query("DELETE FROM gametmp WHERE id IN (SELECT game_id FROM Hand WHERE user_id IN (".$userstr."));");
+
+ $r = DB_query_array("SELECT randomnumbers FROM gametmp LIMIT 1;");
+ DB_query("DROP TEMPORARY TABLE IF EXISTS gametmp;");
+
if($r)
return $r[0];
else
$session = DB_get_session_by_gameid($gameid);
/* get number of game */
- $r = DB_query_array("SELECT COUNT(*),create_date FROM Game".
- " WHERE session='$session' ".
- " AND TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid'))<=0 ".
- " GROUP by session");
+ $r = DB_query_array("SELECT SUM(TIME_TO_SEC(TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid')))<=0) ".
+ " FROM Game".
+ " WHERE session='$session' ");
return $session.".".$r[0];
}
*/
$r = NULL;
-
+
switch($type)
{
case 'name':
"AND Hand.position=".DB_quote_smart($var1)."");
break;
}
-
+
$r = DB_fetch_array($result);
if($r)
return "";
}
+function DB_add_exchanged_card($card,$old_hand_id,$new_hand_id)
+{
+ DB_query("INSERT INTO Card_Exchange VALUES (NULL,$new_hand_id,$old_hand_id,$card)");
+ return;
+}
+
+function DB_get_exchanged_cards($hash)
+{
+ $cards = array();
+
+ $handid = DB_get_handid('hash',$hash);
+
+ $result = DB_query("SELECT card_id FROM Card_Exchange WHERE orig_hand_id=".DB_quote_smart($handid));
+ while($r = DB_fetch_array($result))
+ $cards[]=$r[0];
+
+ return $cards;
+}
+
+function DB_played_by_others($gameid)
+{
+ $gameids = array();
+ $result = DB_query("SELECT id FROM Game WHERE randomnumbers=(SELECT randomnumbers from Game where id=$gameid) and status='gameover'");
+ while($r = DB_fetch_array($result))
+ if($r[0]!=$gameid)
+ $gameids[]=$r[0];
+ return $gameids;
+}
?>
\ No newline at end of file