CLEANUP: cleaned up CSS a bit
[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: </p>
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> Schweinchen (both foxes), only in normal games or silent solos: </p>
71       <ul>
72         <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
73         <li> <input type="radio" name="schweinchen" value="both" />
74               both become highest trump (automatic call at beginning of the game)
75         </li>
76         <li> <input type="radio" name="schweinchen" value="second" />
77              first one normal, second one becomes highest (call during the game) </li>
78         <li> <input type="radio" name="schweinchen" value="secondaftercall" />
79              second one become highest only in case re/contra was announced
80         </li>
81       </ul>
82       <p> Call Re/Contra, etc.: </p>
83       <ul>
84          <li><input type="radio" name="callrule" value="1st-own-card" checked="checked" />
85               Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.</li>
86          <li><input type="radio" name="callrule" value="5th-card" />
87               Can call re/contra until 5th card is played, 90 until 9th card is played, etc.</li>
88          <li><input type="radio" name="callrule" value="9-cards"  />
89               Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.</li>
90       </ul>
91    <input type="submit" value="start game" />
92  </form>
93 <?php
94 }
95
96 function output_table($data,$caption="",$class="")
97 {
98   if($class!="")
99     $HTML  = "\n<table class=\"$class\">\n";
100   else
101     $HTML  = "\n<table>\n";
102
103   $i=0;
104
105   if($caption!="")
106     $HTML .= "  <caption> $caption </caption>\n";
107
108   foreach($data as $record)
109     {
110       if(!$i)
111         $HTML .= "  <thead>\n  <tr>\n";
112       else
113         {
114           if($i==1) $HTML .= "  <tbody>\n";
115           if($i % 2)
116             $HTML .= "  <tr class=\"odd\">   ";
117           else
118             $HTML .= "  <tr class=\"even\">  ";
119         }
120       foreach($record as $point)
121         {
122           if($i)
123             $HTML .= "    <td>$point</td> ";
124           else
125             $HTML .= "    <th>$point</th> ";
126         }
127
128       if(!$i)
129         $HTML .= "  </tr>\n  </thead>\n";
130       else
131         {
132           $HTML .= "  </tr>\n";
133         }
134       $i++;
135     }
136   $HTML .= "  </tbody>\n</table>\n";
137
138   return $HTML;
139 }
140
141 function display_card($card,$dir="english")
142 {
143   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
144    * convert even cards to the matching odd value */
145
146   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
147     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
148   else
149     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
150
151   return;
152 }
153
154 function display_link_card($card,$dir="english",$type="card")
155 {
156   if( $card/2 - (int)($card/2) == 0.5)
157     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";
158   else
159     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";
160   return;
161 }
162
163 function output_check_for_sickness($me,$mycards)
164 {
165  ?>
166   <div class="sickness"> Thanks for joining the game...<br />
167
168     do you want to play solo?
169     <select name="solo" size="1">
170       <option selected="selected">No</option>
171       <option>trumpless</option>
172       <option>trump</option>
173       <option>queen</option>
174       <option>jack</option>
175       <option>club</option>
176       <option>spade</option>
177       <option>heart</option>
178     </select>
179     <br />
180
181  <?php
182
183   echo "Wedding?";
184   if(check_wedding($mycards))
185      {
186        echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
187        echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
188      }
189    else
190      {
191        echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
192      };
193
194   echo "Do you have poverty?";
195   if(count_trump($mycards)<4)
196     {
197       echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
198       echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
199     }
200   else
201     {
202       echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
203     };
204
205    echo "Do you have too many nines?";
206   if(count_nines($mycards)>4)
207      {
208        echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
209        echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
210      }
211    else
212      {
213        echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
214      };
215
216    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
217    echo "<input type=\"submit\" value=\"count me in\" />\n";
218
219    echo "</div>\n";
220
221   return;
222 }
223
224 function output_form_calls($me)
225 {
226   if( can_call(120,$me) )
227     echo " re/contra (120):".
228       " <input type=\"radio\" name=\"call\" value=\"120\" /> <br />";
229   if( can_call(90,$me) )
230     echo " 90:".
231       " <input type=\"radio\" name=\"call\" value=\"90\" /> <br />";
232   if( can_call(60,$me) )
233     echo " 60:".
234       " <input type=\"radio\" name=\"call\" value=\"60\" /> <br />";
235   if( can_call(30,$me) )
236     echo " 30:".
237       " <input type=\"radio\" name=\"call\" value=\"30\" /> <br />";
238   if( can_call(0,$me) )
239     echo " 0:".
240       " <input type=\"radio\" name=\"call\" value=\"0\" /> <br />".
241       " no call:".
242       " <input type=\"radio\" name=\"call\" value=\"no\" /> <br />";
243 }
244
245 function output_check_want_to_play($me)
246 {
247    ?>
248  <div class="joingame">
249    Do you want to play a game of DoKo? <br />
250    yes<input type="radio" name="in" value="yes" />
251    no<input type="radio" name="in" value="no" /> <br />
252 <?php
253   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
254   echo "\n";
255   echo "<input type=\"submit\" value=\"submit\" />\n";
256   echo " </div>\n";
257
258   return;
259 }
260
261 function output_header()
262 {
263    global $REV;
264 ?>
265 <!DOCTYPE html PUBLIC
266     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
267     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
268 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
269   <head>
270      <title>e-Doko</title>
271      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
272      <link rel="shortcut icon" type="image/x-icon" href="pics/edoko-favicon.png" />
273      <link rel="stylesheet" type="text/css" href="css/standard016.css" />
274      <script type="text/javascript" src="include/game.js"> </script>
275   </head>
276 <body onload="high_last();">
277 <div class="header">
278 <h1> Welcome to E-Doko <sup style="color:#888;">(RC 1)</sup> </h1>
279 </div>
280 <?php
281
282   echo "<div class=\"main\">";
283   return;
284 }
285
286 function output_footer()
287 {
288   global $REV,$PREF;
289
290   echo "</div>\n\n";
291   echo "<div class=\"footer\">\n";
292   echo "  <p class=\"left\"> copyright 2006-2008 Arun Persaud, Lance Thornton <br />\n".
293     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
294     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
295     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
296  echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
297     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
298     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
299     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
300     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
301     "  </p> \n";
302   echo "\n";
303   echo "</div>\n";
304
305   echo "</body>\n";
306   echo "</html>\n";
307
308   return;
309 }
310
311 function output_status()
312 {
313   global $defaulttimezone,$INDEX,$WIKI;
314    if(isset($_SESSION["name"]))
315      {
316        $name = $_SESSION["name"];
317
318        /* logout info */
319        echo "\n<div class=\"status\">\n";
320        echo $name,"\n";
321        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
322        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
323        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
324        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
325        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
326        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
327        echo "</div>\n";
328
329        /* last logon time */
330        $myid  = DB_get_userid("name",$name);
331        $zone  = DB_get_user_timezone($myid);
332
333        $time     = DB_get_user_timestamp($myid);
334        date_default_timezone_set($defaulttimezone);
335        $unixtime = strtotime($time);
336        date_default_timezone_set($zone);
337
338        echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
339      }
340    else
341      {
342        echo "\n<div class=\"status\">\n";
343        echo "<a href=\"".$INDEX."\">login</a>\n";
344        echo "</div>\n";
345      }
346   return;
347 }
348
349 function output_select_timezone($name,$timezone="")
350 {
351   $Tzone = array ( "Europe/London"     => "London",
352                    "Europe/Berlin"     => "Berlin",
353                    "America/Vancouver" => "Berkeley",
354                    "Pacific/Auckland"  => "Wellington" );
355
356   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
357
358   foreach($Tzone as $zone=>$city)
359     {
360       if($timezone==$zone)
361         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
362       else
363         echo "   <option value=\"$zone\">$city</option>\n";
364     }
365   echo "  </select>\n";
366
367   return;
368 }
369
370 function output_password_recovery($email,$password)
371 {
372 ?>
373    <form action="index.php" method="post">
374 <?php
375   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
376   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
377   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
378 ?>
379      <fieldset>
380        <legend>Password recovery</legend>
381         <table>
382          <tr>
383             <td><label for="email">Old password:</label></td>
384             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
385          </tr><tr>
386             <td><label for="password">New password:</label></td>
387             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
388          </tr><tr>
389             <td><label for="password">Retype:</label></td>
390             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
391          </tr><tr>
392            <td></td>
393            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
394          </tr>
395         </table>
396      </fieldset>
397    </form>
398
399 <?php
400 }
401
402 function output_user_notes($userid,$gameid,$userstatus)
403 {
404   echo "<div class=\"notes\"> Personal notes: <br />\n";
405   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
406   foreach($notes as $note)
407     echo "$note <hr />\n";
408   if($userstatus!='gameover')
409     echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
410   echo "</div> \n";
411
412   return;
413 }
414
415 ?>