Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/update_sms_for_arkesel.php

<?php
/**
 * Update SMS Management System for Arkesel Gateway
 * Run this to add Arkesel support to existing SMS tables
 */

require_once 'config/config.php';

checkLogin();

// Only superusers can update
if (!isSuperuser()) {
    redirect('dashboard.php');
}

$db = Database::getInstance()->getConnection();
$errors = [];
$success = [];
$warnings = [];

try {
    $db->beginTransaction();
    
    // Get all existing columns
    $stmt = $db->query("SHOW COLUMNS FROM sms_settings");
    $existingColumns = [];
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $existingColumns[] = $row['Field'];
    }
    
    // Define all columns that should exist
    $requiredColumns = [
        'gateway_provider' => "ENUM('africas_talking', 'twilio', 'bulksms_nigeria', 'hubtel', 'clickatell', 'smsportal', 'arkesel', 'custom') NOT NULL DEFAULT 'africas_talking'",
        'is_enabled' => "TINYINT(1) DEFAULT 0",
        'at_api_key' => "VARCHAR(255) DEFAULT NULL",
        'at_username' => "VARCHAR(255) DEFAULT NULL",
        'at_sender_id' => "VARCHAR(20) DEFAULT NULL",
        'twilio_account_sid' => "VARCHAR(255) DEFAULT NULL",
        'twilio_auth_token' => "VARCHAR(255) DEFAULT NULL",
        'twilio_from_number' => "VARCHAR(20) DEFAULT NULL",
        'bulksms_api_token' => "VARCHAR(255) DEFAULT NULL",
        'bulksms_sender_id' => "VARCHAR(20) DEFAULT NULL",
        'hubtel_client_id' => "VARCHAR(255) DEFAULT NULL",
        'hubtel_client_secret' => "VARCHAR(255) DEFAULT NULL",
        'hubtel_sender_id' => "VARCHAR(20) DEFAULT NULL",
        'clickatell_api_key' => "VARCHAR(255) DEFAULT NULL",
        'smsportal_client_id' => "VARCHAR(255) DEFAULT NULL",
        'smsportal_client_secret' => "VARCHAR(255) DEFAULT NULL",
        'arkesel_api_key' => "VARCHAR(255) DEFAULT NULL",
        'arkesel_sender_id' => "VARCHAR(20) DEFAULT NULL",
        'custom_api_url' => "VARCHAR(500) DEFAULT NULL",
        'custom_api_key' => "VARCHAR(255) DEFAULT NULL",
        'custom_method' => "ENUM('GET', 'POST') DEFAULT 'POST'",
        'custom_headers' => "TEXT DEFAULT NULL",
        'default_sender_name' => "VARCHAR(20) DEFAULT NULL",
        'test_mode' => "TINYINT(1) DEFAULT 1"
    ];
    
    // Add missing columns
    $addedCount = 0;
    foreach ($requiredColumns as $column => $definition) {
        if (!in_array($column, $existingColumns)) {
            $db->exec("ALTER TABLE sms_settings ADD COLUMN $column $definition");
            $success[] = "Added column: $column";
            $addedCount++;
        }
    }
    
    // Update gateway_provider if it exists but needs updating
    if (in_array('gateway_provider', $existingColumns)) {
        $db->exec("
            ALTER TABLE sms_settings 
            MODIFY COLUMN gateway_provider ENUM('africas_talking', 'twilio', 'bulksms_nigeria', 'hubtel', 'clickatell', 'smsportal', 'arkesel', 'custom') 
            NOT NULL DEFAULT 'africas_talking'
        ");
        $success[] = 'Updated gateway_provider to include Arkesel';
    }
    
    if ($addedCount > 0) {
        $success[] = "Added $addedCount missing columns";
    } else {
        $warnings[] = 'All columns already exist';
    }
    
    // Ensure created_at and updated_at exist
    if (!in_array('created_at', $existingColumns)) {
        $db->exec("ALTER TABLE sms_settings ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
        $success[] = 'Added created_at column';
    }
    if (!in_array('updated_at', $existingColumns)) {
        $db->exec("ALTER TABLE sms_settings ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
        $success[] = 'Added updated_at column';
    }
    
    $db->commit();
    $success[] = 'SMS Management System updated successfully!';
    
} catch (PDOException $e) {
    if ($db->inTransaction()) {
        $db->rollBack();
    }
    $errors[] = 'Database error: ' . $e->getMessage();
} catch (Exception $e) {
    if ($db->inTransaction()) {
        $db->rollBack();
    }
    $errors[] = 'Error: ' . $e->getMessage();
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Update SMS Management</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * { font-family: 'Inter', sans-serif; }
        .gradient-bg { background: linear-gradient(135deg, #1E40AF 0%, #9333EA 50%, #F97316 100%); }
    </style>
</head>
<body class="gradient-bg min-h-screen flex items-center justify-center p-4">
    <div class="bg-white rounded-2xl shadow-2xl p-8 max-w-2xl w-full">
        <div class="text-center mb-8">
            <div class="inline-block p-4 bg-gradient-to-r from-blue-600 to-purple-600 rounded-full mb-4">
                <i class="fas fa-sync-alt text-5xl text-white"></i>
            </div>
            <h1 class="text-3xl font-bold text-gray-800">SMS Management Update</h1>
            <p class="text-gray-600 mt-2">Adding Arkesel Gateway Support</p>
        </div>

        <?php if (!empty($success)): ?>
            <div class="bg-green-100 border border-green-400 text-green-800 px-6 py-4 rounded-lg mb-6">
                <div class="flex items-start">
                    <i class="fas fa-check-circle text-2xl mr-4 mt-1"></i>
                    <div class="flex-1">
                        <h3 class="font-bold text-lg mb-2">Update Successful!</h3>
                        <ul class="space-y-2">
                            <?php foreach ($success as $msg): ?>
                                <li class="flex items-center">
                                    <i class="fas fa-check mr-2 text-green-600"></i>
                                    <?php echo htmlspecialchars($msg); ?>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($errors)): ?>
            <div class="bg-red-100 border border-red-400 text-red-800 px-6 py-4 rounded-lg mb-6">
                <div class="flex items-start">
                    <i class="fas fa-exclamation-circle text-2xl mr-4 mt-1"></i>
                    <div class="flex-1">
                        <h3 class="font-bold text-lg mb-2">Update Errors</h3>
                        <ul class="space-y-2">
                            <?php foreach ($errors as $error): ?>
                                <li class="flex items-start">
                                    <i class="fas fa-times mr-2 text-red-600 mt-1"></i>
                                    <?php echo htmlspecialchars($error); ?>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($warnings)): ?>
            <div class="bg-yellow-100 border border-yellow-400 text-yellow-800 px-6 py-4 rounded-lg mb-6">
                <div class="flex items-start">
                    <i class="fas fa-exclamation-triangle text-2xl mr-4 mt-1"></i>
                    <div class="flex-1">
                        <h3 class="font-bold text-lg mb-2">Warnings</h3>
                        <ul class="space-y-2">
                            <?php foreach (array_unique($warnings) as $warning): ?>
                                <li class="flex items-start">
                                    <i class="fas fa-info-circle mr-2 text-yellow-600 mt-1"></i>
                                    <?php echo htmlspecialchars($warning); ?>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <!-- What's New -->
        <div class="bg-purple-50 rounded-lg p-6 mb-6">
            <h3 class="font-bold text-gray-800 mb-4 flex items-center">
                <i class="fas fa-star text-purple-600 mr-2"></i>What's New
            </h3>
            <div class="space-y-3">
                <div class="flex items-start">
                    <div class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5 flex-shrink-0">
                        <i class="fas fa-plus text-xs"></i>
                    </div>
                    <div>
                        <p class="font-semibold text-gray-800">Arkesel Gateway Added</p>
                        <p class="text-sm text-gray-600">Popular Ghanaian SMS provider now supported</p>
                    </div>
                </div>
                <div class="flex items-start">
                    <div class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5 flex-shrink-0">
                        <i class="fas fa-database text-xs"></i>
                    </div>
                    <div>
                        <p class="font-semibold text-gray-800">Database Schema Updated</p>
                        <p class="text-sm text-gray-600">Gateway provider column and Arkesel fields added</p>
                    </div>
                </div>
                <div class="flex items-start">
                    <div class="bg-purple-600 text-white rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5 flex-shrink-0">
                        <i class="fas fa-cog text-xs"></i>
                    </div>
                    <div>
                        <p class="font-semibold text-gray-800">Configuration Ready</p>
                        <p class="text-sm text-gray-600">Set up Arkesel in SMS settings now</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Arkesel Info -->
        <div class="bg-blue-50 rounded-lg p-6 mb-6">
            <h3 class="font-bold text-gray-800 mb-3 flex items-center">
                <span class="text-2xl mr-2">🇬🇭</span>About Arkesel
            </h3>
            <div class="space-y-2 text-sm text-gray-700">
                <p><strong>Country:</strong> Ghana</p>
                <p><strong>Website:</strong> <a href="https://sms.arkesel.com" target="_blank" class="text-blue-600 underline">sms.arkesel.com</a></p>
                <p><strong>Features:</strong> Excellent local delivery in Ghana, simple API integration</p>
                <p><strong>Requirements:</strong> API Key and optional Sender ID</p>
            </div>
        </div>

        <!-- Action Buttons -->
        <div class="flex flex-col sm:flex-row gap-3">
            <a href="modules/sms/settings.php" class="flex-1 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white text-center px-6 py-3 rounded-lg font-semibold transition duration-200 transform hover:scale-105 shadow-lg">
                <i class="fas fa-cog mr-2"></i>Configure Arkesel
            </a>
            <a href="modules/sms/index.php" class="flex-1 bg-gradient-to-r from-green-600 to-green-700 hover:from-green-700 hover:to-green-800 text-white text-center px-6 py-3 rounded-lg font-semibold transition duration-200 transform hover:scale-105 shadow-lg">
                <i class="fas fa-sms mr-2"></i>Go to SMS Management
            </a>
        </div>

        <div class="mt-6 text-center">
            <a href="dashboard.php" class="text-gray-600 hover:text-gray-800 font-medium inline-flex items-center">
                <i class="fas fa-arrow-left mr-2"></i>Back to Dashboard
            </a>
        </div>

        <!-- Next Steps -->
        <div class="mt-8 p-4 bg-gradient-to-r from-blue-50 to-purple-50 rounded-lg">
            <h4 class="font-bold text-gray-800 mb-2">Next Steps:</h4>
            <ol class="text-sm text-gray-700 space-y-1">
                <li>1. Go to SMS Settings and select Arkesel gateway</li>
                <li>2. Enter your API Key from sms.arkesel.com</li>
                <li>3. Set your Sender ID (optional)</li>
                <li>4. Send a test SMS to verify</li>
            </ol>
        </div>
    </div>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists