35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
function getCurrentUser() {
|
|
// For now, return the seeded admin user
|
|
return db()->query("SELECT * FROM users LIMIT 1")->fetch();
|
|
}
|
|
|
|
function logActivity($job_id, $event_type, $field_name = null, $old_value = null, $new_value = null) {
|
|
$user = getCurrentUser();
|
|
$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([
|
|
$job_id,
|
|
$user['company_id'],
|
|
$user['id'],
|
|
$user['name'],
|
|
$event_type,
|
|
$field_name,
|
|
$old_value,
|
|
$new_value
|
|
]);
|
|
}
|
|
|
|
function getJobStatuses($company_id) {
|
|
$stmt = db()->prepare("SELECT * FROM job_statuses WHERE company_id = ?");
|
|
$stmt->execute([$company_id]);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
function getClients($company_id) {
|
|
$stmt = db()->prepare("SELECT * FROM clients WHERE company_id = ? AND is_active = 1");
|
|
$stmt->execute([$company_id]);
|
|
return $stmt->fetchAll();
|
|
}
|