<?php
function template25($institutions, $branch, $students_array, $examination, $array, $result, $class_id, $section_id = null) {
    global $conn_rjllearning_specific ;
    
?>

<!DOCTYPE html>
<html>
    
<body>
    <div class="container_marksheet_template1">
        <div class="content_container_template1">
            <div class="header_template1" align="center">
                <div class="logo_div_img_template1">
                    <img src="<?php echo $institutions['logo']; ?>">
                </div>
                
                <div class="header_institution">
                    <span class="heading_template1"><?php echo $institutions['institution_name']; ?></span><br>
                    <span class="heading_code_info_template1"><?php echo htmlspecialchars($branch['affiliation_code'] !== null ? $branch['affiliation_code'] : ''); ?></span>
                    <span class="heading_address_template1"><?php echo $branch['address'];
                        if ($branch['pincode'] != "" || $branch['city'] != "" || $branch['state_name'] != "" || $branch['country_name'] != "") {
                            echo ", " . $branch['city'] . ", " . $branch['state_name'] . ", " . $branch['country_name'] . " - " . $branch['pincode'];
                        }
                    ?></span><br>
                    <span class="contact_template1" style="text-transform: none;"><?php echo $branch['contact_number'];
                        if ($branch['email'] != "") {
                            echo ", &nbsp;" . strtolower($branch['email']);
                        }
                    ?></span>
                </div>
            </div>
            
            <div class="fullstretch header_info_container margintop10" align="center">
                <div class="fullstretch heading_report_template1">Holistic Progress Card</div>
                <div class="year_template1">Academic Session <?php echo $result; ?></div>
            </div>

            <!-- Student Info Section -->
            <div class="fullstretch margintop10" align="center">
                <div class="student_info_template1">
                    <table class="student_info_table_template1">
                        <tr>
                            <td>Name</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $students_array[0]['name']; ?></td>
                        </tr>
                        <tr>
                            <td>Class</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $class_id; ?></td>
                        </tr>
                        <tr>    
                            <td>Father's Name</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $students_array[0]['fathername']; ?></td>
                        </tr>
                    </table>
                </div>
                <div class="student_info_template1">
                    <table class="student_info_table_template1">
                        <tr>
                            <td>Admission Number</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $students_array[0]['admission_number']; ?></td>
                        </tr>
                        <tr>
                            <td>Section</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $section_id; ?></td>
                        </tr>
                        <tr>
                            <td>Mother's Name</td>
                            <td>:&nbsp;</td>
                            <td><?php echo $students_array[0]['mothername']; ?></td>
                        </tr>
                    </table>
                </div>
            </div>

            <!-- Scholastic Area Table -->
            <div class="fullstretch table1_container_template1" align="center">
                <table class="table1_template1" border="1">
                    <tr>
                        <th>&nbsp;</th>
                        <th colspan="7">Scholastic Area</th>
                    </tr>
                    <tr>
                        <th class="alignleft">Subject</th>
                        <th>Periodic Test (5)</th>
                        <th>Portfolio (5)</th>
                        <th>Multiple Assessment (5)</th>
                        <th>Subject Enrichment Activity (5)</th>
                        <th><?php echo ucwords($examination); ?> Exam (80)</th>
                        <th>Total Marks (100)</th>
                        <th>Grade</th>
                    </tr>

                    <?php $temp_count = 0; ?>
                    <tr>
                        <th class="texttransformupper alignleft">English</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Hindi</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Punjabi</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Mathematics</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Science</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Social Science</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">General Knowledge</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>

                    <tr>
                        <th class="texttransformupper alignleft">Computer Education</th>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td class="aligncenter"><?php echo displayMark($array[++$temp_count]); ?></td>
                        <td><?php echo displayGrade($array, $temp_count); ?></td>
                    </tr>
                </table>
            </div>

            <!-- Summary Section -->
            <div class="fullstretch margintop10 marginbottom10 flexbox-row-spacearound-start" align="center">
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <th class="alignleft">Attendance</th>
                            <td class="alignright">&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <th class="alignleft">Total Marks</th>
                            <td class="alignright">&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <th class="alignleft">Percentage</th>
                            <td class="alignright">&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <th class="alignleft">Overall Grade</th>
                            <td class="alignright">&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
                        </tr>
                    </table>
                </div>
            </div>

            <!-- Co-Scholastic Area -->
            <div class="fullstretch table1_container_template1 margintop0" align="center">
                <table class="table1_template1 evaluation_table tablelayout_fixed" border="1">
                    <tr>
                        <th colspan="2">Co - Scholastic Final</th>
                        <th colspan="2">Personality and Social Traits</th>
                    </tr>
                    <tr>
                        <th>Particulars</th>
                        <th><?php echo ucwords($examination); ?></th>
                        <th>Particulars</th>
                        <th><?php echo ucwords($examination); ?></th>
                    </tr>
                    <tr>
                        <td>General Awareness</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Team Spirit</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Computer Science</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Neatness</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Sports Discipline</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Courtesy</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Art & Craft</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Confidence</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Club Activities</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Punctuality</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Performing Art - Dance & Music</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Social & Emotional Development</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Work Education</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td>Conversation & Communication</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                    </tr>
                    <tr>
                        <td>Value Education</td>
                        <td class="aligncenter"><?php echo $array[++$temp_count]; ?></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
            </div>

            <!-- Participation Section -->
            <div class="fullstretch margintop10 table1_container_template1" align="center">
                <table class="table1_template1 evaluation_table tablelayout_fixed" border="1">
                    <?php if ($array[++$temp_count] != '') { ?>
                        <tr>
                            <th>Specific Participation</th>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td>
                            <?php if ($array[$temp_count] != '') { ?>
                                <b>Participation / Positions in various competitions:</b>
                                <?php echo ucwords($array[$temp_count]); ?>
                                <br>
                            <?php } ?>
                            <b>Remarks:</b> <?php echo ucwords($array[++$temp_count]); ?>
                        </td>
                    </tr>
                </table>
            </div>

            <!-- Promotion Message (if applicable) -->
            <div class="fullstretch margintop20" align="center">
                <table class="transparent_table" border="1">
                    <tr align="left">
                        <th colspan="2" align="left">
                            <span class="congratulate_message">
                                <?php
                                    $promotionClassId = $array[++$temp_count];
                                    if (!empty($promotionClassId)) {
                                        // Fetch class_name from DB using the class ID
                                        $className = '';
                                        $stmt = $conn_rjllearning_specific->prepare(
                                            "SELECT classname FROM class_info WHERE id = :id LIMIT 1"
                                        );
                                        $stmt->bindParam(':id', $promotionClassId, PDO::PARAM_INT);
                                        $stmt->execute();
                                        $classRow = $stmt->fetch(PDO::FETCH_ASSOC);
                            
                                        $className = $classRow['classname'] ?? '';
                            
                                        // Map gender to salutation
                                        $gender = strtoupper(trim($students_array[0]['gender'] ?? ''));
                                        $salutation = ($gender === 'M') ? 'Mr.' : (($gender === 'F') ? 'Miss.' : '');
                            
                                        // Display student promotion message with class name
                                        if(!empty($className))
                                        {
                                            echo "Congratulations! "
                                                . $salutation . " "
                                                . ucwords(strtolower($students_array[0]['name']))
                                                . " has been promoted to Class "
                                                . htmlspecialchars($className);
                                        }
                                }
                                ?>
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <?php
                            $newSessionDate = $array[++$temp_count];
                            if (!empty($newSessionDate)) {
                                $formattedDate = date("d-m-Y", strtotime($newSessionDate));
                                echo "New session begins from : " . htmlspecialchars($formattedDate);
                            }
                            ?>
                        </td>
                    </tr>
                </table>
            </div>

            <!-- Signatures Section -->
            <div class="fullstretch margintop50 flexbox-row-spacearound-start fontsize11" align="center">
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <td>Class Incharge</td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <td>Principal/ Headmistress</td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table class="student_info_table_template1">
                        <tr>
                            <td>Parent</td>
                        </tr>
                    </table>
                </div>
            </div>

            <!-- Footer Note -->
            <div class="fullstretch" align="center" style="margin-top:10px;color:red;font-size:10pt;">
                * Incase of any discrepancies in marksheet, please contact school administration.
            </div>
        </div>
    </div>
</body>

</html>

<?php
}
?>