35274-vm/add_channel.php
Flatlogic Bot d2f005da56 nu norm
2025-10-27 13:55:31 +00:00

83 lines
3.1 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$error = '';
$channel_identifier = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$channel_identifier = trim($_POST['channel_identifier'] ?? '');
if (empty($channel_identifier)) {
$error = 'Telegram Channel ID or URL is required.';
} else {
// Basic parsing to get ID from URL
if (filter_var($channel_identifier, FILTER_VALIDATE_URL)) {
$path = parse_url($channel_identifier, PHP_URL_PATH);
$channel_identifier = basename($path);
}
// Prepend '@' if it's a public username without it
if (strpos($channel_identifier, '@') !== 0 && !is_numeric($channel_identifier)) {
$channel_identifier = '@' . $channel_identifier;
}
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO channels (channel_identifier) VALUES (:channel_identifier)");
$stmt->execute([':channel_identifier' => $channel_identifier]);
session_start();
$_SESSION['flash_message'] = "Channel '{$channel_identifier}' added successfully!";
header("Location: index.php");
exit;
} catch (PDOException $e) {
if ($e->errorInfo[1] == 1062) { // Duplicate entry
$error = "Error: Channel '{$channel_identifier}' already exists.";
} else {
$error = "Database error: " . $e->getMessage();
}
}
}
}
require_once __DIR__ . '/layout_header.php';
?>
<div class="container-fluid">
<h1 class="h2 mb-4">Add New Channel</h1>
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="add_channel.php" method="POST">
<div class="mb-3">
<label for="channel_identifier" class="form-label">Telegram Channel ID or URL</label>
<input type="text" class="form-control" id="channel_identifier" name="channel_identifier"
placeholder="e.g., @channelname or https://t.me/channelname"
value="<?php echo htmlspecialchars($channel_identifier); ?>" required>
<div class="form-text text-secondary-color">
Provide the public channel username (e.g., @durov) or full URL.
</div>
</div>
<button type="submit" class="btn btn-primary">
<i data-feather="plus" class="me-1" style="width:16px; height:16px;"></i>
Add Channel
</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
require_once __DIR__ . '/layout_footer.php';
?>