<?php

Widgets('all');
Widgets('mailing_labels');
Widgets('document_template');
$addition['force_search'] = true;

if(!$_REQUEST['search_servicefunction'] || $_REQUEST['search_servicefunction']=='search' || $_SYSTEM['modules_search']){
	DisplayHeader(".:".ProgramTitle().":.");
	$addition['new'] = true;
	$addition['action'] .= "&CREATEPDF=true";
	Search('student_id',$addition);
}
else
{
	// For the Student Fees / Student Payments programs
	$_REQUEST['print_statements'] = true;
	if($_REQUEST['mailing_labels']=='Y')
		$addition['group'][] = 'ADDRESS_ID';	
	
	$array = get_student_list($addition);

	if(count($array))
	{
		$handle = PDFStart();
		foreach($array as $student)
		{
			if($_REQUEST['mailing_labels']=='Y')
			{
				foreach($student as $address)
				{
					echo '<BR><BR><BR>';
					unset($_SYSTEM['DisplayHeader']);
					$_REQUEST['DrawAlign'] = 'ALIGN_LEFT';
	    				DisplayHeader(_('Statement'),null,null,null,null,null,null,true);
					DisplayHeader($address['FULL_NAME'].' ('.$address['STUDENT_ID'].')');
					DisplayHeader(_('Class Level').': '.$address['CLASSLEVEL_ID']);
					DisplayHeader(get_school(get_school_id()));
					DisplayHeader(ProperDate(get_db_date()));
					unset($_REQUEST['DrawAlign']);
					echo '<BR><BR><TABLE width=100%><TR><TD width=50> &nbsp; </TD><TD>'.$address[1]['MAILING_LABEL'].'</TD></TR></TABLE><BR>';
					
					$_SESSION['student_id'] = $address['STUDENT_ID'];
					include($staticpath.'modules/mod_billing/BilStudFeesList.php');
					include($staticpath.'modules/mod_billing/BilStudPaysList.php');
					DrawTemplateHeaders($student_id,'footer');
					echo '<!-- NEW PAGE -->';				
				}
			}
			else
			{
				$_SESSION['student_id'] = $student['STUDENT_ID'];
				unset($_SYSTEM['DisplayHeader']);
				$_REQUEST['DrawAlign'] = 'ALIGN_LEFT';
				DisplayHeader(_('Statement'),null,null,null,null,null,null,true);
				DisplayHeader($student['FULL_NAME'].' ('.$student['STUDENT_ID'].')');
				DisplayHeader(_('Class Level').': '.$student['CLASSLEVEL_ID']);
				DisplayHeader(get_school(get_school_id()));
				DisplayHeader(ProperDate(get_db_date()));
				unset($_REQUEST['DrawAlign']);
				include($staticpath.'modules/mod_billing/BilStudFeesList.php');
				include($staticpath.'modules/mod_billing/BilStudPaysList.php');
				DrawTemplateHeaders($student_id,'footer');
				echo '<!-- NEW PAGE -->';
			}
		}
		unset($_SESSION['student_id']);
		PDFStop($handle);
	}
	else
		BackPrompt(_('No Students were found.'));
}
?>