2 /* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 /* functions which only ouput html */
29 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
33 echo "<div class=\"message\">\n<form action=\"index.php?action=new\" method=\"post\">\n";
34 $output = sprintf(_('Do you want to continue playing? (This will start a new game, with %s starting the game.)'),$playerA);
36 echo " <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
37 echo " <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
38 echo " <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
39 echo " <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
40 echo " <input type=\"hidden\" name=\"dullen\" value=\"".$RULES['dullen']."\" />\n";
41 echo " <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES['schweinchen']."\" />\n";
42 echo " <input type=\"hidden\" name=\"callrule\" value=\"".$RULES['call']."\" />\n";
43 echo " <input type=\"hidden\" name=\"lowtrump\" value=\"".$RULES['lowtrump']."\" />\n";
44 echo " <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
45 echo " <input type=\"submit\" value=\""._('keep playing')."\" />\n";
46 echo "</form>\n</div>";
50 function output_form_for_new_game($names)
52 $copy_names = $names; /* local copy, so that we can delete names from it
53 * after we selected them to make sure that each name
56 echo ' <form action="index.php?action=new" method="post">';
57 echo ' <h2> '._('Select players (Remember: you need to be one of the players)').' </h2>';
58 echo ' <div class="table">';
59 echo ' <img class="table" src="pics/table.png" alt="table" />';
61 /* ask player for names */
65 /* delete players name, since he will be on position D anyway */
66 unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
68 srand((float) microtime() * 10000000);
69 foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
71 /* pick 3 names at random and put the players name on position D*/
74 $randkey = array_rand($copy_names);
75 $rand = $copy_names[$randkey];
76 /* delete this name from the list of possible names */
77 unset($copy_names[$randkey]);
81 $rand = $_SESSION["name"];
84 echo " <div class=\"table".$i."\">\n";
86 echo " <select name=\"$player\" size=\"1\"> \n";
87 foreach($names as $name)
91 echo " <option selected=\"selected\">$name</option>\n";
94 echo " <option>$name</option>\n";
96 echo " </select>\n </div>\n";
101 echo ' <h2 class="rules">'._('Rules').'</h2>';
102 echo ' <h3>'._('Gameplay-related').'</h3>';
103 echo ' <h4>'._('Ten of hearts').':</h4>';
105 echo ' <select name="dullen">';
106 echo ' <option value="none"> '._('just normal non-trump').' </option>';
107 echo ' <option value="firstwins"> '._('first ten of hearts wins the trick').' </option>';
108 echo ' <option value="secondwins" selected="selected"> '.('second ten of hearts wins the trick').' </option>';
111 echo ' <h4>'._('Schweinchen (both foxes), only in normal games or silent solos').':</h4>';
113 echo ' <select name="schweinchen">';
114 echo ' <option value="none" selected="selected"> '._('none').' </option>';
115 echo ' <option value="both"> '._('both become highest trump (automatic call at beginning of the game)').' </option>';
116 echo ' <option value="second"> '._('first one normal, second one becomes highest (call during the game)').' </option>';
117 echo ' <option value="secondaftercall"> ',_('second one become highest only in case re/contra was announced');
121 echo ' <h4>'._('Call Re/Contra, etc.').':</h4>';
123 echo ' <select name="callrule">';
124 echo ' <option value="1st-own-card" selected="selected"> '._('Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.').'</option>';
125 echo ' <option value="5th-card"> '._('Can call re/contra until 5th card is played, 90 until 9th card is played, etc.').'</option>';
126 echo ' <option value="9-cards" > '._('Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.').'</option>';
129 echo ' <h4>'._('Low trump').'</h4>';
131 echo ' '._('Player can\'t trump a fox, that is none of his trump is higher than a fox.');
132 echo ' <select name="lowtrump">';
133 echo ' <option value="poverty">'._('The trump will be treated as poverty and offered to another player.').'</option>';
134 echo ' <option value="cancel"> '._('The game will be canceled unless there is a solo.').'</option>';
135 echo ' <option value="none"> '._('Bad luck, the player needs to play a normal game.').'</option>';
138 echo ' <h3>'._('Scoring-related').'</h3>';
139 echo ' <h4>'._('(not yet implemented)').'</h4>';
140 echo ' <p><input type="submit" value="'._('start game').'"></p>';
145 function output_table($data,$caption="",$class="",$id="")
151 $HTML.= " class=\"$class\"";
153 $HTML.= " id=\"$id\"";
160 $HTML .= " <caption> $caption </caption>\n";
162 foreach($data as $record)
165 $HTML .= " <thead>\n <tr>\n";
168 if($i==1) $HTML .= " <tbody>\n";
171 foreach($record as $point)
174 $HTML .= " <td>$point</td> ";
176 $HTML .= " <th>$point</th> ";
180 $HTML .= " </tr>\n </thead>\n";
187 $HTML .= " </tbody>\n</table>\n";
192 function display_card($card,$dir="english")
194 /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
195 * convert even cards to the matching odd value */
197 if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
198 echo "<img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" />\n";
200 echo "<img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" />\n";
205 function display_link_card($card,$dir="english",$type="card", $selected=0)
208 $selected = 'checked="checked"';
210 if( $card/2 - (int)($card/2) == 0.5)
211 echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></label>\n";
213 echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></label>\n";
217 function output_check_for_sickness($me,$mycards)
221 echo ' <div class="sickness"> '._('Thanks for joining the game').'...<br />';
223 echo ' '._('Do you want to play solo?').'';
224 echo ' <select name="solo" size="1">';
225 echo ' <option value="No" selected="selected">'.'No'.'</option>';
226 echo ' <option value="trumpless">'._('trumpless').'</option>';
227 echo ' <option value="trump">'._('trump').'</option>';
228 echo ' <option value="queen">'._('queen').'</option>';
229 echo ' <option value="jack">'._('jack').'</option>';
230 echo ' <option value="club">'._('club').'</option>';
231 echo ' <option valvue="spade">'._('spade').'</option>';
232 echo ' <option value="hear">'._('heart').'</option>';
237 if(check_wedding($mycards))
239 echo ' '._('yes')."<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
240 echo ' '._('no')." <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
244 echo ' '._('no')." <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
247 echo _('Do you have poverty?');
248 if(count_trump($mycards)<4)
250 echo ' '._('yes')."<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
251 echo ' '._('no')." <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
255 echo ' '._('no')." <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
258 echo _('Do you have too many nines?');
259 if(count_nines($mycards)>4)
261 echo ' '._('yes')."<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
262 echo ' '._('no')." <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
266 echo ' '._('no')." <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
269 if($RULES['lowtrump']=='cancel' || $RULES['lowtrump']=='poverty')
271 if($RULES['lowtrump']=='cancel')
272 echo _('Do you have low trump (cancel game)?');
274 echo _('Do you have low trump (poverty)?');
276 if(check_low_trump($mycards))
278 echo ' '._('yes')."<input type=\"radio\" name=\"lowtrump\" value=\"yes\" checked=\"checked\" />";
279 echo ' '._('no')." <input type=\"radio\" name=\"lowtrump\" value=\"no\" /> <br />\n";
283 echo ' '._('no')." <input type=\"hidden\" name=\"lowtrump\" value=\"no\" /> <br />\n";
287 echo "<input type=\"hidden\" name=\"lowtrump\" value=\"no\" />";
289 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
290 echo "<input type=\"submit\" value=\""._('count me in')."\" />\n";
297 function output_form_calls($me,$myparty)
299 $highstart = ' <span class="highcall">';
300 $highend = '</span>';
302 $tmp = can_call(120,$me);
305 if($tmp==2) echo $highstart;
308 else if ($myparty=='contra')
309 echo ' contra (120):';
311 echo ' re/contra (120):';
312 echo ' <input type="radio" name="call" value="120" />';
313 if($tmp==2) echo $highend;
316 $tmp = can_call(90,$me);
319 if($tmp==2) echo $highstart;
321 ' <input type="radio" name="call" value="90" />';
322 if($tmp==2) echo $highend;
325 $tmp = can_call(60,$me);
328 if($tmp==2) echo $highstart;
330 ' <input type="radio" name="call" value="60" />';
331 if($tmp==2) echo $highend;
334 $tmp = can_call(30,$me);
337 if($tmp==2) echo $highstart;
339 ' <input type="radio" name="call" value="30" />';
340 if($tmp==2) echo $highend;
343 $tmp = can_call(0,$me);
346 if($tmp==2) echo $highstart;
348 ' <input type="radio" name="call" value="0" />';
349 if($tmp==2) echo $highend;
352 ' <input type="radio" name="call" value="no" />'."\n";
356 function output_check_want_to_play($me)
358 echo ' <div class="joingame">';
359 echo ' '._('Do you want to play a game of DoKo?').' <br />';
360 echo ' '._('yes').'<input type="radio" name="in" value="yes" />';
361 echo ' '._('no').'<input type="radio" name="in" value="no" /> <br />';
362 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
364 echo "<input type=\"submit\" value=\""._('submit')."\" />\n";
370 function output_header()
377 <title>e-Doko</title>
378 <meta charset="utf-8" />
379 <link rel="shortcut icon" href="pics/edoko-favicon.png" />
380 <link rel="stylesheet" href="css/normalize.css?v=1" />
381 <link rel="stylesheet" href="css/standard.css?v=37" />
382 <link rel="stylesheet" href="css/dateinput.css?v=1"/>
383 <script type="text/javascript" src="include/jquery.js"> </script>
384 <script type="text/javascript" src="include/jquery.tablesorter.js"></script>
385 <script type="text/javascript" src="include/jquery.tools.min.js"></script>
386 <script type="text/javascript" src="include/game.js"> </script>
387 <script type="text/javascript">
390 <body onload="high_last();">
393 echo '<h1> '._('Welcome to E-Doko').' </h1>';
398 echo "<div class=\"main\">";
402 function output_footer()
404 global $REV, $PREF, $INDEX;
408 echo " <p class=\"left\"> copyright 2006-2011 <a href=\"$INDEX?action=about\">Arun Persaud, et al.</a> <br />\n".
409 " Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
410 " - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
411 " a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
412 echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
413 " via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
414 " <a href=\"http://www.dreamhost.com/green.cgi\">\n".
415 " <img alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
416 " src=\"pics/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
418 echo "</footer>\n\n";
425 function output_status()
427 global $defaulttimezone, $INDEX, $WIKI, $RSS;
429 if(isset($_SESSION['name']))
431 $name = $_SESSION['name'];
433 /* last logon time */
434 $myid = DB_get_userid('name',$name);
435 $zone = DB_get_user_timezone($myid);
437 $time = DB_get_user_timestamp($myid);
438 date_default_timezone_set($defaulttimezone);
439 $unixtime = strtotime($time);
440 date_default_timezone_set($zone);
443 $token = get_user_token($myid);
446 echo "\n<div class=\"status\">\n";
448 echo " | <a href=\"".$INDEX."\">"._('mypage')."</a>\n";
449 echo " | <a href=\"".$INDEX."?action=prefs\">"._('settings')."</a>\n";
450 echo " | <a href=\"".$INDEX."?action=new\">"._('new game')."</a>\n";
451 echo " | <a href=\"".$INDEX."?action=stats\">"._('statistics')."</a>\n";
452 echo " | <a href=\"".$WIKI."\">"._('wiki/bugs')."</a>\n";
453 echo " | <a href=\"".$RSS."?uid=".$myid."&token=".$token."\">"._('atom')."</a>\n";
454 echo " | <a href=\"".$INDEX."?action=logout\">"._('logout')."</a>\n";
457 echo "<div class=\"lastlogin\"><span>"._('last login').": ".date("r",$unixtime)."</span></div>\n\n";
462 function output_select_timezone($name,$timezone="")
464 $Tzone = array ("Pacific/Apia" => "Apia", /*UTC-11*/
465 "Pacific/Honolulu" => "Honolulu", /*UTC-10*/
466 "America/Anchorage" => "Anchorage", /*UTC-9*/
467 "America/Vancouver" => "Berkeley", /*UTC-8*/
468 "America/Phoenix" => "Phoenix", /*UTC-7*/
469 "America/Chicago" => "Chicago", /*UTC-6*/
470 "America/New_York" => "New York", /*UTC-5*/
471 "America/Santiago" => "Santiago", /*UTC-4*/
472 "America/Buenos_Aires" => "Buenos Aires", /*UTC-3*/
473 "Atlantic/South_Georgia" => "Fernando de Noronha", /*UTC-2*/
474 "Atlantic/Azores" => "Azores", /*UTC-1"*/
475 "Europe/London" => "London", /*UTC*/
476 "Europe/Berlin" => "Berlin", /*UTC+1*/
477 "Africa/Cairo" => "Cairo", /*UTC+2*/
478 "Europe/Moscow" => "Moscow", /*UTC+3*/
479 "Asia/Tehran" => "Tehran", /*UTC+3:30*/
480 "Asia/Dubai" => "Dubai", /*UTC+4*/
481 "Asia/Karachi" => "Karachi", /*UTC+5*/
482 "Asia/Calcutta" => "Delhi", /*UTC+5:30*/
483 "Asia/Kathmandu" => "Kathmandu", /*UTC+5:45*/
484 "Asia/Dhaka" => "Dhaka", /*UTC+6*/
485 "Asia/Rangoon" => "Yangon", /*UTC+6:30*/
486 "Asia/Bangkok" => "Bangkok", /*UTC+7*/
487 "Asia/Hong_Kong" => "Beijing", /*UTC+8*/
488 "Asia/Tokyo" => "Tokyo", /*UTC+9*/
489 "Australia/Darwin" => "Darwin", /*UTC+9:30*/
490 "Australia/Sydney" => "Sydney", /*UTC+10*/
491 "Asia/Magadan" => "Magadan", /*UTC+11*/
492 "Pacific/Auckland" => "Wellington" ); /*UTC+12*/
494 echo " <select id=\"$name\" name=\"$name\" size=\"1\">\n";
496 foreach($Tzone as $zone=>$city)
499 echo " <option value=\"$zone\" selected=\"selected\">$city</option>\n";
501 echo " <option value=\"$zone\">$city</option>\n";
508 function output_select_language($name,$language="")
510 $LOCALE = array ("English" => "en",
513 echo " <select id=\"$name\" name=\"$name\" size=\"1\">\n";
515 foreach($LOCALE as $place=>$locale)
517 if($language==$locale)
518 echo " <option value=\"$locale\" selected=\"selected\">$place</option>\n";
520 echo " <option value=\"$locale\">$place</option>\n";
528 function output_password_recovery($email,$password)
531 <form action="index.php" method="post">
533 echo " <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
534 echo " <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
535 echo " <input type=\"hidden\" name=\"passwd\" value=\"set\" />\n";
538 <legend>Password recovery</legend>
541 <td><label for="password0">Old password:</label></td>
542 <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
544 <td><label for="password1">New password:</label></td>
545 <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
547 <td><label for="password2">Retype:</label></td>
548 <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
551 <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
560 function output_user_notes($userid,$gameid,$userstatus)
562 echo "<div class=\"notes\"> "._('Personal notes').": <br />\n";
563 $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
564 foreach($notes as $note)
565 echo " $note <hr />\n";
566 if($userstatus!='gameover')
567 echo " <input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
573 function output_robotproof($i)
590 function output_exchanged_cards()
592 /* in a poverty game this function will output the exchanged cards
593 * players in the team will see the cards, the other team will see
594 * the backside of cards
597 /* need some information about the game */
598 global $gameid,$mygametype, $PREF,$me,$mystatus, $RULES;
600 /* some variables to track where the people with poverty are sitting */
606 /* only need to do it in a poverty game, this might not be needed, but
607 * just to make sure everything is ok
609 if($mygametype == 'poverty' || $mygametype=='dpoverty')
611 /* find out who has poverty */
612 for($mypos=1;$mypos<5;$mypos++)
614 $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
615 if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
617 $povertypos2 = $mypos;
619 $povertypos1 = $mypos;
621 /* get hash and exchanged cards for all involved */
622 $povertyhash1 = DB_get_hash_from_game_and_pos($gameid,$povertypos1);
623 $partnerhash1 = DB_get_partner_hash_by_hash($povertyhash1);
625 $povertycards1 = DB_get_exchanged_cards($povertyhash1);
626 $partnercards1 = DB_get_exchanged_cards($partnerhash1);
628 $partnerpos1 = DB_get_pos_by_hash($partnerhash1);
631 $povertyhash2 = DB_get_hash_from_game_and_pos($gameid,$povertypos2);
632 $partnerhash2 = DB_get_partner_hash_by_hash($povertyhash2);
634 $povertycards2 = DB_get_exchanged_cards($povertyhash2);
635 $partnercards2 = DB_get_exchanged_cards($partnerhash2);
637 $partnerpos2 = DB_get_pos_by_hash($partnerhash2);
642 * go through all positions, check that position has cards that need to be shown and
646 for($mypos=1;$mypos<5;$mypos++)
648 $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
649 if($usersick!=NULL ||
650 $mypos==$povertypos1 || $mypos==$partnerpos1 ||
651 $mypos==$povertypos2 || $mypos==$partnerpos2 )
653 /* figure out if we gave trump back */
656 foreach($povertycards1 as $card)
666 foreach($povertycards2 as $card)
675 /* output vorbehalt */
676 echo " <div class=\"vorbehalt".($mypos-1)."\"> Vorbehalt <br />\n";
678 echo " $usersick <br />\n";
681 if($mypos==$partnerpos1)
683 foreach($partnercards1 as $card)
686 if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
687 display_card($card,$PREF['cardset']);
689 display_card(0,$PREF['cardset']);
691 if($trump_back1) echo ' '._('Trump back');
693 else if($mypos==$povertypos1)
695 foreach($povertycards1 as $card)
698 if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
699 display_card($card,$PREF['cardset']);
701 display_card(0,$PREF['cardset']);
703 if($trump_back1) echo ' '._('Trump back');
705 else if($mypos==$povertypos2)
707 foreach($povertycards2 as $card)
710 if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
711 display_card($card,$PREF['cardset']);
713 display_card(0,$PREF['cardset']);
715 if($trump_back2) echo ' '._('Trump back');
717 else if($mypos==$partnerpos2)
719 foreach($partnercards2 as $card)
721 if(is_trump($card)) $trump_back=1;
723 if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
724 display_card($card,$PREF['cardset']);
726 display_card(0,$PREF['cardset']);
728 if($trump_back2) echo ' '._('Trump back');
732 if($mygametype == $usersick)