<?php
session_start();
// ============
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============

extract($_GET);
$branchid = $_SESSION['LOGIN_BRANCH'];

//$timezone = date_default_timezone_get();
$date = date('d/m/Y', time());









$branch_id = isset($_SESSION['LOGIN_BRANCH']) ? $_SESSION['LOGIN_BRANCH']: '';
if($branch_id !=''){
	$brans_obj = $obj->View_branch_details_By_Cond($branch_id,'B');
	$inst_name = $brans_obj->insName;
	$ins_code_name = $brans_obj->insCodeName; 
	$extablishd_year = $brans_obj->_establish_year ;
	$ins_logo = $brans_obj->_logo_location;
	$ins_address = $brans_obj->_address;
	$inst_thanta = $brans_obj->thana_name ;
	$ins_district = $brans_obj->distrinc_name  ;
	$ins_division = $brans_obj->division_name  ;
	$ins_web = $brans_obj->_web_address !='' ? $brans_obj->_web_address : '' ;
	$ins_email = $brans_obj->_email_add !='' ? '|| '.$brans_obj->_email_add : '' ;
	
}

 
// if($ins_logo !=''){
// 				  $image = '<img src="../../../'.$ins_logo.'" style="top:20px;height:150px; float:left;margin-left: -12px;" title="logo" alt="" id="image" />';
// 				/*  $image1 = ../../../../.$ins_logo.; */
// 				 }
$im='../../'.$ins_logo;
if(file_exists($im)){

      $image = '<img src="../../'.$ins_logo.'" style="top:20px;height:150px; float:left;margin-left: -12px;" title="logo" alt="" id="image" />';
    
}   
else{
  $image = '<img src="../../asset/custom/shadow.jpg"  />';
        
 }


require_once('../../asset/custom/tcpdf/examples/tcpdf_include.php');
require_once('../../asset/custom/tcpdf/tcpdf.php');



 $PDF_HEADER_LOGO = "logo_example.jpg";//any image file. check correct path.

$your_width=210;
$your_height=297;
$custom_layout = array($your_width, $your_height);


class MYPDF extends TCPDF {
	
	
	protected $image1 ;
	 public function setImagesrc($sr) {
		 $this->image1 = $sr;
	 }
	public function Header() {
		$this->SetAlpha(0.09);
	$this->Image($this->image1, 70, 100, 70, 100, '', '', '', true, 50);
       /*  */
	
		
		/*  */
       
     /* $this->SetAlpha(0.09);
		//$img_file = 'Untitled-1.jpg';
       $this->Image($this->image1, 70, 100, 70, 100, '', '', '', true, 50);     
      $this->SetAlpha(1); */

	 
    }
	
	
    public function Footer() {
		
		
		/*  */
		
		$this->SetFont('helvetica', 'N', 10);
		
		$this->Line(5, 290, 205, 290);
			/*  */

		
		
	
		
		//$this->Line(15, 290, 205, 290);
		//$this->Line(15, 200, 285, 200);
		
		
		$this->SetY(-7);
		$this->SetX(15);
		$by = 'Generated By:'.$_SESSION["LOGIN_USER"];
        $this->SetFont('helvetica', 'N', 8);
        $this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');
		
		$style3 = array('width' => 0.4, 'cap' => 'round', 'join' => 'round', 'dash' => '1,1', 'color' => black);
		$this->Line(9.7, 283, 35, 283, $style3);
        $this->Line(200, 283, 173, 283, $style3);
		
		$this->Text(14, 285, 'Preapared By');
        $this->Text(179, 285, 'Approved by');
		
		$this->SetY(-4);
		$this->SetX(15);
		$date = 'Printed Date:';

        $this->SetFont('helvetica', 'N', 6);
        $this->Cell(0, 5,$date.   date(" d/m/Y H\hi:s"), 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
        $this->SetY(-5);
        $this->SetFont('helvetica', 'N', 10);
		$a = 'Powered by:'.$_SESSION["powred"];
        $this->Cell(0, 5, $a, 0, false, 'C', 0, '', 0, false, 'T', 'M');
		
		$this->SetY(-7);
    // Set font
    $this->SetFont('helvetica', 'I', 8);
    // Page number
    $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');

		
		
		/*  */
		
		
		
		
		
		
		
		
		
    }
}

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $custom_layout, true, 'UTF-8', false);

