NEW FEATURE: new sorting algorithm
[e-DoKo.git] / include / db.php
index 2cc94e97497ec2a904de2655f2ef684d4947760a..de549a5bd68a438f39b28c14cc603ac74af2b066 100644 (file)
@@ -1,5 +1,5 @@
 <?php
 <?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))
  * use a variable defined in config.php to check this
  */
 if(!isset($HOST))
@@ -81,14 +81,14 @@ function DB_query_array($query)
 {
   $result = DB_query($query);
   $return = DB_fetch_array($result);
 {
   $result = DB_query($query);
   $return = DB_fetch_array($result);
-  
+
   return $return;
 }
 
 function DB_query_array_all($query)
 {
   $result = array();
   return $return;
 }
 
 function DB_query_array_all($query)
 {
   $result = array();
-  
+
   $queryresult  = DB_query($query);
   while($row = DB_fetch_array($queryresult))
     $result[] = $row;
   $queryresult  = DB_query($query);
   while($row = DB_fetch_array($queryresult))
     $result[] = $row;
@@ -638,7 +638,7 @@ function DB_get_ruleset($dullen,$schweinchen,$call)
 
   $result = DB_query("SELECT id FROM Rulesets WHERE".
                     " dullen=".DB_quote_smart($dullen)." AND ".
 
   $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);
                     " schweinchen=".DB_quote_smart($schweinchen));
   if($result)
     $r    = DB_fetch_array($result);
@@ -695,7 +695,7 @@ function DB_get_PREF($myid)
   if($r)
     {
       /* licence only valid until then */
   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";
        $PREF["cardset"]="altenburg";
       else
        $PREF["cardset"]="english";
@@ -729,6 +729,14 @@ function DB_get_PREF($myid)
   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;
 }
 
   return $PREF;
 }
 
@@ -737,11 +745,11 @@ function DB_get_RULES($gameid)
   $r = DB_query_array("SELECT * FROM Rulesets".
                      " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
                      " WHERE Game.id='$gameid'" );
   $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];
   $RULES["dullen"]      = $r[2];
   $RULES["schweinchen"] = $r[3];
   $RULES["call"]        = $r[4];
-  
+
   return $RULES;
 }
 
   return $RULES;
 }
 
@@ -979,7 +987,7 @@ function DB_get_userid($type,$var1="",$var2="")
    */
 
   $r = NULL;
    */
 
   $r = NULL;
-  
+
   switch($type)
     {
     case 'name':
   switch($type)
     {
     case 'name':
@@ -1051,7 +1059,7 @@ function DB_get_email($type,$var1='',$var2='')
                         "AND Hand.position=".DB_quote_smart($var1)."");
       break;
     }
                         "AND Hand.position=".DB_quote_smart($var1)."");
       break;
     }
-  
+
   $r = DB_fetch_array($result);
 
   if($r)
   $r = DB_fetch_array($result);
 
   if($r)
@@ -1102,5 +1110,13 @@ function DB_get_exchanged_cards($hash)
   return $cards;
 }
 
   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
 ?>
\ No newline at end of file