<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2015 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>
 ********************************************************************************/
$groupname = isset($this->groupname)?$this->groupname:'';
$groupid = isset($this->groupid)?$this->groupid:'';

?>
<form name="assignemployees" id="formid" action= "" method="post" >
<input type="hidden" name="groupid" id="groupid" value="<?php echo $groupid;?>" />
<div class="veiw_form_emp">
<div id="actionButtonsDiv" class="new-form-ui-submit inner_action_div"  style="margin-top: 9px;">  
			<button onclick="slideupqsdiv()" type="button" id="Cancel" name="Cancel">Close</button>
			
			</div></div>
<div id="" class="grpnamecls_2">
<div class="up_arrow"></div>
	
</div>


<div id="groupnamediv" class="grpnamecls">
<div class="up_arrow"></div>
	<label class="required">Group Name</label>
	<input type="text" maxlength="30" name="group_name" id="group_name" value="<?php echo $groupname;?>" onblur='validategroupname(this)' onkeyup='validategroupname(this)'>
</div>

	
	
	<span id="success_users_message" style="display:none;  margin-left: 5px;" class="green_color_text"></span>

<div class="clear"></div>

<div class="users_list">

<div class="left-user">
<div class="users_list_left_title">Employees <!--(Click on an employee to add to group)--></div>
		<div class="search_emp_by_name_div">
			<input type="text" name="search_emp_by_name" id="search_emp_by_name" value="" placeholder="Search Employee"/>
			<input type="button" value="Go" name="search" id="search">&nbsp;
			<input type="button" id="idclear" name="tclear" value="Clear" class="btn_search_clear" onclick="javascript:clearSearchData();"/>
			
		</div>
		<div class="clearall"></div>
<?php 
$height = sapp_PerformanceHelper::calculateheight(count($this->ungroupedEmployeeDetails));	
?>		

<div class="users_list_left" style=" height: <?php echo $height; ?>" >

<?php
if(count($this->ungroupedEmployeeDetails) > 0)
{
	$isUser = 0;
	
	foreach($this->ungroupedEmployeeDetails as $emp)
	{
		$jobtitle_length=strlen($emp['jobtitle_name']);
		$jobtitle =$emp['jobtitle_name'];
			?>
			<div class="users_left_list_div users_left_list user_div_<?php echo $emp['user_id'];?>" style="cursor:pointer;" onclick="javascript:fnAddRemoveProjectUser(1,'<?php echo $emp['user_id'];?>','<?php echo addslashes($emp['userfullname']);?>','<?php echo $emp['profileimg'];?>','<?php echo $emp['employeeId'];?>','<?php echo $emp['jobtitle_name'];?>');" subject = "<?php echo $emp['user_id'];?>" alt="Add" title="<?php echo addslashes($emp['userfullname']);?>" name="<?php echo addslashes($emp['userfullname']);?>">
			<span class="values">
			<div class="profile_img">
			<img src="<?php echo $this->baseUrl("public/uploads/profile/").$emp['profileimg'];?>" width="28px"  height="28px" onerror="this.src='<?php echo MEDIA_PATH; ?>images/default-profile-pic.jpg'"/>
			</div> </span> 
			<span class="member_name" title="<?php echo $emp['userfullname'];?>"><?php echo $emp['userfullname'];?></span>
           	<span class="member_id" title="<?php echo $emp['employeeId'];?>">(<?php echo $emp['employeeId'];?>)</span>
            <span class="member_jname" title="<?php echo $emp['jobtitle_name'];?>"><?php echo ($jobtitle_length<=17)?$jobtitle:substr($jobtitle,0,15) . '...';?></span>
			</div>
			<?php
			$isUser++;
			
	}
	if($isUser < 1)
	{
		?>
		<div class="users_left_list_div no_left_data_found"><span class="values">Employees are not available.</span></div>
		<?php		
	}
}
else
{
?>
	<div class="users_left_list_div no_left_data_found" ><span class="values">Employees are not available.</span></div>
<?php
}
?>

<div class="users_left_list_div  no_search_results" style="display:none"><span class="values">No results were found.</span></div> 

</div>
</div>
<div class="left-user right_left_user">
<div class="users_list_right_title">Selected Employees<span class="emp_count">(<span id="emp_count_val"><?php echo isset($this->empcount)?$this->empcount:0;?></span>)</span></div>

		<div class="search_emp_by_name_div">
			<input type="text" name="search_emp_by_name" id="search_emp_by_name_right" value="" placeholder="Search Employee"/>
			<input type="button" value="Go" name="search" id="search_right">&nbsp;
			<input type="button" id="idclear_right" name="tclear" value="Clear" class="btn_search_clear" onclick="javascript:clearSearchData_right();"/>
			
		</div>
		<div class="clearall"></div>
