<?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=default&qlk=".md5(3));
}
//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 = "SUMMER"; // 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


// 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, 'NIGER STATE COLLEGE OF EDUCATION MINNA', 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', 7);
		// Page number
		$this->Cell(0, 10, "SOURCE: www.coeminna.edu.ng/eportals NIGER STATE COEMINNA - 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)). '-CRF';
$title =strtoupper($title);
$author = get_user_fullname($u).'_ IBB Univ';


// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($author);
$pdf->SetTitle($title);
$pdf->SetSubject('Course Form');
$pdf->SetKeywords('COE, 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', '', 12);

// 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));
$app_no = strtoupper (get_user_application_number($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)));
$shool = 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);

//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" />';



}

//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/><h5  style="color:#00000; font-weight:normal" ><i>P.M.B 39, MINNA, NIGER STATE</i></h5>';
 $output0 .= '<h4>SUMMER SEMESTER PROGRAMME (SSPC REGISTRATION FORM)</h4>';
 $output0  .= '<h6   style="color:#00000; font-weight:normal"> '. $st .' CONTACT SESSION.</h6>';
 //$output0  .= '<h5  style="color:#9999; font-weight:normal;"  >COURSE REGISTRATION FORM -  CRF</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 semester = '1'
	// 	 AND student_id ='$u'
	// 	 AND session_id = '$s'
	// 	 ORDER BY course_id
	// 	 ";
	//
	//   $r3 = mysqli_query(dbc(),$q3);
	  $sn = 0 ;

		$row =
		$total_row = 20;
	  // if(mysqli_num_rows($r3) > 0)
	  // {//show table


            // $output .= '<h6 id="list" class="btn btn-primary">FIRST SEMESTER</h6>';


	        $output .=		'<table cellspacing="1"  border="1" cellpadding="1" style="font-size:12px;">
			  <thead>
						  <tr>
						  <th width="5%"><b>S/N</b></th>
						  <th width="10%"><b>CODE</b></th>
						  <th width="65%"><b>TITLE</b></th>

						  <th width="20%"><b>UNIT</b></th>

						  </tr>

			   </thead>
			  <tbody>';

		  for($row =0; $row <= $total_row; $row++) //= mysqli_fetch_array($r3, MYSQLI_ASSOC)
		  {



			  $output .= "<tr>";
			  $output .= '<td width="5%">'.$sn = $sn+1 .'</td>';
			  $output .= '<td width="10%"></td>';
			  $output .= '<td width="65%"></td>';
			  $output .= '<td width="20%"></td>';



			  $output .= '</tr>';

			  //add total unit carried
			  // $total_units = 0;
			  // $total_unit = $total_units + get_course_unit($row['course_id']);
			  // $t +=  $total_unit;

		  }
			  // $output .= "<tr>";
			  // $output .= "<td></td>";
			  // $output .= "<td></td>";
			  //  $output .= "<td></td>";
			  // $output .= "<td><b>SUB TOTAL </b></td>";
			  // $output .= "<td> </td>";
			  // $output .= "</tr>";
	  // }
	  // else
	  // {//show the msg
		//
		// 	  $output .='No record found.';
		//
		//
	  // }



	  $output .=
	  '</tbody>
	  </table>';





  //declare t4 to be 0
  // $t4 = 0;
  // $total = 0;
  // $output4 ='';
  // //view the temporary table and show the preview for second 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 semester = '2'
	// 	 AND student_id ='$u'
	// 	 AND session_id = '$s'
	// 	 ORDER BY course_id";
	//
	//   $r4 = mysqli_query(dbc(),$q4);
	//   $sn4 = 0 ;
	//
	//
	//
	//    $output4 .= '<h6 id="list" class="btn btn-success">SECOND SEMESTER</h6>';
	//
	// 	  $output4 .=
	// 		'<table cellspacing="1"  border="1" cellpadding="1" style="font-size:8px;">
	// 		  <thead>
	// 					  <tr>
	// 					  <th width="5%"><b>S/N</b></th>
	// 					  <th width="10%"><b>CODE</b></th>
	// 					  <th width="50%"><b>TITLE</b></th>
	// 					  <th width="10%"><b>TYPE</b></th>
	// 					  <th width="10%"><b>UNIT</b></th>
	// 					  <th width="15%"><b>SIGN</b></th>
	// 					  </tr>
	// 			</thead>
	// 		  <tbody>';
	//
	//
	//
	//   if(mysqli_num_rows($r4) > 0)
	//   {//show table
	//
	//
	// 	  while($row4 = mysqli_fetch_array($r4, MYSQLI_ASSOC))
	// 	  {
	// 		  //add total unit carried
	// 		  $total_units4 = 0;
	// 		  $total_unit4 = $total_units4 + get_course_unit($row4['course_id']);
	// 		  $t4 += $total_unit4;
	//
	// 		  $output4 .= "<tr>";
	// 		  $output4 .= '<td width="5%">'.$sn4 = $sn4 +1 .'</td>';
	// 		  $output4 .= '<td width="10%">'.get_course_code($row4['course_id'])."</td>";
	// 		  $output4 .= '<td width="50%">'.strtoupper(get_course_name($row4['course_id']))."</td>";
	// 		  $output4 .= '<td width="10%">'.strtoupper(seen_as_elective_for_pdf($row4['seen_as_elective']))."</td>";
	//
	// 		  $output4 .= '<td width="10%">'.get_course_unit($row4['course_id'])."</td>";
	// 		  $output4 .= '<td width="15%"></td>';
	//
	// 		  $output4 .= "</tr>";
	//
	//
	//
	// 	  }
	// 		  $output4 .= "<tr>";
	// 		  $output4 .= "<td></td>";
	// 		  $output4 .= "<td></td>";
	// 		  $output4 .= "<td></td>";
	//
	// 		  $output4 .= "<td><b>SUB TOTAL </b></td>";
	// 		  $output4 .= "<td>".$t4."</td>";
	// 		  $output4 .= "</tr>";
	//
	//
	//
	//   }
	//   else
	//   {//show the msg
	//
	// 		 $output4 .='No record found.';
	//
	//
	//   }
	//
	//
	//
	//   $output4 .='</tbody></table>';
	//
	//
	//   //add the total of the course
	//   $total= $t + $t4;


