-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlog_entry_edit.php
297 lines (246 loc) · 11.7 KB
/
vlog_entry_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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
define('INCLUDE_PATH', 'include/');
require(INCLUDE_PATH.'vitals.inc.php');
require(INCLUDE_PATH.'lib/vlogs.inc.php');
$entry_id = intval($_REQUEST['e']);
$vlog_id = intval($_REQUEST['v']);
$area = $_POST['area'];
if (isset($_POST['cancel'])) {
header('Location: vlog_entry_view.php?v='.$vlog_id.'&e='.$entry_id);
exit;
} else if (($_POST['v'] && $_POST['e']) || $_GET['processed']) {
//check if there are any upload errors
if(empty($_POST)) {
$_SESSION['errors'][] = "General error. Your URL is incorrect or you are trying to post a file that is too large for this installation.";
require(INCLUDE_PATH.'header.inc.php');
require(INCLUDE_PATH.'footer.inc.php');
exit;
}
check_uploads();
if (!isset($_SESSION['errors'])) {
if ($area=="subject") {
//error check subject
if (empty($_POST['subject']) || (empty($_FILES['isub-file']['tmp_name']) && empty($_FILES['vsub-file']['tmp_name']) && empty($_POST['sub-text'])) ) {
$_SESSION['errors'][] = 'Subject empty.';
} else if ($_POST['subject'] == "image") {
$ext = explode('.', $_FILES['isub-file']['name']);
$ext = $ext[1];
if (!in_array($ext, $filetypes_image)) {
$_SESSION['errors'][] = 'You have chosen to use an image file for your subject - invalid file format.'. $ext;
}
} else if ($_POST['subject'] == "video") {
$ext = explode('.', $_FILES['vsub-file']['name']);
$ext = $ext[1];
if (!in_array($ext, $filetypes_video)) {
$_SESSION['errors'][] = 'You have chosen a video file for your subject - invalid file format.';
}
} else if ( ($_POST['subject'] == "text") && empty($_POST['sub-text']) ) {
$_SESSION['errors'][] = 'You have chosen text for your subject - message cannot be empty.';
}
}
//error check message
$ext = strtolower(end(explode('.',$_FILES['sl2msg-file']['name'])));
if ($area=="message") {
if (empty($_POST['message']) || ( (empty($_FILES['sl1msg-file']['tmp_name']) && empty($_FILES['sl2msg-file']['tmp_name'])) && empty($_FILES['vmsg-file']['tmp_name']) && empty($_POST['msg-text'])) ) {
$_SESSION['errors'][] = 'Message empty.';
} else if ($_POST['message'] == "signlink" && ( empty($_FILES['sl1msg-file']['tmp_name']) || empty($_FILES['sl2msg-file']['tmp_name']) || $ext!="mp4") ) {
$_SESSION['errors'][] = 'You have chosen to post a Signlink message - this requires that you submit two files: a flash file and a .mp4 file.';
} else if ($_POST['message'] == "video") {
$ext = end(explode('.', $_FILES['vmsg-file']['name']));
if (!in_array($ext, $filetypes_video)) {
$_SESSION['errors'][] = 'You have chosen to post a video message - invalid file format.';
}
} else if ( $_POST['message'] == "text" && empty($_POST['msg-text']) ) {
$_SESSION['errors'][] = 'You have chosen to post a text message - message cannot be empty.';
}
}
}
if (!isset($_SESSION['errors'])) {
$now = date('Y-m-d G:i:s');
if ($area=="subject") {
//prepare to insert into db
switch ($_POST['subject']) {
case 'image':
$subject = '';
$subject_alt = $addslashes(htmlspecialchars($_POST['isub-alt']));
break;
case 'video':
$subject = '';
$subject_alt = $addslashes(htmlspecialchars($_POST['vsub-alt']));
break;
case 'text':
$subject = $addslashes(htmlspecialchars($_POST['sub-text']));
$subject_alt = '';
break;
}
$sql = "UPDATE vlogs_entries SET title='$subject', title_alt='$subject_alt' WHERE vlog_id=$vlog_id AND entry_id=$entry_id";
}
if ($area=="message") {
switch ($_POST['message']) {
case 'signlink':
$message = '';
$message_alt = '';
break;
case 'video':
$message = '';
$message_alt = $addslashes(htmlspecialchars($_POST['vmsg-alt']));
break;
case 'text':
$message = $addslashes(htmlspecialchars($_POST['msg-text']));
$message_alt = '';
break;
}
$sql = "UPDATE vlogs_entries SET content='$message', content_alt='$message_alt' WHERE vlog_id=$vlog_id AND entry_id=$entry_id";
}
if (!$result = mysql_query($sql, $db)) {
$_SESSION['errors'][] = 'Database error.';
} else {
//delete old files, save new
if ($area=="subject") {
delete_files('entries', $entry_id, 'title');
switch ($_POST['subject']) {
case 'image':
if (is_uploaded_file($_FILES['isub-file']['tmp_name'])) {
save_image('entry', 'title', 'isub-file', $entry_id);
}
break;
case 'video':
if (is_uploaded_file($_FILES['vsub-file']['tmp_name'])) {
save_video('entry', 'title', 'vsub-file', $entry_id);
}
break;
}
}
if ($area=="message") {
delete_files('entries', $entry_id);
switch ($_POST['message']) {
case 'signlink':
if (is_uploaded_file($_FILES['sl1msg-file']['tmp_name']) && is_uploaded_file($_FILES['sl2msg-file']['tmp_name'])) {
save_signlink('entry', 'message', 'sl1msg-file', $entry_id);
save_signlink('entry', 'message2', 'sl2msg-file', $entry_id);
}
break;
case 'video':
if (is_uploaded_file($_FILES['vmsg-file']['tmp_name'])) {
save_video('entry', 'message', 'vmsg-file', $entry_id);
}
break;
}
}
$_SESSION['feedback'][] = 'Entry edited successfully.';
}
}
}
$title = get_title('entry', $entry_id);
$sql = "SELECT * FROM vlogs_entries WHERE vlog_id=$vlog_id AND entry_id=$entry_id";
if (!$result = mysql_query($sql, $db)) {
$_SESSION['errors'][] = 'Database error.';
} else {
$row = mysql_fetch_assoc($result);
}
//check if user has logged in and can post
if (!$_SESSION['valid_user']) {
$_SESSION['errors'][] = 'You must be logged in to write an entry. Please <a href="login.php?v='.intval($_REQUEST['v']).'">login</a>.';
require(INCLUDE_PATH.'header.inc.php');
require(INCLUDE_PATH.'footer.inc.php');
exit;
}
//check if user owns this vlog
if ($_SESSION['member_id'] != get_vlog_owner($vlog_id)) {
$_SESSION['errors'][] = "You don't have permission to edit this post.";
require(INCLUDE_PATH.'header.inc.php');
require(INCLUDE_PATH.'footer.inc.php');
exit;
}
require(INCLUDE_PATH.'header.inc.php');
echo '<h3>Edit Entry</h3>';
?>
<script type="text/javascript" src="jscripts/forum_post.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#edit-subject-form").hide();
$("#edit-message-form").hide();
$("#edit-subject").click(
function() {
$("#edit-subject-form").toggle();
});
$("#edit-message").click(
function() {
$("#edit-message-form").toggle();
});
});
</script>
<div class="file-info">
<span class="bold">Title</span><br />
<p>If you would like to change the subject of your post, choose "Edit Subject", enter the appropriate information, and use the Submit button.</p>
<?php echo $title; ?> (<span id="edit-subject" style="color:#11568B;cursor:pointer;">Edit Title</span>)
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?processed=1" method="post" name="form_sub" id="form_sub" enctype="multipart/form-data" style="clear:both; padding-top:2px;">
<input type="hidden" name="v" value="<?php echo $vlog_id; ?>" />
<input type="hidden" name="e" value="<?php echo $entry_id; ?>" />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_UPLOAD_SIZE; ?>" />
<input type="hidden" name="area" value="subject" />
<div class="choice" id="edit-subject-form">
<p>Choose what kind of subject you would like your post to have (image, video, or plain text) then provide the appropriate details.</p>
<label><input type="radio" name="subject" value="image" <?php if($_POST['subject'] == "image") { echo 'checked="checked"'; }?> />Image</label>
<div class="choice-info" id="subject-image">
<dl class="col-list">
<dt>File</dt> <dd><input type="file" id="isub-file" name="isub-file" /></dd>
<dt>Alt Text<dt> <dd><input type="text" id="isub-alt" name="isub-alt" size="80" value="<?php echo $_POST['isub-alt']; ?>" /></dd>
</dl>
</div><br />
<label><input type="radio" name="subject" value="video" <?php if($_POST['subject'] == "video") { echo 'checked="checked"'; }?> /> Video</label>
<div class="choice-info" id="subject-video">
<dl class="col-list">
<dt>File</dt> <dd><input type="file" id="vsub-file" name="vsub-file" /></dd>
<dt>Alt Text<dt> <dd><input type="text" id="vsub-alt" name="vsub-alt" size="80" value="<?php echo $_POST['vsub-alt']; ?>" /></dd>
</dl>
</div><br />
<label><input type="radio" name="subject" value="text" <?php if($_POST['subject'] == "text") { echo 'checked="checked"'; }?> /> Text</label>
<div class="choice-info" id="subject-text">
<input type="text" id="sub-text" name="sub-text" size="85" value="<?php echo $_POST['sub-text']; ?>" />
</div>
<div class="row" style="text-align:right;">
<input type="button" onclick="validateOnSubmit('subject')" name="submit_form" id="submit_sub_form" value="Submit">
</div>
</form>
</div>
</div>
<div class="important-info">
<span class="bold">Content</span><br />
<p>If you would like to edit your entry's content, choose "Edit Content", enter the appropriate information, and use the Submit button.</p>
<?php echo get_vlog_message($row['content'], $row['content_alt'], 'entries', $entry_id); ?> (<span id="edit-message" style="color:#11568B;cursor:pointer;">Edit Content</span>)
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?processed=1" method="post" name="form_msg" id="form_msg" enctype="multipart/form-data" style="clear:both; padding-top:2px;">
<input type="hidden" name="v" value="<?php echo $vlog_id; ?>" />
<input type="hidden" name="e" value="<?php echo $entry_id; ?>" />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_UPLOAD_SIZE; ?>" />
<input type="hidden" name="area" value="message" />
<div class="choice" id="edit-message-form">
<p>Choose what kind of message you are posting (signlink object, video, or plain text) then provide the appropriate details.</p>
<label><input type="radio" name="message" value="signlink" <?php if($_POST['message'] == "signlink") { echo 'checked="checked"'; }?> />Signlink Object</label>
<div class="choice-info" id="message-sl">
<dl class="col-list">
<dt>SWF File</dt> <dd><input type="file" id="sl1msg-file" name="sl1msg-file" /></dd>
<dt>MP4 File<dt> <dd><input type="file" id="sl2msg-file" name="sl2msg-file" /></dd>
</dl>
</div><br />
<label><input type="radio" name="message" value="video" <?php if($_POST['message'] == "video") { echo 'checked="checked"'; }?> /> Video</label>
<div class="choice-info" id="message-video">
<dl class="col-list">
<dt>File</dt> <dd><input type="file" id="vmsg-file" name="vmsg-file" /></dd>
<dt>Alt Text<dt> <dd><input type="text" id="vmsg-alt" name="vmsg-alt" value="<?php echo $_POST['vmsg-alt']; ?>" /></dd>
</dl>
</div><br />
<label><input type="radio" name="message" value="text" <?php if($_POST['message'] == "text") { echo 'checked="checked"'; }?> /> Text</label>
<div class="choice-info" id="message-text">
<textarea id="msg-text" id="msg-text" name="msg-text" rows="25" cols="90" style="height:20em;"><?php echo $_POST['msg-text']; ?></textarea>
</div>
<div class="row" style="text-align:right;">
<input type="button" onclick="validateOnSubmit('message')" name="submit_form" value="Submit">
</div>
</div>
</div>
<div class="row" style="padding-top:10px;text-align:right;">
<input type="submit" name="cancel" value="Finished" />
</div>
</form>
<?php require(INCLUDE_PATH.'footer.inc.php'); ?>