FEATURE: make edoko brand name and avatar logo link to the user's home page
[e-DoKo.git] / include / output.php
1 <?php
2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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   echo "       <select name=\"PlayerD\" size=\"1\">  \n";
134   foreach($names as $name)
135     {
136       if($name==$rand)
137         echo "         <option selected=\"selected\">$name</option>\n";
138       else
139         echo "         <option>$name</option>\n";
140     }
141   echo "       </select>\n     </div>\n";
142
143   /* ask player for names */
144
145     echo '    </div>';
146     echo '';
147     echo '     <h2 class="rules">'._('Rules').'</h2>';
148     echo '     <h3>'._('Gameplay-related').'</h3>';
149     echo '     <h4>'._('Ten of hearts').':</h4>';
150     echo '     <p>';
151     echo '       <select name="dullen">';
152     echo '         <option value="none"> '._('just normal non-trump').'  </option>';
153     echo '         <option value="firstwins"> '._('first ten of hearts wins the trick').' </option>';
154     echo '         <option value="secondwins" selected="selected"> '.('second ten of hearts wins the trick').' </option>';
155     echo '       </select>';
156     echo '     </p>';
157     echo '     <h4>'._('Schweinchen (both foxes), only in normal games or silent solos').':</h4>';
158     echo '     <p>';
159     echo '       <select name="schweinchen">';
160     echo '         <option value="none" selected="selected"> '._('none').' </option>';
161     echo '       <option value="both"> '._('both become highest trump (automatic call at beginning of the game)').'   </option>';
162     echo '       <option value="second"> '._('first one normal, second one becomes highest (call during the game)').' </option>';
163     echo '       <option value="secondaftercall">  ',_('second one become highest only in case re/contra was announced');
164     echo '       </option>';
165     echo '       </select>';
166     echo '     </p>';
167     echo '     <h4>'._('Call Re/Contra, etc.').':</h4>';
168     echo '     <p>';
169     echo '       <select name="callrule">';
170     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>';
171     echo '       <option value="5th-card"> '._('Can call re/contra until 5th card is played, 90 until 9th card is played, etc.').'</option>';
172     echo '       <option value="9-cards" > '._('Can call re/contra until 5th card is played, 90 if player still has 9 cards, etc.').'</option>';
173     echo '       </select>';
174     echo '     </p>';
175     echo '     <h4>'._('Low trump').'</h4>';
176     echo '     <p>';
177     echo '       '._('Player can\'t trump a fox, that is none of his trump is higher than a fox.');
178     echo '       <select name="lowtrump">';
179     echo '       <option value="poverty">'._('The trump will be treated as poverty and offered to another player.').'</option>';
180     echo '       <option value="cancel"> '._('The game will be canceled unless there is a solo.').'</option>';
181     echo '       <option value="none">   '._('Bad luck, the player needs to play a normal game.').'</option>';
182     echo '       </select>';
183     echo '     </p>';
184     echo '     <h3>'._('Scoring-related').'</h3>';
185     echo '     <h4>'._('(not yet implemented)').'</h4>';
186     echo '     <p><input type="submit" value="'._('start game').'"></p>';
187     echo '     </form>';
188
189 }
190
191 function output_table($data,$caption="",$class="",$id="")
192 {
193
194   $HTML  = "\n<table";
195
196   if($class!="")
197     $HTML.= " class=\"$class\"";
198   if($id!="")
199     $HTML.= " id=\"$id\"";
200
201   $HTML.=">\n";
202
203   $i=0;
204
205   if($caption!="")
206     $HTML .= "  <caption> $caption </caption>\n";
207
208   foreach($data as $record)
209     {
210       if(!$i)
211         $HTML .= "  <thead>\n  <tr>\n";
212       else
213         {
214           if($i==1) $HTML .= "  <tbody>\n";
215           $HTML .= "  <tr>  ";
216         }
217       foreach($record as $point)
218         {
219           if($i)
220             $HTML .= "    <td>$point</td> ";
221           else
222             $HTML .= "    <th>$point</th> ";
223         }
224
225       if(!$i)
226         $HTML .= "  </tr>\n  </thead>\n";
227       else
228         {
229           $HTML .= "  </tr>\n";
230         }
231       $i++;
232     }
233   $HTML .= "  </tbody>\n</table>\n";
234
235   return $HTML;
236 }
237
238 function display_card($card,$dir="english")
239 {
240   /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
241    * convert even cards to the matching odd value */
242
243   if( $card/2 - (int)($card/2) == 0.5 || $card == 0)
244     echo "<img src=\"cards/".$dir."/".$card.".png\"  alt=\"".DB_get_card_name($card)."\" />\n";
245   else
246     echo "<img src=\"cards/".$dir."/".($card-1).".png\"  alt=\"".DB_get_card_name($card-1)."\" />\n";
247
248   return;
249 }
250
251 function display_link_card($card,$dir="english",$type="card", $selected=0)
252 {
253   if($selected)
254     $selected = 'checked="checked"';
255
256   if( $card/2 - (int)($card/2) == 0.5)
257     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";
258   else
259     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";
260   return;
261 }
262
263 function output_check_for_sickness($me,$mycards)
264 {
265   global $RULES;
266
267   echo '  <div class="sickness"> '._('Thanks for joining the game').'...<br />';
268   echo '';
269   echo '    '._('Do you want to play solo?').'';
270   echo '    <select name="solo" size="1">';
271   echo '      <option value="No" selected="selected">'._('No').'</option>';
272   echo '      <option value="trumpless">'._('trumpless').'</option>';
273   echo '      <option value="trump">'._('trump').'</option>';
274   echo '      <option value="queen">'._('queen').'</option>';
275   echo '      <option value="jack">'._('jack').'</option>';
276   echo '      <option value="club">'._('club').'</option>';
277   echo '      <option value="spade">'._('spade').'</option>';
278   echo '      <option value="heart">'._('heart').'</option>';
279   echo '    </select>';
280   echo '    <br />';
281
282   if(check_wedding($mycards))
283      {
284        echo _('Do you want to call Wedding?');
285        echo ' '._('yes')."<input type=\"radio\" name=\"wedding\" value=\"yes\" checked=\"checked\" />";
286        echo ' '._('no')." <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
287      }
288    else
289      {
290        echo "  <input type=\"hidden\" name=\"wedding\" value=\"no\" />\n";
291      };
292
293   if(count_trump($mycards)<4)
294     {
295       echo _('Do you want to call poverty?');
296       echo ' '._('yes')."<input type=\"radio\" name=\"poverty\" value=\"yes\" checked=\"checked\" />";
297       echo ' '._('no')." <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
298     }
299   else
300     {
301       echo "  <input type=\"hidden\" name=\"poverty\" value=\"no\" />\n";
302     };
303
304   if(count_nines($mycards)>4)
305      {
306        echo _('Do you want to call too many nines?');
307        echo ' '._('yes')."<input type=\"radio\" name=\"nines\" value=\"yes\" checked=\"checked\" />";
308        echo ' '._('no')." <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
309      }
310    else
311      {
312        echo "  <input type=\"hidden\" name=\"nines\" value=\"no\" />\n";
313      };
314
315   if($RULES['lowtrump']=='cancel' || $RULES['lowtrump']=='poverty')
316     {
317       if(check_low_trump($mycards))
318         {
319           if($RULES['lowtrump']=='cancel')
320             echo _('Do you want to call low trump (cancel game)?');
321           else
322             echo _('Do you want to call low trump (poverty)?');
323
324           echo ' '._('yes')."<input type=\"radio\" name=\"lowtrump\" value=\"yes\" checked=\"checked\" />";
325           echo ' '._('no')." <input type=\"radio\" name=\"lowtrump\" value=\"no\" /> <br />\n";
326         }
327       else
328         {
329           echo "  <input type=\"hidden\" name=\"lowtrump\" value=\"no\" />\n";
330         };
331     }
332   else
333     echo "  <input type=\"hidden\" name=\"lowtrump\" value=\"no\" />";
334
335    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
336    echo "<br /><input type=\"submit\" value=\""._('count me in')."\" />\n";
337
338    echo "</div>\n";
339
340   return;
341 }
342
343 function output_form_calls($me,$myparty)
344 {
345   $highstart = '  <span class="highcall">';
346   $highend   = '</span>';
347
348   $tmp = can_call(120,$me);
349   if( $tmp )
350     {
351       if($tmp==2) echo $highstart;
352       if($myparty=='re')
353         echo '  re (120):';
354       else if ($myparty=='contra')
355         echo '  contra (120):';
356       else
357         echo '  re/contra (120):';
358       echo ' <input type="radio" name="call" value="120" />';
359       if($tmp==2) echo $highend;
360       echo "\n";
361     }
362   $tmp = can_call(90,$me);
363   if( $tmp )
364     {
365       if($tmp==2) echo $highstart;
366       echo '  90:'.
367         ' <input type="radio" name="call" value="90" />';
368       if($tmp==2) echo $highend;
369       echo "\n";
370     }
371   $tmp = can_call(60,$me);
372   if( $tmp )
373     {
374       if($tmp==2) echo $highstart;
375       echo '  60:'.
376         ' <input type="radio" name="call" value="60" />';
377       if($tmp==2) echo $highend;
378       echo "\n";
379     }
380   $tmp = can_call(30,$me);
381   if( $tmp )
382     {
383       if($tmp==2) echo $highstart;
384       echo '  30:'.
385         ' <input type="radio" name="call" value="30" />';
386       if($tmp==2) echo $highend;
387       echo "\n";
388     }
389   $tmp = can_call(0,$me);
390   if( $tmp )
391     {
392       if($tmp==2) echo $highstart;
393       echo '  0:'.
394         ' <input type="radio" name="call" value="0" />';
395       if($tmp==2) echo $highend;
396       echo "\n".
397         '  no call:'.
398         ' <input type="radio" name="call" value="no" />'."\n";
399     }
400 }
401
402 function output_check_want_to_play($me)
403 {
404   echo ' <div class="joingame">';
405   echo '   '._('Do you want to play a game of DoKo?').' <br />';
406   echo '   '._('yes').'<input type="radio" name="in" value="yes" checked="checked" />';
407   echo '   '._('no').'<input type="radio" name="in" value="no" /> <br />';
408   echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
409   echo "\n";
410   echo "<input type=\"submit\" value=\""._('submit')."\" />\n";
411   echo " </div>\n";
412
413   return;
414 }
415
416 function output_header()
417 {
418    global $REV;
419 ?>
420 <!DOCTYPE html>
421 <html lang="en">
422   <head>
423      <title>e-Doko</title>
424      <meta charset="utf-8" />
425      <meta name="viewport" content="width=device-width; initial-scale=1.0;" />
426      <link id="favicon" rel="shortcut icon" href="pics/edoko-favicon.png" />
427      <link rel="stylesheet" media="all" href="<?php echo autoversion("css/bootstrap.css"); ?>" />
428      <link rel="stylesheet" href="<?php echo autoversion("css/standard.css"); ?>" />
429      <link rel="stylesheet" href="<?php echo autoversion("css/dateinput.css"); ?>"/>
430 <!--
431      <link rel="stylesheet/less" media="all" href="<?php echo autoversion("css/bootstrap.less"); ?>" />
432      <link rel="stylesheet/less" href="<?php echo autoversion("css/standard.less"); ?>" />
433      <script src="js/less.min.js" type="text/javascript"></script>
434 !-->
435   </head>
436 <body onload="high_last();">
437 <?php
438
439   echo "<div class=\"main\">";
440   return;
441 }
442
443 function output_footer()
444 {
445   global $REV, $PREF, $INDEX;
446
447   echo "</div>\n\n";
448   echo "<footer>\n";
449   echo "  <p class=\"left\"> copyright 2006-2014 <a href=\"$INDEX?action=about\">Arun Persaud, et al.</a> <br />\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><p>\n";
455   echo "</footer>\n\n";
456
457   echo '<script src="'.autoversion('js/jquery.min.js').             '"></script>';
458   echo '<script src="'.autoversion('js/jquery.tablesorter.min.js'). '"></script>';
459   echo '<script src="'.autoversion('js/jquery.tools.min.js').       '"></script>';
460   echo '<script src="'.autoversion('js/bootstrap.min.js').          '"></script>';
461   echo '<script src="'.autoversion('js/layout.js').                 '"></script>';
462   echo '<script src="'.autoversion('js/game.js').                   '"></script>';
463
464   echo "</body>\n";
465   echo "</html>\n";
466
467   return;
468 }
469
470 function output_navbar()
471 {
472   global $defaulttimezone, $INDEX, $WIKI, $RSS;
473
474   if(isset($_SESSION['name']))
475     {
476       $name  = $_SESSION['name'];
477       $email = DB_get_email('name',$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<nav class=\"navbar navbar-default navbar-fixed-top\" role=\"navigation\">\n";
493       echo "  <div class=\"container-fluid\">\n";
494       echo "    <div class=\"navbar-header\">";
495       echo "         <a href=\"".$INDEX."\">\n";
496       echo "           <img class=\"grav navbar-right\" title=\""._('last login').": ".date("r",$unixtime)."\" ";
497       echo             "src=\"http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=identicon\" /></a>\n";
498       echo '         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-elements">
499                          <span class="sr-only">Toggle navigation</span>
500                          <span class="icon-bar"></span>
501                          <span class="icon-bar"></span>
502                         <span class="icon-bar"></span>
503                      </button>';
504       echo "      <a class=\"navbar-brand\" href=\"".$INDEX."\">E-DoKo</a>\n";
505       echo "    </div>";
506       echo '    <div class="collapse navbar-collapse" id="navbar-collapse-elements">';
507       echo "      <ul class=\"nav navbar-nav\">";
508       echo "         <li> <a href=\"".$INDEX."\"><span class=\"glyphicon glyphicon-home\"></span>"._('Home')."</a></li>\n";
509       echo "         <li> <a href=\"".$INDEX."?action=prefs\"><span class=\"glyphicon glyphicon-cog\"></span>".
510         _('settings')."</a></li>\n";
511       echo "         <li> <a href=\"".$INDEX."?action=new\">"._('new game')."</a></li>\n";
512       echo "         <li> <a href=\"".$INDEX."?action=stats\">"._('statistics')."</a></li>\n";
513       echo "         <li> <a href=\"".$WIKI."\">"._('wiki/bugs')."</a></li>\n";
514       echo "         <li> <a href=\"".$RSS."?uid=".$myid."&amp;token=".$token."\">"._('atom')."</a></li>\n";
515       echo "         <li> <a href=\"".$INDEX."?action=logout\"><span class=\"glyphicon glyphicon-off\"></span>"._('logout')."</a></li>\n";
516       echo "      </ul>\n";
517       echo "    </div>\n";
518       echo "  </div>\n";
519       echo "</nav>\n";
520     }
521   return;
522 }
523
524 function output_select_timezone($name,$timezone="")
525 {
526   $Tzone = array ("Pacific/Apia"         => "Apia",                /*UTC-11*/
527                   "Pacific/Honolulu"     => "Honolulu",            /*UTC-10*/
528                   "America/Anchorage"    => "Anchorage",           /*UTC-9*/
529                   "America/Vancouver"    => "Berkeley",            /*UTC-8*/
530                   "America/Phoenix"      => "Phoenix",             /*UTC-7*/
531                   "America/Chicago"      => "Chicago",             /*UTC-6*/
532                   "America/New_York"     => "New York",            /*UTC-5*/
533                   "America/Santiago"     => "Santiago",            /*UTC-4*/
534                   "America/Buenos_Aires" => "Buenos Aires",        /*UTC-3*/
535                   "Atlantic/South_Georgia" => "Fernando de Noronha", /*UTC-2*/
536                   "Atlantic/Azores"       => "Azores",             /*UTC-1"*/
537                   "Europe/London"         => "London",             /*UTC*/
538                   "Europe/Berlin"         => "Berlin",             /*UTC+1*/
539                   "Africa/Cairo"          => "Cairo",              /*UTC+2*/
540                   "Europe/Moscow"         => "Moscow",             /*UTC+3*/
541                   "Asia/Tehran"           => "Tehran",             /*UTC+3:30*/
542                   "Asia/Dubai"            => "Dubai",              /*UTC+4*/
543                   "Asia/Karachi"          => "Karachi",            /*UTC+5*/
544                   "Asia/Calcutta"         => "Delhi",              /*UTC+5:30*/
545                   "Asia/Kathmandu"        => "Kathmandu",          /*UTC+5:45*/
546                   "Asia/Dhaka"            => "Dhaka",              /*UTC+6*/
547                   "Asia/Rangoon"          => "Yangon",             /*UTC+6:30*/
548                   "Asia/Bangkok"          => "Bangkok",            /*UTC+7*/
549                   "Asia/Hong_Kong"        => "Beijing",            /*UTC+8*/
550                   "Asia/Tokyo"            => "Tokyo",              /*UTC+9*/
551                   "Australia/Darwin"      => "Darwin",             /*UTC+9:30*/
552                   "Australia/Sydney"      => "Sydney",             /*UTC+10*/
553                   "Asia/Magadan"          => "Magadan",            /*UTC+11*/
554                   "Pacific/Auckland"      => "Wellington" );       /*UTC+12*/
555
556   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
557
558   foreach($Tzone as $zone=>$city)
559     {
560       if($timezone==$zone)
561         echo "   <option value=\"$zone\" selected=\"selected\">$city</option>\n";
562       else
563         echo "   <option value=\"$zone\">$city</option>\n";
564     }
565   echo "  </select>\n";
566
567   return;
568 }
569
570 function output_select_language($name,$language="")
571 {
572   $LOCALE = array ("English"     => "en",
573                    "Deutsch"     => "de" );
574
575   echo "  <select id=\"$name\" name=\"$name\" size=\"1\">\n";
576
577   foreach($LOCALE as $place=>$locale)
578     {
579       if($language==$locale)
580         echo "   <option value=\"$locale\" selected=\"selected\">$place</option>\n";
581       else
582         echo "   <option value=\"$locale\">$place</option>\n";
583     }
584   echo "  </select>\n";
585
586   return;
587 }
588
589
590 function output_password_recovery($email,$password)
591 {
592 ?>
593    <form action="index.php" method="post">
594 <?php
595   echo "  <input type=\"hidden\" name=\"email\" value=\"".$email."\" />\n";
596   echo "  <input type=\"hidden\" name=\"password\" value=\"".$password."\" />\n";
597   echo "  <input type=\"hidden\" name=\"passwd\"  value=\"set\" />\n";
598 ?>
599      <fieldset>
600        <legend>Password recovery</legend>
601         <table>
602          <tr>
603             <td><label for="password0">Old password:</label></td>
604             <td><input type="password" id="password0" name="password0" size="20" maxlength="30" /> </td>
605          </tr><tr>
606             <td><label for="password1">New password:</label></td>
607             <td><input type="password" id="password1" name="password1" size="20" maxlength="30" /></td>
608          </tr><tr>
609             <td><label for="password2">Retype:</label></td>
610             <td><input type="password" id="password2" name="password2" size="20" maxlength="30" /></td>
611          </tr><tr>
612            <td></td>
613            <td> <input type="submit" class="submitbutton" name="passwd" value="set" /></td>
614          </tr>
615         </table>
616      </fieldset>
617    </form>
618
619 <?php
620 }
621
622 function output_user_notes($userid,$gameid,$userstatus)
623 {
624   echo "<div class=\"notes\"> "._('Personal notes').": <br />\n";
625   $notes = DB_get_notes_by_userid_and_gameid($userid,$gameid);
626   foreach($notes as $note)
627     echo "  $note <hr />\n";
628   if($userstatus!='gameover')
629     echo "  <input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
630   echo "</div>\n\n";
631
632   return;
633 }
634
635 function output_robotproof($i)
636 {
637   switch($i)
638     {
639     case 0:
640       return "6*7=";
641     case 1:
642       return "5*7=";
643     case 2:
644       return "4*7=";
645     case 3:
646       return "3*7=";
647     case 4:
648       return "2*7=";
649     }
650 }
651
652 function output_exchanged_cards($gametype)
653 {
654   /* in a poverty game this function will output the exchanged cards
655    * players in the team will see the cards, the other team will see
656    * the backside of cards
657    */
658
659   /* need some information about the game */
660   global $gameid,$PREF,$me,$mystatus, $RULES;
661
662   /* some variables to track where the people with poverty are sitting */
663   $partnerpos1 = 0;
664   $povertypos1 = 0;
665   $partnerpos2 = 0;
666   $povertypos2 = 0;
667
668   /* only need to do it in a poverty game, this might not be needed, but
669    * just to make sure everything is ok
670    */
671   if($gametype == 'poverty' || $gametype=='dpoverty')
672     {
673       /* find out who has poverty */
674       for($mypos=1;$mypos<5;$mypos++)
675         {
676           $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
677           if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
678             if($povertypos1)
679               $povertypos2 = $mypos;
680             else
681               $povertypos1 = $mypos;
682         }
683       /* get hash and exchanged cards for all involved */
684       $povertyhash1 = DB_get_hash_from_game_and_pos($gameid,$povertypos1);
685       $partnerhash1 = DB_get_partner_hash_by_hash($povertyhash1);
686
687       $povertycards1 = DB_get_exchanged_cards($povertyhash1);
688       $partnercards1 = DB_get_exchanged_cards($partnerhash1);
689
690       $partnerpos1 = DB_get_pos_by_hash($partnerhash1);
691       if($povertypos2)
692         {
693           $povertyhash2 = DB_get_hash_from_game_and_pos($gameid,$povertypos2);
694           $partnerhash2 = DB_get_partner_hash_by_hash($povertyhash2);
695
696           $povertycards2 = DB_get_exchanged_cards($povertyhash2);
697           $partnercards2 = DB_get_exchanged_cards($partnerhash2);
698
699           $partnerpos2 = DB_get_pos_by_hash($partnerhash2);
700         }
701     }
702
703   /* output the cards
704    * go through all positions, check that position has cards that need to be shown and
705    * show those cards
706    */
707   $show=1;
708   for($mypos=1;$mypos<5;$mypos++)
709     {
710       /* output comments */
711       if($mypos==2)
712         {
713           /* display all comments on the top right (card1)*/
714           $comments = DB_get_pre_comment($gameid);
715           /* display card */
716           echo "      <div class=\"card1\">\n";
717           /* display comments */
718           foreach( $comments as $comment )
719             echo "        <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
720           echo "      </div>\n"; /* end div card */
721         }
722
723       $usersick = DB_get_sickness_by_pos_and_gameid($mypos,$gameid);
724       if($usersick!=NULL ||
725          $mypos==$povertypos1 || $mypos==$partnerpos1 ||
726          $mypos==$povertypos2 || $mypos==$partnerpos2 )
727         {
728           /* figure out if we gave trump back */
729           $trump_back1=0;
730           if($povertypos2)
731             foreach($povertycards1 as $card)
732               {
733                 if(is_trump($card))
734                   {
735                     $trump_back1=1;
736                     break;
737                   }
738               }
739           $trump_back2=0;
740           if($povertypos2)
741             foreach($povertycards2 as $card)
742               {
743                 if(is_trump($card))
744                   {
745                     $trump_back2=1;
746                     break;
747                   }
748               }
749
750           /* output vorbehalt  */
751           echo "      <div class=\"vorbehalt".($mypos-1)."\"> Vorbehalt <br />\n";
752           if($show)
753             echo "       $usersick <br />\n";
754
755           /* output cards */
756           if($mypos==$partnerpos1)
757             {
758               foreach($partnercards1 as $card)
759                 {
760                   echo '        ';
761                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
762                     display_card($card,$PREF['cardset']);
763                   else
764                     display_card(0,$PREF['cardset']);
765                 }
766               if($trump_back1) echo '        '._('Trump back');
767             }
768           else if($mypos==$povertypos1)
769             {
770               foreach($povertycards1 as $card)
771                 {
772                   echo '        ';
773                   if($povertyhash1 == $me || $partnerhash1 == $me || $mystatus=='gameover')
774                     display_card($card,$PREF['cardset']);
775                   else
776                     display_card(0,$PREF['cardset']);
777               }
778               if($trump_back1) echo '        '._('Trump back');
779             }
780           else if($mypos==$povertypos2)
781             {
782               foreach($povertycards2 as $card)
783                 {
784                   echo '        ';
785                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
786                     display_card($card,$PREF['cardset']);
787                   else
788                     display_card(0,$PREF['cardset']);
789                 }
790               if($trump_back2) echo '        '._('Trump back');
791             }
792           else if($mypos==$partnerpos2)
793             {
794               foreach($partnercards2 as $card)
795                 {
796                   if(is_trump($card)) $trump_back=1;
797                   echo '        ';
798                   if($povertyhash2 == $me || $partnerhash2 == $me || $mystatus=='gameover')
799                     display_card($card,$PREF['cardset']);
800                   else
801                     display_card(0,$PREF['cardset']);
802                 }
803               if($trump_back2) echo '        '._('Trump back');
804             }
805           echo  "      </div>\n";
806         }
807       if($gametype == $usersick)
808         $show = 0;
809     }
810 }
811
812
813 ?>