Location: PHPKode > projects > SimpleHRM > simplehrm-1.0-beta1/simplehrm-1.0-beta1/flexycms/modules/company/company_manager.php
<?php
/*
 * Class   : company_manager
 * Purpose : All company related functionalities goes here
 */
class company_manager extends mod_manager {
#######################################################################################################
### Function Name : company_manager								    ###
### Description   : This is a constructor      							    ###					 
### Input         : Reference of smarty,input and output parameters 	  			    ###
### Output	  : Initiates mod manager and initialize object and business class for user manager ###
#######################################################################################################
	function company_manager (& $smarty, & $_output, & $_input) {
		if($_REQUEST['ce']!='0'){
	    		check_session();
	    	}else{
	    		//for autocomplete and fancybox
	    		if(!$_SESSION['id_user'] && $_REQUEST['for']=='norauto'){
	    			exit("<span class='fcolor'>".getmessage('COM_NO_SESSION')."</span>|".getmessage('COM_NO_SESSION'));
	    		}elseif(!$_SESSION['id_user']){
	    			//exit("<span class='fcolor'>".getmessage('COM_NO_SESSION')."</span>");
				if($_REQUEST['choice'] == 'downLoadHrForm') {
					check_session();
				}else{
					exit("nosession");
				}
	    		}
	    	}
		$this->mod_manager($smarty, $_output, $_input, 'company');
		$this->obj_company= new company;
		$this->company_bl = new company_bl;
 	}
##################################################################################
### Function Name : get_module_name(Predefined Function) 		       ###
##################################################################################
	function get_module_name() { 
		return 'company';
	}
##################################################################################
### Function Name : get_manager_name(Predefined Function) 		       ###
##################################################################################
	function get_manager_name() {
		return 'company';
	}
##################################################################################
### Function Name : default(Predefined Function) 		               ###
### Description   : Handle default request(if no choice specified)             ###
##################################################################################
	function _default() {
		return true;
	}
##################################################################################
### Function Name : manager_error_handler			               ###
### Description   : Function to handle error when choice not found             ###
### Input         : No input 					               ###
### Ouput	  : Error handling template.		                       ###
##################################################################################
	function manager_error_handler() {
		$call = "_".$this->_input['choice'];
		if (function_exists($call)) {
			$call($this);
		} else {
			//Put your own error handling code here
			$this->_output['tpl'] ='default/error_handler';
		}
	}
	
	
##################################################################################
### Function Name : companyInfo                                                ###
### Description   : This function show the company information listing or edit ###
### Input         : no input for listing and edit flag for edit information    ###
### Output         : Show company information listing or edit template         ###
##################################################################################
	function _companyInfo(){
		global $link;
		$sql_cinfo = 'CALL get_search_sql("'.TABLE_PREFIX.'company","id_company='.$_SESSION['id_company'].' LIMIT 1")';
		$this->_output['res'] = getsingleindexrow($sql_cinfo);
		
		$company_sql = $this->company_bl->generalConf();
		$company_res = getsingleindexrow($company_sql);

		$this->_output['company_res'] = $company_res;

		if($this->_input['edit']){
			
			$timezone_sql ='CALL get_search_sql("'.TABLE_PREFIX.'timezone","")';
			$timezone_res = getindexrows($timezone_sql,"timezone_value","timezone_text");
				
			$this->_output['timezone']    = $timezone_res;
			$this->_output['currency']    = $GLOBALS['conf']['CURRENCY'];

			$this->_output['tpl'] = 'company/editCompanyInfo';
		}else{
			$sql_cnt_emp="SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."employee E LEFT JOIN ".TABLE_PREFIX."employeeTerminationContract ETC ON E.id_employee=ETC.id_employee WHERE IF(terminate_date!='',terminate_date > NOW(),1) AND id_company=".$_SESSION['id_company'];
			$res_cnt_emp = getsingleindexrow($sql_cnt_emp);
			
			$this->_output['res']['cnt'] = $res_cnt_emp['cnt'];
			$this->_output['tpl'] = 'company/companyInfo';
		}
	}
	
###############################################################################
### Function Name : previewImage                                            ###
### Description   : Function to show preview image during edit company info ###
### Input         : Files array                                             ###
### Output         : Name of the image                                      ###
###############################################################################
	function _previewImage(){
		if ($_FILES['image']['name']){
			$time= strtotime("now");
			$rid= $time."_";
			$uploadDir= APP_ROOT.$GLOBALS['conf']['IMAGE']['preview_orig'];
			$thumbnailDir= APP_ROOT.$GLOBALS['conf']['IMAGE']['preview_thumb'];
			$thumb_height= $GLOBALS['conf']['IMAGE']['thumb_height'];
			$thumb_width= $GLOBALS['conf']['IMAGE']['thumb_width'];
			$fname = $rid.convert_me($_FILES['image']['name']);
			
			$file_tmp = $_FILES['image']['tmp_name'];
			$status	= copy($file_tmp, $uploadDir.$fname);
			$copy_thumb= copy($uploadDir.$fname, $thumbnailDir.$fname);			
			$this->r = new thumbnail_manager($uploadDir.$fname,$thumbnailDir.$fname);
			$this->r->get_container_thumb($thumb_height,$thumb_width,0,0);
			print $fname;
		}
	}

##############################################################################################
### Function Name : editCompanyInfo                                      		   ###
### Description   : Function to edit company information  				   ###
### Input         : Form data as array                                                     ###
### Output        : Updated company information to table and redirect to company info page ###
##############################################################################################
	function _editCompanyInfo(){
		if($this->_input['previewimg']){
			$uploadDir = APP_ROOT.$GLOBALS['conf']['IMAGE']['companylogo_orig'];
			$thumbnailDir= APP_ROOT.$GLOBALS['conf']['IMAGE']['companylogo_image_thumb'];
			$thumb_height= $GLOBALS['conf']['IMAGE']['thumb_height'];
			$thumb_width= $GLOBALS['conf']['IMAGE']['thumb_width'];
			
			$img= trim(strstr($this->_input['previewimg'],'_'),'_');
			$fname= $_SESSION['id_company']."_".$img;			
			$this->_input['company']['logo'] = $img;			
			$_SESSION['logo'] = $_SESSION['id_company']."_".$img;
			
			$sourcefile= APP_ROOT.$GLOBALS['conf']['IMAGE']['preview_orig'].$this->_input['previewimg'];
			$status	= @copy($sourcefile, $uploadDir.$fname);
			$copy_thumb= @copy($uploadDir.$fname, $thumbnailDir.$fname);
			$this->r= new thumbnail_manager($uploadDir.$fname,$thumbnailDir.$fname);
			$this->r->get_container_thumb($thumb_height,$thumb_width,0,0);
			@unlink($uploadDir.$_SESSION['id_company']."_".$this->_input['hidimg']);
		}		
		$r = $this->obj_company->editCompany("company",$this->_input['company']);
		if($r){
			$_SESSION['company_name'] = $this->_input['company']['company_name'];
			$_SESSION['raise_message']['global'] = getmessage('COM_UPD_SUCC');
		}
		redirect(LBL_SITE_URL."company/companyInfo");
	}
	
######################################################################################
### Function Name : addEditDivision                                                ###
### Description   : This function open addEditDivision modal form                  ###
### Input         : no input                                                       ###
### Ouput         : company addEditDivision template                               ###
######################################################################################
	function _addEditDivision(){
		$ch=$this->_input['ch'];
		$id=$this->_input['id'];
		if($ch=='edit'){
			$cond="id_division=".$id." AND id_company=".$_SESSION['id_company'];
			$sql='CALL get_search_sql("'.TABLE_PREFIX.'companyDivision","'.$cond.'")';
			$this->_output['res_division']=getsingleindexrow($sql);
		}
		$this->_output['start']=$this->_input['start'];
		$this->_output['tpl']='company/addEditDivision';
	}
######################################################################################
### Function Name : divisions                                                      ###
### Description   : This function show the company divisions information           ###
### Input         : one status variable is taken for redirecting to                ###
###					divisionslisting or divisions              ###
### Ouput         : company divisions  or  divisionslisting template               ###
######################################################################################
	function _divisions($x=0){
		$sql="SELECT id_division, div_name,notes FROM ".TABLE_PREFIX."companyDivision";
		$uri = 'company/divisions';
		$this->_output['type']	= "box";  // no, extra, nextprev, advance, normal, box
		$this->_output['pg_header'] = "Divisions List";
		$this->_output['field'] = array("div_name"=>array("Division Name", 1));
		$this->_output['limit'] = $GLOBALS['conf']['PAGINATE']['rec_per_page'];
		$this->_output['show'] = $GLOBALS['conf']['PAGINATE']['show_page'];
		$this->_output['sql'] = $sql;
		$this->_output['uri'] = $uri;
		$this->_output['ajax']= "ajax";
		$this->_output['sort_order']= "DESC";
		$this->_output['sort_by']= "id_division";
		$this->_input['qstart']=$this->_input['qstart'];
		$this->_output['res1']=$this->commonEmpCount('id_division','companyDivision','division');
		if(isset($this->_input['qstart']) || $x){
			$this->_input['choice']='divisions';
			$this->company_bl->page_listing($this,"company/divisionlisting"); 
		}else{
			$this->company_bl->page_listing($this,"company/division"); 
		}
	}
######################################################################################
### Function Name : commonEmpCount                                                 ###
### Description   : This function returns the nunber of employee associated with   ###
###                a particular division or department or team or jobtitle likewise###
### Input         : id table ,tableneme,groupby id                                 ###
### Ouput         : returns the result result in an array format                   ###
######################################################################################
	function commonEmpCount($id,$tbl,$group_by){
		$sql_cnt_emp="SELECT D.".$id.",COUNT(*) AS cnt,emp_status,id_employee,joined_date FROM (SELECT E.*,ETC.terminate_date FROM ".TABLE_PREFIX."employee E LEFT JOIN ".TABLE_PREFIX."employeeTerminationContract ETC ON E.id_employee=ETC.id_employee) AS TE , ".TABLE_PREFIX.$tbl." D WHERE TE.".$group_by."=D.".$id." AND IF(terminate_date!='',terminate_date > NOW(),1) AND TE.id_company=".$_SESSION['id_company']." GROUP BY TE.".$group_by;
		//print $sql_cnt_emp;
		return getindexrows($sql_cnt_emp,$id,'cnt');
	}
######################################################################################
### Function Name : insertdivision                                                 ###
### Description   : This function insert the company division data in database     ###
### Input         : form data                                                      ###
### Ouput         : redirect to the divisions function                             ###
######################################################################################
	function _insertdivision(){
		$arr['div_name']=$this->_input['division']['div_name'];
		$arr['id_company']=$_SESSION['id_company'];
		if($this->_input['division']['notes']){
			$arr['notes']=$this->_input['division']['notes'];	
		}
		$r=$this->obj_company->insert("companyDivision",$arr);
		if($r){
			print "<script>callmsg('".getmessage('COM_INS_SUCC')."');</script>";
			$this->_divisions(1);
		}
	}	
######################################################################################
### Function Name : updatedivision                                                 ###
### Description   : This function update the company division data in database     ###
### Input         : form data                                                      ###
### Ouput         : redirect to the divisions function                             ###
######################################################################################
	function _updatedivision(){
		$condition=" id_division = ".$this->_input['id_division'] ;
		$r=$this->obj_company->update_company("companyDivision",$this->_input['division'],$condition);
		print "<script>callmsg('".getmessage('COM_UPD_SUCC')."');</script>";
		$this->_divisions(2);
	}
######################################################################################
### Function Name : remove_division                                                ###
### Description   : This function delete one company division record in database   ###
### Input         : form data                                                      ###
### Ouput         : redirect to the divisions function                             ###
######################################################################################
	function _remove_division(){
		$cond=" id_division = '".$this->_input['id_division']."'";
		$r=$this->obj_company->delete_dept("companyDivision",$cond);
		if($r){
			if(($this->_input['cnt']==1) && ($this->_input['qstart'])){
                               $this->_input['qstart']=$this->_input['qstart']-$GLOBALS['conf']['PAGINATE']['rec_per_page'];
                        }
                        print "<script>callmsg('".getmessage('COM_DEL_SUCC')."');</script>";
			$this->_divisions(2);
		}
	}
######################################################################################
### Function Name : addEditDepartment                                              ###
### Description   : This function open addEditDepartment modal form                ###
### Input         : no input                                                       ###
### Ouput         : company addEditDepartment template                             ###
######################################################################################
	function _addEditDepartment(){
		$ch=$this->_input['ch'];
		$id=$this->_input['id'];
		$this->_output['division']=$this->_getResult('companyDivision','id_division','div_name');
		if($ch=='edit'){
			$cond="id_department=".$id;
			$sql='CALL get_search_sql("'.TABLE_PREFIX.'companyDepartment","'.$cond.'")';
			$this->_output['res_department']=getsingleindexrow($sql);
		}
		$this->_output['tpl']='company/addEditDepartment';
	}
######################################################################################
### Function Name : departments                                                    ###
### Description   : This function show the company departments information         ###
### Input         : one status variable is taken for redirecting to                ###
###					departmentslisting or departments          ###
### Ouput         : company departments  or  departmentslisting template           ###
######################################################################################
	function _departments($x=0){
		$sql="SELECT dt.id_department,dv.id_division,dv.div_name, dt.dept_name,dt.notes
FROM ".TABLE_PREFIX."companyDepartment dt, ".TABLE_PREFIX."companyDivision dv
WHERE dt.id_division = dv.id_division";
		$uri = 'company/departments';
		$this->_output['type']	= "box";  // no, extra, nextprev, advance, normal, box
		$this->_output['pg_header'] = "Department List";
		$this->_output['field'] = array("div_name"=>array("Division Name",1),"dept_name"=>array("Department Name", 1));
		$this->_output['limit'] = $GLOBALS['conf']['PAGINATE']['rec_per_page'];
		$this->_output['show'] = $GLOBALS['conf']['PAGINATE']['show_page'];
		$this->_output['sql'] = $sql;
		$this->_output['uri'] = $uri;
		$this->_output['ajax']= "ajax";
		$this->_output['sort_order']= "DESC";
		$this->_output['sort_by']= "dt.id_department";
		$this->_input['qstart']=$this->_input['qstart'];
		$this->_output['res1']=$this->commonEmpCount('id_department','companyDepartment','department');
		if(isset($this->_input['qstart']) || $x){
			$this->_input['choice']='departments';
			$this->company_bl->page_listing($this,"company/departmentlisting"); 
		}else{
			$this->company_bl->page_listing($this,"company/department"); 
		}
	}	
######################################################################################
### Function Name : insertdepartment                                               ###
### Description   : This function insert the company department data in database   ###
### Input         : form data                                                      ###
### Ouput         : redirect to the departments function                           ###
######################################################################################
	function _insertdepartment(){
		$arr['dept_name']=$this->_input['department']['dept_name'];
		$arr['id_division']=$this->_input['department']['id_division'];
		if($this->_input['department']['notes']){
			$arr['notes']=$this->_input['department']['notes'];	
		}
		$r=$this->obj_company->insert("companyDepartment",$arr);
		if($r){
			print "<script>callmsg('".getmessage('COM_INS_SUCC')."');</script>";
			$this->_departments(1);
		}
	}
######################################################################################
### Function Name : updatedepartment                                               ###
### Description   : This function update the company department data in database   ###
### Input         : form data                                                      ###
### Ouput         : redirect to the departments function                           ###
######################################################################################
	function _updatedepartment(){
		$condition="id_department = ".$this->_input['id_department'] ;
		$r=$this->obj_company->update_company("companyDepartment",$this->_input['department'],$condition);
		print "<script>callmsg('".getmessage('COM_UPD_SUCC')."');</script>";
		$this->_departments(2);
	}
######################################################################################
### Function Name : remove_department                                              ###
### Description   : This function delete one company department record in database ###
### Input         : form data                                                      ###
### Ouput         : redirect to the departments function                           ###
######################################################################################
	function _remove_department(){
		$cond=" id_department = '".$this->_input['id_department']."'";
		$r=$this->obj_company->delete_dept("companyDepartment",$cond);
		if($r){
				if(($this->_input['cnt']==1) && ($this->_input['qstart'])){
		                       $this->_input['qstart']=$this->_input['qstart']-$GLOBALS['conf']['PAGINATE']['rec_per_page'];
		                }
		                print "<script>callmsg('".getmessage('COM_DEL_SUCC')."');</script>";
				$this->_departments(2);
		}
	}
######################################################################################
### Function Name : addEditTeam                                                    ###
### Description   : This function open adddivision modal form                      ###
### Input         : no input                                                       ###
### Ouput         : company addEditTeam template                                   ###
######################################################################################
	function _addEditTeam(){
		$ch=$this->_input['ch'];
		$id=$this->_input['id'];
		$this->_output['div']=$this->_getResult('companyDivision','id_division','div_name');
		if($ch=='edit'){
			$cond="t.id_team=".$id;
			$sql="SELECT dt.id_department,dv.id_division,t.id_team,dv.div_name,dt.dept_name,t.team_name,t.notes
FROM ".TABLE_PREFIX."companyTeam t, ".TABLE_PREFIX."companyDepartment dt,".TABLE_PREFIX."companyDivision dv WHERE t.id_department=dt.id_department AND dt.id_division = dv.id_division AND ".$cond;
			$res_team=getsingleindexrow($sql);
			$this->_output['res_team']=$res_team;
			$this->_output['dept']=$this->_getResult('companyDepartment','id_department','dept_name',"id_department=".$res_team['id_department']);
		}
		$this->_output['tpl']='company/addEditTeam';
	}
######################################################################################
### Function Name : team                                                   	   ###
### Description   : This function show the company teams information               ###
### Input         : $x is taken for the redirection purpose.initially take default ###
###			value then it take value provided.                         ###
### Ouput         : company departments  or  departmentslisting template           ###
######################################################################################
	function _team($x=0){
		$sql="SELECT dt.id_department,dv.id_division,t.id_team,dv.div_name,dt.dept_name,t.team_name,t.notes
FROM ".TABLE_PREFIX."companyTeam t, ".TABLE_PREFIX."companyDepartment dt,".TABLE_PREFIX."companyDivision dv WHERE t.id_department=dt.id_department AND dt.id_division = dv.id_division";
		
		$uri = 'company/team';
		$this->_output['type']	= "box";  // no, extra, nextprev, advance, normal, box
		$this->_output['pg_header'] = "Team List";
		$this->_output['field'] = array("div_name"=>array("Division Name",1),"dept_name"=>array("Department Name", 1),"team_name"=>array("Team Name",1));
		$this->_output['limit'] = $GLOBALS['conf']['PAGINATE']['rec_per_page'];
		$this->_output['show'] = $GLOBALS['conf']['PAGINATE']['show_page'];
		$this->_output['sql'] = $sql;
		$this->_output['uri'] = $uri;
		$this->_output['ajax']= "ajax";
		$this->_output['sort_order']= "DESC";
		$this->_output['sort_by']= "id_team";
		
		$this->_output['res1']=$this->commonEmpCount('id_team','companyTeam','team');
		if(isset($this->_input['qstart']) || $x){
			$this->_input['choice']='team';
			$this->company_bl->page_listing($this,"company/teamlisting"); 
		}else{
			$this->company_bl->page_listing($this,"company/team"); 
		}
	}
######################################################################################
### Function Name : insertteam                                                     ###
### Description   : This function insert the company team data in database         ###
### Input         : form data                                                      ###
### Ouput         : redirect to the team function                                  ###
######################################################################################
	function _insertteam(){
		$arr['team_name']=$this->_input['team']['team_name'];
		$arr['id_department']=$this->_input['team']['id_department'];
		if($this->_input['team']['notes']){
			$arr['notes']=$this->_input['team']['notes'];	
		}
		$r=$this->obj_company->insert("companyTeam",$arr);
		if($r){
			print "<script>callmsg('".getmessage('COM_INS_SUCC')."');</script>";
			$this->_team(1);
		}
	}
######################################################################################
### Function Name : updateteam                                                     ###
### Description   : This function update the company team data in database         ###
### Input         : form data                                                      ###
### Ouput         : redirect to the team function                                  ###
######################################################################################
	function _updateteam(){
		$condition="id_team = ".$this->_input['id_team'] ;
		$arr['id_department']=$this->_input['team']['id_department'];
		$arr['team_name']=$this->_input['team']['team_name'];
		if($this->_input['team']['notes']){
			$arr['notes']=$this->_input['team']['notes'];	
		}
		$r=$this->obj_company->update_company("companyTeam",$arr,$condition);
		print "<script>callmsg('".getmessage('COM_UPD_SUCC')."');</script>";
		$this->_team(2);
	}
######################################################################################
### Function Name : removeteam                                                     ###
### Description   : This function delete one company team record in database       ###
### Input         : form data                                                      ###
### Ouput         : redirect to the team function                                  ###
######################################################################################
	function _removeteam(){
		$cond=" id_team = '".$this->_input['id_team']."'";
		$r=$this->obj_company->delete_dept("companyTeam",$cond);
		if($r){
			if(($this->_input['cnt']==1) && ($this->_input['qstart'])){
	               			$this->_input['qstart']=$this->_input['qstart']-$GLOBALS['conf']['PAGINATE']['rec_per_page'];
			}
		       print "<script>callmsg('".getmessage('COM_DEL_SUCC')."');</script>";
			$this->_team(3);
		}
	}
######################################################################################
### Function Name : getResult                                                      ###
### Description   : This function return the result of a query in an index array   ### 
###                     format                                                     ###
### Input         : table name,table id,particular field,condition on that         ###
### Ouput         : index array		                                           ###
######################################################################################
	function _getResult($tableName,$tableId,$fieldName,$cond=''){
		if($cond){
			$sql=get_search_sql($tableName,$cond);
		}else{
			$sql=get_search_sql($tableName);
		}
		$res=getindexrows($sql,$tableId,$fieldName,$err);
		return $res;
	}
######################################################################################
### Function Name : jobtitles		                                           ###
### Description   : This function show the company jobtitles information           ###
### Input         : one status variable is taken for redirecting to                ###
###					jobtitleslisting or jobtitles              ###
### Ouput         : company jobtitles  or  jobtitleslisting template               ###
######################################################################################
	function _jobtitles($x=0){
		$uri = 'index.php/page-company-choice-jobtitles';
		$this->_output['div']=$this->_getResult('companyDivision','id_division','div_name');
		$this->_output['dept1']=$this->_getResult('companyDepartment','id_department','dept_name');
		$this->_output['team1']=$this->_getResult('companyTeam','id_team','team_name');
		$res4=$this->commonEmpCount('id_job_title','companyJobTitle','job_title');
		$this->_output['res4']=$res4;
		$sql="SELECT b.id_department, a.id_division, c.id_job_title, b.dept_name, a.div_name,d.team_name,c.job_title_name,d.id_team,c.notes
FROM ".TABLE_PREFIX."companyDivision AS a, ".TABLE_PREFIX."companyDepartment AS b,".TABLE_PREFIX."companyTeam AS d, ".TABLE_PREFIX."companyJobTitle AS c
WHERE a.id_division = b.id_division AND b.id_department = d.id_department AND d.id_team=c.id_team AND ";
		
		$id_division=$this->_input['id_division'];
		$id_department=$this->_input['id_department'];
		$id_team=$this->_input['id_team'];
		$job_title_name=$this->_input['job_title_name'];
		if($id_division!=''){
			$sql.="a.id_division = ".$id_division." AND ";
			$uri.="-id_division-".$id_division;
		}
		if($id_department!=''){
			$sql.="b.id_department =".$id_department." AND ";
			$uri.="-id_department-".$id_department;
		}
		if($id_team!=''){
			$sql.="d.id_team =".$id_team." AND ";
			$uri.="-".$key."-".$value;
		}
		if($job_title_name!=''){
			$sql.="c.job_title_name like '%".$job_title_name."%' AND ";
			$uri.="-job_title_name-".$job_title_name;
		}
		$sql=trim($sql,' AND');
		//print $sql;
		$this->_output['type']	= "box";  // no, extra, nextprev, advance, normal, box
		$this->_output['pg_header'] = "Team List";
		$this->_output['field'] = array("div_name"=>array("Division Name", 1),"dept_name"=>array("Department Name",1),"team_name"=>array("Team Name",1),"job_title_name"=>array("Job Title Name", 1));
		$this->_output['limit'] = $GLOBALS['conf']['PAGINATE']['rec_per_page'];
		$this->_output['show'] = $GLOBALS['conf']['PAGINATE']['show_page'];
		$this->_output['sql'] = $sql;
		$this->_output['uri'] = $uri;
		$this->_output['ajax']= "ajax";
		$this->_output['sort_order']= "DESC";
		$this->_output['sort_by']= "id_job_title";	
		if($this->_input['chk']){
			$this->_input['choice']='jobtitles';
			$this->company_bl->page_listing($this,"company/jobtitleslisting"); 
		}else{
			$this->company_bl->page_listing($this,"company/jobtitlesearch"); 
		}
	}

######################################################################################
### Function Name : addjobtitle                                                    ###
### Description   : This function open jobtitle modal form                         ###
### Input         : no input                                                       ###
### Ouput         : company addEditJobTitle template                               ###
######################################################################################
	function _addjobtitle(){
		$this->_output['div']=$this->_getResult('companyDivision','id_division','div_name');
		$this->_output['dept1']=$this->_getResult('companyDepartment','id_department','dept_name');
		$this->_output['team1']=$this->_getResult('companyTeam','id_team','team_name');
		$this->_output['status']="add";	
		$this->_output['tpl']='company/addEditJobTitle';
	}	
######################################################################################
### Function Name : editjobtitle                                                   ###
### Description   : This function open editable jobtitle modal form                ###
### Input         : form data                                                      ###
### Ouput         : company addEditJobTitle template                               ###
######################################################################################
	function _editjobtitle(){
		$this->_output['res']=$this->_input;
		$this->_output['div']=$this->_getResult('companyDivision','id_division','div_name');
		$this->_output['dept1']=$this->_getResult('companyDepartment','id_department','dept_name',"id_division=".$this->_input['id_division']);
		$this->_output['team1']=$this->_getResult('companyTeam','id_team','team_name',"id_department=".$this->_input['id_department']);
		$this->_output['status']="add";	
		$this->_output['editstatus']="1";
		$this->_output['flag']="1";	
		$this->_output['tpl']='company/addEditJobTitle';
	}	
######################################################################################
### Function Name : insertjobtitles                                                ###
### Description   : This function insert the company jobtitles data in database    ###
### Input         : form data                                                      ###
### Ouput         : redirect to jobtitles function                                 ###
######################################################################################
	function _insertjobtitles(){
		$arr['id_team']=$this->_input['jobtitles1']['id_team'];
		$arr['job_title_name']=$this->_input['jobtitles1']['job_title_name'];
		if($this->_input['jobtitles1']['notes']){
			$arr['notes']=$this->_input['jobtitles1']['notes'];	
		}
		$r=$this->obj_company->insert("companyJobTitle",$arr);
		if($r){
			print "<script>callmsg('".getmessage('COM_INS_SUCC')."');</script>";
			$this->_input['choice']="jobtitles";
			$this->_jobtitles(1);
		}
	}	
######################################################################################
### Function Name : updatejobtitles                                                ###
### Description   : This function update the company jobtitles data in database    ###
### Input         : form data                                                      ###
### Ouput         : redirect to jobtitles function                                 ###
######################################################################################
	function _updatejobtitles(){
		$arr['id_team']=$this->_input['jobtitles1']['id_team'];
		$arr['job_title_name']=$this->_input['jobtitles1']['job_title_name'];
		if($this->_input['jobtitles1']['notes']){
			$arr['notes']=$this->_input['jobtitles1']['notes'];	
		}
		$condition=" id_job_title = ".$this->_input['id_job_title'];
		$r=$this->obj_company->update_company("companyJobTitle",$arr,$condition);
		print "<script>callmsg('".getmessage('COM_UPD_SUCC')."');</script>";
		$this->_input['choice']="jobtitles";
		$this->_jobtitles(2);
	}
######################################################################################
### Function Name : remove_jobtitle                                                ###
### Description   : This function delete one company jobtitle record in database   ###
### Input         : form data                                                      ###
### Ouput         : redirect to jobtitles function                                 ###
######################################################################################
	function _remove_jobtitle(){
		$cond=" id_job_title = '".$this->_input['id_job_title']."'";
		$r=$this->obj_company->delete_dept("companyJobTitle",$cond);
		if($r){
			if(($this->_input['cnt']==1) && ($this->_input['qstart'])){
	               			$this->_input['qstart']=$this->_input['qstart']-$GLOBALS['conf']['PAGINATE']['rec_per_page'];
			}
	        	print "<script>callmsg('".getmessage('COM_DEL_SUCC')."');</script>";
			$this->_jobtitles(3);
		}
	}
######################################################################################
### Function Name : addHrForm                                                      ###
### Description   : This function open addhrForm modal form                        ###
### Input         : no input                                                       ###
### Ouput         : company addhrForm template                                     ###
######################################################################################
	function _addHrForm(){
		$this->_output['tpl']='company/addhrForm';
	}
######################################################################################
### Function Name : hrForms                                                        ###
### Description   : This function show the company Hr Form information             ###
### Input         : one status variable is taken for redirecting to                ###
###					HrFormListing or hrForm                    ###
### Ouput         : company hrForm  or  hrFormListing template                     ###
######################################################################################
	function _hrForms($x=0){
		$sql="SELECT *,IF(sec<60,CONCAT(sec,' second'),IF(min<60,CONCAT(min,' minute'),IF(hours<24,CONCAT(hours,' hour'),CONCAT(day,' day')))) updt FROM (SELECT id_hr_form, form_name,file_name,add_date,TIMESTAMPDIFF(DAY,add_date,NOW()) day,TIMESTAMPDIFF(HOUR,add_date,NOW()) hours,TIMESTAMPDIFF(MINUTE,add_date,NOW()) min,TIMESTAMPDIFF(SECOND,add_date,NOW()) sec FROM ".TABLE_PREFIX."companyHrForm WHERE 1) T";

		$uri = 'company/hrForms';
		$this->_output['type']	= "box";  // no, extra, nextprev, advance, normal, box
		$this->_output['pg_header'] = "Hrform List";
		$this->_output['field'] = array("form_name"=>array("Form Name", 1),"file_name"=>array("File Name", 1),"add_date"=>array("Date of upload", 1));
		$this->_output['limit'] = $GLOBALS['conf']['PAGINATE']['rec_per_page'];
		$this->_output['show'] = $GLOBALS['conf']['PAGINATE']['show_page'];
		$this->_output['sql'] = $sql;
		$this->_output['uri'] = $uri;
		$this->_output['ajax']= "ajax";
		$this->_output['sort_order']= "DESC";
		$this->_output['sort_by']= "id_hr_form";
		$this->_input['choice']='hrForms';
		if($_SESSION['hrform_qs']!=''){
			$this->_input['qstart']=$_SESSION['hrform_qs'];
			$_SESSION['hrform_qs']='';
		}
		//$this->_input['qstart']=$this->_input['start'];
		if($this->_input['chk']){
			$this->company_bl->page_listing($this,"company/hrFormListing"); 
		}else{
			$this->company_bl->page_listing($this,"company/hrForm"); 
		}
	}
######################################################################################
### Function Name : insertHrform                                                   ###
### Description   : This function insert the company hrForm data in database       ###
### Input         : form data                                                      ###
### Ouput         : redirect to hrForm function                                    ###
######################################################################################
	function _insertHrform(){
		$file=$_FILES['fname']['tmp_name'];
		$dest_file=convert_me($_FILES['fname']['name']);
		$arr['form_name']=$this->_input['hrform']['form_name'];
		$arr['file_name']=$dest_file;
		$arr['id_company']=$_SESSION['id_company'];
		$arr['add_date']='NOW()';
		$arr['ip']=$_SERVER['REMOTE_ADDR'];
		$r=$this->obj_company->insert("companyHrForm",$arr);
		if($r){
			copy($file,APP_ROOT.'files/hr_form/'.$r.'_'.$dest_file);
			$_SESSION['raise_message']['global']=getmessage('COM_INS_SUCC');
			redirect(LBL_SITE_URL."company/hrForms");
		}
	}
######################################################################################
### Function Name : editHrForm                                                     ###
### Description   : This function show the editable addhrForm ttemplate            ###
### Input         : form data                                                      ###
### Ouput         : company addhrForm template                                     ###
######################################################################################
	function _editHrForm(){
		$sql="SELECT id_hr_form,form_name,file_name,add_date FROM ".TABLE_PREFIX."companyHrForm WHERE id_hr_form=".$this->_input['id_hr_form'];
		$res=getrows($sql,$err);
		$this->_output['res_hrform'] = $res[0];
		$this->_output['tpl']='company/addhrForm';
	}
######################################################################################
### Function Name : updateHrform                                                   ###
### Description   : This function update the company Hrform data in database       ###
### Input         : form data                                                      ###
### Ouput         : redirect to hrForm() function                                  ###
######################################################################################
	function _updateHrform(){
		$uploadDir = APP_ROOT."files/hr_form/";
		$arr['form_name']=$this->_input['hrform']['form_name'];
		$file=$_FILES['fname']['tmp_name'];
		$dest_file=$_FILES['fname']['name'];
		if($dest_file!=''){
			$arr['file_name']=convert_me($dest_file);
			@unlink($uploadDir.$this->_input['id_hr_form']."_".trim($this->_input['fl_nm']));
			copy($file,APP_ROOT.'files/hr_form/'.$this->_input['id_hr_form'].'_'.$arr['file_name']);
		}
		$condition=" id_hr_form = ".$this->_input['id_hr_form'];
		$r=$this->obj_company->update_company("companyHrForm",$arr,$condition);
		if($r){
			$_SESSION['raise_message']['global']=getmessage('COM_UPD_SUCC');
		}
		$_SESSION['hrform_qs']=$this->_input['qstart'];
		redirect(LBL_SITE_URL."company/hrForms");
	}
######################################################################################
### Function Name : remove_HrForm                                                  ###
### Description   : This function delete one HrForm from database table and server ###
### Input         : form data                                                      ###
### Ouput         : redirect to hrForm() function.                                 ###
######################################################################################
	function _remove_HrForm(){
		$uploadDir = APP_ROOT."files/hr_form/";               
		$fname= $this->_input['id_hr_form']."_".trim($this->_input['file_name']);
		$cond=" id_hr_form = '".$this->_input['id_hr_form']."'";
		$r=$this->obj_company->delete_dept("companyHrForm",$cond);
		if($r){
			if(($this->_input['cnt']==1) && ($this->_input['qstart'])){
	               			$this->_input['qstart']=$this->_input['qstart']-$GLOBALS['conf']['PAGINATE']['rec_per_page'];
			}
        	 print "<script>callmsg('".getmessage('COM_DEL_SUCC')."');</script>";
	      	 @unlink($uploadDir.$fname);
	      	 $this->_hrForms(2);
		}
	}	
######################################################################################
### Function Name : downLoadHrForm                                                 ###
### Description   : This function download the file from the server                ###
### Input         : form data                                                      ###
### Ouput         : downloaded file                                                ###
######################################################################################
	function _downLoadHrForm(){
		if($_SESSION['id_company']){
			$sql="SELECT id_hr_form,file_name FROM ".TABLE_PREFIX."companyHrForm WHERE id_hr_form=".$this->_input['id_hr_form']." LIMIT 1";
			$res=getsingleindexrow($sql,$err);
		}
		$dfile=APP_ROOT.'files/hr_form/'.$res['id_hr_form'].'_';
		$this->downloadFile($dfile,$res['file_name']);
	}
######################################################################################
### Function Name : getdeptName                                                    ###
### Description   : This function put the department name according to division    ###
### Input         : form data                                                      ###
### Ouput         : deptname template                                              ###
######################################################################################
	function _getdeptName(){
		if($this->_input['id_division']){
			$this->_output['dept']=$this->_getResult('companyDepartment','id_department','dept_name',"id_division=".$this->_input['id_division']);
		}else{
			$this->_output['dept1']=$this->_getResult('companyDepartment','id_department','dept_name');
		}
		$this->_output['tpl']='company/deptname';
	}
######################################################################################
### Function Name : getteamName                                                    ###
### Description   : This function put the team name according to department        ###
### Input         : form data                                                      ###
### Ouput         : deptname template                                              ###
######################################################################################
	function _getteamName(){
		if($this->_input['id_department']){
			$this->_output['dept']=$this->_getResult('companyTeam','id_team','team_name',"id_department = ".$this->_input['id_department']);
		}else{
			$this->_output['dept1']=$this->_getResult('companyTeam','id_team','team_name');
		}
		$this->_output['tpl']='company/deptname';
	}
######################################################################################
### Function Name : findjobtitlename                                               ###
### Description   : This function find jobtitle name                               ###
### Input         : form data                                                      ###
### Ouput         : ajax_autocomp template                                         ###
######################################################################################
	function _findjobtitlename(){
		$sql="SELECT job_title_name from ".TABLE_PREFIX."companyJobTitle where job_title_name like '%".$this->_input['q']."%' order by job_title_name";
		$data=getrows($sql,$err);
		foreach($data as $key=>$value){
		$val[]=$value['job_title_name'];
		}
		$this->_output['title']=$val;
		$this->_output['tpl']='company/ajax_autocomp';
	
	}		
######################################################################################
### Function Name : downLoadfile                                                   ###
### Description   : This function is a download common function                    ###
### Input         : form data                                                      ###
### Ouput         : Downloaded file                                                ###
######################################################################################
	function downloadFile($dir="",$file_name=""){
		ob_clean();
		if(!file_exists($dir.$file_name)){			
        		print $dir.$file_name." not found";exit;
    		}
		$file_extension = strtolower(substr(strrchr($file_name,'.'),1));
		
		switch($file_extension){
			case "pdf": $ctype="application/pdf"; break;
			case "exe": $ctype="application/octet-stream"; break;
			case "zip": $ctype="application/zip"; break;
			case "doc": $ctype="application/msword"; break;
			case "xls": $ctype="application/vnd.ms-excel"; break;
			case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
			case "gif": $ctype="image/gif"; break;
			case "png": $ctype="image/png"; break;
			case "jpg": 
        		case "jpeg": $ctype="image/jpeg"; break;
        		case "bmp": $ctype="image/bmp"; break;
        		case "tif": $ctype="image/tif"; break;
			case "tiff": $ctype="image/tiff"; break;
        		case "txt": $ctype="text/plain";break;
        		case "css": $ctype="text/css"; break;
			case "csv": $ctype="application/csv";break;
			case "xml": $ctype="text/xml"; break;
			case "avi": $ctype="video/x-msvideo"; break;
			default: $ctype="application/force-download";
		}
		$fsize=filesize($dir.$file_name);
		
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: public");
		header("Content-Description: File Transfer");
		header("Content-Type: $ctype");
		header("Content-Disposition: attachment; filename=\"$file_name\"");
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: " . $fsize);

		$fp = fopen($dir.$file_name, "r");
		fpassthru($fp);
	}
}//end of class
Return current item: SimpleHRM