starting to bootstrap the layout: navbar and tricks
[e-DoKo.git] / include / output.php
1 <?php
2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
3  *
4  *   This file is part of e-DoKo.
5  *
6  *   e-DoKo is free software: you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, either version 3 of the License, or
9  *   (at your option) any later version.
10  *
11  *   e-DoKo is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 /* make sure that we are not called from outside the scripts,
22  * use a variable defined in config.php to check this
23  */
24 if(!isset($HOST))
25   exit;
26
27 /* functions which only ouput html  */
28
29 function autoversion($file)
30 {
31   /* changes the file name of e.g. css/style.css to css/style.<md5>.css/js
32    * this way the browser can cache the file and will reload it if the file changed
33    * needs to have .htaccess set up correctly to link back to css/style.css */
34
35   /* only use it for file that have an absolut path */
36   if(!file_exists(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file))
37     return $file;
38
39   $md5 = md5_file(dirname($_SERVER['SCRIPT_FILENAME']). '/' . $file);
40   return preg_replace('{\\.([^./]+)$}', ".$md5.\$1", $file);
41 }
42
43
44 function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
45 {
46   global $RULES;
47
48   echo "<div class=\"message\">\n<form action=\"index.php?action=new\" method=\"post\">\n";
49   $output = sprintf(_('Do you want to continue playing? (This will start a new game, with %s starting the game.)'),$playerA);
50   echo $output."\n";
51   echo "  <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
52   echo "  <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
53   echo "  <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
54   echo "  <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
55   echo "  <input type=\"hidden\" name=\"dullen\"  value=\"".$RULES['dullen']."\" />\n";
56   echo "  <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES['schweinchen']."\" />\n";
57   echo "  <input type=\"hidden\" name=\"callrule\" value=\"".$RULES['call']."\" />\n";
58   echo "  <input type=\"hidden\" name=\"lowtrump\" value=\"".$RULES['lowtrump']."\" />\n";
59   echo "  <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
60   echo "  <input type=\"submit\" value=\""._('keep playing')."\" />\n";
61   echo "</form>\n</div>";
62   return;
63 }
64
65 function output_form_for_new_game($names)
66 {
67   $copy_names = $names; /* local copy, so that we can delete names from it
68                          * after we selected them to make sure that each name
69                          * only shows up once
70                          */
71
72   /* delete players name, since he will be on position D anyway */
73   unset($copy_names[array_search($_SESSION["name"],$copy_names)]);
74   srand((float) microtime() * 10000000);
75
76
77   echo '  <form action="index.php?action=new" method="post">';
78   echo '    <h2> '._('Select players (Remember: you need to be one of the players)').' </h2>';
79
80   echo '   <div class="table">';
81
82   echo  "     <div class=\"table1\">\n";
83   $randkey = array_rand($copy_names);
84   $rand = $copy_names[$randkey];
85   /* delete this name from the list of possible names */
86   unset($copy_names[$randkey]);
87   echo "       <select name=\"PlayerB\" size=\"1\">  \n";
88   foreach($names as $name)
89     {
90       if($name==$rand)
91         echo "         <option selected=\"selected\">$name</option>\n";
92       else
93         echo "         <option>$name</option>\n";
94     }
95   echo "       </select>\n     </div>\n";
96
97   echo '   <div class="middle">';
98
99   $randkey = array_rand($copy_names);
100   $rand = $copy_names[$randkey];
101   /* delete this name from the list of possible names */
102   unset($copy_names[$randkey]);
103   echo  "     <div class=\"table0\">\n";
104   echo "       <select name=\"PlayerA\" size=\"1\">  \n";
105   foreach($names as $name)
106     {
107       if($name==$rand)
108         echo "         <option selected=\"selected\">$name</option>\n";
109       else
110         echo "         <option>$name</option>\n";
111     }
112   echo "       </select>\n     </div>\n";
113
114   echo '     <img class="table" src="pics/table.png" alt="table" />';
115   $randkey = array_rand($copy_names);
116   $rand = $copy_names[$randkey];
117   /* delete this name from the list of possible names */
118   unset($copy_names[$randkey]);
119   echo  "     <div class=\"table2\">\n";
120   echo "       <select name=\"PlayerC\" size=\"1\">  \n";
121   foreach($names as $name)
122     {
123       if($name==$rand)
124         echo "         <option selected=\"selected\">$name</option>\n";
125       else
126         echo "         <option>$name</option>\n";
127     }
128   echo "       </select>\n     </div>\n";
129
130   echo '   </div>';
131   $rand = $_SESSION["name"];
132   echo  "     <div class=\"table3\">\n";
133   $i++;
134   echo "       <select name=\"PlayerD\" size=\"1\">  \n";
135   foreach($names as $name)
136     {
137       if($name==$rand)
138         echo "         <option selected=\"selected\">$name</option>\n";
139       else
140         echo "         <option>$name</option>\n";
141     }
142   echo "       </select>\n     </div>\n";
143
144   /* ask player for names */
145
146     echo '    </div>';
147     echo '';
148     echo '     <h2 class="rules">'._('Rules').'</h2>';
149     echo '     <h3>'._('Gameplay-related').'</h3>';
150     echo '     <h4>'._('Ten of hearts').':</h4>';
151     echo '     <p>';
152     echo '       <select name="dullen">';
153     echo '         <option value="none"> '._('just normal non-trump').'  </option>';
154     echo '         <option value="firstwins"> '._('first ten of hearts wins the trick').' </option>';
155     echo '         <option value="secondwins" selected="selected"> '.('second ten of hearts wins the trick').' </option>';
156     echo '       </select>';
157     echo '     </p>';
158     echo '     <h4>'._('Schweinchen (both foxes), only in normal games or silent solos').':</h4>';
159     echo '     <p>';
160     echo '       <select name="schweinchen">';
161     echo '         <option value="none" selected="selected"> '._('none').' </option>';
162     echo '       <option value="both"> '._('both become highest trump (automatic call at beginning of the game)').'   </option>';
163     echo '       <option value="second"> '._('first one normal, second one becomes highest (call during the game)').' </option>';
164     echo '       <option value="secondaftercall">  ',_('second one become highest only in case re/contra was announced');
165     echo '       </option>';
166     echo '       </select>';
167     echo '     </p>';
168     echo '     <h4>'._('Call Re/Contra, etc.').':</h4>';
169     echo '     <p>';
170     echo '       <select name="callrule">';
171     echo '       <option value="1st-own-card" selected="selected">  '._('Can call re/contra on the first <strong>own</strong> card played, 90 on the second, etc.').'</option>';
172     echo '       <option value="5th-card"> '._('Can call re/contra until 5th card is played, 90 until 9th card is played, etc.').'</option>';
173     echo '       <option value="9-cards" > '._('Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.').'</option>';
174     echo '       </select>';
175     echo '     </p>';
176     echo '     <h4>'._('Low trump').'</h4>';
177     echo '     <p>';
178     echo '       '._('Player can\'t trump a fox, that is none of his trump is higher than a fox.');
179     echo '       <select name="lowtrump">';
180     echo '       <option value="poverty">'._('The trump will be treated as poverty and offered to another player.').'</option>';
181     echo '       <option value="cancel"> '._('The game will be canceled unless there is a solo.').'</option>';
182     echo '       <option value="none">   '._('Bad luck, the player needs to play a normal game.').'</option>';
183     echo '       </select>';
184     echo '     </p>';
185     echo '     <h3>'._('Scoring-related').'</h3>';
186     echo '     <h4>'._('(not yet implemented)').'</h4>';
187     echo '     <p><input type="submit" value="'._('start game').'"></p>';
188     echo '     </form>';
189
190 }
191
192 function output_table($data,$caption="",$class="",$id="")
193 {
194
195   $HTML  = "\n<table";
196
197   if($class!="")
198     $HTML.= " class=\"$class\"";
199   if($id!="")
200     $HTML.= " id=\"$id\"";
201
202   $HTML.=">\n";
203
204   $i=0;
205
206   if($caption!="")
207     $HTML .= "  <caption> $caption </caption>\n";
208
209   foreach($data as $record)
210     {
211       if(!$i)
212         $HTML .= "  <thead>\n  <tr>\n";
213       else
214         {
215           if($i==1) $HTML .= "  <tbody>\n";
216           $HTML .= "  <tr>  ";
217         }
218       foreach($record as $point)
219         {
220           if($i)
221             $HTML .= "    <td>$point</td> ";
222           else
223             $HTML .= "    <th>$point</th> ";
224         }
225
226       if(!$i)
227         $HTML .= "  </tr>\n  </thead>\n";
228       else
229         {
230           $HTML .= "  </tr>\n";
231         }
232       $i++;
233     }
234   $HTML .= "  </tbody>\n</table>\n";
235
236   return $HTML;
237 }
238
239 function display_card($card,$dir="english")
240 {
241   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
242    * convert even cards to the matching odd value */
243
244   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
245     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
246   else
247     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
248
249   return;
250 }
251
252 function display_link_card($card,$dir="english",$type="card", $selected=0)
253 {
254   if($selected)
255     $selected = 'checked="checked"';
256
257   if( $card/2 - (int)($card/2) == 0.5)
258     echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></label>\n";
259   else
260     echo "<label class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></label>\n";
261   return;
262 }
263
264 function output_check_for_sickness($me,$mycards)
265 {
266   global $RULES;
267
268   echo '  <div class="sickness"> '._('Thanks for joining the game').'...<br />';
269   echo '';
270   echo '    '._('Do you want to play solo?').'';
271   echo '    <select name="solo" size="1">';
272   echo '      <option value="No" selected="selected">'.'No'.'</option>';
273   echo '      <option value="trumpless">'._('trumpless').'</option>';
274   echo '      <option value="trump">'._('trump').'</option>';
275   echo '      <option value="queen">'._('queen').'</option>';
276   echo '      <option value="jack">'._('jack').'</option>';
277   echo '      <option value="club">'._('club').'</option>';
278   echo '      <option valvue="spade">'._('spade').'</option>';
279   echo '      <option value="hear">'._('heart').'</option>';
280   echo '    </select>';
281   echo '    <br />';
282
283   if(check_wedding($mycards))
284      {
285        echo _('Do you want to call Wedding?');
286        echo ' '._('yes')."<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
287        echo ' '._('no')." <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
288      }
289    else
290      {
291        echo "  <input type=\"hidden\" name=\"wedding\" value=\"no\" />\n";
292      };
293
294   if(count_trump($mycards)<4)
295     {
296       echo _('Do you want to call poverty?');
297       echo ' '._('yes')."<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
298       echo ' '._('no')." <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
299     }
300   else
301     {
302       echo "  <input type=\"hidden\" name=\"poverty\" value=\"no\" />\n";
303     };
304
305   if(count_nines($mycards)>4)
306      {
307        echo _('Do you want to call too many nines?');
308        echo ' '._('yes')."<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
309        echo ' '._('no')." <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
310      }
311    else
312      {
313        echo "  <input type=\"hidden\" name=\"nines\" value=\"no\" />\n";
314      };
315
316   if($RULES['lowtrump']=='cancel' || $RULES['lowtrump']=='poverty')
317     {
318       if(check_low_trump($mycards))
319         {
320           if($RULES['lowtrump']=='cancel')
321             echo _('Do you want to call low trump (cancel game)?');
322           else
323             echo _('Do you want to call low trump (poverty)?');
324
325           echo ' '._('yes')."<input type=\"radio\" name=\"lowtrump\" value=\"yes\" checked=\"checked\" />";
326           echo ' '._('no')." <input type=\"radio\" name=\"lowtrump\" value=\"no\" /> <br />\n";
327         }
328       else
329         {
330           echo "  <input type=\"hidden\" name=\"lowtrump\" value=\"no\" />\n";
331         };
332     }
333   else
334     echo "  <input type=\"hidden\" name=\"lowtrump\" value=\"no\" />";
335
336    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
337    echo "<br /><input type=\"submit\" value=\""._('count me in')."\" />\n";
338
339    echo "</div>\n";
340
341   return;
342 }
343
344 function output_form_calls($me,$myparty)
345 {
346   $highstart = '  <span class="highcall">';
347   $highend   = '</span>';
348
349   $tmp = can_call(120,$me);
350   if( $tmp )
351     {
352       if($tmp==2) echo $highstart;
353       if($myparty=='re')
354         echo '  re (120):';
355       else if ($myparty=='contra')
356         echo '  contra (120):';
357       else
358         echo '  re/contra (120):';
359       echo ' <input type="radio" name="call" value="120" />';
360       if($tmp==2) echo $highend;
361       echo "\n";
362     }
363   $tmp = can_call(90,$me);
364   if( $tmp )
365     {
366       if($tmp==2) echo $highstart;
367       echo '  90:'.
368         ' <input type="radio" name="call" value="90" />';
369       if($tmp==2) echo $highend;
370       echo "\n";
371     }
372   $tmp = can_call(60,$me);
373   if( $tmp )
374     {
375       if($tmp==2) echo $highstart;
376       echo '  60:'.
377         ' <input type="radio" name="call" value="60" />';
378       if($tmp==2) echo $highend;
379       echo "\n";
380     }
381   $tmp = can_call(30,$me);
382   if( $tmp )
383     {
384       if($tmp==2) echo $highstart;
385       echo '  30:'.
386         ' <input type="radio" name="call" value="30" />';
387       if($tmp==2) echo $highend;
388       echo "\n";
389     }
390   $tmp = can_call(0,$me);
391   if( $tmp )
392     {
393       if($tmp==2) echo $highstart;
394       echo '  0:'.
395         ' <input type="radio" name="call" value="0" />';
396       if($tmp==2) echo $highend;
397       echo "\n".
398         '  no call:'.
399         ' <input type="radio" name="call" value="no" />'."\n";
400     }
401 }
402
403 function output_check_want_to_play($me)
404 {
405   echo ' <div class="joingame">';
406   echo '   '._('Do you want to play a game of DoKo?').' <br />';
407   echo '   '._('yes').'<input type="radio" name="in" value="yes" checked="checked" />';
408   echo '   '._('no').'<input type="radio" name="in" value="no" /> <br />';
409   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
410   echo "\n";
411   echo "<input type=\"submit\" value=\""._('submit')."\" />\n";
412   echo " </div>\n";
413
414   return;
415 }
416
417 function output_header()
418 {
419    global $REV;
420 ?>
421 <!DOCTYPE html>
422 <html lang="en">
423   <head>
424      <title>e-Doko</title>
425      <meta charset="utf-8" />
426      <meta name="viewport" content="width=device-width; initial-scale=1.0;" />
427      <link rel="shortcut icon" href="pics/edoko-favicon.png" />
428      <link rel="stylesheet/less" media="all" href="<?php echo autoversion("css/bootstrap.less"); ?>" />
429      <link rel="stylesheet/less" href="<?php echo autoversion("css/standard.less"); ?>" />
430      <link rel="stylesheet" href="<?php echo autoversion("css/dateinput.css"); ?>"/>
431      <script src="js/less.min.js" type="text/javascript"></script>
432   </head>
433 <body onload="high_last();">
434 <?php
435
436   echo "<div class=\"main\">";
437   return;
438 }
439
440 function output_footer()
441 {
442   global $REV, $PREF, $INDEX;
443
444   echo "</div>\n\n";
445   echo "<footer>\n";
446   echo "  <p class=\"left\"> copyright 2006-2012 <a href=\"$INDEX?action=about\">Arun Persaud, et al.</a> <br />\n".
447     "  Verwendung der [deutschen] Kartenbilder mit Genehmigung <br />der Spielkartenfabrik Altenburg GmbH,(c) ASS Altenburger <br />\n".
448     "  - ASS Altenburger Spielkarten - Spielkartenfabrik Altenburg GmbH <br />\n".
449     "  a Carta Mundi Company Email: info@spielkarten.com Internet: www.spielkarten.com</p>\n";
450   echo " <p class=\"right\"> See the latest changes <a href=\"http://nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=summary\">\n".
451     "  via git </a> <br />or download the source via <br />\n'git clone http://nubati.net/git/e-DoKo.git' <br />\n".
452     "  <a href=\"http://www.dreamhost.com/green.cgi\">\n".
453     "  <img alt=\"Green Web Hosting! This site hosted by DreamHost.\"".
454     " src=\"pics/green1.gif\" height=\"32\" width=\"100\" /></a>\n".
455     "  </p> \n";
456   echo "</footer>\n\n";
457
458   echo '<script src="'.autoversion('js/jquery.min.js').             '"></script>';
459   echo '<script src="'.autoversion('js/jquery.tablesorter.min.js'). '"></script>';
460   echo '<script src="'.autoversion('js/jquery.tools.min.js').       '"></script>';
461   echo '<script src="'.autoversion('js/bootstrap.min.js').          '"></script>';
462   echo '<script src="'.autoversion('js/layout.js').                 '"></script>';
463   echo '<script src="'.autoversion('js/game.js').                   '"></script>';
464
465   echo "</body>\n";
466   echo "</html>\n";
467
468   return;
469 }
470
471 function output_navbar()
472 {
473   global $defaulttimezone, $INDEX, $WIKI, $RSS;
474
475   if(isset($_SESSION['name']))
476     {
477       $name = $_SESSION['name'];
478
479       /* last logon time */
480       $myid  = DB_get_userid('name',$name);
481       $zone  = DB_get_user_timezone($myid);
482
483       $time     = DB_get_user_timestamp($myid);
484       date_default_timezone_set($defaulttimezone);
485       $unixtime = strtotime($time);
486       date_default_timezone_set($zone);
487
488       /* rss token */
489       $token = get_user_token($myid);
490
491       /* logout info */
492       echo "\n<div class=\"navbar navbar-fixed-top\">\n";
493       echo "  <div class=\"navbar-inner\">\n";
494       echo "    <span class=\"brand\" href=\"#\">E-DoKo</span>\n";
495       echo "    <ul class=\"nav\">";
496       echo "       <li><a href=\"#\">$name</a> </li>\n";
497       echo "       <li class=\"divider-vertical\"></li>\n";
498       echo " <li> <a href=\"".$INDEX."\">"._('mypage')."</a></li>\n";
499       echo "       <li class=\"divider-vertical\"></li>\n";
500       echo " <li> <a href=\"".$INDEX."?action=prefs\">"._('settings')."</a></li>\n";
501       echo "       <li class=\"divider-vertical\"></li>\n";
502       echo " <li> <a href=\"".$INDEX."?action=new\">"._('new game')."</a></li>\n";
503       echo "       <li class=\"divider-vertical\"></li>\n";
504       echo " <li> <a href=\"".$INDEX."?action=stats\">"._('statistics')."</a></li>\n";
505       echo "       <li class=\"divider-vertical\"></li>\n";
506       echo " <li> <a href=\"".$WIKI."\">"._('wiki/bugs')."</a></li>\n";
507       echo "       <li class=\"divider-vertical\"></li>\n";
508       echo " <li> <a href=\"".$RSS."?uid=".$myid."&amp;token=".$token."\">"._('atom')."</a></li>\n";
509       echo "       <li class=\"divider-vertical\"></li>\n";
510       echo " <li> <a href=\"".$INDEX."?action=logout\">"._('logout')."</a></li>\n";
511       echo "    </ul>\n";
512       echo "  </div>\n";
513       echo "</div>\n\n";
514
515       echo "<div class=\"lastlogin\"><span>"._('last login').": ".date("r",$unixtime)."</span></div>\n\n";
516     }
517   return;
518 }
519
520 function output_select_timezone($name,$timezone="")
521 {
522   $Tzone = array ("Pacific/Apia"         => "Apia",                /*UTC-11*/
523                   "Pacific/Honolulu"     => "Honolulu",            /*UTC-10*/
524                   "America/Anchorage"    => "Anchorage",           /*UTC-9*/
525                   "America/Vancouver"    => "Berkeley",            /*UTC-8*/
526                   "America/Phoenix"      => "Phoenix",             /*UTC-7*/
527                   "America/Chicago"      => "Chicago",             /*UTC-6*/
528                   "America/New_York"     => "New York",            /*UTC-5*/
529                   "America/Santiago"     => "Santiago",            /*UTC-4*/
530                   "America/Buenos_Aires" => "Buenos Aires",        /*UTC-3*/
531                   "Atlantic/South_Georgia" => "Fernando de Noronha", /*UTC-2*/
532                   "Atlantic/Azores"       => "Azores",             /*UTC-1"*/
533                   "Europe/London"         => "London",             /*UTC*/
534                   "Europe/Berlin"         => "Berlin",             /*UTC+1*/
535                   "Africa/Cairo"          => "Cairo",              /*UTC+2*/
536                   "Europe/Moscow"         => "Moscow",             /*UTC+3*/
537                   "Asia/Tehran"           => "Tehran",             /*UTC+3:30*/
538                   "Asia/Dubai"            => "Dubai",              /*UTC+4*/
539                   "Asia/Karachi"          => "Karachi",            /*UTC+5*/
540                   "Asia/Calcutta"         => "Delhi",              /*UTC+5:30*/
541                   "Asia/Kathmandu"        => "Kathmandu",          /*UTC+5:45*/
542                   "Asia/Dhaka"            => "Dhaka",              /*UTC+6*/
543                   "Asia/Rangoon"          => "Yangon",             /*UTC+6:30*/
544                   "Asia/Bangkok"          => "Bangkok",            /*UTC+7*/
545                   "Asia/Hong_Kong"        => "Beijing",            /*UTC+8*/
546                   "Asia/Tokyo"            => "Tokyo",              /*UTC+9*/
547                   "Australia/Darwin"      => "Darwin",             /*UTC+9:30*/
548                   "Australia/Sydney"      => "Sydney",             /*UTC+10*/
549                   "Asia/Magadan"          => "Magadan",            /*UTC+11*/
550                   "Pacific/Auckland"      => "Wellington" );       /*UTC+12*/
551
552   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
553
554   foreach($Tzone as $zone=>$city)
555     {
556       if($timezone==$zone)
557         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
558       else
559         echo "   <option value=\"$zone\">$city</option>\n";
560     }
561   echo "  </select>\n";
562
563   return;
564 }
565
566 function output_select_language($name,$language="")
567 {
568   $LOCALE = array ("English"     => "en",
569                    "Deutsch"     => "de" );
570
571   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
572
573   foreach($LOCALE as $place=>$locale)
574     {
575       if($language==$locale)
576         echo "   <option value=\"$locale\" selected=\"selected\">$place</option>\n";
577       else
578         echo "   <option value=\"$locale\">$place</option>\n";
579     }
580   echo "  </select>\n";
581
582   return;
583 }
584
585
586 function output_password_recovery($email,$password)
587 {
588 ?>
589    <form action="index.php" method="post">
590 <?php
591   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
592   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
593   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
594 ?>
595      <fieldset>
596        <legend>Password recovery</legend>
597         <table>
598          <tr>
599             <td><label for="password0">Old password:</label></td>
600             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
601          </tr><tr>
602             <td><label for="password1">New password:</label></td>
603             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
604          </tr><tr>
605             <td><label for="password2">Retype:</label></td>
606             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
607          </tr><tr>
608            <td></td>
609            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
610          </tr>
611         </table>
612      </fieldset>
613    </form>
614
615 <?php
616 }
617
618 function output_user_notes($userid,$gameid,$userstatus)
619 {
620   echo "<div class=\"notes\"> "._('Personal notes').": <br />\n";
621   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
622   foreach($notes as $note)
623     echo "  $note <hr />\n";
624   if($userstatus!='gameover')
625     echo "  <input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
626   echo "</div>\n\n";
627
628   return;
629 }
630
631 function output_robotproof($i)
632 {
633   switch($i)
634     {
635     case 0:
636       return "6*7=";
637     case 1:
638       return "5*7=";
639     case 2:
640       return "4*7=";
641     case 3:
642       return "3*7=";
643     case 4:
644       return "2*7=";
645     }
646 }
647
648 function output_exchanged_cards()
649 {
650   /* in a poverty game this function will output the exchanged cards
651    * players in the team will see the cards, the other team will see
652    * the backside of cards
653    */
654
655   /* need some information about the game */
656   global $gameid,$mygametype, $PREF,$me,$mystatus, $RULES;
657
658   /* some variables to track where the people with poverty are sitting */
659   $partnerpos1 = 0;
660   $povertypos1 = 0;
661   $partnerpos2 = 0;
662   $povertypos2 = 0;
663
664   /* only need to do it in a poverty game, this might not be needed, but
665    * just to make sure everything is ok
666    */
667   if($mygametype == 'poverty' || $mygametype=='dpoverty')
668     {
669       /* find out who has poverty */
670       for($mypos=1;$mypos<5;$mypos++)
671         {
672           $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
673           if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
674             if($povertypos1)
675               $povertypos2 = $mypos;
676             else
677               $povertypos1 = $mypos;
678         }
679       /* get hash and exchanged cards for all involved */
680       $povertyhash1 = DB_get_hash_from_game_and_pos($gameid,$povertypos1);
681       $partnerhash1 = DB_get_partner_hash_by_hash($povertyhash1);
682
683       $povertycards1 = DB_get_exchanged_cards($povertyhash1);
684       $partnercards1 = DB_get_exchanged_cards($partnerhash1);
685
686       $partnerpos1 = DB_get_pos_by_hash($partnerhash1);
687       if($povertypos2)
688         {
689           $povertyhash2 = DB_get_hash_from_game_and_pos($gameid,$povertypos2);
690           $partnerhash2 = DB_get_partner_hash_by_hash($povertyhash2);
691
692           $povertycards2 = DB_get_exchanged_cards($povertyhash2);
693           $partnercards2 = DB_get_exchanged_cards($partnerhash2);
694
695           $partnerpos2 = DB_get_pos_by_hash($partnerhash2);
696         }
697     }
698
699   /* output the cards
700    * go through all positions, check that position has cards that need to be shown and
701    * show those cards
702    */
703   $show=1;
704   for($mypos=1;$mypos<5;$mypos++)
705     {
706       /* output comments */
707       if($mypos==2)
708         {
709           /* display all comments on the top right (card1)*/
710           $comments = DB_get_pre_comment($gameid);
711           /* display card */
712           echo "      <div class=\"card1\">\n";
713           /* display comments */
714           foreach( $comments as $comment )
715             echo "        <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
716           echo "      </div>\n"; /* end div card */
717         }
718
719       $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
720       if($usersick!=NULL ||
721          $mypos==$povertypos1 || $mypos==$partnerpos1 ||
722          $mypos==$povertypos2 || $mypos==$partnerpos2 )
723         {
724           /* figure out if we gave trump back */
725           $trump_back1=0;
726           if($povertypos2)
727             foreach($povertycards1 as $card)
728               {
729                 if(is_trump($card))
730                   {
731                     $trump_back1=1;
732                     break;
733                   }
734               }
735           $trump_back2=0;
736           if($povertypos2)
737             foreach($povertycards2 as $card)
738               {
739                 if(is_trump($card))
740                   {
741                     $trump_back2=1;
742                     break;
743                   }
744               }
745
746           /* output vorbehalt  */
747           echo "      <div class=\"vorbehalt".($mypos-1)."\"> Vorbehalt <br />\n";
748           if($show)
749             echo "       $usersick <br />\n";
750
751           /* output cards */
752           if($mypos==$partnerpos1)
753             {
754               foreach($partnercards1 as $card)
755                 {
756                   echo '        ';
757                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
758                     display_card($card,$PREF['cardset']);
759                   else
760                     display_card(0,$PREF['cardset']);
761                 }
762               if($trump_back1) echo '        '._('Trump back');
763             }
764           else if($mypos==$povertypos1)
765             {
766               foreach($povertycards1 as $card)
767                 {
768                   echo '        ';
769                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
770                     display_card($card,$PREF['cardset']);
771                   else
772                     display_card(0,$PREF['cardset']);
773               }
774               if($trump_back1) echo '        '._('Trump back');
775             }
776           else if($mypos==$povertypos2)
777             {
778               foreach($povertycards2 as $card)
779                 {
780                   echo '        ';
781                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
782                     display_card($card,$PREF['cardset']);
783                   else
784                     display_card(0,$PREF['cardset']);
785                 }
786               if($trump_back2) echo '        '._('Trump back');
787             }
788           else if($mypos==$partnerpos2)
789             {
790               foreach($partnercards2 as $card)
791                 {
792                   if(is_trump($card)) $trump_back=1;
793                   echo '        ';
794                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
795                     display_card($card,$PREF['cardset']);
796                   else
797                     display_card(0,$PREF['cardset']);
798                 }
799               if($trump_back2) echo '        '._('Trump back');
800             }
801           echo  "      </div>\n";
802         }
803       if($mygametype == $usersick)
804         $show = 0;
805     }
806 }
807
808
809 ?>