BUGFIX: some email messages had newlines missing before the footer
[e-DoKo.git] / include / output.php
1 <?php
2 /* make sure that we are not called from outside the scripts,
3  * use a variable defined in config.php to check this
4  */
5 if(!isset($HOST))
6   exit;
7
8 /* functions which only ouput html  */
9
10 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
11 {
12   global $RULES;
13
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 the $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>";
26   return;
27 }
28
29 function output_form_for_new_game($names)
30 {
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
33                          * only shows up once
34                          */
35 ?>
36   <form action="index.php?action=new" method="post">
37     <h2> Select players (Remember: you need to be one of the players) </h2>
38
39    <div class="table">
40      <img class="table" src="pics/table.png" alt="table" />
41 <?php
42
43   /* ask player for names */
44
45   $i=0;
46
47   /* delete players name, since he will be on position D anyway */
48   unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
49
50   srand((float) microtime() * 10000000);
51   foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
52     {
53       /* pick 3 names at random and put the players name on position D*/
54       if($i<3)
55         {
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]);
60         }
61       else
62         {
63           $rand = $_SESSION["name"];
64         }
65
66       echo  "     <div class=\"table".$i."\">\n";
67       $i++;
68       echo "       <select name=\"$player\" size=\"1\">  \n";
69       foreach($names as $name)
70         {
71           if($name==$rand)
72             {
73               echo "         <option selected=\"selected\">$name</option>\n";
74             }
75           else
76             echo "         <option>$name</option>\n";
77         }
78       echo "       </select>\n     </div>\n";
79     }
80 ?>
81     </div>
82
83    <h2 class="rules"> Rules </h2>
84       <p> Some areas are grayed out which means that the rule is not implemented yet and therefore cannot be selected </p>
85       <p> Ten of hearts: </p>
86       <ul>
87         <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
88         <li> <input type="radio" name="dullen" value="firstwins" /> first ten of hearts wins the trick </li>
89         <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
90       </ul>
91       <p> Schweinchen (both foxes), only in normal games or silent solos: </p>
92       <ul>
93         <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
94         <li> <input type="radio" name="schweinchen" value="both" />
95               both become highest trump (automatic call at beginning of the game)
96         </li>
97         <li> <input type="radio" name="schweinchen" value="second" />
98              first one normal, second one becomes highest (call during the game) </li>
99         <li> <input type="radio" name="schweinchen" value="secondaftercall" />
100              second one become highest only in case re/contra was announced
101         </li>
102       </ul>
103       <p> Call Re/Contra, etc.: </p>
104       <ul>
105          <li><input type="radio" name="callrule" value="1st-own-card" checked="checked" />
106               Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.</li>
107          <li><input type="radio" name="callrule" value="5th-card" />
108               Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</li>
109          <li><input type="radio" name="callrule" value="9-cards"  />
110               Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</li>
111       </ul>
112    <input type="submit" value="start game" />
113  </form>
114 <?php
115 }
116
117 function output_table($data,$caption="",$class="",$id="")
118 {
119
120   $HTML  = "\n<table";
121
122   if($class!="")
123     $HTML.= " class=\"$class\"";
124   if($id!="")
125     $HTML.= " id=\"$id\"";
126
127   $HTML.=">\n";
128
129   $i=0;
130
131   if($caption!="")
132     $HTML .= "  <caption> $caption </caption>\n";
133
134   foreach($data as $record)
135     {
136       if(!$i)
137         $HTML .= "  <thead>\n  <tr>\n";
138       else
139         {
140           if($i==1) $HTML .= "  <tbody>\n";
141           $HTML .= "  <tr>  ";
142         }
143       foreach($record as $point)
144         {
145           if($i)
146             $HTML .= "    <td>$point</td> ";
147           else
148             $HTML .= "    <th>$point</th> ";
149         }
150
151       if(!$i)
152         $HTML .= "  </tr>\n  </thead>\n";
153       else
154         {
155           $HTML .= "  </tr>\n";
156         }
157       $i++;
158     }
159   $HTML .= "  </tbody>\n</table>\n";
160
161   return $HTML;
162 }
163
164 function display_card($card,$dir="english")
165 {
166   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
167    * convert even cards to the matching odd value */
168
169   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
170     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
171   else
172     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
173
174   return;
175 }
176
177 function display_link_card($card,$dir="english",$type="card")
178 {
179   if( $card/2 - (int)($card/2) == 0.5)
180     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";
181   else
182     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";
183   return;
184 }
185
186 function output_check_for_sickness($me,$mycards)
187 {
188  ?>
189   <div class="sickness"> Thanks for joining the game...<br />
190
191     do you want to play solo?
192     <select name="solo" size="1">
193       <option selected="selected">No</option>
194       <option>trumpless</option>
195       <option>trump</option>
196       <option>queen</option>
197       <option>jack</option>
198       <option>club</option>
199       <option>spade</option>
200       <option>heart</option>
201     </select>
202     <br />
203
204  <?php
205
206   echo "Wedding?";
207   if(check_wedding($mycards))
208      {
209        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
210        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
211      }
212    else
213      {
214        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
215      };
216
217   echo "Do you have poverty?";
218   if(count_trump($mycards)<4)
219     {
220       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
221       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
222     }
223   else
224     {
225       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
226     };
227
228    echo "Do you have too many nines?";
229   if(count_nines($mycards)>4)
230      {
231        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
232        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
233      }
234    else
235      {
236        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
237      };
238
239    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
240    echo "<input type=\"submit\" value=\"count me in\" />\n";
241
242    echo "</div>\n";
243
244   return;
245 }
246
247 function output_form_calls($me,$myparty)
248 {
249   if( can_call(120,$me) )
250     {
251     if($myparty=='re')
252       echo "re (120):";
253     else if ($myparty=='contra')
254       echo "contra (120):";
255     else
256       echo " re/contra (120):";
257     echo " <input type=\"radio\" name=\"call\" value=\"120\" /> <br />";
258     }
259   if( can_call(90,$me) )
260     echo " 90:".
261       " <input type=\"radio\" name=\"call\" value=\"90\" /> <br />";
262   if( can_call(60,$me) )
263     echo " 60:".
264       " <input type=\"radio\" name=\"call\" value=\"60\" /> <br />";
265   if( can_call(30,$me) )
266     echo " 30:".
267       " <input type=\"radio\" name=\"call\" value=\"30\" /> <br />";
268   if( can_call(0,$me) )
269     echo " 0:".
270       " <input type=\"radio\" name=\"call\" value=\"0\" /> <br />".
271       " no call:".
272       " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
273 }
274
275 function output_check_want_to_play($me)
276 {
277    ?>
278  <div class="joingame">
279    Do you want to play a game of DoKo? <br />
280    yes<input type="radio" name="in" value="yes" />
281    no<input type="radio" name="in" value="no" /> <br />
282 <?php
283   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
284   echo "\n";
285   echo "<input type=\"submit\" value=\"submit\" />\n";
286   echo " </div>\n";
287
288   return;
289 }
290
291 function output_header()
292 {
293    global $REV;
294 ?>
295 <!DOCTYPE html PUBLIC
296     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
297     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
298 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
299   <head>
300      <title>e-Doko</title>
301      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
302      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
303      <link rel="stylesheet" type="text/css" href="css/standard021.css" />
304      <script type="text/javascript" src="include/game.js"> </script>
305      <script type="text/javascript" src="include/jquery.js"> </script>
306      <script type="text/javascript" src="include/jquery.tablesorter.js"></script>
307      <script type="text/javascript">
308         $(document).ready(function()
309            {
310               $("#ScoreTable").tablesorter({ widgets: ['zebra']});
311            });
312      </script>
313   </head>
314 <body onload="high_last();">
315 <div class="header">
316 <h1> Welcome to E-Doko </h1>
317 </div>
318 <?php
319
320   echo "<div class=\"main\">";
321   return;
322 }
323
324 function output_footer()
325 {
326   global $REV,$PREF;
327
328   echo "</div>\n\n";
329   echo "<div class=\"footer\">\n";
330   echo "  <p class=\"left\"> copyright 2006-2009 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support) <br />\n".
331     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
332     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
333     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
334  echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
335     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
336     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
337     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
338     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
339     "  </p> \n";
340   echo "\n";
341   echo "</div>\n";
342
343   echo "</body>\n";
344   echo "</html>\n";
345
346   return;
347 }
348
349 function output_status()
350 {
351   global $defaulttimezone,$INDEX,$WIKI;
352    if(isset($_SESSION["name"]))
353      {
354        $name = $_SESSION["name"];
355
356        /* logout info */
357        echo "\n<div class=\"status\">\n";
358        echo $name,"\n";
359        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
360        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
361        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
362        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
363        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
364        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
365        echo "</div>\n";
366
367        /* last logon time */
368        $myid  = DB_get_userid("name",$name);
369        $zone  = DB_get_user_timezone($myid);
370
371        $time     = DB_get_user_timestamp($myid);
372        date_default_timezone_set($defaulttimezone);
373        $unixtime = strtotime($time);
374        date_default_timezone_set($zone);
375
376        echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
377      }
378    else
379      {
380        echo "\n<div class=\"status\">\n";
381        echo "<a href=\"".$INDEX."\">login</a>\n";
382        echo "</div>\n";
383      }
384   return;
385 }
386
387 function output_select_timezone($name,$timezone="")
388 {
389   $Tzone = array ( "Europe/London"     => "London",
390                    "Europe/Berlin"     => "Berlin",
391                    "America/Vancouver" => "Berkeley",
392                    "Pacific/Auckland"  => "Wellington" );
393
394   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
395
396   foreach($Tzone as $zone=>$city)
397     {
398       if($timezone==$zone)
399         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
400       else
401         echo "   <option value=\"$zone\">$city</option>\n";
402     }
403   echo "  </select>\n";
404
405   return;
406 }
407
408 function output_password_recovery($email,$password)
409 {
410 ?>
411    <form action="index.php" method="post">
412 <?php
413   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
414   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
415   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
416 ?>
417      <fieldset>
418        <legend>Password recovery</legend>
419         <table>
420          <tr>
421             <td><label for="email">Old password:</label></td>
422             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
423          </tr><tr>
424             <td><label for="password">New password:</label></td>
425             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
426          </tr><tr>
427             <td><label for="password">Retype:</label></td>
428             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
429          </tr><tr>
430            <td></td>
431            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
432          </tr>
433         </table>
434      </fieldset>
435    </form>
436
437 <?php
438 }
439
440 function output_user_notes($userid,$gameid,$userstatus)
441 {
442   echo "<div class=\"notes\"> Personal notes: <br />\n";
443   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
444   foreach($notes as $note)
445     echo "$note <hr />\n";
446   if($userstatus!='gameover')
447     echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
448   echo "</div> \n";
449
450   return;
451 }
452
453 function output_robotproof($i)
454 {
455   switch($i)
456     {
457     case 0:
458       return "6*7=";
459     case 1:
460       return "5*7=";
461     case 2:
462       return "4*7=";
463     case 3:
464       return "3*7=";
465     case 4:
466       return "2*7=";
467     }
468 }
469
470 function output_exchanged_cards()
471 {
472   /* in a poverty game this function will output the exchanged cards
473    * players in the team will see the cards, the other team will see
474    * the backside of cards
475    */
476
477   /* need some information about the game */
478   global $gameid,$mygametype, $PREF,$me,$mystatus;
479
480   /* some variables to track where the people with poverty are sitting */
481   $partnerpos1 = 0;
482   $povertypos1 = 0;
483   $partnerpos2 = 0;
484   $povertypos2 = 0;
485
486   /* only need to do it in a poverty game, this might not be needed, but
487    * just to make sure everything is ok
488    */
489   if($mygametype == 'poverty' || $mygametype=='dpoverty')
490     {
491       /* find out who has poverty */
492       for($mypos=1;$mypos<5;$mypos++)
493         {
494           $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
495           if($usersick == 'poverty')
496             if($povertypos1)
497               $povertypos2 = $mypos;
498             else
499               $povertypos1 = $mypos;
500         }
501       /* get hash and exchanged cards for all involved */
502       $povertyhash1 = DB_get_hash_from_game_and_pos($gameid,$povertypos1);
503       $partnerhash1 = DB_get_partner_hash_by_hash($povertyhash1);
504
505       $povertycards1 = DB_get_exchanged_cards($povertyhash1);
506       $partnercards1 = DB_get_exchanged_cards($partnerhash1);
507
508       $partnerpos1 = DB_get_pos_by_hash($partnerhash1);
509       if($povertypos2)
510         {
511           $povertyhash2 = DB_get_hash_from_game_and_pos($gameid,$povertypos2);
512           $partnerhash2 = DB_get_partner_hash_by_hash($povertyhash2);
513
514           $povertycards2 = DB_get_exchanged_cards($povertyhash2);
515           $partnercards2 = DB_get_exchanged_cards($partnerhash2);
516
517           $partnerpos2 = DB_get_pos_by_hash($partnerhash2);
518         }
519     }
520
521   /* output the cards
522    * go through all positions, check that position has cards that need to be shown and
523    * show those cards
524    */
525   $show = 1;
526   for($mypos=1;$mypos<5;$mypos++)
527     {
528       $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
529       if($usersick!=NULL ||
530          $mypos==$povertypos1 || $mypos==$partnerpos1 ||
531          $mypos==$povertypos2 || $mypos==$partnerpos2 )
532         {
533           echo "      <div class=\"vorbehalt".($mypos-1)."\"> Vorbehalt <br />\n";
534           if($show)
535             echo "       $usersick <br />\n";
536           if($mypos==$partnerpos1)
537             {
538               $trump_back=0;
539               foreach($partnercards1 as $card)
540                 {
541                   if(is_trump($card)) $trump_back=1;
542                   echo '        ';
543                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
544                     display_card($card,$PREF['cardset']);
545                   else
546                     display_card(0,$PREF['cardset']);
547                 }
548               if($trump_back) echo "Trump back";
549             }
550           else if($mypos==$povertypos1)
551             {
552               foreach($povertycards1 as $card)
553                 {
554                   echo '        ';
555                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
556                     display_card($card,$PREF['cardset']);
557                   else
558                     display_card(0,$PREF['cardset']);
559               }
560             }
561           else if($mypos==$povertypos2)
562             {
563               foreach($povertycards2 as $card)
564                 {
565                   echo '        ';
566                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
567                     display_card($card,$PREF['cardset']);
568                   else
569                     display_card(0,$PREF['cardset']);
570                 }
571             }
572           else if($mypos==$partnerpos2)
573             {
574               $trump_back=0;
575               foreach($partnercards2 as $card)
576                 {
577                   if(is_trump($card)) $trump_back=1;
578                   echo '        ';
579                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
580                     display_card($card,$PREF['cardset']);
581                   else
582                     display_card(0,$PREF['cardset']);
583                 }
584               if($trump_back) echo "Trump back";
585             }
586           echo  "      </div>\n";
587
588           if($mygametype == $usersick)
589             $show = 0;
590         }
591     }
592 }
593
594
595 ?>