-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageoffers.php
130 lines (129 loc) · 6.24 KB
/
manageoffers.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
<?php
session_start();
if(empty($_SESSION) && !isset($_SESSION['my_uid']))
header('Location: index.php');
elseif(isset($_SESSION['my_role']) && $_SESSION['my_role'] < 2)
header('Location: home.php');
if(!empty($_GET) && isset($_GET['action']) && isset($_GET['oid'])) {
if($_GET['action'] == 'delete') {
require 'inc/connection.php';
$query = "DELETE FROM subject_offers WHERE offer_id = ".$_GET['oid']." LIMIT 1";
$result = mysqli_query($connection,$query);
if(mysqli_affected_rows($connection) > 0)
$message = "<h4 class='text-success'>Subject offer was successfully deleted.</h4>";
else
$message = "<h4 class='text-danger'>Subject offer was not successfully deleted.</h4><h5>The subject offer may still have students who enrolled in this subject offer.</h5>";
}
elseif($_GET['action'] == 'editoff') {
require 'inc/connection.php';
$query = "SELECT offer_id,subject_code,subject_desc FROM subject_offers INNER JOIN subjects ON subject_offers.subject_id=subjects.subject_id WHERE offer_id = ".$_GET['oid']." LIMIT 1";
$result = mysqli_query($connection,$query);
$edoff = mysqli_fetch_array($result);
}
}
elseif(!empty($_POST) && isset($_POST['btnAddOff'])) {
require 'inc/connection.php';
$subject = $_POST['subject'];
$sem = $_POST['sem'];
$query = "SELECT * FROM subject_offers WHERE subject_id=".$subject." AND user_id=".$_SESSION['my_uid']." AND sem_id=".$sem."";
$result = mysqli_query($connection,$query);
if(mysqli_num_rows($result) > 0)
$message = '<h4>Offer already exists in this semester.</h4>';
else {
$query = "INSERT INTO subject_offers(subject_id,user_id,offer_date,sem_id) VALUES('$subject','".$_SESSION['my_uid']."',NOW(),".$sem.")";
$result = mysqli_query($connection,$query);
if(mysqli_affected_rows($connection) > 0)
$message = '<h4 class="text-success">You have successfully added a Subject Offer.</h4>';
else
$message = '<h4 class="text-danger">There is something wrong when adding the Subject Offer.</h4><h5>Please try again adding later.</h5>';
}
}
elseif(!empty($_POST) && isset($_POST['btnEditOff'])) {
require 'inc/connection.php';
$offid = $_POST['offid'];
$sem = $_POST['sem'];
$subject = $_POST['subject'];
$query = "SELECT * FROM subject_offers WHERE subject_id=".$subject." AND user_id=".$_SESSION['my_uid']." AND sem_id=".$sem."";
$result = mysqli_query($connection,$query);
if(mysqli_num_rows($result) > 0)
$message = '<h4 class="text-danger">Offer already exists.</h4>';
else {
$query = "UPDATE subject_offers SET subject_id ='$subject', sem_id=".$sem.", offer_date=NOW() WHERE offer_id = '$offid'";
$result = mysqli_query($connection,$query);
if(mysqli_affected_rows($connection) > 0)
$message = "<h4 class='text-success'>Offer details were successfully modified.</h4>";
else
$message = "<h4 class='text-danger'>No changes were done on the Offer details.</h4>";
}
}
elseif(!empty($_GET) && isset($_GET['query'])) {
require 'inc/connection.php';
$input = strtolower($_GET['query']);
$query = "SELECT subject_offers.offer_id, subject_offers.subject_id, subjects.subject_code, subjects.subject_desc, subject_offers.offer_date FROM subject_offers INNER JOIN subjects ON subjects.subject_id = subject_offers.subject_id WHERE LOWER(CONCAT(subject_code,subject_desc)) LIKE '%".$input."%' AND user_id= ".$_SESSION['my_uid']." ORDER BY subject_code";
$offers = mysqli_query($connection,$query);
if(mysqli_num_rows($offers) > 0)
$message = "<h4 class='text-success'>Found ".mysqli_num_rows($offers)." subject offer(s).</h4>";
else
$message = "<h4 class='text-danger'>No subjects offers found.</h4>";
}
?>
<!DOCTYPE html>
<html>
<?php include 'inc/head.php'; ?>
<body>
<div class="container">
<?php include 'inc/header.php'; ?>
<article>
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Manage Subject Offers</h3>
</div>
<div class="panel-body">
<form class="form-inline" role="form" method="get" action="manageoffers.php">
<div class="btn-group">
<a class="btn btn-default btn-sm" href="home.php"><span class="glyphicon glyphicon-home"></span> Home</a>
</div>
<div class="form-group">
<input type="search" class="form-control input-sm" id="query" name="query" placeholder="Offer Search" required>
<button type="submit" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button>
</div>
</form>
<?php if(isset($message)) echo '<div class="well well-sm">'.$message.'</div>';?>
<?php
if(isset($_GET['action']) && $_GET['action'] == 'editoff')
include 'inc/editoff.php';
else
include 'inc/addoff.php';
?>
<table class="table table-responsive table-striped table-hover">
<thead>
<tr>
<th>Subject Code</th>
<th>Descriptive Title</th>
<th>Date Offered</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
if(!isset($offers)) {
require 'inc/connection.php';
$query = "SELECT offer_id,subject_offers.subject_id, offer_date,subject_code,subject_desc FROM subject_offers INNER JOIN subjects ON subject_offers.subject_id=subjects.subject_id WHERE user_id='".$_SESSION['my_uid']."'";
$offers = mysqli_query($connection,$query);
}
foreach($offers as $offer) {
echo '<tr>';
echo '<td>'.$offer['subject_code'].'</td><td>'.$offer['subject_desc'].'</td><td>'.date_format(new DateTime($sub['date_added']),'F d, Y h:i A').'</td><td><a name="btnEditOff" href="manageoffers.php?action=editoff&oid='.$offer['offer_id'].'"><span class="glyphicon glyphicon-pencil"></span></a></td><td><a name="btnDelOff" href="manageoffers.php?action=delete&oid='.$offer['offer_id'].'" onclick="if (! confirm(\'Are you sure to delete this subject offer?\')) { return false; }"><span class="glyphicon glyphicon-trash"></span></a></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</article>
<?php include 'inc/footer.php'; ?>
</div>
</body>
</html>