File "rickshaw_actions.php"

Full path: /home/itsevak/public_html/prepaiddev.itsevak.com/admin/rickshaw_actions.php
File size: 7.36 B (7.36 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php
require_once '../includes/functions.php';

// Require validator access (admin, super_admin, or validator)
requireValidatorAccess();

// Set content type to JSON
header('Content-Type: application/json');

// Get the request data
$input = json_decode(file_get_contents('php://input'), true);

if (!$input) {
    echo json_encode(['success' => false, 'message' => 'Invalid request data']);
    exit;
}

$action = $input['action'] ?? '';
$rickshawId = $input['rickshaw_id'] ?? null;

if (!$rickshawId) {
    echo json_encode(['success' => false, 'message' => 'Rickshaw ID is required']);
    exit;
}

$user = getCurrentUser();
$adminId = $user['id'];

switch ($action) {
    case 'update_status':
        $status = $input['status'] ?? '';
        
        if (!in_array($status, ['active', 'inactive', 'pending_approval'])) {
            echo json_encode(['success' => false, 'message' => 'Invalid status']);
            exit;
        }
        
        $result = updateAutoRickshawStatus($rickshawId, $status, $adminId);
        echo json_encode($result);
        break;
        
    case 'get_details':
        $rickshaw = getAutoRickshawById($rickshawId);
        
        if (!$rickshaw) {
            echo json_encode(['success' => false, 'message' => 'Rickshaw not found']);
            exit;
        }
        
        // Generate HTML for the modal
        $html = generateRickshawDetailsHTML($rickshaw);
        echo json_encode(['success' => true, 'html' => $html]);
        break;
        
    default:
        echo json_encode(['success' => false, 'message' => 'Invalid action']);
        break;
}

function generateRickshawDetailsHTML($rickshaw) {
    $statusBadge = getStatusBadge($rickshaw['status']);
    
    $html = '
    <div class="row">
        <div class="col-md-6">
            <h6 class="fw-bold">Auto Rickshaw Details</h6>
            <table class="table table-sm">
                <tr><td><strong>Number Plate:</strong></td><td>' . htmlspecialchars($rickshaw['number_plate']) . '</td></tr>
                <tr><td><strong>Unique ID:</strong></td><td>' . htmlspecialchars($rickshaw['unique_local_id']) . '</td></tr>
                <tr><td><strong>Model:</strong></td><td>' . htmlspecialchars($rickshaw['model'] ?? 'N/A') . '</td></tr>
                <tr><td><strong>Color:</strong></td><td>' . htmlspecialchars($rickshaw['color'] ?? 'N/A') . '</td></tr>
                <tr><td><strong>Status:</strong></td><td>' . $statusBadge . '</td></tr>
                <tr><td><strong>Registration Date:</strong></td><td>' . date('M d, Y', strtotime($rickshaw['created_at'])) . '</td></tr>
            </table>
        </div>
        <div class="col-md-6">
            <h6 class="fw-bold">Owner Details</h6>
            <table class="table table-sm">
                <tr><td><strong>Name:</strong></td><td>' . htmlspecialchars($rickshaw['owner_name']) . '</td></tr>
                <tr><td><strong>Email:</strong></td><td>' . htmlspecialchars($rickshaw['owner_email']) . '</td></tr>
                <tr><td><strong>Phone:</strong></td><td>' . htmlspecialchars($rickshaw['owner_phone']) . '</td></tr>
                <tr><td><strong>Address:</strong></td><td>' . htmlspecialchars($rickshaw['owner_address'] ?? 'N/A') . '</td></tr>
            </table>
        </div>
    </div>';
    
    // Add documents section if available
    if ($rickshaw['document_photo_1'] || $rickshaw['document_photo_2'] || $rickshaw['document_photo_3']) {
        $documents = array_filter([$rickshaw['document_photo_1'], $rickshaw['document_photo_2'], $rickshaw['document_photo_3']]);
        
        $html .= '
        <div class="row mt-3">
            <div class="col-12">
                <h6 class="fw-bold">Documents</h6>
                
                <!-- Document Thumbnails -->
                <div class="row mb-3">';
        
        foreach ($documents as $index => $document) {
            if ($document) {
                $html .= '
                    <div class="col-md-4 mb-2">
                        <div class="text-center">
                            <div class="document-thumbnail-container" style="border: 2px solid #e9ecef; border-radius: 8px; padding: 8px; transition: all 0.3s ease; cursor: pointer;" 
                                 onmouseover="this.style.borderColor=\'#667eea\'; this.style.transform=\'scale(1.02)\'" 
                                 onmouseout="this.style.borderColor=\'#e9ecef\'; this.style.transform=\'scale(1)\'"
                                 onclick="viewAdminDocuments(' . $rickshaw['id'] . ', \'' . htmlspecialchars($document) . '\')">
                                <img src="<?php echo url_for(''); ?>uploads/' . htmlspecialchars($document) . '" 
                                     class="img-fluid" 
                                     alt="Document ' . ($index + 1) . '"
                                     style="max-height: 120px; width: 100%; object-fit: cover; border-radius: 4px;">
                                <p class="mt-2 mb-0">
                                    <small class="text-muted">Document ' . ($index + 1) . '</small>
                                </p>
                            </div>
                        </div>
                    </div>';
            }
        }
        
        $html .= '
                </div>
                
                <!-- Action Buttons -->
                <div class="d-flex gap-2 flex-wrap">';
        
        if ($rickshaw['document_photo_1']) {
            $html .= '<button type="button" class="btn btn-sm btn-outline-primary" onclick="viewAdminDocuments(' . $rickshaw['id'] . ', \'' . htmlspecialchars($rickshaw['document_photo_1']) . '\')">
                        <i class="fas fa-file-image"></i> Document 1
                      </button>';
        }
        if ($rickshaw['document_photo_2']) {
            $html .= '<button type="button" class="btn btn-sm btn-outline-primary" onclick="viewAdminDocuments(' . $rickshaw['id'] . ', \'' . htmlspecialchars($rickshaw['document_photo_2']) . '\')">
                        <i class="fas fa-file-image"></i> Document 2
                      </button>';
        }
        if ($rickshaw['document_photo_3']) {
            $html .= '<button type="button" class="btn btn-sm btn-outline-primary" onclick="viewAdminDocuments(' . $rickshaw['id'] . ', \'' . htmlspecialchars($rickshaw['document_photo_3']) . '\')">
                        <i class="fas fa-file-image"></i> Document 3
                      </button>';
        }
        
        $html .= '
                    <button type="button" class="btn btn-sm btn-primary" onclick="viewAllRickshawDocuments(' . $rickshaw['id'] . ', ' . htmlspecialchars(json_encode($documents)) . ')">
                        <i class="fas fa-images"></i> View All Documents
                    </button>
                </div>
            </div>
        </div>';
    }
    
    // Add QR code if available
    if ($rickshaw['qr_code_path']) {
        $html .= '
        <div class="row mt-3">
            <div class="col-12">
                <h6 class="fw-bold">QR Code</h6>
                <img src="<?php echo url_for(''); ?>uploads/' . htmlspecialchars($rickshaw['qr_code_path']) . '" 
                     alt="QR Code" class="img-thumbnail" style="width: 150px; height: 150px;">
            </div>
        </div>';
    }
    
    return $html;
}
?>