CLEANUP: make index.php very short and move everything in separate files
[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 output_status();
9
10 $me = $_REQUEST["me"];
11
12 /* test for valid ID */
13 $myid = DB_get_userid('hash',$me);
14 if(!$myid)
15   {
16     echo "Can't find you in the database, please check the url.<br />\n";
17     echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
18     output_footer();
19     DB_close();
20     exit();
21   }
22
23 DB_update_user_timestamp($myid);
24
25 /* get some information from the DB */
26 $gameid   = DB_get_gameid_by_hash($me);
27 $myname   = DB_get_name('hash',$me);
28
29 /* check if game really is old enough to be canceled */
30 $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
31 $r = mysql_fetch_array($result,MYSQL_NUM);
32 if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
33   {
34     $message = "Hello, \n\n".
35       "Game ".DB_format_gameid($gameid).
36       " has been canceled since nothing happend for a while and $myname requested it.\n";
37
38     $userids = DB_get_all_userid_by_gameid($gameid);
39     foreach($userids as $user)
40       {
41         $To = DB_get_email('userid',$user);
42         mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (timed out)",$message);
43       }
44
45     /* delete everything from the dB */
46     DB_cancel_game($me);
47
48     echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
49       " has been canceled.<br /><br /></p>";
50   }
51  else
52    echo "<p>You need to wait longer before you can cancel a game...</p>\n";
53 ?>