CLEANUP: get card names from the database
[e-DoKo.git] / output.php
1 <?php
2
3 /* functions which only ouput html  */
4
5 function display_links($email,$password)
6 {
7   global $wiki;
8   echo "<div class=\"bug\">\n".
9     "Report bugs in the <a href=\"". $wiki."\">wiki</a>.<hr />\n";
10   output_link_to_user_page($email,$password);
11   echo  "</div>\n";
12   return;
13 }
14
15 function output_link_to_user_page($email,$password)
16 {
17   echo "<div class=\"over\">\n";
18   echo "<form action=\"index.php\" method=\"post\">\n";
19   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
20   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
21   echo "  <input type=\"submit\" class=\"submitbutton\" value=\"go to my user page\" />\n";
22   echo "</form>\n";
23   echo "</div>\n";
24   
25   return;
26 }
27
28 function output_user_settings($email,$password)
29 {
30   global $PREF;
31
32   echo "<div class=\"useroptions\">\n";
33   echo "<h4> Settings </h4>\n";
34   echo "<form action=\"index.php\" method=\"post\">\n";
35   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
36   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
37   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"ask\" />\n";
38   echo "  <input type=\"submit\" class=\"submitbutton\" name=\"pass\" value=\"change password\" /> <br />\n";
39   echo "</form>\n";
40   echo "<form action=\"index.php\" method=\"post\">\n";
41   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
42   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
43   echo "  <input type=\"hidden\" name=\"setpref\"  value=\"englishcards\" />\n";
44   echo "  <input type=\"submit\" class=\"submitbutton\" value=\"use english cards\" /> <br />\n";
45   echo "</form>\n";
46   echo "<form action=\"index.php\" method=\"post\">\n";
47   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
48   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
49   echo "  <input type=\"hidden\" name=\"setpref\"  value=\"germancards\" />\n";
50   echo "  <input type=\"submit\" class=\"submitbutton\" value=\"use german cards\" /> <br />\n";
51   echo "</form>\n";
52   echo "</div>\n";
53   return;
54 }
55
56 function output_register()
57 {
58   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 />";
59   echo "TODO: figure out a better way to handle passwords <br />\n";
60   ?>
61         <form action="index.php" method="post">
62           <fieldset>
63             <legend>Register</legend>
64              <table>
65               <tr>
66                <td><label for="Rfullname">Full name:</label></td>
67                <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
68               </tr><tr>
69                <td><label for="Remail">Email:</label></td>
70                <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
71               </tr><tr>
72                <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
73                <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
74               </tr><tr>
75                <td><label for="Rtimezone">Timezone:</label></td>
76                <td>
77                   <select id="Rtimezone" name="Rtimezone" size="1">
78                      <option value="1">Berlin</option>
79                      <option value="-8">Berkeley</option>
80                      <option value="13">Wellington</option>
81                   </select>
82                  (If your timezone is not listed, just select whatever you want and email the admin your correct time zone.)
83                </td>
84               </tr><tr>
85                <td colspan="2"> <input type="submit" value="register" /></td>
86              </table>
87           </fieldset>
88         </form>
89 <?php
90   return;
91 }                                          
92
93 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
94 {
95   global $RULES;
96
97   echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
98   echo "<form action=\"index.php\" method=\"post\">\n";
99   echo "  <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
100   echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
101   echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
102   echo "  <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
103   echo "  <input type=\"hidden\" name=\"dullen\"  value=\"".$RULES["dullen"]."\" />\n";
104   echo "  <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES["schweinchen"]."\" />\n";
105   echo "  <input type=\"hidden\" name=\"call\" value=\"".$RULES["call"]."\" />\n";
106   echo "  <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
107   echo "  <input type=\"submit\" value=\"keep playing\" />\n";
108   echo "</form>\n";
109
110   return;
111 }
112
113 function output_form_for_new_game($names)
114 {
115 ?>
116     <h2> Players </h2>
117     <p>Please select four players (or use the randomly pre-selected names)</p>
118        <form action="index.php" method="post">
119 <?php
120     /* ask for player names */
121   foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
122   {
123     srand((float) microtime() * 10000000);
124     $randkey = array_rand($names);
125     $rand = $names[$randkey];
126     echo "    Name:  <select name=\"$player\" size=\"1\" />  \n";
127     foreach($names as $name)
128     {
129       if($name==$rand)
130         {
131           echo "     <option selected=\"selected\">$name</option>\n";
132         }
133       else
134         echo "     <option>$name</option>\n";
135     }
136     echo "  </select>\n";
137    }
138 ?>   
139    <h2> Rules </h2> 
140       <p> Some areas are grayed out which means that the rule is not implemented yet and therefore cannot be selected </p>
141       <p> ten of hearts: 
142          <ul>
143          <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
144          <li> <input type="radio" name="dullen" value="firstwins" /> first ten of hearts wins the trick </li>
145          <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
146          </ul>
147       </p>
148       <p> schweinchen (both foxes), only in normal games or silent solos: 
149         <ul>
150         <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
151         <li> <input type="radio" name="schweinchen" value="both" /> 
152               both become highest trump (automatic call at beginning of the game)
153         </li>
154         <li> <input type="radio" name="schweinchen" value="second" /> 
155               first one normal, second one becomes highest (call during the game) </li>
156         <li> <input type="radio" name="schweinchen" value="secondaftercall"  disabled="disabled" /> 
157       second one become highest only in case re/contra was announced (not working yet)
158         </li>
159         </ul>
160       </p>
161       <p> Call Re/Contra, etc.: 
162         <ul>
163            <li><input type="radio" name="call" value="1st-own-card" checked="checked" />
164                 Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.</li>
165            <li><input type="radio" name="call" value="5th-card" /> 
166                 Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</li>
167            <li><input type="radio" name="call" value="9-cards"  /> 
168                 Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</li>
169         </ul>
170       </p>      
171    <input type="submit" value="start game" />
172  </form>
173 <?php
174 }
175
176 function display_card($card,$dir="english")
177 {
178   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ... 
179    * convert even cards to the matching odd value */
180
181   if( $card/2 - (int)($card/2) == 0.5)
182     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
183   else
184     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
185
186   return;
187 }
188
189 function display_link_card($card,$dir="english",$type="card")
190 {
191   if( $card/2 - (int)($card/2) == 0.5)
192     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";
193   else
194     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";
195   return;
196 }
197
198 function output_check_for_sickness($me,$mycards)
199 {
200  ?>
201   <form action="index.php" method="post">
202
203     do you want to play solo? 
204     <select name="solo" size="1">
205       <option selected="selected">No</option>
206       <option>trumpless</option>
207       <option>trump</option>
208       <option>queen</option>
209       <option>jack</option>
210       <option>club</option>
211       <option>spade</option>
212       <option>heart</option>
213     </select>     
214     <br />
215
216  <?php   
217       
218   echo "Wedding?";
219   if(check_wedding($mycards))
220      {
221        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
222        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
223      }
224    else
225      {
226        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
227      };
228
229   echo "Do you have poverty?";
230   if(count_trump($mycards)<4)
231     {
232       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
233       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
234     }
235   else
236     {
237       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
238     };
239
240    echo "Do you have too many nines?";
241   if(count_nines($mycards)>4)
242      {
243        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
244        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
245      }
246    else
247      {
248        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
249      };
250
251    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
252    echo "<input type=\"submit\" value=\"count me in\" />\n";
253
254    echo "</form>\n";
255
256   return;
257 }
258
259 function check_want_to_play($me)
260 {
261    ?>
262  <form action="index.php" method="post">
263    Do you want to play a game of DoKo?
264    yes<input type="radio" name="in" value="yes" />
265    no<input type="radio" name="in" value="no" /> <br />
266
267 <?php   
268 /*
269    Do you want to get an email for every card played or only if it your move?
270    every card<input type="radio" name="update" value="card" />
271    only on my turn<input type="radio" name="update" value="turn" /> <br />
272 */
273   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
274   echo "\n";
275   echo "<input type=\"submit\" value=\"count me in\" />\n";
276   echo " </form>\n";
277
278   return;
279 }
280
281 function output_home_page($pre,$game,$done,$avgtime)
282 {
283 ?>
284     <p> If you want to play a game of Doppelkopf, you found the right place ;) </p>
285 <?php
286     if($pre == 0)
287       echo "<p> At the moment there are no games that are being started ";
288     else if($pre==1)
289       echo "<p> At the moment there is one games that is being started ";
290     else
291       echo "<p> At the moment there are $pre games that are being started ";
292
293     echo "and ";
294
295     if($game==0)
296       echo "zero games that are ongoing. ";
297     else if($game==1)   
298       echo "one game that is ongoing. ";
299     else 
300       echo "$game games that are ongoing. ";
301
302     echo "<br />\n";
303
304     if($done==0)
305       echo "No game has been completed on this server. </p>";
306     else if($done==1)
307       echo "One game has been completed on this server. </p>";
308     else
309       echo "$done games have been completed on this server. Average time of a game: $avgtime days</p>";
310 ?>
311
312     <p> Please <a href="index.php?register">register</a>, in case you haven't done that yet  <br />
313         or login with you email-address or name and password here:
314     </p>
315         <form action="index.php" method="post">
316           <fieldset>
317             <legend>Login</legend>
318              <table>
319               <tr>
320                  <td><label for="email">Email:</label></td>
321                  <td><input type="text" id="email" name="email" size="20" maxlength="30" /> </td>
322               </tr><tr>
323                  <td><label for="password">Password:</label></td>
324                  <td><input type="password" id="password" name="password" size="20" maxlength="30" /></td>
325               </tr><tr>
326                 <td> <input type="submit" class="submitbutton" name="login" value="login" /></td>
327                 <td> <input type="submit" class="submitbutton" name="forgot" value="Forgot your password?" /></td>
328               </tr>
329              </table>
330           </fieldset>
331         </form>
332
333 <?php
334  return;
335 }
336
337 function output_header()
338 {
339    global $REV;
340 ?>
341 <!DOCTYPE html PUBLIC
342     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
343     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
344 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
345   <head>
346      <title>e-Doko</title>
347      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
348      <link rel="stylesheet" type="text/css" href="css/standard.css" />  
349      <script type="text/javascript">
350        function hl(num) {
351          if(document.getElementById){
352            var i;
353            for(i=1;i<13;i++){
354              if(document.getElementById("trick"+i))
355                document.getElementById("trick"+i).style.display = 'none';
356            }
357            document.getElementById("trick"+num).style.display = 'block';
358          }
359        }
360        function high_last(){
361          if(document.getElementById){
362            var i;
363            for(i=12;i>0;i--) {
364              if(document.getElementById("trick"+i))
365                {
366                  hl(i);
367                  break;
368                }
369            }
370          }
371        }
372      </script>
373   </head>
374 <body onload="high_last();">
375 <div class="header">
376 <h1> Welcome to E-Doko <sup style="color:#888;">(beta)</sup> </h1>
377 </div>
378
379 <?php
380   return;
381 }
382
383
384
385 function output_footer()
386 {
387   global $REV,$PREF;
388
389   echo "<div class=\"footer\">\n";
390   echo "<p class=\"left\"> copyright 2006-2007 Arun Persaud <br />\n".
391     "Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />".
392     "- ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />".
393     "a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
394   echo "<p class=\"right\"> Revision: $REV; <br /><a href=\"http://svn.nubati.net/emaildoko/trunk/\">".
395     "http://svn.nubati.net/emaildoko/trunk/</a> <br />".
396     "<a href=\"http://www.dreamhost.com/green.cgi\">".
397     "<img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
398     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>".
399     "</p> \n";
400   echo "\n";
401   echo "</div>\n";
402
403   echo "</body>\n";
404   echo "</html>\n";
405
406   return;
407 }
408
409 function output_password_recovery($email,$password)
410 {
411 ?>
412    <form action="index.php" method="post">
413 <?php
414   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
415   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
416   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
417 ?>    
418      <fieldset>
419        <legend>Password recovery</legend>
420         <table>
421          <tr>
422             <td><label for="email">Old password:</label></td>
423             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
424          </tr><tr>
425             <td><label for="password">New password:</label></td>
426             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
427          </tr><tr>
428             <td><label for="password">Retype:</label></td>
429             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
430          </tr><tr>
431            <td></td>
432            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
433          </tr>
434         </table>
435      </fieldset>
436    </form>
437
438 <?php
439 }
440 ?>