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