28489a08a50fabd1829b422d81dd1f1a29c03a2d
[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/standard003.css" />
232      <script type="text/javascript">
233        var current=0;
234        function hl(num) {
235          if(document.getElementById){
236            var i;
237            for(i=1;i<14;i++){
238              if(document.getElementById("trick"+i))
239                document.getElementById("trick"+i).style.display = 'none';
240            }
241            document.getElementById("trick"+num).style.display = 'block';
242            current=num;
243          }
244        }
245        function high_last(){
246          if(document.getElementById){
247            var i;
248            for(i=13;i>=0;i--) {
249              if(document.getElementById("trick"+i))
250                {
251                  hl(i);
252                  current=i;
253                  break;
254                }
255            }
256          }
257        }
258        function hl_next()
259          {
260            if(document.getElementById("trick"+(current+1)))
261              hl(current+1);
262          }
263        function hl_prev()
264          {
265            if(document.getElementById("trick"+(current-1)))
266              hl(current-1);
267          }
268      </script>
269   </head>
270 <body onload="high_last();">
271 <div class="header">
272 <h1> Welcome to E-Doko <sup style="color:#888;">(beta)</sup> </h1>
273 </div>
274 <?php
275
276   echo "<div class=\"main\">";
277   return;
278 }
279
280 function output_footer()
281 {
282   global $REV,$PREF;
283
284   echo "</div>\n\n";
285   echo "<div class=\"footer\">\n";
286   echo "  <p class=\"left\"> copyright 2006-2008 Arun Persaud, Lance Thornton <br />\n".
287     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
288     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
289     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
290  echo "  <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
291     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
292     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
293     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
294     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
295     "  </p> \n";
296   echo "\n";
297   echo "</div>\n";
298
299   echo "</body>\n";
300   echo "</html>\n";
301
302   return;
303 }
304
305 function output_status()
306 {
307   global $defaulttimezone,$INDEX,$WIKI;
308    if(isset($_SESSION["name"]))
309      {
310        $name = $_SESSION["name"];
311
312        /* logout info */
313        echo "\n<div class=\"status\">\n";
314        echo $name,"\n";
315        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
316        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
317        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
318        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
319        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
320        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
321        echo "</div>\n";
322
323        /* last logon time */
324        $myid  = DB_get_userid("name",$name);
325        $zone  = DB_get_user_timezone($myid);
326
327        $time     = DB_get_user_timestamp($myid);
328        date_default_timezone_set($defaulttimezone);
329        $unixtime = strtotime($time);
330        date_default_timezone_set($zone);
331
332        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>\n";
333      };
334   return;
335 }
336
337 function output_select_timezone($name,$timezone="")
338 {
339   $Tzone = array ( "Europe/London"     => "London",
340                    "Europe/Berlin"     => "Berlin",
341                    "America/Vancouver" => "Berkeley",
342                    "Pacific/Auckland"  => "Wellington" );
343
344   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
345
346   foreach($Tzone as $zone=>$city)
347     {
348       if($timezone==$zone)
349         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
350       else
351         echo "   <option value=\"$zone\">$city</option>\n";
352     }
353   echo "  </select>\n";
354
355   return;
356 }
357
358
359
360 function output_password_recovery($email,$password)
361 {
362 ?>
363    <form action="index.php" method="post">
364 <?php
365   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
366   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
367   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
368 ?>
369      <fieldset>
370        <legend>Password recovery</legend>
371         <table>
372          <tr>
373             <td><label for="email">Old password:</label></td>
374             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
375          </tr><tr>
376             <td><label for="password">New password:</label></td>
377             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
378          </tr><tr>
379             <td><label for="password">Retype:</label></td>
380             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
381          </tr><tr>
382            <td></td>
383            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
384          </tr>
385         </table>
386      </fieldset>
387    </form>
388
389 <?php
390 }
391 ?>