-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_request.php
189 lines (143 loc) · 5.07 KB
/
delete_request.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
<?php
// $message = "";
session_start();
//
// echo "<pre>".print_r($_POST)."</pre>-----";
if ((!isset( $_SESSION['admin_del'] ))|| $_SESSION['admin_del']!="admin" ) {
// echo "delete is set";
// header("Location:./login.php");
echo "<h1> Blocked </h1>";
}
else if (isset($_POST['sub']) && isset($_POST['unit'])) {
// echo "<hr> iside delte function";
function split_with_file_name($str, &$file_name)
{
$len = strlen($str);
while ($len > 0 && $str[$len - 1] != "/") {
$file_name = $str[$len - 1] . $file_name;
$len--;
}
$len--;
return 0;
}
function split_it($string, $patt)
{
$arr = [];
$len = strlen($string);
$str = "";
$i = 0;
$j = 0;
$count = 0;
while ($i < $len) {
if ($string[$i] == $patt) {
$arr[$count++] = $str;
$str = "";
$j = 0;
} else {
$str[$j++] = $string[$i];
}
$i++;
}
if ($len > 0)
$arr[$count++] = $str;
print_r($arr);
return $arr;
}
include "password.php";
// $conn = new mysqli("localhost", "root", "", "my_db") or die("Not able to connect");
$sub = trim($_POST['sub']);
$unit = trim($_POST['unit']);
$table_name = $sub . $unit;
if (isset($_POST['cat']) && isset($_POST['delete']) && ($_POST['delete'] == "1") && isset($_POST['path_name'])) {
// echo "<br>inside delte method";
$cat = trim($_POST['cat']);
$path_name = trim($_POST['path_name']);
if ($cat != "" && $path_name != "") {
$sql = "DELETE FroM $table_name where path_name='$path_name'";
$conn->query($sql);
// echo "<br>delted--**-- path ";
//check if table is empty
// $message = $message. "<br>$sql";
$sql = "SELECT * FroM $table_name ";
// echo "<br>$sql";
$result = $conn->query($sql);
// echo "<hr> checking the table to delte ";
// echo "</pre>".print_r($result)."</pre>-----";
// echo "<br> topic delte-----------------<br>";
// echo "</pre>".print_r($result)."</pre>-----";
if ($result != "" && $result->num_rows == 0) {
$sql = "DELETE FroM topic where topic_name='$sub' AND unit='$unit' ";
$conn->query($sql);
$sql = "DROP table $table_name";
$conn->query($sql);
// echo "<br>deleting the topic name and table ";
}
if(file_exists($path_name) && (is_dir("$path_name") == false )){
// echo "<hr>delting the file ";
unlink($path_name);
}
}
///continue
}
//notes box
$sql = "SELECT * FroM $table_name where cat='note'";
// echo "<br>$sql";
$result = $conn->query($sql);
if ($result != "" && $result->num_rows > 0) {
echo ' <div class="box">
<p> Notes: </p><hr> <ol>';
while ($row = $result->fetch_assoc()) {
$temp_name = "";
split_with_file_name($row['path_name'], $temp_name);
echo "<li name='note' value='" . $row['path_name'] . "'>" . $temp_name . "</li>";
}
echo '</ol> </div>';
}
//qp box
$sql = "SELECT * FroM $table_name where cat='qp'";
// echo "<br>$sql";
$result = $conn->query($sql);
if ($result != "" && $result->num_rows > 0) {
echo ' <div class="box">
<p> Question Papers: </p> <hr><ol>';
while ($row = $result->fetch_assoc()) {
$temp_name = "";
split_with_file_name($row['path_name'], $temp_name);
echo "<li name='qp' value='" . $row['path_name'] . "'>" . $temp_name . "</li>";
}
echo '</ol> </div>';
}
//books
$sql = "SELECT * FroM $table_name where cat='book'";
// echo "<br>$sql";
$result = $conn->query($sql);
if ($result != "" && $result->num_rows > 0) {
echo ' <div class="box">
<p> Books: </p><hr> <ol>';
while ($row = $result->fetch_assoc()) {
$temp_name = "";
split_with_file_name($row['path_name'], $temp_name);
echo "<li name='book' value='" . $row['path_name'] . "'>" . $temp_name . "</li>";
}
echo '</ol> </div>';
}
//video
$sql = "SELECT * FroM $table_name where cat='vd'";
// echo "<br>$sql";
$result = $conn->query($sql);
if ($result != "" && $result->num_rows > 0) {
echo ' <div class="box">
<p> Video Lectures: </p><hr> <ol>';
while ($row = $result->fetch_assoc()) {
$temp_name = "";
split_with_file_name($row['path_name'], $temp_name);
$file_name = $temp_name;
echo "<li name='vd' value='" . $row['path_name'] . "'>" . $temp_name . "</li>";
}
echo '</ol> </div>';
}
$conn->close();
}
else{
echo "<h1> Unexpectedly Ended </h1>";
}