<?php 
$height = sapp_PerformanceHelper::calculateheight(count($this->groupedEmployeeDetails));
if(count($this->ungroupedEmployeeDetails) > 0)
{
?>		
<div class="users_list_right" style=" height: <?php echo $height; ?>">
<div class="users_right_list_div no_right_data_found" style="display:block;"><span class="values">Add employees to group.</span></div>

<?php
}
$exist_member_ids = '';
if(count($this->groupedEmployeeDetails) > 0)
{
	$isUser = 0;
	foreach($this->groupedEmployeeDetails as $emp)
	{
		$jobtitle_length=strlen($emp['jobtitle_name']);
		$jobtitle =$emp['jobtitle_name'];
  ?>
			<div class="users_right_list_div users_right_list user_div_<?php echo $emp['user_id'];?>" style="cursor:pointer;" onclick="javascript:fnAddRemoveProjectUser(0,'<?php echo $emp['user_id'];?>','<?php echo addslashes($emp['userfullname']);?>','<?php echo $emp['profileimg'];?>','<?php echo $emp['employeeId'];?>','<?php echo $emp['jobtitle_name'];?>');" subject = "<?php echo $emp['user_id'];?>" alt="Add" title="<?php echo addslashes($emp['userfullname']);?>" name="<?php echo addslashes($emp['userfullname']);?>">
			<span class="values">
			<div class="profile_img">
			<img src="<?php echo $this->baseUrl("public/uploads/profile/").$emp['profileimg'];?>" width="28px"  height="28px" onerror="this.src='<?php echo MEDIA_PATH; ?>images/default-profile-pic.jpg'"/>
			</div> </span> 
			<span class="member_name" title="<?php echo $emp['userfullname'];?>"><?php echo $emp['userfullname'];?></span>
           	<span class="member_id" title="<?php echo $emp['employeeId'];?>">(<?php echo $emp['employeeId'];?>)</span>
            <span class="member_jname" title="<?php echo $emp['jobtitle_name'];?>"><?php echo ($jobtitle_length<=17)?$jobtitle:substr($jobtitle,0,15) . '...';?></span>
			</div>
			<?php
			$isUser++;
			$exist_member_ids.= $emp['user_id'].',';
	}
	if($isUser < 1)
	{
		?>
		<div class="added_users_list_div no_added_user_found"><span class="values">Employees are not available.</span></div>
		<?php		
	}
	if($exist_member_ids !='')
	  $exist_member_ids = rtrim($exist_member_ids,',');
}
else
{
?>
	<div class="added_users_list_div no_added_user_found" style="display:none;"><span class="values">Employees are not grouped yet.</span></div>
<?php
}
?>
<div class="users_right_list_div  no_search_results_right" style="display:none"><span class="values">No results were found.</span></div>


</div>

</div>

<input type="hidden" name="mem_list_str" id="mem_list_str" value="" />

<input type="hidden" name="edit_group_id" id="edit_group_id" value="<?php echo $this->groupid;?>" />

<input type="hidden" name="existetd_mem_str" id="existetd_mem_str" value="<?php echo $exist_member_ids;?>" />

<input type="hidden" name="original_mem_str" id="original_mem_str" value="<?php echo $exist_member_ids;?>" />

<?php 
			if(!empty($this->questionsArr))
				{
					sapp_PerformanceHelper::questions_privileges($this->questionsArr,$this->appraisalid,$this->checkArr,$this->initializationdata);
?>	
				<div class="content_box add_new_fields checklist_new_fields action_buttons_div">
					<span id="no_members_error" style="display:none;color: red; position: absolute; font-size: 12px; margin-left: 4px;"></span>
					<div id="actionButtonsDiv" class="new-form-ui-submit inner_action_div" style="margin-right: 0px; float: left;">  
					
					<input type="button" name="saveFiled" id="saveFiled" style="margin-right: 0px; float: left;" class="raise_button" value="Save" onclick="javascript:fnSaveMappedEmployees('<?php echo $this->groupid;?>','<?php echo $this->appraisalid;?>');" /> &nbsp;
					<input type="submit" style="display:none;" style="margin-right: 0px; float: left;" name="savehiddenFiled" id="savehiddenFiled" class="raise_button" value="Save" onclick="javascript:saveempgroupdetails('appraisalinit/savegroupedemployeesajax/format/json');" /> &nbsp;
					
					</div>
				</div>
				
<?php			}else
				{		
?>
				
				<div style="clear: both;position: relative;top: 17px;width: 92%;" class="ml-alert-1-error">
						<div class="style-1-icon error"></div>
							Questions are not configured. Click <a href="<?php echo BASE_URL.'/appraisalquestions/add'?>" style="color:#A31414;text-decoration: none;font-weight: bold;">here </a> to configure questions.
				</div>
<?php }?>

		

</div>
</form>

<script type="text/javascript" language="javascript">
$(document).ready(function()
{
	$("form").bind("keypress", function(e) {
		if (e.keyCode == 13) return false;
	});	
	group_emp_ready_fn();
	$("#qssubmitdiv").remove();
});

</script>
 