BUGFIX: new password needs to be at least 4 characters long
[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"  disabled="disabled" />
79              second one become highest only in case re/contra was announced (not working yet)
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/standard010.css" />
274      <script type="text/javascript">
275        var current=0;
276        function hl(num) {
277          if(document.getElementById){
278            var i;
279            for(i=0;i<14;i++){
280              if(document.getElementById("trick"+i))
281                document.getElementById("trick"+i).style.display = 'none';
282            }
283            document.getElementById("trick"+num).style.display = 'block';
284            current=num;
285          }
286        }
287        function high_last(){
288          if(document.getElementById){
289            var i;
290            for(i=13;i>=0;i--) {
291              if(document.getElementById("trick"+i))
292                {
293                  hl(i);
294                  current=i;
295                  break;
296                }
297            }
298          }
299        }
300        function hl_next()
301          {
302            if(document.getElementById("trick"+(current+1)))
303              hl(current+1);
304          }
305        function hl_prev()
306          {
307            if(document.getElementById("trick"+(current-1)))
308              hl(current-1);
309          }
310      </script>
311   </head>
312 <body onload="high_last();">
313 <div class="header">
314 <h1> Welcome to E-Doko <sup style="color:#888;">(beta)</sup> </h1>
315 </div>
316 <?php
317
318   echo "<div class=\"main\">";
319   return;
320 }
321
322 function output_footer()
323 {
324   global $REV,$PREF;
325
326   echo "</div>\n\n";
327   echo "<div class=\"footer\">\n";
328   echo "  <p class=\"left\"> copyright 2006-2008 Arun Persaud, Lance Thornton <br />\n".
329     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
330     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
331     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
332  echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
333     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
334     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
335     "  <img  border=\"0\" alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
336     "src=\"https://secure.newdream.net/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
337     "  </p> \n";
338   echo "\n";
339   echo "</div>\n";
340
341   echo "</body>\n";
342   echo "</html>\n";
343
344   return;
345 }
346
347 function output_status()
348 {
349   global $defaulttimezone,$INDEX,$WIKI;
350    if(isset($_SESSION["name"]))
351      {
352        $name = $_SESSION["name"];
353
354        /* logout info */
355        echo "\n<div class=\"status\">\n";
356        echo $name,"\n";
357        echo " | <a href=\"".$INDEX."\"> mypage </a>\n";
358        echo " | <a href=\"".$INDEX."?action=prefs\">settings</a>\n";
359        echo " | <a href=\"".$INDEX."?action=new\">new game</a>\n";
360        echo " | <a href=\"".$INDEX."?action=stats\">statistics</a>\n";
361        echo " | <a href=\"".$WIKI."\">wiki</a>\n";
362        echo " |&nbsp;&nbsp;&nbsp; <a href=\"".$INDEX."?action=logout\">logout</a>\n";
363        echo "</div>\n";
364
365        /* last logon time */
366        $myid  = DB_get_userid("name",$name);
367        $zone  = DB_get_user_timezone($myid);
368
369        $time     = DB_get_user_timestamp($myid);
370        date_default_timezone_set($defaulttimezone);
371        $unixtime = strtotime($time);
372        date_default_timezone_set($zone);
373
374        echo "<div class=\"lastlogin\"><span>last login: ".date("r",$unixtime)."</span></div>\n";
375      }
376    else
377      {
378        echo "\n<div class=\"status\">\n";
379        echo "<a href=\"".$INDEX."\">login</a>\n";
380        echo "</div>\n";
381      }
382   return;
383 }
384
385 function output_select_timezone($name,$timezone="")
386 {
387   $Tzone = array ( "Europe/London"     => "London",
388                    "Europe/Berlin"     => "Berlin",
389                    "America/Vancouver" => "Berkeley",
390                    "Pacific/Auckland"  => "Wellington" );
391
392   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
393
394   foreach($Tzone as $zone=>$city)
395     {
396       if($timezone==$zone)
397         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
398       else
399         echo "   <option value=\"$zone\">$city</option>\n";
400     }
401   echo "  </select>\n";
402
403   return;
404 }
405
406 function output_password_recovery($email,$password)
407 {
408 ?>
409    <form action="index.php" method="post">
410 <?php
411   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
412   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
413   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
414 ?>
415      <fieldset>
416        <legend>Password recovery</legend>
417         <table>
418          <tr>
419             <td><label for="email">Old password:</label></td>
420             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
421          </tr><tr>
422             <td><label for="password">New password:</label></td>
423             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
424          </tr><tr>
425             <td><label for="password">Retype:</label></td>
426             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
427          </tr><tr>
428            <td></td>
429            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
430          </tr>
431         </table>
432      </fieldset>
433    </form>
434
435 <?php
436 }
437
438 function output_user_notes($userid,$gameid,$userstatus)
439 {
440   echo "<div class=\"notes\"> Personal notes: <br />\n";
441   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
442   foreach($notes as $note)
443     echo "$note <hr />\n";
444   if($userstatus!='gameover')
445     echo "<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
446   echo "</div> \n";
447
448   return;
449 }
450     
451 ?>