<?php
    include_once("class/class.MySQL.php");
	$db	=new MySQL();
session_start();
	$current_logged_user = $_SESSION['admin_id'];
?>

<!DOCTYPE html>
<html>
    <head>
 <?php include("header-js.php");?>	
		
<!-----hrm-------------->		


<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/jquery-ui.css" />
<link rel="stylesheet" href="css/responsive.css" />
<link rel="stylesheet" href="css/simplePagination.css" />
<!-- Responsive -->
<script language="javascript" src="js/css3-mediaqueries.js" type="text/javascript"></script>

<!-- /Responsive -->
<!-- Tabcontent (ORDER) -->
<link rel="stylesheet" type="text/css" href="css/tab-content.css" />	
<script src="js/dateFormat.js"></script>
<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/tab-content.js"></script>
<script type="text/javascript" src="js/insert.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>

<?php
if($_SESSION['usertype']=='Superadmin' || $_SESSION['branchadmin']=='Y')
{
?>
<script type="text/javascript" src="js/add-perfomance-attribute.js"></script>
<?php
}
?>

<!-- FORM -->

<link rel="stylesheet" href="css/form-slide.css" type="text/css" media="screen"/>

<script type="text/javascript" src="js/sliding.form.js"></script>
<script type="text/javascript" >
$('#recdate').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});

function costratio(){
	//alert(document.getElementById("recost").value);
	var costratio = 0;
	var recselcand = document.getElementById('recselcand').value;
	var recost = document.getElementById('recost').value;
	costratio = recost/recselcand;
	document.getElementById('recostratio').value = costratio;
	//recselcand
	//alert(myTextField);
}
</script>

<!-----hrm-------------->
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
    </head>


    <body class="skin-blue">
	 <?php 
	include("header.php");
