-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_subject.php
119 lines (109 loc) · 4.16 KB
/
edit_subject.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
<?php require_once("includes/sessions.php"); ?>
<?php
if (!isset($_SESSION['username'])) {
header("Location: index.php");
exit;
}
?>
<?php require_once("includes/dbconnection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
if (intval($_GET['subj']) == 0) {
//redirect
redirect_to("content.php");
}
if (isset($_POST['submit'])) {
$errors = array();
//FORM VALIDATION //,'visible'
$required_fields = array('menu_name','position');
foreach($required_fields as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_int($_POST[$fieldname]))) {
$errors[] = $fieldname;
}
}
$fields_with_lengths = array('menu_name' => 30);
foreach($fields_with_lengths as $fieldname => $maxlength ) {
if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) {
$errors[] = $fieldname;
}
}
if (empty($errors)) {
//PERFORM UPDATE
$id = mysql_prep($_GET['subj']);
$menu_name = mysql_prep($_POST['menu_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$query = "UPDATE subjects SET menu_name = '$menu_name', position = '$position', visible = '$visible' WHERE id = '$id' ";
$result = mysql_query($query, $dbconnect);
if (mysql_affected_rows() == 1) {
//Success
$message = "The subject was successfully updated.";
} else {
//Failed
$message = "The subject update failed.";
$message .= "<br />". mysql_error();
}
} else {
//Errors Occured
if (count($errors) > 1) {
$message = "There were " . count($errors) . " errors in the form.";
} else {
$message = "There was " . count($errors) . " error in the form.";
}
}
} //END OF ISSET POST
?>
<?php find_selected_page(); ?>
<?php require_once("includes/top.php"); ?>
<div id="contentLoad">
<h2>Edit Subject: <?php echo $sel_subject['menu_name']; ?></h2>
<?php
if (!empty($message)) {
echo "<p class=\"message\">" . $message . "</p>";
}
?>
<form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" method="post">
<p>Subject name:
<input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
</p>
<p>Position:
<select name="position">
<?php
$subject_set = get_all_subjects();
$subject_count = mysql_num_rows($subject_set);
for($count=1; $count <= $subject_count+1; $count++) {
echo "<option value=\"{$count}\"";
if ($sel_subject['position'] == $count) {
echo " selected";
}
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0"<?php if ($sel_subject['visible'] == 0) { echo " checked"; } ?> /> No
<input type="radio" name="visible" value="1"<?php if ($sel_subject['visible'] == 1) { echo " checked"; } ?>/> Yes
</p>
<input type="submit" name="submit" value="Edit Subject" />
<a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Delete Subject, are you sure?');">Delete Subject</a> <a href="content.php">Cancel Editing</a>
</form>
<p><hr />
<a href="new_page.php?subj=<?php echo urlencode($sel_subject['id']); ?>">+ Add a new page to <?php echo $sel_subject['menu_name']; ?>.</a>
<br />
<br />
</p>
</div> <!--ENDS CONTENTLOAD-->
</div> <!--ENDS CONTENT_MAIN-->
<div id="content_sub">
<?php echo navigation($sel_subject, $sel_page); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
<br />
<a href="staff.php">Back to Main Menu</a>
<br />
<a href="logout.php">Logout</a>
</div> <!--ENDS CONTENT_SUB-->
<?php require_once("includes/site_info.php"); ?>