forked from iamcal/choose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.php
190 lines (137 loc) · 5.24 KB
/
room.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?
include('../../../includes/db.php');
db_select_db('cal_games');
if ($_POST[email]){
setcookie('email_cookie', $_POST[email], time()+(60*60*24*365));
}
include('header.txt');
#
# get the number of rooms
#
list($rooms) = db_list(db_fetch("SELECT COUNT(*) FROM choose_rooms"));
$insert = "<br /><br /><b>Rooms:</b> ".number_format($rooms);
#
# utility function
#
function get_room_depth($room_id){
if ($room_id == 1){return 1;}
list($parent_room_id) = db_list(db_fetch("SELECT id FROM choose_rooms WHERE room_1=$room_id OR room_2=$room_id"));
if ($parent_room_id){
return 1 + get_room_depth($parent_room_id);
}
return 1;
}
#
# add a new room?
#
$problems = array();
if ($_POST[addroom]){
if (!strlen(trim($_POST[email]))) $problems[] = "Please enter your email address";
if (!strlen(trim($_POST[blurb]))) $problems[] = "Please enter your part of the story";
if (!$_POST[end_here]){
if (!strlen(trim($_POST[choice1]))) $problems[] = "Please enter the first choice";
if (!strlen(trim($_POST[choice2]))) $problems[] = "Please enter the second choice";
}
if (!count($problems)){
$ret = db_insert('choose_rooms', array(
'email' => AddSlashes($_POST[email]),
'blurb' => AddSlashes($_POST[blurb]),
'text_1' => AddSlashes($_POST[choice1]),
'room_1' => 0,
'text_2' => AddSlashes($_POST[choice2]),
'room_2' => 0,
'end_here' => AddSlashes($_POST[end_here]),
'ip' => AddSlashes($_SERVER[REMOTE_ADDR]),
));
$room_id = $ret[insert_id];
$opt = intval($_POST[opt]);
$from = intval($_POST[from]);
db_update('choose_rooms', array(
"room_$opt" => $room_id,
), "id=$from AND room_$opt=0");
print "Your room has been added. <a href=\"room.php\">Click here</a> to start again.";
include('footer.txt');
exit;
}
}
#
# is this a null (insert a link here) room?
#
if ($_REQUEST[from] && !$_GET[room]){
$from_id = intval($_REQUEST[from]);
$from_room = db_single(db_fetch("SELECT * FROM choose_rooms WHERE id=$from_id"));
$depth = get_room_depth($from_id);
$opt = intval($_REQUEST[opt]);
$email_cookie = HtmlSpecialChars($_COOKIE[email_cookie]);
if (count($problems)){
echo "<div class=\"problems\">\n";
foreach ($problems as $p){
echo "» $p<br />\n";
}
echo "</div>\n";
echo "<br />\n";
}
print "<!-- $depth -->";
print "Now it's time for you to create your own adventure :)<br><br>";
print "What happens when someone chooses "".HtmlSpecialChars($from_room["text_$opt"]).""?<br/>";
echo "<br />";
print "<form method=\"post\">";
print "<input type=\"hidden\" name=\"addroom\" value=\"1\">";
print "<input type=\"hidden\" name=\"from\" value=\"$from_id\">";
print "<input type=\"hidden\" name=\"opt\" value=\"$opt\">";
print "Your email address: (it wont be shown on the site)<br><input type=\"text\" name=\"email\" size=\"50\" value=\"$email_cookie\"><br><br>";
print "Story description:<br><textarea name=\"blurb\" cols=\"50\" rows=\"10\"></textarea><br><br>";
if ($depth>19){
print "<select name=\"end_here\"><option value=\"0\">The adventure continues...</option><option value=\"1\">The adventure ends here</option></select><br><br>";
}else{
print "<input type=\"hidden\" name=\"end_here\" value=\"0\">";
}
print "Choice 1:<br><input type=\"text\" name=\"choice1\" size=\"50\"><br><br>";
print "Choice 2:<br><input type=\"text\" name=\"choice2\" size=\"50\"><br><br>";
print "<input type=\"submit\" value=\"Add My Room!\">";
include('footer.txt');
exit;
}
#
# just a regular old choice room
#
$room_id = max(intval($_GET[room]), 1);
$room = db_single(db_fetch("SELECT * FROM choose_rooms WHERE id=$room_id"));
if (!$room[id]){
print "error: room $room_id not found";
include('footer.txt');
exit;
}
$depth = get_room_depth($room_id);
echo "<!-- depth: $depth -->\n";
if ($room[id] == 1){
echo "<div class=\"warnbox\">\n";
echo "<b>Warning:</b> This game is not suitable for children. Some story choices contain language and situations that some adults may find offensive. ";
echo "This story is written by visitors to the site, and is largely unmoderated. Please do not use this in the classroom. ";
echo "</div>\n";
}
if ($room[end_here]){
print nl2br(htmlentities(chop($room[blurb])));
print "<br><br><b>It's all over.</b> Why not <a href=\"room.php\">start again</a>.";
}else{
print defaulty(nl2br(htmlentities(trim($room[blurb]))))."<br />\n";
echo "<br />\n";
echo "<b>What will you do?</b><br />\n";
echo "<div class=\"choices\">\n";
print "[1] <a href=\"room.php?room=$room[room_1]&from=$room_id&opt=1\">".defaulty(htmlentities($room[text_1]))."</a><br />\n";
print "[2] <a href=\"room.php?room=$room[room_2]&from=$room_id&opt=2\">".defaulty(htmlentities($room[text_2]))."</a><br />\n";
echo "</div>\n";
}
print "<br><br><br><br>";
echo "Something wrong with this entry? Bad spelling/grammar? Empty? Makes no sense? Then <a href=\"report.php?id=$room[id]\">report it</a>.<br />";
if ($_SERVER[PHP_AUTH_USER]){
echo "<br />";
echo "<div class=\"godbox\">You're logged in as an admin!";
echo "[<a href=\"edit.php?id=$room[id]\">edit</a>]";
echo "</div>";
}
function defaulty($x){
return strlen($x) ? $x : '<i>Blank</i>';
}
include('footer.txt');
?>