fixed error - Error saving job statuses

This commit is contained in:
Flatlogic Bot 2026-01-23 15:54:08 +00:00
parent dc3ef2491a
commit 8ab8df671a
4 changed files with 12 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
require_once __DIR__ . '/../db/config.php'; require_once __DIR__ . '/../db/config.php';
function get_current_user() { function getCurrentAppUser() {
// In a real application, this would fetch the logged-in user from a session or token. // In a real application, this would fetch the logged-in user from a session or token.
// For now, we'll hardcode the admin user from the seeded data. // For now, we'll hardcode the admin user from the seeded data.
// This assumes the admin user has company_id 1 (from the seed). // This assumes the admin user has company_id 1 (from the seed).
@ -14,7 +14,7 @@ function get_current_user() {
} }
function get_current_company_id() { function get_current_company_id() {
$user = get_current_user(); $user = getCurrentAppUser();
return $user ? $user['company_id'] : null; return $user ? $user['company_id'] : null;
} }
@ -26,7 +26,7 @@ function get_company_onboarding_status($company_id) {
} }
function logActivity($job_id, $event_type, $field_name = null, $old_value = null, $new_value = null) { function logActivity($job_id, $event_type, $field_name = null, $old_value = null, $new_value = null) {
$user = get_current_user(); $user = getCurrentAppUser();
if (!$user) { return; } // Don't log if no user context if (!$user) { return; } // Don't log if no user context
$stmt = db()->prepare("INSERT INTO activity_logs (job_id, company_id, user_id, user_name, event_type, field_name, old_value, new_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt = db()->prepare("INSERT INTO activity_logs (job_id, company_id, user_id, user_name, event_type, field_name, old_value, new_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([ $stmt->execute([
@ -206,4 +206,4 @@ function deleteJobFile($file_id, $job_id, $company_id) {
$pdo->rollBack(); $pdo->rollBack();
return ['success' => FALSE, 'message' => 'Database error: ' . $e->getMessage()]; return ['success' => FALSE, 'message' => 'Database error: ' . $e->getMessage()];
} }
} }

View File

@ -2,7 +2,7 @@
require_once 'includes/helpers.php'; require_once 'includes/helpers.php';
// Get current user and company ID // Get current user and company ID
$user = get_current_user(); $user = getCurrentAppUser();
// If no user or company ID, redirect to a login/error page (to be implemented later) // If no user or company ID, redirect to a login/error page (to be implemented later)
if (!$user || !($company_id = get_current_company_id())) { if (!$user || !($company_id = get_current_company_id())) {
@ -73,7 +73,7 @@ $clients = getClients($company_id);
<div class="container"> <div class="container">
<a class="navbar-brand fw-bold" href="index.php">Repairs Pro</a> <a class="navbar-brand fw-bold" href="index.php">Repairs Pro</a>
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<span class="me-3 text-secondary"><?php echo htmlspecialchars($user['name']); ?></span> <span class="me-3 text-secondary"><?php echo htmlspecialchars($user['name'] ?? ''); ?></span>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#createJobModal">New Job</button> <button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#createJobModal">New Job</button>
</div> </div>
</div> </div>
@ -185,4 +185,4 @@ $clients = getClients($company_id);
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body> </body>
</html> </html>

View File

@ -1,6 +1,6 @@
<?php <?php
require_once 'includes/helpers.php'; require_once 'includes/helpers.php';
$user = get_current_user(); $user = getCurrentAppUser();
$company_id = get_current_company_id(); $company_id = get_current_company_id();
$job_id = $_GET['id'] ?? null; $job_id = $_GET['id'] ?? null;
@ -389,4 +389,4 @@ $message_type = $_GET['message_type'] ?? '';
}); });
</script> </script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@ require_once __DIR__ . '/includes/helpers.php';
// Placeholder for company ID - in a real app, this would come from the session after login // Placeholder for company ID - in a real app, this would come from the session after login
$company_id = get_current_company_id(); $company_id = get_current_company_id();
$current_user = get_current_user(); $current_user = getCurrentAppUser();
if (!$company_id) { if (!$company_id) {
// Redirect to login or error page if no company is identified // Redirect to login or error page if no company is identified
@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$insert_stmt = $pdo->prepare("INSERT INTO job_statuses (company_id, name, is_default) VALUES (?, ?, ?)"); $insert_stmt = $pdo->prepare("INSERT INTO job_statuses (company_id, name, is_default) VALUES (?, ?, ?)");
foreach ($statuses as $index => $status_name) { foreach ($statuses as $index => $status_name) {
$is_default = ($index == $default_status_index); $is_default = (int)($index == $default_status_index); // Explicitly cast to int (0 or 1)
$insert_stmt->execute([$company_id, $status_name, $is_default]); $insert_stmt->execute([$company_id, $status_name, $is_default]);
} }
@ -259,4 +259,4 @@ if (isset($_GET['message'])) {
<?php endif; ?> <?php endif; ?>
</div> </div>
</body> </body>
</html> </html>