0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.147.8.200


Current Path : /var/www/html/collportal/Reports/
Upload File :
Current File : /var/www/html/collportal/Reports/report_attendance_sheet.php

<?php

$main_src=substr($_SERVER['SCRIPT_FILENAME'],0,strlen($_SERVER['SCRIPT_FILENAME'])-7);
$pdf_writer_class =$main_src."/tarka_pdf_latest/fpdf.php";	
require_once($pdf_writer_class);
class batch_work_sheet extends FPDF
 {
	public $aobj_context;
	public $college_name;	
	public $town;	
	public $address;	
	public $Degree_name;	

	function Default_construstor($aobj_context)
	{
			$this->aobj_context=$aobj_context;
			
			include($this->pdf_writer_class);
				
			$this->FUNIVCODE = $aobj_context->mobj_data["univcode"];
			$this->degree = $aobj_context->mobj_data['fdegree']; 
			$this->collcode = $aobj_context->mobj_data['collcode'];
			$this->exam = $aobj_context->mobj_data['exmval']; 
			$this->subject   = $aobj_context->mobj_data["subVal"];  
			// $this->sub_name   = $aobj_context->mobj_data["sub_name"];
			$this->from_batch=  $aobj_context->mobj_data["frmBatch"] ; 
			$this->to_batch=  $aobj_context->mobj_data["toBatch"] ;
			
			$this->freeze_status=" (VERIFICATION PENDING)";
			$this->pdf=  new FPDF();
			$this->pdf=$this;	
			$this->GetMaxMarksDetails();	
			$getnumword=$aobj_context->main_src."/src/getnumword.php";
			include($getnumword);
			$get_date_time="SELECT DATE_FORMAT(now(),'%d-%b-%Y %H:%m %r') as dt";
			$ob_dt = $this->aobj_context->mobj_db->GetRow($get_date_time); 
			$this->date_timef=$ob_dt['dt'];
		}

function Header()
{
	$FUNIVCODE = $_SESSION['FUNIVCODE'];

		  $page_header_college ="select FUNIVADD1 as address,FUNIVNAME as college_name ,
								pdf_logo_path as pdf_logo_path,
								ifnull(fdegas,'Degree') as fdegas,
			ifnull(fcollas,'College') as fcollas,
			ifnull(fsubas,'Subject') as fsubas,
			ifnull(FREGROLL,'Reg. No.') as FREGROLL 
								from control ";
		 //echo $page_header_college;die();
		$lobj_page_header_college = $this->aobj_context->mobj_db->GetRow($page_header_college); 
		$this->coll_name = $lobj_page_header_college['college_name']; 
		$this->address = $lobj_page_header_college['address'];
		
		$this->fdegas = $lobj_page_header_college['fdegas'];
		$this->fcollas = $lobj_page_header_college['fcollas'];
		$this->fsubas = $lobj_page_header_college['fsubas'];
		$this->FREGROLL = $lobj_page_header_college['FREGROLL']; 
		
		$this->pdf_logo_path = $this->aobj_context->main_src."img/".$this->FUNIVCODE."_report_uni_logo.jpg"; 
		$get_college_name="select concat(FCOLLNAME,', ',FTOWN) as col_name from college where FCOLLCODE='{$this->collcode}'";
			$this->lobj_get_college_name = $this->aobj_context->mobj_db->GetRow($get_college_name);
			$this->col_name=$this->lobj_get_college_name['col_name'];
			
			$get_exam_date="select FEXAMDATE as exam_date,FEXAMNAME,fdescpn 
						from degree where FDEGREE='{$this->degree}' 
						and FEXAMNO='{$this->exam}'";
			$this->lobj_get_exam_date = $this->aobj_context->mobj_db->GetRow($get_exam_date);
			$this->exam_date=$this->lobj_get_exam_date['exam_date'];
			$this->FEXAMNAME=$this->lobj_get_exam_date['FEXAMNAME'];
			$this->degree_name=$this->lobj_get_exam_date['fdescpn'];

			$get_pract_max="select fsubshort from subject where 
				FDEGREE='{$this->degree}'
				and FEXAMNO='{$this->exam}'
				and FCSUBCODE='{$this->subject}' ";
			$lobj_get_pract_max = $this->aobj_context->mobj_db->GetRow($get_pract_max);
			$fsubshort = $lobj_get_pract_max['fsubshort'];

			$this->pdf_logo_path = $this->aobj_context->main_src."img/".$this->FUNIVCODE."_logo.jpg"; 

			if($FUNIVCODE == '052' || $FUNIVCODE == '055')
			{
				$fsubcode = $fsubshort;
			}else{
				$fsubcode = $this->subject;
			}
				
				if($FUNIVCODE == '049')
				{	
					
					if(file_exists($this->pdf_logo_path)) 
					{
					 $this->pdf->Image($this->pdf_logo_path,60,7,90,20);	   
					}	
					$this->pdf->Ln(10);

				}else if($FUNIVCODE == '055')
				{

					$this->pdf->Image($img_logo_path,30,2,140,20);
					$this->pdf->Ln(15);				}
				else
				{
					if(file_exists($this->pdf_logo_path)) 
					{
						if($FUNIVCODE == '052')
							$this->pdf->Image($this->pdf_logo_path,5,5,37,15);
						else	
							$this->pdf->Image($this->pdf_logo_path,5,7,20);	  

					}
					
					if($FUNIVCODE == '052')
					{
						$this->pdf->SetFont('Times','B',9);
						$this->pdf->Cell(0,4,"JSS MAHAVIDYAPEETHA",0,1,'C'); 
					}
					$this->pdf->SetFont('Times','B',14);
					$this->pdf->Cell(0,4,$this->coll_name,0,1,'C'); 
					$this->pdf->SetFont('Times','',8);	
					$this->pdf->Cell(0,4,$this->address,0,0,'C'); 
				}

				if($FUNIVCODE != '055')
				{
					$this->pdf->SetFont('Times','',10);	
					$this->pdf->Cell(0,4,"Page {$this->pdf->PageNo()}/{nb}",0,1,'R'); 
					$this->pdf->Ln(5);
					$this->pdf->SetFont('Times','B',10);
					$this->pdf->Cell(0,4,$this->fcollas." : ".$this->collcode." ".$this->col_name,0,1,'C');
				}

				//$this->pdf->Ln(2);
				$this->pdf->SetFont('Times','BU',10);
				$this->pdf->Cell(0,5,'Practical Attendance Sheet',0,1,'C');
				$this->pdf->SetFont('Times','',10);

			
				$this->pdf->Cell(0,4,$this->fdegas." : ".$this->degree." - ".$this->degree_name,0,1,'C');
				$this->pdf->Cell(0,4," Exam : {$this->FEXAMNAME} - ".$this->exam_date,0,1,'C');
				//$this->pdf->Ln(2);
				$this->pdf->Cell(0,4,$this->fsubas." : ".$fsubcode." - ".$this->sub_name."(".$this->fs_sub_name.")",0,1,'C');
				$this->pdf->Ln(2); 
				
			
			$this->pdf->SetFont('Times','B',12);					
			$this->pdf->Ln(3); 	  
}	
function GetMaxMarksDetails()
{
	$get_pract_max="select FSMAXMARKS from subject where 
				FDEGREE='{$this->degree}'
				and FEXAMNO='{$this->exam}'
				and FCSUBCODE='{$this->subject}' ";
	$lobj_get_pract_max = $this->aobj_context->mobj_db->GetRow($get_pract_max);
	$this->pract_max_marks=$lobj_get_pract_max['FSMAXMARKS'];
	$get_vival_sub=" select FVVCODE from  practical_master
					where FDEGREE='{$this->degree}'
				and FEXAMNO='{$this->exam}'
				and FPRCODE='{$this->subject}'";
		$lobj_get_vival_sub = $this->aobj_context->mobj_db->GetRow($get_vival_sub);	
	$viva_sub=	$lobj_get_vival_sub['FVVCODE'];
$get_pract_max="select FSMAXMARKS from subject where 
				FDEGREE='{$this->degree}'
				and FEXAMNO='{$this->exam}'
				and FCSUBCODE='{$viva_sub}' ";
	$lobj_get_pract_max = $this->aobj_context->mobj_db->GetRow($get_pract_max);
	$this->viva_max_marks=$lobj_get_pract_max['FSMAXMARKS'];	
}

	 
	function GetQuery()
	{		
		
		$FUNIVCODE = $_SESSION['FUNIVCODE'];
				$get_practical_records = "select lpad(FBATCH,2,'0') as FBATCH,sub.FCSUBCODE,sub.FSUBNAME,stu.FREGNO, stu.FNAME ,FSUBNAME,FSSUBNAME
					 
						FROM student stu inner join marks_pr mak ON stu.FREGNO=mak.FREGNO 
						and mak.Fdegree='{$this->degree}' and mak.Fexamno='{$this->exam}' and mak.FCOLLCODE='{$this->collcode}'
						inner join subject sub on sub.FCSUBCODE = mak.FSUBCODE 
						and sub.FCSUBCODE='{$this->subject}' 
						and sub.FDEGREE='{$this->degree}' and sub.FEXAMNO='{$this->exam}'					 
						WHERE stu.FREGNO != '' 
						and ifnull(stu.fdeleted,'') <> 'T'
						and FBATCH>='{$this->from_batch}' and FBATCH<='{$this->to_batch}'
						group by stu.FREGNO,sub.FCSUBCODE,FBATCH  order by IFNULL(mak.FBATCH, ''),stu.FREGNO";
				//  var_dump($get_practical_records);die();
				$this->lobj_get_practical_records = $this->aobj_context->mobj_db->GetAll($get_practical_records);
				
				 
				$this->header_subject=$FCSUBCODE;
				$this->header_sub_name=$sub_name;
				$this->pdf->SetMargins(10,5);
					$get_viva_details=" select  FVVCODE from  practical_master where FDEGREE='{$this->degree}'
							and FEXAMNO='{$this->exam}' and FPRCODE='{$this->subject}' ";
				$lobj_get_viva_details = $this->aobj_context->mobj_db->GetRow($get_viva_details);
				$FVVCODE=$lobj_get_viva_details['FVVCODE'];
				 
				//echo $get_viva_details;die();
			
				//print_r($this->viva_marks_arr);die();
				$sl_no=1;
				$this->batch_details=array();
				$c=0;
				foreach($this->lobj_get_practical_records as $k=>$v)
				{
					$reg_no=$v['FREGNO'];
					$FBATCH=$v['FBATCH'];
					$name[$v['FREGNO']]=$v['FNAME'];
					$this->sub_name=$v['FSUBNAME'];
					$this->fs_sub_name=$v['FSSUBNAME'];
					$this->batch_details[$FBATCH]['details'][$c]=$reg_no;
					$this->batch_details[$FBATCH]['cnt']+=1;
					$c++;
				}
			 
				$regname = "Reg. No.";
				if($FUNIVCODE == '049')
					$regname = "USN";
				
				if($FUNIVCODE == '052')
					$width = ["8",'27','60','23','23','20','18'];
				else
					$width = ["12",'33','80','25','25','23'];

			foreach($this->batch_details as $k=>$v)
			{
					$this->pdf->SetFont('Times','B',10);	
					$batch_no=$k;
					$get_date_time="select concat(' Date : ',date_format(ifnull(FEXAMDATE,'00/00/0000'),'%d/%m/%Y'),' Time : ',ifnull(FEXAMTIME,'')) as 
								batch_date_time,
								froomname,
								if(ifnull(m1.fteachcode,'') = '',ifnull(fexaminer1,''),m1.fteachname) as fexaminer1,
								if(ifnull(m2.fteachcode,'') = '',ifnull(fexaminer2,''),m2.fteachname) as fexaminer2,
								if(ifnull(m3.fteachcode,'') = '',ifnull(fexaminer3,''),m3.fteachname) as fexaminer3,
								if(ifnull(m4.fteachcode,'') = '',ifnull(fexaminer4,''),m4.fteachname) as fexaminer4,
								if(ifnull(m5.fteachcode,'') = '',ifnull(fexaminer5,''),m5.fteachname) as fexaminer5
								
								from practical_entry_freeze p
								left join masteach m1 on m1.fteachcode = fexaminer1
								left join masteach m2 on m2.fteachcode = fexaminer2
								left join masteach m3 on m3.fteachcode = fexaminer3
								left join masteach m4 on m4.fteachcode = fexaminer4
								left join masteach m5 on m5.fteachcode = fexaminer5

 								where p.FCOLLCODE='{$this->collcode}'
								and p.FDEGREE='{$this->degree}'
								and p.FEXAM='{$this->exam}'
								and lpad(p.FBATCH,2,'0')='{$batch_no}'
								and p.FCSUBCODE='{$this->subject}' ";

					//var_dump($get_date_time);			
					$lobj_get_date_time = $this->aobj_context->mobj_db->GetRow($get_date_time);	
 					$date_time = $lobj_get_date_time['batch_date_time'];
					$froomname = $lobj_get_date_time['froomname'];

					$fexaminer1 = $lobj_get_date_time['fexaminer1'];
					$fexaminer2 = $lobj_get_date_time['fexaminer2'];
					$fexaminer3 = $lobj_get_date_time['fexaminer3'];
					$fexaminer4 = $lobj_get_date_time['fexaminer4'];
					$fexaminer5 = $lobj_get_date_time['fexaminer5'];

					$sl_no=1;
					$batch_cnt=$v['cnt'];
					$batch_details=$v['details'];
					$this->pdf->AddPage();
					$this->pdf->Rect(4,03,205,280);
					$this->pdf->SetMargins(10,5);
					if($froomname != '')
						$this->pdf->Cell(176,5,"Room Name :$froomname","",1,'C');
					$this->pdf->Cell(176,5,"Batch :{$batch_no} {$date_time}","",1,'C');
					$this->pdf->Cell($width[0],5,'Sl.',"LRT",0,'C');
					$this->pdf->Cell($width[1],5,'',"LRT",0,'C');
					$this->pdf->Cell($width[2],5,'',"LRT",0,'C');
					$this->pdf->Cell($width[3],5,'Main',"LRT",0,'C');
					$this->pdf->Cell($width[4],5,'Additional',"LRT",0,'C');
					if($FUNIVCODE == '052')
					{
						$this->pdf->Cell($width[6],5,'Graph ',"LRT",0,'C');
						$this->pdf->Cell($width[6],5,'Semi-Log ',"LRT",0,'C');
					}

					$this->pdf->Cell($width[5],5,'',"LRT",1,'C');
					/* $this->pdf->Cell(50,5,"({$this->subject}) Practical","LRT",1,'C');
					$this->get_x_pos=$this->pdf->GetX();
					$this->get_y_pos=$this->pdf->GetY();
					if(!empty($FVVCODE))
					{
					$this->pdf->SetXY($this->get_x_pos+115,$this->get_y_pos-5);
					$this->pdf->Cell(50,5,"({$FVVCODE}) Record","LRT",1,'C');
					}
					*/		
					$this->get_x_pos=$this->pdf->GetX();
					$this->get_y_pos=$this->pdf->GetY();
					$this->pdf->Cell($width[0],5,'No.',"LRB",0,'C');
					$this->pdf->Cell($width[1],5,$this->FREGROLL,"LRB",0,'C');
					$this->pdf->Cell($width[2],5,'Name',"LRB",0,'C');
					$this->pdf->Cell($width[3],5,'Ans. Book No.',"LRB",0,'C'); 
					$this->pdf->Cell($width[4],5,'Ans. Book No.',"LRB",0,'C'); 
					if($FUNIVCODE == '052')
					{
						$this->pdf->Cell($width[6],5,'Sheet No.',"LRB",0,'C');
						$this->pdf->Cell($width[6],5,'Sheet No.',"LRB",0,'C');
					}
					$this->pdf->Cell($width[5],5,'Signature.',"LRB",1,'C');
						
			/* 	if(!empty($FVVCODE))
				{
				$this->pdf->SetXY($this->get_x_pos+115,$this->get_y_pos);
					$this->pdf->Cell(80,5," (Max: {$this->viva_max_marks})","LRB",1,'C');
				} */
				foreach($batch_details as $bv)
				{
				
					$nb =0;
					$yH =0;
					$reg_no=$bv;
					$nb=max($nb,NbLines($width[2],$name[$reg_no],$this->pdf));
					if($nb >1)
					{	
						// $yH = 4+$nb;
						$yH = 5*$nb;
						
					}
					else
						$yH = 6*$nb;
					
						
					$this->pdf->SetFont('Times','',9);	
					
					// if($nb >1) 
					// {
					// 	var_dump($yH);
					// 	var_dump($reg_no);
					// 	var_dump($name[$reg_no]);
					
					// }	
					$this->pdf->Cell($width[0],$yH,$sl_no,"1",0,'C');
					$this->pdf->Cell($width[1],$yH,$reg_no,"1",0,'C');
					//$this->pdf->Cell(60,6,$name[$reg_no],"1",0,'L');
					$x=$this->pdf->GetX();
					$y=$this->pdf->GetY();
					//Draw the border
					
					$this->pdf->Rect($x,$y,$width[2],$yH);
					if($nb >1) 
						$yx = 4;
					else
						$yx	= $yH;
					$this->pdf->MultiCell($width[2],$yx,$name[$reg_no],0,'L');
					
					$this->pdf->SetXY($x+$width[2],$y);
					$this->pdf->Cell($width[3],$yH,'',"1",0,'C');
					$this->pdf->Cell($width[4],$yH,'',"1",0,'C');
					if($FUNIVCODE == '052')
					{
						$this->pdf->Cell($width[6],$yH,'',"1",0,'C');
						$this->pdf->Cell($width[6],$yH,'',"1",0,'C');
					}
					$this->pdf->Cell($width[5],$yH,'',"1",1,'C');
					/* $this->pdf->Cell(50,6,'',"1",1,'C');
					$y_pos=$this->pdf->GetY();
					if(!empty($FVVCODE))
					{
					$this->pdf->SetXY($this->get_x_pos+115,$y_pos-6);
					$this->pdf->Cell(50,6,'',"1",1,'C');
					} */
					if($this->pdf->GetY()>210)
					{
						$this->WriteFooter($fexaminer1,$fexaminer2,$fexaminer3,$fexaminer4,$fexaminer5);
						$this->pdf->AddPage();
						$this->pdf->Rect(4,03,205,280);
						$this->pdf->SetFont('Times','B',12);	
						$this->pdf->SetMargins(10,5);
						if($froomname != '')
							$this->pdf->Cell(176,5,"Room Name :$froomname","",1,'C');
						$this->pdf->Cell(176,5,"Batch :{$batch_no} {$date_time}","",1,'C');
						
						$this->pdf->Cell($width[0],5,'Sl.',"LRT",0,'C');
						$this->pdf->Cell($width[1],5,'',"LRT",0,'C');
						$this->pdf->Cell($width[2],5,'',"LRT",0,'C');
						$this->pdf->Cell($width[3],5,'Main',"LRT",0,'C');
						$this->pdf->Cell($width[4],5,'Additional',"LRT",0,'C');
						if($FUNIVCODE == '052')
						{
							$this->pdf->Cell($width[6],5,'Graph ',"LRT",0,'C');
							$this->pdf->Cell($width[6],5,'Semi-Log ',"LRT",0,'C');
						}
						$this->pdf->Cell($width[5],5,'',"LRT",1,'C');
						$this->get_x_pos=$this->pdf->GetX();
						$this->get_y_pos=$this->pdf->GetY();
					
						$this->pdf->Cell($width[0],5,'No.',"LRB",0,'C');
						$this->pdf->Cell($width[1],5,$this->FREGROLL,"LRB",0,'C');
						$this->pdf->Cell($width[2],5,'Name.',"LRB",0,'C');
						$this->pdf->Cell($width[3],5,'Ans. Book No.',"LRB",0,'C'); 
						$this->pdf->Cell($width[4],5,'Ans. Book No.',"LRB",0,'C'); 
						if($FUNIVCODE == '052')
						{
							$this->pdf->Cell($width[6],5,'Sheet No.',"LRB",0,'C');
							$this->pdf->Cell($width[6],5,'Sheet No.',"LRB",0,'C');
						}
						$this->pdf->Cell($width[5],5,'Signature.',"LRB",1,'C');
					}
					$sl_no++;
				}
			
					$this->WriteFooter($fexaminer1,$fexaminer2,$fexaminer3,$fexaminer4,$fexaminer5); 
					$this->pdf->Ln(3);	
			}
	}
	function WriteFooter($fexaminer1,$fexaminer2,$fexaminer3,$fexaminer4,$fexaminer5)
	{
		$this->pdf->Ln(6);
		$X_pos=$this->pdf->GetX();
		$FUNIVCODE = $_SESSION['FUNIVCODE'];
		$this->pdf->SetFont('Arial','',8);
		$this->pdf->SetX($X_pos+15);		
		$this->pdf->Ln(3);$this->pdf->SetFont('Arial','',9);
		$this->pdf->Cell(35,6,'',"",0,'C');
		
		/* $this->pdf->Cell(30,6,'Examiner - 03',"",0,'C');
		$this->pdf->Cell(30,6,'Examiner - 04',"",1,'C'); */


		if($FUNIVCODE == '049')
		{
			$this->pdf->Cell(40,6,'Examiner - 01',"",0,'C');
			$this->pdf->Cell(40,6,'Examiner - 02',"",1,'C');
			
		}else
		{
			$this->pdf->Cell(33,6,'Examiner - 01',"",0,'L');
			$this->pdf->Cell(33,6,'Examiner - 02',"",0,'L');
			if($fexaminer3 != '')
				$this->pdf->Cell(33,6,'Examiner - 03',"",0,'L');
			if($fexaminer4 != '')
				$this->pdf->Cell(33,6,'Examiner - 04',"",0,'L');
			if($fexaminer5 != '')
				$this->pdf->Cell(33,6,'Examiner - 05',"",0,'L');
				
			$this->pdf->Cell(1,6,'',"",1,'L');	

		}

		$this->pdf->Cell(8,6,'',"",0,'C');
		$this->pdf->Cell(25,6,'Name',"",0,'L');
		$this->pdf->Cell(3,6,':',"",0,'C');	

		if($FUNIVCODE == '049')
		{
			$this->pdf->Cell(40,6,$fexaminer1,"",0,'C');
			$this->pdf->Cell(40,6,$fexaminer2,"",1,'C');
			
		}else
		{
			$this->pdf->SetFont('Arial','',7);
			$this->pdf->Cell(33,6,$fexaminer1,"",0,'L');
			$this->pdf->Cell(33,6,$fexaminer2,"",0,'L');
		
			$this->pdf->Cell(33,6,$fexaminer3,"",0,'L');
			$this->pdf->Cell(33,6,$fexaminer4,"",0,'L');
			$this->pdf->Cell(33,6,$fexaminer5,"",1,'L');

		}
		$this->pdf->SetFont('Arial','',9);
		$this->pdf->Cell(8,6,'',"",0,'C');
		$this->pdf->Cell(25,6,'College / Degn',"",0,'L');
		$this->pdf->Cell(3,6,':',"",1,'C');
		
		$this->pdf->Cell(8,6,'',"",0,'C');
		$this->pdf->Cell(25,6,'Signature',"",0,'L');
		$this->pdf->Cell(3,6,':',"",1,'C');
		
		$this->pdf->Cell(8,6,'',"",0,'C');
		$this->pdf->Cell(25,6,'Date & Time',"",0,'L');
		$this->pdf->Cell(3,6,':',"",0,'C');		
		$this->pdf->Cell(50,3,$pdf->date_1,'0',1,'L'); 
		$this->pdf->Ln(9);
		$this->pdf->SetX($X_pos+15);
		
		$this->pdf->Ln(5);
	}
   	function Footer()
	{
			$this->ip=$_SERVER["REMOTE_ADDR"];	
			$this->pdf->SetFont('Arial','',8);  
			$this->pdf->setY(-20);
		 	//$this->pdf->Cell(90,3,'Printed Date & Time: '.$this->date_timef,'0',0,'L');
			$this->pdf->Cell(140,6,'Printed   : IP Address : '.$this->ip." Date ".$this->date_timef,'0',0,'L');

	}	

	function SendOutput()
	{
		$this->pdf->Output("batch_work_sheet_{$this->report_id}.pdf","I");
	}
}
		
function GenerateAttendanceSheets($aobj_context)
{
	// var_dump("Sdksdhsdk");die();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$class_obj=new batch_work_sheet(); 
	$class_obj->AliasNbPages();
	$class_obj->Default_construstor($aobj_context); 
	$class_obj->GetQuery();
	$class_obj->SendOutput();
}

function NbLines($w,$txt,$pdf)
{
    //Computes the number of lines a MultiCell of width w will take
    $cw=&$pdf->CurrentFont['cw'];
    if($w==0)
        $w=$pdf->w-$pdf->rMargin-$pdf->x;
    $wmax=($w-2*$pdf->cMargin)*1000/$pdf->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 and $s[$nb-1]=="\n")
        $nb--;
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $nl=1;
    while($i<$nb){
        $c=$s[$i];
        if($c=="\n"){
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
            continue;
        }
        if($c==' ')
            $sep=$i;
        $l+=$cw[$c];
        if($l>$wmax){
            if($sep==-1){
                if($i==$j)
                    $i++;
            } else
                $i=$sep+1;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
        } else
            $i++;
    }
    return $nl;
 }
?>