<?php

ob_start();


//include my own function
include 'includes/functions.php';



//customly collect the id and session
if(isset($_GET['u']))
{
	$u = $_GET['u'];
	$s = $_GET['s'];
}
else
{
	header("Location:dashboard.php?act=excard&qlk=".md5(8));
}
//collect other dinfo
$dept_id = get_user_department_id($u);
$school_id = get_user_school_id($u);

$programme_id = get_user_programme_id($u); //get programme if for a suer
$level = get_user_level($u); //get user level 
$programme_type = get_user_programme_type_id($user); //programme type


$session = get_current_session($id = '1'); //current session is always
$semester = get_current_semester($id = '1'); //current session is always

//for imge
$image = get_user_image($u);//get image
if($image != '')
{
	$passport = '<img  src="../uploads/'.$image.'" border="0" height="61" width="51" />';
	
	

}
else
{
	$passport = '<img  src="../uploads/img.jpg" border="0" height="61" width="51" />';


	
}

//get logo
$logo = 'images/coe.png';



// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf_include.php');


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	//Page header
	public function Header() {
		// Logo
		//$image_file = K_PATH_IMAGES.'logo.jpg';
		//$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		// Set font
		//$this->SetFont('helvetica', 'B', 14);
		// Title
		//$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M'); original commented 
		//$this->Cell(0, 15, 'IBBU CONSULT & SERVICES', 0, false, 'C', 0, '', 0, false, 'M', 'M');
	}

	// Page footer
	public function Footer() {
		// Position at 15 mm from bottom
		$this->SetY(-15);
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, "SOURCE: www.coeminna.edu.ng NIGER STATE COLLEGE OF EDUCATION MINNA - STUDENT Portal,  Page ".$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
	}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


//customly collect the title
$title = str_replace ('/','_',get_user_mat_no($u)). '-EC';
$title =strtoupper($title);
$author = get_user_fullname($u).'_ COE MINNA';


// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($author);
$pdf->SetTitle($title);
$pdf->SetSubject('EXAM CARD');
$pdf->SetKeywords('COEMINNA, PDF, course, slip, '.$s.'');


// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);



// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
//$pdf->SetFont('times', 'BI', 12) original;
$pdf->SetFont('times', '', 9);

// add a page
$pdf->AddPage();





//collect other dinfo
$dept_id = get_user_department_id($u);
$school_id = get_user_school_id($u);

$level = get_user_level($u); //get user level 
$name = strtoupper (get_user_fullname($u));
$mat_no = strtoupper (get_user_mat_no($u));


//collect academic info
$pt = strtoupper(show_programme_type(get_user_programme_type($u)));
$study_mode = strtoupper(show_study_mode(get_user_study_mode($u)));
$school = strtoupper(get_school_title(get_user_school_id($u)));

$department = strtoupper(get_department_title(get_user_department_id($u)));
$programme = strtoupper(get_programme_title(get_user_programme_id($u)));

$st =  get_session_title($session);
$smt =  get_semester_title($semester);



