<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2014 Sapplica
 *   
 *  Sentrifugo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sentrifugo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sentrifugo.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Sentrifugo Support <support@sentrifugo.com>
 ********************************************************************************/

if($this->error_msg !='')
{
?>
    <div class="ml-alert-1-info m1-info-set"><div class="style-1-icon info"></div><?php echo $this->error_msg;?></div>
<?php 
}
else 
{ ?>

<?php if(empty($this->emp_data)) { ?>
				<div class="managerresponsediv_msg" style="margin-top: 100px;">
					No data found.
				</div>
	
<?php } else {	   
    $emp_data = $this->emp_data;
    $manager_id = $this->manager_id;
    $status_arr = array(0 => 'Pending employee ratings',1 => 'Pending L1 ratings',2 => 'Pending L2 ratings',
                3 => 'Pending L3 ratings',4 => 'Pending L4 ratings',5 => 'Pending L5 ratings',6 => 'Completed');  
        
?>
    <script type="text/javascript" src="<?php echo MEDIA_PATH;?>js/pa.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo MEDIA_PATH; ?>css/rateit.css" />
    <script type="text/javascript" src="<?php echo MEDIA_PATH;?>js/jquery.rateit.js"></script>
    <span id="error_message"></span>
    
<?php 
    if(count($emp_data) > 0)
    {
?>
<?php   
		$profile_img_src = $line_manager_img_src = MEDIA_PATH.'images/default-profile-pic.jpg';         
        foreach($emp_data as $key => $edata)
        {     
            //echo "<pre>";print_r($edata);echo "</pre>";
            if($edata['appraisal_ratings'] == 1)
            {
                $ratingMin = 0; $ratingMax = 5;
            } 
            else 
            {
                $ratingMin = 0; $ratingMax = 10;
            }
?>
            <div id="idmaindiv_<?php echo $key;?>" class="employee_appraisal_details_full my_team_appri_row"> 
                <div  class="manager_feed_div_ manager_feed_div_2">
					<div class="users_left_list_div users_list">
						<span class="values">
							<div class="profile_img">
									<img src="<?php echo $this->baseUrl("public/uploads/profile/").$edata['profileimg'];?>" width="28px"  height="28px" onerror="this.src='<?php echo MEDIA_PATH; ?>images/default-profile-pic.jpg'"/>
							</div>
						</span>
							
						<span class="member_name"><?php echo $edata['userfullname'];?></span>
						<span class="member_id">(<?php echo $edata['employeeId'];?>)</span>
						<span class="member_jname"><?php echo $edata['jobtitle_name'];?></span>
					</div>
					<!--div class="status_div pending"><?php echo $edata['appraisal_status'];?></div-->
					<div class="status_div_block"><span>Appraisal Status</span><div class="status_div <?php echo $edata['appraisal_status']=='Completed'?'completed':'pending';?>"><?php echo $edata['appraisal_status']=='Completed'?'Completed':$edata['appraisal_status'];?></div></div>
					<?php 
							for($i=1;$i<=5;$i++)
							{
								if(strpos($edata['appraisal_status'],"$i") !== false) break;
								if(isset($edata['line_rating_'.$i]) && $edata['line_rating_'.$i]!='')
								{		
								  if (!empty($edata['line_manager_img_'.$edata['line_manager_'.$i]])) {
										$line_manager_img_src = $this->baseUrl("public/uploads/profile/").$edata['line_manager_img_'.$edata['line_manager_'.$i]];	
									}
					?>
									<div class="users_left_list_div users_list other_mana <?php echo ($i > 1)?'other_mana_more':'';?>"> 
										<span class="values">
											<div class="profile_img">
												<img class="js_profile_img" src="<?php echo $line_manager_img_src;?>" width="28px"  height="28px" onerror="this.src='<?php echo MEDIA_PATH; ?>images/default-profile-pic.jpg'"/>
											</div>
										</span>
										<span class="line_mgr_text">L<?php echo $i;?> Rating</span>
										<span class="line_mgr_rat"><?php echo $edata['line_rating_'.$i];?></span>
									</div>
					<?php
								}
							} 
					?>
					<div class="clear"></div>					
                </div>
                
<?php 
            if($edata['manager_editing_status'] == 'add_edit')
            {
                //if($edata['appraisal_status'] == 'Pending L1 ratings')
                //{
?>
				<form name="frm_manager_response_<?php echo $key;?>" id="idfrm_manager_response_<?php echo $key;?>" method="post" action="">
<?php                 
                //}
?>                
                <div class="add_manager_response" id="id_add_manager_response_<?php echo $key;?>">
                    <span class="l_manager_txt">L<?php echo $edata['line_status'];?> Manager Overall Rating</span>
                    <input class="app_req_field li_rating_class_<?php echo $key;?>" type="hidden" id="consol_rating_<?php echo $key;?>" name="consol_rating" value="<?php echo $edata['line_rating_'.$edata['line_status']];?>">
                    <div id="id_rate_<?php echo $key;?>" class="rateit" data-rateit-backingfld="#consol_rating_<?php echo $key;?>" data-rateit-step="1" 
                         data-rateit-resetable="false" data-rateit-min="<?php echo $ratingMin;?>" 
                         data-rateit-max="<?php echo $ratingMax;?>"></div>
                    <textarea class="app_req_field_<?php echo $key;?> exp-textarea_<?php echo $key;?> appri_textarea" name="consol_comments" style="margin-top: 4px; height: 27px;" id="idconsol_comments_<?php echo $key;?>"><?php echo $edata['line_comment_'.$edata['line_status']];?></textarea>
					<?php        
                if($edata['line_status'] > 1)
                {                    
				?>					
					<div class="manager_links">
                        <span class="mng_submit" id="id_submit_<?php echo $key;?>" data-key="<?php echo $key;?>">Submit</span>
                        <span class="mng_sdraft" id="id_sdraft_<?php echo $key;?>" data-key="<?php echo $key;?>">Save as Draft</span>
                        <span class="mng_sclear" id="id_sclear_<?php echo $key;?>" data-key="<?php echo $key;?>">Clear</span>
                    </div>
				<?php     
                }
				?>	
                </div>
<?php        
                if($edata['line_status'] > 1)
                {                    
?>
                        <input type="hidden" name="hid_btn_flag" id="idhid_btn_flag_<?php echo $key;?>" />
                        <input type="hidden" name="hid_total_lines" id="idhid_total_lines_<?php echo $key;?>" value="<?php echo $edata['total_lines'];?>" />
                        <input type="hidden" name="hid_consolidated_rating" id="idhid_consolidated_rating_<?php echo $key;?>" value="<?php echo $edata['consolidated_rating'];?>" />
                        <input type="hidden" name="hid_emp_id" id="idhid_emp_id_<?php echo $key;?>" value="<?php echo $edata['user_id'];?>" />
                        <input type="hidden" name="hid_init_id" id="idhid_init_id_<?php echo $key;?>" value="<?php echo $edata['init_id'];?>" />
                        <input type="hidden" name="hid_line_status" id="idhid_line_status_<?php echo $key;?>" value="<?php echo $edata['line_status'];?>" />
                    </form> 
                  
<?php     
                }
            }
            if(array_search($edata['appraisal_status'], $status_arr) > 0)
            {
?>
                <div data-key="<?php echo $key;?>" data-user ="<?php echo sapp_Global::_encrypt($edata['user_id']);?>" 
                     data-flag = "<?php echo sapp_Global::_encrypt($edata['manager_editing_status']);?>" 
                     data-status = "<?php echo sapp_Global::_encrypt($edata['appraisal_status']);?>" 
                     data-init_id ="<?php echo sapp_Global::_encrypt($edata['init_id']);?>" 
                     data-config_id ="<?php echo sapp_Global::_encrypt($edata['pa_configured_id']);?>" 
                     data-app_rating ="<?php echo sapp_Global::_encrypt($edata['appraisal_ratings']);?>" 
                     class="div_collapse cls_expand" id="iddiv_collapse_<?php echo $key;?>">Expand</div>                
                <div id="iddivcontent_<?php echo $key;?>" class="employee_appraisal_tabs my_team_apprisal" style="display:none;"></div>                
<?php 
                if($edata['appraisal_status'] == 'Pending L1 ratings')
                {
                    echo "</form>";
                }
            }
?>
	<div class="clear"></div>   
</div>

<?php     
        }
?>
<?php            
    }
    else 
    {
?>
        <div class="ml-alert-1-info m1-info-set"><div class="style-1-icon info"></div>No employees found.</div>
<?php     
    }
?>
    
<?php 
}}
?>
<script type='text/javascript'>
$(document).ready(function(){
	$('.mng_sdraft').click(function(){
		var key = $(this).attr('data-key');            
		save_mng_response(key,'draft');
	});
	$('.mng_submit').click(function(){
		var id = $(this).prop('id');
		jConfirm("Are you sure you want to submit your response?", "Confirmation", function(r) 
		{
			if(r==true)
			{
				var key = $('#'+id).attr('data-key');            
				save_mng_response(key,'submit');
			}
		});
		
	});
	$('.mng_sclear').click(function(){
		var key = $(this).attr('data-key');
		$('#consol_rating_'+key).val('');
		$('#idconsol_comments_'+key).val('');
		$('#id_rate_'+key).rateit('value', null);
	});
	$('.div_collapse').click(function(){
		var parentid = $(this).parent().attr('id');
		var key = $(this).attr('data-key');
		var id = $(this).prop('id');
		var disp_status = $('#iddivcontent_'+key).is(':visible');
		if(disp_status == false)
		{
			var user_id = $(this).attr('data-user');
			var flag = $(this).attr('data-flag');
			var emp_status = $(this).attr('data-status');
			var app_id = $(this).attr('data-init_id');
			var config_id = $(this).attr('data-config_id');
			var app_rating = $(this).attr('data-app_rating');
			var params = {emp_status:emp_status,key:key,user_id:user_id,flag:flag,appraisal_id:app_id,manager_id:'<?php echo sapp_Global::_encrypt($this->manager_id);?>',app_config_id:config_id,app_rating:app_rating};
			$.blockUI({ width:'50px',message: $("#spinner").html() });
			$.post(base_url+'/myteamappraisal/getempcontent/format/html',params,function(data){
				$('#'+id).removeClass('cls_expand');
				$('#'+id).addClass('cls_collapse');
				$('#iddivcontent_'+key).show();
				$('#iddivcontent_'+key).html(data);
				$('#'+id).html('Collapse');
				$('#'+parentid).addClass('expand_manager');
				$.unblockUI();
			},'html');
			
		}
		else
		{
			$('#iddivcontent_'+key).html('');
			$(this).addClass('cls_expand');
			$(this).removeClass('cls_collapse');
			$('#iddivcontent_'+key).hide();
			$('#'+parentid).removeClass('expand_manager');
			$(this).html('Expand');
		}
	});

	$('#idclear').hide();
	$(".search_go").hide();
	$('#search_emp_by_name').bind('keyup', function(event) {
		var keycode = (event.keyCode ? event.keyCode : event.which);
		if(keycode == '13'){
			displaysearchedteam();
		}
		if(this.value)
		{
			$('#idclear').show();
			$(".search_go").show();
		}
		else
		{
			$('#idclear').hide();
			$(".search_go").hide();
		}
	});

	
});//end of ready function.
</script>