/home/bkprco/public_html/actions/add_client.php
prepare("INSERT INTO clients (account_id, name, email, phone) VALUES (?, ?, ?, ?)");
$stmt->execute([
$accountId,
$name,
$email,
$phone
]);
header('Location: ../clients.php');
exit;
?>
/home/bkprco/public_html/actions/assign_service.php
prepare("SELECT * FROM services WHERE id = ? AND account_id = ?");
$stmt->execute([$service_id, current_account_id()]);
$service = $stmt->fetch();
if (!$service) {
die("Service not found or you don't have permission to assign it.");
}
// Insert the service assignment into 'assigned_services'
$stmt = $pdo->prepare("INSERT INTO assigned_services (client_id, service_id, deadline_date, repeat_frequency)
VALUES (?, ?, ?, ?)");
$stmt->execute([$client_id, $service_id, $deadline_date, $service['repeat_frequency']]);
// Fetch tasks related to the service
$stmt = $pdo->prepare("SELECT * FROM service_tasks WHERE service_id = ?");
$stmt->execute([$service_id]);
$tasks = $stmt->fetchAll();
// Generate tasks for the client based on the service deadline
foreach ($tasks as $task) {
// Calculate the task due date based on the lead time and the service deadline
$task_due_date = calculate_task_due_date($deadline_date, $task['lead_time'], $task['lead_time_type']);
// Insert the task into the 'tasks' table
$stmt = $pdo->prepare("INSERT INTO tasks (client_id, service_id, task_name, due_date)
VALUES (?, ?, ?, ?)");
$stmt->execute([$client_id, $service_id, $task['task_name'], $task_due_date]);
}
// Redirect back to the client details page
header("Location: ../client_details.php?client_id=" . $client_id);
exit;
// Function to calculate task due date based on lead time
function calculate_task_due_date($deadline_date, $lead_time, $lead_time_type) {
switch ($lead_time_type) {
case 'days':
return date('Y-m-d', strtotime("-$lead_time days", strtotime($deadline_date)));
case 'weeks':
return date('Y-m-d', strtotime("-$lead_time weeks", strtotime($deadline_date)));
case 'months':
return date('Y-m-d', strtotime("-$lead_time months", strtotime($deadline_date)));
default:
return $deadline_date; // Fallback if no lead_time_type is provided
}
}
/home/bkprco/public_html/actions/login_user.php
prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
// Set session variables
$_SESSION['user_id'] = $user['id'];
$_SESSION['account_id'] = $user['account_id']; // Ensure account_id is set
header('Location: ../dashboard.php');
exit;
} else {
echo "Invalid login";
}
/home/bkprco/public_html/actions/register_user.php
beginTransaction();
$stmt = $pdo->prepare("INSERT INTO accounts (name) VALUES (?)");
$stmt->execute([$account_name]);
$account_id = $pdo->lastInsertId();
$stmt = $pdo->prepare("INSERT INTO users (account_id, name, email, password_hash, role) VALUES (?, ?, ?, ?, 'admin')");
$stmt->execute([$account_id, $name, $email, $password]);
$user_id = $pdo->lastInsertId();
$pdo->commit();
$_SESSION['user_id'] = $user_id;
$_SESSION['account_id'] = $account_id;
header('Location: ../public/dashboard.php');
exit;
?>
/home/bkprco/public_html/includes/auth.php
/home/bkprco/public_html/includes/db.php
PDO::ERRMODE_EXCEPTION];
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4", $user, $pass, $options);
// Logging setup
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/../error.log');
error_reporting(E_ALL);
set_exception_handler(function ($e) {
error_log("Uncaught Exception: " . $e->getMessage() . "\n" . $e->getTraceAsString());
http_response_code(500);
die("Something went wrong. Please try again later.");
});
set_error_handler(function ($severity, $message, $file, $line) {
error_log("Error: $message in $file on line $line");
http_response_code(500);
die("Something went wrong. Please try again later.");
});
register_shutdown_function(function () {
$error = error_get_last();
if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
error_log("Fatal Error: {$error['message']} in {$error['file']} on line {$error['line']}");
http_response_code(500);
die("Something went wrong. Please try again later.");
}
});
try {
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4", $user, $pass, $options);
} catch (PDOException $e) {
error_log("Database connection error: " . $e->getMessage());
die("A database error occurred. Please try again later.");
}