$pdf->setImagesrc('../../'.$ins_logo);


// 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);




$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', '', 10);
 $pdf->AddPage();


/*  */



$tbl_header = '<table style="width: 100%;height:10%;padding-bottom:=30px"  cellspacing="">';
$tbl_footer = '</table>';
// create columns content
$tbl .= '<tr>
        <td style=" width: 20%;">
		'.$image.'
		                 
		               
						 
		</td>
        <td style=" width: 60%;">
						<h1 style="font-size: 25px;text-align: center;line-height:5px;"><b>  '.$inst_name.'</b>
						  
						</h1>
						
						<h5 style="text-align:center;font-size:14px;line-height:5px;"> '.$ins_address.' , '.$inst_thanta.' , '.$ins_district.' , '.$ins_division.'  </h5>
						 <h5 style="text-align:center;font-size:10px;line-height:10px;">'.$ins_web.'  '.$ins_email.' </h5>
				         <h5 style="text-align:center;font-size:14px;line-height:5px;">Teacher Routine</h5>
				         
		</td>
        <td style=" width:20%;">
		
		
		<tr>
		     
		<td>';
	
		$tbl.= '</td>
					</tr>
					
					
		
		</td>
        
    </tr>';
// School Code
// <h5 style="text-align:center;font-size:14px;margin-top:0px">Code:  '.$ins_code_name.' </h5>


$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, false, false, false, false, '');


$pdf->Ln(-7);

 

$table1 = "_pf_emp_personal_info e LEFT JOIN _int_common_setup cd ON(e._department_id=cd._id)
			LEFT JOIN _int_common_setup cdg ON(e._designation_id=cdg._id)
			LEFT JOIN _int_institute_setup ins ON(e._department_id=ins._id)";
$col1 = "e._full_name emp_name, cd._name emp_dep,cdg._name emp_deg";
$where1 = "e._id=$teacher_id";
$title1 = $obj->View_column_details_By_Cond($table1,$col1,$where1);
extract($title1);

$table2 = "_int_institute_setup_vw";
$col2 = "shift,medium";
$where2 = "medium_id='$medium_id' limit 1";
$title2 = $obj->View_column_details_By_Cond($table2,$col2,$where2);
extract($title2);



$tbl21.='<b>Teacher Name: '. $title1['emp_name'].' ('.$title1['emp_deg'].') | Dept :'.$title1['emp_dep'].'<br/>' .'Routine For- Shift: '.$title2['shift'].' | '.' Medium: '.$title2['medium'].'</b><br/>';


$tbl1 .= '<br/><br/>


<table>
	<thead>
		<tr>
			<th style="border: 1px solid #000000;font-size:14px;text-align:center; ">Day/Class</th>';
			$tbl2.='';
			foreach ($obj->View_All_By_Cond("_r_class_period","_medium_id='$medium_id' AND _status='A' ORDER BY _start_time ASC") AS $period_val){
			extract($period_val);
		
		$tbl2.=	'<th style="background-color:grey; border: 1px solid #000000;font-size:11px;text-align:center; " >'.$period_val['_period_name'].''; $tbl2.='<br/>
                      '.$period_val['_start_time'].''; $tbl2.='-
                      '.$period_val['_end_time'].'
		
			</th>';
		}	 
