forked from GeekHaven/Leave-Application-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin-dashboard-fetch.php
57 lines (46 loc) · 1.63 KB
/
admin-dashboard-fetch.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
<?php
session_start();
require 'db.php' ;
//logic for checking admin
if(isset($_POST['method']) === true && empty($_POST['method']) === false) {
if($method === 'getApps') {
if(/*!admin*/) {
} else {
try {
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $connection->prepare('SELECT * FROM application WHERE branch = :branch');
$stmt->execute(['email' => $_SESSION['branch']]);
$applications = $stmt->fetch(PDO::FETCH_ASSOC);
if($applications == Null){
echo '<script language="javascript">alert("No applications currently")</script>';
echo 'No applications currently';
}
else{
// json_endcode(data)
// echo(json_encode)
// use jquery to get response in frondhend and loop json data to show in dashboard
$apps = [];
foreach ($applications as $app) {
$apps[] = $app;
}
echo json_encode($apps);
/**Jquery to use in fronthend**/
/*
$(document).ready(function(){
$.ajax({
url: 'admin-dashboard-fetch.php',
type: 'post',
data: {method: 'getApps'},
success: function(data) {
// check for no application
// if data == 'No applications currently' else //logic ends
// showdirectly
}
})
});
*/
}
}
}
}
}