Repository navigation
Expand file tree
/
Copy patheditimg.php
More file actions
247 lines (233 loc) · 9.17 KB
/
Copy patheditimg.php
File metadata and controls
247 lines (233 loc) · 9.17 KB
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
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--- header and style definitions -->
<head>
<title>Edit Image - ThatShouldBeAComic.com</title>
<!--[if lt IE 9]>
<script src="http://www.dreamreign.com/include/excanvas.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="thatshouldbeacomic.css" />
<link type="text/css" href="jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
<?php
require_once 'config.php';
$email = $_SESSION['email'];
$curimage=$_GET['image'];
if (!$curimage)
{
$_SESSION['lastPage'] = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
else
{
$_SESSION['lastPage'] = $GLOBALS['FQP'] . "/editimg.php?image=$curimage";
}
?>
<script src="getimage.php?image=<?php echo $curimage ?>"></script>
</head>
<!--- Content-->
<body>
<a href="index.php">
<img src="tsbacbanner.png" style="margin-left:10%; margin-right:10%; width:80%; opacity:.8;" />
</a>
<div align="center">
<?php require($DOCUMENT_ROOT . "mainmenu.html"); ?>
<br />
<!------Comic Viewer------------>
<a class="comicview" href="#">
<canvas id="canvas" name="canvas"></canvas>
<span>
<!-- *** Code to show box when hover -->
<div align="center">
<table id="infobox" class="imgdesc">
<tr> <td><span id="filedesc"></span> </tr> </td>
</table>
</div>
</span>
</a>
<!----------------------------->
<?php require($DOCUMENT_ROOT . "rotatemenu.html"); ?>
</div>
<p class="clear">
<script type="text/javascript" src="phpget.js"></script>
<script type="text/javascript" src="cview.js"></script>
<script type="text/javascript">
window.onload=function(){
init(0);
}
</script>
</p>
<?php
$displayName= $_SESSION['displayName'];
$submit = $_POST['submit'];
if ($submit)
$dbemail = strip_tags($_POST['Email']);
if (isset($curimage))
{
$toSend = "SELECT `Name`, `Desc`, `Date` FROM `Images` WHERE `ImgID` = :curimage AND `Email` = :email;";
try {
$connect = connect_tsbac();
$stmt = $connect->prepare($toSend, $GLOBALS['PDO_ATTRIBS']);
$stmt->execute(array(':curimage'=>$curimage, ':email'=>$email))
or errormail($email,"Failed to execute query. editimg.php","edit image failed, image query failed!","image not found");
$connect=null; // disconnect
} catch (PDOException $e) {
errormail($email, $e->getMessage(), $message, $e->getMessage());
}
$rowCt = $stmt->rowCount();
if ($rowCt == 0)
die("\nImage Not Found? Are you sure you're logged in?");
else {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$dbname = $row['Name'];
$dbdesc = $row['Desc'];
$dbdate = $row['Date'];
}
}
$date = strtotime(strip_tags($_POST['date']));
$imageName = strip_tags($_POST['imageName']);
$desc = strip_tags($_POST['desc']);
$userlevel = $_SESSION['userlevel'];
$goBack = $_SESSION['lastPage'];
$target_path = $_SESSION['UploadPath'];
if (substr($target_path,0,1)=="/")
{ $target_path = substr($target_path,1,strlen($target_path)-1); }
if (substr($target_path,strlen($target_path)-2,1)!='/')
{ $target_path.= '/'; }
if (isset($_FILES['uploadedfile'])) {
$file_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$uploadNeeded = true;
} else {
$uploadNeeded = false;
}
if ($submit)
{
if ($email&& $curimage && ($userlevel>=50) && ($uploadNeeded))
{
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $file_path)) {
echo "<br />The file ". basename($_FILES['uploadedfile']['name'])
. " has been uploaded";
$fileName = $_FILES['uploadedfile']['name'];
$connect = connect_tsbac();
if ($date) {
$toSend = "Update `Images` "
." Set `Filename`= :fileName, `Name`=:imageName, `Date`=FROM_UNIXTIME(:date), "
." `Desc` = :desc "
." WHERE `ImgID` = :curimage ";
} else {
$toSend = "Update `Images` "
." Set `Filename`=:fileName, `Name`=:imageName, "
." `Desc` = :desc "
." WHERE `ImgID` = :curimage ";
}
//dbug helper:
$message= "fileName: $fileName \n target_path: $target_path \n imageName: $imageName \n submit: $submit \n email: $email";
$message.= "\n desc: $desc \n Date: $date \n GoBack: $goBack \n Sending: \n $toSend";
try {
$stmt = $connect->prepare($toSend, $GLOBALS['PDO_ATTRIBS']);
$stmt->bindValue(":fileName", $fileName, PDO::PARAM_STR);
$stmt->bindValue(":imageName", $imageName, PDO::PARAM_STR);
if ($date) $stmt->bindValue(":date", $date, PDO::PARAM_INT);
$stmt->bindValue(":desc", $desc, PDO::PARAM_STR);
$stmt->bindValue(":curimage", $curimage, PDO::PARAM_STR);
$stmt->execute()
or errormail($email, $message,"edit image failed, image query failed!","image not found");
$connect=null; // disconnect
} catch (PDOException $e) {
errormail($email, $message, $e->getMessage(), "Image could not be updated.");
}
echo "<br /><a href=$goBack>Go back</a>";
} else {
//dbug helper:
$message= "The file " . $_FILES['uploadedfile']['tmp_name'] . " could not be uploaded to $target_path " . basename( $_FILES['uploadedfile']['name']);
$usermsg = $message;
$message.= "fileName: $fileName \n target_path: $target_path \n imageName: $imageName \n submit: $submit \n email: $email";
$message.= "\n desc: $desc \n Date: $date \n GoBack: $goBack";
errormail($email,$message,"move failed", $usermsg);
}
} else if ($curimage && $email && ($userlevel>=50)) {
$connect = connect_tsbac();
if ($date) {
$toSend = "Update `Images` "
." Set `Name`=:imageName, `Date`=FROM_UNIXTIME(:date), "
." `Desc` = :desc "
." WHERE `ImgID` = :curimage ";
} else {
$toSend = "Update `Images` "
." Set `Name`=:imageName, "
." `Desc` = :desc "
." WHERE `ImgID` = :curimage ";
}
//dbug helper:
$message= "fileName: $fileName \n target_path: $target_path \n imageName: $imageName \n submit: $submit \n email: $email";
$message.= "\n desc: $desc \n Date: $date \n GoBack: $goBack \n Sending: \n $toSend";
try {
$stmt = $connect->prepare($toSend, $GLOBALS['PDO_ATTRIBS']);
$stmt->bindValue(":imageName", $imageName, PDO::PARAM_STR);
if ($date) $stmt->bindValue(":date", $date, PDO::PARAM_INT);
$stmt->bindValue(":desc", $desc, PDO::PARAM_STR);
$stmt->bindValue(":curimage", $curimage, PDO::PARAM_STR);
$stmt->execute()
or errormail($email, $message,"edit image failed, image query failed!","image not found");
$connect=null; // disconnect
} catch (PDOException $e) {
errormail($email, $message, $e->getMessage(), "Image could not be updated.");
}
echo "<br /><a href=$goBack>Go back</a>";
}
else if ($userlevel < 50)
{
errormail($email,"email: $email \n userlevel $userlevel", "insufficient user priveleges", "Permission Denied. You have insufficient priveleges");
}
else if (empty($email))
{
errormail("Not logged in (no user)","$message","email: $email \n Go back: $goBack","probably didn't login","Are you sure you logged in? <a href=$goBack>Go back</a>");
}
else
errormail("Blank field detected!","$message","email: $email", "I'm not sure what you just did, try again? <a href=$goBack>Go back</a>") ;
}
?>
<form enctype="multipart/form-data" action="editimg.php?image=<?php if ($curimage) echo $curimage ?>" method="POST">
<table>
<tr>
<input type='hidden' name='Email' <?php if ($dbemail) echo "value='$dbemail'";?>></input><?php if ($dbemail) echo "$dbemail";?>
<td>If new, choose a file to upload:</td>
<td><input name="uploadedfile" type="file" /></td>
</tr>
<tr>
<td>Date Override:</td>
<td><input name="date" id="date" type="text" <?php if ($dbdate) echo 'value="' . htmlspecialchars($dbdate) . '"'; ?> />
</tr>
<tr>
<td>Name:</td>
<td><input name="imageName" type="text" <?php if ($dbname) echo 'value="' . htmlspecialchars($dbname) . '"'; ?> />
</tr>
<tr>
<td>Description:</td>
<td><input name="desc" type="text" <?php if ($dbdesc) echo 'value="' . htmlspecialchars($dbdesc) . '"'; ?> />
</tr>
<tr>
<td></td><td><input type="submit" name="submit" id="submit" value="Save Changes" /></td>
</tr>
</table>
</form>
<script>
$(function() {
$( "#date" ).datepicker({ dateFormat: 'yy-mm-dd' });;
});
$.datepicker.setDefaults({
showOn: 'both',
buttonImageOnly: true,
buttonImage: 'jquery/images/calendar.gif',
changeYear: true,
yearRange: 'c-10:+0',
buttonText: 'Calendar' });
</script>
<br>
<br>
<br>
<br>
</body>
</html>