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