//set the content //this is my own function
$output0 = '';
  //$output = '<div class="text-center"><img src="../images/logo.png" height="80"  width="80"/></div>';
  
  $output0  .= '<br/><br/><span align="center"> <img  src="'.$logo.'" border="0" height="40" width="41" /></span>';
 
   //$output0 .= '<h5 align="center"  style="color:#00000; font-weight:normal" ><i>P.M.B 39, MINNA, NIGER STATE</i></h5>';
 //$output0 .= '<h3>NON-DEGREE PROGRAMME UNIT</h3>';
 	$output0  .= '<h5  align="center"  style="color:#00000; font-weight:normal"> '. $st .' ACADEMIC SESSION.</h5>';
 	$output0  .= '<h5 align="center"  style="color:#9999; font-weight:normal;"  >STUDENT EXAM CARD SLIP</h5>'; 

  $output ='';


  //view the temporary table and show the preview for first semester
  $q3 = " SELECT `id`, `student_id`, `programme_id`, `course_id`, `course_unit`, `seen_as_elective`, `session_id`, 
		 `semester`, `level`, `add_drop_status`, `delete_token`,  `date_added` 
		 FROM `students_courses_nce`
		 WHERE student_id ='$u'
		 AND session_id = '$session' 
		 AND semester = 1
		 ORDER BY date_added
		 "; //semester = '$semester' AND 
	  
	  $r3 = mysqli_query(dbc(),$q3);
	  $sn = 0 ;
	  if(mysqli_num_rows($r3) > 0)
	  {//show table
	  
    	  	
            //$output .= '<h5 id="list" class="btn btn-primary">FIRST SEMESTER</h5> <br>';
  
		    $output .= '<h6 id="list" class="btn btn-success">FIRST SEMESTER</h6>';

	        $output .=		'<table cellspacing="1"  border="1" cellpadding="3" style="font-size:8px;">
			  <thead>
						  <tr>
						  
						  <th width="100%"><b>COURSE CODE</b></th>
						  
						  
						  </tr>
						  
			   </thead>
			  <tbody>';
			 $output .= "<tr>";
			 $output .= "<td>";
	  
		  while($row = mysqli_fetch_array($r3, MYSQLI_ASSOC))
		  {
			  
			  
			  //$output .= "<tr>";
			 // $output .= '<td width="30%">'.$sn = $sn+1 .'</td>';
			  //$output .= '<td width="60%">'.get_course_code($row['course_id'])."</td>";
			 // $output .= "";
			 
			   //$output .= "</tr>";
			   $output .= ' ('.$sn = $sn+1 .') '.get_course_code($row['course_id']);
			  
		  }
		    $output .= "</td>";
		    $output .= "</tr>";
	  }
	  else
	  {//show the msg 
	  
			  $output .='No record found.';
		  
		  
	  }
	  
	  
	  
	  $output .=
	  '</tbody>
	  </table>';
	  
	  
	  
	   //view the temporary table and show the preview for first semester
  $q4 = " SELECT `id`, `student_id`, `programme_id`, `course_id`, `course_unit`, `seen_as_elective`, `session_id`, 
		 `semester`, `level`, `add_drop_status`, `delete_token`,  `date_added` 
		 FROM `students_courses_nce`
		 WHERE student_id ='$u'
		 AND session_id = '$session' 
		 AND semester = 2
		 ORDER BY date_added
		 "; //semester = '$semester' AND 
	  
	  $r4 = mysqli_query(dbc(),$q4);
	  $sn = 0 ;
	  if(mysqli_num_rows($r4) > 0)
	  {//show table
	  
    	  	
            //$output .= '<h5 id="list" class="btn btn-primary">FIRST SEMESTER</h5> <br>';
  
		    $output .= '<h6 id="list" class="btn btn-success">SECOND SEMESTER</h6>';

	        $output .=		'<table cellspacing="1"  border="1" cellpadding="3" style="font-size:8px;">
			  <thead>
						  <tr>
						  
						  <th width="100%"><b>COURSE CODE</b></th>
						  
						  
						  </tr>
						  
			   </thead>
			  <tbody>';
			 $output .= "<tr>";
			 $output .= "<td>";
	  
		  while($row2 = mysqli_fetch_array($r4, MYSQLI_ASSOC))
		  {
			  
			  
			  //$output .= "<tr>";
			 // $output .= '<td width="30%">'.$sn = $sn+1 .'</td>';
			  //$output .= '<td width="60%">'.get_course_code($row['course_id'])."</td>";
			 // $output .= "";
			 
			   //$output .= "</tr>";
			   $output .= ' ('.$sn = $sn+1 .') '.get_course_code($row2['course_id']);
			  
		  }
		    $output .= "</td>";
		    $output .= "</tr>";
	  }
	  else
	  {//show the msg 
	  
			  $output .='No record found.';
		  
		  
	  }
	  
	  
	  
	  $output .=
	  '</tbody>
	  </table>';
	   
	  
	  
	  $output .= '<table style="font-size:9px;" border="0" cellspacing="0" cellpadding="1">



<br><br>

<tr>
<td width="15%">
</td>
<td width="60%">
......................................................................... <br>
 __ Exam Officer\'s Signature , Stamp & Date __
</td>
<td width="15%">
</td>
<td width="10%">
</td>
</tr>

<br/>

<table style="font-size:8px;" border="0" cellspacing="1" cellpadding="1">

