<?php
ini_set('display_errors', 1);

require_once '../../../resources/base_path_include.php';

require_once $base_path_to_learning_resources  . "includes/connect.php"; // use require for mandatory files
require_once $base_path_to_learning_resources . 'lib/function.php';
require_once $base_path_to_learning_resources . 'lib/validate_api_signature.php';

//valdation file
require_once $base_path_to_learning_resources . 'lib/validate_function.php';
require_once $base_path_to_learning . 'user_management/authenticate.php';
require_once $base_path_to_learning . 'admin_api/academic_session/functions/validate_faculty.php';
require_once $base_path_to_learning . 'admin_api/academic_session/functions/functions.php';
require_once $base_path_to_learning . 'functions/common_functions.php';
//db access function
require_once $base_path_to_learning_resources . 'includes/specific_db_config.php';

require_once $base_path_to_learning . "vendor/autoload.php";
require_once $base_path_to_learning_resources . 'lib/bucket_functions/bucket_functions.php';
require_once $base_path_to_learning_resources . 'includes/aws_bucket_config.php';

require_once $base_path_to_learning .'faculty_api/modules/left_students/left_students_functions.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

$institutions = getInstitution($conn_rjllearning, $institution_id);
$additional_data = ['branch_code','pincode','address','contact_number','email'];
$branch = getBranchInfo($conn_rjllearning_specific, $institution_id, $branch_id,$additional_data);
$data= fetch_specific_manage_alumni($conn_rjllearning_specific, $alumni_id, $institution_id, $branch_id);
ExportLeftStudentAdmisson($institutions,$branch,$data);

function ExportLeftStudentAdmisson($institutions, $branch, $data){
    //   print_r($data);die();
    $student_data = $data['personal_info'];
  
    
    if ($student_data['gender'] == 'F') {
            $gender = 'Female';
    } elseif ($student_data['gender'] == 'M') {
            $gender =  'Male';
    }

    $html = ''; // Initialize the $html variable

    $html .= '<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Admission </title>
   <style>
         body {
    font-family: Arial, sans-serif;
    background-color: #fff;
    margin: 0;
    padding: 2px;
}

.container {
    background-color: #fff;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: auto;
    box-shadow: none;
   padding: 20px;
    margin: 20px auto; /* Add margin to create space between the screen and form */
    box-sizing: border-box; /* Ensure padding doesnt affect the containers width */
}

       .header {
            float: left;
            /*            border-bottom: 2px solid #000;*/
            padding-bottom: 10px;
            margin-bottom: 10px;
        }

        .header .logo {
            width: 150px;
            height: auto;

        }

        .header2  {
           float: right;
        }
		.header2 .logo2{
		  width: 150px;
		  height: 170px;
		  border:1px solid #ddd;
		}


        .header h1 {
            margin: 0;
            font-size: 24px;
        }

        .header h2 {
            margin: 5px 0;
            font-size: 18px;
            color: #333;
            font-weight:600;
        }

        .header p {
            margin: 5px 0;
            font-size: 16px;
            color: #333;
        }

        .cert-title {
            margin-top: 10px;
        }

        .cert-title button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: default;
            font-size: 16px;
        }

        .content table {
            width: 100%;
            border-collapse: collapse;
          
        }

        .content table, .content td, .content th {
            border-bottom: 1px solid #ddd;
        }

        .content td, .content th {
            padding: 1px;
            text-align: left;
        }

        /*.content tr:nth-child(even) {
            background-color: #f2f2f2;
        }*/

        // .content tr:hover {
        //     background-color: #ddd;
        // }

        .content th {
            background-color: #f4f4f4;
            color: black;
        }
        .content td{
            font-size: 14px;
            padding:7px;
            font-weight: 600;
            color: #333;
        }

        .signatures {
            display: flex;
            justify-content: space-between;
            margin-top: 40px;
            font-size: 18px;
            
        }

        .sign {
            text-align: center;
            flex: 1;
            font-size: 18px;
        }

        .sign:not(:last-child) {
            margin-right: 20px;
        }
    </style>
</head>
<body>';
       $html .= '<div class="container">
        <div class="header">';
        if($institutions['logo'] != null){
                    $html .= '<img  class="logo" src="'.$institutions['logo'].'" alt="School Logo">';
         
                    }
            $html .= '<h1>'. $institutions['institution_name'] .'</h1>
            <h2>'. $branch['name'].'&nbsp;&nbsp; (Code No.'. $branch['branch_code'].' )</h2>
            <p>'.$branch['address'].' ,&nbsp;&nbsp '.$branch['pincode'].'</p>
            <p>'.$branch['contact_number'].' | '.$branch['email'].'</p>
            <div class="cert-title">
                <button>Admission From</button>
            </div>
        </div>
        <div class="header2">';

             if (isset($student_data['student_profile_image']) && !empty($student_data['student_profile_image'])) {
          $html .= '<img class="logo2" src="' . $student_data['student_profile_image']['filepath'] . '" alt="Student Logo">';
        } else {
            
            if ($gender === 'Male') {
                $defaultImage = 'https://rejoicebilldesk.in/rjllearning_development/resources/images/student-m.png';
            } else if ($gender === 'Female') {
                $defaultImage = 'https://rejoicebilldesk.in/rjllearning_development/resources/images/student-f.png';
            } else {
                $defaultImage = 'https://rejoicebilldesk.in/rjllearning_development/resources/images/student-f.png'; // A generic default image
            }
            $html .= '<img class="logo2" src="' . $defaultImage . '" alt="Default Student Logo">';
        }
          $html .= '</div>         
        <div class="content">
            <table>
                <tr>
                    <td>Admission Number</td>
                    <td>'.$student_data['admission_number'].'</td>
                </tr>
                <tr>
                    <td>Name of the pupil</td>
                    <td>'.$student_data['name'].'</td>
                </tr>
                <tr>
                    <td>Fathers / Guardians Name</td>
                    <td>'.$student_data['mothername'].' </td>
                </tr>
                <tr>
                    <td>Gender</td>
                    <td>'.$gender.'</td>
                </tr>
                <tr>
                    <td>Date of first admission in the school</td>
                    <td>'.date("d-m-Y", strtotime($student_data['date_admission'])).'</td>
                </tr>
                <tr>
                    <td>Date of Birth</td>
                    <td>'.date("d-m-Y", strtotime($student_data['dob'])).'</td>
                </tr>
            
                <tr>
                    <td>Email</td>
                    <td>'.$student_data['email'].'</td>
                </tr>
                 <tr>
                    <td>Mobile</td>
                    <td>'.$student_data['mobile'].'</td>
                </tr>
                 <tr>
                    <td>Admission for Class</td>
                    <td>'.$data['class_info']['class_name'].'</td>
                </tr>
                <tr>
                    <td>Address</td>
                    <td>'.$student_data['address_line_1'].'</td>
                </tr>
                <tr>
                    <td>City</td>
                    <td>'.$student_data['city'].'</td>
                </tr>
                <tr>
                    <td>Nationality</td>
                    <td>'.$student_data['nationality'].'</td>
                </tr>
                <tr>
                    <td>Caste</td>
                    <td>'.$student_data['caste'].'</td>
                </tr>
               
            </table>
        </div>
        <div class="signatures">
            <div class="sign">
                <p>Principal</p>
            </div>
            <div class="sign">
                <p>Class Incharge</p>
            </div>
            <div class="sign">
                <p>Accountant</p>
            </div>
        </div>
    </div>
</body>
</html>';

    // Output the HTML content
    echo $html;
}
