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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u456810272/domains/afrbioidv.com/public_html/api.php

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

$host = 'localhost';
$dbname = 'u456810272_afrbioidv';
$username = 'u456810272_afrbioidv';
$password = 'Global@#980';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => 'Database connection failed: ' . $e->getMessage()]);
    exit;
}

$action = isset($_GET['action']) ? $_GET['action'] : '';
$method = $_SERVER['REQUEST_METHOD'];

if ($action == 'login' && $method == 'POST') {
    $data = json_decode(file_get_contents("php://input"), true);
    if (!$data) $data = $_POST;
    $email = $data['email'] ?? '';
    $pass = $data['password'] ?? '';
    $stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
    $stmt->execute(['email' => $email]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
    if ($user && $user['password'] === $pass) {
        session_start();
        $_SESSION['afr_admin_logged_in'] = true;
        $_SESSION['afr_user_id'] = $user['id'];
        echo json_encode(['status' => 'success', 'message' => 'Login successful', 'user' => ['id' => $user['id'], 'email' => $user['email'], 'role' => $user['role']]]);
    } else {
        http_response_code(401);
        echo json_encode(['status' => 'error', 'message' => 'Invalid email or password']);
    }
    exit;
}

if ($action == 'logout') {
    session_start();
    session_destroy();
    header('Location: index.html');
    exit;
}

if ($action == 'register' && $method == 'POST') {
    $data = json_decode(file_get_contents("php://input"), true);
    if (!$data) $data = $_POST;
    $name = $data['name'] ?? '';
    $email = $data['email'] ?? '';
    $phone = $data['phone'] ?? '';
    $pass = $data['password'] ?? '';
    try {
        $pdo->beginTransaction();
        $stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (:email, :password, 'member')");
        $stmt->execute(['email' => $email, 'password' => $pass]);
        $userId = $pdo->lastInsertId();
        $stmt = $pdo->prepare("INSERT INTO members (user_id, full_name, email, phone) VALUES (:uid, :name, :email, :phone)");
        $stmt->execute(['uid' => $userId, 'name' => $name, 'email' => $email, 'phone' => $phone]);
        $stmt = $pdo->prepare("INSERT INTO subscriptions (user_id, plan, status) VALUES (:uid, 'Free', 'active')");
        $stmt->execute(['uid' => $userId]);
        $pdo->commit();
        echo json_encode(['status' => 'success', 'message' => 'Registration successful']);
    } catch (Exception $e) {
        $pdo->rollBack();
        http_response_code(500);
        echo json_encode(['status' => 'error', 'message' => 'Registration failed: ' . $e->getMessage()]);
    }
    exit;
}

if ($action == 'dashboard_stats' && $method == 'GET') {
    $products = $pdo->query("SELECT COUNT(*) FROM products")->fetchColumn();
    $members = $pdo->query("SELECT COUNT(*) FROM members")->fetchColumn();
    $subs = $pdo->query("SELECT COUNT(*) FROM subscriptions WHERE status='active'")->fetchColumn();
    $revenue = 0;
    echo json_encode(['status' => 'success', 'data' => ['products' => $products, 'members' => $members, 'subscriptions' => $subs, 'revenue' => $revenue]]);
    exit;
}

if ($action == 'products') {
    if ($method == 'GET') {
        if (isset($_GET['id'])) {
            $stmt = $pdo->prepare("SELECT * FROM products WHERE id = :id");
            $stmt->execute(['id' => $_GET['id']]);
            echo json_encode(['status' => 'success', 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
        } else {
            echo json_encode(['status' => 'success', 'data' => $pdo->query("SELECT * FROM products")->fetchAll(PDO::FETCH_ASSOC)]);
        }
    } elseif ($method == 'POST') {
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("INSERT INTO products (name, description, price, status) VALUES (:name, :description, :price, :status)");
        $stmt->execute(['name' => $data['name'], 'description' => $data['description'], 'price' => $data['price'], 'status' => $data['status']]);
        echo json_encode(['status' => 'success', 'message' => 'Product created']);
    } elseif ($method == 'PUT' && isset($_GET['id'])) {
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("UPDATE products SET name=:name, description=:description, price=:price, status=:status WHERE id=:id");
        $stmt->execute(['id' => $_GET['id'], 'name' => $data['name'], 'description' => $data['description'], 'price' => $data['price'], 'status' => $data['status']]);
        echo json_encode(['status' => 'success', 'message' => 'Product updated']);
    } elseif ($method == 'DELETE' && isset($_GET['id'])) {
        $stmt = $pdo->prepare("DELETE FROM products WHERE id = :id");
        $stmt->execute(['id' => $_GET['id']]);
        echo json_encode(['status' => 'success', 'message' => 'Product deleted']);
    }
    exit;
}

if ($action == 'members') {
    if ($method == 'GET') {
        if (isset($_GET['id'])) {
            $stmt = $pdo->prepare("SELECT * FROM members WHERE id = :id");
            $stmt->execute(['id' => $_GET['id']]);
            echo json_encode(['status' => 'success', 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
        } else {
            $limit = isset($_GET['limit']) ? " LIMIT " . intval($_GET['limit']) : "";
            echo json_encode(['status' => 'success', 'data' => $pdo->query("SELECT * FROM members ORDER BY id DESC" . $limit)->fetchAll(PDO::FETCH_ASSOC)]);
        }
    } elseif ($method == 'POST') {
        $data = json_decode(file_get_contents("php://input"), true);
        $pdo->beginTransaction();
        $stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (:email, :password, 'member')");
        $stmt->execute(['email' => $data['email'], 'password' => 'Default@123']);
        $uid = $pdo->lastInsertId();
        $stmt = $pdo->prepare("INSERT INTO members (user_id, full_name, email, phone) VALUES (:uid, :name, :email, :phone)");
        $stmt->execute(['uid' => $uid, 'name' => $data['full_name'], 'email' => $data['email'], 'phone' => $data['phone']]);
        $pdo->commit();
        echo json_encode(['status' => 'success', 'message' => 'Member created']);
    } elseif ($method == 'PUT' && isset($_GET['id'])) {
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("UPDATE members SET full_name=:name, email=:email, phone=:phone WHERE id=:id");
        $stmt->execute(['id' => $_GET['id'], 'name' => $data['full_name'], 'email' => $data['email'], 'phone' => $data['phone']]);
        echo json_encode(['status' => 'success', 'message' => 'Member updated']);
    } elseif ($method == 'DELETE' && isset($_GET['id'])) {
        $stmt = $pdo->prepare("DELETE FROM members WHERE id = :id");
        $stmt->execute(['id' => $_GET['id']]);
        echo json_encode(['status' => 'success', 'message' => 'Member deleted']);
    }
    exit;
}

if ($action == 'subscriptions') {
    if ($method == 'GET') {
        $stmt = $pdo->query("SELECT s.*, u.email as user_email FROM subscriptions s JOIN users u ON s.user_id = u.id");
        echo json_encode(['status' => 'success', 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
    } elseif ($method == 'POST') {
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("INSERT INTO subscriptions (user_id, plan, status) VALUES (:uid, :plan, :status)");
        $stmt->execute(['uid' => $data['user_id'], 'plan' => $data['plan'], 'status' => $data['status']]);
        echo json_encode(['status' => 'success', 'message' => 'Subscription created']);
    } elseif ($method == 'PUT' && isset($_GET['id'])) {
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("UPDATE subscriptions SET plan=:plan, status=:status WHERE id=:id");
        $stmt->execute(['id' => $_GET['id'], 'plan' => $data['plan'], 'status' => $data['status']]);
        echo json_encode(['status' => 'success', 'message' => 'Subscription updated']);
    }
    exit;
}

if ($action == 'settings' && $method == 'GET') {
    echo json_encode(['status' => 'success', 'data' => $pdo->query("SELECT * FROM settings")->fetchAll(PDO::FETCH_KEY_PAIR)]);
} elseif ($action == 'settings' && $method == 'POST') {
    $data = json_decode(file_get_contents("php://input"), true);
    foreach($data as $k => $v) {
        $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (:k, :v) ON DUPLICATE KEY UPDATE setting_value=:v");
        $stmt->execute(['k' => $k, 'v' => $v]);
    }
    echo json_encode(['status' => 'success', 'message' => 'Settings saved']);
}

http_response_code(404);
echo json_encode(['status' => 'error', 'message' => 'Action not found']);
?>
Back to Directory=ceiIENDB`