-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditDeal.php
503 lines (495 loc) · 15.7 KB
/
editDeal.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<?php
/**This program was written by David Brear in September of 2007
* This page is for editing vendor entries
* This page is only accessable to admins.
*/
//include the header.php which also houses the .css file
//also include the database connection, this returns an object called $connection
//include_once("include/authentication.php");
include("include/collegeconnection.php");
if(isset($_COOKIE['userid']))
{
$adminVerify = mysql_query('SELECT * FROM login WHERE id ='.$_COOKIE['userid'].';', $connection);
$adminRow = mysql_fetch_array($adminVerify, MYSQL_ASSOC);
}
else
{
$admin = false;
}
if($adminRow['admin'] == 1)
{
$admin = true;
}
else
{
$admin = false;
}
//if the cookie userid has been sent, this user is logged in and has their ID as a cookie.
if($_COOKIE['userid'])
{
//this user is logged in so get, from the database, their login information.
$data = mysql_query('SELECT * FROM login WHERE id ='.$_COOKIE['userid'].';', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC) or die('Error: Could not find that id.<br> <a href="edit.php">back</a>');
if(!$row['admin'])
{
//if this user does not have admin status kick them out.
header ("Location: schoolindex.php");
}
}
else if(isset($_COOKIE['vendorid']))
{
$placeID = $_GET['edit'];
if($placeID == $_COOKIE['vendorid'])
{
$validateVendor = mysql_query('SELECT name FROM place WHERE id='.$placeID.' AND AK = "'.$_COOKIE['A_K'].'";',$connection);
if(mysql_num_rows($validateVendor) != 1)
{
header('Location: login.php');
}
}
else
{
header('Location: vendor.php?pid='.$_COOKIE['vendorid']);
}
}
else
{
//else this user is either not logged in or does not have cookies enabled. kick them out.
header ("Location: schoolindex.php");
}
//return, from the url, if the admin wants to delete or edit an entry
if(isset($_GET['edit']))
{
$id = ($_GET['edit']); //if this is set, they want to edit an entry
}
if(isset($_GET['delete']))
{
$delete = ($_GET['delete']);//if this is set, they want to delete an entry
}
if($delete)
{
//delete the entry.
$data = mysql_query('DELETE FROM place WHERE id ='.$delete.';', $connection);
header ("Location: schoolindex.php?deleted=1");
}
if (isset($id) && !$_POST['submitted'])
{
//if they want to edit the entry and this page has not been already filled out.
$data = mysql_query('SELECT * FROM place WHERE id ='.$id.';', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC) or header('Location: login.php');
//grab all the information from the database and put it into the page variables.
$login = stripslashes($row['login']);
$password = stripslashes($row['password']);
$name = stripslashes($row['name']);
$phone = stripslashes($row['phone']);
$city = stripslashes($row['city']);
$about = stripslashes($row['about']);
$state = stripslashes($row['state']);
$category = stripslashes($row['category']);
$schoolid = stripslashes($row['schoolid']);
$address = stripslashes($row['address']);
$dealDesc = stripslashes($row['dealDesc']);
$dealURL = stripslashes($row['dealURL']);
$URL = stripslashes($row['URL']);
$AdURL = stripslashes($row['AdURL']);
$distance = stripslashes($row['distance']);
//done.
}
else if(isset($id) && $_POST['submitted'])
{
//if the person wants to edit the entry and has already submitted their modifications.
//get the modifications from the form (POSTED)
$string = '';
if(isset($_POST['name']))
{
$string = $string .'name="'.addslashes($_POST['name']).'",';
}
else
{
$string = $string .'name="",';
}
if(isset($_POST['city']))
{
$string = $string .'city="'.addslashes($_POST['city']).'",';
}
else
{
$string = $string .'city="",';
}
if(isset($_POST['state']))
{
$string = $string .'state="'.addslashes($_POST['state']).'",';
}
else
{
$string = $string .'state="",';
}
if(isset($_POST['about']) && isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
$string = $string .'about="'.addslashes($_POST['about']).'",';
}
if(isset($_POST['category']))
{
$string = $string .'category="'.addslashes($_POST['category']).'",';
}
else
{
$string = $string .'category="",';
}
if(isset($_POST['address']))
{
$string = $string .'address="'.addslashes($_POST['address']).'",';
}
else
{
$string = $string .'address="",';
}
if(isset($_POST['schoolid']) && isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
$string = $string .'schoolid='.addslashes($_POST['schoolid']).',';
}
if(isset($_POST['dealDesc']))
{
$string = $string .'dealDesc="'.addslashes($_POST['dealDesc']).'",';
}
else
{
$string = $string .'dealDesc="",';
}
if(isset($_POST['dealURL']))
{
$string = $string .'dealURL="'.addslashes($_POST['dealURL']).'",';
}
else
{
$string = $string .'dealURL="",';
}
if(isset($_POST['AdURL']))
{
$string = $string .'AdURL="'.addslashes($_POST['AdURL']).'",';
}
else
{
$string = $string .'AdUrl="",';
}
if(isset($_POST['URL']))
{
$string = $string .'URL="'.addslashes($_POST['URL']).'",';
}
else
{
$string = $string .'URL="",';
}
if(isset($_POST['distance']))
{
$string = $string .'distance="'.$_POST['distance'].'",';
}
else
{
$string = $string .'distance="0",';
}
if(isset($_POST['distance']))
{
$string = $string .'phone="'.$_POST['phone'].'"';
}
else
{
$string = $string .'phone=""';
}
//update the database entry for this entry.
mysql_query('update place set '.$string.' WHERE id='.$id.';', $connection)
or die('Error: '.mysql_error().'<br> <a href="edit.php?edit='.$id.'">back</a>');
header ("Location: vendor.php?pid=".$id);
//return that this entry was modified.
}
else if($_POST['submitted'])
{
//if this user just wants to add a new entry.
//grab the data they entered.
if($admin)
{
//insert this data into the database.
$string = '';
if (isset($_POST['login']))
{
$string = $string.'"'.addslashes($_POST['login']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['password']))
{
$string = $string.'"'.addslashes($_POST['password']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['name']))
{
$string = $string.'"'.addslashes($_POST['name']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['city']))
{
$string = $string.'"'.addslashes($_POST['city']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['state']))
{
$string = $string.'"'.addslashes($_POST['state']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['about']) && isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
$string = $string.'"'.addslashes($_POST['about']).'",';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['category']))
{
$string = $string.'"'.addslashes($_POST['category']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['address']))
{
$string = $string.'"'.addslashes($_POST['address']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['distance']))
{
$string = $string.'"'.addslashes($_POST['distance']).'", ';
}
else
{
$string = $string.'"0",';
}
if (isset($_POST['schoolid']))
{
$string = $string.''.addslashes($_POST['schoolid']).', ';
}
else
{
$string = $string.'0,';
}
if (isset($_POST['dealDesc']))
{
$string = $string.'"'.addslashes($_POST['dealDesc']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['dealURL']))
{
$string = $string.'"'.addslashes($_POST['dealURL']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['URL']))
{
$string = $string.'" '.addslashes($_POST['URL']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['AdURL']))
{
$string = $string.'" '.addslashes($_POST['AdURL']).'", ';
}
else
{
$string = $string.'"",';
}
if (isset($_POST['phone']))
{
$string = $string.'" '.addslashes($_POST['phone']).'" ';
}
else
{
$string = $string.'""';
}
mysql_query('INSERT INTO place(login, password, name, city, state, about, category, address, distance, schoolid, dealDesc,
dealURL, URL, AdURL, phone) values('.$string.');', $connection)
or die('Error342: '.mysql_error().'<br> <a href="edit.php">Back</a>');
header ("Location: schoolindex.php?added=1");
//return that the entry has successfully been added
}
}
include("include/header.php");
?>
<script type="text/javascript">
function check()
{
return window.confirm("are you sure you want to <?php if(isset($id)){print 'modify';} else {print 'add';} ?> this entry?");
}
</script>
<style type="text/css" rel="Stylesheet">
.gray
{
background-color: #AAA;
}
</style>
<body>
<div id="mainContentPart">
<div class="schoolIndexCenterbox">
<div class="top"><h1 class="title">Edit page</h1></div>
<?php if (isset($edit) && isset($_COOKIE['admin']) && isset($_COOKIE['userid'])) {print '<a href="editDeal.php?delete='.$edit.'">Delete this Entry</a>'; }?>
<div id="composebox">
<table border="1" cellpadding="1">
<form name="editForm" action="<?php $_SERVER['PHP_SELF'] ?>" onsubmit="return check();" method="post">
<?php
if($admin)
{
print '<tr><td><label for="login">Login</label></td><td><input type="text" name="login" value="'.$login.'"></td></tr>';
print '<tr class="gray"><td><label for="login">Password</label></td><td><input type="password" name="password" value="'.$password.'"></td></tr>';
}
?>
<tr><td><label for="name" class="line">Name</label></td>
<td><input type="text" name="name" value="<?php print $name?>" size="20"></td></tr>
<tr class="gray"><td><label for="phone" class="line">Phone Number</label></td>
<td><input type="text" name="phone" value="<?php print $phone?>" size="20"></td></tr>
<?php
if(isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
print'<tr><td><label for="city">City</label></td>
<td><input type="text" name="city" value="';
print $city.'" size="20"></td></tr>';
}
else
{
print'<tr><td><label for="city">City</label></td>
<td><input type="text" name="city" readonly="true" class="note" value="';
print $city.'" size="20"></td></tr>';
}
if(isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
print '<tr class="gray"><td><label for="state">State</label></td>
<td><select name="state">
<option selected="selected" name="*'.$state.'*">'.$state.'</option>
<option name="Alabama">Alabama</option>
<option name="Alaska">Alaska</option>
<option name="Arizona">Arizona</option>
<option name="Arkansas">Arkansas</option>
<option name="California">California</option>
<option name="Colorado">Colorado</option>
<option name="Connecticut">Connecticut</option>
<option name="Delaware">Delaware</option>
<option name="Florida">Florida</option>
<option name="Georgia">Georgia</option>
<option name="Hawaii">Hawaii</option>
<option name="Idaho">Idaho</option>
<option name="Illinois">Illinois</option>
<option name="Indiana">Indiana</option>
<option name="Iowa">Iowa</option>
<option name="Kansas">Kansas</option>
<option name="Kentucky">Kentucky</option>
<option name="Louisianna">Louisianna</option>
<option name="Maine">Maine</option>
<option name="Maryland">Maryland</option>
<option name="Massachusettes">Massachusettes</option>
<option name="Michigan">Michigan</option>
<option name="Minnesota">Minnesota</option>
<option name="Mississippi">Mississippi</option>
<option name="Missouri">Missouri</option>
<option name="Montana">Montana</option>
<option name="Nebraska">Nebraska</option>
<option name="Nevada">Nevada</option>
<option name="New Hampshire">New Hampshire</option>
<option name="New Jersey">New Jersey</option>
<option name="New Mexico">New Mexico</option>
<option name="New York">New York</option>
<option name="North Carolina">North Carolina</option>
<option name="North Dakota">North Dakota</option>
<option name="Ohio">Ohio</option>
<option name="Oklohoma">Oklohoma</option>
<option name="Oregon">Oregon</option>
<option name="Pennsylvania">Pennsylvania</option>
<option name="Rhode Island">Rhode Island</option>
<option name="South Carolina">South Carolina</option>
<option name="South Dakota">South Dakota</option>
<option name="Tennessee">Tennessee</option>
<option name="Texas">Texas</option>
<option name="Utah">Ohio</option>
<option name="Vermont">Vermont</option>
<option name="Virginia">Virginia</option>
<option name="Washington">Washington</option>
<option name="West Virginia">West Virginia</option>
<option name="Wisconsin">Wisconsin</option>
<option name="Wyoming">Wyoming</option>
</select></td></tr>';
}
else
{
print '<tr class="gray"><td><label for="state">State</label></td>
<td><input name="state" readonly="true" class="note" value="'.$state.'"></td></tr>';
}
if(isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
print '<tr><td><label for="about">About this Vendor:</label></td>
<td><textarea name="about" cols="50" rows="15">';
print $about.'</textarea></td></tr>';
}
else
{
print '<tr><td><label for="about">About this Vendor:</label></td>
<td><textarea name="about" cols="50" rows="15" class="note" readonly="true">';
print $about.'</textarea></td></tr>';
}
?>
<tr class="gray"><td><label for="category">Category:</label></td>
<td><input type="text" name="category" value="<?php print $category ?>" size="20"></td></tr>
<tr><td><label for="address">Address:</label></td>
<td><input type="text" name="address" value="<?php print $address ?>" size="20"></td></tr>
<tr class="gray"><td><label for="distance">Distance from campus:</label></td>
<td><input type="text" name="distance" value="<?php print $distance ?>" size="20"></td></tr>
<?php
if(isset($_COOKIE['admin']) && isset($_COOKIE['userid']))
{
print'<tr><td><label for="schoolid">School\'s ID:</label></td>
<td><input type="text" name="schoolid" value="'.$schoolid.'" size="20"></td></tr>';
}
else
{
print'<input type="hidden" name="schoolid" value="'.$schoolid.'" size="20">';
}
?>
<tr class="gray"><td><label for="dealDesc">Description of the deal(s):</label></td>
<td><textarea name="dealDesc" cols="50" rows="15"><?php print $dealDesc ?></textarea></td></tr>
<tr><td><label for="dealURL">Url of the Deal's image:</label></td>
<td><input type="text" name="dealURL" value="<?php print $dealURL ?>" size="20"></td></tr>
<tr class="gray"><td><label for="AdURL">URL of this vendor's ad:</label></td>
<td><input type="text" name="AdURL" value="<?php print $AdURL ?>" size="20"></td></tr>
<tr><td><label for="URL">Vendor's URL:</label></td>
<td><input type="text" name="URL" value="<?php print $URL ?>" size="20"></td></tr>
<tr><td colspan="100%"><input type="submit" name="submit" value="Submit">
<input type="hidden" name="submitted" value="1"></td></tr>
</form>
</table>
<a href="schoolindex.php">Back to Schools</a>
</div>
</div>
</div>
</body>
<!--this code was written by David Brear on 05/26/07 -->