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