<?php 

function master_result_cb() {
  add_page_stylesheet("contents/plugins/eedu_portal/css/broadsheet.css", "eedu_broadsheetCss");
  add_page_stylesheet("contents/plugins/eedu_portal/css/result.css", "eedu_resultCss");
  $user = new user;
  $sorting = new sorting;
	$post = new post;
	if(!isset($_GET['id']))
		return_method();
	$student_id = $_GET['id'];
  $student_meta = $user->get_user_meta($student_id);
	$class = $_GET['class'];
	$session = $_GET['session'];
  $class_courses = get_class_courses($class, false, false, true, true);
  $broadsheet = eedu_portal_get_annual_broadsheet($class, $session, $class_courses);
  $student_results = get_student_annual_result_from_broadsheet($student_meta, $broadsheet);
  if(!$student_results) {
    echo "No result found";
    return false;
  }
  try {
    $locale = 'en_US';
    $nf = new NumberFormatter($locale, NumberFormatter::ORDINAL);
    $position = $nf->format($student_results['position']);
  } catch(Exception $e) {

  } finally {
    $position = ordinal_suffix_of($student_results['position']);
  }
  

	if (($_GET['media'] ?? '') !== "print"): ?>
        <div><a href="master-result?id=<?php echo $student_id ?>&class=<?php echo $class ?>&session=<?php echo $session ?>&media=print" class="btn btn-secondary popmeup" data-width=1270 data-height=800>Print</a></div>
  <?php endif ?>
	<div id="print" class="col-md-12">
            
		<div class="result">
            <div class="result-body pr-4 pl-4">
            <div class="table-responsive">
                  <table class="table page-break-avoid">
                        <tr>
                              <td style="border-top: none;">
                  <!-- <div class="row"> -->
                        <div class="col-md-12">
                              <?php echo eedu_portal_default_paperhead(['title-h' => 'h2']); ?>
                        </div>
                  <!-- </div> -->
                  <!-- <div class="row"> -->
                        <div class="col-md-12">
                          <table class="table no-border">
                            <tr>
                              <td colspan="2" class="pb-0"><div class="label pt-0 mt-0">Particulars</div></td> 
                              </tr>
                            <tr>
                              <td class="pt-0 pl-0 pr-0"><table class="table">
                                <tr>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Name</span><span><?php echo get_fullname($student_meta, true); ?></span></div></td>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Dob</span><span><?php echo $student_meta['dob']; ?></span></div></td>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Class</span><span><?php echo get_class_name($class); ?></span></div></td>
                                </tr>
                                <tr>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Student ID</span><span><?php echo $student_meta['username']; ?></span></div></td>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Academic Session</span><span><?php echo get_session_name($session); ?></span></div></td>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Subjects Offered</span><span><?php echo $student_results['subjects_offered']; ?></span></div></td>
                                </tr>
                                <tr>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Number of students in class</span><span><?php echo $students_count = _count($broadsheet); ?></span></div></td>
                                  <td class="pr-0 pl-0 pt-0 pb-0"><div class="particular"><span>Position in class</span><span><?php echo $position ." out of ".$students_count; ?></span></div></td>
                                </tr>

                                <?php //do_action('master-result-sheet-particulars-extra', $compiled_results[0]); ?>
                                </table>
                              </td>
                              <td class="pt-0 pl-0 pr-0"><div>
                                <div class="img-container"> <img src="<?php echo get_user_image($student_meta); ?>" class="img img-responsive"> </div>
                                </div></td>
                            </tr>
                          </table>
                        </div>
                  <!-- </div> -->
                  <!-- <div class="row"> -->
                        <table class="table no-border">
                          <tr>
                            <td>
                              <div class="row">
                                    <div class="col-md-12">
                                          <div class="label pt-0 mt-0">Cognitive Record</div>
                                          <?php do_action('get_master_result_card', ['student_results' =>$student_results, 'class_courses' => $class_courses, 'session' => $session]); ?> 
                                          
                                          <br><div class="label pt-0 mt-0">Comments</div> <br>
                                          <div class="col-md-12 clear-padding-left clear-padding-right"><div class="particular"><span><?php echo get_option('pref_name_for_form_teacher'); ?>'s Comment:</span><span><?php echo (get_option("auto_comment_on_annual")) ? $student_results['comment'] : ""; ?></span></div></div>
                                          <?php //do_action('master-result-sheet-comments-extra', $compiled_results[0]); ?>
                                    </div> 
                              </div>
<?php 
// return;
$principal = get_option('school_principal');
$form_teacher = get_form_teacher($student_meta['class'], $student_meta['category']);
$principal_meta = $user->get_user_meta($principal);
$form_teacher_meta = $user->get_user_meta($form_teacher);
 ?>
                              <div class="row">
                                    <div class="col-md-12">
                                          <div class="label pt-0 mt-0">Endorsments</div> <br>
                                          <table class="table text-center">
                                                <tr>
                                                  <td><div class="result-signature signature"><img src="<?php echo $form_teacher_meta['signature']; ?>"></div>
                                                  <div class="result-signature name text-center"><?php echo get_fullname($form_teacher_meta); ?></div> <div class="result-signature designation text-center"><small><?php echo get_option('pref_name_for_form_teacher') ?></small></div> </td>
                                                  <td><div class="result-signature signature"><img src="<?php echo $principal_meta['signature']; ?>"></div>
                                                  <div class="result-signature name text-center"><?php echo get_fullname($principal_meta); ?></div> <div class="result-signature designation text-center"><small><?php echo get_option('pref_name_for_principal') ?></small></div> </td>
                                                </tr>
                                          </table>
                                    </div>
                              </div>
                              </td>
                              <td>
                              <div class="label pt-0 mt-0">Psychometrics Record</div>
                              <?php do_action('get_psychometrics', ['student_id' => $student_meta['id']]); ?>
                              </td>
                           </tr>
                        </table>
                  <!-- </div> -->
                  <!-- <div class="row"> -->
                        <div class="col-md-12">
                              <?php //do_action('result-sheet-footer-extra', $result_meta); ?>
                        </div>
                  <!-- </div> -->
                        
                              </td>
                        </tr>
                  </table>
               </div>




        </div>
	</div>
  <div class="page-break-before"></div>
	<?php
  global $post_meta;
  add_page_javascript('app/assets/js/page-scripts/js-functions.js');
}