summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2009-01-15 21:40:35 -0800
committerArun Persaud <arun@nubati.net>2009-01-15 21:40:35 -0800
commit4b622dbdb85fbb3512a881ec4786a05f6cd4701c (patch)
treebc3ee3fc89b39fa29c8c74ca38ff1d9d53d36c3d /include
parent8114e8920b56b4f078d2b3ff8d283cdf4d18c679 (diff)
downloade-DoKo-4b622dbdb85fbb3512a881ec4786a05f6cd4701c.tar.gz
e-DoKo-4b622dbdb85fbb3512a881ec4786a05f6cd4701c.tar.bz2
e-DoKo-4b622dbdb85fbb3512a881ec4786a05f6cd4701c.zip
NEW FEATURE: new user settings allows people to not be available for new games
Players who set their preference on this setting to 'no' are not considered as players in a new game.
Diffstat (limited to 'include')
-rw-r--r--include/db.php29
-rw-r--r--include/newgame.php12
-rw-r--r--include/output.php5
-rw-r--r--include/preferences.php34
4 files changed, 77 insertions, 3 deletions
diff --git a/include/db.php b/include/db.php
index e5699f6..6d4080c 100644
--- a/include/db.php
+++ b/include/db.php
@@ -439,6 +439,24 @@ function DB_get_all_names()
$names = array();
$result = DB_query("SELECT fullname FROM User");
+
+ while($r = DB_fetch_array($result))
+ $names[] = $r[0];
+
+ return $names;
+}
+
+function DB_get_all_user_names_open_for_games()
+{
+ $names = array();
+
+ DB_query("DROP TEMPORARY TABLE IF EXISTS Usertmp;");
+ DB_query("CREATE TEMPORARY TABLE Usertmp SELECT id,fullname FROM User;");
+ DB_query("DELETE FROM Usertmp WHERE id IN (SELECT user_id FROM User_Prefs WHERE pref_key='open for games' and value='no')");
+
+ $result = DB_query("SELECT fullname FROM Usertmp");
+ DB_query("DROP TEMPORARY TABLE IF EXISTS Usertmp;");
+
while($r = DB_fetch_array($result))
$names[] = $r[0];
@@ -737,6 +755,15 @@ function DB_get_PREF($myid)
else
$PREF['sorting']='high-low';
+ /* Open for new games */
+ $r = DB_query_array("SELECT value FROM User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='open for games'" );
+ if($r)
+ $PREF['open_for_games'] = $r[0];
+ else
+ $PREF['open_for_games']='yes';
+
+
return $PREF;
}
@@ -1118,7 +1145,7 @@ function DB_get_exchanged_cards($hash)
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'");
+ $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];
diff --git a/include/newgame.php b/include/newgame.php
index 7349e7e..7a88a80 100644
--- a/include/newgame.php
+++ b/include/newgame.php
@@ -23,10 +23,20 @@ else
if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
{
- $names = DB_get_all_names();
+ /* only get players that want to be in new games */
+ $names = DB_get_all_user_names_open_for_games();
+
+ /* add player if he is not open for games */
+ if(!in_array($names,$_SESSION["name"]))
+ $names[]=$_SESSION["name"];
+
+ /* add some randomness */
+ shuffle($names);
+
echo "<div class=\"user\">\n";
output_form_for_new_game($names);
echo "</div>\n";
+
display_user_menu($myid);
}
else
diff --git a/include/output.php b/include/output.php
index 9564b82..e4a06e8 100644
--- a/include/output.php
+++ b/include/output.php
@@ -39,8 +39,11 @@ function output_form_for_new_game($names)
<div class="table">
<img class="table" src="pics/table.png" alt="table" />
<?php
- /* ask for player names */
+
+ /* ask player for names */
+
$i=0;
+
/* delete players name, since he will be on position D anyway */
unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
diff --git a/include/preferences.php b/include/preferences.php
index 775c4b2..616c5e2 100644
--- a/include/preferences.php
+++ b/include/preferences.php
@@ -110,6 +110,24 @@ if(myisset("sorting"))
}
}
+if(myisset("open_for_games"))
+ {
+ $openforgames = $_REQUEST['open_for_games'];
+ if($openforgames != $PREF['open_for_games'])
+ {
+ /* check if we already have an entry for the user, if so change it, if not create new one */
+ $result = DB_query("SELECT * from User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='open for games'" );
+ if( DB_fetch_array($result))
+ $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($openforgames).
+ " WHERE user_id='$myid' AND pref_key='open for games'" );
+ else
+ $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','open for games',".
+ DB_quote_smart($openforgames).")");
+ $changed_openforgames=1;
+ }
+ }
+
if(myisset("password0") && $_REQUEST["password0"]!="" )
{
@@ -200,6 +218,22 @@ echo " <select id=\"sorting\" name=\"sorting\" size=\"1\">\n";
echo " </select>\n";
if($changed_sorting) echo "changed";
echo " </td></tr>\n";
+echo " <tr><td>Open for new games: </td><td>";
+
+echo " <select id=\"open_for_games\" name=\"open_for_games\" size=\"1\">\n";
+ if($PREF['open_for_games']=="no")
+ {
+ echo " <option value=\"yes\">yes</option>\n";
+ echo " <option value=\"no\" selected=\"selected\">no</option>\n";
+ }
+ else /* default */
+ {
+ echo " <option value=\"yes\" selected=\"selected\">yes</option>\n";
+ echo " <option value=\"no\">no</option>\n";
+ }
+ echo " </select>\n";
+if($changed_openforgames) echo "changed";
+echo " </td></tr>\n";
echo " <tr><td>Card set: </td><td>";
echo " <select id=\"cards\" name=\"cards\" size=\"1\">\n";