- Add Field Engineer Management feature, allowing creation, and assignment of engineers to service requests. - Add Service Contract/AMC Management feature, allowing creation of contracts and linking them to service requests. - Update admin panel to manage engineers and contracts. - Update service request form to include contract selection.
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Create service_requests table
|
|
$pdo->exec("
|
|
CREATE TABLE IF NOT EXISTS `service_requests` (
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
`name` VARCHAR(255) NOT NULL,
|
|
`phone` VARCHAR(255) NOT NULL,
|
|
`address` TEXT NOT NULL,
|
|
`service_type` VARCHAR(255) NOT NULL,
|
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
");
|
|
|
|
// Create users table for admin authentication
|
|
$pdo->exec("
|
|
CREATE TABLE IF NOT EXISTS `users` (
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
`username` VARCHAR(255) NOT NULL UNIQUE,
|
|
`password_hash` VARCHAR(255) NOT NULL
|
|
);
|
|
");
|
|
|
|
// Add a default admin user if one doesn't exist
|
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
|
|
$stmt->execute();
|
|
if ($stmt->fetch() === false) {
|
|
$pdo->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)")
|
|
->execute(['admin', password_hash('password', PASSWORD_DEFAULT)]);
|
|
}
|
|
|
|
echo "Database setup completed successfully.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database setup failed: " . $e->getMessage() . "\n");
|
|
}
|
|
|