<?php

function template23($institutions, $branch, $students_array, $examination, $array, $result, $class_id, $section_id = null)
{
  global $conn_rjllearning_specific;

?>
  <!DOCTYPE html>

  <div class="container_marksheet_template1">
    <div class="content_container_template1">
      <div class="fullstretch header_template1">
        <!--<div class="logo_div_img_template1">-->
        <!--  <img src="$base_path_to_learning_resources. "assets/gvis_logo/gvis_logo.svg"" alt="School Logo">-->
        <!--</div>-->

        <div class="logo_div_img_template1">
          <img src="<?php echo $institutions['logo']; ?>" alt="School 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><br/>
          <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">
            <?php echo $branch['contact_number'];
            if ($branch['email'] != "") {
              echo ", &nbsp;" . strtolower($branch['email']);
            }
            ?>
          </span>
        </div>
      </div>

      <div class="fullstretch header_info_container">
        <div class="fullstretch heading_report_template1">
          Holistic Progress Card
        </div>
        <div class="year_template1">Academic Session <?php echo $result; ?></div>
      </div>

      <div class="fullstretch student_info_section">
        <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>

      <div class="fullstretch table1_container_template1">
        <table class="table1_template1" border="1">
          <thead>
            <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 Obtained (100)</th>
              <th>Grade</th>
            </tr>
          </thead>
          <tbody>
            <?php $temp_count = 0; ?>
            <tr>
              <td class="table1_template1_subjects alignleft">English</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">Punjabi</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">Hindi</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">Mathematics</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">E.V.S.</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">General Knowledge</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
            <tr>
              <td class="table1_template1_subjects alignleft">Computer Education</td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayMark($array[++$temp_count]); ?></td>
              <td><?php echo displayGrade($array, $temp_count); ?></td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="fullstretch margintop10 flexbox-row-spacearound-start">
        <div class="summary-item">
          <table class="student_info_table_template2">
            <tr>
              <th class="alignleft">Attendance</th>
              <th class="alignleft colon">:</th>
              <td>&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
            </tr>
          </table>
        </div>
        <div class="summary-item">
          <table class="student_info_table_template2">
            <tr>
              <th class="alignleft">Total Marks</th>
              <th class="alignleft colon">:</th>
              <td>&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
            </tr>
          </table>
        </div>
        <div class="summary-item">
          <table class="student_info_table_template2">
            <tr>
              <th class="alignleft">Percentage</th>
              <th class="alignleft colon">:</th>
              <td>&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
            </tr>
          </table>
        </div>
        <div class="summary-item">
          <table class="student_info_table_template2">
            <tr>
              <th class="alignleft">Overall Grade</th>
              <th class="alignleft colon">:</th>
              <td>&nbsp;&nbsp;<?php echo $array[++$temp_count]; ?></td>
            </tr>
          </table>
        </div>
      </div>

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

      <div class="fullstretch table1_container_template1" align="center">
        <table class="specific_participation_table">
          <?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>

      <div class="fullstretch promotion_table">
        <table>
          <tr>
            <td>
              <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">
              <span class="new_session">
                <?php
                $newSessionDate = $array[++$temp_count];
                if (!empty($newSessionDate) and strtolower($newSessionDate) != "na") {
                  $formattedDate = date("d-m-Y", strtotime($newSessionDate));
                  echo "New session begins from : " . htmlspecialchars($formattedDate);
                }
                ?>
              </span>
            </td>
          </tr>
        </table>
      </div>

      <div class="fullstretch signature_container">
        <div>
          <table class="student_info_table_template1">
            <tr>
              <td>Class In-charge</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>

      <div class="fullstretch disclaimer">
        * In case of any discrepancies in marksheet, please contact school
        administration.
      </div>
    </div>
  </div>

<?php
}
