<?php
/**********************************************************
* Source Copyright 2014 Author                            *
* Unauthorized reproduction is not allowed                *  
* Author: JPK Software Solutions Pvt. Ltd.                *
* Email: sales@visionhelpdesk.com                         *
* Owner: www.visionhelpdesk.com                           *
**********************************************************/
if(!defined('_VIS_')) die('Error: Call from undefined function');
class staff {
    var $error;

    function home($operation) {
        if(VIS_LOCATION_AREA==0) {
            $data['version']=VIS_CURR_VERSION;
            $data['branding']=(!defined('VIS_BRAND_FREE') || VIS_BRAND_FREE!='VALID')?'FALSE':'TRUE';
            $data['language']=VIS_LANGUAGE_NAME;
            $data['date_format']=VIS_DATE_FORMAT;
            $data['datetime_format']=VIS_DATETIME_FORMAT;
            echo get_xml($data, 'license');
            return true;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
        //$staff=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $modules=$object->get_modules('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $toolbar=$object->get_staff_toolbar('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'voip.php');
		$voip_object=new class_voip($database);
		$asign_twilio_staffs = $voip_object->check_asign_twilio_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA);
                $twilio_filter='integration_type=27 AND is_enabled=1';
	        list($count, $twilio_details)=$set_object->get_integration_setting($twilio_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);		
                $twilio_details=$twilio_details[0];
				
		#Exotel
			$exotel_filter='integration_type=38 AND is_enabled=1';
	        list($exo_count, $exotel_details)=$set_object->get_integration_setting($exotel_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
				
										/*$intercom_filter='integration_type=47 AND is_enabled=1';
	        list($inter_count, $intercom_detail)=$set_object->get_integration_setting($intercom_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
									$intercom_details=$intercom_detail[0];
									if($intercom_detail!=-1){
									 $staff=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA); //need intercom 
									}*/
			
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'page.php');
        return true;
    }

    function vis_login_check($operation) {
        return $this->home($operation);
    }

