<?php
include("../includes/db_connection.php");
include("../includes/auth.php");
include("../includes/mailer.php");

$id = $_GET['id'];
$action = $_GET['action'];

if($action == "activate"){
    $conn->query("UPDATE associates SET status='active' WHERE id=$id");

    $data = $conn->query("SELECT email,name FROM associates WHERE id=$id")->fetch_assoc();

    sendMail(
        $data['email'],
        "Account Activated",
        "Dear ".$data['name'].",<br>Your associate account has been activated."
    );
}

if($action == "deactivate"){
    $conn->query("UPDATE associates SET status='inactive' WHERE id=$id");

    $data = $conn->query("SELECT email,name FROM associates WHERE id=$id")->fetch_assoc();

    sendMail(
        $data['email'],
        "Account Deactivated",
        "Dear ".$data['name'].",<br>Your associate account has been temporarily 
		deactivated."
    );
}

if($action == "reject"){
    $conn->query("UPDATE associates SET status='rejected' WHERE id=$id");
}

header("Location: associates.php");
exit;
?>