setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("Database connection error: " . $e->getMessage()); }v // Error and success messages $error = ''; $success = ''; // Check if the user is logged in $is_logged_in = isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true; // Processing the login form if (isset($_POST['login'])) { $password = $_POST['password']; try { $stmt = $pdo->query("SELECT password_hash FROM admin LIMIT 1"); $admin = $stmt->fetch(PDO::FETCH_ASSOC); if ($admin && password_verify($password, $admin['password_hash'])) { $_SESSION['admin_logged_in'] = true; $is_logged_in = true; $success = "Connection successful!"; } else { $error = "Incorrect password!"; } } catch (PDOException $e) { $error = "Error while verifying password: " . $e->getMessage(); } } // Processing the logout form if (isset($_POST['logout'])) { $_SESSION['admin_logged_in'] = false; $is_logged_in = false; $success = "Disconnected successfully!"; } // Processing the service addition form if ($is_logged_in && isset($_POST['add_service'])) { $name = $_POST['name']; $icon = $_POST['icon']; $url = $_POST['url']; try { // Find the next order $stmt = $pdo->query("SELECT MAX(order_num) as max_order FROM services"); $result = $stmt->fetch(PDO::FETCH_ASSOC); $next_order = ($result['max_order'] ?? 0) + 1; $stmt = $pdo->prepare("INSERT INTO services (name, icon, url, order_num) VALUES (?, ?, ?, ?)"); $stmt->execute([$name, $icon, $url, $next_order]); $success = "Service added successfully!"; } catch (PDOException $e) { $error = "Error while adding the service: " . $e->getMessage(); } } // Processing the service change form if ($is_logged_in && isset($_POST['edit_service'])) { $id = $_POST['id']; $name = $_POST['name']; $icon = $_POST['icon']; $url = $_POST['url']; try { $stmt = $pdo->prepare("UPDATE services SET name = ?, icon = ?, url = ? WHERE id = ?"); $stmt->execute([$name, $icon, $url, $id]); $success = "Service successfully modified!"; } catch (PDOException $e) { $error = "Error while modifying the service: " . $e->getMessage(); } } // Processing the service cancellation form if ($is_logged_in && isset($_POST['delete_service'])) { $id = $_POST['id']; try { $stmt = $pdo->prepare("DELETE FROM services WHERE id = ?"); $stmt->execute([$id]); $success = "Service successfully deleted!"; } catch (PDOException $e) { $error = "Error while deleting the service: " . $e->getMessage(); } } // Processing of the service reorganization form if ($is_logged_in && isset($_POST['reorder'])) { $ids = $_POST['service_ids']; try { $pdo->beginTransaction(); foreach ($ids as $order => $id) { $stmt = $pdo->prepare("UPDATE services SET order_num = ? WHERE id = ?"); $stmt->execute([$order + 1, $id]); } $pdo->commit(); $success = "Services successfully reorganized!"; } catch (PDOException $e) { $pdo->rollBack(); $error = "Error during service reorganization: " . $e->getMessage(); } } // Retrieving services from the database try { $stmt = $pdo->query("SELECT * FROM services ORDER BY order_num ASC"); $services = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $services = []; $error = "Error retrieving services: " . $e->getMessage(); } $title = $config['site']['name']; $description = "Internal system administration area of the ". $config['site']['name'] ." website."; $url = "https://". $config['site']['main_domain'] ."/services?edit"; $meta_image = "https://". $config['site']['imgs_domain'] ."/-/WaWA7/FoRUmETa47.png/raw"; $robots = "noindex, nofollow"; ?> <?php echo $title; ?> - Admin

Admin

Login

Add a service

Services

Icon Name URL Actions

Select an icon

← Back to home page