<?php

function template12($institutions, $branch, $students_array, $examination, $array, $result, $class_id, $section_id = null)
{
    global  $conn_rjllearning_specific;
?>
<!DOCTYPE html>
<html>
    
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Template 12</title>
  <link href="<?php echo 'https://rejoicebilldesk.in/rjllearning_development/resources/marksheet_template/template12/custom_stylesheets/4/4_temp12.css?key=' . time(); ?>" type="text/css" rel="stylesheet">
</head>

<body>
	<div class="container_marksheet_template1">
		<div class="content_container_template1">
			<div class="header_template1" align="center">
                  <!--<div class="logo_div_img_template1">-->
                  <!--  <img class="images" src="<?php echo $institutions['logo']; ?>">-->
                  <!--</div>-->
                <div class="logo_div_img_template1">
                    <img src="<?php echo 'https://rejoicebilldesk.in/rjllearning_development/resources/assets/gvis_logo/gvis_logo.svg'; ?>" alt="School Logo">
                </div>  
              <div class="header_institution">
                <span class="heading_template1"><?php echo htmlspecialchars($institutions['institution_name']); ?></span><br>
                <span class="heading_code_info_template1"><?php echo htmlspecialchars($branch['branch_code']); ?></span><?php if ($branch['branch_code'] != "") { ?><br><?php } ?>
                <span class="heading_address_template1"><?php echo htmlspecialchars($branch['address']);
                  if ($branch['pincode'] != "") {
                    echo " - " . htmlspecialchars($branch['pincode']);
                  }
                ?></span><br>
                <span class="contact_template1" style="text-transform: lowercase;"><?php echo htmlspecialchars($branch['contact_number']);
                  if ($branch['email'] != "") {
                    echo ", &nbsp;" . strtolower(htmlspecialchars($branch['email']));
                  }
                ?></span>
              </div>
            </div>

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

    		<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 Obtained(100)</th>
    					<th>Grade</th>
    				</tr>
    
    				<?php $temp_count = 0; ?>
    
    				<tr>
    					<th class="texttransformupper alignleft">English</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">Punjabi</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">Hindi</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">Mathematics</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">E.V.S.</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">General Knowledge</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    				<tr>
    					<th class="texttransformupper alignleft">Computer Education</th>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    					<td><?php echo $array[++$temp_count]; ?></td>
    				</tr>
    
    			</table>
    </div>
    
    		<div class="fullstretch margintop20 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>
    
    
    		<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>
    
    		<div class="fullstretch 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>
    				
    		<div class="fullstretch margintop20" align="center">
                <table>
                    <tr>
                        <th colspan="2">
                            <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);
                                        } else {
                                            echo "Congratulations! "
                                                . $salutation . " "
                                                . ucwords(strtolower($students_array[0]['name']))
                                                . " has been promoted to next class.";
                                        }
                                }
                                ?>
                            </span>
                        </th>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <span class="new_session">
                                <?php
                                    $newSessionDate = $array[++$temp_count];
                                    if (!empty($newSessionDate)) {
                                        $formattedDate = date("d-m-Y", strtotime($newSessionDate));
                                        echo "New session begins from : " . htmlspecialchars($formattedDate);
                                    }
                                ?>
                            </span>
                        </td>
                    </tr>
                </table>
            </div>
    
    		<div class="fullstretch margintop20 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>
    
    		<div class="fullstretch" align="center" style="color:red;font-size:10pt;margin-top:10px;font-style:italic">
    		    * Incase of any discrepancies in marksheet, please contact school administration.
    		</div>
    
    	</div>
    </div>
</body>

</html>
<?php
}
?>