38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
$name = trim($_POST['name'] ?? '');
|
|
$repo_url = trim($_POST['repo_url'] ?? '');
|
|
$owner_team = trim($_POST['owner_team'] ?? '');
|
|
|
|
if (empty($name) || empty($repo_url) || empty($owner_team)) {
|
|
$_SESSION['feedback'] = ['type' => 'danger', 'message' => 'All fields are required.'];
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
if (!filter_var($repo_url, FILTER_VALIDATE_URL)) {
|
|
$_SESSION['feedback'] = ['type' => 'danger', 'message' => 'Please enter a valid repository URL.'];
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO services (name, repo_url, owner_team) VALUES (?, ?, ?)");
|
|
$stmt->execute([$name, $repo_url, $owner_team]);
|
|
$_SESSION['feedback'] = ['type' => 'success', 'message' => 'Service registered successfully!'];
|
|
} catch (PDOException $e) {
|
|
error_log($e->getMessage());
|
|
$_SESSION['feedback'] = ['type' => 'danger', 'message' => 'An error occurred while saving the service.'];
|
|
}
|
|
|
|
header('Location: index.php');
|
|
exit();
|