X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fdb.php;h=55d97c97e4673134418ad5a1aa49f934a65e799a;hp=ef902adaf21e73a0bc23f301f14c0a1aaddcb45b;hb=b76cddb9313d8a67e5d7e1830503b5775666238f;hpb=6206ef89ad9a9a1a541ecb67971815d11f12199b diff --git a/include/db.php b/include/db.php index ef902ad..55d97c9 100644 --- a/include/db.php +++ b/include/db.php @@ -18,8 +18,10 @@ function DB_open() mysql_select_db($DB_database) or die('Could not select database'); } else - return -1; - + { + echo mysql_errno() . ": " . mysql_error(). "\n"; + return -1; + } return 0; } @@ -59,16 +61,17 @@ function DB_test() function DB_query($query) { /* debug/optimize the database - $logfile=fopen('/tmp/DBlog.log','a+'); - fwrite($logfile,"EXPLAIN $query ;\n"); - $time = microtime(); $return = mysql_query($query); $time = $time - microtime(); - fwrite($logfile,"time of above query: $time\n"); - - fclose($logfile); + if($time > 0.05) // this way we can find only the long ones + { + $logfile=fopen('/tmp/DBlog.log','a+'); + fwrite($logfile,"EXPLAIN $query ;\n"); + fwrite($logfile,"time of above query: $time\n"); + fclose($logfile); + }; return $return; */ @@ -111,6 +114,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).""); @@ -266,34 +275,6 @@ function DB_get_gameid_by_hash($hash) return 0; } -function DB_cancel_game($hash) -{ - $gameid = DB_get_gameid_by_hash($hash); - - if(!$gameid) - return; - - /* get the IDs of all players */ - $result = DB_query("SELECT id FROM Hand WHERE game_id=".DB_quote_smart($gameid)); - while($r = DB_fetch_array($result)) - { - $id = $r[0]; - - $tmp = DB_query_array("SELECT id FROM Hand_Card WHERE hand_id=".DB_quote_smart($id)); - DB_query("DELETE FROM Play WHERE hand_card_id=".DB_quote_smart($tmp[0])); - - DB_query("DELETE FROM Hand_Card WHERE hand_id=".DB_quote_smart($id)); - DB_query("DELETE FROM Hand WHERE id=".DB_quote_smart($id)); - } - - /* delete game */ - DB_query("DELETE FROM User_Game_Prefs WHERE game_id=".DB_quote_smart($gameid)); - DB_query("DELETE FROM Trick WHERE game_id=".DB_quote_smart($gameid)); - DB_query("DELETE FROM Game WHERE id=".DB_quote_smart($gameid)); - - return; -} - function DB_get_hand($me) { $cards = array(); @@ -489,6 +470,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(); @@ -506,6 +498,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) { @@ -522,6 +523,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)); @@ -725,6 +737,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'; @@ -741,13 +754,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': @@ -1063,7 +1081,7 @@ function DB_get_userid($type,$var1="",$var2="") /* test if a recovery password has been set */ if(!$r) { - echo "testing alternative password"; + /* testing alternative password */ $result = DB_query("SELECT User.id FROM User". " LEFT JOIN Recovery ON User.id=Recovery.user_id". " WHERE email=".DB_quote_smart($var1). @@ -1174,4 +1192,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