<?php

function template13($institutions, $branch, $students_array, $examination, $arrays, $result, $class_id, $section_id = null)
{
    // Merge array and ensure proper keys
    $array = array_merge([null], $arrays);

    // Fill missing marks with 0 and ensure remarks exist
    for ($i = 1; $i <= 13; $i++) {
        if (!isset($array[$i])) $array[$i] = ($i == 12 ? 0 : '');
    }

    // Calculate total marks for subjects 5 to 11
    $total_marks = 0;
    for ($i = 5; $i <= 11; $i++) {
        $total_marks += intval($array[$i]);
    }
    $array[12] = $total_marks;

    // Ensure remarks is set
    $remarks = $array[13];
?>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MARKS UPLOAD</title>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
    <!--<link rel="stylesheet" type="text/css"-->
    <!-- href="<?php echo 'https://rejoicebilldesk.in/rjllearning_development/resources/marksheet_template/template13/style_template13.css?key=' . time(); ?>" />-->
    <link href="<?php echo 'https://rejoicebilldesk.in/rjllearning_development/resources/marksheet_template/template13/custom_stylesheet/4/4_temp13.css?key=' . time(); ?>" 
          type="text/css" rel="stylesheet">
</head>
<body>

    <div class="container_marksheet_template1">
        <div class="border_template1">
            <div class="content_container_template1">

                <!-- Header -->
                <div class="fullstretch header_template1" align="center">
                    <div class="logo_div_img_template1">
                        <img class="images" 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 $branch['branch_code']; ?></span>
                        <?php if ($branch['branch_code'] != ""): ?><br><?php endif; ?>
                        <span class="heading_address_template1">
                            <?php echo $branch['address'];
                            if ($branch['pincode'] != "") {
                                echo " - " . $branch['pincode'];
                            } ?>
                        </span><br>
                        <span class="contact_template1" style="text-transform: lowercase;">
                            <?php echo $branch['contact_number'];
                            if ($branch['email'] != "") {
                                echo ", &nbsp;" . strtolower($branch['email']);
                            } ?>
                        </span>
                    </div>
                </div>

                <!-- Report Heading -->
                <div class="fullstretch header_info_container" align="center">
                    <div class="fullstretch heading_report_template1">Progress Report</div>
                    <div class="year_template1">Academic Session <?php echo $result; ?></div>
                </div>

                <!-- Student Info -->
                <div class="fullstretch" align="center">
                    <div class="student_info_template1">
                        <table class="student_info_table_template1">
                            <tr>
                                <td>Name</td><td></td>
                                <td><?php echo $students_array[0]['name']; ?></td>
                            </tr>
                            <tr>
                                <td>Class</td><td></td>
                                <td><?php echo $class_id; ?></td>
                            </tr>
                            <tr>
                                <td>Father's Name</td><td></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></td>
                                <td><?php echo $students_array[0]['admission_number']; ?></td>
                            </tr>
                            <tr>
                                <td>Stream</td><td></td>
                                <td><?php echo ucwords(strtolower("Humanties")); ?></td>
                            </tr>
                            <tr>
                                <td>Mother's Name</td><td></td>
                                <td><?php echo $students_array[0]['mothername']; ?></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <!-- Marks Table -->
                <div class="form-container">
                    <table id="template_table_edit">
                        <tr align="left">
                            <th>Subject</th>
                            <th><?php echo ucwords(strtolower($examination)); ?> (40)</th>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft">English</th>
                            <td><?php echo $array[5]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft">Physical Education</th>
                            <td><?php echo $array[6]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft"><?php echo $array[1]; ?></th>
                            <td><?php echo $array[7]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft"><?php echo $array[2]; ?></th>
                            <td><?php echo $array[8]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft"><?php echo $array[3]; ?></th>
                            <td><?php echo $array[9]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft"><?php echo $array[4]; ?></th>
                            <td><?php echo $array[10]; ?></td>
                        </tr>

                        <tr>
                            <th class="texttransformupper alignleft">Information Technology (Add.)</th>
                            <td><?php echo $array[11]; ?></td>
                        </tr>

                        <!-- Total Marks -->
                        <tr>
                            <th class="texttransformupper alignleft">Total</th>
                            <td><?php echo $array[12]; ?></td>
                        </tr>
                    </table>
                </div>

                <!-- Remarks -->
                <div class="fullstretch margintop20" align="center">
                    <div class="student_info_template1">
                        <table class="info student_info_table_template1">
                            <tr>
                                <td><b>Remarks</b></td>
                            </tr>
                            <tr>
                                <td><?php echo $remarks; ?></td>
                            </tr>
                        </table>
                    </div>
                </div>

                <!-- Signatures -->
                <div class="fullstretch margintop50" align="center">
                    <div class="student_info_template1">
                        <table class="info student_info_table_template1">
                            <tr><td>Class Incharge</td></tr>
                        </table>
                    </div>
                    <div class="student_info_template1">
                        <table class="info student_info_table_template1">
                            <tr><td>Principal / Headmistress</td></tr>
                        </table>
                    </div>
                </div>

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

            </div>
        </div>
    </div>
</body>
</html>
<?php
}
?>