    function forgot_password($operation) {
        $data=parse_form_array($operation['vis_action']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $fpass=$object->forgot_password($data['vis_useremail'], VIS_LOCATION_AREA);
        $database->database_disconnect();
        $this->error=($fpass)?4:3;
        return $this->login_form();
    }

    function quick_view($operation) {
        $dashboardSettings=array();
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $settingobject=new class_setting($database);
        list($info, $modules)=$settingobject->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
		$page=0;
        $access=$object->get_module_access('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staffDetails=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $pin_data=$object->get_pinup(VIS_STAFF_ID, VIS_LOCATION_AREA);
        include_once(VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'ticket.php');
        $tkt_object = new class_ticket($database);
		$staff       = $tkt_object->get_staff_list(VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		$agent_count = ($staff!=-1)?count($staff):0;
		
	    list($roundrobin_info, $roundrobin_details)=$settingobject->get_roundrobin('is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
       
        $database->database_disconnect();
        if(VIS_LOCATION_AREA==0) echo get_xml($pin_data, 'quick_view');
        else include(VIS_PATH_TEMPLATE.'home.php');
        return true;
    }
    
    function load_home_counts($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);
        $counts=$ticket_object->get_quick_counts(VIS_TABLE_PREFIX."ticket.status_id!=3", VIS_STAFF_ID, VIS_LOCATION_AREA);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        $objectClient=new class_client($database);
        $clientCounts=$objectClient->get_quick_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $quick_view=$object->get_task_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$staff       = $ticket_object->get_staff_list(VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		$agent_count = ($staff!=-1)?count($staff):0;		
								$filter='status_id!=3 and due_time!=0 and is_deleted=0 and draft_id=0';
								list($ticket_info, $ticket_details1)=$ticket_object->get_home_overdue_ticket_count($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA,'','',0,1);
		$overdue_count_within15=($ticket_info['within_fifty']!='')?$ticket_info['within_fifty']:0;
		$overdue_count_within30=($ticket_info['within_thirty']!='')?$ticket_info['within_thirty']:0;
		$overdue_count_within60=($ticket_info['within_sixty']!='')?$ticket_info['within_sixty']:0;
		$overdue_count_within_1day=($ticket_info['within_oneday']!='')?$ticket_info['within_oneday']:0;
		
		$filters=$ticket_object->get_filters_details('vscope=1 and owner=0 and (filter_name="30 Minutes overdue" or filter_name="60 Minutes overdue" or filter_name="1 Day overdue")', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		if($filters!=-1){
		for($i=0;$i<count($filters);$i++) {
			if(trim($filters[$i]['filter_name'])=='30 Minutes overdue')
{
$overdue_filter_30=$filters[$i]['filter_id'];
}
if(trim($filters[$i]['filter_name'])=='60 Minutes overdue')
{
$overdue_filter_60=$filters[$i]['filter_id'];
}
if(trim($filters[$i]['filter_name'])=='1 Day overdue')
{
$overdue_filter_1day=$filters[$i]['filter_id'];
}
		}
		}
								
 
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $settingobject=new class_setting($database);
        $All_Activities = $object->get_recent_activities(VIS_STAFF_ID,0,'',1);
        $total_pages = ceil($All_Activities['count']/10);
        $load_more_activities = ($total_pages > $page+1) ? $page : '';
        $recentActivities = $object->get_recent_activities(VIS_STAFF_ID,0,0);
        if($recentActivities!=-1){
			for($i=0;$i<count($recentActivities);$i++){
				if($recentActivities[$i]['operation_id']==7){
					if($recentActivities[$i]['old_info']=='' || $recentActivities[$i]['old_info']==0) $staffid=$recentActivities[$i]['new_info'];
					else  $staffid=$recentActivities[$i]['old_info'];
					if($staffid!=0){
						$staff_info=$settingobject->get_staff(VIS_TABLE_PREFIX.'staff.staff_id='.$staffid, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
						$recentActivities[$i]['user_info'] =  $staff_info[1][0]['first_name'].' '.$staff_info[1][0]['last_name'];
					}
				}
				else if($recentActivities[$i]['operation_id']==13){
						$sla_old_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['old_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
						$sla_new_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['new_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
						$recentActivities[$i]['old_info'] =  $sla_old_info[1][0]['sla_name'];
						$recentActivities[$i]['new_info'] =  $sla_new_info[1][0]['sla_name'];
				}
			}
		}
		
		/* date: start 6-10-15*/
		
		if(VIS_STAFF_ID==1)
		{
			$firsttime=$settingobject->get_settings('title="vis_first_time_login"',VIS_STAFF_ID, VIS_LOCATION_AREA);
			if(is_array($firsttime))
			{
				if(isset($operation['vis_firstlogin'])) {
					if($operation['vis_firstlogin']==1)
					{
						$firstimeload=$firsttime[0]['content'];
					}else{
						$firstimeload=0;
					}
				}else{
						$firstimeload=0;
					}
			}else{
				$firstimeload=0;
			}
		}else{
			$firstimeload=0;
		}
		/* date: end 6-10-15*/
		
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'home_activities.php');
        return true;
    }
	
	 /* date: start 6-10-15*/
	function first_time_login($operation)
	{
		$database=new class_database();
		$settingobject = new class_setting($database);
		$firsttime=$settingobject->get_settings('title="vis_first_time_login"',VIS_STAFF_ID, VIS_LOCATION_AREA);
			if(is_array($firsttime))
			{
				$checkfirstimeload=$firsttime[0]['content'];
			}else{
				$checkfirstimeload=0;
			}
		include(VIS_PATH_TEMPLATE.'first_time_login.php');
	}
	function update_firsttime_status($operation)
	{
		$database=new class_database();
		$settingobject=new class_setting($database);
		$settingobject->clear_first_time_login($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
		echo json_encode( array('vis_result' => 1) ); exit;
	}
	function update_fsttime_status_remindletter($operation)
	{
		$database=new class_database();
		$settingobject=new class_setting($database);
		$settingobject->clear_fsttime_status_remindletter($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
		echo json_encode( array('vis_result' => 1) ); exit;
	}
	/* date: end 6-10-15*/
    
	function load_more_recent_activities($operation) {
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $settingobject=new class_setting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $page = (isset($operation['vis_page']) && is_numeric($operation['vis_page'])) ? $operation['vis_page'] : 0;
        $All_Activities = $object->get_recent_activities(VIS_STAFF_ID,0,'',1);
         $total_pages = ceil($All_Activities['count']/10);
        $load_more_activities = ($total_pages > $page+1) ? $page : '';
		$recentActivities = $object->get_recent_activities(VIS_STAFF_ID,0,$page);  
	    if($recentActivities!=-1){
        for($i=0;$i<count($recentActivities);$i++){
            if($recentActivities[$i]['operation_id']==7){
                if($recentActivities[$i]['old_info']=='' || $recentActivities[$i]['old_info']==0) $staffid=$recentActivities[$i]['new_info'];
                else  $staffid=$recentActivities[$i]['old_info'];
                if($staffid!=0){
                    $staff_info=$settingobject->get_staff(VIS_TABLE_PREFIX.'staff.staff_id='.$staffid, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
                    $recentActivities[$i]['user_info'] =  $staff_info[1][0]['first_name'].' '.$staff_info[1][0]['last_name'];
                }
            }
            else if($recentActivities[$i]['operation_id']==13){
                    $sla_old_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['old_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                    $sla_new_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['new_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                    $recentActivities[$i]['old_info'] =  $sla_old_info[1][0]['sla_name'];
                    $recentActivities[$i]['new_info'] =  $sla_new_info[1][0]['sla_name'];
            }
        }
	    }
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'load_more_recent_activities.php');
        return true;
	}
    function remove_pin($operation) {
        global $vis_language;
        if(isset($operation['vis_pin_id']) && is_numeric($operation['vis_pin_id'])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
            $object=new class_staff($database);
            $ret=$object->remove_pin($operation['vis_pin_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $pin_data=$object->get_pinup(VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            if(!$ret) {
                if(VIS_LOCATION_AREA==0) echo 'error';
                else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
            else {
                /*if(VIS_LOCATION_AREA==0) echo 'success';
                else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");</script>';*/
            }
            echo '<script> $("#pinned_items").html('.count($pin_data).'); </script>';
            include(VIS_PATH_TEMPLATE.'pinned_items.php');
            return true;
        } else {
            if(VIS_LOCATION_AREA==0) echo 'error';
        }
        return false;
    }

    function load_header($operation) {
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		
        $staffobject=new class_staff($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'voip.php');
        $voip_object=new class_voip($database);
		
        $staff=$staffobject->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
		
		include(VIS_PATH_PLUGINS.'twilio/Services/Twilio/Capability.php');

		$accountSid = '';$authToken  = '';$appsid  = '';
		$filter='integration_type=27 AND domain_id=0 AND is_enabled=1';
		list($twilio_info, $twilio_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($twilio_details!=-1){
			$twilio_details = $twilio_details[0];
			$accountSid = $twilio_details['host_name'];
			$authToken  = $twilio_details['user_name'];
			$appsid  = $twilio_details['db_password'];
		}else{
			$filter='integration_type=27 AND domain_id='.VIS_DOMAIN.' AND is_enabled=1';
			list($twilio_info, $twilio_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($twilio_details!=-1){
				$twilio_details = $twilio_details[0];
				$accountSid = $twilio_details['host_name'];
				$authToken  = $twilio_details['user_name'];
				$appsid  = $twilio_details['db_password'];
			}
		}
		$token = new Services_Twilio_Capability($accountSid, $authToken);
		$token->allowClientOutgoing($appsid);
		$twilio_staff_id = 'staff'.VIS_STAFF_ID;
		$token->allowClientIncoming($twilio_staff_id);
		$twilio_generated_token = $token->generateToken();
		
		$forward_details=$voip_object->get_staff_forward(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$asign_twilio_staff = $voip_object->check_asign_twilio_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		#Exotel
			$exotel_filter='integration_type=38 AND is_enabled=1';
	        list($exo_count, $exotel_details)=$object->get_integration_setting($exotel_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
            //$exotel_details=$exotel_details[0];	
		#Aircall
		$aircall_filter='integration_type=50 AND is_enabled=1';
	        list($aircall_count, $aircall_details)=$object->get_integration_setting($aircall_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');					
	
		$query="SELECT `content` FROM `avis_settings` WHERE `title` ='vis_help_panel_view' ";
		$res=$database->query_exec($query);
		$help_view = $database->fetch_result_array($res); 
		$show_help = $help_view[0]['content'];
		$query="SELECT access FROM `avis_auto_assign_ticket_setting` WHERE `staff_id` =".VIS_STAFF_ID;
		$res=$database->query_exec($query);
		$autoAssignStaff = $database->fetch_result_array($res);
		include(VIS_PATH_TEMPLATE.'top_bar.php');
        return true;
    }

    function staff_signature($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
		 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');        
        $settingobject=new class_setting($database);
		 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object=new class_staff($database);
		 list($forum_info, $forum_modules)=$settingobject->get_module('is_enabled=1 and module_id=12 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($forum_modules!=-1) $mod_forum=1;
        $department=$object->get_department(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id asc ');
        $domain=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		 // $filter='department_id=1';
			$filter='content!=""';
        if(isset($operation['vis_staff_id']) && is_numeric($operation['vis_staff_id'])) $filter.=' and staff_id='.$operation['vis_staff_id'];
        else $filter.=' and staff_id='.VIS_STAFF_ID;
        $signature=$staff_object->get_signature($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
								$selecteddpt='';
										
								
		 for($i=0;$i<count($signature);$i++)
		 {
			if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1) 
			{  	
				$signature[$i]['content'] = get_plain_text($signature[$i]['content']);
			}
			
				if($signature[$i]['is_forum']==0)
				{
					if($signature[$i]['content']!='')
						{
							$ticket_signature = $signature[$i]['content'];
							$selecteddpt=$signature[$i]['department_id'];
						}
				}
				
				if($signature[$i]['is_forum']==1)
				{
						if($signature[$i]['content']!='')
						{   
						    $forum_signature = $signature[$i]['content'];
						    $selecteddpt=$signature[$i]['department_id'];
						}
				}
					
		 }
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'signature.php');
        return true;
    }

    function load_signature($operation) {
        global $vis_language;
        if(!isset($operation['vis_department'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDEPTNTFND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $filter='department_id='.$operation['vis_department'].' and is_forum=0 ';
        if(isset($operation['vis_staff_id']) && is_numeric($operation['vis_staff_id'])) $filter.=' and staff_id='.$operation['vis_staff_id'];
        else $filter.=' and staff_id='.VIS_STAFF_ID;
        $signature=$object->get_signature($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		 $signature = $signature[0];
        $database->database_disconnect();
        //include(VIS_PATH_TEMPLATE.'signature_editor.php');
        echo $ticket_signature=$signature['content'];	
        return true;
    }

    function update_staff_signature($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_staff_signature_content'] =='') $data['vis_staff_signature_content']=$operation['vis_staff_signature_content'];
        if((!isset($data['vis_department']) || $data['vis_department']==0) && $data['vis_sign_all_dept'] != 1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDEPTNTFND'].'"); </script>';
            return false;
        }
        if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1)
        $data['vis_staff_signature_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_staff_signature_content']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $object1=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object2=new class_staff($database);

        $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$operation['vis_staff_id'];
        list($staff_info, $staff_details)=$object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff_details[0];
        $staff_info['staff_count']=(!$staff_details || $staff_details==-1)?0:count($staff_details);
		if($staff_details!=-1) for($i=0;$i<count($staff_details);$i++){
            $staff_details[$i]['department']=array();
            if(isset($data['vis_sign_all_dept']) && $data['vis_sign_all_dept'] == 1){
				if($staff_details[$i]['department_access']==0){
					 $staff_details[$i]['department'] = $object->get_department_access('', VIS_STAFF_ID, VIS_LOCATION_AREA);
					 if($staff_details[$i]['department'] != -1){
					 foreach($staff_details[$i]['department'] as $dept){
					 $data['vis_department'] = $dept['department_id'];
					 $ret = $object2->update_staff_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}
				}
				else if($staff_details[$i]['department_access']==-2){
					$filter = VIS_TABLE_PREFIX.'staff_group.group_id = '.VIS_TABLE_PREFIX.'staff.group_id and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff_details[$i]['group_id'];
					list($staffgroup_info, $staff_group)=$object->get_staffgroup_ofstaff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staffgroup_info['department_access']==0){
					$staff_department=$staffgroup_info['department_access'];
					$filter = '';
					}else{
					$staff_department = explode(',', $staffgroup_info['department_access']);
					$filter = '(';
					for($j=0;$j<count($staff_department); $j++)
					$filter .= ' department_id='.$staff_department[$j].' or';
					$filter = substr($filter,0, -2);
					$filter .=' )';
					}
					$staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staff_details[$i]['department'] != -1){
					foreach($staff_details[$i]['department'] as $dept){
					 $data['vis_department'] = $dept['department_id'];
						$ret = $object2->update_staff_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}

				}
				else{
					$staff_department = explode(',', $staff_details[$i]['department_access']);
					$filter = '(';
					for($j=0;$j<count($staff_department); $j++)
					$filter .= ' department_id='.$staff_department[$j].' or';
					$filter = substr($filter,0, -2);
					$filter .=' )';
					$staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staff_details[$i]['department'] != -1){
					foreach($staff_details[$i]['department'] as $dept){
					$data['vis_department'] = $dept['department_id'];
					$ret = $object2->update_staff_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}
				}
			}
			else $ret = $object2->update_staff_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			$activity_log=$object->add_staff_activity_log("Modified ".$staff_details[0]['first_name']." ".$staff_details[0]['last_name']." ( ".$staff_details[0]['email']." ) staff signature", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); </script>';
		}
        $database->database_disconnect();
        return true;
    }

    function staff_settings($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $devices=$object->get_device('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'settings.php');
        return true;
    }

    function update_staff_setting($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!isset($data['vis_staff_id'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSTFNTFND'].'"); </script>';
            return false;
        }
        $data['vis_sound_alert']=(!isset($data['vis_sound_alert']))?0:1;
        $data['vis_dst']=(!isset($data['vis_dst']))?0:1;
        $data['vis_editor']=(!isset($data['vis_editor']))?0:1;
        if(!isset($data['vis_session_time']) || !is_numeric($data['vis_session_time'])) $data['vis_session_time']=30;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->update_staff_settings($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else
        {
			echo '<script>$("#short_summary").visExecution("load_area",{"vis_module":"staff", "vis_operation":"display_short_summary"});</script>';
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");javascript:active_preference_tab();</script>';
		}
        return true;
    }

    function view_profile($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $staff=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_group=$object->get_staff_group('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff[0];
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'profile.php');
        return true;
    }

    function update_staff($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        $flag=true;
        if(!isset($data['vis_staff_id'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSTFNTFND'].'"); </script>';
            $flag=false;
        }
        if(strpos($data['vis_firstname'], ' ') > 0)
		{
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFNAMEMISS'].'"); </script>';
            $flag=false;
		}
        if(trim($data['vis_firstname'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFNAMEMISS'].'"); </script>';
            $flag=false;
        }       
		 if(isset($data['vis_email']) && trim($data['vis_email'])!='')
		 {
			list($message, $flag) = check_email_validation($data['vis_email']);
			if(!$flag) {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$message.'"); </script>';
				$flag=false;
			} 
		 } 
        if(trim($data['vis_username'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGUNAMEMISS'].'"); </script>';
            $flag=false;
        }
		if($data['vis_mobile_number']!='' && !is_numeric($data['vis_mobile_number'])){
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGMOBILENONUM'].'"); </script>';
			return false;
		}
        if($data['vis_contact_number']!='' && !is_numeric($data['vis_contact_number'])){
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGCONTNONUM'].'"); </script>';
			return false;
		}
		if(isset($data['vis_office_email']) && trim($data['vis_office_email'])!='')
		 {
			list($message, $flag) = check_email_validation($data['vis_office_email']);
			if(!$flag) {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$message.'"); </script>';
				$flag=false;
			} 
		 }
        if($data['vis_facebook_id']!=''){
			$url_data = parse_url($data['vis_facebook_id']);
			//if($url_data['scheme'] != "http") $data['vis_facebook_id'] = 'http://'.$data['vis_facebook_id'];
			$facebook='/(ftp|http|https):\/\/?((www|\w\w)\.)?facebook.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/';
			if(!preg_match($facebook,$data['vis_facebook_id']))
			{
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFACEBOOKID'].'"); </script>';
                $flag=false;
			}
		}
		if($data['vis_twitter_id']!='')
        {
			$url_data = parse_url($data['vis_twitter_id']);
			if(!preg_match('/https|http:\/\/twitter\.com\/(#!\/)?[a-zA-Z0-9_]+/', $data['vis_twitter_id']))
			{
			     echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGTWITTERID'].'"); </script>';
                $flag=false;
			}
        }
        if($data['vis_google_id']!='')
        {
			$url_data = parse_url($data['vis_google_id']);
			if(($url_data['scheme'] != "http" || $url_data['scheme'] != "https") && ($url_data['host'] != "plus.google.com"))
			{
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGGOOGLEIDMISS'].'"); </script>';
                $flag=false;
			}
        }
        if($data['vis_linkedin_id']!='')
        {
			$url_data = parse_url($data['vis_linkedin_id']);
			$linkedin='/(ftp|http|https):\/\/?((www|\w\w)\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/';
            if (!preg_match($linkedin, $data['vis_linkedin_id']))
            {
					 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGLINKEDINIDMISS'].'"); </script>';
                    $flag=false;
			}
		}
        if(!$flag) return false;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);

        $staff=$setting_object->get_staff_for_sorting('(email="'.$data['vis_email'].'" || user_name="'.$data['vis_username'].'") and staff_id!='.$data['vis_staff_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $tmp=$setting_object->get_staff_for_sorting('(email="'.$data['vis_email'].'" || user_name="'.$data['vis_username'].'") and staff_id!="'.$data['vis_staff_id'].'"', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $staff)=$tmp;
        if($staff!=-1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSTAFFSAMEDETAILS'].'"); </script>';
            return false;
        }
		$ret=$object->update_staff($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else
        {
			$activity_log=$setting_object->add_staff_activity_log("Modified  ".$data['vis_firstname']." ".$data['vis_lastname']." ( ".$data['vis_email']." ) staff profile", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script>$("#short_summary").visExecution("load_area",{"vis_module":"staff", "vis_operation":"display_short_summary"});</script>';

			echo '<script>$("#vis_top_user_detail_menu").visExecution("load_area", {"vis_module":"staff", "vis_operation":"load_user_menu", "vis_load_tabs": false});</script>';

			echo "<script>$('#clearImg').visExecution('load_operations', {'vis_module':'home', 'vis_operation':'remove_profile_img','vis_dorefresh':'1'});</script>";
			
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
			
			
		}
        $database->database_disconnect();
        return true;
    }

	function view_alerts($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTALERTS'];
        $operation['vis_operation']='add_alert';
		$operation['vis_current_operation']='view_alerts';
		//$operation['vis_current_module']='setting';
		$operation['vis_current_module']='staff';
        $operation['vis_message']=$vis_language['TXTADDALERT'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        list($view_info, $view_details)=$object->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
		$sort_by=(isset($operation['vis_sort_by']))?$operation['vis_sort_by']:'';
		$admin_access=$object->get_staff_access('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(isset($admin_access[0]['level']) && $admin_access[0]['level']==1) $filter='';
		else $filter = VIS_TABLE_PREFIX.'alert.owner='.VIS_STAFF_ID;
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
		{
		$data= isset($operation['vis_action']) && $operation['vis_action']!='' ? parse_form_array($operation['vis_action']) : $operation;
		if($data['vis_title']!=''){$filter= ($filter!='')?'alert_name like "%'.$data['vis_title'].'%" and '.$filter:'alert_name like "%'.$data['vis_title'].'%"';}
		if($data['vis_status']!=''){$filter= ($filter!='')?'avis_alert.is_enabled="'.$data['vis_status'].'" and '.$filter:'avis_alert.is_enabled="'.$data['vis_status'].'"';}
		}
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
	    $alerts=$object->get_alerts($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
	    $alerts_total=$object->get_alerts($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'');
	    $alert_total=($alerts_total==-1)?0:count($alerts_total);
		$alert_info['alert_count']= $alert_total;
		$view_info['page_count']=($alert_total==0)?0:ceil($alert_total/$view_info['page_count']);
        $database->database_disconnect();
		$alert_info['page']=$page;
        $database->database_disconnect();
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
        ob_start();
        include(VIS_PATH_TEMPLATE.'list_alert.php');
		$alert_list = ob_get_clean();
	    ob_end_flush();
		$select='';
		$select .= "<div class=\"pull-right\">";
		$select .= "<select name=\"pageing\" id=\"paging\" class=\"form-control input-sm selectpicker pull-right paging v-middle\"  onchange=\"javascript:vis_apply_filter(this.value);\">";
		for($i=0;$i<$view_info['page_count'];$i++)
		$select.='<option value="'.$i.'" '.(($page==$i)?'selected="selected"':'').'>'.($i+1).'</option>';
		$select .= "</select><div class=\"text-muted pull-right label_page\">".$vis_language['TXTPAGE'].":</div>";
		echo json_encode( array('total_cnt'=>$alert_total, 'paging' => $select, 'list'=> $alert_list));
		 }else
        include(VIS_PATH_TEMPLATE.'alert_list.php');
        return true;
    }

    function add_alert($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTALERTS'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');//ADDED TODAY
        $ticket=new class_ticket($database);
        $client=new class_client($database);
        $setting=new class_setting($database);
		$sub_object=new class_subsetting($database);//ADDED TODAY
		$admin_access=$sub_object->get_admin_access(VIS_STAFF_ID, ' ', VIS_LOCATION_AREA);//ADDED TODAY
		$setting_check=explode(',',$admin_access['domain_access']);// ADDED TODAY
		if(($setting_check[51]==0 && $admin_access['domain_access']!=0)|| $admin_access['domain_access']==''){echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'")</script>';return false;}//ADDED TODAY
        include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'client.php'); 
        $object_client = new client();
        list($info, $modules)=$setting->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        list($schedule_count,$schedule)=$setting->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($stfinfo, $staff_details)=$setting->get_staff(VIS_TABLE_PREFIX.'staff.is_enabled=1','', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $etemplate)=$setting->get_etemplate('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $sms_setting=$setting->get_integration_details('integration_type=3 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $hipchat_setting=$setting->get_integration_details('integration_type=39 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $slack_setting=$setting->get_integration_details('integration_type=40 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domains=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);  $domains= $domains[1];
		list($hipchat_setting, $hipchat_details)  = $hipchat_setting;
		$hipchat_details = $hipchat_details[0];
		if($hipchat_details!=-1)
		{
			       $url = $hipchat_details['billing_url']."/v2/room?auth_token=".$hipchat_details['api_key']."&scope=view_room";
			      
			       $roomlist = file_get_contents($url);
			       $roomlist = json_decode($roomlist);
                   $roomlist = get_object_vars($roomlist);
			       $roomlist = $roomlist['items'];
			      
		}
		list($slack_setting, $slack_details)  = $slack_setting;
		$slack_details = $slack_details[0];
		
		if($slack_details!=-1)
		{
			$url = "https://slack.com/api/channels.list?token=".$slack_details['api_key'];
			$ch = curl_init( $url );
			curl_setopt( $ch, CURLOPT_POST, 1);
			curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string);
			curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
				'Content-Type: application/json',                                                                                
				'Content-Length: ' . strlen($data_string))                                                                       
			);   
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

			$response = curl_exec( $ch );
			$out_detail = json_decode($response);
			$channel_details = get_object_vars($out_detail);
            $channel_list =$channel_details['channels'];
		}
		 if(VIS_ADMIN_ACCESS_LEVEL==1) {
			list($sla_count,$sla)=$setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$lang_dt=$setting->get_language('is_enabled=1', '', 0, '', 0, VIS_LOCATION_AREA);
			list($info, $client_language)=$lang_dt;
			$label_details=$setting->get_labels('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$channel_details=$ticket->get_channel('is_enabled=1',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$ticket_types=$ticket->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA);
			$domain_list=$object_client->get_domain_access_list();
			$user_groups=$client->get_client_group(' (domain_id in ('.$domain_list.') or domain_id=0 ) and is_enable=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$departments=$ticket->get_department(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$status=$ticket->get_status_list('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$priorities=$ticket->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($categories_count,$categories)=$setting->get_ticket_category_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($subcategories_count,$subcategories)=$setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($items_count,$items)=$setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($levels_count,$levels)=$setting->get_ticket_level_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			$flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=1');
			if(VIS_ITIL==1){
				list($impact_count, $impact)=$setting->get_impact('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($risks_count, $risks)=$setting->get_risk('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($release_type_count, $release_type)=$setting->get_release_type('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($change_type_count, $change_type)=$setting->get_change_type('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				$locations=$setting->get_locations(' and is_enabled=1',0, -1, $sort_by='', VIS_LOCATION_AREA);
			}
		 }
        else {
			if(VIS_ITIL==1){
				include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
				$ticket_module = new ticket($database);
				$impact=$ticket_module->get_properties('get_impacts', '');
				$risks=$ticket_module->get_properties('get_risks', '');
				$release_type=$ticket_module->get_properties('get_releasetype', '');
				$change_type=$ticket_module->get_properties('get_changetype', '');
				$locations=$setting->get_properties('get_location', 'is_enabled=1');$locations=$locations[1];
				
			}
		$status=$setting->get_properties('get_status', 'is_enabled=1'); $status=$status[1];
		$priorities=$setting->get_properties('get_priorities', 'is_enabled=1'); $priorities=$priorities[1];
		$ticket_types=$setting->get_properties('get_types', 'is_enabled=1'); $ticket_types=$ticket_types[1];
		$flags=$setting->get_properties('get_flags', 'is_enabled=1');$flags=$flags[1];
		$label_details=$setting->get_properties('get_labels', '');	$label_details=$label_details[1];
		$channel_details=$setting->get_properties('get_channel', 'is_enabled=1');$channel_details=$channel_details[1];
		$categories=$setting->get_properties('get_ticket_category', 'is_enabled=1'); $categories=$categories[1];
		$subcategories=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.ticket_subcategory.'is_enabled=1'); $subcategories=$subcategories[1];
		$items=$setting->get_properties('get_ticket_item', VIS_TABLE_PREFIX.'ticket_item.is_enabled=1'); $items=$items[1];
		$levels=$setting->get_properties('get_ticket_level', 'is_enabled=1'); $levels=$levels[1];		
		}	
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'alert_add.php');
        return true;
    }

    function edit_alert($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTALERTS'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $ticket=new class_ticket($database);
        $client=new class_client($database);
        $staff=new class_staff($database);
        $setting=new class_setting($database);
        include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'client.php'); 
        $object_client = new client();
        list($info, $modules)=$setting->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        list($schedule_count,$schedule)=$setting->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($stfinfo, $staff_details)=$setting->get_staff(VIS_TABLE_PREFIX.'staff.is_enabled=1','', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $etemplate)=$setting->get_etemplate('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $sms_setting=$setting->get_integration_details('integration_type=3 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $hipchat_setting=$setting->get_integration_details('integration_type=39 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $slack_setting=$setting->get_integration_details('integration_type=40 AND '.VIS_TABLE_PREFIX.'integration.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        
        list($hipchat_setting, $hipchat_details)  = $hipchat_setting;
		$hipchat_details = $hipchat_details[0];
		if($hipchat_details!=-1)
		{
			       $url = $hipchat_details['billing_url']."/v2/room?auth_token=".$hipchat_details['api_key']."&scope=view_room";
			      
			       $roomlist = file_get_contents($url);
			       $roomlist = json_decode($roomlist);
                   $roomlist = get_object_vars($roomlist);
			       $roomlist = $roomlist['items'];
			      
				   /*$post_data = '';
				 	$ch = curl_init( $url );
					$myvars = array('start-index'=>0,'max-results'=>100,'include-private'=>'true' ,'include-archived'=>'false');
					$data_string = json_encode( $myvars);

					$ch = curl_init( $url );
					curl_setopt( $ch, CURLOPT_POST, 1);
					curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string);
					curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
					curl_setopt( $ch, CURLOPT_HTTPHEADER, array(                                                                          
					'Content-Type: application/json',                                                                                
					'Content-Length: ' . strlen($data_string)));   
					curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

					$responses = curl_exec( $ch );
					curl_close($ch);
					echo '<pre>22hererer===';
					print_r($responses);*/
		}
		list($slack_setting, $slack_details)  = $slack_setting;
		$slack_details = $slack_details[0];
		if($slack_details!=-1)
		{
			$url = "https://slack.com/api/channels.list?token=".$slack_details['api_key'];
			$ch = curl_init( $url );
			curl_setopt( $ch, CURLOPT_POST, 1);
			curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string);
			curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
				'Content-Type: application/json',                                                                                
				'Content-Length: ' . strlen($data_string))                                                                       
			);   
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

			$response = curl_exec( $ch );
			$out_detail = json_decode($response);
			$channel_details = get_object_vars($out_detail);
            $channel_list =$channel_details['channels'];
		}
	
        $alert=$staff->get_alerts('alert_id='.$action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $alert=$alert[0];
        $alert_event=array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
        $event=explode(',', $alert['event']);
        $staff_owner=is_numeric($alert['reciever'])?array(0=>$alert['reciever']):explode(',', $alert['reciever']);
        $team_owner=is_numeric($alert['reciever_team'])?array(0=>$alert['reciever_team']):explode(',', $alert['reciever_team']);
        for($i=0;$i<count($event);$i++) $alert_event[$event[$i]]=1;
        $alert_criteria=$staff->get_alert_criteria($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);        
        $domain_list=$object_client->get_domain_access_list();
        $user_groups=$client->get_client_group(' (domain_id in ('.$domain_list.') or domain_id=0 ) and is_enable=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $departments=$ticket->get_department(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domains=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);  $domains= $domains[1];
        
        list($sla_count,$sla)=$setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $lang_dt=$setting->get_language('is_enabled=1', '', 0, '', 0, VIS_LOCATION_AREA);
        list($info, $client_language)=$lang_dt;
		 if(VIS_ADMIN_ACCESS_LEVEL==1) {
			 $label_details=$setting->get_labels('', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $channel_details=$ticket->get_channel('is_enabled=1',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			 $ticket_types=$ticket->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA,'is_enabled=1');
			 $status=$ticket->get_status_list('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $priorities=$ticket->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA,'is_enabled=1');
			 list($categories_count,$categories)=$setting->get_ticket_category_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
		     list($subcategories_count,$subcategories)=$setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
		    list($items_count,$items)=$setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
           list($levels_count,$levels)=$setting->get_ticket_level_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
            $flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=1');
			if(VIS_ITIL==1){
				list($impact_count, $impact)=$setting->get_impact('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($risks_count, $risks)=$setting->get_risk('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($release_type_count, $release_type)=$setting->get_release_type('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				list($change_type_count, $change_type)=$setting->get_change_type('is_enabled=1', '','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				$locations=$setting->get_locations(' and is_enabled=1',0, -1, $sort_by='', VIS_LOCATION_AREA);
			}
		 }  
		else {
		$status=$setting->get_properties('get_status', 'is_enabled=1'); $status=$status[1];
		$priorities=$setting->get_properties('get_priorities', 'is_enabled=1'); $priorities=$priorities[1];
		$ticket_types=$setting->get_properties('get_types', 'is_enabled=1'); $ticket_types=$ticket_types[1];
		$flags=$setting->get_properties('get_flags', 'is_enabled=1');$flags=$flags[1];
		$label_details=$setting->get_properties('get_labels', '');	$label_details=$label_details[1];
		$channel_details=$setting->get_properties('get_channel', 'is_enabled=1');$channel_details=$channel_details[1];
		$categories=$setting->get_properties('get_ticket_category', 'is_enabled=1'); $categories=$categories[1];
		$subcategories=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1'); $subcategories=$subcategories[1];
		$items=$setting->get_properties('get_ticket_item', VIS_TABLE_PREFIX.'ticket_item.is_enabled=1'); $items=$items[1];
		$levels=$setting->get_properties('get_ticket_level', 'is_enabled=1'); $levels=$levels[1];		
			if(VIS_ITIL==1){
				include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
				$ticket_module = new ticket($database);
				$impact=$ticket_module->get_properties('get_impacts', '');
				$risks=$ticket_module->get_properties('get_risks', '');
				$release_type=$ticket_module->get_properties('get_releasetype', '');
				$change_type=$ticket_module->get_properties('get_changetype', '');
				$locations=$setting->get_properties('get_location', 'is_enabled=1');$locations=$locations[1];
			}
		}		 
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'alert_edit.php');
        return true;
    }

    function save_alert($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
          if(!isset($data['vis_staff_team']) && !isset($data['vis_staff'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSTAFFTEAM'].'"); </script>';
            return false;
        }
		if(!isset($data['vis_alert_title']) || trim($data['vis_alert_title'])=='' || preg_match("/([<>%\#\/])/", trim($data['vis_alert_title']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_event'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGEVTNTSEL'].'"); </script>';
            return false;
        }
        else if($data['vis_alert_order'] == '')
        {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDER'].'"); </script>';
             return false;
        }
        else if(!is_numeric($data['vis_alert_order']))
         {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDERNUM'].'"); </script>';
             return false;
        }
        $data['event']=implode(',', $data['vis_event']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $ret=$object->add_alert($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_alerts';
		$operation['vis_current_module']='home';
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			$activity_log=$setting_object->add_staff_activity_log("Added alert ".$data['vis_alert_title'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTALERTS'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function update_alert($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
		  if(!isset($data['vis_staff_team']) && !isset($data['vis_staff'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSTAFFTEAM'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_alert_title']) || trim($data['vis_alert_title'])=='' || preg_match("/([<>%\#\/])/", trim($data['vis_alert_title']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_event'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGEVTNTSEL'].'"); </script>';
            return false;
        }
        else if($data['vis_alert_order'] == '')
        {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDER'].'"); </script>';
             return false;
        }
        else if(!is_numeric($data['vis_alert_order']))
         {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDERNUM'].'"); </script>';
             return false;
        }
        $data['event']=implode(',', $data['vis_event']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        
        $ret=$object->update_alert($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_alerts';
		$operation['vis_current_module']='home';

        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			$activity_log=$setting_object->add_staff_activity_log("Modified alert ".$data['vis_alert_title'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");  $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTALERTS'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function view_calendar($operation) {
        $date=(isset($operation['vis_date']))?$operation['vis_date']:(date('n').'-'.date('Y'));
        include(VIS_PATH_TEMPLATE.'calendar.php');
        return true;
    }

    function load_calendar($operation) {
        $date=(isset($operation['vis_date']) && $operation['vis_date']!='')?$operation['vis_date']:(date('n').'-'.date('Y'));
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'calendar.php');
        $database=new class_database();
        $object=new class_calendar($database);
        echo $object->create_calendar($date, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        return true;
    }

    function add_cal_event($operation) {
        $date=(isset($operation['vis_monthyear']))?$operation['vis_monthyear']:'';
        include(VIS_PATH_TEMPLATE.'cal_task_add.php');
        return true;
    }

    function edit_task($operation) {
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'calendar.php');
        $database=new class_database();
        $object=new class_calendar($database);
        $task=$object->get_task('task_id='.$operation['vis_task_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $task=$task[0];
        include(VIS_PATH_TEMPLATE.'cal_task_edit.php');
        return true;
    }

    function save_cal_task($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_title']=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'calendar.php');
        $object=new class_calendar($database);
        $ret=$object->add_cal_task($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_calendar_tab").visExecution("load_area", {"vis_module":"home", "vis_operation":"view_calendar"}) </script>';
        return true;
    }

    function update_cal_task($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_title']=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'calendar.php');
        $object=new class_calendar($database);
        $ret=$object->update_cal_task($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); $("#vis_calendar_tab").visExecution("load_area", {"vis_module":"home", "vis_operation":"view_calendar"}) </script>';
        return true;
    }

    function view_task($operation) {
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'calendar.php');
        $database=new class_database();
        $object=new class_calendar($database);
        $tasks=$object->get_task('owner='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'task_list.php');
        return true;
    }

    function load_left_panel($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
		$query="SELECT `content` FROM `avis_settings` WHERE `title` ='vis_left_panel_view' ";
		$res=$database->query_exec($query);
		$lp_view = $database->fetch_result_array($res); 
		$default = $lp_view[0]['content']; // 0=default, 1=veiw label
		
        $counts=$object->get_quick_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $filter = "( ".VIS_TABLE_PREFIX."ticket.status_id!=3 ) and ".VIS_TABLE_PREFIX."ticket.is_spam=0 and is_deleted=0 and draft_id=0";
		$temp = $object->get_ticket_listing_count($filter,'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($ticket_info, $ticket_details)= $temp;
        $counts['inbox'] = $ticket_info['total'];
        $filter = "( ".VIS_TABLE_PREFIX."ticket.status_id!=3 ) and ".VIS_TABLE_PREFIX."ticket.is_spam=0 and is_deleted=0 and draft_id=".VIS_STAFF_ID;
		$temp = $object->get_ticket_listing_count($filter,'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($ticket_info, $ticket_details)= $temp;
        $counts['drafts'] = $ticket_info['total'];
		if($default==0 || !isset($default)){
			$queue_details=array();
			$page = (isset($operation['vis_page']) && is_numeric($operation['vis_page'])) ? $operation['vis_page'] : 0;
			$limit = ($page*10).',10';
			$sort_by = VIS_TABLE_PREFIX.'domain.display_order,'.VIS_TABLE_PREFIX.'domain.domain_id, '.VIS_TABLE_PREFIX.'department.display_order asc';
			$filter = VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1';
			$all_dept = $object->get_lp_department($filter, '', $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA, 1);
			$total_dept = $last_dept_cnt = $remaining_dept = 0; $dept_arr = array();
			for($i=0; $i<count($all_dept); $i++) {
				$total_dept += $all_dept[$i]['dept_cnt'];
				$dept_arr[$all_dept[$i]['domain_id']] = $all_dept[$i]['dept_cnt'];
			}
			$total_pages = ceil($total_dept/10);
			$load_more_lp_dept = ($total_pages > $page+1) ? ++$page : '';
			$queue_details = $object->get_lp_department($filter, $limit, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$last_domain_id = $company = '';
			if($queue_details != -1){
				for($i=0, $j=-1; $i<count($queue_details);$i++) {
					if($company == '' || isset($company) && $company != $queue_details[$i]['domain_id']){
						$j++; $k=0;
						$company = $queue_details[$i]['domain_id'];
						$domain[$j]['domain']['domain_id'] = $queue_details[$i]['domain_id'];
						$domain[$j]['domain']['domain_name'] = $queue_details[$i]['domain_name'];
					}
					$domain[$j]['departments'][$k]['department_id'] = $queue_details[$i]['department_id'];
					$domain[$j]['departments'][$k]['department_name'] = $queue_details[$i]['department_name'];

					$domain[$j]['departments'][$k++]['status'] = $object->get_department_status_list($queue_details[$i]['department_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
				}
				if( $dept_arr[$domain[$j]['domain']['domain_id']] > count($domain[$j]['departments']) )
					$last_domain_id = $domain[$j]['domain']['domain_id'];
			}		//echo '<pre>';print_r(end($domain));echo '</pre>';
		}else{
			##get label
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$staff_object=new class_staff($database);
			$staff=$staff_object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);			
			$department_access = explode(',',$staff[0]['department_access']);
			$find_in_set = '';
			for($i=0;$i<count($department_access);$i++){
				$find_in_set .= ' or find_in_set('.$department_access[$i].', department_access) ';
			}
			$filter = (VIS_STAFF_ID!=1)?'(department_access=0 '.$find_in_set.') and  ':'';
			$label_details	=	$object->get_left_panel_labels_list(' '.$filter.' is_enabled=1 and `visible_to_leftpanel` = 1 ', VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'left_panel.php');
        return true;
    }

    function search_global($operation) {
        global $vis_language;
        $database=new class_database();
        $search_res_msg = ""; $cnt = 0;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'forum.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'problem.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'changes.php');
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'releases.php');
        $client_object=new class_client($database);
        $ticket_object=new class_ticket($database);
								$object_selfhelp=new class_selfhelp($database);
								$object_forum = new class_forum($database);
								$object_problem=new class_problem($database);
								$object_changes=new class_changes($database);
								$object_release=new class_releases($database);
        if(strlen(trim($operation['vis_data'])) < 3){
			$search_res_msg = $vis_language['TXTGLOBALSEARCHERROR'];
		} else {
			
			$domains=$ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($domains!= -1)
        {
			for($cnts =0 ;$cnts < count($domains) ; $cnts++) 
			{ 
				$domain_access .= $domains[$cnts]['domain_id'].',';
			};
			$domain_access=substr($domain_access,0,-1);
        }
			
			// 1 ticket,2 client, 3 solution,4 forums, 5 organization, 6 Problems, 7 Release, 8 Chanage
			if($operation['vis_srmodule']==1){
			//
			
			$filter='(subject like "%'.addslashes($operation['vis_data']).'%" or ticket_hash ="'.addslashes($operation['vis_data']).'") and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.is_deleted = 0 and 	'.VIS_TABLE_PREFIX.'ticket.is_spam = 0 ';
			
			list($info, $tickets)=$ticket_object->get_ticket($filter, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			//
			if($tickets == -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($tickets != -1){ $cnt = count($tickets); $search_title=$vis_language['TXTTICKETS'];}
			}
			elseif($operation['vis_srmodule']==2){
			$filter=''.VIS_TABLE_PREFIX.'client_email.additional_email like "%'.$operation['vis_data'].'%" or email like "%'.$operation['vis_data'].'%" or first_name like "%'.$operation['vis_data'].'%" or last_name like "%'.$operation['vis_data'].'%" or contact_number like "%'.$operation['vis_data'].'%" or user_name like "%'.$operation['vis_data'].'%"';
			$client=$client_object->get_client_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($client == -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($client != -1){ $cnt = count($client); $search_title=$vis_language['TXTCLIENT'];}
			}
			elseif($operation['vis_srmodule']==3){
				
				$filter=VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id=0 and (article_title like "%'.addslashes($operation['vis_data']).'%" or '.VIS_TABLE_PREFIX.'selfhelp_article.article_keywords like "%'.addslashes($operation['vis_data']).'%")';
			list($info, $solution)=$object_selfhelp->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit,' entry_date desc ',$domains);
			if($solution== -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($solution != -1){ $cnt = count($solution); $search_title=$vis_language['TXTSELFHELP'];
				include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'selfhelp.php');
				$selfhelp_obj=new selfhelp($database);
				for($s=0;$s<$cnt;$s++){
					$solution[$s]['title_selfhelp'] = $selfhelp_obj->getcategorybreadcrumb($solution[$s]['parent_id']);
				}
			}
				 }
			elseif($operation['vis_srmodule']==4){
				if($domain_access!=-1){
				$filter .= VIS_TABLE_PREFIX.'forum_category.domain_id IN('.$domain_access.') and '.VIS_TABLE_PREFIX . 'forum_topic.title like "%'.addslashes($operation['vis_data']).'%" ';
				}else{
				$filter=VIS_TABLE_PREFIX . 'forum_topic.title like "%'.addslashes($operation['vis_data']).'%" ';
				}
			list($info, $forums)=$object_forum->get_topic($filter, $limit, $sort, VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			if(count($forums)== 0 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($forums != -1){ $cnt = count($forums); $search_title=$vis_language['TXTFORUMS'];}
				 }
			elseif($operation['vis_srmodule']==5){
			$filter=''.VIS_TABLE_PREFIX.'client_group.group_name like "%'.addslashes($operation['vis_data']).'%"';
			$organization=$client_object->get_organization_data($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($organization == -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($organization != -1){ $cnt = count($organization); $search_title=$vis_language['TXTORGANIZATION'];}
			}
			elseif($operation['vis_srmodule']==6){
				$filter='(subject like "%'.addslashes($operation['vis_data']).'%" or problem_hash ="'.addslashes($operation['vis_data']).'") ';
			list($info, $problems)=$object_problem->get_problems($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($problems== -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($problems != -1){ $cnt = count($problems); $search_title=$vis_language['TXTPROBLEMS'];}
				 }
					elseif($operation['vis_srmodule']==7){
				$filter='(subject like "%'.addslashes($operation['vis_data']).'%" or release_hash ="'.addslashes($operation['vis_data']).'") ';
			list($info, $release)=$object_release->get_releases($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);		
			if($release== -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($release != -1){ $cnt = count($release); $search_title=$vis_language['TXTPROBLEMS'];}
				 }
					elseif($operation['vis_srmodule']==8){
				$filter='(subject like "%'.addslashes($operation['vis_data']).'%" or changes_hash ="'.addslashes($operation['vis_data']).'") ';
			list($info, $change)=$object_changes->get_changes($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($change== -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($change != -1){ $cnt = count($change); $search_title=$vis_language['TXTPROBLEMS'];}
				 }
			else{
				$filter='(subject like "%'.($operation['vis_data']).'%" or ticket_hash ="'.addslashes($operation['vis_data']).'") and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.is_deleted = 0 and 	'.VIS_TABLE_PREFIX.'ticket.is_spam = 0 ';
			list($info, $tickets)=$ticket_object->get_ticket($filter, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($tickets == -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
			if($tickets != -1){ $cnt = count($tickets); $search_title=$vis_language['TXTTICKETS'];}
			}
			
			
			
			$database->database_disconnect();
			//if($client != -1) $cnt += count($client);
			//if($tickets != -1) $cnt += count($tickets);
			

		}
        //if($tickets == -1 && $client == -1 && $organization == -1 && $search_res_msg == '') { $search_res_msg = $vis_language['TXTNOMATCHFOUND']; }
        include(VIS_PATH_TEMPLATE.'global_search_result.php');
        return true;
    }

    function access_restrict($operation) {
        global $vis_language;
        echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
        return false;
    }

    function load_settings_panel($operation) {
        include(VIS_PATH_TEMPLATE.'settings_panel.php');
        return true;
    }

    function login_form() {
        if($this->error==1) $incomplete_login=true;
        if($this->error==2) $invalid_login=true;
        if($this->error==3) $forget_pass=false;
        if($this->error==4) $forget_pass=true;
        if($this->error==5) $ip_ban=true;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($info, $languages)=$object->get_language('is_enabled=1', '', 0, '', 0, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if( !$this->error || $this->error == 6)
			include(VIS_PATH_TEMPLATE.'login.php');
		else{
			global $vis_language;
			$err = '';
			if(isset($incomplete_login) && $incomplete_login) $err = $vis_language['MSGINCOMPLETEINFO'];
			if(isset($invalid_login) && $invalid_login) $err = $vis_language['MSGINVALIDLOGINDETAILS'];
			if(isset($forget_pass) && $forget_pass) $err = $vis_language['MSGPASSSET'];
			if(isset($forget_pass) && !$forget_pass) $err = $vis_language['MSGEMAILMISS'];
            if(isset($ip_ban) && $ip_ban) $err = $vis_language['MSGIPBAN'];
			if($err != '')//echo '<div class="alert alert-danger"><strong>'.$err.'</strong></div>';
				echo $err;
		}
        return true;
    }

    function change_password($operation) {
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object_setting=new class_setting($database);
		$filter=VIS_TABLE_PREFIX.'settings.title="vis_security_password"';
		$security_password_details=$object_setting->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);

        include(VIS_PATH_TEMPLATE.'change_password.php');
        return true;
    }

    function update_staff_password($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(trim($data['vis_new_password'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGINFOMISS'].'"); </script>';
            return false;
        }

        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
		$filter=VIS_TABLE_PREFIX.'settings.title="vis_security_password"';
		$security_password_details=$setting_object->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$security_password = ($security_password_details==-1)?50:$security_password_details[0]['content'];
		if($data['password_strength_per']<$security_password) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['TXTPASSWORDNOTALLOWED'].'"); </script>';
            return false;
        }

        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->update_staff_password($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($ret==-1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINVLDOLDPWD'].'"); </script>';
            return false;
        }
        elseif($ret==0) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else{ 
            echo '<script>$("#short_summary").visExecution("load_area",{"vis_module":"staff", "vis_operation":"display_short_summary"});</script>';

			echo '<script>$("#vis_top_user_detail_menu").visExecution("load_area", {"vis_module":"staff", "vis_operation":"load_user_menu", "vis_load_tabs": false});</script>';
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';         
        }
        $database->database_disconnect();       
        return true;
    }

    function show_toolbar($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $toolbar=$object->get_staff_toolbar('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'toolbar_edit.php');
        return true;
    }

    function update_toolbar($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->set_toolbar($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
        return true;
    }

    function view_prefrences($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $staff=$object->get_staff_setting('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff[0];
        $database->database_disconnect();
        $themes=array();
        if ($d=@dir(VIS_PATH_THEME.'../')) {
            while (false !== ($entry = $d->read())) {
                if(!@is_dir(VIS_PATH_THEME.$entry)) {
                    $themes[]=$entry;
                }
            }
        }
        include(VIS_PATH_TEMPLATE.'prefrences.php');
        return true;
    }

    function update_properties($operation) {
        global $vis_language;
        if(isset($operation['vis_update_id']) && is_numeric($operation['vis_update_id'])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
            $object=new class_staff($database);
            $ret=$object->update_property($operation['vis_action'], $operation['vis_update_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            if(!$ret) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"ticket", "vis_operation":"filter_ticket", "vis_action":"#/ticket/filter_ticket/'.$vis_language['TXTTICKETS'].'/1"}); </script>';
            return true;
        }
        else {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGINFOMISS'].'"); </script>';
            return false;
        }
    }

    function get_properties($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        switch($operation) {
            case 'get_views':
                $filter='is_enabled=1';
                if(!defined('VIS_ADMIN_ACCESS') || VIS_ADMIN_ACCESS==-1) $filter.=' and view_id!=1';
                $ret=$object->get_view_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            break;
            default: $ret=false;
        }
        $database->database_disconnect();
        return $ret;
    }

    function load_menu_toolbar($operation) {
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object=new class_staff($database);
        $staff_access=$staff_object->get_staff('staff_id='.VIS_STAFF_ID,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_department=$staff_access[0]['department_access'];
         if($staff_department==-2)
        {
			$filter = VIS_TABLE_PREFIX.'staff_group.group_id = '.VIS_TABLE_PREFIX.'staff.group_id and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff_access[0]['group_id'].' and '.VIS_TABLE_PREFIX.'staff.staff_id='.VIS_STAFF_ID;
			list($staffgroup_info, $staff_group)=$object->get_staffgroup_ofstaff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$staff_department_array=explode(',', $staffgroup_info['department_access']);
		}
		else
		{
			$staff_department_array=explode(',', $staff_department);
		}
		$dept=array();
		$domain_access=array();
		for($i=0;$i<count($staff_department_array); $i++)
		{
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$ticket_object=new class_ticket($database);
			if($staff_department_array[$i]!=0)
			{
				$department=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.department_id='.$staff_department_array[$i], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
				$dept[]=$department[0];
			}
			else
			{
				$department=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
				$dept=$department;
			}
		}
		for($i=0;$i<count($dept); $i++)
		{
			if($dept[$i]!='') $domain_access[]=$dept[$i]['domain_id'];
		}
		$domain_access=array_unique($domain_access);
		$domain_access=implode(',', $domain_access);
		if(substr($domain_access, -1)==',')
		$domain_access=substr($domain_access,0,-1);
        list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        $module['online_staff']=1;
        $filter='integration_type=19 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($livechat_info, $livechat_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$livechat=$livechat_details[0];
        $filter1='integration_type=20 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($livezilla_info, $livezilla_details)=$object->get_integration_setting($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $livezilla=$livezilla_details[0];
		$filter2='integration_type=22 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($userlike_info, $userlike_details)=$object->get_integration_setting($filter2, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $userlike=$userlike_details[0];
        $filter3='integration_type=21 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($comm100_info, $comm100_details)=$object->get_integration_setting($filter3, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $comm100=$comm100_details[0];

		$goto_filter='integration_type=23 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($count, $gotosetting_details)=$object->get_integration_setting($goto_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $gotosetting_details=$gotosetting_details[0];

		$assist_filter='integration_type=24 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($count, $assist_details)=$object->get_integration_setting($assist_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $assist_details=$assist_details[0];

		$teamviewer_filter='integration_type=25 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($count, $teamviewer_details)=$object->get_integration_setting($teamviewer_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $teamviewer_details=$teamviewer_details[0];

        $webex_filter='integration_type=26 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($count, $webex_details)=$object->get_integration_setting($webex_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $webex_details=$webex_details[0];


        $twilio_filter='integration_type=27 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($count, $twilio_details)=$object->get_integration_setting($twilio_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        $twilio_details=$twilio_details[0];
		
		$magento_filter='integration_type=31 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.'))';
        list($count, $magento_details)=$object->get_integration_setting($magento_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        $freshbook_filter='integration_type=29 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($count, $freshbook_details)=$object->get_integration_setting($freshbook_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $freshbook_details=$freshbook_details[0];
       
        $filter='integration_type=30 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($clickdesk_info, $clickdesk_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$clickdesk=$clickdesk_details[0]; 
        
        $filter='integration_type=32 AND is_enabled=1 AND '.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.')';
        list($zopim_info, $zopim_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $zopim=$zopim_details[0]; 
		
		#Exotel
			$exotel_filter='integration_type=38 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
	        list($exo_count, $exotel_details)=$object->get_integration_setting($exotel_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
                $exotel_details=$exotel_details[0];
		#crisp
			$filter='integration_type=46';
			list($crisp_info, $crisp_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); 
			$crisp_details=$crisp_details[0];
		
		#Aircall
			$aircall_filter='integration_type=50 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
	        list($aircall_count, $aircall_details)=$object->get_integration_setting($aircall_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
                $aircall_details=$aircall_details[0];
				
		#Asterisk
			$asterisk_filter='integration_type=51 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
	        list($asterisk_count, $asterisk_details)=$object->get_integration_setting($asterisk_filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'order by domain_id desc');		
                $asterisk_details=$asterisk_details[0];
			
        $gcal_filter='integration_type=42 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id in ('.$domain_access.') or '.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($gcal_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $gcal_details=$gcal_details[0]; 
	    if(count($gcal_details)>0 && $gcal_details!=-1){
			include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_DriveService.php');
			$client = new Google_Client();
			$client->setClientId($gcal_details['host_name']);
			$client->setClientSecret($gcal_details['user_name']);
			$client->setRedirectUri($gcal_details['billing_url']);
			$client->setDeveloperKey($gcal_details['db_name']);
			$cal = new Google_CalendarService($client);
			$tasksService= new Google_TasksService($client);
			$driveService= new Google_DriveService($client);
			if (isset($query_str[1])) {
			  $client->authenticate($query_str[1]);
			  $_SESSION['token'] = $client->getAccessToken();
			}
			if (isset($_SESSION['token'])) {
			  $client->setAccessToken($_SESSION['token']);
			}
			else {
				  $authUrl = $client->createAuthUrl();				 
			}
		}
        include(VIS_PATH_TEMPLATE.'menu_toolbar.php');
        $database->database_disconnect();
        return true;
    }

    function list_contents($operation) {
        $list=$this->get_properties($operation['vis_action']);
        include_once(VIS_PATH_TEMPLATE.'staff_properties.php');
        if($list && function_exists($operation['vis_action'])) {
            echo $operation['vis_action']($list, $operation);
        }
        else return false;
        return true;
    }

    function view_views($operation){
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        $page=(isset($operation['vis_page']))?$operation['vis_page']:0;
        $object=new class_staff($database);
        list($view_info, $view_details_temp)=$object->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter=(!defined('VIS_ADMIN_ACCESS') )?'view_id!=1':'';
        if(VIS_ADMIN_ACCESS_LEVEL==1) $filter=$filter;
		else $filter = ($filter!='')? $filter.' and '.VIS_TABLE_PREFIX.'view.owner='.VIS_STAFF_ID:VIS_TABLE_PREFIX.'view.owner='.VIS_STAFF_ID;
        $view_details=$object->get_view_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,($page+1),$limit);
        $view_total=$object->get_view_count($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_details_info['page_count']=($view_total['total']==0)?0:ceil($view_total['total']/$view_info['page_count']);
        $view_details_info['page']=$page;
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'views.php');
        return true;
    }

    function new_view($operation){
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $field_list=$object->get_view_field(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'view_new.php');
        return true;
    }

    function add_view($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_status']=='on') $data['vis_status']=1;
        else $data['vis_status']=0;
        if(trim($data['vis_viewname'])=='' || preg_match("/([<>%\#\/])/", trim($data['vis_viewname']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        if(trim($data['vis_list_value'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFLDNTSEL'].'"); </script>';
            return false;
        }
        if(trim($data['vis_listcount'])=='' || !is_numeric($data['vis_listcount']) || $data['vis_listcount']<1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGLISTCNTNUMERIC'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->add_view($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $operation['vis_current_operation']='view_views';
        $operation['vis_current_module']='home';
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTVIEWS'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"});</script>';
        return true;
    }

    function update_view($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_status']=='on') $data['vis_status']=1;
        else $data['vis_status']=0;
        if(trim($data['vis_viewname'])=='' || preg_match("/([<>%\#\/])/", trim($data['vis_viewname']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        if(trim($data['vis_list_value'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFLDNTSEL'].'"); </script>';
            return false;
        }
        if(trim($data['vis_listcount'])=='' || !is_numeric($data['vis_listcount']) || $data['vis_listcount']<1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGLISTCNTNUMERIC'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->update_view($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $operation['vis_current_operation']='view_views';
        $operation['vis_current_module']='home';
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTVIEWS'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"});</script>';
        return true;
    }

    function view_details($operation) {
        global $vis_language;
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
            $object=new class_staff($database);
            $filter=VIS_TABLE_PREFIX.'view.view_id='.$action[4];
            $view_details=$object->get_view_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $field_list=$object->get_view_field(VIS_STAFF_ID, VIS_LOCATION_AREA, $action[4]);
            $view_access=$object->get_view_details($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            include(VIS_PATH_TEMPLATE.'view_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGDOMAINNOTFOUND'];
            return false;
        }
    }

    function left_panel_view($operation){
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $domain_details=$object->get_domain('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($domain_details==-1) return false;
        else {
            for($i=0;$i<count($domain_details);$i++)
                $domain_details[$i]['departments']=$object->get_lp_department(VIS_TABLE_PREFIX.'department.domain_id='.$domain_details[$i]['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'left_panel_view.php');
        return true;
    }

    function get_staff($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $filter=(isset($operation['vis_filter']) && $operation['vis_filter']!='')?$operation['vis_filter']:'';
        if($filter=='' && VIS_LOCATION_AREA==0) $filter='is_enabled=1';
        $staff=$object->get_staff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($staff==-1) {
            echo $vis_language['TXTNOMATCHFOUND'];
        }
        else {
            echo get_xml($staff, 'staff');
        }
        $database->database_disconnect();
        return true;
    }

    function check_automation($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $notificatins=$object->get_notification_setting(VIS_STAFF_ID,VIS_LOCATION_AREA);
        $filter=' session_id="'.$_COOKIE[VIS_STAFF_COOKIE].'"';
        $object->update_session($filter, VIS_STAFF_ID,VIS_LOCATION_AREA);
		
		$autoticketlockflag=0;
				$staffsetting=$object->get_staff_group('group_id='.VIS_STAFF_GROUP, VIS_STAFF_ID, VIS_LOCATION_AREA);
				
				if($staffsetting!=-1){ 
				$access=explode(',', $staffsetting[0]['access']); 
				if(isset($access[100])){$autoticketlockflag=$access[100];}else{$autoticketlockflag=0;}
				}
				else{$autoticketlockflag=0;}
				
				if($autoticketlockflag==1){
		$object->auto_unlock_ticket('', VIS_STAFF_ID,VIS_LOCATION_AREA);
				}
		
        echo "<script>$('#global_menu').visExecution('load_area', {'vis_module':'home', 'vis_operation':'load_global_menu'});</script>";
        if($notificatins){
			echo '<script>$("#vis_notify_container").show();</script>';
			$ret=$object->check_automation(VIS_STAFF_ID, VIS_LOCATION_AREA,$operation);
			if($ret!=-1 && $ret!='') {
				echo '<script>var count=parseInt($("#vis_notify_count").text());if(isNaN(count)){count=0;}count=(count+'.$ret.');$("#vis_notify_count").html(count);</script>';
			}
		}
        else echo '<script>$("#vis_notify_container").hide();</script>';
		$this->refresh_leftpanel($operation);
		$this->refresh_right_panel($operation);
		
        $database->database_disconnect();
        return true;
    }

    function online_staff($operation){
        $online = 1;
        $page = (isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        list($view_info, $view_details)=$object->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(isset($operation['isOffline']) && $operation['isOffline'] == 1)
        {
			$page = (isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
			$limit=' limit '.($page*$view_info['page_count']).','.$view_info['page_count'];
			list($staffCnt,$online_staff) = $object->online_staff(1, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$online = 0;
			$view_info['page_count']=($staffCnt['total']==0)?0:ceil($staffCnt['total']/$view_info['page_count']);
			$view_info['page'] = $page;

        }
        else
        {
			$page = (isset($operation['vis_page_online']) && is_numeric($operation['vis_page_online']))?$operation['vis_page_online']:0;
			$limit=' limit '.($page*$view_info['page_count']).','.$view_info['page_count'];
			list($staffCnt,$online_staff) = $object->online_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$view_info['page_count']=($staffCnt['total']==0)?0:ceil($staffCnt['total']/$view_info['page_count']);
			$view_info['page_online'] = $page;
		}

        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'online_staff.php');
        return true;
    }

    function upload_file($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        if($operation['vis_switch']==2)
        {
			$ret=$object->upload_file($_FILES, $operation, VIS_DOMAIN, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
		}
		else
		{
        list($width, $height) = getimagesize($_FILES['vis_pro_img']['tmp_name']);
         if($width<=25 && $height<=25)
         {
			$ret=$object->upload_file($_FILES, $operation, VIS_DOMAIN, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
	     }
	     else
	     {?>
			  <script> parent.$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGIMGSIZE']; ?>"); </script>'; <?
            return false;

		 }
	 }
        if(!$ret) { ?>
            <script> parent.$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>'; <?
            return false;
        }
        else {
            $clearBtn = $message=$message1='';
            $attach='';
            //for($i=0;$i<count($ret);$i++) {
													if($operation['vis_switch']==2){
														$message.='<img  src=\"'.VIS_PATH_PROFILE.$ret['attachment_name_new'].'\" class=\"lg bg-white img-responsive\" />';
													}else{
               $message.='<img width=\"48\" src=\"'.VIS_PATH_PROFILE.$ret['attachment_name_new'].'\" class=\"bg-white img-responsive\" />';
													}
               $message1.='<img src=\"'.VIS_PATH_PROFILE.$ret['attachment_name_new'].'\"/>';
				$clearBtn.= '<button type=\"button\" id=\"clearBtn\" class=\"btn btn-primary btn-xs\" onclick=\"javascript:clear_prof_image();\">'.$vis_language['TXTCLEAR'].'</button>';
				$clearchnlBtn.= '<button type=\"button\" id=\"clearchnlBtn\" class=\"btn btn-primary btn-xs\" onclick=\"javascript:clear_image();\">'.$vis_language['TXTCLEAR'].'</button>';
				$clearnewchnlBtn.= '<button type=\"button\" id=\"clearnewchnlBtn\" class=\"btn btn-primary btn-xs\" onclick=\"javascript:clear_image1();\">'.$vis_language['TXTCLEAR'].'</button>';
            //}
           ?> <?
            if($operation['vis_switch']==1){	?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message1 ?>", "vis_button":"<? echo $clearchnlBtn ?>", "vis_attachments":"<? echo $attach; ?>","vis_channel":1}); </script>
            <? } else if($operation['vis_switch']==0){?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message1 ?>", "vis_button":"<? echo $clearnewchnlBtn ?>", "vis_attachments":"<? echo $attach; ?>","vis_channel":2}); </script>
             <? } else  if($operation['vis_switch']==2){?>
             <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clearBtn ?>", "vis_attachments":"<? echo $attach; ?>"}); </script> <? }
        }
        return true;
    }

    function remove_profile_img($operation) { 
	//echo '<pre>'; print_r($operation); echo '</pre>';
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        
		if(!isset($operation['vis_dorefresh']) || $operation['vis_dorefresh']!=1 ){
			$ret=$object->clear_staff_img($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
		}						
								$profileimg='';
								if(VIS_LOCATION_AREA==2 && $operation['vis_channel_update']!=1 && $operation['vis_channel_new']!=1){
								$filter='is_enabled=1 and staff_id='.VIS_STAFF_ID;
        $staff=$object->get_staff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
								$staff=$staff[0];
								$firstname=preg_split('//u', $staff['first_name'], -1, PREG_SPLIT_NO_EMPTY);
									$lastname=preg_split('//u', $staff['last_name'], -1, PREG_SPLIT_NO_EMPTY);
								$profileimg=ucfirst($firstname[0]).ucfirst($lastname[0]);
								}
								
        $database->database_disconnect();
        if(!$ret && !isset($operation['vis_dorefresh'])) { ?>
            <script> $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>'; <?
            return false;
        }
        else {
            $message='';
            $attach='';
            //for($i=0;$i<count($ret);$i++) {
                //$attach.=$ret['attachment_id'].',';
            //} ?>
           <? if($operation['vis_channel_update']!=1 && $operation['vis_channel_new']!=1){
			     //$message.='<img width=\"48\" src=\"'.VIS_PATH_PROFILE.'default.jpg\" class=\"bg-white img-responsive\"/>';
								$message='<div class=\"lg\">'.$profileimg.'</div>';
			if($profileimg!=''){ ?>			
            <script> 
			vis_staff_profile_img = $('#vis_staff_profile_img').html();
			res = vis_staff_profile_img.split('src');
			vis_dorefresh = '<?php echo $operation['vis_dorefresh'];?>';
			if((res.length==1 && vis_dorefresh==1)|| vis_dorefresh!=1){
			$('#clearBtn').remove();			
			$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>"}); }</script>
            <? }//check isset for refrash div
			} else if($operation['vis_channel_update']==1){
				$message.='<i class=\"vh vh-channel vh-2x\"></i>'; ?>
             <script> $('#clearchnlBtn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_channel":1}); </script>
             <? }else if($operation['vis_channel_new']==1){
				 $message.='<i class=\"vh vh-channel vh-2x\"></i>'; ?>
              <script> $('#clearnewchnlBtn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_channel":2}); </script> <? }
        }
        return true;
    }

    function get_view_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETEVIEW'];
        if($operation['vis_view_id']==1) {
            $message_info['vis_message']=$vis_language['MSGVIVCNTDEL'];
            $message_info['vis_event']="";
        }
        else {
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'delete_view', 'vis_view_id':".$operation['vis_view_id']."})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function delete_view($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $filter=' view_id='.$operation['vis_view_id'];
        $ret=$object->delete_view($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_workpanel_div").visExecution("load_module", "Views", {"vis_module":"home", "vis_operation":"view_views"}); $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
        return true;
    }

    function get_task_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETETASK'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'delete_task', 'vis_task_id':".$operation['vis_task_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function delete_task($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->delete_task($operation['vis_task_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_task_delete_form").dialog("close");</script>';
            return false;
        }
        else echo '<script> $("#vis_task_delete_form").dialog("close"); $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
        return true;
    }

    function get_alert_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETEALERT'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
		$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'delete_alert', 'vis_alert_id':".$operation['vis_alert_id'].",'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function delete_alert($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $alert=$object->get_alerts('alert_id='.$operation['vis_alert_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ret=$object->delete_alert($operation['vis_alert_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_alert_delete_form").dialog("close"); </script>';
            return false;
        }
        else {
			$activity_log=$setting_object->add_staff_activity_log("Removed alert ".$alert[0]['alert_name'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_alerts","vis_page":"'.$vis_page.'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function load_notification($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        //$staff=$object->get_notifications('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        include(VIS_PATH_TEMPLATE.'staff_notification.php');
        $notificatins=$object->get_notification_setting(VIS_STAFF_ID,VIS_LOCATION_AREA);
        if($notificatins){
			$ret=$object->check_automation(VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			if($ret!=-1 && $ret!='') {
				echo '<script>$("#vis_notify_count").html("'.$ret.'")</script>';
			}
			else echo '<script>$("#vis_notify_count").html("")</script>';
		}
        else echo '<script>$("#vis_notify_container").hide();</script>';
        return true;
    }

    function notify_blab($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'blabber.php');
        $object=new class_blabber($database);
        $notifications=$object->get_notifications('staff_id!='.VIS_STAFF_ID.' and module_id=6', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
    }

	 function notify_task($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $task_notifications = $object->get_notifications( 'module_id=1', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
    }

    function notify_selfhelp($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $notifications=$object->get_notifications('module_id=4', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
    }

    function notify_ticket($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $notifications=$object->get_notifications('module_id=2', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
    }

    function notify_client($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        $object=new class_client($database);
        $notifications=$object->get_notifications('module_id=3', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
    }

    function clear_leftpanel($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $return = $object->clear_leftpanel(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        return $return;
    }

    function add_device_key($operation) {
        if(!isset($operation['vis_regid']) || $operation['vis_regid']=='') {
            echo 'Registration id missing';
            return false;
        }
        elseif(!isset($operation['vis_staff_id']) || $operation['vis_staff_id']=='') {
            echo 'Staff id missing';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $return=$object->add_device_key($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        echo $return?'success':'error';
        return $return;
    }

    function delete_device_key($operation) {
        if(!isset($operation['vis_regid']) || $operation['vis_regid']=='') {
            echo 'Registration id missing';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $return=$object->delete_device_key($operation['vis_regid'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        echo $return?'success':'error';
        return $return;
    }

    function app_devices($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $devices=$object->get_device('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'devices.php');
        return true;
    }

    function get_device_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']='Delete device';
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'device_delete', 'vis_device_id':".$operation['vis_device_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function device_delete($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->device_delete($operation['vis_device_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_device_delete_form").dialog("close"); </script>';
            return false;
        }
        else echo '<script> $("#vis_device_delete_form").dialog("close"); $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_module_home_div").tabs("load", $("#vis_module_home_div").tabs("option", "selected")); </script>';
        return true;
    }

    function vis_notifications($operation){
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);  
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $staff_access=$staff_object->get_staff('staff_id='.VIS_STAFF_ID,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_department=$staff_access[0]['department_access'];
        if($staff_department!=0)
        {
			 if($staff_department==-2)
			{
				$tempfilter = VIS_TABLE_PREFIX.'staff_group.group_id = '.VIS_TABLE_PREFIX.'staff.group_id and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff_access[0]['group_id'].' and '.VIS_TABLE_PREFIX.'staff.staff_id='.VIS_STAFF_ID;
				list($staffgroup_info, $staff_group)=$setting_object->get_staffgroup_ofstaff($tempfilter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				if($staffgroup_info['department_access']==0)
				$staff_department_array=$staffgroup_info['department_access'];
				else
				$staff_department_array=explode(',', $staffgroup_info['department_access']);
			}
			else
			{
				$staff_department_array=explode(',', $staff_department);
			}
		}
        $ticket_notifications = $ticket_object->get_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=2 and (operation_id=1 or operation_id=2)', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if($ticket_notifications!=-1){
            $last_element=end($ticket_notifications);
            $ticket_object->delete_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=2 and (operation_id=1 or operation_id=2) ', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
        }
        $reply_ticket_notifications = $ticket_object->get_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=2 and (operation_id=3 or operation_id=4) ', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if($reply_ticket_notifications!=-1){
            $last_element=end($reply_ticket_notifications);
            $ticket_object->delete_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=2 and (operation_id=3 or operation_id=4) ', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'blabber.php');
        $object=new class_blabber($database);
        $blabber_notifications = $object->get_notifications('operator_id!='.VIS_STAFF_ID.' and module_id=6 and operation_id=5 ', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if($blabber_notifications!=-1){
            $last_element=end($blabber_notifications);
            $ticket_object->delete_notifications('operator_id!='.VIS_STAFF_ID.' and module_id=6 and operation_id=5', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
        }
        $blabber_comment_notifications = $object->get_notifications('operator_id!='.VIS_STAFF_ID.' and module_id=6 and operation_id=6 ', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if($blabber_comment_notifications!=-1){
            $last_element=end($blabber_comment_notifications);
            $ticket_object->delete_notifications('operator_id!='.VIS_STAFF_ID.' and module_id=6 and operation_id=6', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $selfhelp_notifications = $object->get_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=4 and operation_id=7 ', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($selfhelp_notifications!=-1){
            $last_element=end($selfhelp_notifications);
            $ticket_object->delete_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=4 and operation_id=7 ', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        $selfhelp_comment_notifications = $object->get_notifications('module_id=4 and operation_id=8', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($selfhelp_comment_notifications!=-1){
            $last_element=end($selfhelp_comment_notifications);
            $ticket_object->delete_notifications('module_id=4 and operation_id=8', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        $object=new class_client($database);
        $client_notifications = $object->get_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=3', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($client_notifications!=-1){
            $last_element=end($client_notifications);
            $ticket_object->delete_notifications('((operator_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=3', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $task_notifications = $object->get_notifications( VIS_TABLE_PREFIX.'task.staff_id!='.VIS_STAFF_ID.' and module_id=1 and operation_id=11 and access_ids='.VIS_STAFF_ID , 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($task_notifications!=-1){
            $last_element=end($task_notifications);
            $ticket_object->delete_notifications(VIS_TABLE_PREFIX.'task.staff_id!='.VIS_STAFF_ID.' and module_id=1 and operation_id=11 and access_ids='.VIS_STAFF_ID, $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        $get_task_comment_notifications = $object->get_task_comment_notifications( VIS_TABLE_PREFIX.'task_comment.owner!='.VIS_STAFF_ID.' and module_id=1 and operation_id=12 and access_ids='.VIS_STAFF_ID, 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($get_task_comment_notifications!=-1){
            $last_element=end($get_task_comment_notifications);
            $ticket_object->delete_notifications(VIS_TABLE_PREFIX.'task_comment.owner!='.VIS_STAFF_ID.' and module_id=1 and operation_id=12 and access_ids='.VIS_STAFF_ID, $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'billing.php');
        $object=new class_billing($database);
        $order_notifications = $object->get_notifications('module_id=5', 'limit 5', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($order_notifications!=-1){
            $last_element=end($order_notifications);
            $ticket_object->delete_notifications('module_id=5', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        } 
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'forum.php');
        $object=new class_forum($database);
        $forum_notifications = $object->get_notifications('((staff_id!='.VIS_STAFF_ID.' and '.VIS_TABLE_PREFIX.'notification.is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=12 and ( access_ids = '.VIS_STAFF_ID.' OR access_ids = 0) and operation_id=15', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($forum_notifications!=-1){
            $last_element=end($forum_notifications);
            $ticket_object->delete_notifications('((staff_id!='.VIS_STAFF_ID.' and '.VIS_TABLE_PREFIX.'notification.is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=12 and operation_id=15', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        $forum_topic_comment_notifications = $object->get_topic_comment_notifications('((staff_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=12 and ( access_ids = '.VIS_STAFF_ID.' OR access_ids = 0) and operation_id=16', 'limit 10', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($forum_topic_comment_notifications!=-1){
            $last_element=end($forum_topic_comment_notifications);
            $ticket_object->delete_notifications('((staff_id!='.VIS_STAFF_ID.' and is_client=0) or ('.VIS_TABLE_PREFIX.'notification.is_client=1)) and module_id=12 and operation_id=16', $last_element['operation_time'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        }
        $order_access_notification=$selfhelp_access_notification=$selfhelp_comment_access_notification=$client_access_notification=$ticket_access_notification=$reply_ticket_access_notification=$forum_access_notifications=  $forum_topic_comment_access_notifications =array(); 
        if($ticket_notifications != -1){
		for($i=0; $i < count($ticket_notifications); $i++){
			if($ticket_notifications[$i]['operation_id']==1 || $ticket_notifications[$i]['operation_id']==2 ){
				if($staff_department_array!=0){
					if(in_array($ticket_notifications[$i]['access_ids'], $staff_department_array))
					{
						$ticket_access_notification[]=$ticket_notifications[$i];
					}
				}
				else{
					$ticket_access_notification[]=$ticket_notifications[$i];
				}
			}
		}
		}
		else $ticket_access_notification=-1;
		if($reply_ticket_notifications != -1){
		for($i=0; $i < count($reply_ticket_notifications); $i++){
			if($reply_ticket_notifications[$i]['operation_id']==3 || $reply_ticket_notifications[$i]['operation_id']==4 ){
				if($staff_department_array!=0){
					if(in_array($reply_ticket_notifications[$i]['access_ids'], $staff_department_array))
					{
						$reply_ticket_access_notification[]=$reply_ticket_notifications[$i];
					}
				}
				else{
					$reply_ticket_access_notification[]=$reply_ticket_notifications[$i];
				}
			}
		}
		}
		else $reply_ticket_access_notification=-1;
		if($selfhelp_notifications != -1 || $selfhelp_comment_notifications!=-1 || $client_notifications != -1 || $order_notifications != -1 || $forum_notifications !=-1 || $forum_topic_comment_notifications !=-1){
			$dept=array();
			$domain_access=array();
			for($j=0;$j<count($staff_department_array); $j++)
			{
				$department=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.department_id='.$staff_department_array[$j], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
				$dept[]=$department[0];
			}
			if($dept!=-1){
				for($k=0;$k<count($dept); $k++)
				{
					if($dept[$k]!='')
					$domain_access[]=$dept[$k]['domain_id'];
				}	
			}
			$domain_access=array_unique($domain_access);
	    }
		if($selfhelp_notifications != -1){
		for($i=0; $i < count($selfhelp_notifications); $i++){
			if($selfhelp_notifications[$i]['operation_id']==7 ){
					if($staff_department_array==0){
						$selfhelp_access_notification[]=$selfhelp_notifications[$i];
					}
					else {
							if(in_array($selfhelp_notifications[$i]['access_ids'], $domain_access))
							{
								$selfhelp_access_notification[]=$selfhelp_notifications[$i];
							}
						}
					}
				}
		}
		else $selfhelp_access_notification=-1;
		if($selfhelp_comment_notifications != -1){
		for($i=0; $i < count($selfhelp_comment_notifications); $i++){
			if($selfhelp_comment_notifications[$i]['operation_id']==8 ){
					if($staff_department_array==0){
						$selfhelp_comment_access_notification[]=$selfhelp_comment_notifications[$i];
					}
					else {
							if(in_array($selfhelp_comment_notifications[$i]['access_ids'], $domain_access))
							{
								$selfhelp_comment_access_notification[]=$selfhelp_comment_notifications[$i];
							}
						}
					}
				}
		}
		else $selfhelp_comment_access_notification=-1;
		if($client_notifications != -1){ 
		for($i=0; $i < count($client_notifications); $i++){
			if($client_notifications[$i]['operation_id']==10 ){
					if($staff_department_array==0){
						$client_access_notification[]=$client_notifications[$i];
					}
					else {
							if(in_array($client_notifications[$i]['access_ids'], $domain_access))
							{
								$client_access_notification[]=$client_notifications[$i];
							}
						}
					}
				}
		}
		else $client_access_notification=-1;
		if($order_notifications != -1){
		for($i=0; $i < count($order_notifications); $i++){
			if($order_notifications[$i]['operation_id']==13 ){
					if($staff_department_array==0){
						$order_access_notification[]=$order_notifications[$i];
					}
					else {
							if(in_array($order_notifications[$i]['access_ids'], $domain_access))
							{
								$order_access_notification[]=$order_notifications[$i];
							}
						}
					}
				}
		}
		else $order_access_notification=-1;
		if($forum_notifications != -1){
		for($i=0; $i < count($forum_notifications); $i++){
			if($forum_notifications[$i]['operation_id']==15 ){
					if($staff_department_array==0){
						$forum_access_notifications[]=$forum_notifications[$i];
					}
					else {
							if(in_array($forum_notifications[$i]['access_ids'], $domain_access))
							{
								$forum_access_notifications[]=$forum_notifications[$i];
							}
						}
					}
				}
		}
		else $forum_access_notifications=-1;
		if($forum_topic_comment_notifications != -1){
		for($i=0; $i < count($forum_topic_comment_notifications); $i++){
			if($forum_topic_comment_notifications[$i]['operation_id']==16 ){
					if($staff_department_array==0){
						$forum_topic_comment_access_notifications[]=$forum_topic_comment_notifications[$i];
					}
					else {
							if(in_array($forum_topic_comment_notifications[$i]['access_ids'], $domain_access))
							{
								$forum_topic_comment_access_notifications[]=$forum_topic_comment_notifications[$i];
							}
						}
					}
				}
		}
		else $forum_topic_comment_access_notifications=-1;
		$notifications = array_merge(
								($blabber_notifications != -1) ? $blabber_notifications : array(),
								($blabber_comment_notifications != -1) ? $blabber_comment_notifications : array(),
								($selfhelp_access_notification != -1) ? $selfhelp_access_notification : array(),
								($selfhelp_comment_access_notification != -1) ? $selfhelp_comment_access_notification : array(),
								($ticket_access_notification != -1) ? $ticket_access_notification : array(),
								($reply_ticket_access_notification != -1) ? $reply_ticket_access_notification : array(),
								($client_access_notification != -1) ? $client_access_notification : array(),
								($task_notifications != -1) ? $task_notifications : array(),
								($get_task_comment_notifications != -1) ? $get_task_comment_notifications : array(),
								($order_access_notification != -1) ? $order_access_notification : array(),
								($forum_access_notifications != -1) ? $forum_access_notifications : array(),
								($forum_topic_comment_access_notifications != -1) ? $forum_topic_comment_access_notifications : array()

							);
		for($i=0; $i < count($notifications); $i++){
			for($j=$i+1; $j<count($notifications); $j++){
				if($notifications[$i]['operation_time'] < $notifications[$j]['operation_time']){
					$temp = $notifications[$i];
					$notifications[$i] = $notifications[$j];
					$notifications[$j] = $temp;
				}
			}
		}	
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'notification.php');
        return true;
	}

	function refresh_leftpanel($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $str = '';
        if(isset($operation['vis_draft']) && $operation['vis_draft']==1){
			$filter = "( ".VIS_TABLE_PREFIX."ticket.status_id!=3 ) and ".VIS_TABLE_PREFIX."ticket.is_spam=0 and is_deleted=0 and draft_id=".VIS_STAFF_ID;
			$temp = $object->get_ticket_listing_count($filter,'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($ticket_info, $ticket_details)= $temp;
			$str .= '$("#vis_draft_ticket_lp_cnt").text("'.$ticket_info['total'].'");';
		}
		$options=parse_form_array($operation['vis_action']);
		$counts=$object->get_quick_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filter = "( ".VIS_TABLE_PREFIX."ticket.status_id!=3 ) and ".VIS_TABLE_PREFIX."ticket.is_spam=0 and is_deleted=0 and draft_id=0";
		$temp = $object->get_ticket_listing_count($filter,'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($ticket_info, $ticket_details)= $temp;
		$str .= '$("#vis_ticket_lp_cnt").text("'.$ticket_info['total'].'");';
		$str .= '$("#vis_trash_ticket_lp_cnt").text("'.$counts['trash'].'");';
		$str .= '$("#vis_spam_ticket_lp_cnt").text("'.$counts['spam'].'");';
		$str .= '$("#vis_schedule_ticket_lp_cnt").text("'.$counts['schedule'].'");';
		
		$query="SELECT `content` FROM `avis_settings` WHERE `title` ='vis_left_panel_view' ";
		$res=$database->query_exec($query);
		$lp_view = $database->fetch_result_array($res); 
		$default = $lp_view[0]['content']; // 0=default, 1=veiw label
		if($default==0 || !isset($default)){
			if(isset($operation['dept']) && !empty($operation['dept'])) {
				for($i=0; $i<count($operation['dept']); $i++){
					$arr = explode("-",$operation['dept'][$i]);
					$dept_id = $arr[0];
					$filter = "find_in_set(status_id, '".$arr[1]."')";
					$status = $object->get_department_status_list($dept_id, VIS_STAFF_ID, VIS_LOCATION_AREA, $filter);
					for($k=0; $k<count($status); $k++){
						$str .= '$("#vis_lp_department_'.$dept_id.'_status_'.$status[$k]['status_id'].'").text("'.$status[$k]['ticket_count'].'");';
					}
				}
			}else {
				if($operation['vis_domain_id']!='') $filter=' and '.VIS_TABLE_PREFIX.'domain.domain_id='.$operation['vis_domain_id']; else $filter='';
				$domains=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1'.$filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				$sort_by = VIS_TABLE_PREFIX.'domain.domain_id, '.VIS_TABLE_PREFIX.'department.display_order asc';
				if($domains!=-1) for($i=0;$i<count($domains);$i++) {
					$queue_details[$i]['departments']=$object->get_lp_department(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.$domains[$i]['domain_id'], '', $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($queue_details[$i]['departments']!=-1) for($j=0;$j<count($queue_details[$i]['departments']);$j++) {
						$queue_details[$i]['departments'][$j]['status']=$object->get_department_status_list($queue_details[$i]['departments'][$j]['department_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
						if($queue_details[$i]['departments'][$j]['status']!=-1) for($k=0;$k<count($queue_details[$i]['departments'][$j]['status']);$k++) {
						   $str .=  '$("#vis_lp_department_'.$queue_details[$i]['departments'][$j]['department_id'].'_status_'.$queue_details[$i]['departments'][$j]['status'][$k]['status_id'].'").text('.$queue_details[$i]['departments'][$j]['status'][$k]['ticket_count'].');';
						}
					}
				}
			} 
		}else{			
			##get label
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$staff_object=new class_staff($database);
			$staff=$staff_object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);			
			$department_access = explode(',',$staff[0]['department_access']);
			$find_in_set = '';
			for($i=0;$i<count($department_access);$i++){
				$find_in_set .= ' or find_in_set('.$department_access[$i].', department_access) ';
			}
			$filter = (VIS_STAFF_ID!=1)?'(department_access=0 '.$find_in_set.') and  ':'';
			$label_details	=	$object->get_left_panel_labels_list(' '.$filter.' is_enabled=1 and `visible_to_leftpanel` = 1 ', VIS_STAFF_ID, VIS_LOCATION_AREA);			
			for($j=0; $j<count($label_details); $j++) { 
				$str .= '  $("#vis_lbl_cnt'.$label_details[$j]['label_id'].'").text("'.$label_details[$j]['lbl_count'].'");  ';
			}
		}
		echo '<script>'.$str .'</script>';
        $database->database_disconnect();
        return true;
    }

	function load_more_lp_dept($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $queue_details=array();
        $page = (isset($operation['vis_page']) && is_numeric($operation['vis_page'])) ? $operation['vis_page'] : 0;
        $limit = ($page*10).',10';
        
		$sort_by = VIS_TABLE_PREFIX.'domain.display_order,'.VIS_TABLE_PREFIX.'domain.domain_id, '.VIS_TABLE_PREFIX.'department.display_order asc';
        $filter = VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1';
        $all_dept = $object->get_lp_department($filter, '', $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA, 1);
        $total_dept = $last_dept_cnt = $remaining_dept = 0; $dept_arr = array();
        for($i=0; $i<count($all_dept); $i++) {
			$total_dept += $all_dept[$i]['dept_cnt'];
			$dept_arr[$all_dept[$i]['domain_id']] = $all_dept[$i]['dept_cnt'];
		}
        $total_pages = ceil($total_dept/10);
        $load_more_lp_dept = ($total_pages > $page+1) ? ++$page : '';
        $queue_details = $object->get_lp_department($filter, $limit, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $last_domain_id = $company = '';
		if($queue_details != -1){
			for($i=0, $j=-1; $i<count($queue_details);$i++) {
				if($company == '' || isset($company) && $company != $queue_details[$i]['domain_id']){
					$j++; $k=0;
					$company = $queue_details[$i]['domain_id'];
					$domain[$j]['domain']['domain_id'] = $queue_details[$i]['domain_id'];
					$domain[$j]['domain']['domain_name'] = $queue_details[$i]['domain_name'];
				}
				$domain[$j]['departments'][$k]['department_id'] = $queue_details[$i]['department_id'];
				$domain[$j]['departments'][$k]['department_name'] = $queue_details[$i]['department_name'];

				$domain[$j]['departments'][$k++]['status'] = $object->get_department_status_list($queue_details[$i]['department_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			if( $dept_arr[$domain[$j]['domain']['domain_id']] > count($domain[$j]['departments']) )
				$last_domain_id = $domain[$j]['domain']['domain_id'];
		}		//echo '<pre>';print_r(end($domain));echo '</pre>';
        $database->database_disconnect();
        $arr = array();
		ob_start();
		include(VIS_PATH_TEMPLATE.'left_panel_next_dept.php');
		$arr[] =  ob_get_clean();
		ob_end_flush(); //print_r($arr);die;
		echo json_encode( $arr );
        //return true;
    }

    function load_global_menu($operation){
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);
		$counts=$ticket_object->get_filter_quick_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filters=$ticket_object->get_filters_details('is_enabled =1 and vscope=1 and is_report!=1 and (owner='.VIS_STAFF_ID.' or (filter_id=25 or filter_id=26 or filter_id=27 or filter_id=28 or filter_id=29))', VIS_STAFF_ID, VIS_LOCATION_AREA);
        include(VIS_PATH_TEMPLATE.'global_menu.php');
        return true;
	}
	function profile_view($operation) {
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');        
        $settingobject=new class_setting($database);
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4]))
        {
			$operation['vis_online']=1;
			$staff_id = $action[4];
	    }
        else $staff_id = VIS_STAFF_ID;
        $staff=$object->get_staff('staff_id='.$staff_id, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_group=$object->get_staff_group('is_enabled=1 and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff[0]['group_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_group=$staff_group[0];
        if(isset($operation['isOffline'])) $filter = 1;
        else $filter = 1;
        list($staffCnt,$online_staff) = $object->online_staff(VIS_TABLE_PREFIX.'sessions.user_id='.$staff_id, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        if(!isset($operation['vis_online_status'])){
            if($online_staff!=-1) $operation['vis_online_status']=1;
            else $operation['vis_online_status']=0;
        }
        $staff=$staff[0];
        list($info, $modules)=$settingobject->get_module('is_enabled=1 and module_id=9 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($modules!=-1) $mod_gamification=1;
        list($forum_info, $forum_modules)=$settingobject->get_module('is_enabled=1 and module_id=12 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($forum_modules!=-1) $mod_forum=1;
        list($blab_info, $blab_modules)=$settingobject->get_module('is_enabled=1 and module_id=6 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($blab_modules!=-1) $mod_blab=1;
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'profile_view.php');
        return true;
    }
    function get_staff_ticket_count($operation) {
        global $vis_language;
		$database=new class_database();        
        if(isset($operation['vis_staff_id']) && $operation['vis_staff_id']!='') $staff_id = $operation['vis_staff_id'];
        else $staff_id = VIS_STAFF_ID;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		$ticket_object=new class_ticket($database);
        $ticketCounts=$ticket_object->get_tickets_count($staff_id, VIS_LOCATION_AREA);
								//$ticketCounts['closed']=$this->getticketclosecount($staff_id);
        $database->database_disconnect();
        echo '<script> $("#replied_cnt").html("'.$ticketCounts['replied'].'"); $("#awaiting_cnt").html("'.$ticketCounts['awaiting'].'"); $("#closed_cnt").html("'.$ticketCounts['closed'].'"); </script>';
        return true;
    } 

    function time_tracking($operation)
    {
		$database = new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'report.php');
		$object = new class_report($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		$ticket_object = new class_ticket($database);
		$filter = "staff_id = ".VIS_STAFF_ID ;
		$time_tracking = $object->get_time_tracking_staff_report($filter, VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domain_details=$ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$currency=$domain_details[0]['currency'];
		include(VIS_PATH_TEMPLATE.'time_tracking.php');
	}
	function recent_activity($operation)
	{
		$database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object = new class_staff($database);
         include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object = new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $settingobject=new class_setting($database);
        $page =0;
        $recentActivities = $object->get_recent_activities(VIS_STAFF_ID,VIS_STAFF_ID,$vis_page=0);
        $All_Activities = $object->get_recent_activities(VIS_STAFF_ID,VIS_STAFF_ID,'',1);
        $total_Activities = $All_Activities['count']; 
        $total_pages = ceil($total_Activities/10);
        $load_more_activities = ($total_pages > $page+1) ? $page : '';
        if($recentActivities != -1){
        for($i=0;$i<count($recentActivities);$i++){
		$ticket_details=$ticket_object->get_ticket('ticket_id='.$recentActivities[$i]['ticket_id'],'', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA, '', $conditions='');
		 if( $ticket_details[1] == -1)  $recentActivities[$i]['actionLinks'] = '';
		 else $recentActivities[$i]['actionLinks'] = 1;
            if($recentActivities[$i]['operation_id']==7){
                if($recentActivities[$i]['old_info']=='' || $recentActivities[$i]['old_info']==0) $staffid=$recentActivities[$i]['new_info'];
                else  $staffid=$recentActivities[$i]['old_info'];
                if($staffid!=0){
                    $staff_info=$settingobject->get_staff(VIS_TABLE_PREFIX.'staff.staff_id='.$staffid, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
                    $recentActivities[$i]['user_info'] =  $staff_info[1][0]['first_name'].' '.$staff_info[1][0]['last_name'];
                }
            }
            else if($recentActivities[$i]['operation_id']==13){
                    $sla_old_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['old_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                    $sla_new_info=$settingobject->get_sla(VIS_TABLE_PREFIX.'sla.sla_id='.$recentActivities[$i]['new_info'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                    $recentActivities[$i]['old_info'] =  $sla_old_info[1][0]['sla_name'];
                    $recentActivities[$i]['new_info'] =  $sla_new_info[1][0]['sla_name'];
            }
        }
        }
        $database->database_disconnect();
		if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'recent_activity.php');
	}
	function load_right_panel($operation){
		
		global $vis_language;
		$database=new class_database();
		if(isset($operation['vis_current_module']) && $operation['vis_current_module'] == 'blabber') {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			$load_header=(isset($operation['vis_action']) && $operation['vis_action']=='no_load')?false:true;
			$staff = $ticket->get_properties('get_staff', $data='');
			$database->database_disconnect();
			$share_id=array();
			if(isset($operation['vis_share_id'])) $share_id=unserialize(base64_decode($operation['vis_share_id']));
			include(VIS_PATH_TEMPLATE.'blab_staff_add.php');
		} elseif($operation['vis_current_module'] == 'home' && $operation['vis_current_operations'] == 'quick_view') {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$object=new class_staff($database);
			
				$pin_data=$object->get_pinup(VIS_STAFF_ID, VIS_LOCATION_AREA);
				if(VIS_SHOWONLINESTAFF_ACCESS ==1){
				list($staffCnt,$online_staff) = $object->online_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
				}else{ /*echo "<script>$('#vis_right_panel_div').hide();</script>";*/ }
				$database->database_disconnect();
				include(VIS_PATH_TEMPLATE.'home_right.php');			
		}elseif($operation['vis_current_module'] == 'home' && ($operation['vis_current_operations'] == 'view_tasks' || $operation['vis_current_operations'] == 'view_update_tasks' || $operation['vis_current_operations'] == 'new_task'))
		{
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$object=new class_staff($database);
			$quick_view=$object->get_task_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'task_filters.php');
		}elseif($operation['vis_current_module'] == 'problem' && ($operation['vis_current_operations'] == 'new_problem' || $operation['vis_current_operations'] == 'view_problems' || $operation['vis_current_operations'] == 'filter_problem' || $operation['vis_current_operations'] == 'problems_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'problem.php');
			$object=new class_problem($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$impacts=$ticket->get_properties('get_impacts', '');

			$quick_view=$object->get_problem_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'problem_filters.php');
		}elseif($operation['vis_current_module'] == 'changes' && ($operation['vis_current_operations'] == 'new_change' || $operation['vis_current_operations'] == 'view_changes' || $operation['vis_current_operations'] == 'filter_changes' || $operation['vis_current_operations'] == 'changes_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'changes.php');
			$object=new class_changes($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$impacts=$ticket->get_properties('get_impacts', '');
			$risks=$ticket->get_properties('get_risks', '');
			$changetype=$ticket->get_properties('get_changetype', '');

			$quick_view=$object->get_changes_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'changes_filters.php');
		}elseif($operation['vis_current_module'] == 'releases' && ($operation['vis_current_operations'] == 'new_release' || $operation['vis_current_operations'] == 'view_releases' || $operation['vis_current_operations'] == 'filter_releases' || $operation['vis_current_operations'] == 'releases_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'releases.php');
			$object=new class_releases($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$releasetype=$ticket->get_properties('get_releasetype', '');

			$quick_view=$object->get_releases_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'releases_filters.php');
		}
		elseif($operation['vis_current_module'] == 'forums')
		{
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'forum.php');
			$forumObject=new class_forum($database);
			$counts=$forumObject->get_quick_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$domainDetails = $forumObject->get_right_panel_forum_cnt('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'forum_right_panel.php');
			
	}elseif($operation['vis_module'] == 'home' && ($operation['vis_operation'] == 'load_right_panel'))
		{
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$object=new class_staff($database);
			$quick_view=$object->get_task_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'task_filters.php');
		}
		
	}

	function staff_listing($operation) //function for displaying auto results for staff & staffgroup on add blab.
	{
		global $vis_language;
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $objectStf=new class_staff($database);
        include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
		$ticket=new ticket($database);
        if(!isset($operation['vis_task_assign']) && $operation['vis_task_assign']!=1){
		$filter='(first_name like "%'.$operation['vis_data'].'%" or last_name like "%'.$operation['vis_data'].'%") and '.VIS_TABLE_PREFIX.'staff.is_enabled=1 and staff_id!='.VIS_STAFF_ID;
		}else{
		$filter='(first_name like "%'.$operation['vis_data'].'%" or last_name like "%'.$operation['vis_data'].'%") and '.VIS_TABLE_PREFIX.'staff.is_enabled=1 ';
		}
		$filterGrp = '(group_name like "%'.$operation['vis_data'].'%") and is_enabled=1';
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($staffgroup_info, $staffgroup_details)=$object->get_staffgroup($filterGrp, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$staff = $ticket->get_properties('get_staff', $data='',$filter);
        $database->database_disconnect();
        if(empty($staff[0]))$staff = -1;
        if(empty($staffgroup_details))$staffgroup_details = -1;
		
		$count=count($staff);
        $cntGrp = count($staffgroup_details);
       
        $result='[';
        if($staff!=-1)
        {
			$result.='{"full_name":"'.$vis_language['TXTSTAFF'].'","id":"00","type":"heading"},';
			for($i=0;$i<$count;$i++) {

				$result.='{"id":"'.$staff[$i]['staff_id'].'", "full_name":"'.str_replace("\'","'",trim($staff[$i]['first_name'])).' '.str_replace("\'","'",trim($staff[$i]['last_name'])).'","type":"normal"},';
			}
		}
		if((!isset($operation['vis_task_assign']) && $operation['vis_task_assign']!=1) && (!isset($operation['vis_forum']) && $operation['vis_forum']!=1))
		{
			if($staffgroup_details!=-1)
			{
				$result.='{"full_name":"'.$vis_language['TXTTEAM'].'","id":"00","type":"heading"},';
				for($i=0;$i<$cntGrp;$i++) {

					$result.='{"group_id":"'.$staffgroup_details[$i]['group_id'].'","id":"'.$staffgroup_details[$i]['group_id'].'", "full_name":"'.str_replace("\'","'",trim($staffgroup_details[$i]['group_name'])).'","type":"normal"},';
				}
			}
	    }
        $result=substr($result, 0, -1);
        if($result==''){ $result = "[]"; echo $result; return true;}
        $result.=']';
        if(VIS_LOCATION_AREA==0) echo get_xml($staff, 'staff');
        else echo $result;
		return true;
	}
	function save_dashboard_settings($operation)
	{
		$database = new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $objectStf=new class_staff($database);
        $data = $objectStf->save_dashboard_settings(VIS_STAFF_ID,$operation);
	}
	function display_short_summary($operation){
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $staff=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$staff=$staff[0];
		$staff_group=$object->get_staff_group('is_enabled=1 and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff['group_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_group=$staff_group[0];
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'profile_short_summary.php');
        return true;
	}
	function view_macros($operation){
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
		$data= isset($operation['vis_action']) && $operation['vis_action']!='' ? parse_form_array($operation['vis_action']) : $operation;
		if($data['vis_title']!='') $and_operations['macro_title like "%'] = $data['vis_title'].'%"';
		if($data['vis_access']!='')$and_operations['access="'] = $data['vis_access'].'"';
		if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		}
		if($and_operations!='' && count($and_operations)!=0) {
            $filter="(";
            foreach($and_operations as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'macros.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_operations!="" && count($or_operations)!=0) {
            $filter.="(";
            foreach($or_operations as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'macros.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=")";
        }
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
	    $page=(isset($operation['vis_page']))?$operation['vis_page']:0;
        $object=new class_staff($database);
		$admin_access=$object->get_staff_access('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$staff_list = $object->get_staff('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($admin_access==-1 || $admin_access[0]['level']==2)$filter.=' staff_id = ' . VIS_STAFF_ID.' or access = "0"';
	    list($view_info, $view_details_temp) = $object->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit = ($page*$view_info['page_count']).','.$view_info['page_count'];
	    $macros_details = $object->get_macros_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, ($page+1), $limit,'',1 );
        $macros_total = $object->get_macros_count($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $macros_details_info['page_count'] = ($macros_total['total']==0)?0:ceil($macros_total['total']/$view_info['page_count']);
        $macros_details_info['page'] = $page;
		//$database->database_disconnect();
		$operation['vis_current_operation']='view_macros';
		$operation['vis_current_module']='home';
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'macros_list.php');
			$macros_list = ob_get_clean();
			ob_end_flush();
			$select='';
			$select .= "<div class=\"pull-right\">";
			$select .= "<select name=\"pageing\" id=\"paging\" class=\"form-control input-sm selectpicker pull-right paging v-middle\"  onchange=\"javascript:vis_apply_filter(this.value);\">";
			for($i=0;$i<$view_info['page_count'];$i++)
			$select.='<option value="'.$i.'" '.(($page==$i)?'selected="selected"':'').'>'.($i+1).'</option>';
			$select .= "</select><div class=\"text-muted pull-right label_page\">".$vis_language['TXTPAGE'].":</div>";
			echo json_encode( array('total_cnt'=>$macros_total['total'], 'paging' => $select, 'list'=> $macros_list));
			}else
        include(VIS_PATH_TEMPLATE.'macros.php');
        return true;
	}
	function new_macro($operation) {
		global $vis_language;
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object = new class_ticket($database);
		$department_list = $ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$status_list = $ticket_object->get_status_list('is_enabled=1',VIS_STAFF_ID, VIS_LOCATION_AREA);
		$type_list = $ticket_object->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=1');
		$priority_list = $ticket_object->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=1');
		$labels_list = $ticket_object->get_labels_list('', VIS_STAFF_ID, VIS_LOCATION_AREA);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff_object = new class_staff($database);
		$staff_list = $staff_object->get_staff('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
		list($sla_count,$sla)=$obj_setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domain=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$module_setting=$obj_setting->get_module_setting('domain_id='.$domain[0]['domain_id'].' and module_id=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
		list($cat_count,$category_list)=$obj_setting->get_ticket_category_list('is_enabled=1 and department_access=0',$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		}//check access
		if(isset($module_setting['vis_show_level']) && ($module_setting['vis_show_level']==1 || $module_setting['vis_show_level']==2)){
		list($level_count,$level_list)=$obj_setting->get_ticket_level_list('is_enabled=1 and department_access=0',$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		}
		if(VIS_ITIL==1){
		$location_assets=$obj_setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
		}
		$filter_condtn = 'is_enabled=1 and (department_access=0)';
  $flag_list=$ticket_object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
		
        include(VIS_PATH_TEMPLATE.'macro_new.php');
        return true;
	}
	function add_macro($operation) {
		global $vis_language;
		$data = parse_form_array($operation['vis_action']);
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object = new class_staff($database);
		if(!isset($data['vis_macro_title']) || $data['vis_macro_title']=='' || preg_match("/([<>%\#\/])/", trim($data['vis_macro_title']))) {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
			return false;
		}
		if(!isset($data['vis_displayorder']) || $data['vis_displayorder']=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDER'].'"); </script>';
            return false;
        } else if(!is_numeric($data['vis_displayorder'])) {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDERNUM'].'"); </script>';
             return false;
        }
		if(isset($data['vis_macro_tag']) && $data['vis_macro_tag'] != '') {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$ticket_object = new class_ticket($database);
			$tag_arr = explode(",", $data['vis_macro_tag']);
			foreach($tag_arr as $tag) {
				$tag_data['vis_newtag'] = $tag;
				$vis_tags[] = $ticket_object->add_live_tag($tag_data, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			$data['vis_macro_tag'] = count($vis_tags) > 1 ? implode(",", $vis_tags) : $vis_tags[0];
		}
		if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1){
			$data['vis_post_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_post_content']);
		}
		$data['vis_comment'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_comment']);
		$res = $staff_object->add_macro($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(!$res) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
		else
		echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module", "'.$vis_language['TXTMACROS'].'", {"vis_module":"home", "vis_operation":"view_macros"});</script>';
        return true;
	}
	function get_macro_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETE'].' '.$vis_language['TXTMACROS'];
        if($operation['vis_view_id']==1) {
            $message_info['vis_message']=$vis_language['MSGVIVCNTDEL'];
            $message_info['vis_event']="";
        }
        else {
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'delete_macro', 'vis_macro_id':".$operation['vis_macro_id']."})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
    function delete_macro($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $filter=' macro_id='.$operation['vis_macro_id'];
        $ret=$object->delete_macro($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_workpanel_div").visExecution("load_module", "Views", {"vis_module":"home", "vis_operation":"view_macros"}); $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
        return true;
    }
	function macro_details($operation) {		
        global $vis_language;
        $action=explode('/', $operation['vis_action']);
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database = new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
            $staff_object = new class_staff($database);
            $filter = 'macro_id = '.$action[4];
			$macro_details = $staff_object->get_macro_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$macro_details = $macro_details[0];
			//$macro_total = $staff_object->get_macros_count(VIS_STAFF_ID, VIS_LOCATION_AREA);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$ticket_object = new class_ticket($database);
			$department_list = $ticket_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$filter_condtn = ($macro_details['department'] == '0') ? 'is_enabled=1' : 'is_enabled=1 and (department_access=0 or find_in_set('.$macro_details['department'].', department_access))';
			$type_list = $ticket_object->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
			$status_list = $ticket_object->get_status_list($filter_condtn, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$priority_list = $ticket_object->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
			$staff_object = new class_staff($database);
			if($macro_details['department'] == '0') {
				$staff_list = $staff_object->get_staff('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
			} else {
				$staff_list = $staff_object->get_staff('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA, $macro_details['department']);
			}
			$labels_list = $ticket_object->get_labels_list($filter_condtn, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$tag_arr = explode(",", $macro_details['tags']);
			$filter = ' label_id = 0 ';
			foreach($tag_arr as $t) {
				$filter .= ($filter != '') ? ' or label_id = ' . $t : ' label_id = ' . $t;
			}
			$tags = $ticket_object->get_tag_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
           if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1) {
			   $macro_details['post_content'] = get_plain_text($macro_details['post_content']);
		   }
		   $macro_details['comment'] = get_plain_text($macro_details['comment']);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
		list($sla_count,$sla)=$obj_setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domains=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.department_id='.$macro_details['department'], VIS_STAFF_ID, VIS_LOCATION_AREA);
	
		
		$module_setting=$obj_setting->get_module_setting('domain_id='.$domains[0]['domain_id'].' and module_id=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
		list($cat_count,$category_list)=$obj_setting->get_ticket_category_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			if(isset($module_setting['vis_show_subcategory']) && ($module_setting['vis_show_subcategory']==1 || $module_setting['vis_show_subcategory']==2)){
		list($subcat_count,$subcategory_list)=$obj_setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_subcategory.category_id='.$macro_details['category_id'],$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			}
			if(isset($module_setting['vis_show_item']) && ($module_setting['vis_show_item']==1 || $module_setting['vis_show_item']==2)){
		list($item_count,$item_list)=$obj_setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1 and  '.VIS_TABLE_PREFIX.'ticket_item.subcategory_id='.$macro_details['subcategory_id'],$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			}
		}// check category module setting
		if(isset($module_setting['vis_show_level']) && ($module_setting['vis_show_level']==1 || $module_setting['vis_show_level']==2)){
		list($level_count,$level_list)=$obj_setting->get_ticket_level_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		}
		if(VIS_ITIL==1){
		$location_assets=$obj_setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0 OR FIND_IN_SET(".$macro_details['department'].", ".VIS_TABLE_PREFIX."itil_location.department_access)>0)",0, -1, '', VIS_STAFF_ID);
		}
		$filter_condtn = 'is_enabled=1 and (department_access=0 or find_in_set('.$macro_details['department'].', department_access))';
   $flag_list=$ticket_object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
		
		 $database->database_disconnect();
			
            include(VIS_PATH_TEMPLATE.'macro_new.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGDOMAINNOTFOUND'];
            return false;
        }
	}
	function update_macro($operation) {
        global $vis_language;
        $database = new class_database();
        $data = parse_form_array($operation['vis_action']);
		$data['vis_macro_id'] = $operation['vis_macro_id'];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object = new class_staff($database);
		if(!isset($data['vis_macro_title']) || $data['vis_macro_title']=='' || preg_match("/([<>%\#\/])/", trim($data['vis_macro_title']))) {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
			return false;
		} 
		if(!isset($data['vis_displayorder']) || $data['vis_displayorder']=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDER'].'"); </script>';
            return false;
        } else if(!is_numeric($data['vis_displayorder'])) {
             echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFILDISORDERNUM'].'"); </script>';
             return false;
        }
		if(isset($data['vis_macro_tag']) && $data['vis_macro_tag'] != '') {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$ticket_object = new class_ticket($database);
			$tag_arr = array_unique(explode(",", $data['vis_macro_tag']));
			foreach($tag_arr as $tag) {
				$tag_data['vis_newtag'] = $tag;
				$vis_tags[] = $ticket_object->add_live_tag($tag_data, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			$data['vis_macro_tag'] = count($vis_tags) > 1 ? implode(",", $vis_tags) : $vis_tags[0];
		}
		if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1){
			$data['vis_post_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_post_content']);
		}
		$data['vis_comment'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_comment']);
        $ret = $staff_object->update_macro($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTMACROS'].'",{"vis_module":"home", "vis_operation":"view_macros"});</script>';
        return true;
    }
    function view_tasks($operation){
		global $vis_language;
		if(VIS_MODULE_ACCESS_TASK!=1) 
        {
			echo "<script>$('#vis_right_panel_div').hide();</script>";
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
            return false;  
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $operation['filter_id']= (isset($action[4]))?$action[4]:$operation['vis_filter_id'];
        if(isset($operation['vis_filter_id'])) $action[4]=$operation['vis_filter_id'];
        $database=new class_database();
        $object=new class_staff($database);
        $sett_object=new class_setting($database);
		$filter = VIS_TABLE_PREFIX.'task.autotask_flag!=1 and ';
        if(isset($operation['criteria']) && $operation['criteria']!='')
		{
			$action[4]=13;
			$filter .='task_title like "%'.mysql_real_escape_string($operation['criteria']).'%" and ('.VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID.' OR '.VIS_TABLE_PREFIX.'task_assign.owner_id='.VIS_STAFF_ID.' ) ';
			$criteria = urlencode($operation['criteria']);
        }
        else if($action[4]==1)
        {
		    $filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID.' and ('.VIS_TABLE_PREFIX.'task.task_status=1 or ((enddate-unix_timestamp()) <= 0 and ('.VIS_TABLE_PREFIX.'task.task_status!=3 and '.VIS_TABLE_PREFIX.'task.task_status!=4)) or ((enddate-unix_timestamp()) > 0 and '.VIS_TABLE_PREFIX.'task.task_status=5))';
		}
        else if($action[4]==2)
        {
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID;
		}
		else if($action[4]==3)
		{
			$filter .=VIS_TABLE_PREFIX.'task_assign.owner_id='.VIS_STAFF_ID;
		}
		else if($action[4]==4)
		{
			$filter .='(enddate-unix_timestamp()) > 0 and '.VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.task_status=1';
		}
		else if($action[4]==5)
		{
			$filter .="(enddate-unix_timestamp()) <= 0 and (".VIS_TABLE_PREFIX."task.task_status!=3 and ".VIS_TABLE_PREFIX."task.task_status!=4)  and ".VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID;
		}
		else if($action[4]==6)
		{
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and ' .VIS_TABLE_PREFIX.'task.task_status=3';
		}
		else if($action[4]==7)
		{
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.task_status=4';
		}
		else if($action[4]==8)
		{
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.priority=1';
		}
		else if($action[4]==9)
		{
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.priority=2';
		}
		else if($action[4]==10)
		{
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.priority=3';
		}
		else if($action[4]==11)
		{
			$current_date=Date('m/d/Y');
			$filter .=VIS_TABLE_PREFIX."task.staff_id=".VIS_STAFF_ID. " and ".VIS_TABLE_PREFIX."task.task_status!=4 and startdate LIKE '".$current_date."%'";
		}
		else if($action[4]==12)
		{
			$filter .= 'find_in_set('.VIS_STAFF_ID.','.VIS_TABLE_PREFIX.'task.owner_favourite)';
		}
		else if($action[4]==14)
		{
			$filter .='(enddate-unix_timestamp()) > 0 and '.VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID. ' and '.VIS_TABLE_PREFIX.'task.task_status=5';
		}
		else
        {
			$filter .=VIS_TABLE_PREFIX.'task.staff_id='.VIS_STAFF_ID.' and ('.VIS_TABLE_PREFIX.'task.task_status=1 or ((enddate-unix_timestamp()) <= 0 and ('.VIS_TABLE_PREFIX.'task.task_status!=3 and '.VIS_TABLE_PREFIX.'task.task_status!=4))  or ((enddate-unix_timestamp()) > 0 and '.VIS_TABLE_PREFIX.'task.task_status=5))';
		}
        if(isset($operation['vis_page'])) $page = $operation['vis_page']; else $page=0;
        $module_setting=$sett_object->get_module_setting('module_id=11', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'] = (isset($module_setting['vis_task_list_count']) && $module_setting['vis_task_list_count']!='')?$module_setting['vis_task_list_count']:5;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($task_info, $task_details)=$object->get_task($filter,$action[4],$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
         list($total_task_info, $total_task_details)=$object->get_task($filter,$action[4],'', '',VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($task_info['total']==0)?0:ceil($task_info['total']/$view_info['page_count']);
        $task_info['task_count']=(!$task_details || $task_details==-1)?0:count($task_details);
        $task_info['page']=$page;
        $view_info['view_count']=count($task_details);
        $newly_added_task_details=$object->get_newly_added_task(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $newly_added_task_details=$newly_added_task_details[0];
        $get_task_comment=$object->get_task_comment(VIS_TABLE_PREFIX.'task_comment.task_id='.$newly_added_task_details['task_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!isset($operation['vis_change']))
		include(VIS_PATH_TEMPLATE.'task.php');
		else
		include(VIS_PATH_TEMPLATE.'tasks_list.php');
        return true;
    }
    function view_update_tasks($operation){
		global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		  include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(isset($operation['vis_task_id'])) $action[4]=$operation['vis_task_id'];
        $operation['filter_id']=(isset($data['vis_task_filter_id']) && $data['vis_task_filter_id']!='')?$data['vis_task_filter_id']:$operation['vis_filter_id'];
        $database=new class_database();
        $object=new class_staff($database);
		 $ticket_object=new class_ticket($database);
        $filter=VIS_TABLE_PREFIX.'task_assign.owner_id='.VIS_STAFF_ID;
        $assign_task_details=$object->get_task_assign_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $task_list=' ';
								
								$filter1='';
		if(VIS_ADMIN_ACCESS!=1) $filter1.= ' group_id='.VIS_STAFF_GROUP;
		$get_groups = $object->get_staff_group($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        if($assign_task_details!=-1) for($i=0;$i<count($assign_task_details);$i++){
        $task_list.=$assign_task_details[$i]['task_id'].',';}
        else  $task_list=0;
		$task_list = rtrim(trim($task_list),',');
        $filter=VIS_TABLE_PREFIX."task.staff_id=".VIS_STAFF_ID ." or task_id in (".$task_list.")";
        list($task_info, $task_details)=$object->get_task($filter,'',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($task_details!=-1) for($i=0;$i<count($task_details);$i++){
        $access_task_list[]=$task_details[$i]['task_id'];}
        if(in_array($action[4], $access_task_list) || in_array($operation['vis_task_id'], $access_task_list))
		{
				if(isset($operation['vis_page'])) $page = $operation['vis_page']; else $page=0;
				$view_info['page_count'] = 5;
				$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
				list($task_info, $task_details)=$object->get_task('','',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
				$view_info['page_count']=($task_info['total']==0)?0:ceil($task_info['total']/$view_info['page_count']);
				$task_info['task_count']=(!$task_details || $task_details==-1)?0:count($task_details);
				$task_info['page']=$page;
				$view_info['view_count']=count($task_details);
				$newly_added_task_details=$object->get_newly_added_task(VIS_STAFF_ID, VIS_LOCATION_AREA);
				$newly_added_task_details=$newly_added_task_details[0];
				if(isset($operation['vis_task_id']) && is_numeric($operation['vis_task_id'])) $action[4]=$operation['vis_task_id'];
				if(isset($action[4]) && is_numeric($action[4]))
				$filter=VIS_TABLE_PREFIX.'task_assign.task_id='.$action[4];
				else
				$filter=VIS_TABLE_PREFIX.'task_assign.task_id='.$newly_added_task_details[0]['task_id'];
				$assign_task_details=$object->get_task_assign_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
				for($i=0;$i<count($assign_task_details);$i++)
				{
					$old_staff.=$assign_task_details[$i]['owner_id'].",";
				}
				if(isset($action[4]) && is_numeric($action[4]))
				$newly_added_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.task_id='.$action[4],'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				$newly_added_task_details=$newly_added_task_details[1][0];
				if($newly_added_task_details['parent_id']>0 && $newly_added_task_details['is_repeat']!=1){
					$parent_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.task_id='.$newly_added_task_details['parent_id'],'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
					$parent_task_details=$parent_task_details[1][0];
				}
				else if($newly_added_task_details['parent_id']==0 )
				{
					$child_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.parent_id='.$newly_added_task_details['task_id'].' and ('.VIS_TABLE_PREFIX."task.staff_id=".VIS_STAFF_ID ." or task_id in (".$task_list."))",'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				}
				$get_task_comment=$object->get_task_comment(VIS_TABLE_PREFIX.'task_comment.task_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
				$get_recursive_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.parent_id='.$newly_added_task_details['task_id'].' and '.VIS_TABLE_PREFIX.'task.is_repeat=1 and ('.VIS_TABLE_PREFIX."task.staff_id=".VIS_STAFF_ID ." or task_id in (".$task_list."))",'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				$get_recursive_task_total=$get_recursive_task_details[0]['total'];
				$get_sub_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.parent_id='.$newly_added_task_details['task_id'].' and '.VIS_TABLE_PREFIX.'task.is_repeat=0 and ('.VIS_TABLE_PREFIX."task.staff_id=".VIS_STAFF_ID ." or task_id in (".$task_list."))",'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
				$get_sub_task_total=$get_sub_task_details[0]['total'];
				$end_date=$newly_added_task_details['enddate'];
				$task_schedule=$newly_added_task_details['task_repeat_schedule'];
				$task_occurence=$newly_added_task_details['task_repeat_occurence'];
				$occurance = $object->get_occurence($end_date,$task_schedule,$task_occurence);
				
				// ======== Newly Added Code Starts here =========
				include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
				$ticket=new ticket();
				include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');    
				$ticket_obj=new class_ticket($database);
				$location=array(0=>13, 1=>13, 2=>13);
				$filter12=VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN;                   
				$departments=$ticket_obj->get_department($filter12,VIS_STAFF_ID, VIS_LOCATION_AREA);
				$departmentid = $departments[0]['department_id'];
				$parent_id = $newly_added_task_details['task_id'];
				if($newly_added_task_details['staff_id'] == VIS_STAFF_ID)
				$custom_field_var=$ticket->get_custom_fields($location, 0, $departmentid, $parent_id, $database);
				else
			 $custom_field_var =$ticket->edit_custom_fields($location, $parent_id, $departmentid, $database,1);
				// ======== Newly Added Code Ends Here ===========
				#-- task attached for the tickets starts here --
				//$action[4];
				
				$query1="SELECT parent_id FROM `avis_itil_relation` WHERE child_id=".$action[4]." and attach_type=12 ";
				
				$res1=$database->query_exec($query1);
				
				$task_ticket_ids = $database->fetch_result_array($res1); 
				$task_ticket_count=count($task_ticket_ids);
				
				$ids="";
				for($k=0;$k<count($task_ticket_ids);$k++)
				{
					
					if($k!=($task_ticket_count-1))
					{
						
						 $ids.=	$task_ticket_ids[$k]['parent_id'].",";
					}
					else
					{
						 $ids.=	$task_ticket_ids[$k]['parent_id'];
					}
				 
				}
				
				$task_filter=" avis_ticket.ticket_id in (".$ids.") and draft_id=0 and ".VIS_TABLE_PREFIX."ticket.is_deleted = 0 and ".VIS_TABLE_PREFIX."ticket.is_spam = 0 ";
				
				$total_task_tickets=0;
				
				list($info_task,$task_ticket_data)=$ticket_object->get_ticket($task_filter,'', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
				
				if(isset($info_task['total']) && !empty($info_task['total']))
				{
				$total_task_tickets=$info_task['total'];	
				}
				
				
				#--task attached for the tickets ends here --
				$database->database_disconnect();
				if($newly_added_task_details['staff_id'] == VIS_STAFF_ID)
					include(VIS_PATH_TEMPLATE.'task_update.php');
				else
					include(VIS_PATH_TEMPLATE.'task_view.php');
				return true;
		}
		else
		{
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
            return false;
		}
	}
	function refresh_task_comment_list($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $get_task_comment=$object->get_task_comment(VIS_TABLE_PREFIX.'task_comment.task_id='.$operation['vis_task_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'task_comment_list.php');
        return true;
    }
	function new_task($operation) {
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
		$filter = '';
		if(VIS_ADMIN_ACCESS_LEVEL!=1) $filter.= ' group_id='.VIS_STAFF_GROUP;
		$get_groups = $object->get_staff_group($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		// ======== Newly Added Code Starts here =========
		include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
		$ticket=new ticket();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');    
		$ticket_obj=new class_ticket($database);
		$location[0] = 13;
		$filter=VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN;                   
        $departments=$ticket_obj->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $departmentid = $departments[0]['department_id'];
		$custom_field_var=$ticket->get_custom_fields($location, 0, $departmentid, 0, $database);
		// ======== Newly Added Code Ends Here ===========
		
		if((isset($operation['vis_ticket_id']) && $operation['vis_ticket_id']!='') || (isset($operation['vis_problem_id']) && $operation['vis_problem_id']!='') || (isset($operation['vis_changes_id']) && $operation['vis_changes_id']!='') || (isset($operation['vis_release_id']) && $operation['vis_release_id']!=''))
		include(VIS_PATH_TEMPLATE.'new_task_modal.php');
		else
		include(VIS_PATH_TEMPLATE.'new_task.php');
		
       return true;
	}
     function add_task($operation) {
		$flag ='true';      
		global $vis_language;
 		if(isset($operation['vis_action']) && $operation['vis_action']!='')
			$data=parse_form_array($operation['vis_action']);
        else
        {
			foreach($operation as $key=>$val) {
			  if(!is_array($val))
				$data[$key] = addslashes($val);
			  else
				$data[$key] = $val;
			}
		}
        if($data['vis_task_title']=='' || preg_match("/([<>%\#\/])/", trim($data['vis_task_title']))) {
            echo '<script> $("#add_new_task_button").removeAttr("disabled");  $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        $data['vis_parent_id']=$operation['vis_parent_id'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $tktobject=new class_ticket($database);
								
		if(isset($data['vis_groupname'])){
			$staff_ids = '';
			foreach($data['vis_groupname'] as $team_id){
				$staff_arr = $object->get_staff_setting(' group_id='.$team_id.' and is_enabled = 1',VIS_STAFF_ID, VIS_LOCATION_AREA);
				if($staff_arr!=-1){
					for($m=0;$m<count($staff_arr);$m++){
						$staff_ids .= $staff_arr[$m]['staff_id'].',';
					}
				}
			}
		}else{
			$staff_ids = '';
		}
		if($staff_ids!=''){
			$data['vis_task_grp_share']=$staff_ids.$data['vis_task_grp_share'];
			$task_grp_share=array_unique(explode(',', $data['vis_task_grp_share']));
			$data['vis_task_grp_share']=implode(',',$task_grp_share).',';
		}
		$data['vis_operation']='add_task';
$check_custom = $tktobject->check_custom_data($data,'13', $operation['vis_parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
				 $customerrormessage=' ('.$check_custom[1].')';
				if($check_custom!=1 && $check_custom[0]==0){ $check_custom=false; }
				if($check_custom==false)				
				{
					echo '<script> $("#add_new_task_button").removeAttr("disabled");  $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].''.$customerrormessage.'"); </script>';
					return false;
				}
		  
		if($data['auto_task_flag']==1)
		{		
			if(($data['vis_overdueday']=='' && $data['vis_overduehr']=='' && $data['vis_overduemin']=='') || (!is_numeric($data['vis_overduehr']) && $data['vis_overduehr']!='') || (!is_numeric($data['vis_overduemin']) && $data['vis_overduemin']!='') || (!is_numeric($data['vis_overdueday']) && $data['vis_overdueday']!='') || $data['vis_overduehr']<0 || $data['vis_overduemin']<0 || $data['vis_overdueday']<0) {
				$flag ='false';        
			}
			if(($data['vis_resolutionday']=='' && $data['vis_resolutionhr']=='' && $data['vis_resolutionmin']=='') || (!is_numeric($data['vis_resolutionhr']) && $data['vis_resolutionhr']!='') || (!is_numeric($data['vis_resolutionmin']) && $data['vis_resolutionmin']!='') || (!is_numeric($data['vis_resolutionday']) && $data['vis_resolutionday']!='') || $data['vis_resolutionhr']<0 || $data['vis_resolutionmin']<0 || $data['vis_resolutionday']<0) {
            $flag ='false';   
			}
			if($data['vis_overdueday']!='') $data['vis_duetime']=($data['vis_overduehr']*60)+$data['vis_overduemin']+($data['vis_overdueday']*1440);
			else  $data['vis_duetime']=($data['vis_overduehr']*60)+$data['vis_overduemin'];

			if($data['vis_resolutionday']!='') $data['vis_resolvetime']=($data['vis_resolutionhr']*60)+$data['vis_resolutionmin']+($data['vis_resolutionday']*1440);
			else $data['vis_resolvetime']=($data['vis_resolutionhr']*60)+$data['vis_resolutionmin'];
		}	
		if($flag == 'true')
		{
        $ret=$object->add_task($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
        if(!$ret) {
			if(VIS_LOCATION_AREA==0) {
				echo 'error';
				return false;
			} else {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
				return false;
			}
        }
        else 
		{
			if(VIS_LOCATION_AREA==0) {
				echo 'success';
			} else {
				if(isset($data['vis_parent_id']) && $data['vis_parent_id']!='')
					$activity_log=$sub_object->add_staff_activity_log("Subtask (created) - ".$data['vis_task_title'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
				else
					$activity_log=$sub_object->add_staff_activity_log("New task added - ".$data['vis_task_title'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
				
				if(isset($data['vis_parent_id']) && $data['vis_parent_id']!='') echo '<script>$(".modal").modal("toggle");</script>';
				
				if(isset($data['auto_task_flag']) && $data['auto_task_flag']!='' && $data['page']=='add'){
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#autosub_task_list").visExecution("load_area",{"vis_module":"setting", "vis_operation":"refresh_autosubtask_list"}); $(".modal").modal("toggle");</script>'; 
				}
				elseif(isset($data['auto_task_flag']) && $data['auto_task_flag']!='' && $data['page']=='update' ){
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#autosub_task_list").visExecution("load_area",{"vis_module":"setting", "vis_operation":"refresh_autosubtask_list","vis_autotask_id":"'.$data['autotask_id'].'"}); $(".modal").modal("toggle");</script>'; 
				}
				elseif(isset($data['vis_ticket_id']) && $data['vis_ticket_id']!=''){
					echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");';
					echo "$('#vis_details_list_".$data['vis_ticket_id']."').visExecution('load_operations',{'vis_module':'ticket', 'vis_operation':'get_details', 'vis_action':'details', 'vis_ticket_id':".$data['vis_ticket_id'].",'vis_readonly':1});$('.modal').modal('toggle');</script>";
				}elseif(isset($data['vis_problem_id']) && $data['vis_problem_id']!=''){
					echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");';
					echo "$('#vis_details_list_".$data['vis_problem_id']."').visExecution('load_operations',{'vis_module':'problem', 'vis_operation':'get_details', 'vis_action':'details', 'vis_problem_id':'".$data['vis_problem_id']."' }); set_active_tab('ticket_details');$('.modal').modal('toggle');</script>";
				}elseif(isset($data['vis_changes_id']) && $data['vis_changes_id']!=''){
					echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");';
					echo "$('#vis_details_list_".$data['vis_changes_id']."').visExecution('load_operations',{'vis_module':'changes', 'vis_operation':'get_details', 'vis_action':'details', 'vis_changes_id':'".$data['vis_changes_id']."' }); set_active_tab('ticket_details');$('.modal').modal('toggle');</script>";
				}elseif(isset($data['vis_release_id']) && $data['vis_release_id']!=''){
					echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");';
					echo "$('#vis_details_list_".$data['vis_release_id']."').visExecution('load_operations',{'vis_module':'releases', 'vis_operation':'get_details', 'vis_action':'details', 'vis_release_id':'".$data['vis_release_id']."' }); set_active_tab('release_details');$('.modal').modal('toggle');</script>";
				}
				else{
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'");  $("#vis_workpanel_div").visExecution("load_module","Tasks/1",{"vis_module":"home", "vis_operation":"view_tasks" ,"vis_filter_id":1}); $("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
				}
			}
		}
		$database->database_disconnect();
        return true;
    }
    function update_task($operation) {
        global $vis_language;
        if(isset($operation['vis_filter_id']) && $operation['vis_filter_id']!='') $data['vis_filter_id']=$operation['vis_filter_id'];
        $data=parse_form_array($operation['vis_action']);
        if(isset($data['vis_tasktitle']) && $data['vis_tasktitle']=='' || preg_match("/([<>%\#\/])/", trim($data['vis_tasktitle']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        } 
        if(isset($data['vis_task_status']) && $data['vis_task_status']==1)
		  {
			  if(isset($data['vis_task_staff_id']) && $data['vis_task_staff_id']!=VIS_STAFF_ID)
			  { 
				echo '<script>$("#vis_global_msg_div").visInterface("load_global_message","'.$vis_language['MSGACCSSDND'].'");</script>';  return false;
			  }
		  } 
		  if(isset($data['vis_task_status']) && $data['vis_task_status']==2)
		  {
			  if(isset($data['vis_task_staff_id']) && $data['vis_task_staff_id']!=VIS_STAFF_ID)
			  { 
				 echo '<script>$("#vis_global_msg_div").visInterface("load_global_message","'.$vis_language['MSGACCSSDND'].'");</script>';  return false;
			  }
		  } 

        if(isset($operation['vis_task_id']) && $operation['vis_task_id']!='') $data['vis_task_id']=$operation['vis_task_id'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
								
								if(isset($data['vis_groupname'])){
			$staff_ids = '';
			foreach($data['vis_groupname'] as $team_id){
				$staff_arr = $object->get_staff_setting(' group_id='.$team_id.' and is_enabled = 1',VIS_STAFF_ID, VIS_LOCATION_AREA);
				if($staff_arr!=-1){
						for($m=0;$m<count($staff_arr);$m++){
							$staff_ids .= $staff_arr[$m]['staff_id'].',';
						}
				}
			}
		}else{
			$staff_ids = '';
		}
		if($staff_ids!=''){
		$data['vis_task_grp_share']=$staff_ids.$data['vis_task_grp_share'];
		$task_grp_share=array_unique(explode(',', $data['vis_task_grp_share']));
		$data['vis_task_grp_share']=implode(',',$task_grp_share).',';
		}
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $tktobject=new class_ticket($database);
		$check_custom = $tktobject->check_custom_data($data,'13', $operation['vis_parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
				 $customerrormessage=' ('.$check_custom[1].')';
				if($check_custom!=1 && $check_custom[0]==0){ $check_custom=false; }
				if($check_custom==false)				
				{
					echo '<script> $("#add_new_task_button").removeAttr("disabled");  $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].''.$customerrormessage.'"); </script>';
					return false;
				}
		
        $ret=$object->update_task($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($ret) {
			$data['vis_operation']='update_task';
            global $operation_hnd;
            $data['vis_task_grp_share']=substr($data['vis_task_grp_share'], 0, -1);
			$staff=explode(',', $data['vis_task_grp_share']);
			$data['vis_old_staff']=substr($data['vis_old_staff'], 0, -1);
			$old_staff=explode(',', $data['vis_old_staff']);
			$data['vis_task_grp_share']=array_merge(array_diff($staff, $old_staff), array_diff($old_staff, $staff));
			$data['vis_task_grp_share']=implode(',', $data['vis_task_grp_share']);
            $operation_hnd->check_automation($data, $database);
        }
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			if(isset($data['vis_parent_id']) && $data['vis_parent_id']>0)
			$activity_log=$sub_object->add_staff_activity_log("Subtask (updated) - ".$data['vis_tasktitle'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			else
			$activity_log=$sub_object->add_staff_activity_log("Task updated - ".$data['vis_tasktitle'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTTASKS'].'/'.$data['vis_filter_id'].'", {"vis_module":"home", "vis_operation":"view_tasks"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		}
		$database->database_disconnect();
        return true;
    }
	function get_macro_ticket_properties($operation) {
		global $vis_language;
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object = new class_ticket($database);
		$filter_condtn = ($operation['vis_dept_id'] == 0) ? 'is_enabled=1' : 'is_enabled=1 and (department_access=0 or find_in_set('.$operation['vis_dept_id'].', department_access))';
		$type_list = $ticket_object->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
		$status_list = $ticket_object->get_status_list($filter_condtn, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$priority_list = $ticket_object->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff_object = new class_staff($database);
		$staff_list = $staff_object->get_staff('is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA, (($operation['vis_dept_id'] == 0) ? '' : $operation['vis_dept_id']));
        $labels_list = $ticket_object->get_labels_list($filter_condtn, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
	
		$domain=$ticket_object->get_department(VIS_TABLE_PREFIX.'department.department_id='.$operation['vis_dept_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$module_setting=$obj_setting->get_module_setting('domain_id='.$domain[0]['domain_id'].' and module_id=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$filter_condtn = ($operation['vis_dept_id'] == 0) ? 'is_enabled=1 and department_access=0' : 'is_enabled=1 and (department_access=0 or find_in_set('.$operation['vis_dept_id'].', department_access))';
		
		if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
		list($cat_count,$category_list)=$obj_setting->get_ticket_category_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		}//check access
		if(isset($module_setting['vis_show_level']) && ($module_setting['vis_show_level']==1 || $module_setting['vis_show_level']==2)){
		list($level_count,$level_list)=$obj_setting->get_ticket_level_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		}//check access
		if(VIS_ITIL==1){
		$location_assets=$obj_setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0 OR FIND_IN_SET(".$operation['vis_dept_id'].", ".VIS_TABLE_PREFIX."itil_location.department_access)>0)",0, -1, '', VIS_STAFF_ID);
}

$filter_condtn = 'is_enabled=1 and (department_access=0 or find_in_set('.$operation['vis_dept_id'].', department_access))';
   $flag_list=$ticket_object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter_condtn);
		
		include_once(VIS_PATH_TEMPLATE.'macro_ticket_properties.php');
		return true;
	}
	function show_macro_details($operation) { // display macro details on clicking 'View' link
		global $vis_language;
		$database = new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff_object = new class_staff($database);
		$filter = 'macro_id = '.$operation['vis_macro_id'];
		$macro_details = $staff_object->get_macros_list('macro_id = '.$operation['vis_macro_id'], VIS_STAFF_ID, VIS_LOCATION_AREA,'','',1);
		$macro_details = $macro_details[0];
		$details_txt = '<div class=\'form-group m-b-n\'><div class=\'col-sm-12 txt_nowrap\'><label>'.$vis_language['TXTTITLE'].'</label><span class="text-muted m-l-sm">'.$macro_details['macro_title'].'</span></div></div>';
		$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12\'><label>'.$vis_language['TXTDEPARTMENT'].'</label><span class=\'text-muted m-l-sm\'>'.$macro_details['department'].'</span></div></div>';
		$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12\'><label>'.$vis_language['TXTSTATUS'].'</label><span class="text-muted m-l-sm">'.$macro_details['status'].'</span></div></div>';
		$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12\'><label>'.$vis_language['TXTPRIORITY'].'</label><span class="text-muted m-l-sm">'.$macro_details['priority'].'</span></div></div>';
		$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12\'><label>'.$vis_language['TXTTYPE'].'</label><span class=\'text-muted m-l-sm\'>'.$macro_details['type'].'</span></div></div>';
		if($macro_details['owner_list'] != '' && strpos($macro_details['owner_list'], ",")) {
			$owner_arr = explode(",", $macro_details['owner_list']);
			$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12 txt_nowrap\'><label>'.$vis_language['TXTOWNER'].'</label>';
			foreach($owner_arr as $owner) {
				$details_txt .= '<span class=\'btn btn-xs alert-danger m-l-sm\'>'.$owner.'</span>';
			}
			$details_txt .= '</div></div>';
		} else if($macro_details['owner_list'] != '' && !strpos($macro_details['owner_list'], ",")) {
			$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12 txt_nowrap\'><label>'.$vis_language['TXTOWNER'].'</label>';
			$details_txt .= '<span class=\'btn btn-xs alert-danger m-l-sm\'>'.$macro_details['owner_list'].'</span>';
			$details_txt .= '</div></div>';
		}
		if($macro_details['label_list'] != '' && strpos($macro_details['label_list'], ",")) {
			$label_arr = explode(",", $macro_details['label_list']);
			$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12 txt_nowrap\'><label>'.$vis_language['TXTLABELS'].'</label>';
			foreach($label_arr as $label) {
				$label_arr2 = explode(":", $label);
				$details_txt .= '<span class=\'btn btn-xs l-h-1x text-xs m-l-sm\' style=\'background-color: '.$label_arr2[1].'; color: #fff;\'>'.$label_arr2[0].'</span>';
			}
			$details_txt .= '</div></div>';
		}
		if($macro_details['tag_list'] != '' && strpos($macro_details['tag_list'], ",")) {
			$tag_arr = explode(",", $macro_details['tag_list']);
			$details_txt .= '<div class=\'form-group m-b-n\'><div class=\'col-sm-12 txt_nowrap\'><label>'.$vis_language['TXTTAGS'].'</label>';
			foreach($tag_arr as $tag) {
				$details_txt .= '<span class=\'btn btn-xs alert-success m-l-sm\'>'.$tag.'</span>';
			}
			$details_txt .= '</div></div>';
		}
		echo $details_txt;
	}
	function apply_macro($operation) {		//print_r($operation);
		global $vis_language;
		$database = new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff_object = new class_staff($database);
		$macro_details = $staff_object->get_macro_list('macro_id = '.$operation['vis_macro_id']);
		//$macro_details = $staff_object->get_macros_list('macro_id = '.$operation['vis_macro_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		$macro_details = $macro_details[0];
		$res = ''; // apply macro on ticket
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		$ticket_object = new class_ticket($database);
        if($macro_details['department']==0){
            $filter_condtn = ($operation['vis_department_id'] == 0) ? 'is_enabled=1' : 'is_enabled=1 and (department_access=0 or find_in_set('.$operation['vis_department_id'].', department_access))';
            $labelslist = $ticket_object->get_labels_list($filter_condtn, VIS_STAFF_ID, VIS_LOCATION_AREA);
            for($i=0;$i<count($labelslist);$i++) $labels_list[$i]=$labelslist[$i]['label_id'];
            $temp_labels=explode(',',$macro_details['labels']);
            $count=count($temp_labels);
            for($i=0;$i<$count;$i++) if(!in_array($temp_labels[$i],$labels_list)) unset($temp_labels[$i]);
            $macro_details['labels']=implode(',',$temp_labels);
        }
		if($macro_details['owner'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // no change macro property for owner in reply/forward operation
			$owner_details = $ticket_object->get_ticket_owner('ticket_id = '.$operation['vis_ticket_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($owner_details != -1) {
				$res .= '$("[class^=\'staff_\']").prop("checked", false); $("#vis_owner_list").val(""); $("#owners_list").html(""); $("#multipleownerlist").hide();';
				foreach ($owner_details as $owner) {
					$res .= 'assign_owner('.$owner['staff_id'].', 1);';
				}
			}
		} elseif($macro_details['owner'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) { // no change macro property for owner in new ticket operation
			$res .= '$("[class^=\'staff_\']").prop("checked", false); $("#vis_owner_list").val(""); $("#owners_list").html(""); $("#multipleownerlist").hide();';
			$res .= 'assign_owner('.$macro_details['owner'].', 1);';
		} elseif($macro_details['owner'] != '' && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] >= 0 && !strpos($macro_details['owner'], ',')) { // single owner
			$res .= 'assign_owner('.$macro_details['owner'].');';
		} else if(strpos($macro_details['owner'], ',') > 0) {	// multiple owners
			$owner_details = explode(",", $macro_details['owner']);
			foreach ($owner_details as $owner) { $res .= 'assign_owner('.$owner.');'; }
		}
		if(($macro_details['status'] == 0 || $macro_details['priority'] == 0) && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // get status_id, priority_id of ticket for no change macro
			$conditions = array('priority_id');
			$ticket_details = $ticket_object->get_ticket('ticket_id = '.$operation["vis_ticket_id"], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA, '', $conditions);
			$ticket_details = $ticket_details[1][0];//print_r($ticket_details);
		}
		if($macro_details['department'] > 0) { // status: no change macro on new ticket or apply status set in macro
			$res .= '$("#vis_department").val('.$macro_details['department'].');';
		}
		$res .= '$("#vis_department").selectpicker("refresh");';
		
		if(($macro_details['status'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['status'] > 0)) { // status: no change macro on new ticket or apply status set in macro
			$res .= '$("#vis_status").val('.$macro_details['status'].');';
		} elseif ($macro_details['status'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // status: no change macro on existing ticket
			$res .= '$("#vis_status").val('.$ticket_details['status_id'].');';
		}
		$res .= '$("#vis_status").selectpicker("refresh");';
		if(($macro_details['priority'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['priority'] > 0)) { // priority: no change macro on new ticket or apply status set in macro
			$res .= '$("#vis_priority").val('.$macro_details['priority'].');';
		}elseif ($macro_details['priority'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // status: no change macro on existing ticket
			$res .= '$("#vis_priority").val('.$ticket_details['priority_id'].');';
		}
		$res .= '$("#vis_priority").selectpicker("refresh");';
		if(($macro_details['type'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['type'] > 0)) { // type: no change macro on new ticket or apply status set in macro
			$res .= '$("#vis_type").val('.$macro_details['type'].');';
		}elseif ($macro_details['type'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // type: no change macro on existing ticket
			$res .= '$("#vis_type").val('.$ticket_details['type_id'].');';
		}
		$res .= '$("#vis_type").selectpicker("refresh");';
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
		
		list($domain_info, $domain_details)=$obj_setting->get_domain("department_id=".$operation['vis_department_id'], '', $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$module_setting=$obj_setting->get_module_setting('domain_id='.$domain_details[0]['domain_id'].' and module_id=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filter = 'is_enabled=1 and (department_access=0 or find_in_set('.$operation['department_id'].', department_access))';
							
		if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
			if(($macro_details['category_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['category_id'] > 0)) { 
				$res .= '$("#vis_category").val('.$macro_details['category_id'].');';
				$category_id=$macro_details['category_id'];
			} elseif ($macro_details['category_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // status: no change macro on existing ticket
				$res .= '$("#vis_category").val('.$ticket_details['category_id'].');';
				$category_id=$ticket_details['category_id'];
			}
			$res .= '$("#vis_category").selectpicker("refresh");';
			
			if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
				if(($macro_details['subcategory_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['subcategory_id'] > 0)) { 
					$subcategory_id=$macro_details['subcategory_id'];
				} elseif ($macro_details['subcategory_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { 
					$subcategory_id=$ticket_details['subcategory_id'];
				}
						
				list($cat_count,$subcategory_list)=$obj_setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_subcategory.category_id='.$category_id,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
				$subcatdrp='<option value="0">'.$vis_language['TXTSELECT'].'</option>';
				
				if(isset($subcategory_list)){
					foreach($subcategory_list as $subcatlist){
						$selected=($subcatlist['subcategory_id']==$subcategory_id)?'selected="selected"':'';
						$subcatdrp .='<option '.$selected.' value="'.$subcatlist['subcategory_id'].'">'.$subcatlist['title'].'</option>';
					}
					
				}
				
				$res .= '$("#vis_subcategory").html("'.addslashes($subcatdrp).'");';
				$res .= '$("#vis_subcategory").selectpicker("refresh");';
					
				if(isset($module_setting['vis_show_category']) && ($module_setting['vis_show_category']==1 || $module_setting['vis_show_category']==2)){
					if(($macro_details['item_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['item_id'] > 0)) { 
						$item_id=$macro_details['item_id'];
					} elseif ($macro_details['item_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { 
						$item_id=$ticket_details['item_id'];
						$res .= '$("#vis_item").val('.$ticket_details['item_id'].');';
					}
					
					list($item_count,$item_list)=$obj_setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_item.subcategory_id='.$subcategory_id,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
									
					$itemdrp='<option value="0">'.$vis_language['TXTSELECT'].'</option>';
					
					if(isset($item_list)){
						foreach($item_list as $itemlist){
							$selected=($itemlist['item_id']==$item_id)?'selected="selected"':'';
							$itemdrp .='<option '.$selected.' value="'.$itemlist['item_id'].'">'.$itemlist['title'].'</option>';
						}
						
					}
					$res .= '$("#vis_item").html("'.addslashes($itemdrp).'");';
					$res .= '$("#vis_item").selectpicker("refresh");';
				}
			}
		}
		
		if(isset($module_setting['vis_show_level']) || $module_setting['vis_show_level']==1 || $module_setting['vis_show_level']==2){		
			if(($macro_details['level_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['level_id'] > 0)) { 
				$res .= '$("#vis_ticket_level").val('.$macro_details['level_id'].');';
			} elseif ($macro_details['vis_ticket_level'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // status: no change macro on existing ticket
				$res .= '$("#vis_ticket_level").val('.$ticket_details['level_id'].');';
			}
			$res .= '$("#vis_ticket_level").selectpicker("refresh");';
		}
		
		if(VIS_ITIL==1){
			if(($macro_details['location_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['location_id'] > 0)) { 
				$res .= '$("#vis_assets_location").val('.$macro_details['location_id'].');';
			} elseif ($macro_details['location_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { // status: no change macro on existing ticket
				$res .= '$("#vis_assets_location").val('.$ticket_details['location_id'].');';
			}
			$res .= '$("#vis_assets_location").selectpicker("refresh");';
		}
		
		if(($macro_details['flag_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) || ($macro_details['flag_id'] > 0)) { 
					$res .= '$("#vis_flag_id").val('.$macro_details['flag_id'].');';
					} elseif ($macro_details['flag_id'] == 0 && isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) { 
						$res .= '$("#vis_flag_id").val('.$ticket_details['flag_id'].');';
					}
					
		if(isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] == 0) {
			$res .= '$("#vis_type").val('.$macro_details['type'].');$("#vis_type").selectpicker("refresh");';
		}
		if($macro_details['comment'] != '') {
			$res .= '$("#vis_comment").val("'.$macro_details['comment'].'\n"+$("#vis_comment").val()); $("#vis_add_comment").show();';
		} else {
			$res .= '$("#vis_comment").val();';
		}
		$vis_ticket_id = (isset($operation['vis_ticket_id']) && $operation['vis_ticket_id'] > 0) ? $operation['vis_ticket_id'] : 0;
		if($macro_details['post_content'] != '') {
			$macro_details['post_content']= mysql_real_escape_string($macro_details['post_content']);
			$macro_details['post_content'] = str_replace(array("\r\n"),"<br>",$macro_details['post_content']);
			$macro_details['post_content'] = str_replace(array("\r","\n"),"",$macro_details['post_content']);
			$macro_details['post_content'] = str_replace(array("\\r\\n"),"",$macro_details['post_content']);
			//$macro_details['post_content'] = str_replace(array("\r\n","\r","\n","\\r\\n"),"<br>",$macro_details['post_content']);
			$macro_details['post_content'] = str_replace('\"','"',$macro_details['post_content']);
			$macro_details['post_content'] = addslashes($macro_details['post_content']);
			function deslash($content) {
			  // Note: \\\ inside a regex denotes a single backslash.

			  /*
				 * Replace one or more backslashes followed by a single quote with
				 * a single quote.
				 */
			  $content = preg_replace("/\\\+'/", "'", $content);

			  /*
				 * Replace one or more backslashes followed by a double quote with
				 * a double quote.
				 */
			  //$content = preg_replace('/\\\+"/', '"', $content);

			  // Replace one or more backslashes with one backslash.
			  //$content = preg_replace("/\\\+/", "\\", $content);

			  return $content;
			}
			$macro_details['post_content'] = deslash($macro_details['post_content']);
			if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) {
				$res .= '$("#vis_ticket_post_'.$vis_ticket_id.'").redactor("code.set", "'.$macro_details['post_content'].'<br>"+$("#vis_ticket_post_'.$vis_ticket_id.'").redactor("code.get"));';
			}else{
				$res .= '$("#vis_ticket_post_'.$vis_ticket_id.'").val("'.$macro_details['post_content'].'\n"+$("#vis_ticket_post_'.$vis_ticket_id.'").val());';
				
			}
		}
		$tags = ($macro_details['tags'] != '') ? $macro_details['tags'] : "";
		$res .= '$("#vis_tag_list").val("'.$tags.'");';
		$labels = ($macro_details['labels'] != '') ? $macro_details['labels'] : "";
		$res .= '$("#vis_label_list").val("'.$labels.'");';
		$res .= '$("#vis_ticket_post_'.$vis_ticket_id.'").val($("#vis_ticket_post_'.$vis_ticket_id.'").val().replace(/<br>/gi, "\n"));';
		$res .= '$("#vis_comment").val($("#vis_comment").val().replace(/<br>/gi, "\n"));';
		$res .= '$("#vis_apply_macros").val("1");';
		$res .= '$("#vis_macro_sla_id").val("'.$macro_details['sla'].'");';
		echo '<script>'.$res.'</script>';
	}
	 function add_task_comment($operation) {
        global $vis_language;
        if(isset($operation['vis_action']) && $operation['vis_action']!='') $data=parse_form_array($operation['vis_action']);
        else $data=$operation;
        if(!isset($data['vis_task_comment']) || trim($data['vis_task_comment']=='')) {
            if(VIS_LOCATION_AREA==2)
            {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); </script>';
				return false;
			}
        }
        else $data['vis_task_comment']=nl2br($data['vis_task_comment']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->add_task_comment($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($ret) {
			$data['vis_operation']='add_task_comment';
            global $operation_hnd;
            $operation_hnd->check_automation($data, $database);
        }
        if(VIS_LOCATION_AREA==2) {
            if(!$ret) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
            else
            {
				$activity_log=$sub_object->add_staff_activity_log("Added task comment", VIS_STAFF_ID,10,VIS_LOCATION_AREA);
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");  $("#vis_comment_list").visExecution("load_area", {"vis_module":"home", "vis_operation":"refresh_task_comment_list", "vis_task_id":'.$data['vis_task_id'].'});</script>';
				//return true;
			}
        }
        $database->database_disconnect();

    }
    function confirm_delete_task_comment($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELCOMMENT'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$(this).visExecution('load_operations', {'vis_module':'home', 'vis_operation':'delete_task_comment', 'vis_comment_id':".$operation['vis_comment_id'].", 'vis_task_id':".$operation['vis_task_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function delete_task_comment($operation) {
        global $vis_language;
        $database = new class_database();
        global $operation_hnd;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $newly_added_task_details=$object->get_task(VIS_TABLE_PREFIX.'task.task_id='.$operation['vis_task_id'],'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
		$newly_added_task_details=$newly_added_task_details[1][0];
		$comment_details=$object->get_task_comment(VIS_TABLE_PREFIX.'task_comment.comment_id='.$operation['vis_comment_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($newly_added_task_details['staff_id']==VIS_STAFF_ID || $comment_details[0]['owner']==VIS_STAFF_ID)
        {
			$result=$object->delete_task_comment($operation['vis_comment_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($result==0)
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'");$(".modal").modal("toggle");</script>';
			else {
				$activity_log=$sub_object->add_staff_activity_log("Deleted task comment", VIS_STAFF_ID,10,VIS_LOCATION_AREA);
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_comment_list").visExecution("load_area", {"vis_module":"home", "vis_operation":"refresh_task_comment_list", "vis_task_id":'.$operation['vis_task_id'].'});</script>';
			}
			return $result;
		}
		else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
        $database->database_disconnect();
        return false;
    }
     function set_task_status_toclose($operation) {
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->set_task_status_toclose($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			$activity_log=$sub_object->add_staff_activity_log("Updated task status to close", VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script>$("#vis_workpanel_div").visExecution("load_area", {"vis_module":"home", "vis_operation":"view_update_tasks" ,"vis_task_id":"'.$operation['vis_task_id'].'"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		}
		$database->database_disconnect();
        return true;

	 }
	  function set_task_status_tocompleted($operation) {
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->set_task_status_tocompleted($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else { 
			$activity_log=$sub_object->add_staff_activity_log("Updated task status to complete", VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script> $("#vis_workpanel_div").visExecution("load_area", {"vis_module":"home", "vis_operation":"view_update_tasks" ,"vis_task_id":"'.$operation['vis_task_id'].'"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		}
		$database->database_disconnect();
        return true;

	 }
	  function get_delete_task($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETETASK'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'task_delete', 'vis_task_id':".$operation['vis_task_id'].",'vis_filter_id':".$operation['vis_filter_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function task_delete($operation) {
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
         list($task_info, $task_details)=$object->get_task('task_id='.$operation['vis_task_id'],'',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ret=$object->task_delete($operation, VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else { 
			$activity_log=$sub_object->add_staff_activity_log("Deleted task - ".$task_details[0]['task_title'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTTASKS'].'/'.$operation['vis_filter_id'].'", {"vis_module":"home", "vis_operation":"view_tasks"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		}
        $database->database_disconnect();
        return true;

	}

	function domain_array($from, $to){
		if(is_array($from)){
			for($i=0;$i<count($from);$i++){
				if(!in_array($from[$i]['domain_id'], $to) && $from[$i]['domain_id']!=0)
					array_push($to, $from[$i]['domain_id']);
			}
		}
		return $to;
	}

	function integration($operation){
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		if(!isset($operation["vis_domain"]))$operation["vis_domain"]='none';

		list($vis_all_domain_gotomeeting, $gotomeeting_details)=$object->integation_app_availability('23', $operation["vis_domain"]);
		list($vis_all_domain_gotoassist, $gotoassist_details)=$object->integation_app_availability('24', $operation["vis_domain"]);
		list($vis_all_domain_teamviewer, $teamviewer_details)=$object->integation_app_availability('25', $operation["vis_domain"]);
		list($vis_all_domain_webex, $webex_details)=$object->integation_app_availability('26', $operation["vis_domain"]);
		//list($vis_all_domain_twilio, $twilio_details)=$object->integation_app_availability('27', $operation["vis_domain"]);
        list($vis_all_domain_livezilla, $livezilla_details)=$object->integation_app_availability('20', $operation["vis_domain"]);

		if($operation['vis_domain']!='none'){
			include(VIS_PATH_TEMPLATE.'profile_integration_app.php');
		}else{
			$domain_array=array();
			$domain_array= $this->domain_array($gotomeeting_details, $domain_array);
			$domain_array= $this->domain_array($gotoassist_details, $domain_array);
			$domain_array= $this->domain_array($teamviewer_details, $domain_array);
			$domain_array= $this->domain_array($webex_details, $domain_array);
			$domain_array= $this->domain_array($livezilla_details, $domain_array);
			//$domain_array= $this->domain_array($twilio_details, $domain_array);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			include(VIS_PATH_TEMPLATE.'profile_integration.php');
		}
        return true;
	}
	function integration_app_setting($operation){
		if($operation['vis_domain']=='all'){
			$operation['vis_domain']='0';
		}
		$filter=' domain_id='.$operation['vis_domain'].' and remoteapp_type='.$operation['vis_app'];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $remotescreen_details=$object->get_remotescreen_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'profile_integration_details.php');
		return true;
	}

	function update_remotescreen_setting($operation){
		global $vis_language;
		if(isset($operation['vis_action'])) $data=parse_form_array($operation['vis_action']);
        else $data=$operation;
        $data['domain_id'] = ($data['vis_sign_all_domain']==1) ? 0 : $data['vis_domain'];
        $data['remoteapp_type']=$data['vis_app'];

        if($data['vis_app']==23){
			if(trim($data['vis_meeting_email'])=='' || trim($data['vis_meeting_password'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
				list($message, $flag) = check_email_validation($data['vis_meeting_email']);
				if(!$flag) {
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGEMAILMISS'].'"); </script>';
				  $flag=false;
				} 
				$data['user_name']=$data['vis_meeting_email'];
				$data['user_password'] =$data['vis_meeting_password'];
			}
		}

		if($data['vis_app']==24){
			if(trim($data['vis_assist_email'])=='' || trim($data['vis_assist_password'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
					list($message, $flag) = check_email_validation($data['vis_assist_email']);
				if(!$flag) {
					 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGEMAILMISS'].'"); </script>';
                   $flag=false;
				}
				$data['user_name']=$data['vis_assist_email'];
				$data['user_password'] =$data['vis_assist_password'];
			}
		}
		if($data['vis_app']==25){
			if(trim($data['vis_temaviewer_id'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
				$data['client_id']=$data['vis_temaviewer_id'];
			}
		}

		if($data['vis_app']==26){
			if(trim($data['vis_webex_user'])=='' || trim($data['vis_webex_password'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
				$data['user_name']=$data['vis_webex_user'];
				$data['user_password'] =$data['vis_webex_password'];
			}
		}
		
		if($data['vis_app']==20){
			if(trim($data['vis_livezilla_user'])=='' || trim($data['vis_livezilla_password'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
				$data['user_name']=$data['vis_livezilla_user'];
				$data['user_password'] =$data['vis_livezilla_password'];
			}
		}
		/*if($data['vis_app']==27){
			if(trim($data['vis_twilio_asid'])=='' || trim($data['vis_twilio_atoken'])=='' || trim($data['vis_twilio_appsid'])=='') {
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'");  </script>';
				return false;
			}
			else{
				$data['user_name']=$data['vis_twilio_asid'];
				$data['user_password'] =$data['vis_twilio_atoken'];
				$data['client_id'] =$data['vis_twilio_appsid'];
			}
		}*/

		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object=new class_staff($database);
        if($data['domain_id']!=0){ $ret=$staff_object->delete_remotescreen_setting($data['remoteapp_type'], VIS_STAFF_ID, VIS_LOCATION_AREA);}

        if($data['vis_remotescreen_id']!=''){
			$filter=" remoteapp_id=".$data['vis_remotescreen_id'];
			$ret=$staff_object->update_remotescreen_setting($filter, $data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		else {
			$ret=$staff_object->add_remotescreen_setting($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		if($ret){
			if(isset($data['vis_sign_all_domain'])&& $data['vis_sign_all_domain']==1){
				$qry = "DELETE FROM `".VIS_TABLE_PREFIX."remotescreen` WHERE  `domain_id` <> 0 AND `remoteapp_type` = ".$data['vis_app']." AND `staff_id` = ".VIS_STAFF_ID;
				 $result=$database->query_exec($qry);
			}else{
				$qry = "DELETE FROM `".VIS_TABLE_PREFIX."remotescreen` WHERE  `domain_id` = 0 AND `remoteapp_type` = ".$data['vis_app']." AND `staff_id` = ".VIS_STAFF_ID;
			     $result=$database->query_exec($qry);
			} 
		}

		$database->database_disconnect();
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else  echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_app_area").visExecution("load_area", {"vis_module":"staff", "vis_operation":"integration","vis_domain":'.$data['domain_id'].'});</script>';
		return true;

	}
	function set_task_asfavourites($operation) {
		global $vis_language;
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->set_task_asfavourites($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
         if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else  echo '<script>$("#vis_workpanel_div").visExecution("load_area", {"vis_module":"home", "vis_operation":"view_tasks" ,"vis_filter_id":"'.$operation['vis_filter_id'].'"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		return true;
	 }
     function reset_password($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $spliter=(strstr($_SERVER['QUERY_STRING'], '/'))?'/':',';
        $action=explode($spliter, $_SERVER['QUERY_STRING']);
        $filter=VIS_TABLE_PREFIX.'settings.title="vis_security_password"';
		$security_password_details=$object->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($security_password_details==-1) $security_password_limit=50; else $security_password_limit=$security_password_details[0]['content'];
        $database->database_disconnect();
        if(isset($action[3]) && $action[3]!='') {
            $staff_email=base64_decode($action[3]);
            $passwd_auth=$action[4];
        }else{
            $staff_email=$operation['vis_email'];
            $passwd_auth=$operation['vis_passwd_auth'];
        }
        $header_title=$vis_language['TXTRESETPASSWORD'];
        include(VIS_PATH_TEMPLATE.'header.php');
        include(VIS_PATH_TEMPLATE.'staff_reset_password.php');
        include(VIS_PATH_TEMPLATE.'footer.php');
        return true;
    }
    
    function set_forgetpassword($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$filter=VIS_TABLE_PREFIX.'settings.title="vis_security_password"';
		$security_password_details=$object->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($operation['password_strength_per']<$security_password_details[0]['content']) {
            $operation['message']=$vis_language['TXTPASSWORDNOTALLOWED'];
            return $this->reset_password($operation);
        }
        if($operation['vis_newpassword']!=$operation['vis_confirm']) {
            $operation['message']=$vis_language['MSGPASSMISSMTCH'];
            return $this->reset_password($operation);
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staffobject=new class_staff($database);
        $filter=' email="'.$operation['vis_email'].'" and password_auth='.convert_uudecode (base64_decode($operation['vis_passwd_auth']));
        $staffs=$staffobject->get_staff($filter, '', '', '', VIS_CLIENT_ID, VIS_LOCATION_AREA);        
        if($staffs==-1 || $staffs==''){
            $operation['message']=$vis_language['MSGRESETPASSWORDLINKEXPIRED'];
            return $this->reset_password($operation);
        }else{
            $res=$staffobject->set_forgetpassword($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            if($res){
                $_SESSION['successmessage']=$vis_language['MSGSUCCOPRT'];
            }
            header('Location: index.php');
        }
    }
    function send_resetassword_link($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $fpass=$object->forgot_password($operation['vis_useremail'], VIS_LOCATION_AREA);
        $database->database_disconnect();
        echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "<div class=\"alert-success\">'.$vis_language['MSGEMAILSENTTORESETPASSWORD'].'</div>"); </script>';
    }
    function load_more_profile_recent_activities($operation) {
		$database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object = new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object = new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $settingobject=new class_setting($database);
        $page = (isset($operation['vis_page']) && is_numeric($operation['vis_page'])) ? $operation['vis_page'] : 0;
        $recentActivities = $object->get_recent_activities(VIS_STAFF_ID,VIS_STAFF_ID,$page);
        $All_Activities = $object->get_recent_activities(VIS_STAFF_ID,VIS_STAFF_ID,'',1);
        $total_Activities = $All_Activities['count']; 
        $total_pages = ceil($total_Activities/10);
        $load_more_activities = ($total_pages > $page+1) ? $page : '';
        
        if($recentActivities != -1){
        for($i=0;$i<count($recentActivities);$i++){
		$ticket_details=$ticket_object->get_ticket('ticket_id='.$recentActivities[$i]['ticket_id'],'', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA, '', $conditions='');
		 if( $ticket_details[1] == -1)  $recentActivities[$i]['actionLinks'] = '';
		 else $recentActivities[$i]['actionLinks'] = 1;
            if($recentActivities[$i]['operation_id']==7){
                if($recentActivities[$i]['old_info']=='' || $recentActivities[$i]['old_info']==0) $staffid=$recentActivities[$i]['new_info'];
                else  $staffid=$recentActivities[$i]['old_info'];
                if($staffid!=0){
                    $staff_info=$settingobject->get_staff(VIS_TABLE_PREFIX.'staff.staff_id='.$staffid, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
                    $recentActivities[$i]['user_info'] =  $staff_info[1][0]['first_name'].' '.$staff_info[1][0]['last_name'];
                }
            }
        }
        }
        $database->database_disconnect();
		if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'load_more_staff_recent_activity.php');
		
	}

    function load_user_menu($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $staff=$object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'staff_menu.php');
        return true;
    }

	function get_change_setting_status($operation) { // activity log delete action
        global $vis_language;
        $operation['vis_action'] = str_replace(",","&", $operation['vis_action']);
		$message_info['vis_form_title']=$vis_language['TXTALERTMESSAGE'];
		$message_info['vis_message']=($operation['vis_switch']='organization')?$vis_language['MSGCHANGESTATUSMESSAGEFORORANIZATION']:$vis_language['MSGCHANGESTATUSMESSAGE'];
		$message_info['vis_event']="$('#vis_global_msg_div').visExecution('submit_form', {'vis_module':'home', 'vis_operation':'change_setting_status', 'vis_form':'".$operation['vis_form']."','vis_current_operation':'".$operation['vis_current_operation']."','vis_current_module':'".$operation['vis_current_module']."','vis_switch':'".$operation['vis_switch']."','vis_is_enable':'".$operation['vis_is_enable']."','vis_page':'".$operation['vis_page']."', 'vis_action':'".$operation['vis_action']."'})";
        include(VIS_PATH_TEMPLATE.'confirm_change_status.php');
        return true;
    }
	function change_setting_status($operation){
        $list_chk=array();
        global $vis_language;
        if(isset($operation['vis_ticket_id']) && is_numeric($operation['vis_ticket_id'])) {
            $property=$operation['vis_action'];
            $list_chk[]=$operation['vis_ticket_id'];
        }
        else {
            $options=parse_form_array($operation['vis_action']);
            $property=$options['action'];
            foreach($options as $data=>$value) if(preg_match('/vis_global_mass_chk_[0-9]/', $data)) $list_chk[]=$value;
        }
        $database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->change_setting_status($operation['vis_switch'], $operation['vis_is_enable'], $list_chk, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else
        {
			if(isset($operation['vis_form']) && $operation['vis_form']=='vis_filter_form')
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#global_menu").visExecution("load_area", {"vis_module":"home", "vis_operation":"load_global_menu"}); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'","vis_page":"'.$vis_page.'"}); </script>';
			else
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'","vis_page":"'.$vis_page.'"}); </script>';
		}
        return $ret;
    }
    function add_subtask($operation) {
		global $vis_language;
		include(VIS_PATH_TEMPLATE.'subtask.php');
        return true;
	}
	function confirm_detach_subtask($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDETACH'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$(this).visExecution('load_operations', {'vis_module':'home', 'vis_operation':'detach_subtask', 'vis_task_id':'".$operation['vis_task_id']."','vis_parent_id':'".$operation['vis_parent_id']."'});";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function detach_subtask($operation) {
        global $vis_language;
		$database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        list($task_info, $task_details)=$object->get_task('task_id='.$operation['vis_parent_id'],'',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$result = $object->detach_subtask($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($result) {
			$activity_log=$sub_object->add_staff_activity_log("Detached task - ".$task_details[0]['task_title'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo "<script>$('#vis_global_msg_div').visInterface('load_global_message', '".$vis_language['MSGSUCCOPRT']."');window.location.reload();</script>";
		}
		else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'");</script>';
		$database->database_disconnect();
        return $result;
    }

    function reset_badgecount($operation){
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $object->reset_badgecount($operation['api_key'],0);
        $database->database_disconnect();
        return true;
    }

    function send_mobilepushnotification($operationid, $userid, $parentid, $access, $devicetype){ 
     //$devicetype = 3 for Apple
     global $vis_language;
     $database=new class_database();
     include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
     $object = new class_staff($database);
     $devices = $object->get_devicelist();
     include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
     $ticket_object = new class_ticket($database);
     include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
     $client_object = new class_client($database);
     $body = array();
     if($devices!=-1)
     for($i=0;$i<count($devices);$i++){
        list($departmentaccess,$domainaccess) = $object->get_staffacessdepartments($devices[$i]["staff_id"]);

            if($operationid==10){
               if($departmentaccess ==0 || in_array($access, $domainaccess)) {
                  $client = $client_object->get_client("client_id=".$parentid, "", "", "", 0, 0);
                  if($devices[$i]["device_type"]==3){
                     $body['aps']['type'] = "client";
                     $body['aps']['client_id'] = $client[1][0]["client_id"];
                     $body['aps']['client_name'] = $client[1][0]["first_name"]." ".$client[1][0]["last_name"];
                     $body['aps']['alert'] = "New client added";
                     $body['aps']['badge'] = $devices[$i]["badgecount"]+1;
                     $object->reset_badgecount($devices[$i]["api_key"],$devices[$i]["badgecount"]+1);
                     $devices[$i]["badgecount"] = $devices[$i]["badgecount"] + 1;
                     $this->send_apns($devices[$i]["api_key"],$body);
                  }
               }
            }else{
               if($departmentaccess ==0 || in_array($access, $departmentaccess)){
                  $ticket = $ticket_object->get_ticket("ticket_id=".$parentid, "", "", '', 0, 0);
                  if($devices[$i]["device_type"]==3){
                    $body['aps']['ticket_id'] = $ticket[1][0]["ticket_id"];
                    $body['aps']['ticket_hash'] = $ticket[1][0]["ticket_hash"];
                    $body['aps']['department_id'] = $ticket[1][0]["department_id"];
                    $body['aps']['client_id'] = $ticket[1][0]["client_id"];
                    $body['aps']['type'] = "ticket";
                    if($operationid==2 || $operationid==1)
                       $body['aps']['alert'] = "New ticket";
                    else
                       $body['aps']['alert'] = "New client reply";
                    if(($operationid==1 && $devices[$i]["staff_id"]!=$userid) || $operationid!=1){
                       $body['aps']['badge'] = $devices[$i]["badgecount"]+1;
                       $object->reset_badgecount($devices[$i]["api_key"],$devices[$i]["badgecount"]+1);
                       $devices[$i]["badgecount"] = $devices[$i]["badgecount"] + 1;
                       $this->send_apns($devices[$i]["api_key"],$body);
                    }
                 }
               }
            }
     }
    }

    function send_apns($deviceToken,$body){
      //Setup stream (connect to Apple Push Server)
      $ctx = stream_context_create();
      stream_context_set_option($ctx, 'ssl', 'passphrase', 'vision');
      stream_context_set_option($ctx, 'ssl', 'local_cert', VIS_PATH_PLUGINS.'iphone/ckProd.pem');
      $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
      stream_set_blocking ($fp, 0); 
      if (!$fp) {
       // echo "Failed to connect (stream_socket_client): $err $errstrn";
      } else {
        // Keep push alive (waiting for delivery) for 90 days
        $apple_expiry = time() + (90 * 24 * 60 * 60); 
        $apple_identifier = 1;
        //$deviceToken = "764a7ec327d69549c46d73ddac0f2c5361f774c1936d53e4aebf84e06783a7ed";
        $payload = json_encode($body);
        // Enhanced Notification
        $msg = pack("C", 1) . pack("N", $apple_identifier) . pack("N", $apple_expiry) . pack("n", 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",  strlen($payload)) . $payload; 
        // SEND PUSH
        fwrite($fp, $msg);
        fclose($fp);
      }
    }
	
	//get ajax category dropdown
	function get_ticket_drp_subcategory($operation) {
		global $vis_language;
        $database = new class_database();
     	$filter_condtn = ($operation['vis_category_id'] == 0) ? VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_subcategory.category_id=0' : VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_subcategory.category_id='.$operation['vis_category_id'];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
		list($cat_count,$subcategory_list)=$obj_setting->get_ticket_subcategory_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		if(count($subcategory_list)>10){ $datalive='data-live-search="true"'; }
		$select = ((isset($operation['vis_flag']) && $operation['vis_flag']=='ticket') || (isset($operation['vis_client']) && $operation['vis_client']=='1'))?$vis_language['TXTSELECT']:$vis_language['TXTNOCHANGE'];		
		$subcatdrp='<select id="vis_subcategory" name="vis_subcategory" class="form-control input-sm selectpicker" onchange="getitem(this.value)" '.$datalive.'>
		<option value="0">'.$select.'</option>';
		
		if(isset($subcategory_list))
		{
			foreach($subcategory_list as $subcatlist)
			{
			    $selected = ($operation['vis_subcategory_id']!='' && ($operation['vis_subcategory_id']==$subcatlist['subcategory_id']))?' selected="selected"':'';
				$subcatdrp .='<option value="'.$subcatlist['subcategory_id'].'" '. $selected.'>'.$subcatlist['title'].'</option>';
			}
			
		}
		$subcatdrp .='</select>';
		echo $subcatdrp;
		return true;
	}
	
	function get_ticket_drp_item($operation) {
		global $vis_language;
        $database = new class_database();
		$filter_condtn = ($operation['vis_subcategory_id'] == 0) ? VIS_TABLE_PREFIX.'ticket_item.is_enabled=1 and  '.VIS_TABLE_PREFIX.'ticket_item.subcategory_id=0' : VIS_TABLE_PREFIX.'ticket_item.is_enabled=1 and '.VIS_TABLE_PREFIX.'ticket_item.subcategory_id='.$operation['vis_subcategory_id'];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$obj_setting=new class_setting($database);
		list($item_count,$item_list)=$obj_setting->get_ticket_item_list($filter_condtn,$data='', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		
		if(count($item_list)>10){ $datalive='data-live-search="true"'; }
		$select = ((isset($operation['vis_flag']) && $operation['vis_flag']=='ticket') || (isset($operation['vis_client']) && $operation['vis_client']=='1'))?$vis_language['TXTSELECT']:$vis_language['TXTNOCHANGE'];		
		$itemdrp='<select id="vis_item" name="vis_item" class="form-control input-sm selectpicker" '.$datalive.'>
		<option value="0">'.$select.'</option>';
		
		if(isset($item_list))
		{
			foreach($item_list as $itemlist)
			{
				$selected = ($operation['vis_itemid']!='' && $operation['vis_itemid']==$itemlist['item_id'])?' selected="selected"':'';
				$itemdrp .='<option value="'.$itemlist['item_id'].'" '. $selected.'>'.$itemlist['title'].'</option>';
			}
			
		}
		$itemdrp .='</select>';
		echo $itemdrp;
		return true;
	}
	function forum_signature($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        $domain=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'forum_signature.php');
        return true;
    }
    function load_forum_signature($operation) {
        global $vis_language;
        if(!isset($operation['vis_domain'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDOMNTFND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $filter='department_id='.$operation['vis_domain'].' and is_forum=1';
        if(isset($operation['vis_staff_id']) && is_numeric($operation['vis_staff_id'])) $filter.=' and staff_id='.$operation['vis_staff_id'];
        else $filter.=' and staff_id='.VIS_STAFF_ID;
        $signature=$object->get_signature($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $signature=$signature[0];
        $database->database_disconnect();
        //include(VIS_PATH_TEMPLATE.'signature_editor.php');
        echo $forum_signature=$signature['content'];	
        return true;
    }
    function update_forum_signature($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if($data['vis_forum_signature_content'] !='') $data['vis_staff_signature_content']=$data['vis_forum_signature_content'];
        if((!isset($data['vis_domain']) || $data['vis_domain']==0) && $data['vis_sign_all_domain'] != 1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDEPTNTFND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $object1=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object2=new class_staff($database);

        $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$operation['vis_staff_id'];
        list($staff_info, $staff_details)=$object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff_details[0];
        $staff_info['staff_count']=(!$staff_details || $staff_details==-1)?0:count($staff_details);
		if($staff_details!=-1) for($i=0;$i<count($staff_details);$i++){
            $staff_details[$i]['department']=array();
            $domain_access = array();
            if(isset($data['vis_sign_all_domain']) && $data['vis_sign_all_domain'] == 1){
				if($staff_details[$i]['department_access']==0){
					 $staff_details[$i]['department'] = $object->get_department_access('', VIS_STAFF_ID, VIS_LOCATION_AREA);
					 if($staff_details[$i]['department'] != -1){
					 foreach($staff_details[$i]['department'] as $dept){
						 $domain_access[]=$dept['domain_id'];
						 $domain_access=array_unique($domain_access);
				     }
				     foreach($domain_access as $dom){
					 $data['vis_domain'] = $dom;
					 $ret = $object2->update_forum_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}
				}
				else if($staff_details[$i]['department_access']==-2){
					$filter = VIS_TABLE_PREFIX.'staff_group.group_id = '.VIS_TABLE_PREFIX.'staff.group_id and '.VIS_TABLE_PREFIX.'staff_group.group_id='.$staff_details[$i]['group_id'];
					list($staffgroup_info, $staff_group)=$object->get_staffgroup_ofstaff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staffgroup_info['department_access']==0){
					$staff_department=$staffgroup_info['department_access'];
					$filter = '';
					}else{
					$staff_department = explode(',', $staffgroup_info['department_access']);
					$filter = '(';
					for($j=0;$j<count($staff_department); $j++)
					$filter .= ' department_id='.$staff_department[$j].' or';
					$filter = substr($filter,0, -2);
					$filter .=' )';
					}
					$staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staff_details[$i]['department'] != -1){
					foreach($staff_details[$i]['department'] as $dept){
						 $domain_access[]=$dept['domain_id'];
						 $domain_access=array_unique($domain_access);
				    }
					foreach($domain_access as $dom){
					$data['vis_domain'] = $dom;
					$ret = $object2->update_forum_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}

				}
				else{
					$staff_department = explode(',', $staff_details[$i]['department_access']);
					$filter = '(';
					for($j=0;$j<count($staff_department); $j++)
					$filter .= ' department_id='.$staff_department[$j].' or';
					$filter = substr($filter,0, -2);
					$filter .=' )';
					$staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					if($staff_details[$i]['department'] != -1){
					foreach($staff_details[$i]['department'] as $dept){
						 $domain_access[]=$dept['domain_id'];
						 $domain_access=array_unique($domain_access);
				    }
					foreach($domain_access as $dom){
					$data['vis_domain'] = $dom;
					$ret = $object2->update_forum_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);}}
				}
			}
			else $ret = $object2->update_forum_signature($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			$activity_log=$object->add_staff_activity_log("Modified ".$staff_details[0]['first_name']." ".$staff_details[0]['last_name']." ( ".$staff_details[0]['email']." ) forum signature", VIS_STAFF_ID,9,VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); </script>';
		}
        $database->database_disconnect();
        return true;
    }
    
    function sendmail_queue($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket=new class_ticket($database);
        $ticket->sendmail_queue(VIS_SENDMAILLIMIT);
        $database->database_disconnect();
        return true;
    }
				
				function getticketclosecount($staff_id) {
        global $vis_language;  
         $database=new class_database();
			
						 $currentdate = date('Y-m-d h:i:s');
							$weekDate =strtotime("-1 week ")- VIS_TIMEZONE;
								$filter = ' operation_id=2 AND new_info="Closed" AND entry_date between '.$weekDate.' AND '.strtotime($currentdate).' and operator!=1 and operator_id='.$staff_id; 
				 
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'report.php');
            $object=new class_report($database);
												$total_close_ticket=0;
           $report=$object->get_work_report($filter, $staff_id, VIS_LOCATION_AREA);
											if($report!=-1){
												$total_close_ticket=count($report);
											}
        $database->database_disconnect();
        return $total_close_ticket;
    }
	function get_help_doc($operation){
		 global $vis_language;
		 include(VIS_PATH_TEMPLATE.'vh-help.php');
        return true;
	 }
	function execute_comman_cron()
	{
		global $vis_language;  
  $database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php'); 
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$staff=new class_staff($database);
	$sub_object=new class_subsetting($database);
	$setting_object=new class_setting($database);
	
	  $timestamp = time();
		$date_time = date("H a", $timestamp);
		//update domain and staff timezone dst
		if(strtotime($date_time) == strtotime("12 pm")){		 
		   if(strtotime($date_time) <= strtotime("12:30 pm")){
							$stafflist=$staff->get_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA);
				for($i=0;$i<count($stafflist);$i++){
					$dst = $sub_object->get_dst_setting($stafflist[$i]['timezone']);
					
					$sub_object->update_staff_dst($dst,$stafflist[$i]['staff_id']);		
				}
				list($domain_info, $domain_details)=$setting_object->get_domain('', $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
				for($j=0;$j<count($domain_details);$j++){
					$dst = $sub_object->get_dst_setting($domain_details[$j]['timezone']);
					$sub_object->update_domain_dst($dst,$domain_details[$j]['domain_id']);
				}
				}
		}
		//end
		
		
	}
		function get_gcal_event_list($operation) {
			
		global $vis_language;
		$database=new class_database();
		$data=explode('/',$operation['vis_action']);
		$action=explode('&',$data[3]);
		$action=$action[0];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter='integration_type=42 AND is_enabled=1';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $vis_domain = $gcal_details[0]['domain_id'];
        if(count($gcal_details)>0 && $gcal_details!=-1){
			foreach($gcal_details as $gcal){
				include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
				$client = new Google_Client();
				$client->setClientId($gcal['host_name']);
				$client->setClientSecret($gcal['user_name']);
				$client->setRedirectUri($gcal['billing_url']);
				$client->setDeveloperKey($gcal['db_name']);
				$cal = new Google_CalendarService($client);
				$tasksService= new Google_TasksService($client);
				if (isset($_SESSION['code'])) {
				  $client->authenticate($_SESSION['code']);
				  $_SESSION['token'] = $client->getAccessToken();
				  unset($_SESSION['code']);
				}
				if (isset($_SESSION['token'])) {
				  $client->setAccessToken($_SESSION['token']);
				}
			    if ($client->getAccessToken()) {
					if($action==$vis_language['TXTEVENTS']){
						$calList = $cal->calendarList->listCalendarList();
						$eventList = $eventList1 = array();
						for($i=0;$i<count($calList['items']);$i++){
							$cal_id = $calList['items'][$i]['id'];
							$eventList1 = $cal->events->listEvents($calList['items'][$i]['id']);
							$eventList = array_merge($eventList ,$eventList1['items']);
							}
							$event_array=$event_list=array();
							$event=$eventList;
							for($i=0;$i<count($event);$i++){
							$event_array[$i]['calId']=$event[$i]['organizer']['email'];
							$event_array[$i]['id']=$event[$i]['id'];
							$event_array[$i]['name']=$event[$i]['summary'];
							$event_array[$i]['description']=$event[$i]['description'];
							$event_array[$i]['location']=$event[$i]['location'];
							$event_array[$i]['creator']=$event[$i]['creator']['email'];
							$event_array[$i]['created']=$event[$i]['created'];
							$event_array[$i]['start']=$event[$i]['start']['dateTime'];
							$event_array[$i]['end']=$event[$i]['end']['dateTime'];
							$guset=$event[$i]['attendees'];
							$guest_email='';
							for($g=0;$g<count($guset);$g++){
								$guest_email.=$guset[$g]['email'].',<br>';
							}
							$guest_email=substr($guest_email, 0, -5);
							$event_array[$i]['guest_email']=$guest_email;
						}
						$view_info['page_count']=(count($event_array)==0)?0:ceil(count($event_array)/10);
						$event_page=$operation['vis_page'];
						$start=$operation['vis_page']*10;
						$end=$start+10;
						if($end>count($event_array)) $end=count($event_array);
						for($j=$start; $j<$end;$j++) 
						$event_list[]=$event_array[$j];
						if(isset($operation['vis_page']) && $operation['vis_page']!='')
						include(VIS_PATH_TEMPLATE.'gcal_event_list.php');
						else
						include(VIS_PATH_TEMPLATE.'gcal_events.php');
						exit;	
					}else if($action==$vis_language['TXTTASKS']){
						$lists = $tasksService->tasklists->listTasklists();
						$tasks = $taskList1 = array();
						for($i=0;$i<count($lists['items']);$i++){
							$list_id = $lists['items'][$i]['id'];
							$taskList1 = $tasksService->tasks->listTasks($list_id);
							$tasks = array_merge($tasks ,$taskList1['items']);
							}
						$task_array=$task_list=array();
						$task=$tasks;
						for($k=0;$k<count($task);$k++){$listId=explode('/',$task[$k]['selfLink']);
							$task_array[$k]['listid']=$listId[6];
							$task_array[$k]['id']=$task[$k]['id'];
							$task_array[$k]['name']=$task[$k]['title'];
							$task_array[$k]['description']=$task[$k]['notes'];
							$task_array[$k]['due']=$task[$k]['due'];
							$task_array[$k]['updated']=$task[$k]['updated'];
						}
						$view_info['page_count']=(count($task_array)==0)?0:ceil(count($task_array)/10);
						$task_page=$operation['vis_page'];
						$start=$operation['vis_page']*10;
						$end=$start+10;
						if($end>count($task_array)) $end=count($task_array);
						for($j=$start; $j<$end;$j++) 
						$task_list[]=$task_array[$j];
						if(isset($operation['vis_page']) && $operation['vis_page']!='')
						include(VIS_PATH_TEMPLATE.'gcal_task_list.php');
						else
						include(VIS_PATH_TEMPLATE.'gcal_tasks.php');
						exit;	
					}
				}
				 else {
					 $authUrl = $client->createAuthUrl();	
				}
			}
		}
	}
	function add_gcal_event($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter='integration_type=42 AND is_enabled=1 ';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(count($gcal_details)>0 && $gcal_details!=-1){
			foreach($gcal_details as $gcal){
				include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
				$client = new Google_Client();
				$client->setClientId($gcal['host_name']);
				$client->setClientSecret($gcal['user_name']);
				$client->setRedirectUri($gcal['billing_url']);
				$client->setDeveloperKey($gcal['db_name']);
				$cal = new Google_CalendarService($client);
				$tasksService= new Google_TasksService($client);
				if (isset($_SESSION['code'])) {
				  $client->authenticate($_SESSION['code']);
				  $_SESSION['token'] = $client->getAccessToken();
				  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
				}
				if (isset($_SESSION['token'])) {
				  $client->setAccessToken($_SESSION['token']);
				}
			    if ($client->getAccessToken()) {
					$calList = $cal->calendarList->listCalendarList();
				}
			}
		}
		include(VIS_PATH_TEMPLATE.'add_gcal_event.php');
		return true;
	}
	function add_gcal_task($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter='integration_type=42 AND is_enabled=1 ';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(count($gcal_details)>0 && $gcal_details!=-1){
			foreach($gcal_details as $gcal){
				include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
				$client = new Google_Client();
				$client->setClientId($gcal['host_name']);
				$client->setClientSecret($gcal['user_name']);
				$client->setRedirectUri($gcal['billing_url']);
				$client->setDeveloperKey($gcal['db_name']);
				$cal = new Google_CalendarService($client);
				$tasksService= new Google_TasksService($client);
				if (isset($_SESSION['code'])) {
				  $client->authenticate($_SESSION['code']);
				  $_SESSION['token'] = $client->getAccessToken();
				  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
				}
				if (isset($_SESSION['token'])) {
				  $client->setAccessToken($_SESSION['token']);
				}
			    if ($client->getAccessToken()) {
					 $taskList = $tasksService->tasklists->listTasklists();
				}
			}
		}
		include(VIS_PATH_TEMPLATE.'add_gcal_task.php');
		return true;
	}
	function new_gcal($operation){
		global $vis_language;
		$database=new class_database();
		$data=parse_form_array($operation['vis_action']);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter='integration_type=42 AND is_enabled=1 ';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        //$gcal_details=$gcal_details[0];
        if(count($gcal_details)>0 && $gcal_details!=-1){
			foreach($gcal_details as $gcal){
				include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
				$client = new Google_Client();
				$client->setClientId($gcal['host_name']);
				$client->setClientSecret($gcal['user_name']);
				$client->setRedirectUri($gcal['billing_url']);
				$client->setDeveloperKey($gcal['db_name']);
				$cal = new Google_CalendarService($client);
				$tasksService= new Google_TasksService($client);
				if (isset($_SESSION['code'])) {
				  $client->authenticate($_SESSION['code']);
				  $_SESSION['token'] = $client->getAccessToken();
				  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
				}
				if (isset($_SESSION['token'])) {
				  $client->setAccessToken($_SESSION['token']);
				}
			    if ($client->getAccessToken()) {
					if($operation['vis_event']==1){
						if(!isset($data['vis_eventname']) || trim($data['vis_eventname'])=='') {
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
							return false;
						}
					}
					if($operation['vis_task']==1){
						if(!isset($data['vis_taskname']) || trim($data['vis_taskname'])=='') {
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
							return false;
						}
					}
					if($operation['vis_event']==1){
						$eresult = $emails = array();
						$attendees_email = explode(',',$data['vis_event_guest_email']);
						for($i=0;$i<count($attendees_email);$i++){
							$eresult[]['email'] = $attendees_email[$i];
						}
						if($eresult[0]['email']=='')$eresult =array();
						$event = new Google_Event(array(
						  'summary' => $data['vis_eventname'],
						  'location' => $data['vis_event_loc'],
						  'description' => $data['vis_event_desc'],
						  'start' => array(
							'dateTime' => date(DATE_W3C,strtotime($data['vis_event_start_date'])),
						  ),
						  'end' => array(
							'dateTime' =>  date(DATE_W3C,strtotime($data['vis_event_end_date'])),
						  ),
						  'attendees' =>
							$eresult
						));
						$res_event = $cal->events->insert($data['vis_cal_list'], $event);
						if($res_event!=''){
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTEVENTS'].'",{"vis_module":"home", "vis_operation":"get_gcal_event_list"});</script>';
							return true;
						}else{
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
							return false;
						}
					}
					else if($operation['vis_task']==1){
						$task = new Google_Task();
						$task->setTitle($data['vis_taskname']);
						$task->setNotes($data['vis_task_desc']);
						$task->setDue(date(DATE_W3C,strtotime($data['vis_task_due_date'])));

						$taskresult = $tasksService->tasks->insert($data['vis_task_list'], $task);
						if($taskresult!=''){
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTTASKS'].'",{"vis_module":"home", "vis_operation":"get_gcal_event_list"});</script>';
							return true;
						}else{
							echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
							return false;
						}
					}
				}
			}
		}
					
	}
	function get_gcal_details($operation) {
		global $vis_language;
		$database=new class_database();
		$data=explode('/',$operation['vis_action']);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter='integration_type=42 AND is_enabled=1 ';
        list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(count($gcal_details)>0 && $gcal_details!=-1){
			foreach($gcal_details as $gcal){
				include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
				include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
				$client = new Google_Client();
				$client->setClientId($gcal['host_name']);
				$client->setClientSecret($gcal['user_name']);
				$client->setRedirectUri($gcal['billing_url']);
				$client->setDeveloperKey($gcal['db_name']);
				$cal = new Google_CalendarService($client);
				$tasksService= new Google_TasksService($client);
				if (isset($_SESSION['code'])) {
				  $client->authenticate($_SESSION['code']);
				  $_SESSION['token'] = $client->getAccessToken();
				  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
				}
				if (isset($_SESSION['token'])) {
				  $client->setAccessToken($_SESSION['token']);
				}
			    if ($client->getAccessToken()) {
					if($data[3]==$vis_language['TXTEVENTS'] || $operation['vis_event']==1){
					if(isset($operation['vis_cal_id']) && isset($operation['vis_event_id'])){
						$eventList = $cal->events->get($operation['vis_cal_id'],$operation['vis_event_id']);
						$event_array=$event_list=array();
						$event_array['name']=$eventList['summary'];
						$event_array['description']=$eventList['description'];
						$event_array['location']=$eventList['location'];
						$event_array['creator']=$eventList['creator']['email'];
						$event_array['created']=format_datetime(strtotime($eventList['created']));
						$event_array['start']=format_datetime(strtotime($eventList['start']['dateTime']));
						$event_array['end']=format_datetime(strtotime($eventList['end']['dateTime']));
						$guset=$eventList['attendees'];
						$guest_email='';
						for($g=0;$g<count($guset);$g++){
							$guest_email.=$guset[$g]['email'].'<br>';
						}
						if(substr($guest_email, -5)==',') $guest_email=substr($guest_email, 0, -5);
						$event_array['guest_email']=$guest_email;
					}
					if($operation['vis_chat_type']=='googlecalender'){
						return $event_array;
					}else{
						include(VIS_PATH_TEMPLATE.'gcal_event_details.php');	
						return true;
					}
					}else if($data[3]==$vis_language['TXTTASKS'] || $operation['vis_task']=='1'){
						$task = $tasksService->tasks->get($operation['vis_tasklist_id'],$operation['vis_task_id']);
						$task_array=array();
						$task_array['name']=$task['title'];
						$task_array['description']=$task['notes'];
						$task_array['due']=format_datetime(strtotime($task['due']));
						$task_array['updated']=format_datetime(strtotime($task['updated']));
						if($operation['vis_task']==1){
							return $task_array;
						}else{
							include(VIS_PATH_TEMPLATE.'gcal_task_details.php');	
							return true;
						}
					}
				}
				 else {
					  $authUrl = $client->createAuthUrl();
				}
			}
		}
	}
	 function update_task_status_by_assign_user($operation) {
        global $vis_language;
        if(isset($operation['vis_filter_id']) && $operation['vis_filter_id']!='') $data['vis_filter_id']=$operation['vis_filter_id'];
        $data=parse_form_array($operation['vis_action']);
        if(isset($operation['vis_task_id']) && $operation['vis_task_id']!='') $data['vis_task_id']=$operation['vis_task_id'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->update_task_status_by_assign_user($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			if(isset($data['vis_parent_id']) && $data['vis_parent_id']>0)
			$activity_log=$sub_object->add_staff_activity_log("Subtask status updated - ".$operation['vis_tasktitle'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			else
			$activity_log=$sub_object->add_staff_activity_log("Task status updated - ".$operation['vis_tasktitle'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$operation['vis_tasktitle'].'/'.$data['vis_task_id'].'", {"vis_module":"home", "vis_operation":"view_update_tasks", "vis_tasktitle":"'.$operation['vis_tasktitle'].'", "vis_task_id":"'.$data['vis_task_id'].'"});$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"home","vis_current_operations":"view_tasks"});</script>';
		}
		$database->database_disconnect();
        return true;
    }
    function change_auto_assign_availability($operation){
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->change_auto_assign_availability($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($operation['vis_status']==1)
        echo '<script>$("#auto_assign").html(\'<button class="btn btn-primary btn-xs active" id="vis_auto_assign" data-toggle="button" onclick="$(this).visExecution("load_area", {"vis_module":"staff", "vis_operation":"change_auto_assign_availability", "vis_status":"'. $operation['vis_status'].'"});"><span class="text">Off</span><span class="text-active">On</span></button>\');</script>';
        else echo '<script>$("#auto_assign").html(\'<button class="btn btn-default btn-xs" id="vis_auto_assign" data-toggle="button" onclick="$(this).visExecution("load_area", {"vis_module":"staff", "vis_operation":"change_auto_assign_availability", "vis_status":"'.$operation['vis_status'].'"});"><span class="text">Off</span><span class="text-active">On</span></button>\');</script>';
        return true;
	}
	function change_available_agent_setting($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'ticket.php');
        $tkt_object = new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
        $status = (isset($operation['vis_status_filter']))?$operation['vis_status_filter']:1;
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$page = isset($operation['vis_page'])?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $staff_count       = $tkt_object->get_staff_list(VIS_STAFF_ID, VIS_LOCATION_AREA,$status,'');
        $view_info['page_count']=(count($staff_count)==0)?0:ceil(count($staff_count)/$view_info['page_count']);
		$staff       = $tkt_object->get_staff_list(VIS_STAFF_ID, VIS_LOCATION_AREA,$status,$limit);
		$staff_info['page']=$page;
		include(VIS_PATH_TEMPLATE.'available_agent_settings.php');
        return true;
	}
	function change_auto_assign_setting($operation){
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $ret=$object->change_auto_assign_setting($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($ret){
			if($operation['vis_status']=='on') $operation['vis_status']=0;
			else $operation['vis_status']=1;	
			if(!isset($operation['vis_profile'])) echo '<script> $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"staff", "vis_operation":"change_available_agent_setting","vis_status_filter":"'.$operation['vis_status'].'"}); </script>';
			return true;
		}
		else
		return false;
	}
	
	function refresh_right_panel($operation){ //print_r($operation);
		global $vis_language;
		$database=new class_database();
		if($operation['vis_module_name'] == 'problem' && ($operation['vis_function'] == 'new_problem' || $operation['vis_function'] == 'view_problems' || $operation['vis_function'] == 'filter_problem' || $operation['vis_function'] == 'problems_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'problem.php');
			$object=new class_problem($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$impacts=$ticket->get_properties('get_impacts', '');

			$quick_view=$object->get_problem_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			$problem_filters=array(8=>$vis_language['TXTALL'],9=>$vis_language['TXTOPEN'],10=>$vis_language['TXTCLOSED'],11=>$vis_language['TXTASSIGNED']);
			 $str = '';
			for($i=8;$i<=count($problem_filters)+7;$i++){
				$str .= '$("#vis_cnt_'.$i.'").text("'.$quick_view[$i].'");';
            }
			echo '<script>'.$str .'</script>';
		   $database->database_disconnect();	
		}elseif($operation['vis_module_name'] == 'changes' && ($operation['vis_function'] == 'new_change' || $operation['vis_function'] == 'view_changes' || $operation['vis_function'] == 'filter_changes' || $operation['vis_function'] == 'changes_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'changes.php');
			$object=new class_changes($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$impacts=$ticket->get_properties('get_impacts', '');
			$risks=$ticket->get_properties('get_risks', '');
			$changetype=$ticket->get_properties('get_changetype', '');

			$quick_view=$object->get_changes_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			$changes_filters=array(12=>$vis_language['TXTALL'],13=>$vis_language['TXTOPEN'],14=>$vis_language['TXTCLOSED'],15=>$vis_language['TXTASSIGNED']);
			$str = '';
			for($i=12;$i<=count($changes_filters)+11;$i++){
				$str .= '$("#vis_cnt_'.$i.'").text("'.$quick_view[$i].'");';
             }			
			echo '<script>'.$str .'</script>';			
			$database->database_disconnect();			
			
		}elseif($operation['vis_module_name'] == 'releases' && ($operation['vis_function'] == 'new_release' || $operation['vis_function'] == 'view_releases' || $operation['vis_function'] == 'filter_releases' || $operation['vis_function'] == 'releases_details')){

			$filter_id=$operation['vis_filter_id'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'releases.php');
			$object=new class_releases($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
			$ticket=new ticket($database);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$class_ticket=new class_ticket($database);

			$filter=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$class_ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$status=$ticket->get_properties('get_status', '');
			$priorities=$ticket->get_properties('get_priorities', '');
			$releasetype=$ticket->get_properties('get_releasetype', '');

			$quick_view=$object->get_releases_filter_counts('', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$releases_filters=array(16=>$vis_language['TXTALL'],17=>$vis_language['TXTOPEN'],18=>$vis_language['TXTCLOSED'],19=>$vis_language['TXTASSIGNED']);
			 $str = '';
			for($i=16;$i<=count($releases_filters)+15;$i++){
				$str .= '$("#vis_cnt_'.$i.'").text("'.$quick_view[$i].'");';
            }
			echo '<script>'.$str .'</script>';			
			$database->database_disconnect();			
		}		
		
	}

	//for ios encrypt password for match vision api password to md5
	function password_encrypt($string, $key) {
    $result = '';
    for($i = 0; $i < strlen($string); $i++) {
        $char = substr($string, $i, 1);
        $keychar = substr($key, ($i % strlen($key))-1, 1);
        $char = chr(ord($char) + ord($keychar));
        $result .= $char;
        } 
    return base64_encode($result);
    }
	
	//for ios get staff details to show profile
	function get_staff_details($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $username = $_GET['vis_txtusername'];
        $password = $_GET['vis_txtuserpass'];
        $pass     = $this->password_encrypt($password, "helpdesk software vision helpdesk"); 

        $filter   = " user_name = '".$username."' and authentication = '".$pass."' ";
        $staff=$object->get_staff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($staff==-1) {
            echo $vis_language['TXTNOMATCHFOUND'];
        }
        else {
            echo get_xml($staff, 'staff');
        }
        $database->database_disconnect();
        return true;
        
    }
	
	function get_delete_autotask($operation) {
		global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETETASK'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'staff', 'vis_operation':'autotask_delete', 'vis_task_id':".$operation['vis_task_id'].",'vis_filter_id':".$operation['vis_filter_id'].",'vis_autotask_id':".$operation['autotask_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function autotask_delete($operation) {
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
         list($task_info, $task_details)=$object->get_task('task_id='.$operation['vis_task_id'],'',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ret=$object->task_delete($operation, VIS_STAFF_ID, VIS_LOCATION_AREA); 
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else{ 
			$activity_log=$sub_object->add_staff_activity_log("Deleted auto sub task - ".$task_details[0]['task_title'], VIS_STAFF_ID,10,VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGSUCCOPRT'].'");  $("#autosub_task_list").visExecution("load_area",{"vis_module":"setting", "vis_operation":"refresh_autosubtask_list","vis_autotask_id":"'.$operation['vis_autotask_id'].'"}); </script>';
		}	 
        $database->database_disconnect();
        return true;
	}
	### Update autosub task 
	function update_autosubtask($operation) {
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
		list($task_info, $task_details)=$object->get_task('task_id='.$operation['task_id'],'',$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$task_details = $task_details[0];
		$filter=VIS_TABLE_PREFIX.'task_assign.task_id='.$operation['task_id'];
        $assign_task_details=$object->get_task_assign_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
		for($i=0;$i<count($assign_task_details);$i++)
		{
			$old_staff.=$assign_task_details[$i]['owner_id'].",";
		}
 		include(VIS_PATH_TEMPLATE.'update_task_modal.php');
		return true;
	}	
	
	### Update Auto Subtask details 
	function update_autosub_task($operation)
	{
		global $vis_language;	
		$database=new class_database();				
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$object=new class_staff($database);
		$flag=true;
        if(($operation['vis_overdueday']=='' && $operation['vis_overduehr']=='' && $operation['vis_overduemin']=='') || (!is_numeric($operation['vis_overduehr']) && $operation['vis_overduehr']!='') || (!is_numeric($operation['vis_overduemin']) && $operation['vis_overduemin']!='') || (!is_numeric($operation['vis_overdueday']) && $operation['vis_overdueday']!='') || $operation['vis_overduehr']<0 || $operation['vis_overduemin']<0 || $operation['vis_overdueday']<0) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDUETIMENTSET'].'"); </script>';
            $flag=false;
        }
        if(($operation['vis_resolutionday']=='' && $operation['vis_resolutionhr']=='' && $operation['vis_resolutionmin']=='') || (!is_numeric($operation['vis_resolutionhr']) && $operation['vis_resolutionhr']!='') || (!is_numeric($operation['vis_resolutionmin']) && $operation['vis_resolutionmin']!='') || (!is_numeric($operation['vis_resolutionday']) && $operation['vis_resolutionday']!='') || $operation['vis_resolutionhr']<0 || $operation['vis_resolutionmin']<0 || $operation['vis_resolutionday']<0) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGRESTIMENTSET'].'"); </script>';
            $flag=false;
        }
        if(!$flag) return false;
        if($operation['vis_overdueday']!='') $operation['vis_duetime']=($operation['vis_overduehr']*60)+$operation['vis_overduemin']+($operation['vis_overdueday']*1440);
        else  $operation['vis_duetime']=($operation['vis_overduehr']*60)+$operation['vis_overduemin'];

        if($operation['vis_resolutionday']!='') $operation['vis_resolvetime']=($operation['vis_resolutionhr']*60)+$operation['vis_resolutionmin']+($operation['vis_resolutionday']*1440);
        else $operation['vis_resolvetime']=($operation['vis_resolutionhr']*60)+$operation['vis_resolutionmin'];
		
	    $ret=$object->update_task_details($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(!$ret) {
			   echo $msg = 'error';
            }
            else
            {
				echo $msg ="success";
			}
        $database->database_disconnect();
		return true;
 	}
}
?>
