<?php include 'inc_classes.php';?>
<?php include "admin_authentication.php";?>
<?php include "../classes/thumbnail_images.class.php";?>
<?php
if($_REQUEST['record_id'])
{
    $record_id=$_REQUEST['record_id'];
    $sql_record= "SELECT * FROM emp_performance_report where id='".$record_id."'";
    if(mysql_num_rows($db->query($sql_record)))
        $row_record=$db->fetch_array($db->query($sql_record));
    else
		$record_id=0;
}
$edit_access='';
$sel_acc="select * from edit_previleges where admin_id='".$_SESSION['admin_id']."' and privilege_id='349'";
$ptr_access=mysql_query($sel_acc);
if(mysql_num_rows($ptr_access))
{
	$edit_access='yes';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php if($record_id) echo "Edit"; else echo "Add";?> Employee Performance</title>
<?php include "include/headHeader.php";?>
<?php include "include/functions.php"; ?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
	<!-- <script type='text/javascript' src='js/jquery-1.6.2.min.js'></script>-->
    <script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
	jQuery(document).ready( function() 
	{
		// binds form submission and fields to the validation engine
		jQuery("#jqueryForm").validationEngine('attach', {promptPosition : "topLeft"});
		
	});
// function show_attend1(value)
// {
// 	presence1=value.split("-");
// 	// alert(Repeat_type[0]);
// 	if(presence1[0]=="no")
// 	{
// 		document.getElementById("contain").style.display = 'block';
// 		document.getElementById("contain1").style.display = 'block';
// 	}
// 	else
// 	{
// 		document.getElementById("contain").style.display = 'none';
// 		document.getElementById("contain1").style.display = 'none';
// 	}
// }

    </script>
    
	<!-- <script src="../js/jquery.custom/development-bundle/jquery-1.4.2.js"></script>-->
    <link rel="stylesheet" href="js/development-bundle/demos/demos.css"/>
     <link rel="stylesheet" href="js/chosen.css" />
    <script src="js/development-bundle/ui/jquery.ui.core.js"></script>
    <script src="js/development-bundle/ui/jquery.ui.widget.js"></script>
    <script src="js/development-bundle/ui/jquery.ui.datepicker.js"></script>
    <script src="js/chosen.jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function()
	{            
		$('.datepicker').datepicker({ changeMonth: true,changeYear: true, showButtonPanel: true, closeText: 'Clear'});
		$.datepicker._generateHTML_Old = $.datepicker._generateHTML; $.datepicker._generateHTML = function(inst)
		{
			res = this._generateHTML_Old(inst); res = res.replace("_hideDatepicker()","_clearDate('#"+date.id+"')"); return res;
			//$("#date" ).datepicker({defaultDate: -1,maxDate:"-1D"});
			$("#date").datepicker("setDate", "-1");
		}
		
		$("#staff_id").chosen({allow_single_deselect:true});
		$("#staff_id_s").chosen({allow_single_deselect:true});
		<?php 
		if($_SESSION['type']=="S" || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
		{
			?>
			$("#branch_name").chosen({allow_single_deselect:true});
			$("#branch_name_s").chosen({allow_single_deselect:true});
			<?php
		}
		if($record_id=='')
		{
			?>
			//========values========
			/*document.getElementById("utilisation").value=0;
			document.getElementById("task_completion").value=0;
			document.getElementById("quality_of_work").value=0;
			//===========
			document.getElementById("timesheet_mark").value=0;
			document.getElementById("utilisation_mark").value=0;
			document.getElementById("task_mark").value=0;
			document.getElementById("quality_work_mark").value=0;
			
			document.getElementById("class_start_time_mark").value=0;
			document.getElementById("class_end_time_r_mark").value=0;
			document.getElementById("faculty_grooming_r_mark").value=0;
			document.getElementById("logsheet_send_r_mark").value=0;
			document.getElementById("mobile_used_r_mark").value=0;
			document.getElementById("timetable_followed_r_mark").value=0;
			document.getElementById("student_decoram_r_mark").value=0;
			//========checked=========
			document.getElementById("class_start_time_r_n").checked=true;
			document.getElementById("class_end_time_r_n").checked=true;
			document.getElementById("faculty_grooming_r_n").checked=true;
			document.getElementById("logsheet_send_r_n").checked=true;
			document.getElementById("mobile_used_r_n").checked=true;
			document.getElementById("timetable_followed_r_n").checked=true;
			document.getElementById("student_decoram_r_n").checked=true;
			//=======Values=====
			document.getElementById("late_login_without_info_mark").value=0;
			document.getElementById("absent_without_info_mark").value=0;
			document.getElementById("early_checkout_info_mark").value=0;
			document.getElementById("misconduct_with_staff_mark").value=0;
			document.getElementById("misconduct_with_student_mark").value=0;
			document.getElementById("logsheet_not_checked_mark").value=0;
			document.getElementById("other_issue_mark").value=0;
			//========checked=========
			document.getElementById("late_login_without_info_n").checked=true;
			document.getElementById("absent_without_info_n").checked=true;
			document.getElementById("early_checkout_info_n").checked=true;
			document.getElementById("misconduct_with_staff_n").checked=true;
			document.getElementById("misconduct_with_student_n").checked=true;
			document.getElementById("logsheet_not_checked_n").checked=true;
			document.getElementById("other_issue_n").checked=true;
			//====================================
			document.getElementById("points").value=0;
			document.getElementById("monthly_points").value=0;
			document.getElementById("negative_remark_mark").value=0;*/
			<?php
		}
		?>		
	});
    </script>
 	<script type="text/javascript">
	function submitAction(action)
	{
		var chks = document.getElementsByName('chkRecords[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++)
		{
			if (chks[i].checked)
			{
				hasChecked = true;
				break;
			}
		}
		if (hasChecked == false)
		{
			alert("Please select at least one record to do operation");
			$('#selAction').val('');
			return false;
		}

		document.getElementById('formAction').value=action;
		if(action=="delete")
		{
			if(confirm("Are you sure, you want to delete selected record(s)?"))
				document.frmTakeAction.submit();
			else
			{
				$('#selAction').val('');
				return false;
			}
		}
		else
			document.frmTakeAction.submit();
	}
	function redirect1(value,value1)
	{           
		//alert(value);
	   // alert(value1);
		window.location.href=value+value1;
	}

	function validationToDelete(type)
	{
		if(confirm("Are you sure, you want to delete selected record(s)?"))
			return true;
		else
			return false;
	}
	function getstaff(branch_id)
	{
		var data1="action=stack_report&branch_id="+branch_id;	
		$.ajax({
		url: "show_councellor.php", type: "post", data: data1, cache: false,
		success: function (html)
		{
			if(html !='')
			{
				//alert(html);
				document.getElementById("staff_details").innerHTML=html;
				$("#staff_id_s").chosen({allow_single_deselect:true});
			}
		},
		error:function(exception){alert('Exception:'+exception);}
		});
	}
	function getstaffDetails(branch_id)
	{
		var date= document.getElementById("date").value;
		var data1="action=performance_report&branch_id="+branch_id+"&date="+date;	
		$.ajax({
		url: "performance_key_point_ajax.php", type: "post", data: data1, cache: false,
		success: function (html)
		{
			if(html !='')
			{
				// alert(html);
				document.getElementById("staff_ids").innerHTML=html;
				$("#staff_id").chosen({allow_single_deselect:true});
			}
		},
		error:function(exception){alert('Exception:'+exception);}
		});
	}
	function check_data(staff_id)
	{
		var branch_id= document.getElementById("branch_name").value;
		var date= document.getElementById("date").value;
		// document.getElementById("working_hours").value = '';
		var data1="action=get_staff_presence&branch_id="+branch_id+"&staff_id="+staff_id+"&date="+date;	
		$.ajax({
		url: "ajax.php", type: "post", data: data1, cache: false,
		success: function (html)
		{
			// alert(html);
			var val_Spl=html.split("##");
			var presence = val_Spl[0].trim();
			var att_ids=val_Spl[1].trim();
			// alert(presence);
			// alert(att_ids);
			if(att_ids !='')
			{
				// alert("Yes");
				document.getElementById("presence").value ="yes";
				document.getElementById("contain").style.display = 'none';
				document.getElementById("contain1").style.display = 'none';

				// setTimeout(select_key(staff_id),500);
				
			}
			else
			{
				// alert("No");
				$("#presence").prop("selectedIndex", 2); 
				ok=document.getElementById("contain").style.display = 'block';
		        document.getElementById("contain1").style.display = 'block';
				// alert(ok);
				
				
			}
		},
		error:function(exception){alert('Exception:'+exception);}
		});
		
	}
	function isNumber(evt) {
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode > 31 && (charCode < 48 || charCode > 57)) {
			return false;
		}
		return true;
	}
	function change_mark(t_per)
	{
		if(t_per=='yes')
		{
			document.getElementById("timesheet_mark").value=1;
		}
		else
		{
			document.getElementById("timesheet_mark").value=1;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_utilisation(uti_per)
	{
		var marks=0;
		if(uti_per!='')
		{
			var inmark= roundNumber((uti_per*10),2);
			var marks=Number(inmark / 100); 
			//alert(inmark);
			document.getElementById("utilisation_mark").value=marks;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_task(task_per)
	{
		var marks=0;
		if(task_per!='')
		{
			var inmark= roundNumber((task_per*5),2);
			var marks=Number(inmark / 100); 
			document.getElementById("task_mark").value=marks;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_qualityWork(qw_per)
	{
		var marks=0;
		if(qw_per!='' )
		{
			var inmark= roundNumber((qw_per*5),2);
			var marks=Number(inmark / 100); 
			document.getElementById("quality_work_mark").value=marks;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_cst(cst_val)
	{
		if(cst_val=='yes')
		{
			document.getElementById("class_start_time_mark").value=1;
		}
		else
		{
			document.getElementById("class_start_time_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_cet(cet_val)
	{
		if(cet_val=='yes')
		{
			document.getElementById("class_end_time_r_mark").value=1;
		}
		else
		{
			document.getElementById("class_end_time_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_fg(fg_val)
	{
		if(fg_val=='yes')
		{
			document.getElementById("faculty_grooming_r_mark").value=1;
		}
		else
		{
			document.getElementById("faculty_grooming_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_fg(fg_val)
	{
		if(fg_val=='yes')
		{
			document.getElementById("faculty_grooming_r_mark").value=1;
		}
		else
		{
			document.getElementById("faculty_grooming_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_ls(ls_val)
	{
		if(ls_val=='yes')
		{
			document.getElementById("logsheet_send_r_mark").value=1;
		}
		else
		{
			document.getElementById("logsheet_send_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_mubh(mubh_val)
	{
		if(mubh_val=='yes')
		{
			document.getElementById("mobile_used_r_mark").value=1;
		}
		else
		{
			document.getElementById("mobile_used_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_tf(tf_val)
	{
		if(tf_val=='yes')
		{
			document.getElementById("timetable_followed_r_mark").value=1;
		}
		else
		{
			document.getElementById("timetable_followed_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_sd(sd_val)
	{
		if(sd_val=='yes')
		{
			document.getElementById("student_decoram_r_mark").value=1;
		}
		else
		{
			document.getElementById("student_decoram_r_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_llwi(llwi_val)
	{
		if(llwi_val=='yes')
		{
			document.getElementById("late_login_without_info_mark").value=1;
		}
		else
		{
			document.getElementById("late_login_without_info_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_awi(awi_val)
	{
		if(awi_val=='yes')
		{
			document.getElementById("absent_without_info_mark").value=2;
		}
		else
		{
			document.getElementById("absent_without_info_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_ecwi(ecwi_val)
	{
		if(ecwi_val=='yes')
		{
			document.getElementById("early_checkout_info_mark").value=1;
		}
		else
		{
			document.getElementById("early_checkout_info_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_mws(mws_val)
	{
		if(mws_val=='yes')
		{
			document.getElementById("misconduct_with_staff_mark").value=2;
		}
		else
		{
			document.getElementById("misconduct_with_staff_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_mwst(mwst_val)
	{
		if(mwst_val=='yes')
		{
			document.getElementById("misconduct_with_student_mark").value=2;
		}
		else
		{
			document.getElementById("misconduct_with_student_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_lnc(lnc_val)
	{
		if(lnc_val=='yes')
		{
			document.getElementById("logsheet_not_checked_mark").value=1;
		}
		else
		{
			document.getElementById("logsheet_not_checked_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
	function calculate_oi(oi_val)
	{
		if(oi_val=='yes')
		{
			document.getElementById("other_issue_mark").value=1;
		}
		else
		{
			document.getElementById("other_issue_mark").value=0;
		}
		setTimeout(calculate_mark(),500);
	}
function select_key(admin_id)
{
	
	var branch_id= document.getElementById("branch_name").value;
	var date= document.getElementById("date").value;
	var attendence= document.getElementById("presence").value;
	var type_data="action=performance&admin_id="+admin_id+"&branch_id="+branch_id+"&date="+date+"&presence="+attendence;
    // alert(branch_id);
	$.ajax({
	url: "performance_key_point_ajax.php",type:"post", data: type_data,cache: false,
	success: function(rettype)
	{
		// alert(retstaff);
		document.getElementById("key_titles").innerHTML=rettype;
	
	}
	});
	setTimeout(totals(staff_id),500);
}


function cal_points(cst_val,ids)
{
	var ok='';	
	if(cst_val=='yes')
	{
		ok=document.getElementById("class_start_time_mark"+ids).value;
		this1=ok;
	}
	else if(cst_val=='no')
	{
		ok=document.getElementById("class_start_time_mark"+ids).value;
		this1='-'+ ok;
	}
	// alert(this1);
	document.getElementById("pointing"+ids).value=this1;
	setTimeout(calculate_total(),100);
}
function calculate_total()
	{
		total_points = 0;
		final_point= 0;
		var total_cnt=document.getElementById("total_cnt").value;
		// alert(total_cnt);
		for(i=1;i<=total_cnt;i++)
		{
			ok= document.getElementById("pointing"+i).value;
			total_points +=Number(ok);
			poi= document.getElementById("class_start_time_mark"+i).value;
			final_point +=Number(poi);
	    }
		document.getElementById("tot_points").value=total_points;
		document.getElementById("final_point").value=final_point;
	}
function totals()
	{
		var total_point=0;
		// alert('yes');
		total_cnt=document.getElementById("total_cnt").value;
		//    alert(total_cnt);
		for(i=1;i<=total_cnt;i++)
		{
			point= document.getElementById("class_start_time_mark"+i).value;
			total_point +=Number(point);
			// alert(total_point);
			
	    }
		// if(total_point!=0)
		document.getElementById("tot_points").value=total_point;
		document.getElementById("final_point").value=total_point;
	}
	// function calculate_mark()
	// {
	// 	var timesheet_mark=parseFloat(document.getElementById("timesheet_mark").value);
	// 	var utilisation_mark=parseFloat(document.getElementById("utilisation_mark").value);
	// 	var task_mark=parseFloat(document.getElementById("task_mark").value);
	// 	var quality_work_mark=parseFloat(document.getElementById("quality_work_mark").value);
	// 	var class_start_time_mark=parseFloat(document.getElementById("class_start_time_mark").value);
	// 	var class_end_time_r_mark=parseFloat(document.getElementById("class_end_time_r_mark").value);
	// 	var faculty_grooming_r_mark=parseFloat(document.getElementById("faculty_grooming_r_mark").value);
	// 	var logsheet_send_r_mark=parseFloat(document.getElementById("logsheet_send_r_mark").value);
	// 	var mobile_used_r_mark=parseFloat(document.getElementById("mobile_used_r_mark").value);
	// 	var timetable_followed_r_mark=parseFloat(document.getElementById("timetable_followed_r_mark").value);
	// 	var student_decoram_r_mark=parseFloat(document.getElementById("student_decoram_r_mark").value);
	// 	var negative_remark_mark=parseFloat(document.getElementById("negative_remark_mark").value);
		
	// 	var late_login_without_info_mark=parseFloat(document.getElementById("late_login_without_info_mark").value);
	// 	var absent_without_info_mark=parseFloat(document.getElementById("absent_without_info_mark").value);
	// 	var early_checkout_info_mark=parseFloat(document.getElementById("early_checkout_info_mark").value);
	// 	var misconduct_with_staff_mark=parseFloat(document.getElementById("misconduct_with_staff_mark").value);
	// 	var misconduct_with_student_mark=parseFloat(document.getElementById("misconduct_with_student_mark").value);
	// 	var logsheet_not_checked_mark=parseFloat(document.getElementById("logsheet_not_checked_mark").value);
	// 	var other_issue_mark=parseFloat(document.getElementById("other_issue_mark").value);
		
	// 	var total_negative_mark=parseFloat(late_login_without_info_mark+absent_without_info_mark+early_checkout_info_mark+misconduct_with_staff_mark+misconduct_with_student_mark+logsheet_not_checked_mark+other_issue_mark);
	// 	document.getElementById("negative_remark_mark").value=total_negative_mark;
		
	// 	var total_mark=parseFloat(timesheet_mark+utilisation_mark+task_mark+quality_work_mark+class_start_time_mark+class_end_time_r_mark+faculty_grooming_r_mark+logsheet_send_r_mark+mobile_used_r_mark+timetable_followed_r_mark+student_decoram_r_mark-total_negative_mark);
		
	// 	document.getElementById("points").value=total_mark;
	// }
	
	function validme()
	{   
		frm = document.jqueryForm;
		error='';
		disp_error = 'Clear The Following Errors : \n\n';	 
		if(frm.staff_id.value=='')
		{
			disp_error +='Select Staff Name\n';
			document.getElementById('staff_id').style.border = '1px solid #f00';
			frm.staff_id.focus();
			error='yes';
		}
		 if(frm.presence.value=='')
		 {
			//alert('hi');
			 disp_error +='Select Presence status\n';
			 document.getElementById('presence').style.border = '1px solid #f00';
			 frm.presence.focus();
			 error='yes';
		 }
		
		//  if(frm.presence_info.value=='')
		//  {
		// 	//alert('hi');
		// 	 disp_error +='select Absent Status\n';
		// 	 document.getElementById('presence_info').style.border = '1px solid #f00';
		// 	 frm.presence_info.focus();
		// 	 error='yes';
		//  }
		//  if(frm.absent_point.value=='')
		//  {
		// 	//alert('hi');
		// 	 disp_error +='Enter Absent Points\n';
		// 	 document.getElementById('absent_point').style.border = '1px solid #f00';
		// 	 frm.absent_point.focus();
		// 	 error='yes';
		//  } 
		 if(error=='yes')
		 {
			alert(disp_error);
			 return false;
		 }
		 else
		 return true;
	}
	function presences(vals)
	{   

	if(vals=='yes')
	{	Staff_ids=document.getElementById("staff_id").value;
		if(Staff_ids!='')
		{
			alert("Are You Want To Make Current Employee As Present");
			document.getElementById("contain").style.display = 'none';
			document.getElementById("contain1").style.display = 'none';
			setTimeout(select_key(Staff_ids),500);
			// setTimeout(select_key(),500);
			// check_data(this.value)
		}
		else[
			alert("Please Select the Staff ")
		]
	}
	else if(vals=='no')
	{
		alert("Are You Want To Make Current Employee As Not Present ");
		document.getElementById("key_titles").style.display = 'none';
		ok=document.getElementById("total_cnt").value=1;
		// alert(ok);
		document.getElementById("tot_points").value=0;
		document.getElementById("final_point").value=0;
		document.getElementById("contain").style.display = 'block';
		document.getElementById("contain1").style.display = 'block';

	}
	}
    </script>

</head>
<body>
<?php include "include/header.php";?>
<!--info start-->
<div id="info">
<!--left start-->
<?php include "include/menuLeft.php"; ?>
<!--left end-->
<!--right start-->
<div id="right_info">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
    <td class="top_left"></td>
    <td class="top_mid" valign="bottom"><?php include "include/payroll_menu.php"; ?></td>
    <td class="top_right"></td>
  </tr>
  <tr>
    <td class="mid_left"></td>
    <td class="mid_mid">
        <table width="100%" cellspacing="0" cellpadding="0">
        	<?php
            $errors=array(); $i=0;			
            $success=0;
            
            if($_POST['save_changes'])
            {
                $branch_name=( ($_POST['branch_name'])) ? $_POST['branch_name'] : "";
                $added_date=date('Y-m-d H:i:s');  
                $admin_id=$_SESSION['admin_id'];
				
				
				
				if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
				{
					$sel_branch="select cm_id ,admin_id from site_setting where branch_name='".$branch_name."' and type='A'";
					$ptr_branch=mysql_query($sel_branch);
					$data_branch=mysql_fetch_array($ptr_branch);
					$cm_id=$data_branch['cm_id'];
					
					$branch_name1=$branch_name;
					$_SESSION['cm_id_notification']=$data_branch['cm_id'];
				}	
				else
				{
					$cm_id=$_SESSION['cm_id'];
					$branch_name1=$_SESSION['branch_name'];
				}
				
                if(count($errors))
                {
					?>
					<tr><td colspan="2"> <br></br>
						<table align="left" style="text-align:left;" class="alert">
						<tr><td ><strong>Please correct the following errors</strong><ul>
								<?php
								for($k=0;$k<count($errors);$k++)
										echo '<li style="text-align:left;padding-top:5px;" class="green_head_font">'.$errors[$k].'</li>';?>
								</ul>
						</td></tr>
						</table>
					</td></tr>   <br></br>  
                    <?php
                }
                else
                {
					$tot_point='';
					$tot_earn_point='';
					$count=$_POST['total_cnt'];
					if($count > 1){
					$total_cnt=$count;
					}
					else{
						$total_cnt='1';
					}
					for($i=1;$i<=$total_cnt;$i++)
					{
						$date=( ($_POST['date'])) ? $_POST['date'] : "";
						if($date !='')
						{
							$seps_date = explode('/',$date);
							$report_date = $seps_date[2].'-'.$seps_date[1].'-'.$seps_date[0];
						}
							$data_record['employee_id'] = $_POST['staff_id'];
							$data_record['presence'] = $_POST['presence'];
							$data_record['without_info_absent'] = $_POST['presence_info'];
							if($_POST['presence']=='yes'){
							$data_record['key_point_id'] =$_POST['key_title'.$i];
							$data_record1['status']='present';
							}
							else{
								$data_record['key_point_id'] ='0';
								$data_record1['status']='absent';
							}
							if($_POST['presence_info']=='yes'){
								$my_point=$_POST['points'];
								$data_record['points'] =$my_point;
							}
							elseif($_POST['presence_info']=='no'){
								$my_point=$_POST['points'];
								$data_record['points'] =$my_point;
							}
							else{
								$data_record['points'] =$_POST['point'.$i];
							}
							$data_record['date']=$report_date;
							$data_record['admin_id'] =$admin_id;
							$data_record['cm_id'] =$cm_id;
							$data_record['added_date'] =$added_date;

							$checkout_prod_map_id=$db->query_insert("pm_daily_keypoint_performance", $data_record);
							// echo $checkout_prod_map_id;
						}
						if($_POST['presence_info']=='yes'){
							$tot_point=$_POST['absent_point'];
							$tot_percentage=$tot_point;
						}
						elseif($_POST['presence_info']=='no'){
							$tot_point=$_POST['absent_point'];
							$tot_percentage=$tot_point;
						}
						else{
						$tot_point=$_POST['points'];
						$fnl=$_POST['final_point']; 
						
						// $fnl_point=$fnl / 100;
						$per=$tot_point /$fnl;
						$tot_perc=$per * 100;
						$tot_percentage=round($tot_perc);
						}

						$data_record1['employee_id'] = $_POST['staff_id'];
						$data_record1['total_point'] = $tot_point;
						$data_record1['total_percentage']=$tot_percentage;
						$data_record1['cm_id'] =$cm_id;
						$data_record1['date']=$report_date;
						$data_record1['comment']=$_POST['comments'];
						$data_record1['admin_id'] =$admin_id;
						$data_record1['added_date'] =$added_date;
						$map_id=$db->query_insert("pm_total_keypoint_performancee", $data_record1);
					
                    echo ' <br></br><div id="msgbox" style="width:40%;">Record added successfully</center></div> <br></br>';
                    ?><div id="statusChangesDiv" title="Record Deleted"><center><br><p>Record added successfully</p></center></div>
                    <script type="text/javascript">
                    $(document).ready(function() {
                        $( "#statusChangesDiv" ).dialog({
                            modal: true,
                            buttons: {
                                Ok: function() { $( this ).dialog( "close" );}
                            }
                        });        
                    });
                    setTimeout('document.location.href="add_emp_performance.php";',500);
                    </script>
                    <?php
                }
            }
			if($success==0)
			{
				?>
            	<tr><td>
   				<form method="post" id="jqueryForm" name="jqueryForm" enctype="multipart/form-data" >
				<table border="0" cellspacing="15" cellpadding="0" width="100%">
              	<tr>
                <td colspan="3" class="orange_font">* Mandatory Fields</td>
                </tr>
				<tr>
                    <td width="20%">Select Date<span class="orange_font">*</span></td>
                    <td><input type="text" name="date" class="input_text datepicker" placeholder="Date" id="date" title="Date" value="<?php if($_REQUEST['date']) echo $_REQUEST['date']; else echo date('d/m/Y',strtotime('-1 days')) ?>">
                    </td>
                </tr>
                <tr>
                <td width="20%"> Branch Name<span class="orange_font">*</span></td>
				<?php 
                if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
                {
                    ?>
                    <td>
                        <select name="branch_name" id="branch_name" class="input_select_login" style="width: 300px;" onchange="getstaffDetails(this.value)">
                        <option value="">Select Branch </option>
                        <?php 
                        $sel_branch="select branch_id,branch_name from branch where status='Active'";
                        $ptr_sel=mysql_query($sel_branch);
                        while($data_branch=mysql_fetch_array($ptr_sel))
                        {
                            // $sel='';
                            // if($data_branch['branch_name']==$_GET['branch_name'])
                            // {
                            //     $sel='selected="selected"';
                            // }
                            // else if($data_branch['branch_name']=='Pune')
                            // {
                            //     $sel='selected="selected"';
                            // }
                            echo '<option  value="'.$data_branch['branch_name'].'" > '.$data_branch['branch_name'].'</option>';
                        }
                        ?>
                        </select>
                    </td>
                    <?php
                }
                else 
                {
                    ?>
                    <td colspan="2" align="left">
                    <input type="hidden" name="branch_name" id="branch_name" value="<?php echo $_SESSION['branch_name']; ?>" />
                    </td>
                    <?php 
                }
				?>
                <tr>
                    <td width="20%">Select Staff<span class="orange_font">*</span></td>
                    <td id="staff_ids">
                        <select name="staff_id" id="staff_id" class="input_select" style="width:300px" onchange="check_data(this.value),select_key(this.value)">
                            <option value="">Select Staff</option>
                            <?php
                            if($_SESSION['type']=='S' || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
                            {
                                // if($_REQUEST['branch_name']!='')
                                // {
                                    $branch_name=$_REQUEST['branch_name'];
                                    $select_cm_id="select cm_id from site_setting where branch_name='".$branch_name."' and type='A'";
                                    $ptr_cm_id=mysql_query($select_cm_id);
                                    $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                    $search_cm_id=" and cm_id='".$data_cm_id['cm_id']."'";
                                    $cm_ids=$data_cm_id['cm_id'];
                                // }
                                // else
                                // {
                                //     $search_cm_id=" and cm_id='2'";
                                //     $cm_ids='2';
                                // }
                            }
                            $sle_name="select admin_id,name from site_setting where 1 ".$_SESSION['where']." ".$search_cm_id." and system_status='Enabled' order by name asc"; 
                            $ptr_name=mysql_query($sle_name);
                            while($data_name=mysql_fetch_array($ptr_name))
                            {
                                // $selected='';
                                // if($data_name['admin_id'] == $_REQUEST['staff_id'])
                                // {
                                //     $selected='selected="selected"';
                                // }
                                echo '<option  value="'.$data_name['admin_id'].'">'.$data_name['name'].'</option>';
                            }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="20%">Presence<span class="orange_font">*</span></td>
                    <td>
                        <select name="presence" id="presence" class="input_select" onchange="presences(this.value)">
                        	<option value="">Select Presence</option>
                        	<option value="yes">Yes</option>
                            <option value="no">No</option>
                        </select>
                    </td>
                    <td></td>
                </tr>
				<tr>
                    <td width="20%"> <div style="display:none" id="contain1">Absent Without Info<span class="orange_font">*</span></div></td>
                    <td>
					<div style="display:none" id="contain">
                        <select name="presence_info" id="presence_info" class="input_select" style="width:300px" onchange="absent_points(this.value)" >
                        	<option value="">Select </option>
                        	<option value="yes">Yes</option>
                            <option value="no">No</option>
                        </select>
						<input type="text" name="absent_point" id="absent_point" value="" placeholder=" Absent points" onchange="calculate_absent_point(this.value)" />
						</div>
                    </td>
                    <td></td>
                </tr>       
                <tr>
                    <td width="20%"><strong>Rules Followed</strong><span class="orange_font">*</span></td>
                </tr>
                <tr>
                <td></td>
                <td width="100%" id="key_titles">       
                </td>
                </tr>  
				<tr>
                    <td width="20%">Comment<span class="orange_font">*</span></td>
                    <td>
                        <textarea rows="3" cols="116" name="comments" id="comments"><?php if($_POST['save_changes']) echo $_POST['comments']; ?></textarea>
                    </td>
                    <td></td>
                </tr>              
                <tr>
                    <td width="20%">Total Points<span class="orange_font">*</span></td>
                    <td>
                        <input type="text" name="points" class="input_text" readonly="readonly" id="tot_points" title="points" value="">
						<input type="hidden" name="final_point" class="input_text" readonly="readonly" id="final_point" value="">
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td align="center" colspan="2"><input type="submit" onclick="return validme()" name="save_changes"  value="Save"  /></td>
                </tr>
        	</table>
        	</form>
        	</td></tr>
			<?php
         }   
		 ?>
	 
        </table></td>
    <td class="mid_right"></td>
  </tr>
  <tr>
    <td class="bottom_left"></td>
    <td class="bottom_mid"></td>
    <td class="bottom_right"></td>
  </tr>
</table>
<script>
function calculate_absent_point(val)
	{
		var presence=document.getElementById("presence").value;
		var info=document.getElementById("presence_info").value;
		if(presence=='no'){
			if(info=='yes'){
				if(val ==0){
					alert("  The Value Should Be Non Zero; Otherwise Select Another Option");
					document.getElementById('absent_point').value = "";
				}
				else{
			points= document.getElementById("absent_point").value;
			total_points='-'+points;
				}
			}
			else if(info=='no'){
				if(val !=0){
					alert(" The Value Should Be  Zero;");
					document.getElementById('absent_point').value = "";
				}
				else{
			points= document.getElementById("absent_point").value;
			total_points=points;
				}
			}
			// alert(total_points);
		document.getElementById("tot_points").value=total_points;
		}
		// else if(presence=='no'){
		// 	document.getElementById("tot_points").value="";
		// }
	}
	function absent_points(val)
	{
		var info=document.getElementById("presence_info").value;
				// alert(info);
			if(info=='yes'){
				point='-'+100;
			}
			else{
				point=0;
			}
			document.getElementById("tot_points").value=point;
			document.getElementById("absent_point").value=point;
	}
</script>
</div>
<!--right end-->

</div>
<!--info end-->
<div class="clearit"></div>
<!--footer start-->
<div id="footer"><? require("include/footer.php");?></div>
<!--footer end-->
</body>
</html>
<?php $db->close();?>