CLEANUP: fixed a typo, changed copyright, added Jeff for database scheme
[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 next person 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="")
118 {
119   if($class!="")
120     $HTML  = "\n<table class=\"$class\">\n";
121   else
122     $HTML  = "\n<table>\n";
123
124   $i=0;
125
126   if($caption!="")
127     $HTML .= "  <caption> $caption </caption>\n";
128
129   foreach($data as $record)
130     {
131       if(!$i)
132         $HTML .= "  <thead>\n  <tr>\n";
133       else
134         {
135           if($i==1) $HTML .= "  <tbody>\n";
136           if($i % 2)
137             $HTML .= "  <tr class=\"odd\">   ";
138           else
139             $HTML .= "  <tr class=\"even\">  ";
140         }
141       foreach($record as $point)
142         {
143           if($i)
144             $HTML .= "    <td>$point</td> ";
145           else
146             $HTML .= "    <th>$point</th> ";
147         }
148
149       if(!$i)
150         $HTML .= "  </tr>\n  </thead>\n";
151       else
152         {
153           $HTML .= "  </tr>\n";
154         }
155       $i++;
156     }
157   $HTML .= "  </tbody>\n</table>\n";
158
159   return $HTML;
160 }
161
162 function display_card($card,$dir="english")
163 {
164   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
165    * convert even cards to the matching odd value */
166
167   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
168     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
169   else
170     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
171
172   return;
173 }
174
175 function display_link_card($card,$dir="english",$type="card")
176 {
177   if( $card/2 - (int)($card/2) == 0.5)
178     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";
179   else
180     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";
181   return;
182 }
183
184 function output_check_for_sickness($me,$mycards)
185 {
186  ?>
187   <div class="sickness"> Thanks for joining the game...<br />
188
189     do you want to play solo?
190     <select name="solo" size="1">
191       <option selected="selected">No</option>
192       <option>trumpless</option>
193       <option>trump</option>
194       <option>queen</option>
195       <option>jack</option>
196       <option>club</option>
197       <option>spade</option>
198       <option>heart</option>
199     </select>
200     <br />
201
202  <?php
203
204   echo "Wedding?";
205   if(check_wedding($mycards))
206      {
207        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
208        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
209      }
210    else
211      {
212        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
213      };
214
215   echo "Do you have poverty?";
216   if(count_trump($mycards)<4)
217     {
218       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
219       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
220     }
221   else
222     {
223       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
224     };
225
226    echo "Do you have too many nines?";
227   if(count_nines($mycards)>4)
228      {
229        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
230        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
231      }
232    else
233      {
234        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
235      };
236
237    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
238    echo "<input type=\"submit\" value=\"count me in\" />\n";
239
240    echo "</div>\n";
241
242   return;
243 }
244
245 function output_form_calls($me,$myparty)
246 {
247   if( can_call(120,$me) )
248     {
249     if($myparty=='re')
250       echo "re (120):";
251     else if ($myparty=='contra')
252       echo "contra (120):";
253     else
254       echo " re/contra (120):";
255     echo " <input type=\"radio\" name=\"call\" value=\"120\" /> <br />";
256     }
257   if( can_call(90,$me) )
258     echo " 90:".
259       " <input type=\"radio\" name=\"call\" value=\"90\" /> <br />";
260   if( can_call(60,$me) )
261     echo " 60:".
262       " <input type=\"radio\" name=\"call\" value=\"60\" /> <br />";
263   if( can_call(30,$me) )
264     echo " 30:".
265       " <input type=\"radio\" name=\"call\" value=\"30\" /> <br />";
266   if( can_call(0,$me) )
267     echo " 0:".
268       " <input type=\"radio\" name=\"call\" value=\"0\" /> <br />".
269       " no call:".
270       " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
271 }
272
273 function output_check_want_to_play($me)
274 {
275    ?>
276  <div class="joingame">
277    Do you want to play a game of DoKo? <br />
278    yes<input type="radio" name="in" value="yes" />
279    no<input type="radio" name="in" value="no" /> <br />
280 <?php
281   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
282   echo "\n";
283   echo "<input type=\"submit\" value=\"submit\" />\n";
284   echo " </div>\n";
285
286   return;
287 }
288
289 function output_header()
290 {
291    global $REV;
292 ?>
293 <!DOCTYPE html PUBLIC
294     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
295     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
296 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
297   <head>
298      <title>e-Doko</title>
299      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
300      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
301      <link rel="stylesheet" type="text/css" href="css/standard017.css" />
302      <script type="text/javascript" src="include/game.js"> </script>
303   </head>
304 <body onload="high_last();">
305 <div class="header">
306 <h1> Welcome to E-Doko </h1>
307 </div>
308 <?php
309
310   echo "<div class=\"main\">";
311   return;
312 }
313
314 function output_footer()
315 {
316   global $REV,$PREF;
317
318   echo "</div>\n\n";
319   echo "<div class=\"footer\">\n";
320   echo "  <p class=\"left\"> copyright 2006-2009 Arun Persaud, Lance Thornton(graphics), Jeff Zerger(database support) <br />\n".
321     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
322     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
323     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
324  echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
325     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
326     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
327     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
328     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
329     "  </p> \n";
330   echo "\n";
331   echo "</div>\n";
332
333   echo "</body>\n";
334   echo "</html>\n";
335
336   return;
337 }
338
339 function output_status()
340 {
341   global $defaulttimezone,$INDEX,$WIKI;
342    if(isset($_SESSION["name"]))
343      {
344        $name = $_SESSION["name"];
345
346        /* logout info */
347        echo "\n<div class=\"status\">\n";
348        echo $name,"\n";
349        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
350        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
351        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
352        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
353        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
354        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
355        echo "</div>\n";
356
357        /* last logon time */
358        $myid  = DB_get_userid("name",$name);
359        $zone  = DB_get_user_timezone($myid);
360
361        $time     = DB_get_user_timestamp($myid);
362        date_default_timezone_set($defaulttimezone);
363        $unixtime = strtotime($time);
364        date_default_timezone_set($zone);
365
366        echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
367      }
368    else
369      {
370        echo "\n<div class=\"status\">\n";
371        echo "<a href=\"".$INDEX."\">login</a>\n";
372        echo "</div>\n";
373      }
374   return;
375 }
376
377 function output_select_timezone($name,$timezone="")
378 {
379   $Tzone = array ( "Europe/London"     => "London",
380                    "Europe/Berlin"     => "Berlin",
381                    "America/Vancouver" => "Berkeley",
382                    "Pacific/Auckland"  => "Wellington" );
383
384   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
385
386   foreach($Tzone as $zone=>$city)
387     {
388       if($timezone==$zone)
389         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
390       else
391         echo "   <option value=\"$zone\">$city</option>\n";
392     }
393   echo "  </select>\n";
394
395   return;
396 }
397
398 function output_password_recovery($email,$password)
399 {
400 ?>
401    <form action="index.php" method="post">
402 <?php
403   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
404   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
405   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
406 ?>
407      <fieldset>
408        <legend>Password recovery</legend>
409         <table>
410          <tr>
411             <td><label for="email">Old password:</label></td>
412             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
413          </tr><tr>
414             <td><label for="password">New password:</label></td>
415             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
416          </tr><tr>
417             <td><label for="password">Retype:</label></td>
418             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
419          </tr><tr>
420            <td></td>
421            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
422          </tr>
423         </table>
424      </fieldset>
425    </form>
426
427 <?php
428 }
429
430 function output_user_notes($userid,$gameid,$userstatus)
431 {
432   echo "<div class=\"notes\"> Personal notes: <br />\n";
433   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
434   foreach($notes as $note)
435     echo "$note <hr />\n";
436   if($userstatus!='gameover')
437     echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
438   echo "</div> \n";
439
440   return;
441 }
442
443 ?>