?>


                    <!-- Small boxes (Stat box) -->
                    

                    <!-- Main row -->
                    <div class="row">
                    
					<div id="wrapper">
		
		<div class="content">
			<div class="report-tab">
				<div class="employee-title">
					<div class="report-left"><h2><translate>Performance Review</translate></h2><span></span></div>
					<div class="report-category"></div>
					<div class="clear-float"></div>
				</div>
				<div class="clear-float"></div>
				<!--<div class="report-cell-02"><div class="clear-float"></div>
				</div>-->
					<?php
					if($_SESSION['usertype']=='Superadmin' || $_SESSION['branchadmin']=='Y')
					{
						?>
						<label><input class="btn-tab-01 btn_performance_add btn-tab-active" type="button" value="Add Questions" onClick="add_performance_questions_form()"></label>
						<label><input class="btn-tab-01 btn_performance_view" type="button" value="View Questions" onClick="view_total_qns()"></label>
						<label><input class="btn-tab-01 btn_performance_review" type="button" value="Rate Employee" onClick="review_questions()"></label>
						<div id="PerformanceContentDiv"></div>
						
						<?php
					}
					else
					{
						echo '<div id="PerformanceContentDiv">';
							$query_main_attribute = mysql_query("select A.perfom_attr_id,issue_date,attributes,(case when avg(rate) is null then 0 else avg(rate) end)as attr_rate,(case when max(answered_modified_date) is null then max(answered_date) else max(answered_modified_date) end ) AS answered_date from performance_attribute A left join performance_question B on A.perfom_attr_id=B.perfom_attr_id left join performance C on C.perform_qn_id=B.perform_qn_id group by A.perfom_attr_id");
							$query1_num_rows = mysql_num_rows($query_main_attribute);
							if($query1_num_rows > 0)
							{
								?>
								<form action="" method="post" enctype="multipart/form-data" id="fill_qst1form" name="fill_qst1form" >
									<table class="table">
										<thead>
											<tr>
												<th style="width:10%;"><translate>Sl No</translate></th>
												<th style="width:15%;"><translate>Issue Date</translate></th>
												<th style="width:50%;"><translate>Attribute</translate></th>
												<th style="width:10%;"><translate>Rate</translate></th>
												<th style="width:15%;"><translate>Answered Date</translate></th>
											</tr>
										</thead>
										<tbody>
											<?php		
											$i=1;
											while($row = mysql_fetch_array($query_main_attribute))
											{
												$expandable_query=mysql_query('select A.perform_qn_id,question,weightage from performance_question A left join performance B on A.perform_qn_id	=B.perform_qn_id where A.perfom_attr_id='.$row['perfom_attr_id'].'');
												if($row['issue_date'])
												{
													$issue_date=date("d-m-Y", strtotime($row['issue_date']));
												}
												else
												{
													$issue_date='-';
												}
												if($row['answered_date'])
												{
													$answered_date=date("d-m-Y", strtotime($row['answered_date']));
												}
												else
												{
													$answered_date='-';
												}
												
												$expandable_rows='';
												$query2_num_rows = mysql_num_rows($expandable_query);
												$numerator_rate=0;
												$denumerator_rate=0;
												if($query2_num_rows > 0)
												{
													$j=1;
													
													while($row_expand = mysql_fetch_array($expandable_query))
													{
														$employee_query=mysql_fetch_array(mysql_query('SELECT answer,rate FROM performance WHERE emp_id = '.$current_logged_user.' AND perform_qn_id = '.$row_expand['perform_qn_id'].' '));
														$expandable_rows.='<tr style="background-color:#eee;">
															<td>'.$j.'</td>
															<td>'.$row_expand['question'].'</td>
															<td>';
															$numerator_rate=$numerator_rate+($row_expand['weightage']*$employee_query['rate']);
															$denumerator_rate=$denumerator_rate+$row_expand['weightage'];
															if($employee_query['rate'])
															{
																$emp_rate=$employee_query['rate'];
																$expandable_rows.='<textarea name="qns_answer_area[]" id="qns_answer_area_'.$row_expand['perform_qn_id'].'" class="form-control" rows="3" readonly="readonly" >'.$employee_query['answer'].'</textarea><input type="hidden" name="qst_id[]" value="'.$row_expand['perform_qn_id'].'" /></td>';
															}
															else
															{
																$emp_rate='-';
																$expandable_rows.='<textarea name="qns_answer_area[]" id="qns_answer_area_'.$row_expand['perform_qn_id'].'" class="form-control" rows="3" >'.$employee_query['answer'].'</textarea><input type="hidden" name="qst_id[]" value="'.$row_expand['perform_qn_id'].'" /></td>';
															}
															$expandable_rows.='<td>'.$row_expand['weightage'].'</td>
															<td>'.$emp_rate.'</td>
														</tr>';
														$j++;
													}
													$expandable_footer='<tfoot>
														<tr>
															<td colspan="5" align="center" style="background-color:#FFFFFF;">
																<input type="button" name="button" class="color-button" id="button" value="Submit" onClick="fnFillAnswer('.$current_logged_user.')">
															</td>
														</tr>
													</tfoot>';
												}
												else
												{
													$expandable_rows.='<tr>
														<td colspan="4" align="center" style="color:#FF0000;"><strong>No Data to Display....</strong></td>
													</tr>';
													$expandable_footer='';
												}
												
												/*echo '<tr class="expand_parent_row" style="cursor:pointer">
													<td>'.$i.'</td>
													<td>'.$issue_date.'</td>
													<td>'.$row['attributes'].'</td>
													<td>'.$row['attr_rate'].'</td>
													<td>'.$answered_date.'</td>
												</tr>';*/
												echo '<tr class="expand_parent_row" style="cursor:pointer">
													<td>'.$i.'</td>
													<td>'.$issue_date.'</td>
													<td>'.$row['attributes'].'</td>
													<td>'.($numerator_rate/$denumerator_rate).'</td>
													<td>'.$answered_date.'</td>
												</tr>';
												$i++;
												echo '<tr class="row_to_expand" style="display:none;">
													<td colspan="5">
														<table class="table table-bordered">
															<thead>
																<tr style="background-color:#eee;">
																	<th style="width:10%;"><translate>Sl No</translate></th>
																	<th style="width:30%;"><translate>Question</translate></th>
																	<th style="width:30%;"><translate>Answer</translate></th>
																	<th style="width:20%;"><translate>Weightage</translate></th>
																	<th style="width:10%;"><translate>Rate</translate></th>
																</tr>
															</thead>
															<tbody>'.$expandable_rows.'</tbody>
															'.$expandable_footer.'
														</table>
													</td>
												</tr>';
											}
											?>
										</tbody>
									</table>
								</form>
								<?php             
							}
							else
							{
								echo '<table class="table">
									<thead>
										<tr>
											<th style="width:10%;"><translate>Sl No</translate></th>
											<th style="width:10%;"><translate>Issue Date</translate></th>
											<th style="width:20%;"><translate>Attribute</translate></th>
											<th style="width:20%;"><translate>Rate</translate></th>
											<th style="width:40%;"><translate>Answered Date</translate></th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<td colspan="4" align="center" style="color:#FF0000;"><strong>No Data to Display....</strong></td>
										</tr>
									</tbody>
								</table>';
							}
						echo  '</div>';
					}
				   ?>
			</div>
		</div>
		<div class="footer">
			<strong>© add-HRM</strong><br />
			<span>Developed by <a href="http://www.aadhocc.com" target="_blank">Aadhocc</a></span></div><!-- /footer -->
		</div>
					
					
                    </div><!-- /.row (main row) -->

                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
<?php include "footer-js.php"; ?>
<script type="text/javascript">
	//$('.row_to_expand').hide();
	$('.expand_parent_row').click(function () {
		var currentDetails = $(this).next('.row_to_expand');
		//console.log(currentDetails);
		$('.row_to_expand').not(currentDetails).hide();
		
		currentDetails.toggle();
		
	});
	
</script>
	<!--------------scripts for employee list-------------->
    </body>
</html>