f694c5b4d833a896e3251f32bd849682ce43b8c8
[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 ?>
32   <form action="index.php?action=new" method="post">
33     <h2> Select players (Remember: you need to be one of the players) </h2>
34
35    <div class="table">
36      <img class="table" src="pics/table.png" alt="table" />
37 <?php
38     /* ask for player names */
39     $i=0;
40   foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
41     {
42       srand((float) microtime() * 10000000);
43       $randkey = array_rand($names);
44       $rand = $names[$randkey];
45       echo  "     <div class=\"table".$i."\">\n";
46       $i++;
47       echo "       <select name=\"$player\" size=\"1\">  \n";
48       foreach($names as $name)
49         {
50           if($name==$rand)
51             {
52               echo "         <option selected=\"selected\">$name</option>\n";
53             }
54           else
55             echo "         <option>$name</option>\n";
56         }
57       echo "       </select>\n     </div>\n";
58     }
59 ?>
60     </div>
61
62    <h2 class="rules"> Rules </h2>
63       <p> Some areas are grayed out which means that the rule is not implemented yet and therefore cannot be selected </p>
64       <p> Ten of hearts: </p>
65       <ul>
66         <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
67         <li> <input type="radio" name="dullen" value="firstwins" /> first ten of hearts wins the trick </li>
68         <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
69       </ul>
70       <p> Schweinchen (both foxes), only in normal games or silent solos: </p>
71       <ul>
72         <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
73         <li> <input type="radio" name="schweinchen" value="both" />
74               both become highest trump (automatic call at beginning of the game)
75         </li>
76         <li> <input type="radio" name="schweinchen" value="second" />
77              first one normal, second one becomes highest (call during the game) </li>
78         <li> <input type="radio" name="schweinchen" value="secondaftercall" />
79              second one become highest only in case re/contra was announced
80         </li>
81       </ul>
82       <p> Call Re/Contra, etc.: </p>
83       <ul>
84          <li><input type="radio" name="callrule" value="1st-own-card" checked="checked" />
85               Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.</li>
86          <li><input type="radio" name="callrule" value="5th-card" />
87               Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</li>
88          <li><input type="radio" name="callrule" value="9-cards"  />
89               Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</li>
90       </ul>
91    <input type="submit" value="start game" />
92  </form>
93 <?php
94 }
95
96 function output_table($data,$caption="",$class="")
97 {
98   if($class!="")
99     $HTML  = "\n<table class=\"$class\">\n";
100   else
101     $HTML  = "\n<table>\n";
102
103   $i=0;
104
105   if($caption!="")
106     $HTML .= "  <caption> $caption </caption>\n";
107
108   foreach($data as $record)
109     {
110       if(!$i)
111         $HTML .= "  <thead>\n  <tr>\n";
112       else
113         {
114           if($i==1) $HTML .= "  <tbody>\n";
115           if($i % 2)
116             $HTML .= "  <tr class=\"odd\">   ";
117           else
118             $HTML .= "  <tr class=\"even\">  ";
119         }
120       foreach($record as $point)
121         {
122           if($i)
123             $HTML .= "    <td>$point</td> ";
124           else
125             $HTML .= "    <th>$point</th> ";
126         }
127
128       if(!$i)
129         $HTML .= "  </tr>\n  </thead>\n";
130       else
131         {
132           $HTML .= "  </tr>\n";
133         }
134       $i++;
135     }
136   $HTML .= "  </tbody>\n</table>\n";
137
138   return $HTML;
139 }
140
141 function display_card($card,$dir="english")
142 {
143   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
144    * convert even cards to the matching odd value */
145
146   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
147     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
148   else
149     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
150
151   return;
152 }
153
154 function display_link_card($card,$dir="english",$type="card")
155 {
156   if( $card/2 - (int)($card/2) == 0.5)
157     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";
158   else
159     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";
160   return;
161 }
162
163 function output_check_for_sickness($me,$mycards)
164 {
165  ?>
166   <div class="sickness"> Thanks for joining the game...<br />
167
168     do you want to play solo?
169     <select name="solo" size="1">
170       <option selected="selected">No</option>
171       <option>trumpless</option>
172       <option>trump</option>
173       <option>queen</option>
174       <option>jack</option>
175       <option>club</option>
176       <option>spade</option>
177       <option>heart</option>
178     </select>
179     <br />
180
181  <?php
182
183   echo "Wedding?";
184   if(check_wedding($mycards))
185      {
186        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
187        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
188      }
189    else
190      {
191        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
192      };
193
194   echo "Do you have poverty?";
195   if(count_trump($mycards)<4)
196     {
197       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
198       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
199     }
200   else
201     {
202       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
203     };
204
205    echo "Do you have too many nines?";
206   if(count_nines($mycards)>4)
207      {
208        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
209        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
210      }
211    else
212      {
213        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
214      };
215
216    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
217    echo "<input type=\"submit\" value=\"count me in\" />\n";
218
219    echo "</div>\n";
220
221   return;
222 }
223
224 function output_form_calls($me,$myparty)
225 {
226   if( can_call(120,$me) )
227     {
228     if($myparty=='re')
229       echo "re (120):";
230     else if ($myparty=='contra')
231       echo "contra (120):";
232     else
233       echo " re/contra (120):";
234     echo " <input type=\"radio\" name=\"call\" value=\"120\" /> <br />";
235     }
236   if( can_call(90,$me) )
237     echo " 90:".
238       " <input type=\"radio\" name=\"call\" value=\"90\" /> <br />";
239   if( can_call(60,$me) )
240     echo " 60:".
241       " <input type=\"radio\" name=\"call\" value=\"60\" /> <br />";
242   if( can_call(30,$me) )
243     echo " 30:".
244       " <input type=\"radio\" name=\"call\" value=\"30\" /> <br />";
245   if( can_call(0,$me) )
246     echo " 0:".
247       " <input type=\"radio\" name=\"call\" value=\"0\" /> <br />".
248       " no call:".
249       " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
250 }
251
252 function output_check_want_to_play($me)
253 {
254    ?>
255  <div class="joingame">
256    Do you want to play a game of DoKo? <br />
257    yes<input type="radio" name="in" value="yes" />
258    no<input type="radio" name="in" value="no" /> <br />
259 <?php
260   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
261   echo "\n";
262   echo "<input type=\"submit\" value=\"submit\" />\n";
263   echo " </div>\n";
264
265   return;
266 }
267
268 function output_header()
269 {
270    global $REV;
271 ?>
272 <!DOCTYPE html PUBLIC
273     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
274     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
275 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
276   <head>
277      <title>e-Doko</title>
278      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
279      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
280      <link rel="stylesheet" type="text/css" href="css/standard017.css" />
281      <script type="text/javascript" src="include/game.js"> </script>
282   </head>
283 <body onload="high_last();">
284 <div class="header">
285 <h1> Welcome to E-Doko </h1>
286 </div>
287 <?php
288
289   echo "<div class=\"main\">";
290   return;
291 }
292
293 function output_footer()
294 {
295   global $REV,$PREF;
296
297   echo "</div>\n\n";
298   echo "<div class=\"footer\">\n";
299   echo "  <p class=\"left\"> copyright 2006-2008 Arun Persaud, Lance Thornton <br />\n".
300     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
301     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
302     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
303  echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
304     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
305     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
306     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
307     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
308     "  </p> \n";
309   echo "\n";
310   echo "</div>\n";
311
312   echo "</body>\n";
313   echo "</html>\n";
314
315   return;
316 }
317
318 function output_status()
319 {
320   global $defaulttimezone,$INDEX,$WIKI;
321    if(isset($_SESSION["name"]))
322      {
323        $name = $_SESSION["name"];
324
325        /* logout info */
326        echo "\n<div class=\"status\">\n";
327        echo $name,"\n";
328        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
329        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
330        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
331        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
332        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
333        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
334        echo "</div>\n";
335
336        /* last logon time */
337        $myid  = DB_get_userid("name",$name);
338        $zone  = DB_get_user_timezone($myid);
339
340        $time     = DB_get_user_timestamp($myid);
341        date_default_timezone_set($defaulttimezone);
342        $unixtime = strtotime($time);
343        date_default_timezone_set($zone);
344
345        echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
346      }
347    else
348      {
349        echo "\n<div class=\"status\">\n";
350        echo "<a href=\"".$INDEX."\">login</a>\n";
351        echo "</div>\n";
352      }
353   return;
354 }
355
356 function output_select_timezone($name,$timezone="")
357 {
358   $Tzone = array ( "Europe/London"     => "London",
359                    "Europe/Berlin"     => "Berlin",
360                    "America/Vancouver" => "Berkeley",
361                    "Pacific/Auckland"  => "Wellington" );
362
363   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
364
365   foreach($Tzone as $zone=>$city)
366     {
367       if($timezone==$zone)
368         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
369       else
370         echo "   <option value=\"$zone\">$city</option>\n";
371     }
372   echo "  </select>\n";
373
374   return;
375 }
376
377 function output_password_recovery($email,$password)
378 {
379 ?>
380    <form action="index.php" method="post">
381 <?php
382   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
383   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
384   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
385 ?>
386      <fieldset>
387        <legend>Password recovery</legend>
388         <table>
389          <tr>
390             <td><label for="email">Old password:</label></td>
391             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
392          </tr><tr>
393             <td><label for="password">New password:</label></td>
394             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
395          </tr><tr>
396             <td><label for="password">Retype:</label></td>
397             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
398          </tr><tr>
399            <td></td>
400            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
401          </tr>
402         </table>
403      </fieldset>
404    </form>
405
406 <?php
407 }
408
409 function output_user_notes($userid,$gameid,$userstatus)
410 {
411   echo "<div class=\"notes\"> Personal notes: <br />\n";
412   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
413   foreach($notes as $note)
414     echo "$note <hr />\n";
415   if($userstatus!='gameover')
416     echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
417   echo "</div> \n";
418
419   return;
420 }
421
422 ?>