<?php



$studentId = $studentData['student_id'];
$studentName = $studentData['name'];
$fatherName = $studentData['father_name'];
$motherName = $studentData['mother_name'];
$batch = $studentData['batch'];
$study_centre_name = $studentData['study_centre_name'];

$groupe = $studentData['groupe'];


$studentResultSQL = mysqli_query($conn,"SELECT * FROM `ssc` WHERE `student_id`='$studentId'");

$studentResultRaw = mysqli_fetch_assoc($studentResultSQL); 

 $totalgpa = $studentResultRaw['totalgpa'];
 $passingYear = $studentResultRaw['exam_year'];
 $firstYear = $passingYear - 1;
 
 
//  
 
 function resultCalculate($result){
     
     if ($result > 79) {
                $grade_point = "A+";
                $point = 5.00;
            } elseif ($result > 69) {
                $grade_point = "A";
                $point = 4.00;
            } elseif ($result > 59) {
                $grade_point = "A-";
                $point = 3.50;
            } elseif ($result > 49) {
                $grade_point = "B";
                $point = 3.00;
            } elseif ($result > 39) {
                $grade_point = "C";
                $point = 2.00;
            } elseif ($result > 32) {
                $grade_point = "D";
                $point = 1.00;
            } else {
                $grade_point = "F";
                $point = 0.00;
            }
            
            return [
                     'grade_point' => $grade_point,
                     'point' => $point
                   ];

 }
 

 
$bangla = $studentResultRaw['bangla'];
$banglaRes = resultCalculate($bangla);

$banglatwo = $studentResultRaw['banglatwo'];
$banglatwoRes = resultCalculate($banglatwo);

$english = $studentResultRaw['english'];
$englishRes = resultCalculate($english);

$englishtwo = $studentResultRaw['englishtwo'];
$englishtwoRes = resultCalculate($englishtwo);

$math = $studentResultRaw['math'];
$mathRes = resultCalculate($math);

$baobi = $studentResultRaw['baobi'];
$baobiRes = resultCalculate($baobi);

$ict = $studentResultRaw['ict'];
$ictRes = resultCalculate($ict);

$ismal_and_mural = $studentResultRaw['ismal_and_mural'];
$ismal_and_muralRes = resultCalculate($ismal_and_mural);

$GEOGRAPHY_AND_ENVIRONMENT = $studentResultRaw['GEOGRAPHY_AND_ENVIRONMENT'];
$GEOGRAPHY_AND_ENVIRONMENTRes = resultCalculate($GEOGRAPHY_AND_ENVIRONMENT);








$Civics_and_Good_Governance = $studentResultRaw['Civics_and_Good_Governance'];
$Civics_and_Good_GovernanceRes = resultCalculate($Civics_and_Good_Governance);

$science = $studentResultRaw['science'];
$scienceRes = resultCalculate($science);

$econnomics = $studentResultRaw['econnomics'];
$econnomicsRes = resultCalculate($econnomics);

$Accounting = $studentResultRaw['Accounting'];
$AccountingRes = resultCalculate($Accounting);

$Business_Entrepreneurship = $studentResultRaw['Business_Entrepreneurship'];
$Business_EntrepreneurshipRes = resultCalculate($Business_Entrepreneurship);

$Finance_and_Banking = $studentResultRaw['Finance_and_Banking'];
$Finance_and_BankingRes = resultCalculate($Finance_and_Banking);

$Physics = $studentResultRaw['Physics'];
$PhysicsRes = resultCalculate($Physics);

$Chemistry = $studentResultRaw['Chemistry'];
$ChemistryRes = resultCalculate($Chemistry);

$Biology = $studentResultRaw['Biology'];
$BiologyRes = resultCalculate($Biology);

$Higher_Mathematics = $studentResultRaw['Higher_Mathematics'];
$Higher_MathematicsRes = resultCalculate($Higher_Mathematics);


$agriculture = $studentResultRaw['agriculture'];
$agricultureRes = resultCalculate($agriculture);


$Civics_and_citezenship = $studentResultRaw['Civics_and_citezenship'];
$Civics_and_citezenshipRes = resultCalculate($Civics_and_citezenship);