//$string_ =  get_session_title($s).' Course Form';


// set some text to print
$txt = <<<EOD

<div align="center"> $output0 </div>

<h6 style="border-bottom:solid thin #000; ">BASIC INFORMATION</h6>

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

			  <tr>
			  <td width="25%"> <b>MATRIC No. :</b> $mat_no</td>
			  <td width="40%"> <b>NAME :</b> $name</td>
			   <td width="20%"> <b>LEVEL :</b> $level</td>
				 <td width="15%" colspan="2"> $passport</td>
				</tr>



        <tr>
        <td width="25%"> <b>SCHOOL:</b> $shool</td>
			   <td width="40%"> <b>PROGRAMME :</b> $programme</td>
				  <td width="20%"> App No.: $app_no </td>
				  <td width="15%"> </td>

			  </tr>



 </table>


<br/><br/>
$output




<table style="font-size:14px;" border="1" cellspacing="0" cellpadding="1">
<tr><td width="5%"></td><td width="10%"></td><td width="50%"><b>TOTAL</b></td><td width="20%" style="color:green; font-size:20px; font-weight:bold;"> $total</td></tr>
</table>
<br><br>

<table style="font-size:12px;" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="100%">
........................................................................................................................................................................................................<br>
___ SCHOOL EXAM OFFICER SIGN & DATE _________________ __DESK OFFICER SIGN & DATE __________________
</td>
</tr>

<br/>

<tr>
<td width="">............................................................<br>
___ STUDENT SIGNATURE & DATE __________________________________________________________
</td>
</tr>



<br/>

<tr>
<td width="100%">
___ DEAN: ___________________________________________________________________________________
</td>
</tr>


<br/>

<tr>
<td width="100%">
___ DIRECTOR (SSPC): __________________________________________________________________________
</td>
</tr>


<br/>

<tr>
<td width="100%">
___ BURSARY: ___________________________________________________________________
</td>
</tr>

</table>

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

<tr>
<td width="100%" style="color:red;">
**** NOTE Make four (4) Photocopies of the form each to Dean, Director (SSPC), Bursar and for yourself. <br/> Admission from year 2015 to 2016 are eligible to purchase the Form and register for the Programme.****
</td>
</tr>


</table>


EOD;

// print a block of text using Write()
//$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);

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

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






// -- set new background ---

//// get the current page break margin
//$bMargin = $pdf->getBreakMargin();
//// get current auto-page-break mode
//$auto_page_break = $pdf->getAutoPageBreak();
//// disable auto-page-break
//$pdf->SetAutoPageBreak(false, 0);
//// set bacground image
//$img_file = K_PATH_IMAGES.'bg.jpg';
//$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
//// restore auto-page-break status
//$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
//// set the starting point for the page content
//$pdf->setPageMark();


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

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



//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
//============================================================+
