/
edit_subject.php
113 lines (95 loc) · 3.21 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
<?php
require_once("../../includes/sessions.php");
require_once("../../includes/db_connect.php");
require_once("../../includes/functions.php");
require_once("../../includes/validations_functions.php");
logged_in();
find_selected_page();
if (!$current_subject) {
redirect_to("manage_content.php");
}
include("../../includes/layouts/page_header.php");
?>
<?php
if (isset($_POST['submit'])) {
$menu_name = mysqli_prep($_POST["menu_name"]);
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
$required_fields = array("menu_name","position","visible");
validate_presences($required_fields);
$field_with_max_lengths = array("menu_name" => 60);
validate_max_lengths($field_with_max_lengths);
if (empty($errors)) {
$id = $current_subject["id"];
$update_query = "UPDATE subjects SET ";
$update_query .= "subject_name = '{$menu_name}', ";
$update_query .= "position = '{$position}', ";
$update_query .= "visible = '{$visible}' ";
$update_query .= "WHERE id = {$id} " ;
$update_query .= "LIMIT 1";
$result = mysqli_query($connection,$update_query);
if($result && mysqli_affected_rows($connection) == 1) {
$_SESSION["message"] = "Subject edit success.";
redirect_to("manage_content.php?subject={$id}");
} else {
$_SESSION["message"] = "Subject creation failed.";
redirect_to("manage_content.php?subject={$id}");
}
}//if (empty($errors))
} //if (isset($_POST['submit']))
?>
<div id="main">
<div id="navigation">
<br />
<a href="admin.php">« Admin Menu</a>
<br />
<?php echo navigation($current_subject,$current_page); ?>
</div>
<div id="page">
<?php
if (!empty($errors)) {
echo form_errors($errors);
}
?>
<h2>Edit Subject : <?php echo $current_subject["subject_name"];?> </h2>
<form action="edit_subject.php?subject=<?php echo $current_subject["id"];?>" method="post">
<table border=1>
<tr>
<td>Menu Name : </td>
<td><input type = "text" size = 60 name = "menu_name" value = "<?php echo $current_subject["subject_name"]; ?>" /></td>
</tr>
<tr>
<td>Position : </td>
<td><select name = "position">
<?php
$subject_set = find_all_subjects();
$subject_count = mysqli_num_rows($subject_set);
for ($count=1; $count <= $subject_count; $count++) {
echo "<option value = \"{$count}\"";
if ($current_subject["position"] == $count) {
echo " selected";
}
echo ">{$count}</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Visible : </td>
<td><input type = "radio" name = "visible" value="1" <?php if ($current_subject["visible"] == 1) { echo " checked=\"checked\" "; } ?> /> Yes
<input type = "radio" name = "visible" value="0" <?php if ($current_subject["visible"] == 0) { echo " checked=\"checked\" "; } ?> /> No
</td>
</tr>
<tr>
<td colspan = "2" style="text-align:center;">
<input type = "submit" name = "submit" value = "Update" />
<input type = "reset" value = "Clear" />
<a class="normal" href="manage_content.php"><button type="button">Cancel</a>
</td>
</tr>
</table>
</form>
</div>
</div>
<?php include("../../includes/layouts/page_footer.php");?>