<tr>
<td width="95%" style="color:red;">
**** Note:You will not be allowed to sit for any paper without the presentation of this card.
This card must be printed in colors to make it valid. Black & white copy will not be accepted. ****
</td>
</tr>


</table><br/><br/><br/><br/><br/>';
	  
	  
	  
	  // create columns content
$right_column = $output0.
			'<table cellspacing="1"  border="0" cellpadding="2" style="font-size:8px;">
						  
							  <tr>
							  <td width="60%"> <b>NAME :</b> '. $name.'</td><td width="30%" rowspan="4" align="center"> '.$passport.' </td>
							  </tr>
							  <tr>
							    <td width="60%"> <b>MATRIC NO. :</b> '.$mat_no.'</td><td > </td>
							  </tr>
							  <tr>
							   <td width="60%"> <b>LEVEL :</b> '.$level.'</td><td  > </td>
							  </tr>
							   
							   
							   <tr>
							  
							  <td width="60%"> <b>SCHOOL :</b>'.$school.'</td><td> </td>
							  </tr>
							  <tr>
							  
							  <td width="100%"> <b>PROG. :</b> NCE/ '.$programme.'</td><td> </td>
							  </tr>
							 
						
				 </table>'.
				 $output;

$left_column = '<br/><br/><br/><div style="margin-left:10px"><strong>EXAMINATION RULES AND REGULATIONS </strong> <hr/><br/><br/><br/><br/>
<strong>1.</strong> Candidates should be in vicinity of examination HALL 30 minutes before the examination is due to begin. <br/>
<strong>2.</strong> Candidates are required to sign the attendance slip on their desk.<br/>
<strong>3.</strong> No candidates will be permitted<br/>
<strong>i.</strong> To enter examination hall if he/she is more than 30 minutes late.<br/>
<strong>ii.</strong> To leave the examination hall before end of 45 minutes after the commencement of the examination. <br/>
<strong>iii.</strong> To leave the examination hall during the last 15 minutes of the exam. <br/>


<strong>4.</strong> Candidates must sit at desk with number corresponding to those on their admission card. They are not permitted to move their desk. <br/>
<strong>5.</strong> If a student needs anything, the Invigilator should be called upon by the student by raising
up his/her hand. <br/>
<strong>6.</strong> Candidates are not permitted to introduce into the examination hall papers of any kind violation of this rule attract out right dismissal.<br/>

<strong>7.</strong> Candidate must write their examination number only on each separate answer book and on each supplementary sheet used under no circumstance must they write their names. <br/>
<strong>8.</strong> If they wish to attract the attention of the invigilator they should raise their hands. <br/>
<strong>9.</strong> No smoking No chewing and No Girafffing. <br/>
<strong>10.</strong> Candidates must not jot down any points or write on the examination cards or question paper. <br/>
<strong>11.</strong> Communication of any kinds is strickly forbidden. <br/>
<strong>12.</strong> Candidates must not enter the examination hall with handset or any computerized  gadget. <br/>

 <br/>


 </div>';


	  
	  
	  

  
 

// set some text to print
//$txt = <<<EOD
//
//
//<br/>
//<div align="center"> $output0 </div>
//

//
//
//$output
//
//
//<br><br><br/><br/>
//
//
//

//
//<br/><br/><br/>
//
//
//

//
//
//EOD;
//
//
//
//$pdf->writeHTML($txt, true, false, false, false, '');

// ---------------------------------------------------------





// get current vertical position
$y = $pdf->getY();

// set color for background
$pdf->SetFillColor(255, 255, 200);

// set color for text
$pdf->SetTextColor(0, 63, 127);

// write the first column
$pdf->writeHTMLCell(90, '', '', $y, $left_column, 1, 0, 1, true, 'J', true);

// set color for background
$pdf->SetFillColor(255, 255, 200);

// set color for text
$pdf->SetTextColor(0, 63, 127);

// write the second column
$pdf->writeHTMLCell(90, '', '', '', $right_column, 1, 1, 1, true, 'J', true);

// reset pointer to the last page
$pdf->lastPage();



//temporarily use it 
ob_end_clean();


//Close and output PDF document
//$pdf->Output('example_003.pdf', 'I');
$pdf->Output($title.'.pdf', 'D');

//============================================================+
// END OF FILE
//============================================================+
