-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_notes.php
executable file
·137 lines (119 loc) · 4.5 KB
/
admin_notes.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
<?php
include_once "admin_header.php";
?>
<title>notes</title>
<?php
$msg = "";
// If upload button is clicked ...
if (isset($_POST['submit'])) {
$filename = $_FILES["notes"]["name"];
$tempname = $_FILES["notes"]["tmp_name"];
$branch = $_POST['branch'];
$semester = $_POST['semester'];
$subject = $_POST['subject'];
$folder = "assets/notes/" . $filename;
if (!$db) {
die("connection failed");
}
$msg = "connected successfully";
// Get all the submitted data from the form
$sql = "INSERT INTO notes (branch,notes ,semester,subject ) VALUES ('$branch','$filename','$semester','$subject')";
// Execute query
mysqli_query($db, $sql);
// move the uploaded image into the folder: notes
if (move_uploaded_file($tempname, $folder)) {
$msg = "notes uploaded successfully";
} else {
$msg = "Failed to upload notes";
}
}
$result = mysqli_query($db, "SELECT * FROM notes");
//delete row
if (isset($_POST['delete'])) {
$sql1 = "DELETE FROM notes WHERE id = '{$_REQUEST['id']}'";
if (mysqli_query($db, $sql1)) {
$msg = "record deleted successfully";
} else {
$msg = "Failed to delete record";
}
}
?>
<!--to avoid resubmission of form-->
<script>
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
</script>
<!-------ajax script----->
<script src="assets/js/ajax.js"></script>
<!--custom css-->
<link rel="stylesheet" type="text/css" href="assets/css/admin_notes_paper.css">
<div class="container-fluid">
<div class="row">
<!--form start-->
<div class="col-12 col-lg-3 order-lg-2">
<form class="form-container" method="post" action="admin_notes.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<!---------branch---------->
<label>select branch:</label>
<!-- branch dropdown -->
<select name="branch" id="branchSel" class="custom-select">
<option value="" selected disabled hidden>Select branch</option>
</select>
<!---------------semester----------->
<label>select semester:</label>
<!-- semester dropdown -->
<select name="semester" id="semSel" class="custom-select">
<option value="" selected disabled hidden>Please select branch first</option>
</select>
<!---------------subjects----------->
<label>select subject:</label>
<!-- subject dropdown -->
<select name="subject" id="subjectSel" class="custom-select">
<option value="" selected disabled hidden>Please select sem first</option>
</select>
<div class="form-group">
<label>Upload notes</label>
<input type="file" name="notes" class="form-control-file" required>
</div>
<div class="form-group">
<input class="form-control" type="submit" name="submit" value="submit">
</div>
</form>
</div>
<!-------------form end------------------->
<!-------------preview------------------->
<div class="col-12 col-lg-9 order-lg-1">
<div class="preview">
<?php
$sql3 = "SELECT * FROM notes ORDER BY id DESC";
$result2 = mysqli_query($db, $sql3);
echo "<div class='table-responsive' style='padding: 0px !important; height:90vh !important;'>";
echo '<table class="table table-bordered">';
echo '<thead class="thead-dark" style="position: sticky; top: 0;">';
echo '<tr>';
echo '<th scope="col">subjects</th>';
echo '<th scope="col">branch</th>';
echo '<th scope="col">semester</th>';
echo '<th scope="col">download</th>';
echo '<th scope="col">action</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
while ($row = mysqli_fetch_array($result2)) {
echo '<tr>';
echo '<td>' . $row['subject'] . '</td>';
echo '<td>' . $row['branch'] . '</td>';
echo '<td>' . $row['semester'] . '</td>';
echo '<td><a href="assets/notes/' . $row['notes'] . '" download>' . $row['notes'] . '</a></td>';
echo '<td><form action="" method="POST" class="delete"><input type="hidden" name="id" value=' . $row['id'] . '><input type="submit" name="delete" value= "Delete"></form></td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo "</div>";
?>
</div>
</div>
</div>
</div>