CLEANUP: moved more statistics into the sortable table
[e-DoKo.git] / include / db.php
index 3d9d98c9cf9272b83b5d0f5390fc359398f6bb56..b79da87def6d231ccbc39507619e21a049cc8e09 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
+ *
+ *   This file is part of e-DoKo.
+ *
+ *   e-DoKo is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   e-DoKo is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 /* make sure that we are not called from outside the scripts,
  * use a variable defined in config.php to check this
  */
@@ -114,6 +133,12 @@ function DB_query_array_all($query)
   return $result;
 }
 
+function DB_get_version()
+{
+  $version = DB_query_array('SELECT version FROM Version');
+  return $version[0];
+}
+
 function DB_get_passwd_by_name($name)
 {
   $r = DB_query_array("SELECT password FROM User WHERE fullname=".DB_quote_smart($name)."");
@@ -464,6 +489,17 @@ function DB_get_names_of_last_logins($N)
   return $names;
 }
 
+function DB_get_emails_of_last_logins($N)
+{
+  $emails  = array();
+
+  $result = DB_query("SELECT email FROM User ORDER BY last_login DESC LIMIT $N");
+  while($r = DB_fetch_array($result))
+    $emails[] = $r[0];
+
+  return $emails;
+}
+
 function DB_get_names_of_new_logins($N)
 {
   $names  = array();
@@ -481,6 +517,15 @@ function DB_update_game_timestamp($gameid)
   return;
 }
 
+function DB_get_game_timestamp($gameid)
+{
+  $r = DB_query_array("SELECT mod_date FROM Game WHERE id=".DB_quote_smart($gameid));
+
+  if($r)
+    return $r[0];
+  else
+    return NULL;
+}
 
 function DB_update_user_timestamp($userid)
 {
@@ -497,6 +542,17 @@ function DB_get_user_timestamp($userid)
   else
     return NULL;
 }
+
+function DB_get_user_creation_date($userid)
+{
+  $r = DB_query_array("SELECT create_date FROM User WHERE id=".DB_quote_smart($userid));
+
+  if($r)
+    return $r[0];
+  else
+    return NULL;
+}
+
 function DB_get_user_timezone($userid)
 {
   $r = DB_query_array("SELECT timezone FROM User WHERE id=".DB_quote_smart($userid));
@@ -700,6 +756,7 @@ function DB_get_PREF($myid)
   /* set defaults */
   $PREF['cardset']             = 'english';
   $PREF['email']               = 'emailnonaddict';
+  $PREF['digest']               = 'digest-off';
   $PREF['autosetup']           = 'no';
   $PREF['sorting']             = 'high-low';
   $PREF['open_for_games']      = 'yes';
@@ -716,13 +773,18 @@ function DB_get_PREF($myid)
        {
        case 'cardset':
          /* licence only valid until then */
-         if($pref[1]=="altenburg" && (time()-strtotime( "2009-12-31 23:59:59")<0) )
-           $PREF["cardset"]="altenburg";
+         if($pref[1]=='altenburg' && (time()-strtotime( '2009-12-31 23:59:59')<0) )
+           $PREF['cardset']='altenburg';
          break;
 
        case 'email':
-         if($pref[1]=="emailaddict")
-           $PREF["email"]="emailaddict";
+         if($pref[1]=='emailaddict')
+           $PREF['email']='emailaddict';
+         break;
+
+       case 'digest':
+         if($pref[1])
+           $PREF['digest'] = $pref[1];
          break;
 
        case 'autosetup':
@@ -1149,4 +1211,44 @@ function DB_played_by_others($gameid)
       $gameids[]=$r[0];
   return $gameids;
 }
+
+function DB_get_number_of_tricks($gameid,$position)
+{
+  $r = DB_query_array("SELECT COUNT(winner) FROM Trick Where game_id='$gameid' and winner='$position'");
+  return $r[0];
+}
+
+function DB_digest_insert_email($To,$message)
+{
+  DB_query("INSERT INTO digest_email VALUES (NULL,".DB_quote_smart($To).",NULL,".DB_quote_smart($message).")");
+  return;
+}
+
+function DB_get_digest_users()
+{
+  $users = array();
+
+  $result = DB_query("SELECT user_id FROM User_Prefs WHERE pref_key='digest' and value <> 'digest-off'");
+  while($r = DB_fetch_array($result))
+    $users[]=$r[0];
+
+  return $users;
+}
+
+function DB_get_digest_message_by_email($email)
+{
+  $messages = array();
+
+  $result = DB_query("SELECT id,content FROM digest_email Where email='$email'");
+  while($r = DB_fetch_array($result))
+    $messages[]=$r;
+
+  return $messages;
+}
+
+function DB_digest_delete_message($id)
+{
+  DB_query("Delete from digest_email where id='$id'");
+}
+
 ?>
\ No newline at end of file