CLEANUP: moved html from output.php to welcome.php
[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 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_header()
246 {
247    global $REV;
248 ?>
249 <!DOCTYPE html PUBLIC
250     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
251     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
252 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
253   <head>
254      <title>e-Doko</title>
255      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
256      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
257      <link rel="stylesheet" type="text/css" href="css/standard001.css" />
258      <script type="text/javascript">
259        function hl(num) {
260          if(document.getElementById){
261            var i;
262            for(i=1;i<14;i++){
263              if(document.getElementById("trick"+i))
264                document.getElementById("trick"+i).style.display = 'none';
265            }
266            document.getElementById("trick"+num).style.display = 'block';
267          }
268        }
269        function high_last(){
270          if(document.getElementById){
271            var i;
272            for(i=13;i>0;i--) {
273              if(document.getElementById("trick"+i))
274                {
275                  hl(i);
276                  break;
277                }
278            }
279          }
280        }
281      </script>
282   </head>
283 <body onload="high_last();">
284 <div class="header">
285 <h1> Welcome to E-Doko <sup style="color:#888;">(beta)</sup> </h1>
286 </div>
287 <?php
288
289   echo "<div class=\"main\">";
290   return;
291 }
292
293 function output_footer()
294 {
295   global $REV,$PREF;
296
297   echo "</div>\n\n";
298   echo "<div class=\"footer\">\n";
299   echo "  <p class=\"left\"> copyright 2006-2008 Arun Persaud, Lance Thornton <br />\n".
300     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
301     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
302     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
303  echo "  <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
304     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
305     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
306     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
307     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
308     "  </p> \n";
309   echo "\n";
310   echo "</div>\n";
311
312   echo "</body>\n";
313   echo "</html>\n";
314
315   return;
316 }
317
318 function output_status()
319 {
320   global $defaulttimezone;
321    if(isset($_SESSION["name"]))
322      {
323        $name = $_SESSION["name"];
324
325        /* logout info */
326        echo "\n<div class=\"status\">";
327        echo $name;
328        echo " <a href=\"index.php?action=logout\">logout</a>";
329        echo "</div>\n";
330
331        /* last logon time */
332        $myid  = DB_get_userid("name",$name);
333        $zone  = DB_get_user_timezone($myid);
334
335        $time     = DB_get_user_timestamp($myid);
336        date_default_timezone_set($defaulttimezone);
337        $unixtime = strtotime($time);
338        date_default_timezone_set($zone);
339
340        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>\n";
341      };
342   return;
343 }
344
345
346 function output_password_recovery($email,$password)
347 {
348 ?>
349    <form action="index.php" method="post">
350 <?php
351   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
352   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
353   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
354 ?>
355      <fieldset>
356        <legend>Password recovery</legend>
357         <table>
358          <tr>
359             <td><label for="email">Old password:</label></td>
360             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
361          </tr><tr>
362             <td><label for="password">New password:</label></td>
363             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
364          </tr><tr>
365             <td><label for="password">Retype:</label></td>
366             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
367          </tr><tr>
368            <td></td>
369            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
370          </tr>
371         </table>
372      </fieldset>
373    </form>
374
375 <?php
376 }
377 ?>