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