<p class="m-0"><strong>College Name: </strong> <?php echo $clg_name;?></p>
<p class="m-0"><strong>Course Name: </strong> <?php echo $course_name;?></p>
<p class=""><strong>Department Name: </strong> <?php echo $pCat;?></p>
<p class="m-0"><strong>Associate Name: </strong> <?php echo $fran_name;?></p>
<?php if(!empty($subFran_name)){?>
<p class="m-0"><strong>Sub Associate Name: </strong> <?php echo $subFran_name;?></p>
<?php }?>
<p class=""><strong>Assigned Employee : </strong> <?php echo $employee_name;?></p>
<p class="m-0"><strong>Student Name : </strong> <?php echo $client_name;?></p>
<p class="m-0"><strong>Create Date : </strong> <?php echo $rows["pCreateDate"];?></p>
<p class=""><strong>Course Status : </strong> <?php echo $statusName;?></p>
<div class="view-documents">
    <p class="m-0"><strong>Student Documents : </strong></p>
    <div class="row">
        <?php
            $edit_run = mysqli_query($con, "SELECT * FROM documents WHERE dProduct = '{$rows["pid"]}'");
            $counter = 1; // Initialize a counter for unique IDs
            while ($edit_row = mysqli_fetch_assoc($edit_run)) {
        ?>
        <div class="col-md-12">
            <div class="accordion mt-3" id="documentAccordion<?php echo $counter; ?>">
                <div class="accordion-item">
                    <h2 class="accordion-header" id="heading<?php echo $counter; ?>">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse"
                            data-bs-target="#collapse<?php echo $counter; ?>" aria-expanded="true"
                            aria-controls="collapse<?php echo $counter; ?>">
                            Documents: <?php echo htmlspecialchars($edit_row["dTitle"]); ?>
                        </button>
                    </h2>
                    <div id="collapse<?php echo $counter; ?>" class="accordion-collapse collapse"
                        aria-labelledby="heading<?php echo $counter; ?>"
                        data-bs-parent="#documentAccordion<?php echo $counter; ?>">
                        <div class="accordion-body">
                            <?php 
                            $document = $edit_row["document"];
                            $file_ext = strtolower(pathinfo($document, PATHINFO_EXTENSION)); // Get file extension
                            $document_url = "../upload/documents/" . $document; // Path to the document

                            // Display the file based on its type
                            if (in_array($file_ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) {
                                // Display image
                                echo '<img src="' . htmlspecialchars($document_url) . '" alt="Document Image" style="max-width: 100%; height: auto;">';
                            } elseif ($file_ext == 'pdf') {
                                // Display PDF in an iframe
                                echo '<iframe src="' . htmlspecialchars($document_url) . '" width="100%" height="600px"></iframe>';
                            } elseif (in_array($file_ext, ['doc', 'docx'])) {
                                // Download link for Word document
                                echo '<a href="' . htmlspecialchars($document_url) . '" target="_blank">Download Word Document</a>';
                            } elseif (in_array($file_ext, ['xls', 'xlsx'])) {
                                // Download link for Excel document
                                echo '<a href="' . htmlspecialchars($document_url) . '" target="_blank">Download Excel Document</a>';
                            } else {
                                // Download link for other file types
                                echo '<a href="' . htmlspecialchars($document_url) . '" target="_blank">Download File</a>';
                            }
                        ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php 
            $counter++; // Increment the counter for the next accordion item
        }
        ?>
    </div>
</div>