$baobi = $studentResultRaw['baobi'];
$baobiRes = resultCalculate($baobi);


$commonAllSubj = $banglaRes['point'] + $banglatwoRes['point'] + $englishRes['point'] + $englishtwoRes['point'] + $mathRes['point']  + 
    $ictRes['point'] + $ismal_and_muralRes['point'] + $carrierRes['point'] + $physical_eduRes['point'] + $Civics_and_Good_GovernanceRes['point'] ;

  if($groupe === "Humanities"){
      $full_point = $commonAllSubj + $baobiRes['point'] + $GEOGRAPHY_AND_ENVIRONMENTRes['point'] + $scienceRes['point'] + $econnomicsRes['point'];
      $totalCGPA = $full_point / 14;
      $totalCGPA = round($totalCGPA , 2);
  }else if($groupe === "science"){
      
      
      $full_point = $commonAllSubj + $physicsRes['point'] + $ChemistryRes['point'] + $BiologyRes['point'] + $Higher_MathematicsRes['point'];
      $totalCGPA = $full_point / 14;
      $totalCGPA = round($totalCGPA , 2);
  }

echo <<<HTML
            
          <div data-v-390fc2b0="" class="flex justify-end mb-4">
            <button
            
             
              onclick="window.open('document.php?student_id={$studentId}', '_blank')"
              data-v-390fc2b0=""
              class="bg-gray-700 hover:bg-gray-800 text-white px-4 py-2 rounded-md flex items-center"
              
            
            >
              <svg
                data-v-390fc2b0=""
                xmlns="http://www.w3.org/2000/svg"
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                class="lucide lucide-download-icon h-5 w-5 mr-2"
              >
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
                <polyline points="7 10 12 15 17 10"></polyline>
                <line x1="12" x2="12" y1="15" y2="3"></line></svg
              ><span data-v-390fc2b0="">Download</span>
            </button>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                Student Information
              </h3>
              <dl
                data-v-390fc2b0=""
                class="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3 text-sm"
              >
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Program:</dt>
                  <dd data-v-390fc2b0="" class="">
                    Secondary School Certificate
                  </dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Study Center:
                  </dt>
                  <dd data-v-390fc2b0="" class="">
                    $study_centre_name
                  </dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Student I D:</dt>
                  <dd data-v-390fc2b0="" class="">$studentId</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Student Name:
                  </dt>
                  <dd data-v-390fc2b0="" class="">$studentName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Father Name:</dt>
                  <dd data-v-390fc2b0="" class="">$fatherName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Mother Name:</dt>
                  <dd data-v-390fc2b0="" class="">$motherName</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">Batch:</dt>
                  <dd data-v-390fc2b0="" class="">$batch</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">
                    Passing Year:
                  </dt>
                  <dd data-v-390fc2b0="" class="">$passingYear</dd>
                </div>
                <div
                  data-v-390fc2b0=""
                  class="flex justify-between sm:col-span-1"
                >
                  <dt data-v-390fc2b0="" class="font-semibold">G P A:</dt>
                  <dd data-v-390fc2b0="" class="">$totalgpa</dd>
                </div>
              </dl>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                1st Year
              </h3>
              <div data-v-390fc2b0="" class="overflow-x-auto">
                <table
                  data-v-390fc2b0=""
                  class="min-w-full divide-y divide-gray-200"
                >
                  <thead data-v-390fc2b0="" class="bg-gray-50">
                    <tr data-v-390fc2b0="">
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Exam Year/Term
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Code
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Name
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Letter Grade
                      </th>
                    </tr>
                  </thead>
                  <tbody
                    data-v-390fc2b0=""
                    class="bg-white divide-y divide-gray-200"
                  >
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1651
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Bangla 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                       {$banglaRes['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1652
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        English 1st Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$englishRes['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1653
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Mathematics
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$mathRes['grade_point']}
                      </td>
                    </tr>
                    
HTML;

  if($groupe === "Humanities"){
echo <<<HTML
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1659
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        History of Bangladesh and World Civilization
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$baobiRes['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1660
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Geography and Environment
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$GEOGRAPHY_AND_ENVIRONMENTRes['grade_point']}
                      </td>
                    </tr>
HTML;

}else if($groupe === "science"){
  
  echo <<<HTML
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1370
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Information and Communication Technology
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$ictRes['grade_point']}
                      </td>
                    </tr>
                    
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1137
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Chemistry
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$ChemistryRes['grade_point']}
                      </td>
                    </tr>
HTML;
    
}

