Skip to content

Commit

Permalink
Code Cleanup (Checkout select broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
natsushio committed Feb 16, 2021
1 parent 369397d commit a0226f1
Show file tree
Hide file tree
Showing 46 changed files with 581 additions and 1,232 deletions.
2 changes: 1 addition & 1 deletion .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 15 additions & 20 deletions accountVerify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
include('serverconnect.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'assets/src/Exception.php';
require 'assets/src/PHPMailer.php';
require 'assets/src/SMTP.php';
Expand All @@ -12,12 +11,12 @@
$hash = mysqli_real_escape_string($db, $_GET['hash']);
$query = "Update users set active = '1' where hash = '$hash' and active = '0'";
if ($result = mysqli_query($db, $query)){
if (mysqli_affected_rows($db) == 0){
$_SESSION['msg'] = "Account is already activated, please login with your credentials";
if (mysqli_affected_rows($db) == 0){ //Meaning active is already = 1, and the account is activated already
$_SESSION['msg'] = "Account is already activated, please login with your credentials"; //Set notification
} else{
$_SESSION['msg'] = "Account is activated, you may now login";
$_SESSION['msg'] = "Account is activated, you may now login"; //Set notification

$sql = "SELECT email FROM EqManage.users WHERE hash = ?";
$sql = "SELECT email FROM EqManage.users WHERE hash = ?"; //Prepared statement used as it handles with user database
if ($stmt = mysqli_prepare($db, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_hash);
Expand All @@ -29,30 +28,29 @@
if (mysqli_stmt_execute($stmt)) {
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)){
$email = $row['email'];
$email = $row['email']; //If email was found with specified hash, set that as an email address
}

} else {
echo "Oops! Something went wrong. Please try again later";
echo "Oops! Something went wrong. Please try again later"; //Error Message
}
mysqli_stmt_close($stmt);
}


$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '***REMOVED***'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '***REMOVED***'; // SMTP username
$mail->Password = '***REMOVED***'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = ***REMOVED***; // TCP port to connect to
// TCP port to connect to
$mail->isSMTP();
$mail->Host = '***REMOVED***';
$mail->SMTPAuth = true;// Enable SMTP authentication
$mail->Username = '***REMOVED***'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = ***REMOVED***; //TCP Port

$mail->setFrom('***REMOVED***', 'Notification System');
$mail->addAddress($email); // Add a recipient
$mail->addAddress($email); //Recipient

$mail->isHTML(true); // Set email format to HTML
$mail->isHTML(true); //Set email format to HTML

$bodyContent = '<p>You have successfully activated your account</p>';

Expand All @@ -65,9 +63,6 @@
} else {
echo 'Message has been sent';
}



};
header("Location: login.php?tab=1");
} else{
Expand Down
29 changes: 10 additions & 19 deletions adminCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,32 @@
exit();
}
if ($_SESSION['username'] != 'administrator'){
header('Location: index.php?adminonly=1');
header('Location: index.php?adminonly=1'); //Redirects to the main page if students attempts to login
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
include('serverconnect.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {//When POST request was sent

include('serverconnect.php');
$today = date('Y-m-d H:i:s');
$userID = $_POST['userID'];
$eqID = $_POST['eqID'];
$requestOption = $_POST['checkoutID'];

echo $userID;
echo $eqID;
echo $requestOption;

$getEqName = mysqli_query($db, "select * from EqManage.equipment where id = '$eqID'");
while ($row = mysqli_fetch_array($getEqName)) {
$eqName = $row['equipment'];
}
} //Get name of the equipment to send notification

$checkNotif = mysqli_query($db, "Select * from notification where message = '$eqName was successfully checked out' and target = '$userID'");
if(mysqli_num_rows($checkNotif) != null){ //Saves storage space
echo "present";
$updateNotif = "Update EqManage.notification set status = 0 where message = '$eqName was successfully checked out' and target = '$userID'";
if(mysqli_num_rows($checkNotif) != null){ //If same notification was sent before, reuse the notification, it saves storage space
$updateNotif = "Update EqManage.notification set status = 0, datetime = '$today' where message = '$eqName was successfully checked out' and target = '$userID'";
if (mysqli_query($db, $updateNotif)) {
$last_id = mysqli_insert_id($db);
echo "Notification updated. Last inserted ID is: " . $last_id;
} else {
echo "Error: " . $updateNotif . "<br>" . mysqli_error($db);
}
} else{
} else{ //If the notification was never sent before, add notification to the database
echo "empty";
$notif_query = "INSERT into EqManage.notification (message,target,status,datetime) values ('$eqName was successfully checked out' ,'$userID',0, '$today')";
if (mysqli_query($db, $notif_query)) {
Expand All @@ -48,17 +42,15 @@
}




if ($requestOption == 0) {
$getLogID = mysqli_query($db, "select * from EqManage.log where users_id = '$userID' AND checkoutDate IS NULL AND returnDate IS NULL and equipment_id = '$eqID'");
if ($requestOption == 0) {//When "check out all request" option is selected
$getLogID = mysqli_query($db, "select * from EqManage.log where users_id = '$userID' AND checkoutDate IS NULL AND returnDate IS NULL AND equipment_id = '$eqID'");
while ($row = mysqli_fetch_array($getLogID)) {
$logID = $row['id'];
}
echo "logID".$logID;
$query = "UPDATE EqManage.log set checkoutDate = '$today' where users_id = '$userID' AND checkoutDate IS NULL AND returnDate IS NULL and equipment_id = '$eqID'";
$updateEquipment = "Update EqManage.equipment set popularity = popularity + 1, lastLog_id = '$logID', users_id = '$userID' where id = '$eqID'";
} else {
} else {//When the request ID is specified
$getLogID = mysqli_query($db, "select * from EqManage.log where checkoutRequests_id = '$requestOption' and equipment_id = '$eqID'");
while ($row = mysqli_fetch_array($getLogID)) {
$logID = $row['id'];
Expand All @@ -67,7 +59,6 @@
$updateEquipment = "Update EqManage.equipment set popularity = popularity + 1, lastLog_id = '$logID', users_id = '$userID' where id = '$eqID'";
}


if (mysqli_query($db, $query)) {
echo "Successfully updated table";
} else {
Expand Down
54 changes: 5 additions & 49 deletions adminModal.php
Original file line number Diff line number Diff line change
@@ -1,102 +1,58 @@
<div id="checkoutModal" class="modal" style="display: none;">

<!-- Modal content -->
<div class="modal-content" style="width: fit-content">
<span class="close" style="margin-bottom: 10px;" data-dismiss="modal" onclick="resetCoOption();">×</span>

<div class="select-style" style="width:500px; margin: auto;" align="center">


<div id="eqselectDiv">
<?php include('fetchCheckoutEq.php') ?>
</div>





<!-- <textarea type="text" id="purpose" name="purpose" placeholder="Purpose/Location/Date to be returned" style="padding: 10px 15px; border: 1px solid #ccc;-->
<!-- border-radius: 4px; margin-top: 10px"></textarea>-->
<p> </p>


<select id="studentselect" style="width: 100%; margin-bottom: 10px">
<option value="">Student Name</option>
<?php
include('fetchName.php');

?>

</select>

<p> </p>

<select id="checkOutSelect" style="width: 100%; margin-bottom: 10px">
<option value=""></option>

<?php
include('fetchAllCheckOut.php');

include('fetchAllRq.php');
?>

</select>


<input id="checkout" name="request" type="submit" value="Confirm Checkout" style="width: 100%;" >
</div>
</div>

</div>
<div id="returnModal" class="modal" style="display: none;">

<!-- Modal content -->
<div class="modal-content" style="width: fit-content">
<span class="close" style="margin-bottom: 10px;" data-dismiss="modal" onclick="resetReturnOption();">×</span>

<div class="select-style" style="width:500px; margin: auto;" align="center">


<div id="returnEqSelectDiv">
<?php
include('fetchReturnEq.php');
?>
</div>





<!-- <textarea type="text" id="purpose" name="purpose" placeholder="Purpose/Location/Date to be returned" style="padding: 10px 15px; border: 1px solid #ccc;-->
<!-- border-radius: 4px; margin-top: 10px"></textarea>-->
<p> </p>


<select id="returnStudentSelect" style="width: 100%; margin-bottom: 10px">
<option value="">Student Name</option>
<?php
include('fetchReturnName.php');

?>

</select>

<p> </p>

<select id="returnSelect" style="width: 100%; margin-bottom: 10px">
<option value=""></option>

<?php
include('fetchReturnAllCheckout.php');

include('fetchReturnAllRq.php');
?>

</select>


<input id="return" name="request" type="submit" value="Return" style="width: 100%;" >
</div>
</div>

</div>
<!--Third party script for the 'Select' function-->
<script src="assets/js/select2.min.js"></script>
<!--Scripts only required by Admin Pages-->
<script src="assets/js/adminScript.js"></script>

3 changes: 1 addition & 2 deletions adminNavbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</div>
</li>
<li class="dropdown nav-item">
<a class="dropdown-toggle nav-link" data-toggle="dropdown" aria-expanded="false" href="#">Account</a>
<div class="dropdown-menu" role="menu" style="border-radius: 8px; margin-top:15px; margin-left: -80px">
Expand All @@ -30,7 +29,7 @@
</li>
<li class="dropdown" style="margin-left:10px" id="notif-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" onclick="load_unseen_notification('read')"><span class="badge" style="position: absolute;left: 13px;top: 2px;color: white;background: red;" id="countBadge">0</span>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" onclick="loadNotification('read')"><span class="badge" style="position: absolute;left: 13px;top: 2px;color: white;background: red;" id="countBadge">0</span>
<span class="material-icons" style="padding-top:20%">notifications</span></a>
<ul class="dropdown-menu-notif dropdown-menu" style="padding: 10px; min-width:300px;max-height: 50vh; height: auto;overflow-y: auto; border-radius: 8px; margin-top:15px" id="notif-drop"></ul>
</li>
Expand Down
36 changes: 13 additions & 23 deletions adminReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,59 @@
if ($_SESSION['username'] != 'administrator'){
header('Location: index.php?adminonly=1');
}
echo "outsidasde";
include('serverconnect.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "outside";
if (!isset($_POST['rqID'])) {
echo "mnot rQID";
$today = date('Y-m-d H:i:s');
$userID = $_POST['userID'];
$eqID = $_POST['eqID'];
$requestOption = $_POST['checkoutID'];

echo $userID;
echo $eqID;
echo $requestOption;

$QtyArray = array();
$totalReturnQty = 0;
$query = "";


if ($requestOption == 0) {
if ($requestOption == 0) {//When "All" is selected, all the request send from that user on that equipment is processed for return
$query = "UPDATE EqManage.log set returnDate = '$today' where users_id = '$userID' AND checkoutDate IS NOT NULL AND returnDate IS NULL AND equipment_id = '$eqID'";

$getCheckoutQty = mysqli_query($db, "select * from EqManage.log l left join requests r on l.checkoutRequests_id = r.id where l.users_id = '$userID' AND l.checkoutDate IS NOT NULL AND l.returnDate IS NULL AND l.equipment_id = '$eqID'");

$getCheckoutQty = mysqli_query($db, "select * from EqManage.log l left join requests r on l.checkoutRequests_id = r.id where l.users_id = '$userID' AND l.checkoutDate IS NOT NULL AND l.returnDate IS NULL
AND l.equipment_id = '$eqID'");//Get how many equipment was checked out
while ($row = mysqli_fetch_array($getCheckoutQty)) {
array_push($QtyArray, $row['checkoutQty']);
};

foreach ($QtyArray as $Qty) {
$totalReturnQty += $Qty;
$totalReturnQty += $Qty; //Get the total quantity checked out for one equipment
}
$equipmentUpdateQuery = "UPDATE EqManage.equipment set leftQuantity = leftQuantity + '$totalReturnQty' where id = '$eqID'";

$equipmentUpdateQuery = "UPDATE EqManage.equipment set leftQuantity = leftQuantity + '$totalReturnQty' where id = '$eqID'"; //Restore the quantity
} else {
$query = "UPDATE EqManage.log set returnDate = '$today' where checkoutRequests_id = '$requestOption'";
$getCheckoutQty = mysqli_query($db, "SELECT * FROM EqManage.requests where id = '$requestOption'");
while ($row = mysqli_fetch_array($getCheckoutQty)) {
$totalReturnQty = $row['checkoutQty'];
$totalReturnQty = $row['checkoutQty'];//Total quantity to be restored
}
$equipmentUpdateQuery = "UPDATE EqManage.equipment set leftQuantity = leftQuantity + '$totalReturnQty' where id = '$eqID'";
}

$updateAvailability = "Update EqManage.equipment set availability = 1 where id = '$eqID'"; //It will always be available after return



//Sending notification
$getEqName = mysqli_query($db, "select * from EqManage.equipment where id = '$eqID'");
while ($row = mysqli_fetch_array($getEqName)) {
$eqName = $row['equipment'];
}

$message = $eqName.' was successfully returned';
$checkNotif = mysqli_query($db, "Select * from notification where message = '$message' and target = '$userID'");
if(mysqli_num_rows($checkNotif) != null){
echo "present";
if(mysqli_num_rows($checkNotif) != null){//If same notification was set before, reuse it to save space and speedup query
$updateNotif = "Update EqManage.notification set status = 0 where message = '$message' and target = '$userID'";
if (mysqli_query($db, $updateNotif)) {
$last_id = mysqli_insert_id($db);
echo "Notification updated. Last inserted ID is: " . $last_id;
} else {
echo "Error: " . $updateNotif . "<br>" . mysqli_error($db);
}
} else{
echo "empty";
} else{//If notification was not set before, insert the notification into the database
$notif_query = "INSERT into EqManage.notification (message,target,status,datetime) values ('$message' ,'$userID',0, '$today')";
if (mysqli_query($db, $notif_query)) {
$last_id = mysqli_insert_id($db);
Expand All @@ -94,12 +84,13 @@
echo mysqli_error($db);
}

//Update Availability
if (mysqli_query($db, $updateAvailability)) {
echo "Successfully updated table";
} else {
echo mysqli_error($db);
}
}elseif (isset($_POST['rqID'])){
}elseif (isset($_POST['rqID'])){//If request ID is specified, return process for that particular requestID (checkoutID) will run
echo "rqID";
$checkoutRequestsID = $_POST['rqID'];
echo $checkoutRequestsID;
Expand All @@ -110,7 +101,6 @@
} else {
echo mysqli_error($db);
}
echo "hello";
$query = mysqli_query($db,"Select * from EqManage.requests where id='$checkoutRequestsID'");
while ($row = mysqli_fetch_array($query)) {
$totalReturnQty = $row['checkoutQty'];
Expand Down
Loading

0 comments on commit a0226f1

Please sign in to comment.