<?php require "_header.php";?>
<script language="javascript" type="text/javascript">
document.getElementById("main-content").style.display = 'none';
</script>
<div id="main-report" align="center">
<style type="text/css">
	.table-report{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
		text-align:center;
		border-right:0px none;
		border-bottom:0px none;
	}
	.table-report-inner{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
	}
	.table-report tr{
		padding:5px 5px 5px 5px;
	}
	.table-report td{
		padding:5px 5px 5px 5px;
		border-top:0px none;
		border-left:0px none;
	}
	.table-report th{
		padding:5px 5px 5px 5px;
		font-weight:bold;
		text-align:center;
		border-top:0px none;
		border-left:0px none;
	}	
	.college_name{
		font-family:QTAbbie;
		font-size:22px;	
		font-weight:bold;
		padding:2px 2px 2px 2px;
		text-align:center;
	}
	.college_address{
		font-family:Tahoma, Geneva, sans-serif;
		font-size:11px;	
		text-align:center;
		padding:2px 2px 2px 2px;
	}
	.report_name{
		font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
		font-size:13px;	
		background-color:#CCC;
		text-align:center;
		font-weight:bold;
		padding:2px 2px 2px 2px;
	}
</style>
<?php 
	//$header_row_string="Hall Ticket";
	
	$branch_id 		 = Escape($_REQUEST['branch_hidden']);
	$semester_id 	   = Escape($_REQUEST['semester_hidden']);
	$division_id 	   = Escape($_REQUEST['division_id']);
	$exam_id 		   = Escape($_REQUEST['exam_hidden']); 
	$student_id		= Escape($_REQUEST['student_hidden']); 
	$test 			  = ($_REQUEST['test'] == "First Test") ? 'f' : 'r'; 
	$gturegno_start 	= Escape($_REQUEST['gturegno_start']);
	$gturegno_end 	  = Escape($_REQUEST['gturegno_end']); 
	$branch_disp 	   = Escape($_REQUEST['branch_disp']);
	$semester_disp	 = Escape($_REQUEST['semester_disp']);
	$exam_name 		 = Escape($_REQUEST['exam_disp']);
	$test_name 		 = Escape($_REQUEST['test']);
	$subject_type 	  = Escape($_REQUEST['subject_type']);
	
	
	/* START CONDITION CODE */ 
	$where = "";
	if($student_id != "" && $student_id != "undefined")
		$where .= " AND sm.student_id = $student_id ";
		
	if($gturegno_start != "" && $gturegno_start != "Start From")
		$where .= " AND sm.student_gturegno >= $gturegno_start ";	
		
	if($gturegno_end != "" && $gturegno_end != "End To")
		$where .= " AND sm.student_gturegno <= $gturegno_end ";
		
	
	
		 
	if($branch_id == "" && $semester_id == "" && $exam_id == ""){?>
		<script language="javascript" type="text/javascript">
			location.href='report-hallticket.php';
		</script><?php
	}
	
	if($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])){
		ob_start();
		$i=1;
		if($test == "f"){
			
			/* START SUBJECT DATA */
			$sql_subject = "
				SELECT
					sm.subject_id,
					sm.subject_name,
					es.daydate,
					es.daytime
				FROM
					cms_subjectmaster sm,
					cms_examschedule es
				WHERE
					es.subject_id = sm.subject_id AND	
					sm.branch_id = ".$branch_id." AND	
					sm.semester_id = ".$semester_id." AND	
					es.branch_id = ".$branch_id." AND	
					es.semester_id = ".$semester_id." AND	
					es.exam_id = ".$exam_id." AND				
					es.college_id = ".$_SESSION['VedantnrCollegeId']." AND
					es.year_id = ".$_SESSION['aYearId']." AND
					es.test_type = '".$test."' AND	 
					sm.college_id = ".$_SESSION['VedantnrCollegeId'];
				
			
			if($subject_type!= "Both")
			{
				if($subject_type=='Theory')
				{
					$sql_subject .= " AND sm.subject_practical='0'";
				
				}else if($subject_type=='Practical')
				{
					$sql_subject .= " AND sm.subject_practical='1' ";
				}
			}
			$sql_subject .= " ORDER BY es.daydate ASC, sm.subject_id ASC ";	
			
			
			$res_subject = dbQuery($sql_subject);	
			
			$arr_subject = array();
			$i = 0;
			
			if(dbRows($res_subject) > 0)
			{
				while($rec_subject = dbArray($res_subject))
				{
					$arr_subject[$i]['subject_name'] = $rec_subject['subject_name'];
					$arr_subject[$i]['daydate'] 	 = date("d/m/Y",strtotime($rec_subject['daydate']));
					$arr_subject[$i]['daytime'] 	 = $rec_subject['daytime'];
					$i++;
				}
			}	
			/* END SUBJECT DATA */
			
			/* START STUDENT DATA */
			$sql_student = "
				SELECT
					sm.student_id,
					sm.student_gturegno,
					CONCAT(sm.student_surname,' ',sm.student_firstname,' ',SUBSTR(sm.student_lastname, 1, 1),'.') AS student_name
				FROM
					cms_studentmaster sm,
					cms_studentdetail sd
				WHERE
					sm.student_id = sd.student_id AND
					
					sm.student_active = 1 AND 
					sd.cur_branchid = ".$branch_id." AND
					sd.cur_semesterid = ".$semester_id." AND
					sd.cur_divison = '".$division_id."' AND
					sd.year_id = ".$_SESSION["VedantnrYearId"];
					
			if($where != ""){
				$sql_student .= $where;	
			}
			$sql_student .= " ORDER BY sm.student_gturegno ASC ";	
			$res_student = dbQuery($sql_student);	
			
			if(dbRows($res_student)>0){
			while($rec_student = dbArray($res_student))
			{
				$student_id = $rec_student['student_id'];
				$student_gturegno = $rec_student['student_gturegno'];
				$student_name = $rec_student['student_name'];?>
                	
                    <div style="height:33%;min-height:33%;visibility:visible" >
                    <div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
                    <div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
                    <div class="report_name">Hall Ticket</div>
                    
                    <table width="100%" class="table-report-inner" border="0" cellpadding="2" cellspacing="2">
                    <tr>
                        <td width="50%" align="left"><b>Enrollment No</b> : <?php echo $student_gturegno; ?></td>
                        <td width="50%" align="right"><b>Exam</b> : <?php echo $exam_disp." - ".$test_name; ?></td>
                    </tr>
                    <tr>
                        <td align="left"><b>Student Name</b> : <?php echo $student_name; ?></td>
                        <td align="right"><b>Branch</b> : <?php echo $branch_disp." - ".$semester_disp." - ".$division_id; ?></td>
                    </tr>
					</table>
                    
                    <br />
                    
                    <table width="100%" class="table-report" border="1" cellpadding="0" cellspacing="0">
                    <tr>
                    	<th width="10%">Date</th>
                        <th width="10%">Time</th>
                        <th width="40%">Subject</th>
                        <th width="20%">Supervisor Sign</th>
                        <th width="20%">Student Sign</th>
                    </tr>
                    <?php
                    	for($i = 0; $i < count($arr_subject); $i++)
						{
							?>
                            <tr>
                            	<td><?php echo $arr_subject[$i]['daydate']; ?></td>
                                <td><?php echo $arr_subject[$i]['daytime']; ?></td>
                                <td style="text-align:left"><?php echo $arr_subject[$i]['subject_name']; ?></td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <?php
						}
					?>
                    </table>
                    <table width="100%" class="table-report-inner" border="0">
                    <tr style="height:40px;">
                        <td width="50%">&nbsp;</td>
                        <td width="50%">&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="left">Institute Seal</td>
                        <td align="right">Officer's Sign</td>
                    </tr>
					</table>
                   </div>
                <?php
			}
			$HtmlCode= ob_get_contents();
			ob_end_flush();
			$HtmlUrl  =	"hallticket-report.html";
			$HtmlPath =	"report/".$HtmlUrl;
			createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode);
		?>
		<br/>
		<form name="frm" id="frm" action="" method="post">		
			<input type="hidden"   name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
            <input type="button"  name="btnPrint" id="btnPrint" value="Print" onClick="SetPageAction('PRINT');"/>
			<input type="button"  name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');"/>
			<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');"/>
			<input type="button" name="btnWord" id="btnWord" value="Create WORD" onClick="SetPageAction('WORD');"/>
			<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onClick="SetPageAction('Excel');"/>
		</form>
		<script language="javascript" type="text/javascript">
            function SetPageAction(varAction) {
                if(varAction=="PRINT"){			
                    document.frm.action="print/create-print.php";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="PDF"){			
                    document.frm.action="convertpdf/create-pdf.php";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="HTML"){
                    document.frm.action="<?php echo $HtmlPath; ?>";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="WORD"){
                    document.frm.action="convertword/create-word.php";
                    document.frm.target="_blank";
                    document.frm.submit();
                }
                else if(varAction=="Excel"){
                    document.frm.action="convertword/create-excel.php";
                    document.frm.target="_blank";
                    document.frm.submit();
                }
            }
        </script><?php
		}
			else{
			echo "No data found for selected criteria.";	
		}	
			/* END STUDENT DATA */
			
		} else if($test == "r"){
			/* START STUDENT DATA */
			$sql_student = "
				SELECT
					sm.student_id,
					sm.student_gturegno,
					CONCAT(sm.student_surname,' ',sm.student_firstname,' ',SUBSTR(sm.student_lastname, 1, 1),'.') AS student_name,
					GROUP_CONCAT(rm.subject_id) AS subject_id
				FROM
					cms_studentmaster sm,
					cms_studentdetail sd,
					cms_resultmaster rm
				WHERE
					sm.student_id = sd.student_id AND
					sm.student_id = rm.student_id AND
					
					sm.student_active = 1 AND 
					sd.cur_branchid = ".$branch_id." AND
					sd.cur_semesterid = ".$semester_id." AND
					sd.cur_divison = '".$division_id."' AND
					rm.result = 'Fail' AND
					rm.branch_id = ".$branch_id." AND
					rm.semester_id = ".$semester_id." AND
					rm.exam_id = ".$exam_id." AND
					rm.year_id = ".$_SESSION["VedantnrYearId"]." AND
					sd.year_id = ".$_SESSION["VedantnrYearId"];
					
			if($where != ""){
				$sql_student .= $where;	
			}
			
			
			$sql_student .= " GROUP BY rm.student_id ORDER BY sm.student_gturegno ASC ";	
			$res_student = dbQuery($sql_student);		
					
			if(dbRows($res_student)>0){
				while($rec_student = dbArray($res_student))
				{
					$student_id = $rec_student['student_id'];
					$student_gturegno = $rec_student['student_gturegno'];
					$student_name = $rec_student['student_name'];
					
					$subject_id = $rec_student['subject_id'];
					
					/* START SUBJECT DATA */
					$sql_subject = "
						SELECT
							sm.subject_id,
							sm.subject_name,
							es.daydate,
							es.daytime
						FROM
							cms_subjectmaster sm,
							cms_examschedule es
						WHERE
							es.subject_id = sm.subject_id AND
							sm.subject_id IN (".$subject_id.") AND
							sm.branch_id = ".$branch_id." AND	
							sm.semester_id = ".$semester_id." AND	
							es.branch_id = ".$branch_id." AND	
							es.semester_id = ".$semester_id." AND	
							es.exam_id = ".$exam_id." AND				
							es.college_id = ".$_SESSION['VedantnrCollegeId']." AND
							es.year_id = ".$_SESSION['aYearId']." AND
							es.test_type = '".$test."' AND	 
							sm.college_id = ".$_SESSION['VedantnrCollegeId'];
					
						if($subject_type!= "Both")
						{
							if($subject_type=='Theory')
							{
								$sql_subject .= " AND sm.subject_practical='0'";
							
							}else if($subject_type=='Practical')
							{
								$sql_subject .= " AND sm.subject_practical='1' ";
							}
						}
				
					$sql_subject .= " ORDER BY sm.subject_id ASC ";	
					$res_subject = dbQuery($sql_subject);	
					
					$arr_subject = array();
					$i = 0;
					
					if(dbRows($res_subject) > 0)
					{
						while($rec_subject = dbArray($res_subject))
						{
							$arr_subject[$i]['subject_name'] = $rec_subject['subject_name'];
							$arr_subject[$i]['daydate'] 	 = date("d/m/Y",strtotime($rec_subject['daydate']));
							$arr_subject[$i]['daytime'] 	 = $rec_subject['daytime'];
							$i++;
						}
					}	
					/* END SUBJECT DATA */
					
					
					
					?>
                    <div style="height:50%;min-height:50%;visibility:visible" >
						<div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
						<div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
						<div class="report_name">Hall Ticket</div>
						
						<table width="100%" class="table-report-inner" border="0" cellpadding="2" cellspacing="2">
						<tr>
							<td width="50%" align="left"><b>Enrollment No</b> : <?php echo $student_gturegno; ?></td>
							<td width="50%" align="right"><b>Exam</b> : <?php echo $exam_disp." - ".$test_name; ?></td>
						</tr>
						<tr>
							<td align="left"><b>Student Name</b> : <?php echo $student_name; ?></td>
							<td align="right"><b>Branch</b> : <?php echo $branch_disp." - ".$semester_disp." - ".$division_id; ?></td>
						</tr>
						</table>
						
						<br />
						
						<table width="100%" class="table-report" border="1" cellpadding="0" cellspacing="0">
						<tr>
							<th width="20%">Date</th>
							<th width="20%">Time</th>
							<th width="20%">Subject</th>
							<th width="20%">Supervisor Sign</th>
							<th width="20%">Student Sign</th>
						</tr>
						<?php
						$NOOFRES=count($arr_subject);
							for($i = 0; $i < count($arr_subject); $i++)
							{
								?>
								<tr>
									<td><?php echo $arr_subject[$i]['daydate']; ?></td>
									<td><?php echo $arr_subject[$i]['daytime']; ?></td>
									<td><?php echo $arr_subject[$i]['subject_name']; ?></td>
									<td>&nbsp;</td>
									<td>&nbsp;</td>
								</tr>
								<?php
							}
							
							$totalfees = $RetestFeePerSub * $NOOFRES;
			
							if($totalfees > $RetestFeeMax){
								$retestfee = $RetestFeeMax;
							} else{
								$retestfee = $totalfees;
							}
						?>
						</table>
                        <div style="float:right">Retest Fees:&nbsp;<?php echo $retestfee; ?></div>
						<table width="100%" class="table-report-inner" border="0">
						<tr style="height:50px;">
							<td width="50%">&nbsp;</td>
							<td width="50%">&nbsp;</td>
						</tr>
						<tr>
							<td align="left">Institute Seal</td>
							<td align="right">Officer's Sign</td>
						</tr>
						</table>
                        <br/>
                       </div>
					<?php
				}
				$HtmlCode= ob_get_contents();
				ob_end_flush();
				$HtmlUrl  =	"hallticket-report.html";
				$HtmlPath =	"report/".$HtmlUrl;
				createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode);
			?>
			<br/>
			<form name="frm" id="frm" action="" method="post">		
				<input type="hidden"   name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
				<input type="button"  name="btnPrint" id="btnPrint" value="Print" onClick="SetPageAction('PRINT');"/>
				<input type="button"  name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');"/>
				<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');"/>
				<input type="button" name="btnWord" id="btnWord" value="Create WORD" onClick="SetPageAction('WORD');"/>
				<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onClick="SetPageAction('Excel');"/>
			</form>
			<script language="javascript" type="text/javascript">
				function SetPageAction(varAction) {
					if(varAction=="PRINT"){			
						document.frm.action="print/create-print.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if(varAction=="PDF"){			
						document.frm.action="convertpdf/create-pdf.php";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if(varAction=="HTML"){
						document.frm.action="<?php echo $HtmlPath; ?>";
						document.frm.target = "_blank";
						document.frm.submit();
					}
					else if(varAction=="WORD"){
						document.frm.action="convertword/create-word.php";
						document.frm.target="_blank";
						document.frm.submit();
					}
					else if(varAction=="Excel"){
						document.frm.action="convertword/create-excel.php";
						document.frm.target="_blank";
						document.frm.submit();
					}
				}
			</script><?php
			}
			else{
			echo "No data found for selected criteria.";	
		}		
			/* END STUDENT DATA */		
		}
	}  
   	else{
      	echo "Session Expired";      
   	} 
?>
</div>
<?php require "_footer.php";?>