Skip to main content

AICC content delivery

Displaying an AICC course in PHP involves setting up a mechanism to handle AICC HACP (HTTP AICC Communication Protocol) communication. This protocol enables communication between the course content and an LMS. Here’s a basic example in PHP to help you set up an AICC-compliant display and tracking solution.

Here's what the process generally involves:

  1. Prepare AICC Configuration and Initialization: Define parameters for launching and tracking.
  2. Handle AICC Requests: Use PHP to parse and respond to AICC HACP requests.
  3. Launch the Course Content: Embed or redirect to the actual course content.

Here’s some example PHP code that provides a simple implementation:

1. Setup an AICC Configuration File (aicc.php)

This PHP code example will set up basic handling for AICC data requests, simulate launching the course, and return status.

aicc.php

<?php
// aicc.php - AICC launch and tracking handler

// Configuration for AICC (usually stored in a database or configuration file)
$aicc_data = [
    'course_id' => '12345',
    'student_id' => 'student1',
    'lesson_location' => '',
    'lesson_status' => 'incomplete',
    'score' => '0',
];

// Process incoming AICC requests
if (isset($_POST['command'])) {
    $command = $_POST['command'];
    switch ($command) {
        case 'GetParam':
            // Send course data
            echo get_aicc_params($aicc_data);
            break;
        case 'PutParam':
            // Receive updates from course and store them
            update_aicc_data($aicc_data);
            echo "error=0\r\nerror_text=No Error";
            break;
        case 'GetParamEnc':
            // Encrypted command - not implemented here
            echo "error=1\r\nerror_text=Not Implemented";
            break;
        default:
            echo "error=1\r\nerror_text=Unknown Command";
    }
}

// Function to simulate returning AICC data in format for GetParam command
function get_aicc_params($data) {
    return "course_id={$data['course_id']}\r\n" .
           "student_id={$data['student_id']}\r\n" .
           "lesson_location={$data['lesson_location']}\r\n" .
           "lesson_status={$data['lesson_status']}\r\n" .
           "score={$data['score']}\r\n";
}

// Function to update AICC data based on PutParam command (simulates tracking)
function update_aicc_data(&$data) {
    $params = $_POST['aicc_data'];
    parse_str($params, $parsed_data);

    // Update simulated AICC data (this would be saved in a database in production)
    if (isset($parsed_data['lesson_location'])) {
        $data['lesson_location'] = $parsed_data['lesson_location'];
    }
    if (isset($parsed_data['lesson_status'])) {
        $data['lesson_status'] = $parsed_data['lesson_status'];
    }
    if (isset($parsed_data['score'])) {
        $data['score'] = $parsed_data['score'];
    }
}

2. Course Launch Page

Create a separate PHP page to handle the course launch. This page will redirect the user to the course content, and when the course calls back to aicc.php, it will handle status updates.

launch_course.php

<?php
// launch_course.php - Redirect to AICC-compliant course content

// Prepare AICC launch URL with required parameters
$aicc_url = "aicc.php";
$course_url = "path/to/your/course/content";

// Launch course and pass AICC data URL for communication
echo "<html><body>";
echo "<h1>Launching Course...</h1>";
echo "<iframe src='{$course_url}?aicc_url={$aicc_url}' width='100%' height='600px'></iframe>";
echo "</body></html>";

 

3. Course Content HTML (Simulated)

If you don’t have an AICC course package, you can simulate the content with a basic HTML page that communicates with the aicc.php script.

course_content.html (Example Course Content)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sample AICC Course</title>
    <script>
        function sendAiccData(command, data) {
            const xhr = new XMLHttpRequest();
            xhr.open("POST", "<?php echo $_GET['aicc_url']; ?>", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log("AICC Response: " + xhr.responseText);
                }
            };

            let params = "command=" + command;
            if (data) {
                params += "&aicc_data=" + encodeURIComponent(data);
            }

            xhr.send(params);
        }

        // Simulate completing the course and reporting progress
        function completeCourse() {
            let aiccData = "lesson_location=Module1&lesson_status=completed&score=100";
            sendAiccData("PutParam", aiccData);
            alert("Course Completed!");
        }
    </script>
</head>
<body>
    <h1>Welcome to the AICC Course</h1>
    <p>Content goes here...</p>
    <button onclick="completeCourse()">Complete Course</button>
</body>
</html>

 

Summary of Workflow:

  1. Launch Page (launch_course.php): Redirects or embeds the course content.
  2. Course Content (course_content.html): Communicates progress to aicc.php by calling sendAiccData.
  3. AICC Handler (aicc.php): Receives, stores, and responds to progress and tracking information.

Important Notes:

  • In production, AICC data should be stored in a secure database rather than using static PHP variables.
  • Proper error handling should be added for a robust implementation.
  • Customize course_content.html for real AICC content to interact with your LMS.

This setup provides a simple AICC-compatible structure for course tracking and display with PHP.