echo <<<HTML
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                2nd Year
              </h3>
              <div data-v-390fc2b0="" class="overflow-x-auto">
                <table
                  data-v-390fc2b0=""
                  class="min-w-full divide-y divide-gray-200"
                >
                  <thead data-v-390fc2b0="" class="bg-gray-50">
                    <tr data-v-390fc2b0="">
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Exam Year/Term
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Code
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Course Name
                      </th>
                      <th
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
                      >
                        Letter Grade
                      </th>
                    </tr>
                  </thead>
                  <tbody
                    data-v-390fc2b0=""
                    class="bg-white divide-y divide-gray-200"
                  >
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC2651
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Bangla 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$banglatwoRes['grade_point']}
                      </td>
                    </tr>
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC2652
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Engilsh 2nd Paper
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$englishtwoRes['grade_point']}
                      </td>
                    </tr>
                    
                    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $passingYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC2654
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Islam and Moral Education
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$ismal_and_muralRes['grade_point']}
                      </td>
                    </tr>
                    
                    
                    
                    
                    
HTML;
// Output dynamic row based on group
if ($groupe === "Humanities") {
    echo <<<HTML
    <tr class="hover:bg-gray-50">
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">$passingYear</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">SSC2673</td>
      <td class="px-3 py-2 text-sm text-gray-500">Bangladesh and Global Studies (BGS)</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center">{$baobiRes['grade_point']}</td>
    </tr>
    <tr class="hover:bg-gray-50">
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">$passingYear</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">SSC2673</td>
      <td class="px-3 py-2 text-sm text-gray-500">Civics  and Citizenship</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center">{$Civics_and_citezenshipRes['grade_point']}</td>
    </tr>
    <tr class="hover:bg-gray-50">
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">$passingYear</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">SSC2673</td>
      <td class="px-3 py-2 text-sm text-gray-500">Agriculture Studies</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center">{$agricultureRes['grade_point']}</td>
    </tr>
    
    
HTML;
} elseif ($groupe === "science") {
    echo <<<HTML
    
    <tr data-v-390fc2b0="" class="hover:bg-gray-50">
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        $firstYear
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500"
                      >
                        SSC1136
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 text-sm text-gray-500"
                      >
                        Physics
                      </td>
                      <td
                        data-v-390fc2b0=""
                        class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center"
                      >
                        {$PhysicsRes['grade_point']}
                      </td> 
                    </tr>
    
    <tr class="hover:bg-gray-50">
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">$passingYear</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">SSC2138</td>
      <td class="px-3 py-2 text-sm text-gray-500">Biology</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center">{$BiologyRes['grade_point']}</td>
    </tr>
    <tr class="hover:bg-gray-50">
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">$passingYear</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500">SSC2126</td>
      <td class="px-3 py-2 text-sm text-gray-500">Higher Mathematics</td>
      <td class="px-3 py-2 whitespace-nowrap text-sm text-gray-500 text-center">{$Higher_MathematicsRes['grade_point']}</td>
    </tr>
HTML;
} 

<<<HTML
                    
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div data-v-390fc2b0="" class="bg-white shadow rounded-lg mt-6">
            <div data-v-390fc2b0="" class="p-4">
              <h3 data-v-390fc2b0="" class="text-lg font-semibold mb-2">
                Note
              </h3>
              <p data-v-390fc2b0="" class="text-sm text-gray-600">
                (-)- Waiver, AB- Absent, PR- Problem Related to OMR Sheet
                fill-up, RP- Expelled in the respective course, WH- Withheld,
                IC- Incomplete, NA- Not Applicable, X- No Grade Received
              </p>
            </div>
          </div>
          <!---->
        
HTML;


?>
