<?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>
	.table-report{
		font-family:Verdana, Geneva, sans-serif;
		font-size:11px;
		text-align:left;
		border-right:0px none;
		border-bottom:0px none;
	}
	.table-report-inner{
		font-family:Verdana, Geneva, sans-serif;
		font-size:11px;
	}
	.table-report tr{
		padding:2px 2px 2px 2px;
	}
	.table-report td{
		padding:2px 2px 2px 2px;
		border-top:0px none;
		border-left:0px none;
	}
	.table-report th{
		padding:2px 2px 2px 2px;
		font-weight:bold;
		text-align:left;
		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:12px;	
		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="Present Notice Report";
	
	$type = $_REQUEST['report_type'];
	
	$branch_id 		= Escape($_REQUEST['branch_hidden']);
	$semester_id 	  = Escape($_REQUEST['semester_hidden']);
	$div_id		   = Escape($_REQUEST['division_id']);
	$student_id 	   = Escape($_REQUEST['student_hidden']); 
	$batch_id 		 = Escape($_REQUEST['batch_idhidden']);
	$monthname 		= Escape($_REQUEST['monthname']); 
	
	$branch_name 	  = Escape($_REQUEST['branch_disp']);
	$semester_name 	= Escape($_REQUEST['semester_disp']);
	$month_name 	   = Escape($_REQUEST['month_disp']);
	$year 			 = Escape($_REQUEST['year']);
		 
	if($branch_id == "" && $semester_id == ""){?>
		<script language="javascript" type="text/javascript">
			location.href='report-present-notice.php';
		</script><?php
	}
	elseif($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])){
		ob_start();
		$i=1;
		
		dbquery("SET group_concat_max_len = 102400");
		
		function curmonth_days($branch_id,$semester_id,$div_id,$monthname,$year,$subject_id,$batch_id)
		{
			/* START PRESENT DAYS CODE */ 
			$sql_days = "
				SELECT 
					*
				FROM 
					cms_presentmaster 
				WHERE 
					day_working = 1 AND
					Extract(MONTH FROM day_date)= '".$monthname."' AND Extract(YEAR FROM day_date)= '".$year."'
					AND branch_id = '".$branch_id."'
					AND semester_id = '".$semester_id."'
					AND div_id = '".$div_id."'
					AND subject_id = '".$subject_id."'
					AND college_id = '".$_SESSION['VedantnrCollegeId']."'
					AND year_id = ".$_SESSION["VedantnrYearId"].
					" AND batch_id IN ('".$batch_id."',0)";
			
			$res_days = dbQuery($sql_days);		
			return dbRows($res_days);
			/*$rec_days = dbArray($res_days);
			$rec_days = explode(",",$rec_days['day_present']);
			$rec_days = array_count_values($rec_days);
			return $rec_days[$student_id];*/
			/* END PRESENT DAYS CODE */
		}
		
		function curmonth_presentdays($branch_id,$semester_id,$div_id,$monthname,$year,$student_id,$subject_id,$batch_id)
		{
			/* START PRESENT DAYS CODE */ 
			$sql_days = "
				SELECT 
					GROUP_CONCAT(day_present) AS day_present
				FROM 
					cms_presentmaster 
				WHERE 
					day_working = 1 AND
					Extract(MONTH FROM day_date)= '".$monthname."' AND Extract(YEAR FROM day_date)= '".$year."'
					AND branch_id = '".$branch_id."'
					AND semester_id = '".$semester_id."'
					AND div_id = '".$div_id."'
					AND subject_id = '".$subject_id."'
					AND college_id = '".$_SESSION['VedantnrCollegeId']."'
					AND year_id = ".$_SESSION["VedantnrYearId"].
					" AND batch_id IN ('".$batch_id."',0)";
			$res_days = dbQuery($sql_days);		
			$rec_days = dbArray($res_days);
			$rec_days = explode(",",$rec_days['day_present']);
			$rec_days = array_count_values($rec_days);
			
			if($rec_days[$student_id] > 0)
				return $rec_days[$student_id];
			return 0;	
			/* END PRESENT DAYS CODE */
		}
		
		function semester_days($branch_id,$semester_id,$div_id,$monthname,$year,$student_id,$batch_id)
		{
			/* START SEMESTER CODE */
			$sql_days1 = "
				SELECT 
					GROUP_CONCAT(day_present) AS day_present
				FROM 
					cms_presentmaster 
				WHERE 
					day_working = 1 
					AND	Extract(YEAR FROM day_date)= '".$year."'
					AND Extract(MONTH FROM day_date) <= '".$monthname."'
					AND branch_id = '".$branch_id."'
					AND semester_id = '".$semester_id."'
					AND div_id = '".$div_id."'
					AND college_id = '".$_SESSION['VedantnrCollegeId']."'
					AND year_id = ".$_SESSION["VedantnrYearId"].
					" AND batch_id IN ('".$batch_id."',0)";
			$res_days1 = dbQuery($sql_days1);
			$rec_days1 = dbArray($res_days1);
			$day_present1 = explode(",",$rec_days1['day_present']);
			$rec_days = array_count_values($day_present1);
			return $rec_days[$student_id];
			/* END SEMESTER CODE */	
		}
		
		/* START CURRENT MONTH WORKING DAYS CODE */
		function curmonth_workingdays($branch_id,$semester_id,$div_id,$monthname,$year,$batch_id)
		{
		$sql_workingdays = "
			SELECT 
				day_present AS day_present,
				day_absent AS day_absent
			FROM 
				cms_presentmaster 
			WHERE 
				day_working = 1 AND
				Extract(MONTH FROM day_date)= '".$monthname."' AND Extract(YEAR FROM day_date)= '".$year."'
				AND branch_id = '".$branch_id."'
				AND semester_id = '".$semester_id."'
				AND div_id = '".$div_id."'
				AND college_id = '".$_SESSION['VedantnrCollegeId']."'
				AND year_id = ".$_SESSION["VedantnrYearId"].
				" AND batch_id IN ('".$batch_id."',0)";
		$res_workingdays = dbQuery($sql_workingdays);
		$total__workingdays = dbRows($res_workingdays);
		return $total__workingdays;
		}
		/* END CURRENT MONTH WORKING DAYS CODE */
		
		/* START SEMESTER WORKING DAYS CODE */
		function semester_workingdays($branch_id,$semester_id,$div_id,$monthname,$year,$batch_id)
		{
		$sql_workingdays1 = "
			SELECT 
				day_present AS day_present,
				day_absent AS day_absent
			FROM 
				cms_presentmaster 
			WHERE 
				day_working = 1 
				AND Extract(YEAR FROM day_date) = '".$year."' 
				AND Extract(MONTH FROM day_date) <= '".$monthname."' 
				AND branch_id = '".$branch_id."'
				AND semester_id = '".$semester_id."'
				AND div_id = '".$div_id."'
				AND college_id = '".$_SESSION['VedantnrCollegeId']."'
				AND year_id = ".$_SESSION["VedantnrYearId"].
				" AND batch_id IN ('".$batch_id."',0)";
		$res_workingdays1 = dbQuery($sql_workingdays1);
		$total__workingdays1 = dbRows($res_workingdays1);
		return $total__workingdays1;
		}
		/* END SEMESTER WORKING DAYS CODE */
		
		/* START SUBJECT CODE */
	
		$sql_subject = "
			SELECT
				DISTINCT sm.subject_name,sm.subject_id
			FROM
				cms_presentmaster pm,
				cms_subjectmaster sm
			WHERE
				sm.subject_id = pm.subject_id AND
				pm.branch_id = '".$branch_id."' AND
				pm.semester_id = '".$semester_id."' AND
				pm.div_id = '".$div_id."' AND
				pm.college_id = '".$_SESSION['VedantnrCollegeId']."' AND
				pm.year_id = ".$_SESSION["VedantnrYearId"].
				" 
			ORDER BY
				sm.subject_id ASC ";
		$res_subject = dbQuery($sql_subject);
		
		/* END SUBJECT CODE */
		
		/* START STUDENT CODE */
		$sql_student = "
					SELECT
						sm.student_id,
						CONCAT(sm.student_surname,' ',sm.student_firstname,' ',sm.student_lastname) AS student_name,
						sd.batch_id,
						student_address,
						student_pincode
					FROM
						cms_studentmaster sm,
						cms_studentdetail sd
					WHERE
						sm.student_id = sd.student_id AND
						sd.current_active = 1 AND
						sm.student_active = 1 AND
						sd.year_id = ".$_SESSION["VedantnrYearId"];
		$where = "";
		if($student_id != 0)
			$where .= " AND sm.student_id = $student_id "; 
		if($_REQUEST['batch_idhidden'] != '0')
			$where .= " AND sd.batch_id = '".Escape($_REQUEST['batch_idhidden'])."'"; 
		if($branch_id != "")
			$where .= " AND sd.cur_branchid = $branch_id ";
		if($semester_id != "")
			$where .= " AND sd.cur_semesterid = $semester_id ";
		if($div_id != ""){
			$where .= " AND sd.cur_divison = '".$div_id."'"; 
		
		
	}
		if($where != "")
		$sql_student .= $where;	
		$sql_student .= " ORDER BY sm.student_gturegno ASC ";	
		$res_student = dbQuery($sql_student);
		/* END STUDENT CODE */
		
		if(dbRows($res_student)>0){
			while($rec_student = dbArray($res_student)){
				$student_id = $rec_student['student_id'];	
				$batch_id = $rec_student['batch_id'];
				$count_present = 0;
				$count_absent = 0;
				
				$count_present1 = 0;
				$count_absent1 = 0;
				
				$temp_wdays = 0;
				$temp_pdays = 0;
		
				for($i=0; $i<count($day_present); $i++){
					if($day_present[$i] == $student_id){
						$count_present++;
					}
				}
				
				for($i=0; $i<count($day_present1); $i++){
					if($day_present1[$i] == $student_id){
						$count_present1++;
					}
				}
				?>
                	<table width="100%" border="0" cellpadding="2" cellspacing="2" style="font-size:12px; color:#000;">
                    	<tr>
                        	<td colspan="2" align="center"><div class="college_address"><u>Shree Abjibapa Education & Charitable Trust</u></div></td>
                        </tr>
                        <tr>
                        	<td colspan="2" align="center"><div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div></td>
                        </tr>
                        <tr>
                        	<td colspan="2" align="center"><div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div></td>
                        </tr>
                        <tr>
                        	<td colspan="2" align="center">
                            	<div class="college_address">
                                    Web: <?php echo $_SESSION["VedantnrCollegeUrl"] ;?> 
                                    &nbsp;&nbsp; 
                                    Email: <?php echo $_SESSION["VedantnrCollegeEmail"] ;?> 
                                    &nbsp;&nbsp; 
                                    Phone: <?php echo $_SESSION["VedantnrCollegePhone"] ;?> 
                              	</div>
                          	</td>
                        </tr>
                        <tr>
                        	<td colspan="2">&nbsp;</td>
                        </tr>
                    	<tr>
                        	<td width="80%" align="left" style="padding-left:50px;"><textarea rows="5" cols="40"><?php echo $rec_student['student_name']."\n".$rec_student['student_address']." Pin: ".$rec_student['student_pincode']; ?></textarea></td>
                            <td width="20%" style="text-align:right; padding-right:5px; vertical-align:top;">તા. <?php echo date('d-m-Y'); ?></td>
                        </tr>
                        <tr>
                        	<td colspan="2">પ્રતિ,</td>
                        </tr>
                        <tr>
                        	<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;સુજ્ઞ શ્રી વાલીગણ. કુશળ હશો.</td>
                        </tr>
                        <tr>
                        	<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;આપનો પાલ્‍ય શ્રી <?php echo $rec_student['student_name']; ?></td>
                        </tr>
                        <tr>
                        	<td colspan="2" style="text-align:justify;">&nbsp;&nbsp;&nbsp;&nbsp;અમારી સંસ્‍થામાં <?php echo $branch_name; ?> બ્રાન્‍ચમાં અભ્‍યાસ કરે છે. આપ તેના અભ્‍યાસ અને હાજરી થી સંપૂર્ણ વાકેફ્‍ હશો તેવું અમારું માનવું છે. સેમીસ્‍ટર - <?php echo $semester_id; ?> માં ગેરહાજર રહેનાર અથવા વચ્‍ચેથી કોલેજ છોડી જનાર વિદ્યાર્થીના વાલીને કોલેજના રેકર્ડ મુજબના મોબાઇલ નંબરથી ગેરહાજરીની જાણ કરવામાં આવે છે. Enrollment No ના નિયમ મુજબ જે વિદ્યાર્થીની નિયમ કરતાં એટલે કે ૭૫ % થી ઓછી હાજરીવાળા વિદ્યાર્થીનું Exam Form મોકલવામાં આવતું નથી. સંસ્‍થાએ દરમાસની આખર તારીખે ઓછી હાજરીવાળા વિદ્યાર્થીઓની માહિતી Enrollment No ને મોકલવાની હોય છે. <?php echo $month_name." - ".$year; ?> નો હાજરી નો નીચે મુજબનો રેકોર્ડ GTU માં મોકલેલ છે.</td>
                        </tr>
                        <tr>
                        	<td colspan="2" style="text-align:justify;">&nbsp;&nbsp;&nbsp;&nbsp;આપને આ માહિતી આપવાનાં હેતુ એ છે કે આપનો પાલ્‍ય નિયમિત કોલેજમાં આવે તે બાબતનું નિયમિત ધ્‍યાન રાખશો જેથી સરકારશ્રીના નિયમ મુજબ તેનું એક શૈક્ષણિક વર્ષ બગડે નહીં તેમજ તેની શૈક્ષણિક કારકીર્દી ઉજવળ બને.</td>
                        </tr>
                        <tr>
                        	<td colspan="2" style="text-align:center; font-weight:bold;">સેમીસ્‍ટર - <?php echo $semester_id; ?> નો આપના પાલ્‍યના હાજરીનો રેકોર્ડ નીચે મુજબ છે.</td>
                        </tr>
                        <tr>
                        	<td colspan="2" align="center">
                            	<table border="1" style="font-size:11px;" width="90%" cellpadding="0" cellspacing="0" >	
                                	<tr>
                                    	<th style="padding:2px;text-align:center;font-weight:bold;">વિષય</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;">કામના દીવસ</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;">હાજર દીવસ</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;">Total %</th>
                                    </tr>
                                    <?php
									
                                    	if($type == "blank_sheet"){
											$res_subject = dbQuery($sql_subject);
											while($rec_subject = dbArray($res_subject)){?>
												<tr>
									<td style="padding:2px;text-align:left;"><?php echo $rec_subject['subject_name']; ?></td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												</tr><?php
											}?>
                                    <tr>
                                    	<td style="padding:2px;">સેમીસ્‍ટરમાં કુલ</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                    </tr>   
                                  	<?php
										}
										
										else if($type == "detail_sheet"){
											$res_subject = dbQuery($sql_subject);
											while($rec_subject = dbArray($res_subject)){
												$student_id = $rec_student['student_id'];
												$subject_id = $rec_subject['subject_id']
												?>
												<tr>
									<td style="padding:2px;text-align:left;"><?php echo $rec_subject['subject_name']; ?></td>
												<td style="padding:2px 7px 0px 0px;text-align:right;"><?php
													$wdays = curmonth_days($branch_id,$semester_id,$div_id,$monthname,$year,$subject_id,$batch_id);	
													$temp_wdays += $wdays; 
													echo $wdays; ?>
                                                </td>
												<td style="padding:2px 7px 0px 0px;text-align:right;"><?php 
													$pdays = curmonth_presentdays($branch_id,$semester_id,$div_id,$monthname,$year,$student_id,$subject_id,$batch_id);
                                                    $temp_pdays += $pdays; 
													echo $pdays; ?>
                                               	</td>
												<td style="padding:2px 7px 0px 0px;text-align:right;"><?php echo round(($pdays*100)/$wdays)."%"; ?></td>
												</tr><?php
											}?>
									<tr>
                                    	<th ><b/><?php echo $month_name." "; ?>માસમાં<b/></th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo $temp_wdays; ?></th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo $temp_pdays; ?></th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo number_format(($temp_pdays*100)/$temp_wdays,0)."%"; ?></th>
                                    </tr>
                                    <tr>
                                    	<th style="padding:5px; font-weight:bold;">સેમીસ્‍ટરમાં કુલ</th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo $total__workingdays1=semester_workingdays($branch_id,$semester_id,$div_id,$monthname,$year,$batch_id); ?></th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo $total__presentdays1 = semester_days($branch_id,$semester_id,$div_id,$monthname,$year,$student_id,$batch_id); ?></th>
                                        <th style="padding:2px 7px 0px 0px;text-align:right;font-weight:bold;"><?php echo number_format(($total__presentdays1*100)/$total__workingdays1,0)."%"; ?></th>
                                    </tr><?php		
										}
									?>
                                    
                                    <!--<tr>
                                    	<td style="padding:10px;"><?php //echo $month_name; ?></td>
                                        <td><?php //$total__workingdays = curmonth_workingday($branch_id,$semester_id,$monthname,$year,$batch_id);  ?></td>
                                        <td><?php //echo $count_present; ?></td>
                                        <td><?php //echo number_format(($count_present*100)/$total__workingdays,0); ?></td>
                                    </tr>
                                    <tr>
                                    	<td style="padding:10px; font-weight:bold;">સેમીસ્‍ટરમાં કુલ</td>
                                        <td><?php //echo $total__workingdays1=semester_workingdays($branch_id,$semester_id,$monthname,$year,$batch_id);  ?></td>
                                        <td><?php ////echo $count_present1; ?></td>
                                        <td><?php //echo number_format(($count_present1*100)/$total__workingdays1,0); ?></td>
                                    </tr>-->
                                </table>
                            </td>
                        </tr>
                        <tr>
                        	<td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                        	<td colspan="2" style="text-align:right; padding-right:10px;">મહેન્‍દ્રભાઇ ઠકકર </td>
                        </tr>
                        <tr>
                        	<td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                        	<td colspan="2" style="text-align:right; padding-right:8px;">મેનેજીંગ ડીરેકટર</td>
                        </tr>
                        <tr>
                        	<td colspan="2">વાલીજોગ નોંઘ :-</td>
                        </tr>
                        <tr>
                        	<td colspan="2">
                            	<table width="100%" style="font-size:12px; color:#000;">
                                <tr style="text-align:justify; vertical-align:top;">
                                	<td width="3%">1.</td>
                                    <td width="97%">આપના મોબાઇલ નંબર ઉપર હાજરી તેમજ અન્‍ય SMS મળતા ન હોય તો કોલેજના રકોર્ડે માં આપનો હાલનો નંબર લખાવી દેવા વિનંતી.</td>
                                </tr>
                                <tr style="text-align:justify; vertical-align:top;">
                                	<td>2.</td>
                                    <td>આ પરિપત્ર GTU ના તા.૦૩-૦૩-૨૦૧૧ ના ઇમેઇલ ના અનુસંઘાનમાં મોકલેલ છે.</td>
                                </tr>
                                <tr style="text-align:justify; vertical-align:top;">
                                	<td>3.</td>
                                    <td>જો આપના પાલ્‍યની હાલ સુધીના માસમાં હાજરી ૭૫% થી ઓછી હોય તો આપ શ્રીને નમ્ર વિનંતી કે આપ આગામી માસમાં બાળક પૂરેપૂરી હાજરી આપે જેથી ચાલુ વર્ષ/સેમીસ્‍ટરમાં કોઈપણ પ્રકારના શિક્ષાત્‍મક પગલાં લેવામાં ન આવે.</td>
                                </tr>
                                <tr style="text-align:justify; vertical-align:top;">
                                	<td>4.</td>
                                    <td>જો ૫૦% થી ઓછી હાજરી હોય તો કોલેજમાં રૂબરૂ સંપર્ક કરવા અનુરોધ કરવામાં આવે છે.</td>
                                </tr>
                            	</table>
                           	</td>
                        </tr>
                    </table>
                    <br />
                    <div class="break">&nbsp;</div> 
                <?php
				
			}
			$HtmlCode= ob_get_contents();
			ob_end_flush();
			$HtmlUrl  =	"present-notice-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.";	
		}		
	}  
   	else{
      	echo "Session Expired";      
   	}
?>
</div>
<?php require "_footer.php";?>