fixed: bug in routine to figure out the next player
[e-DoKo.git] / output.php
1 <?php
2
3 /* functions which only ouput html  */
4
5 function display_status($gametype)
6 {
7   echo "<div class=\"info\">";
8   echo " Gametype: $gametype";
9   echo "</div>\n";
10   
11   return;
12 }
13
14 function display_news()
15 {
16   global $wiki;
17   echo "<div class=\"bug\">\n".
18     "  Please hit <strong>shift+reload</strong>.<br /><hr />\n".
19     "  The server now keeps score... (only from now on) <br /><hr />".
20     "  If you find more bugs, please list them in the <a href=\"".
21     $wiki."\">wiki</a>.\n</div>\n";
22   return;
23 }
24
25 function output_link_to_user_page($email,$password)
26 {
27   echo "<div class=\"over\">\n";
28   echo "<form action=\"index.php\" method=\"post\">\n";
29   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
30   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
31   echo "  <input type=\"submit\" value=\"go to my user page\" />\n";
32   echo "</form>\n";
33   echo "</div>\n";
34   
35   return;
36 }
37
38 function output_register()
39 {
40   echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)<br /><br />";
41   echo "TODO: convert timezone into a menu<br />\n";
42   echo "TODO: figure out a way to handle passwrods <br />\n";
43   ?>
44         <form action="index.php" method="post">
45           <fieldset>
46             <legend>Register</legend>
47              <table>
48               <tr>
49                <td><label for="Rfullname">Full name:</label></td>
50                <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
51               </tr><tr>
52                <td><label for="Remail">Email:</label></td>
53                <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
54               </tr><tr>
55                <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
56                <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
57               </tr><tr>
58                <td><label for="Rtimezone">Timezone:</label></td>
59                <td>
60                   <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
61                </td>
62               </tr><tr>
63                <td colspan="2"> <input type="submit" value="register" /></td>
64              </table>
65           </fieldset>
66         </form>
67 <?php
68   return;
69 }                                          
70
71 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
72 {
73   global $RULES;
74
75   echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
76   echo "<form action=\"index.php\" method=\"post\">\n";
77   echo "  <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
78   echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
79   echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
80   echo "  <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
81   echo "  <input type=\"hidden\" name=\"dullen\"  value=\"".$RULES["dullen"]."\" />\n";
82   echo "  <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES["schweinchen"]."\" />\n";
83   echo "  <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
84   echo "  <input type=\"submit\" value=\"keep playing\" />\n";
85   echo "</form>\n";
86
87   return;
88 }
89
90 function output_form_for_new_game($names)
91 {
92 ?>
93     <h2> Players </h2>
94     <p>Please select four players (or use the randomly pre-selected names)</p>
95        <form action="index.php" method="post">
96 <?php
97     /* ask for player names */
98   foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
99   {
100     srand((float) microtime() * 10000000);
101     $randkey = array_rand($names);
102     $rand = $names[$randkey];
103     echo "    Name:  <select name=\"$player\" size=\"1\" />  \n";
104     foreach($names as $name)
105     {
106       if($name==$rand)
107         {
108           echo "     <option selected=\"selected\">$name</option>\n";
109         }
110       else
111         echo "     <option>$name</option>\n";
112     }
113     echo "  </select>\n";
114     unset($names[$randkey]);
115    }
116 ?>   
117    <h2> Rules </h2> 
118       
119       <p> ten of hearts: 
120          <ul>
121          <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
122          <li> <input type="radio" name="dullen" value="firstwins" /> first ten of hearts wins the trick </li>
123          <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
124          </ul>
125       </p>
126       <p> schweinchen (both foxes): 
127         <ul>
128         <li> <input type="radio" name="schweinchen" value="none" /> none </li>
129       <li> <input type="radio" name="schweinchen" value="both" /> both become highest trump (call at beginning of the game)(doesn't work yet) </li>
130         <li> <input type="radio" name="schweinchen" value="second" checked="checked" /> first one normal, second one becomes highest (call during the game) (doesn't work yet) </li>
131       <li> <input type="radio" name="schweinchen" value="secondaftercall"  /> second one become highest only in case re/contra was announced (doesn't work yet)</li>
132       </ul>
133       </p>
134    
135    <input type="submit" value="start game" />
136  </form>
137 <?php
138 }
139
140 function display_card($card)
141 {
142   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ... 
143    * convert even cards to the matching odd value */
144
145   if( $card/2 - (int)($card/2) == 0.5)
146     echo "<img src=\"cards/".$card.".png\"  alt=\"".card_to_name($card)."\" />\n";
147   else
148     echo "<img src=\"cards/".($card-1).".png\"  alt=\"".card_to_name($card-1)."\" />\n";
149
150   return;
151 }
152
153 function display_link_card($card)
154 {
155   if( $card/2 - (int)($card/2) == 0.5)
156     echo "<input type=\"radio\" name=\"card\" value=\"".$card."\" /><img src=\"cards/".$card.".png\" alt=\"\" />\n";
157   else
158     echo "<input type=\"radio\" name=\"card\" value=\"".$card."\" /><img src=\"cards/".($card-1).".png\" alt=\"\" />\n";
159   return;
160 }
161
162 function check_for_sickness($me,$mycards)
163 {
164  ?>
165   <p> Solo will work, but the first player will not change. Nothing else implemented. </p>                
166
167   <form action="index.php" method="post">
168
169     do you want to play solo? 
170     <select name="solo" size="1">
171       <option selected="selected">No</option>
172       <option>trumpless</option>
173       <option>trump</option>
174       <option>queen</option>
175       <option>jack</option>
176       <option>club</option>
177       <option>spade</option>
178       <option>heart</option>
179     </select>     
180     <br />
181
182  <?php   
183       
184   echo "wedding?";
185   if(check_wedding($mycards))
186      {
187        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
188        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
189      }
190    else
191      {
192        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
193      };
194
195   echo "do you have poverty?";
196   if(count_trump($mycards)<4)
197     {
198       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
199       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
200     }
201   else
202     {
203       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
204     };
205
206    echo "do you have too many nines?";
207   if(count_nines($mycards)>4)
208      {
209        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
210        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
211      }
212    else
213      {
214        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
215      };
216
217    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
218    echo "<input type=\"submit\" value=\"count me in\" />\n";
219
220    echo "</form>\n";
221
222   return;
223 }
224
225 function check_want_to_play($me)
226 {
227    ?>
228  <form action="index.php" method="post">
229    Do you want to play a game of DoKo?
230    yes<input type="radio" name="in" value="yes" />
231    no<input type="radio" name="in" value="no" /> <br />
232
233 <?php   
234 /*
235    Do you want to get an email for every card played or only if it your move?
236    every card<input type="radio" name="update" value="card" />
237    only on my turn<input type="radio" name="update" value="turn" /> <br />
238 */
239   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
240   echo "\n";
241   echo "<input type=\"submit\" value=\"count me in\" />\n";
242   echo " </form>\n";
243
244   return;
245 }
246
247 function output_home_page()
248 {
249 ?>
250     <p> If you want to play a game of Doppelkopf, you found the right place ;) </p>
251     <p> Please <a href="index.php?register">register</a>, in case you haven't done yet  <br />
252         or login with you email-address or name and password here:
253     </p>
254         <form action="index.php" method="post">
255           <fieldset>
256             <legend>Login</legend>
257              <table>
258               <tr>
259                <td><label for="email">Email:</label></td><td><input type="text" id="email" name="email" size="20" maxlength="30" /> </td>
260               </tr><tr>
261                <td><label for="password">Password:</label></td><td><input type="password" id="password" name="password" size="20" maxlength="30" /></td>
262               </tr><tr>
263                <td> <input type="submit" value="login" /></td>
264              </table>
265           </fieldset>
266         </form>
267
268 <?php
269  return;
270 }
271
272 function output_header()
273 {
274    global $REV;
275 ?>
276 <!DOCTYPE html PUBLIC
277     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
278     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
279 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
280   <head>
281      <title>e-Doko</title>
282      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
283      <link rel="stylesheet" type="text/css" href="css/standard.css" />  
284      <script type="text/javascript">
285        function hl(num) {
286          if(document.getElementById){
287            var i;
288            for(i=1;i<13;i++){
289              if(document.getElementById("trick"+i))
290                document.getElementById("trick"+i).style.display = 'none';
291            }
292            document.getElementById("trick"+num).style.display = 'block';
293          }
294        }
295        function high_last(){
296          if(document.getElementById){
297            var i;
298            for(i=12;i>0;i--) {
299              if(document.getElementById("trick"+i))
300                {
301                  hl(i);
302                  break;
303                }
304            }
305          }
306        }
307      </script>
308   </head>
309 <body onload="high_last();">
310 <div class="header">
311 <h1> Welcome to E-Doko </h1>
312 <p> Revision: <?php echo "$REV"; ?></p>
313 </div>
314
315 <?php
316   return;
317 }
318
319
320
321 function output_footer()
322 {
323   echo "</body>\n";
324   echo "</html>\n";
325
326   return;
327 }
328 ?>