From 85f97815af1237463bc50b766f06b66b0c5ac8c1 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Fri, 23 Apr 2010 00:06:53 -0700 Subject: [PATCH] new user home page with a bit of jquery thrown in by default only show the active games/sessions and hide all the other games --- css/{standard024.css => standard025.css} | 51 +++++- include/output.php | 15 +- include/user.php | 198 ++++++++++++++++------- 3 files changed, 201 insertions(+), 63 deletions(-) rename css/{standard024.css => standard025.css} (94%) diff --git a/css/standard024.css b/css/standard025.css similarity index 94% rename from css/standard024.css rename to css/standard025.css index ac8aaff..5a5d22f 100644 --- a/css/standard024.css +++ b/css/standard025.css @@ -509,7 +509,47 @@ ul.tricks li div div span.comment span{ } .user { margin-left:25%;margin-right:5%; } -.user td.usergames { width:50%; } + +div.user ul { + list-style:none; +} + +div.user ul li { + position: relative; + padding:3px; + margin: 0px; + width: 80%; + min-height: 1.2em; + border-left: 2px solid #babdb6 ; + border-right: 2px solid #babdb6 ; + border-bottom: 2px solid #babdb6 ; +} + +div.user ul li:first-child { + border-top: 2px solid #babdb6 ; +} +.gamessession { + display:none; +} +.link { + text-decoration:underline; + color: blue; +} + +.user .gameid { + float: left; + width: 5em; +} +.user .turn { + padding-left: 1em; + float: left; + width: 20em; +} +.user .gameshidesession { + float:right; + width: 10em; +} + .wide { margin-left:5%;margin-right:5%; } .over { @@ -532,19 +572,18 @@ div span img.tinybutton { width: 1.4em;} .gamestatuspre { padding: 0 0.3em; - background-color: #fd8901; + background-color: #f57900; } .gamestatusover { padding:0 0.3em; - background-color: #f82c20 ; + background-color: #e9b96e ; + color: #fff; } .gamestatusplay { padding:0 0.3em; - background-color: #15de26; + background-color: #8ae234; } -.multi a{ color: #fff;} - .bigger{ font-size:larger;} diff --git a/include/output.php b/include/output.php index 03e6ced..a4b84a0 100644 --- a/include/output.php +++ b/include/output.php @@ -376,7 +376,7 @@ function output_header() e-Doko - + @@ -384,6 +384,19 @@ function output_header() $(document).ready(function() { $("#ScoreTable").tablesorter({ widgets: ['zebra']}); + + $(".gameshidesession").click( function () { + $(this).parent().children(".gamessession").toggle(300); + }); + + $(".gameshowall").click( function () { + $(".gamessession").show(300); + }); + $(".gamehideall").click( function () { + $(".gamessession").hide(300); + }); + + }); diff --git a/include/user.php b/include/user.php index 1f2ae74..eb4f6c4 100644 --- a/include/user.php +++ b/include/user.php @@ -138,81 +138,167 @@ else echo "

These are all your games:

\n"; /* output legend */ - echo "

Session:
\n"; - echo " p = pre-game phase "; - echo "P = game in progess "; - echo "E = game ended "; - echo "N = N games with same hand
"; + echo "

Games: \n"; + echo "   = pre-game phase "; + echo "   = game in progess "; + echo "N = game over (N people played the same hand)
"; + echo " Reminder: canceling a game can't be reversed!"; echo "

\n"; + /* get all games */ $output = array(); $result = DB_query("SELECT Hand.hash,Hand.game_id,G.mod_date,G.player,G.status, ". - " (SELECT count(H.randomnumbers) FROM Game H WHERE H.randomnumbers=G.randomnumbers) AS count ". + " (SELECT count(H.randomnumbers) FROM Game H WHERE H.randomnumbers=G.randomnumbers) AS count, ". + " G.session". " FROM Hand". " LEFT JOIN Game G ON G.id=Hand.game_id". " WHERE user_id='$myid'". " ORDER BY G.session,G.create_date" ); - $gamenrold = -1; - $count = 0; - echo "\n \n \n"; - else - echo "$gamenr:\n"; - $gamenrold = $gamenr; - echo "\n\n
\n"; - while( $r = DB_fetch_array($result)) + /* sort into active and passive sessions */ + $count = 0; /* count number of games to check for beginner status */ + $session = -1; + $maxgame = 0; + $output_active = ""; + $output_inactive = ""; + $sessionoutput = ""; + $gameoutput = ""; + $keep_going = 2; + while( $keep_going ) { - $count++; - $game = DB_format_gameid($r[1]); - $gamenr = (int) $game; - if($gamenrold < $gamenr) + /* get next element */ + $r = DB_fetch_array($result); + + if($r) + $count++; + else { - if($gamenrold!=-1) - echo "
$gamenr:\n"; + /* need to run the while loop one more time when we run out of elements in the database */ + $keep_going--; + $r[0] = NULL; + $r[1] = NULL; + $r[2] = NULL; + $r[3] = NULL; + $r[4] = NULL; + $r[5] = NULL; + $r[6] = -2; } - $Multi = ($r[5]>1) ? "multi" : ""; - if($r[4]=='pre') - echo " p \n"; - else if (in_array($r[4],array('gameover','cancel-timedout','cancel-nines','cancel-noplay','cancel-trump'))) - { - echo " "; - if($r[5]<2) - echo "E "; - else - echo $r[5]; - echo "\n"; - } - else - echo " P \n"; - if($r[4] == 'pre' || $r[4] == 'play') + if( $r[6]==$session ) { - echo "\n "; - if($r[3]==$myid || !$r[3]) - echo "(it's your turn)\n"; - else + /* same session, update information */ + $maxgame++; + $myhash = $r[0]; + $gameid = $r[1]; + $gamemoddate = $r[2]; + $userid = $r[3]; + $gamestatus = $r[4]; + $gamefrequence = $r[5]; + + /* create output */ + $sessionoutput .= $gameoutput; + $gameoutput = " " + .$gamefrequence."\n"; + } + else + { /* new session */ + + /* output old session if available */ + if($maxgame) { - $name = DB_get_name('userid',$r[3]); - $gameid = $r[1]; - /* check if we need to send out a reminder */ - if(DB_get_reminder($r[3],$gameid)==0) - if(time()-strtotime($r[2]) > 60*60*24*7) - echo "Send a reminder."; - - /* check vacaction status of this user */ - if($vacation=check_vacation($r[3])) + /* is session active? */ + if($gamestatus == 'pre' || $gamestatus== 'play' || time()-strtotime($gamemoddate) < 60*60*24*5 ) { - $stop = substr($vacation[1],0,10); - $title = 'begin:'.substr($vacation[0],0,10).' end:'.$vacation[1].' '.$vacation[2]; - echo "(it's $name's (on vacation until $stop) turn)\n"; + $output_active .= "
  • "; + if($gamestatus == 'pre') + $output_active .= ''; + else if($gamestatus == 'play') + $output_active .= ''; + else + $output_active .= ''; + $output_active .= "". + DB_format_gameid($gameid).'   '; + + + + /* who's turn is it? */ + if( $gamestatus == 'pre' || $gamestatus == 'play') + { + $output_active .= ''; + if($userid==$myid || !$userid) + $output_active .= " your turn\n"; + else + { + $name = DB_get_name('userid',$userid); + + /* check vacaction status of this user */ + if($vacation=check_vacation($userid)) + { + $stop = substr($vacation[1],0,10); + $title = 'begin:'.substr($vacation[0],0,10).' end:'.$vacation[1].' '.$vacation[2]; + $output_active .= " $name's (on vacation until $stop) turn\n"; + } + else + $output_active .= "$name's turn\n"; + + /* check if we need to send out a reminder */ + if(DB_get_reminder($userid,$gameid)==0) + if(time()-strtotime($gamemoddate) > 60*60*24*7) + $output_active .= "Send a reminder? "; + + }; + $output_active .= ''; + + if(time()-strtotime($gamemoddate) > 60*60*24*30) + $output_active .= "Cancel? "; + } + + if($maxgame>1) + { + $output_active .= ' (hide/show) old
    '."\n"; + $output_active .= ' '.$sessionoutput.''; + } + + $output_active .= "
  • \n"; + } else - echo "(it's $name's turn)\n"; - }; - if(time()-strtotime($r[2]) > 60*60*24*30) - echo "Cancel? "; + { + /* session is not active anymore */ + $output_inactive .= "
  • $session:" ; + $output_inactive .= $sessionoutput.$gameoutput ; + $output_inactive .= "
  • \n"; + } + + /* reset all session variables */ + $maxgame = 0; + $sessionoutput = ""; + $gameoutput = ""; + + } + + /* save game information */ + $maxgame++; + $myhash = $r[0]; + $gameid = $r[1]; + $gamemoddate = $r[2]; + $userid = $r[3]; + $gamestatus = $r[4]; + $gamefrequence = $r[5]; + $session = $r[6]; + + /* create output */ + $sessionoutput .= $gameoutput; + $gameoutput = " " + .$gamefrequence."\n"; + } } - echo "
    \n"; + + echo "\n"; /* give a hint for new players */ if($count<10) -- 2.17.1