-
Notifications
You must be signed in to change notification settings - Fork 8
/
edit.php
146 lines (104 loc) · 3.32 KB
/
edit.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
<?php
include('config.php');
include('db.php');
#
# save changes?
#
if ($_POST['done']){
$id = intval($_POST['id']);
db_update('choose_rooms', array(
'blurb' => AddSlashes($_POST['blurb']),
'text_1' => AddSlashes($_POST['text_1']),
'text_2' => AddSlashes($_POST['text_2']),
), "id=$id");
header("location: edit.php?id=$id&done=1");
exit;
}
#
# delete room?
#
if ($_POST['delete']){
$id = intval($_POST['id']);
$room = db_single(mysql_query("SELECT * FROM choose_rooms WHERE id=$id"));
$parent = db_single(mysql_query("SELECT * FROM choose_rooms WHERE room_1=$id OR room_2=$id"));
db_write("DELETE FROM choose_rooms WHERE id=$id");
db_write("UPDATE choose_rooms SET room_1=0 WHERE room_1=$id");
db_write("UPDATE choose_rooms SET room_2=0 WHERE room_2=$id");
header("location: edit.php?id=$parent[id]");
exit;
}
#
# get info for display
#
$room_id = intval($_GET['id']);
$room = db_single(mysql_query("SELECT * FROM choose_rooms WHERE id=$room_id"));
$parent = db_single(mysql_query("SELECT * FROM choose_rooms WHERE room_1=$room_id OR room_2=$room_id"));
if (!$room['id']){
include('header.txt');
print "error: room $room_id not found";
include('footer.txt');
exit;
}
include('header.txt');
?>
<h1>Edit <a href="room.php?room=<?= $room['id'] ?>">Room <?= $room['id'] ?></a></h1>
<?php if ($parent['id']){ ?>
<p>Parent room: <a href="edit.php?id=<?= $parent['id'] ?>">room <?= $parent['id'] ?></a>.</p>
<?php } ?>
<?php if ($_GET['done']){ ?>
<div style="border: 1px solid #000000; padding: 10px; background-color: #eeeeee;">Your changes have been saved.</div>
<?php } ?>
<form action="edit.php" method="post">
<input type="hidden" name="id" value="<?= $room['id'] ?>" />
<input type="hidden" name="done" value="1" />
<br /><p>Description:<br /><textarea name="blurb" cols="50" rows="10"><?= HtmlSpecialChars($room['blurb']) ?></textarea></p>
<?php if ($room['end_here']){ ?>
<p>(stort ends here)</p>
<input type="hidden" name="text_1" value="" />
<input type="hidden" name="text_2" value="" />
<?php }else{ ?>
<p> Choice 1:
<?php if ($room['room_1']){ ?>
(to <a href="edit.php?id=<?= $room['room_1'] ?>">room <?= $room['room_1'] ?></a>)
<?php }else{ ?>
(no story written)
<?php } ?>
<br /><input type="text" name="text_1" size="50" value="<?= HtmlSpecialChars($room['text_1']) ?>" />
</p>
<p> Choice 2:
<?php if ($room['room_2']){ ?>
(to <a href="edit.php?id=<?= $room['room_2'] ?>">room <?= $room['room_2'] ?></a>)
<?php }else{ ?>
(no story written)
<?php } ?>
<br /><input type="text" name="text_2" size="50" value="<?= HtmlSpecialChars($room['text_2']) ?>" />
</p>
<?php } ?>
<p>
<input type="submit" value="Save Changes" />
</p>
</form>
<?php
if ($room['room_1'] || $room['room_2']){
?>
<p>This room can't be deleted - it has children.</p>
<?php
}else{
?>
<form action="edit.php" method="post">
<input type="hidden" name="id" value="<?= $room['id'] ?>" />
<input type="hidden" name="delete" value="1" />
<p>
<br />
<br />
<br />
<br />
<input type="submit" value="Delete This Room" style="background-color: red; color: white; font-weight: bold;" />
</p>
</form>
<?php
}
?>
<?php
include('footer.txt');
?>