Compare commits

..

2 Commits

Author SHA1 Message Date
9c77d8ffb0 Show/hide journal 2025-03-14 08:35:14 +00:00
426c5092ba Journal display 2025-03-13 18:11:19 +00:00
2 changed files with 82 additions and 28 deletions

View File

@@ -1,4 +1,3 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -80,16 +79,12 @@
.editable:hover { .editable:hover {
background:rgb(226, 43, 43); background:rgb(226, 43, 43);
} }
</style> </style>
</head> </head>
<body> <body>
<script> <script>
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
let id = "<?php echo $_GET['id'];?>"; let id = "<?php echo $_GET['id'];?>";
@@ -227,17 +222,42 @@ function opDetail() {
echo "<p><strong>Outbound To:</strong><span class=\"editable\" data-column=\"out_to\" contenteditable=\"true\">" . $row['out_to'] . "</p>"; echo "<p><strong>Outbound To:</strong><span class=\"editable\" data-column=\"out_to\" contenteditable=\"true\">" . $row['out_to'] . "</p>";
echo "<p><strong>ETD:</strong><span class=\"editable\" data-column=\"etd\" contenteditable=\"true\">" . $row['etd'] . "</p>"; echo "<p><strong>ETD:</strong><span class=\"editable\" data-column=\"etd\" contenteditable=\"true\">" . $row['etd'] . "</p>";
echo "<p><strong>Email Address:</strong> " . $row['email'] . "</p>"; echo "<p><strong>Email Address:</strong> " . $row['email'] . "</p>";
echo "<p><strong>Phone:</strong> " . $row['phone'] . "</p>"; echo "<p><strong>Phone:</strong> " . $row['phone'] . "</p>";
echo "<p><strong>Notes:</strong> " . $row['notes'] . "</p>"; echo "<p><strong>Notes:</strong> " . $row['notes'] . "</p>";
echo "<p><i>PPR created at:</strong> " . $row['submitted_dt'] . " by " . $row['created_by'] . "</p></div>"; echo "<p><i>PPR created at:</strong> " . $row['submitted_dt'] . " by " . $row['created_by'] . "</p></div>";
// Fetch journal entries
$journalSql = "SELECT * FROM journal WHERE ppr_id = " . $_GET['id'];
$journalResult = $conn->query($journalSql);
$journalCount = $journalResult->num_rows;
// Add button to toggle journal entries
echo '<br><button onclick="window.close()">Close Window</button>';
echo ' <button onclick="toggleJournal()">Show Journal Entries (' . $journalCount . ')</button>';
echo '<div id="journal-entries" style="display:none;">';
echo '<h3>Journal Entries</h3>';
echo '<table class="journal-table">';
echo '<tr><th>Timestamp</th><th>User</th><th>Entry</th></tr>';
if ($journalCount > 0) {
while ($journalRow = $journalResult->fetch_assoc()) {
echo '<tr>';
echo '<td>' . $journalRow['entry_dt'] . '</td>';
echo '<td>' . $journalRow['user'] . '</td>';
echo '<td>' . $journalRow['entry'] . '</td>';
echo '</tr>';
}
} else {
echo '<tr><td colspan="3">No journal entries found.</td></tr>';
}
echo '</table>';
echo '</div>';
echo '</div>';
} else { } else {
echo "No details found for the given ID."; echo "No details found for the given ID.";
} }
$conn->close(); $conn->close();
} }
@@ -262,7 +282,46 @@ switch($_GET['op']) {
default: default:
} }
?> ?>
<p><center><button onclick="window.close()">Close Window</button></center>
<script>
function toggleJournal() {
var journalEntries = document.getElementById("journal-entries");
var toggleButton = document.querySelector("button[onclick='toggleJournal()']");
if (journalEntries.style.display === "none") {
journalEntries.style.display = "block";
toggleButton.textContent = "Hide Journal Entries";
} else {
journalEntries.style.display = "none";
toggleButton.textContent = "Show Journal Entries";
}
}
</script>
<style>
.journal-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.journal-table th, .journal-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.journal-table th {
background-color: #f2f2f2;
color: #333;
}
.journal-table tr:nth-child(even) {
background-color: #f9f9f9;
}
.journal-table tr:hover {
background-color: #f1f1f1;
}
</style>

View File

@@ -1,24 +1,19 @@
<?php <?php
include("functions.php"); include("functions.php");
// Database connection details $created_by = "Website (DEV)";
$servername = "sasaprod.pattinson.org";
$username = "root";
$password = "PugPictureMousePen";
$dbname = "pprdevdb";
$created_by = "webhook-dev";
// Create connection $conn = connectDb();
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection // Check if the URL has a 'test' parameter set
if ($conn->connect_error) { if (isset($_GET['test'])) {
die("Connection failed: " . $conn->connect_error); $payload = json_decode(file_get_contents('testhook.json'), true);
} else {
$payload = json_decode(file_get_contents('php://input'), true);
} }
// Webhook payload // Log the received payload for debugging
#$payload = json_decode(file_get_contents('php://input'), true); error_log("Received payload: " . print_r($payload, true));
$payload = json_decode(file_get_contents('testhook.json'), true);
// Mapping of JSON 'name' keys to database column names // Mapping of JSON 'name' keys to database column names
$columnMapping = [ $columnMapping = [
@@ -92,15 +87,15 @@ $stmt->bind_param($types, ...$values);
// Execute the statement // Execute the statement
if ($stmt->execute()) { if ($stmt->execute()) {
echo "New record created successfully"; error_log("New record created successfully");
$lastId = $stmt->insert_id; $lastId = $stmt->insert_id;
if (!empty($email)) { if (!empty($email)) {
generatePprEmail($lastId, $email, $ac_reg); generatePprEmail($lastId, $email, $ac_reg);
} else { } else {
echo "Email is not set."; error_log("Email is not set.");
} }
} else { } else {
echo "Error: " . $stmt->error; error_log("Error: " . $stmt->error);
} }
// Close the connection // Close the connection