$tbl1.=$tbl2.'	</tr>
	</thead><tbody>';




	
	
		$j='0';
		foreach ($obj->View_All_By_Cond("_r_class_day","_medium_id='$medium_id' AND _status='1'") AS $day_val){
		extract($day_val);
		$j++;
		$class_day = $day_val['_day'];
		if($day_val['_day']=='1'){$day = 'Saturday';}
		else if($day_val['_day']=='2'){$day = 'Sunday';}
		else if($day_val['_day']=='3'){$day = 'Monday';}
		else if($day_val['_day']=='4'){$day = 'Tuesday';}
		else if($day_val['_day']=='5'){$day = 'Wednesday';}
		else if($day_val['_day']=='6'){$day = 'Thursday';}
		else if($day_val['_day']=='7'){$day = 'Friday';}
		$tbl1.='
		<tr>
			<th style="text-align:center;background-color:grey;font-size:14px;height:80px; border: 1px solid #000000;">
				 '.$day.' 
			</th>';

			foreach ($obj->View_All("(
			  SELECT _id, _medium_id, _section_id, _class_day, _period_id, _subject_id, _teacher_id, _teacher_type, _proxy_teacher_id, _helping_teacher_id, _break
			  FROM _r_class_routine
			  WHERE _medium_id =$medium_id AND _class_day='$class_day'  AND (_teacher_id='$teacher_id' OR _proxy_teacher_id='$teacher_id' OR _helping_teacher_id='$teacher_id') AND _status='A' GROUP BY _period_id
			UNION
			  SELECT _id, _medium_id, _section_id, _class_day, _period_id, 0 _subject_id, 0 _teacher_id, 0 _teacher_type, 0 _proxy_teacher_id, 0 _helping_teacher_id, 0 _break
			  FROM _r_class_routine
			  WHERE _medium_id =$medium_id AND _class_day='$class_day'  AND _status='A' GROUP BY _period_id
			) a GROUP BY _period_id") AS $rutine_period){
				
			extract($rutine_period);
			$rut_id = $rutine_period['_id'];
			$section_id = $rutine_period['_section_id'];
			
		if($rutine_period['_break']=='1' OR $rutine_period['_break']=='2'){
					$tbl1.='<td style="text-align:center;font-size:9px;height:80px; border: 1px solid #000000;background-color:grey;">
                              <img src="images/br.png"> 
					</td>';
				}

				else{

			$tbl1.='<td style="text-align:center;font-size:9px;height:80px; border: 1px solid #000000;">';

				
				$details_r =$obj->Details_By_Cond_for_routine("r._id='$rut_id'");
				extract($details_r);
				$me_det = $obj->View_column_details_By_Cond("_int_institute_setup_vw","shift,medium_id,medium,class,department,student_type,section","section_id='$section_id'");
				extract($me_det);
				if($rutine_period['_subject_id']=='0' AND $rutine_period['_teacher_id']=='0' AND $rutine_period['_proxy_teacher_id']=='0' AND $rutine_period['_helping_teacher_id']=='0'){
				
				$tbl1.='<img src="../../img/emty.png"> ';}
				else{

					if($details_r['_subject_full_name']!=null){
					$tbl1.='Sub:'.$details_r['_subject_full_name'].'<br/>';
					$tbl1.= ''.$details_r['_main_code_name'].''; 
			  		 $tbl1.='('.$details_r['_main_tch_type'].')<br/>';}}
			   if($me_det['class']!=null && $rutine_period['_subject_id']!='0'){
			   	$tbl1.='Class : '.$me_det['class'].'<br/>';
			   }

			   if($me_det['department']!='-'&& $rutine_period['_subject_id']!='0'){
	
			   $tbl1.='Dept :'.$me_det['department'].'<br/>';
			   }
			   if($me_det['student_type']!=null && $rutine_period['_subject_id']!='0'){
			   	$tbl1.='Type :'.$me_det['student_type'].'<br/>';
			   }
			   if($me_det['section']!=null && $rutine_period['_subject_id']!='0'){
			   	$tbl1.='Section :'.$me_det['section'].'<br/>';
			   }
			   if($details_r['_proxy_code_name']!=null && $rutine_period['_subject_id']!='0'){
			  $tbl1.=''.$details_r['_proxy_code_name'].'(P)<br/>';}
			  if($details_r['_help_code_name']!=null){
			   $tbl1.=''. $details_r['_help_code_name'].'(H)';}
				
				
			
		$tbl1.='</td>';}}
		
			 

$tbl1.='
</tr>';

}
$tbl1.='
<tbody>


		
	</table>';

$pdf->writeHTML($tbl21.$tbl1, true, true, false, false, '');


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

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

// write the first column


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

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

// write the second column


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

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

//Close and output PDF document
 $fileatt = $pdf->Output('Teacher routine.pdf', 'I');





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