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