BUGFIX: solo statistics didn't include silent solo
[e-DoKo.git] / include / cancelgame.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 /* display the menu */
9 output_status();
10
11 /* you should only get here from a game page, so $me should be set */
12 if(!myisset("me"))
13   {
14     echo "Hmm, you really shouldn't mess with the urls.<br />\n";
15     return;
16   }
17
18 $me = $_REQUEST["me"];
19
20 /* test for valid ID */
21 $myid = DB_get_userid('hash',$me);
22 if(!$myid)
23   {
24     echo "Can't find you in the database, please check the url.<br />\n";
25     echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
26     return;
27   }
28
29 DB_update_user_timestamp($myid);
30
31 /* get some information from the DB */
32 $gameid   = DB_get_gameid_by_hash($me);
33 $myname   = DB_get_name('hash',$me);
34
35 /* check if game really is old enough to be canceled */
36 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
37 if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
38   {
39     $message = "Hello, \n\n".
40       "Game ".DB_format_gameid($gameid).
41       " has been canceled since nothing happend for a while and $myname requested it.\n";
42
43     /* email to all players */
44     $userids = DB_get_all_userid_by_gameid($gameid);
45     foreach($userids as $user)
46       {
47         $To = DB_get_email('userid',$user);
48         mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (timed out)",$message);
49       }
50
51     /* delete everything from the dB */
52     DB_cancel_game($me);
53
54     echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
55       " has been canceled.<br /><br /></p>";
56   }
57  else /* game can't be canceled yet */
58    echo "<p>You need to wait longer before you can cancel a game...</p>\n";
59 ?>