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