90b91cead33914e4accd08b868de26dd3fc64a8d
[e-DoKo.git] / index.php
1 <!DOCTYPE html PUBLIC
2     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
3     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5   <head>
6      <title>Doko via email</title>
7      <link rel="stylesheet" type="text/css" href="standard.css"/>       
8   </head>
9 <body>
10 <h1> Welcome to E-Doko </h1>
11
12 <?php
13 /* check for status file and read it, if possible */
14
15 if(file_exists("status.txt"))
16    $lines = file("status.txt");
17 else
18    die("no file");
19
20 /* check if we want to start a new game */
21 if( isset($_REQUEST["PlayerA"]) && 
22     isset($_REQUEST["PlayerB"]) && 
23     isset($_REQUEST["PlayerC"]) && 
24     isset($_REQUEST["PlayerD"]) && 
25     isset($_REQUEST["EmailA"]) && 
26     isset($_REQUEST["EmailB"]) && 
27     isset($_REQUEST["EmailC"]) && 
28     isset($_REQUEST["EmailD"]) )
29 {
30    $PlayerA = $_REQUEST["PlayerA"];
31    $PlayerB = $_REQUEST["PlayerB"];
32    $PlayerC = $_REQUEST["PlayerC"];
33    $PlayerD = $_REQUEST["PlayerD"];
34    $EmailA  = $_REQUEST["EmailA"] ;
35    $EmailB  = $_REQUEST["EmailB"] ;
36    $EmailC  = $_REQUEST["EmailC"] ;
37    $EmailD  = $_REQUEST["EmailD"] ;
38
39    /* send out email, check for error with email */
40     echo "send out emails to everyone, asking if they want to join";
41     echo "use link <br>";
42     echo "<a href=\"index.php?a=hash1\"> player 1</a> <br />";
43     echo "<a href=\"index.php?a=hash2\"> player 2</a> <br />";
44     echo "<a href=\"index.php?a=hash3\"> player 3</a> <br />";
45     echo "<a href=\"index.php?a=hash4\"> player 4</a> <br />";
46    /* read in random.txt */
47    if(file_exists("random.txt"))
48      $random = file("random.txt");
49    else
50      die("no random file");
51  
52    $randomNR = explode( ":", $random[1] );
53
54    /* write status into file */
55    $output = fopen("status.txt","w");
56    if ($output)
57    {
58      fwrite($output, "0\n");
59
60      fwrite($output, "hash1:".$PlayerA.":".$EmailA."::" );
61      for($i=0;$i<12;$i++)
62         fwrite($output,";$randomNR[$i]" );
63      fwrite($output,"\n");
64
65      fwrite($output, "hash2:$PlayerB:$EmailB::" );
66      for(;$i<24;$i++)
67         fwrite($output,";$randomNR[$i]" );
68      fwrite($output,"\n");
69
70      fwrite($output, "hash3:$PlayerC:$EmailC::" );
71      for(;$i<36;$i++)
72         fwrite($output,";$randomNR[$i]" );
73      fwrite($output,"\n");
74
75      fwrite($output, "hash4:$PlayerD:$EmailD::");
76      for(;$i<48;$i++)
77         fwrite($output,";$randomNR[$i]" );
78      fwrite($output,"\n");
79
80      fclose($output);
81    }
82    else
83     echo "can't open file for writing";
84 };
85
86 /* test if a game is running, else output everything for a new game */
87 if(sizeof($lines)<2)
88 {
89 ?>
90  <p> no game in progress, please input 4 names and email addresses </p>
91  <form action="index.php" method="post">
92    Name:  <input name="PlayerA" type="text" size="10" maxlength="20" /> 
93    Email: <input name="EmailA"  type="text" size="10" maxlength="20" /> <br />
94
95    Name:  <input name="PlayerB" type="text" size="10" maxlength="20" /> 
96    Email: <input name="EmailB"  type="text" size="10" maxlength="20" /> <br />
97
98    Name:  <input name="PlayerC" type="text" size="10" maxlength="20" /> 
99    Email: <input name="EmailC"  type="text" size="10" maxlength="20" /> <br />
100
101    Name:  <input name="PlayerD" type="text" size="10" maxlength="20" /> 
102    Email: <input name="EmailD"  type="text" size="10" maxlength="20" /> <br />
103
104    <input type="submit" value="start game" />
105  </form>
106 <?php
107 }
108 else
109 { /* load game status */
110    $tmp = explode( ":",$lines[1]);
111    $player[$tmp[0]]["name"]   = $tmp[1];
112    $player[$tmp[0]]["email"]  = $tmp[2];
113    $player[$tmp[0]]["option"] = $tmp[3];
114    $player[$tmp[0]]["cards"]  = $tmp[4];
115
116    $tmp = explode( ":",$lines[2]);
117    $player[$tmp[0]]["name"]   = $tmp[1];
118    $player[$tmp[0]]["email"]  = $tmp[2];
119    $player[$tmp[0]]["option"] = $tmp[3]; 
120    $player[$tmp[0]]["cards"]  = $tmp[4];
121
122    $tmp = explode( ":",$lines[3]);
123    $player[$tmp[0]]["name"]   = $tmp[1];
124    $player[$tmp[0]]["email"]  = $tmp[2];
125    $player[$tmp[0]]["option"] = $tmp[3];
126    $player[$tmp[0]]["cards"]  = $tmp[4];
127
128    $tmp = explode( ":",$lines[4]);
129    $player[$tmp[0]]["name"]   = $tmp[1];
130    $player[$tmp[0]]["email"]  = $tmp[2];
131    $player[$tmp[0]]["option"] = $tmp[3];
132    $player[$tmp[0]]["cards"]  = $tmp[4];
133 }
134
135 /* check if a player wants to accept a game */
136 if(isset($_REQUEST["a"]))
137 {
138    $a=$_REQUEST["a"];
139 ?>
140  <form action="index.php" method="post">
141   Do you want to play a game of DoKo?
142    yes<input type="radio" name="in" value="yes" />
143    no<input type="radio" name="in" value="no" /> <br />
144
145   Do you want to get an email for every card played or only if it your move?
146    every card<input type="radio" name="update" value="card" />
147    only on my turn<input type="radio" name="update" value="turn" /> <br />
148 <?php   
149    echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
150    echo "\n";
151    echo "<input type=\"submit\" value=\"count me in\" />\n";
152    echo " </form>\n";
153 }
154    /* yes? email him his hand, ask for solo, poverty, email every move or every card? */
155 if(isset($_REQUEST["b"]))
156 {
157    $b=$_REQUEST["b"];
158    echo "hash is $b  <br>";
159    if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
160    {
161      echo "go back to ";
162      echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
163    }
164    else
165    { /* show the hand */
166         echo $player[$b]["cards"];
167         $tmp   = $player[$b]["cards"];
168         $cards = explode( ":",$tmp);
169         echo "your cards are";
170         foreach($cards as $card) echo " $card ";
171         echo "<br />\n";   
172  ?>
173  <form action="index.php" method="post">
174    
175    do you want to play solo?
176    yes<input type="radio" name="solo" value="yes" />
177    no<input type="radio" name="solo" value="no" /> <br />
178
179    do you have a wedding?
180    yes<input type="radio" name="wedding" value="yes" />
181    no<input type="radio" name="wedding" value="no" /> <br />
182
183    do you have poverty?
184    yes<input type="radio" name="poverty" value="yes" />
185    no<input type="radio" name="poverty" value="no" /> <br />
186    
187    
188    <input type="hidden" name="c" value="$b" />
189      
190    <input type="submit" value="count me in" />
191
192  </form>
193
194 <?php
195    }
196 }      /* is this the last player that needs to accept? */
197          /* yes, figure out who starts, send out email to first player */
198    /* no, email the rest to cancel game */
199
200 /* player wants to make a move? */
201   /* check if it is this players turn it is (if it's the players turn, convert cards into links) */
202   /* if it is the last card played*/
203      /* add checkbox for who one the trick */
204      /* email next player */
205      /* last card played? */
206         /* count score for each player */
207 ?>
208
209 </body>
210 </html>