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