fix error when language is not set
[e-DoKo.git] / include / db.php
index 23959080ba704661c98737f641344d947fb39567..b104dc0e7fed7f667567a01cf3ac467496aef8fb 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Arun Persaud <arun@nubati.net>
  *
  *   This file is part of e-DoKo.
  *
@@ -379,7 +379,7 @@ function DB_get_current_trickid($gameid)
 
   if(!$sequence || $sequence==4)
     {
-      DB_query("INSERT INTO Trick VALUES (NULL,NULL,NULL, ".DB_quote_smart($gameid).",NULL)");
+      DB_query("INSERT INTO Trick VALUES (CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,NULL,".DB_quote_smart($gameid).",NULL)");
       $trickid  = DB_insert_id();
       $sequence = 1;
       $number++;
@@ -401,7 +401,7 @@ function DB_get_max_trickid($gameid)
 
 function DB_play_card($trickid,$handcardid,$sequence)
 {
-  DB_query("INSERT INTO Play VALUES(NULL,NULL,NULL,".DB_quote_smart($trickid).
+  DB_query("INSERT INTO Play VALUES(CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,NULL,".DB_quote_smart($trickid).
           ",".DB_quote_smart($handcardid).",".DB_quote_smart($sequence).")");
 
   $playid = DB_insert_id();
@@ -507,7 +507,9 @@ function DB_get_names_of_new_logins($N)
 {
   $names  = array();
 
-  $result = DB_query("SELECT fullname FROM User ORDER BY create_date DESC, id DESC LIMIT $N");
+  $result = DB_query("SELECT fullname FROM User".
+                    " WHERE create_date >=(NOW() - interval 45 day)".
+                    " ORDER BY create_date DESC, id DESC LIMIT $N");
   while($r = DB_fetch_array($result))
     $names[] = $r[0];
 
@@ -568,7 +570,7 @@ function DB_get_user_timezone($userid)
 
 function DB_insert_comment($comment,$playid,$gameid,$userid)
 {
-  DB_query("INSERT INTO Comment VALUES (NULL,NULL,NULL,$userid,$playid,$gameid, ".DB_quote_smart($comment).")");
+  DB_query("INSERT INTO Comment VALUES (CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,NULL,$userid,$playid,$gameid, ".DB_quote_smart($comment).")");
 
   return;
 }
@@ -593,7 +595,7 @@ function DB_get_pre_comment_call($gameid)
 
 function DB_insert_note($comment,$gameid,$userid)
 {
-  DB_query("INSERT INTO Notes VALUES (NULL,NULL,NULL,$userid,$gameid, ".DB_quote_smart($comment).")");
+  DB_query("INSERT INTO Notes VALUES (CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,NULL,$userid,$gameid, ".DB_quote_smart($comment).")");
 
   return;
 }
@@ -734,7 +736,7 @@ function DB_get_ruleset($dullen,$schweinchen,$call,$lowtrump)
   else
     {
       /* create new one */
-      $result = DB_query("INSERT INTO Rulesets VALUES (NULL, NULL, ".
+      $result = DB_query("INSERT INTO Rulesets VALUES (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ".
                         DB_quote_smart($dullen).",".
                         DB_quote_smart($schweinchen).",".
                         DB_quote_smart($lowtrump).",".
@@ -910,13 +912,13 @@ function DB_get_email_pref_by_uid($uid)
 function DB_get_unused_randomnumbers($userstr)
 {
   /* 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.
+     First we create a copy of the Game table using just the cards.
+     Then in a second round we delete all the randomnumbers 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 randomnumbers IN (SELECT randomnumbers FROM Hand LEFT JOIN Game ON Game.id=game_id WHERE user_id IN (".$userstr."));");
+  DB_query("CREATE TEMPORARY TABLE gametmp SELECT DISTINCT randomnumbers FROM Game;");
+  DB_query("DELETE FROM gametmp WHERE randomnumbers IN (SELECT DISTINCT randomnumbers FROM Game WHERE id IN (SELECT DISTINCT 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;");
@@ -942,7 +944,7 @@ function DB_get_number_of_passwords_recovery($user)
 function DB_set_recovery_password($user,$newpw)
 {
   DB_query("INSERT INTO Recovery VALUES(NULL,".DB_quote_smart($user).
-          ",".DB_quote_smart($newpw).",NULL)");
+          ",".DB_quote_smart($newpw).",CURRENT_TIMESTAMP)");
   return;
 }
 
@@ -1050,7 +1052,7 @@ function DB_set_reminder($user,$gameid)
 {
   DB_query("INSERT INTO Reminder ".
           "  VALUES(NULL, ".DB_quote_smart($user).", ".DB_quote_smart($gameid).
-          ", NULL) ");
+          ", CURRENT_TIMESTAMP) ");
   return 0;
 }
 
@@ -1247,9 +1249,9 @@ function DB_get_number_of_tricks($gameid,$position)
 function DB_digest_insert_email($To,$message,$type,$gameid)
 {
   if($type == GAME_YOUR_TURN)
-    DB_query("INSERT INTO digest_email VALUES (NULL,".DB_quote_smart($To).",NULL,'your_turn',$gameid,".DB_quote_smart($message).")");
+    DB_query("INSERT INTO digest_email VALUES (NULL,".DB_quote_smart($To).",CURRENT_TIMESTAMP,'your_turn',$gameid,".DB_quote_smart($message).")");
   else
-    DB_query("INSERT INTO digest_email VALUES (NULL,".DB_quote_smart($To).",NULL,'misc',NULL,".DB_quote_smart($message).")");
+    DB_query("INSERT INTO digest_email VALUES (NULL,".DB_quote_smart($To).",CURRENT_TIMESTAMP,'misc',NULL,".DB_quote_smart($message).")");
   return;
 }