<?php
/**
 * Simple QR Code Generator (Fallback)
 * Creates a basic QR code image without external dependencies
 */

function generateSimpleQRCode($text, $filename, $size = 300) {
    // Create a simple QR code representation
    $qr_data = $text;
    $qr_size = $size;
    
    // Create image
    $image = imagecreatetruecolor($qr_size, $qr_size);
    
    // Define colors
    $white = imagecolorallocate($image, 255, 255, 255);
    $black = imagecolorallocate($image, 0, 0, 0);
    $blue = imagecolorallocate($image, 30, 64, 175);
    
    // Fill background
    imagefill($image, 0, 0, $white);
    
    // Create a simple pattern (this is a basic representation)
    $cell_size = $qr_size / 25;
    
    // Draw border
    imagerectangle($image, 0, 0, $qr_size - 1, $qr_size - 1, $black);
    
    // Draw corner squares (QR code positioning patterns)
    $corner_size = $cell_size * 7;
    
    // Top-left corner
    imagefilledrectangle($image, $cell_size, $cell_size, $cell_size + $corner_size, $cell_size + $corner_size, $black);
    imagefilledrectangle($image, $cell_size * 2, $cell_size * 2, $cell_size * 6, $cell_size * 6, $white);
    imagefilledrectangle($image, $cell_size * 3, $cell_size * 3, $cell_size * 5, $cell_size * 5, $black);
    
    // Top-right corner
    imagefilledrectangle($image, $qr_size - $corner_size - $cell_size, $cell_size, $qr_size - $cell_size, $cell_size + $corner_size, $black);
    imagefilledrectangle($image, $qr_size - $corner_size - $cell_size + $cell_size, $cell_size * 2, $qr_size - $cell_size * 2, $cell_size * 6, $white);
    imagefilledrectangle($image, $qr_size - $corner_size - $cell_size + $cell_size * 2, $cell_size * 3, $qr_size - $cell_size * 3, $cell_size * 5, $black);
    
    // Bottom-left corner
    imagefilledrectangle($image, $cell_size, $qr_size - $corner_size - $cell_size, $cell_size + $corner_size, $qr_size - $cell_size, $black);
    imagefilledrectangle($image, $cell_size * 2, $qr_size - $corner_size - $cell_size + $cell_size, $cell_size * 6, $qr_size - $cell_size * 2, $white);
    imagefilledrectangle($image, $cell_size * 3, $qr_size - $corner_size - $cell_size + $cell_size * 2, $cell_size * 5, $qr_size - $cell_size * 3, $black);
    
    // Add text label
    $font_size = 5;
    $text_width = strlen($qr_data) * $font_size;
    $text_x = ($qr_size - $text_width) / 2;
    $text_y = $qr_size - 30;
    
    imagestring($image, $font_size, $text_x, $text_y, "QR Code", $blue);
    
    // Save image
    $result = imagepng($image, $filename);
    imagedestroy($image);
    
    return $result;
}
?> 