2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 /* functions which only ouput html */
10 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
14 echo "<div class=\"message\">\n<form action=\"index.php?action=new\" method=\"post\">\n";
15 echo "Do you want to continue playing?(This will start a new game, with $playerD as dealer.)\n";
16 echo " <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
17 echo " <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
18 echo " <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
19 echo " <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
20 echo " <input type=\"hidden\" name=\"dullen\" value=\"".$RULES["dullen"]."\" />\n";
21 echo " <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES["schweinchen"]."\" />\n";
22 echo " <input type=\"hidden\" name=\"callrule\" value=\"".$RULES["call"]."\" />\n";
23 echo " <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
24 echo " <input type=\"submit\" value=\"keep playing\" />\n";
25 echo "</form>\n</div>";
29 function output_form_for_new_game($names)
31 $copy_names = $names; /* local copy, so that we can delete names from it
32 * after we selected them to make sure that each name
36 <form action="index.php?action=new" method="post">
37 <h2> Select players (Remember: you need to be one of the players) </h2>
40 <img class="table" src="pics/table.png" alt="table" />
43 /* ask player for names */
47 /* delete players name, since he will be on position D anyway */
48 unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
50 srand((float) microtime() * 10000000);
51 foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
53 /* pick 3 names at random and put the players name on position D*/
56 $randkey = array_rand($copy_names);
57 $rand = $copy_names[$randkey];
58 /* delete this name from the list of possible names */
59 unset($copy_names[$randkey]);
63 $rand = $_SESSION["name"];
66 echo " <div class=\"table".$i."\">\n";
68 echo " <select name=\"$player\" size=\"1\"> \n";
69 foreach($names as $name)
73 echo " <option selected=\"selected\">$name</option>\n";
76 echo " <option>$name</option>\n";
78 echo " </select>\n </div>\n";
83 <h2 class="rules">Rules</h2>
84 <h3>Gameplay-related</h3>
85 <h4>Ten of hearts:</h4>
87 <select name="dullen">
88 <option value="none"> just normal non-trump </option>
89 <option value="firstwins"> first ten of hearts wins the trick </option>
90 <option value="secondwins" selected="selected"> second ten of hearts wins the trick </option>
93 <h4>Schweinchen (both foxes), only in normal games or silent solos:</h4>
95 <select name="schweinchen">
96 <option value="none" selected="selected"> none </option>
97 <option value="both"> both become highest trump (automatic call at beginning of the game) </option>
98 <option value="second"> first one normal, second one becomes highest (call during the game) </option>
99 <option value="secondaftercall"> second one become highest only in case re/contra was announced
103 <h4>Call Re/Contra, etc.:</h4>
105 <select name="callrule">
106 <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>
107 <option value="5th-card"> Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</option>
108 <option value="9-cards" > Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</option>
111 <h3>Scoring-related</h3>
112 <h4>(not yet implemented)</h4>
113 <p><input type="submit" value="start game"></p>
118 function output_table($data,$caption="",$class="",$id="")
124 $HTML.= " class=\"$class\"";
126 $HTML.= " id=\"$id\"";
133 $HTML .= " <caption> $caption </caption>\n";
135 foreach($data as $record)
138 $HTML .= " <thead>\n <tr>\n";
141 if($i==1) $HTML .= " <tbody>\n";
144 foreach($record as $point)
147 $HTML .= " <td>$point</td> ";
149 $HTML .= " <th>$point</th> ";
153 $HTML .= " </tr>\n </thead>\n";
160 $HTML .= " </tbody>\n</table>\n";
165 function display_card($card,$dir="english")
167 /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
168 * convert even cards to the matching odd value */
170 if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
171 echo "<img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" />\n";
173 echo "<img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" />\n";
178 function display_link_card($card,$dir="english",$type="card")
180 if( $card/2 - (int)($card/2) == 0.5)
181 echo "<div class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></div>\n";
183 echo "<div class=\"cardinput\" ><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></div>\n";
187 function output_check_for_sickness($me,$mycards)
190 <div class="sickness"> Thanks for joining the game...<br />
192 do you want to play solo?
193 <select name="solo" size="1">
194 <option selected="selected">No</option>
195 <option>trumpless</option>
196 <option>trump</option>
197 <option>queen</option>
198 <option>jack</option>
199 <option>club</option>
200 <option>spade</option>
201 <option>heart</option>
208 if(check_wedding($mycards))
210 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
211 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
215 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
218 echo "Do you have poverty?";
219 if(count_trump($mycards)<4)
221 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
222 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
226 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
229 echo "Do you have too many nines?";
230 if(count_nines($mycards)>4)
232 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
233 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
237 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
240 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
241 echo "<input type=\"submit\" value=\"count me in\" />\n";
248 function output_form_calls($me,$myparty)
250 $highstart = "<span class=\"highcall\">";
251 $highend = "</span>";
253 $tmp = can_call(120,$me);
256 if($tmp==2) echo $highstart;
259 else if ($myparty=='contra')
260 echo "contra (120):";
262 echo " re/contra (120):";
263 echo " <input type=\"radio\" name=\"call\" value=\"120\" />";
264 if($tmp==2) echo $highend;
267 $tmp = can_call(90,$me);
270 if($tmp==2) echo $highstart;
272 " <input type=\"radio\" name=\"call\" value=\"90\" />";
273 if($tmp==2) echo $highend;
276 $tmp = can_call(60,$me);
279 if($tmp==2) echo $highstart;
281 " <input type=\"radio\" name=\"call\" value=\"60\" />";
282 if($tmp==2) echo $highend;
285 $tmp = can_call(30,$me);
288 if($tmp==2) echo $highstart;
290 " <input type=\"radio\" name=\"call\" value=\"30\" />";
291 if($tmp==2) echo $highend;
294 $tmp = can_call(0,$me);
297 if($tmp==2) echo $highstart;
299 " <input type=\"radio\" name=\"call\" value=\"0\" />";
300 if($tmp==2) echo $highend;
303 " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
307 function output_check_want_to_play($me)
310 <div class="joingame">
311 Do you want to play a game of DoKo? <br />
312 yes<input type="radio" name="in" value="yes" />
313 no<input type="radio" name="in" value="no" /> <br />
315 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
317 echo "<input type=\"submit\" value=\"submit\" />\n";
323 function output_header()
327 <!DOCTYPE html PUBLIC
328 "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
329 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
330 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
332 <title>e-Doko</title>
333 <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
334 <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
335 <link rel="stylesheet" type="text/css" href="css/standard023.css" />
336 <script type="text/javascript" src="include/game.js"> </script>
337 <script type="text/javascript" src="include/jquery.js"> </script>
338 <script type="text/javascript" src="include/jquery.tablesorter.js"></script>
339 <script type="text/javascript">
340 $(document).ready(function()
342 $("#ScoreTable").tablesorter({ widgets: ['zebra']});
346 <body onload="high_last();">
348 <h1> Welcome to E-Doko </h1>
352 echo "<div class=\"main\">";
356 function output_footer()
361 echo "<div class=\"footer\">\n";
362 echo " <p class=\"left\"> copyright 2006-2009 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support) <br />\n".
363 " Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
364 " - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
365 " a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
366 echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
367 " via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
368 " <a href=\"http://www.dreamhost.com/green.cgi\">\n".
369 " <img border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
370 "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
381 function output_status()
383 global $defaulttimezone, $INDEX, $WIKI, $RSS;
385 if(isset($_SESSION["name"]))
387 $name = $_SESSION["name"];
389 /* last logon time */
390 $myid = DB_get_userid("name",$name);
391 $zone = DB_get_user_timezone($myid);
393 $time = DB_get_user_timestamp($myid);
394 date_default_timezone_set($defaulttimezone);
395 $unixtime = strtotime($time);
396 date_default_timezone_set($zone);
399 $token = get_user_token($myid);
402 echo "\n<div class=\"status\">\n";
404 echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
405 echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
406 echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
407 echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
408 echo " | <a href=\"".$WIKI."\">wiki</a>\n";
409 echo " | <a href=\"".$RSS."?uid=".$myid."&token=".$token."\">rss</a>\n";
410 echo " | <a href=\"".$INDEX."?action=logout\">logout</a>\n";
413 echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
417 echo "\n<div class=\"status\">\n";
418 echo "<a href=\"".$INDEX."\">login</a>\n";
424 function output_select_timezone($name,$timezone="")
426 $Tzone = array ("Pacific/Apia" => "Apia", /*UTC-11*/
427 "Pacific/Honolulu" => "Honolulu", /*UTC-10*/
428 "America/Anchorage" => "Anchorage", /*UTC-9*/
429 "America/Vancouver" => "Berkeley", /*UTC-8*/
430 "America/Phoenix" => "Phoenix", /*UTC-7*/
431 "America/Chicago" => "Chicago", /*UTC-6*/
432 "America/New_York" => "New York", /*UTC-5*/
433 "America/Santiago" => "Santiago", /*UTC-4*/
434 "America/Buenos_Aires" => "Buenos Aires", /*UTC-3*/
435 "Atlantic/South_Georgia" => "Fernando de Noronha", /*UTC-2*/
436 "Atlantic/Azores" => "Azores", /*UTC-1"*/
437 "Europe/London" => "London", /*UTC*/
438 "Europe/Berlin" => "Berlin", /*UTC+1*/
439 "Africa/Cairo" => "Cairo", /*UTC+2*/
440 "Europe/Moscow" => "Moscow", /*UTC+3*/
441 "Asia/Tehran" => "Tehran", /*UTC+3:30*/
442 "Asia/Dubai" => "Dubai", /*UTC+4*/
443 "Asia/Karachi" => "Karachi", /*UTC+5*/
444 "Asia/Calcutta" => "Delhi", /*UTC+5:30*/
445 "Asia/Kathmandu" => "Kathmandu", /*UTC+5:45*/
446 "Asia/Dhaka" => "Dhaka", /*UTC+6*/
447 "Asia/Rangoon" => "Yangon", /*UTC+6:30*/
448 "Asia/Bangkok" => "Bangkok", /*UTC+7*/
449 "Asia/Hong_Kong" => "Beijing", /*UTC+8*/
450 "Asia/Tokyo" => "Tokyo", /*UTC+9*/
451 "Australia/Darwin" => "Darwin", /*UTC+9:30*/
452 "Australia/Sydney" => "Sydney", /*UTC+10*/
453 "Asia/Magadan" => "Magadan", /*UTC+11*/
454 "Pacific/Auckland" => "Wellington" ); /*UTC+12*/
456 echo " <select id=\"$name\" name=\"$name\" size=\"1\">\n";
458 foreach($Tzone as $zone=>$city)
461 echo " <option value=\"$zone\" selected=\"selected\">$city</option>\n";
463 echo " <option value=\"$zone\">$city</option>\n";
470 function output_password_recovery($email,$password)
473 <form action="index.php" method="post">
475 echo " <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
476 echo " <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
477 echo " <input type=\"hidden\" name=\"passwd\" value=\"set\" />\n";
480 <legend>Password recovery</legend>
483 <td><label for="email">Old password:</label></td>
484 <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
486 <td><label for="password">New password:</label></td>
487 <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
489 <td><label for="password">Retype:</label></td>
490 <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
493 <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
502 function output_user_notes($userid,$gameid,$userstatus)
504 echo "<div class=\"notes\"> Personal notes: <br />\n";
505 $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
506 foreach($notes as $note)
507 echo "$note <hr />\n";
508 if($userstatus!='gameover')
509 echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
515 function output_robotproof($i)
532 function output_exchanged_cards()
534 /* in a poverty game this function will output the exchanged cards
535 * players in the team will see the cards, the other team will see
536 * the backside of cards
539 /* need some information about the game */
540 global $gameid,$mygametype, $PREF,$me,$mystatus;
542 /* some variables to track where the people with poverty are sitting */
548 /* only need to do it in a poverty game, this might not be needed, but
549 * just to make sure everything is ok
551 if($mygametype == 'poverty' || $mygametype=='dpoverty')
553 /* find out who has poverty */
554 for($mypos=1;$mypos<5;$mypos++)
556 $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
557 if($usersick == 'poverty')
559 $povertypos2 = $mypos;
561 $povertypos1 = $mypos;
563 /* get hash and exchanged cards for all involved */
564 $povertyhash1 = DB_get_hash_from_game_and_pos($gameid,$povertypos1);
565 $partnerhash1 = DB_get_partner_hash_by_hash($povertyhash1);
567 $povertycards1 = DB_get_exchanged_cards($povertyhash1);
568 $partnercards1 = DB_get_exchanged_cards($partnerhash1);
570 $partnerpos1 = DB_get_pos_by_hash($partnerhash1);
573 $povertyhash2 = DB_get_hash_from_game_and_pos($gameid,$povertypos2);
574 $partnerhash2 = DB_get_partner_hash_by_hash($povertyhash2);
576 $povertycards2 = DB_get_exchanged_cards($povertyhash2);
577 $partnercards2 = DB_get_exchanged_cards($partnerhash2);
579 $partnerpos2 = DB_get_pos_by_hash($partnerhash2);
584 * go through all positions, check that position has cards that need to be shown and
588 for($mypos=1;$mypos<5;$mypos++)
590 $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
591 if($usersick!=NULL ||
592 $mypos==$povertypos1 || $mypos==$partnerpos1 ||
593 $mypos==$povertypos2 || $mypos==$partnerpos2 )
595 /* figure out if we gave trump back */
598 foreach($povertycards1 as $card)
608 foreach($povertycards2 as $card)
617 /* output vorbehalt */
618 echo " <div class=\"vorbehalt".($mypos-1)."\"> Vorbehalt <br />\n";
620 echo " $usersick <br />\n";
623 if($mypos==$partnerpos1)
625 foreach($partnercards1 as $card)
628 if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
629 display_card($card,$PREF['cardset']);
631 display_card(0,$PREF['cardset']);
633 if($trump_back1) echo " Trump back";
635 else if($mypos==$povertypos1)
637 foreach($povertycards1 as $card)
640 if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
641 display_card($card,$PREF['cardset']);
643 display_card(0,$PREF['cardset']);
645 if($trump_back1) echo " Trump back";
647 else if($mypos==$povertypos2)
649 foreach($povertycards2 as $card)
652 if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
653 display_card($card,$PREF['cardset']);
655 display_card(0,$PREF['cardset']);
657 if($trump_back2) echo " Trump back";
659 else if($mypos==$partnerpos2)
661 foreach($partnercards2 as $card)
663 if(is_trump($card)) $trump_back=1;
665 if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
666 display_card($card,$PREF['cardset']);
668 display_card(0,$PREF['cardset']);
670 if($trump_back2) echo " Trump back";
674 if($mygametype == $usersick)