<?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 setting {
    var $error;

    function setting_menu($operation) {
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$database=new class_database();
		$object=new class_setting($database);
		$domains=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);  $domains= $domains[1];
		$domain_id  = $domains[0]['domain_id'];
		//$module_setting=$object->get_module_setting('domain_id='.$domain_id.' and module_id=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$setting=$object->get_settings('title="vis_license_display"', VIS_STAFF_ID, VIS_LOCATION_AREA);
	    foreach($modules as $var) $module[$var['module']]=1;
        include(VIS_PATH_TEMPLATE.'setting_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']=$vis_language['MSGCHANGESTATUSMESSAGE'];
		$message_info['vis_event']="$('#vis_global_msg_div').visExecution('submit_form', {'vis_module':'setting', '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.'setting.php');
        $object=new class_setting($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($operation['vis_current_operation']=='fb_pages'){
				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":"setting", "vis_operation":"'.$operation['vis_current_operation'].'","vis_page":"'.$vis_page.'","vis_action":"#/setting/'.$operation['vis_current_operation'].'/'.$operation['vis_name'].'/'.$operation['vis_integration_id'].'" }); </script>';
			}elseif(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
				{
					$module = ($operation['vis_current_operation']=="view_alerts")?'home':'setting';
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$module.'", "vis_operation":"'.$operation['vis_current_operation'].'","vis_page":"'.$vis_page.'"}); </script>';
				}
			
		}
        return $ret;
    }
    function domain_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'domain.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'domain.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=")";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($domain_info, $domain_details)=$object->get_domain($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($domain_info['total']==0)?0:ceil($domain_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $domain_info['domain_count']=(!$domain_details || $domain_details==-1)?0:count($domain_details);
        $domain_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTDOMAIN'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'domain_list.php');
			$domain_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'=>$domain_info['total'], 'paging' => $select, 'list'=> $domain_list));
		}else include(VIS_PATH_TEMPLATE.'domains.php');
        return true;
    }
	
    function view_domains($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $operation['view_title']=$vis_language['TXTDOMAIN'];
		$operation['vis_current_operation']='view_domains';
        $operation['vis_current_module']='setting';
        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['domain_name like "%'] = $data['vis_title'].'%"';
		   if($data['vis_domainurl']!='') $and_operations['domain_url like "%'] = $data['vis_domainurl'].'%"';
		   if($data['vis_email']!='') $and_operations['default_email like "%'] = $data['vis_email'].'%"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
        $database->database_disconnect();
        return $this->domain_display($operation, $and_operations, '', '', $page, $sort_by);
    }

    function domain_details($operation){
        global $vis_language;
        $operation['view_title']=$vis_language['TXTDOMAIN'];
        $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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'domain.domain_id='.$action[4].' ';
            list($domain_info, $domain_details)=$object->get_domain($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info, $language_details)=$object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $domain_details=$domain_details[0];
            list($department_info, $department_details)=$sub_object->get_department($filter, '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $dept_ids= array();
            for($i=0;$i<count($department_details);$i++) $dept_ids[$i]=$department_details[$i]['department_id'];
            $tempsmtp_details=$object->get_smtp_details('is_enabled = 1', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $smtp_details=array();
            for($i=0;$i<count($tempsmtp_details);$i++){
                $smtp_deptids=explode(',',$tempsmtp_details[$i]['department_id']);
                for($j=0;$j<count($smtp_deptids);$j++){
                    if(in_array($smtp_deptids[$j],$dept_ids) || $smtp_deptids[$j]==0){
                        $smtp_details[]=$tempsmtp_details[$i];
                        break;
                    }
                }
            }
            $date_time=$object->get_datetime_format($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $themes=array();
            if ($d=@dir(VIS_PATH_CLIENT_THEME)) while (false!==($entry = $d->read())) if(@is_dir(VIS_PATH_CLIENT_THEME.$entry) && $entry!='.' && $entry!='..') $themes[]=$entry;
            include(VIS_PATH_TEMPLATE.'domain_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function department_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'department.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=")";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'department.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=")";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($department_info, $department_details)=$sub_object->get_department($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($department_info['total']==0)?0:ceil($department_info['total']/$view_info['page_count']);
		list($info, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $department_info['department_count']=(!$department_details || $department_details==-1)?0:count($department_details);
        $department_info['page']=$page;
        $view_info['view_count']=count($department_details);
        $view_info['view_title']=$vis_language['TXTDEPARTMENT'];
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'depertment_list.php');
			$department_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'=>$department_info['total'], 'paging' => $select, 'list'=> $department_list));
		}
        else include(VIS_PATH_TEMPLATE.'departments.php');
        return true;
    }

    function view_departments($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $operation['view_title']=$vis_language['TXTDEPARTMENT'];
        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_dept']!='') $and_operations['department_name like "%'] = $data['vis_dept'].'%"';
		   if($data['vis_ispaid']!='')$and_operations['is_paid="'] = $data['vis_ispaid'].'"';
		   if($data['vis_access']!='')$and_operations['access_type="'] = $data['vis_access'].'"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		   if($data['vis_domain']!='')$and_operations['domain_id="'] = $data['vis_domain'].'"';
        }
        $database->database_disconnect();
        return $this->department_display($operation,$and_operations, '', '', $page, $sort_by);
    }

    function department_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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'department.department_id='.$action[4];
            list($department_info, $department_details)=$sub_object->get_department($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($info, $templates)=$object->get_etemplate('is_enabled=1 and language=1', '', 0, '', VIS_STAFF_ID,VIS_LOCATION_AREA);
            $department_lang =$object->get_translation(15, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($staffgroup_info, $staff_group)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $department_details=$department_details[0];
			$filter=VIS_TABLE_PREFIX.'staff.is_enabled=1 and '.VIS_TABLE_PREFIX.'staff.department_access!="-2" ';
            list($domain,$staff_list)=$object->get_staff($filter,'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
            include(VIS_PATH_TEMPLATE.'department_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function staff_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database); 
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $filter=substr($filter,0,-4);
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_fullname']) && $data['vis_fullname'] != "")
            {
				$pos = strrpos($data['vis_fullname'], " ");
			    if($pos!='')
			    {
					$name=explode(" ",$data['vis_fullname']);
					for($i=0; $i<count($name); $i++)
					{
						if($filter!="")
						$filter.=" and ( first_name like '%".$name[$i]."%' or last_name like '%".$name[$i]."%' )"  ;
						else $filter="  ( first_name like '%".$name[$i]."%' or last_name like '%".$name[$i]."%' )"  ;
					}
				}
				else
				{
					if($filter!="")
					$filter.=" and ( first_name like '%".$data['vis_fullname']."%' or last_name like '%".$data['vis_fullname']."%' )";
					else $filter="  ( first_name like '%".$data['vis_fullname']."%' or last_name like '%".$data['vis_fullname']."%' )";
				}
            }
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $filter_enable=(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)?$operation['vis_filter_enable']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $sort_by=(isset($operation['vis_sorted_by']))?$operation['vis_sorted_by']:'is_enabled=1';
        $operation['vis_sorted_by']=(isset($operation['vis_sorted_by']))?$operation['vis_sorted_by']:'is_enabled=1';
        list($staffgroup_info, $staff_group1)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
       
	    if((!isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']!=1)){

		if($filter==''){
			$filter.='';
		}else{
			$filter.=' and ';
		}
		$filter.=VIS_TABLE_PREFIX.'staff.'.$sort_by;
		if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='is_enabled=1')$filter.= ' and ('.VIS_TABLE_PREFIX.'staff.department_access!="-1" OR ('.VIS_TABLE_PREFIX.'staff.department_access IS NULL))';

        if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='is_enabled=0')$filter.= ' and ('.VIS_TABLE_PREFIX.'staff.department_access!="-1" OR ('.VIS_TABLE_PREFIX.'staff.department_access IS NULL))';

        if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='department_access=-1')$filter= VIS_TABLE_PREFIX.'staff.department_access=-1';

       } else { 
		
		if($filter==''){
			$filter.='';
		}else{
			$filter.=' and ';
		}
		$filter.=VIS_TABLE_PREFIX.'staff.'.$operation['vis_sorted_by'];
		if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='is_enabled=1')$filter.= ' and ('.VIS_TABLE_PREFIX.'staff.department_access!="-1" OR ('.VIS_TABLE_PREFIX.'staff.department_access IS NULL))';

        if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='is_enabled=0')$filter.= ' and ('.VIS_TABLE_PREFIX.'staff.department_access!="-1" OR ('.VIS_TABLE_PREFIX.'staff.department_access IS NULL))';

        if(isset($operation['vis_sorted_by']) && $operation['vis_sorted_by']=='department_access=-1')$filter.= ' and '.VIS_TABLE_PREFIX.'staff.department_access=-1'; 
		
	
		}
		
		
		list($staff_info, $staff_details)=$object->get_staff_for_sorting($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $admin_access=$staff->get_staff_access('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($admin_access[0]['level']==0){
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $subobject=new class_subsetting($database);
            if(VIS_DOMAIN_ACCESS!=0){
                $departments=$subobject->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                $department_access=array();
                for($k=0;$k<count($departments[1]);$k++){
                    $department_access[$k]=$departments[1][$k]['department_id'];
                }
            }else $department_access=0;
        }
        $total_staff_count=count($staff_details);
        if($staff_details!=-1 && !empty($staff_details)) for($i=0;$i<$total_staff_count;$i++){
			if($staff_details[$i]['department_access']!=-1){
            $staff_details[$i]['department']=array();
            if($staff_details[$i]['department_access']==0){
                $staff_details[$i]['department'][0]['domain_name']='';
                $staff_details[$i]['department'][0]['department_name'] = $vis_language['TXTALLDEPARTMENTS'];
            }
            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'];
                else $staff_department = explode(',', $staffgroup_info['department_access']);
                if($admin_access[0]['level']==0 && $department_access!=0 && $staff_department!=0 && $staff_details[$i]['staff_id']!=VIS_STAFF_ID){
                    $temp=array();
                    for($k=0;$k<count($staff_department);$k++){
                        if(in_array($staff_department[$k],$department_access)) $temp[]=$staff_department[$k];
                    }
                    if(count($temp)>0){
                        $staff_department=$temp;
                        $filter = '(';
                        for($j=0;$j<count($staff_department); $j++)
                        $filter .= ' department_id='.$staff_department[$j].' or';
                        $filter = substr($filter,0, -2);
                        $filter .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                         if(VIS_DOMAIN_ACCESS!=0 && VIS_DOMAIN_ACCESS!=-1) {
							$filter.=' and '.VIS_TABLE_PREFIX.'domain.domain_id in ('.VIS_DOMAIN_ACCESS.') ';
							}
                        $staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
                    }else unset($staff_details[$i]);
                }else{
                    $filter = '(';
                    for($j=0;$j<count($staff_department); $j++)
                    $filter .= ' department_id='.$staff_department[$j].' or';
                    $filter = substr($filter,0, -2);
                    $filter .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                     if(VIS_DOMAIN_ACCESS!=0 && VIS_DOMAIN_ACCESS!=-1) {
							$filter.=' and '.VIS_TABLE_PREFIX.'domain.domain_id in ('.VIS_DOMAIN_ACCESS.') ';
							}
                    $staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
                }
            }
            else{
                $staff_department = explode(',', $staff_details[$i]['department_access']);
                if($admin_access[0]['level']==0 && $department_access!=0 && $staff_details[$i]['staff_id']!=VIS_STAFF_ID){
                    $temp=array();
                    for($k=0;$k<count($staff_department);$k++){
                        if(in_array($staff_department[$k],$department_access)) $temp[]=$staff_department[$k];
                    }
                    if(count($temp)>0){
                        $staff_department=$temp;
                        $filter = '(';
                        for($j=0;$j<count($staff_department); $j++)
                        $filter .= ' department_id='.$staff_department[$j].' or';
                        $filter = substr($filter,0, -2);
                        $filter .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                         if(VIS_DOMAIN_ACCESS!=0 && VIS_DOMAIN_ACCESS!=-1) {
							$filter.=' and '.VIS_TABLE_PREFIX.'domain.domain_id in ('.VIS_DOMAIN_ACCESS.') ';
							}
                        $staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
                    }else unset($staff_details[$i]);
                }else{
                    $filter = '(';
                    for($j=0;$j<count($staff_department); $j++)
                    $filter .= ' department_id='.$staff_department[$j].' or';
                    $filter = substr($filter,0, -2);
                    $filter .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                     if(VIS_DOMAIN_ACCESS!=0 && VIS_DOMAIN_ACCESS!=-1) {
							$filter.=' and '.VIS_TABLE_PREFIX.'domain.domain_id in ('.VIS_DOMAIN_ACCESS.') ';
							}
                    $staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
                }
            }
        }
	}
        if($admin_access[0]['level']==0 && $department_access!=0){
            $temp=array();
            for($j=0;$j<=$total_staff_count;$j++) if($staff_details[$j]!='') $temp[]=$staff_details[$j];
            $staff_details=$temp;
        }
        $stafflist=$staff->get_staff('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($sort_by=='is_enabled=0')
        $view_info['page_count']=($staff_info[1]==0)?0:ceil($staff_info[1]/$view_info['page_count']);
        else if($sort_by=='department_access=-1')
        $view_info['page_count']=($staff_info[3]==0)?0:ceil($staff_info[3]/$view_info['page_count']);
        else
        $view_info['page_count']=($staff_info[2]==0)?0:ceil($staff_info[2]/$view_info['page_count']);
        $database->database_disconnect();
        $staff_info['staff_count']=(!$staff_details || $staff_details==-1)?0:count($staff_details);
        $staff_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTSTAFF'];
        $operation['vis_current_operation']='view_staff';
        $operation['vis_current_module']='setting';
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'staff_list.php');
			$staff_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'=>$staff_info[4], 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'staff.php');
        return true;
    }

    function view_staff($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTSTAFF'];
        //$and_operations=array('staff_id!='=>1);
        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_username']!='') $and_operations['user_name like "%'] = $data['vis_username'].'%"';
		   if($data['vis_email']!='') $and_operations['email like "%'] = $data['vis_email'].'%"';
		   if($data['vis_group']!='')$and_operations['group_id="'] = $data['vis_group'].'"';
		   if($data['vis_deleted']!='') $operation['vis_sorted_by']= $data['vis_deleted'];
        }
        return $this->staff_display($operation, $and_operations,'', '', $page, $sort_by);
    }
    function adminaccess_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        if(VIS_DOMAIN_ACCESS!=0) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
            return false;
        }
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $setting=new class_setting($database);
        list($info, $modules)=$setting->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter.="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $filter=substr($filter,0,-4);
        $data = parse_form_array($operation['vis_action']);
         if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            if(isset($data['vis_fullname']) && $data['vis_fullname'] != "")
            {
				$pos = strrpos($data['vis_fullname'], " ");
			    if($pos!='')
			    {
					$name=explode(" ",$data['vis_fullname']);
					for($i=0; $i<count($name); $i++)
					{
						$filter.="( first_name like '%".$name[$i]."%' or last_name like '%".$name[$i]."%' ) and "  ;
					}
					$filter=substr($filter, 0, -4);
				}
				else
				{
					$filter.="( first_name like '%".$data['vis_fullname']."%' or last_name like '%".$data['vis_fullname']."%' )";
				}
            }
            if(isset($data['vis_admintype']) && $data['vis_admintype'] != "")
            {
				 if($filter != '') {$filter .= " and ".VIS_TABLE_PREFIX."adminaccess.level  = ".$data['vis_admintype'];  }
                 else if($filter == ''){$filter .= VIS_TABLE_PREFIX."adminaccess.level  = ".$data['vis_admintype'];   }
			}
			if(isset($data['vis_username']) && $data['vis_username'] != "")
            {
				 if($filter != '') {$filter .= " and user_name like '%".$data['vis_username']."%'";  }
                 else if($filter == ''){$filter .= " user_name like '%".$data['vis_username']."%'";  }
			}
        }
        if($filter!='')$filter = VIS_TABLE_PREFIX."staff.staff_id!=1 and ".$filter;
        else $filter = VIS_TABLE_PREFIX."staff.staff_id!=1";
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
         if(isset($data['vis_admintype']) && $data['vis_admintype']!='')
        {
			list($staff_info, $staff_details)=$object->get_filter_staff($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		else
		{
			 list($staff_info, $staff_details)=$object->get_staff($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		if($staff_details!=-1)
		{
			for($i=0;$i<count($staff_details);$i++){
				$admin_access=$sub_object->get_admin_access($staff_details[$i]['staff_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
				$staff_details[$i]['department']=array();
				if($admin_access!=-1 && $admin_access['level']!=2){
					if($admin_access['domain']==0){
						$staff_details[$i]['department'][0]['domain_name']=$vis_language['TXTALLDOMAINS'];
					}
					else{
						$staff_department = explode(',', $admin_access['domain']);
						$filter = '(';
						for($j=0;$j<count($staff_department); $j++)
						$filter .= ' domain_id='.$staff_department[$j].' or';
						$filter = substr($filter,0, -2);
						$filter .=' )';
						$staff_details[$i]['department'] = $object->get_domain_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
					}
					if($admin_access['level']==1) $staff_details[$i]['superadmin']=$vis_language['TXTSUPERADMIN'];
					else  if($admin_access['level']==0)$staff_details[$i]['superadmin']=$vis_language['TXTDOMAINADMIN'];
					 else  if($admin_access['level']==2)$staff_details[$i]['superadmin']='';
				}
				else {
					$staff_details[$i]['department'][0]['domain_name']='';
					$staff_details[$i]['superadmin']='';
				}
			}
		}
        $view_info['page_count']=($staff_info['total']==0)?0:ceil($staff_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $staff_info['staff_count']=(!$staff_details || $staff_details==-1)?0:count($staff_details);
        $staff_info['page']=$page;
        $view_info['view_count']=count($view_details);
          if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'admin_list.php');
			$admin_access_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'=>$staff_info['total'], 'paging' => $select, 'list'=> $admin_access_list));
		}else
        include(VIS_PATH_TEMPLATE.'admin_access_list.php');
        return true;
    }

    function view_adminaccess($operation) {
        $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']:'';
        //$and_operations=array('staff_id!='=>1);
        return $this->adminaccess_display($operation, '', '', '', $page, '');
    }

    function adminaccess_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
            if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
				if($action[4]==1){  echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'")</script>';return false;}
                $database=new class_database();
                include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
				include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
                $object=new class_setting($database);
				$sub_object=new class_subsetting($database);
				list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
				foreach($modules as $var) $module[$var['module']]=1;
                $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$action[4].' ';
                list($staff_info, $staff_details)=$object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                $staff=$staff_details[0];
                $admin_access=$sub_object->get_admin_access($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
                $setting_check=explode(',',$admin_access['domain_access']);
				 
			    list($domain_info, $domain_details)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
                $database->database_disconnect();
                include(VIS_PATH_TEMPLATE.'admin_access_details.php');

                return true;
            }
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function staff_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_staff_id'])) $action[4]=$operation['vis_staff_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			if($action[4]==1){if(VIS_STAFF_ID!=1){echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'")</script>';return false;}}
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $object=new class_setting($database);
            $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$action[4].' ';
            list($staff_info, $staff_details)=$object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $staff=$staff_details[0];
            list($staffgroup_info, $staff_group)=$object->get_staffgroup('', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTSTAFF'];
            include(VIS_PATH_TEMPLATE.'staff_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
    function staff_department_details($operation){
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$operation['vis_staff_id'];
        list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staff_info, $staff_details)=$object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff_details[0];
        list($staffgroup_info, $staff_group)=$object->get_staffgroup('', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $department_access=explode(',',$staff_details[0]['department_access']);
        list($schedule_count,$schedule)=$object->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'staff_departments.php');
        return true;
    }

    function staffgroup_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
		
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff_group.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=")";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'staff_group.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($staffgroup_info, $staffgroup_details)=$object->get_staffgroup($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($staffgroup_info['total']==0)?0:ceil($staffgroup_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $staffgroup_info['staffgroup_count']=(!$staffgroup_details || $staffgroup_details==-1 || $staffgroup_details[0]=='')?0:count($staffgroup_details);
        $staffgroup_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTSTAFF'];
        $operation['vis_current_operation']='view_staffgroup';
        $operation['vis_current_module']='setting';
          if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'staffgroup_list.php');
			$staffgroup_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'=>$staffgroup_info['total'], 'paging' => $select, 'list'=> $staffgroup_list));
		}else
        include(VIS_PATH_TEMPLATE.'staffgroup.php');
        return true;
    }

    function view_staffgroup($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTADDSTAFFGROUP'];
        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_staffgr']!='') $and_operations['group_name like "%'] = $data['vis_staffgr'].'%"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
        return $this->staffgroup_display($operation,$and_operations, '', '', $page, $sort_by);
    }

    function staffgroup_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTUPDATESTAFFGROUP'];
		
        $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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'staff_group.group_id='.$action[4];
            list($schedule_count,$schedule)=$object->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($staffgroup_info, $staffgroup_details)=$object->get_staffgroup($filter, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $staffgroup_details=$staffgroup_details[0];
            $department_access=explode(',',$staffgroup_details['department_access']);

            $staffgroup_access=array_map('intval', explode(',', $staffgroup_details['module']));
            $group_access=explode(',', $staffgroup_details['access']);
            
            list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			foreach($modules as $var) $module[$var['module']]=1; 
			$filter='integration_type=1 AND is_enabled=1';
            list($whmcs_info, $whmcs_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $whmcs=$whmcs_details[0]; 
            $filter='integration_type=3 AND is_enabled=1';
            list($sms_info, $sms_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $sms=$sms_details[0]; 
            
            $filter='integration_type=19 AND is_enabled=1';
            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';
            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';
            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';
            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';
            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';
            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';
            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';
            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';
            list($count, $twilio_details)=$object->get_integration_setting($twilio_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $twilio_details=$twilio_details[0];
            
            $clickdesk_filter='integration_type=30 AND is_enabled=1';
            list($count, $clickdesk_details)=$object->get_integration_setting($clickdesk_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $clickdesk=$clickdesk_details[0];
            
            $zopim_filter='integration_type=32 AND is_enabled=1';
            list($count, $zopim_details)=$object->get_integration_setting($zopim_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $zopim=$zopim_details[0];
            
            $freshbook_filter='integration_type=29 AND is_enabled=1';
			list($count, $freshbook_details)=$object->get_integration_setting($freshbook_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$freshbook_details=$freshbook_details[0];
			
			$mailchimp_filter='integration_type=28 AND is_enabled=1';
			list($count, $mailchimp_details)=$object->get_integration_setting($mailchimp_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$mailchimp_details=$mailchimp_details[0];
			
			$magento_filter='integration_type=31 AND is_enabled=1';
            list($count, $magento_details)=$object->get_integration_setting($magento_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $magento_details=$magento_details[0];
            
			$insightly_filter='integration_type=33 AND is_enabled=1';
            list($count, $insightly_details)=$object->get_integration_setting($insightly_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $insightly_details=$insightly_details[0];
            
            $bigcommerce_filter='integration_type=34 AND is_enabled=1';
            list($count, $bigcommerce_details)=$object->get_integration_setting($bigcommerce_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $bigcommerce_details=$bigcommerce_details[0];
            
            $jira_filter='integration_type=35 AND is_enabled=1';
            list($count, $jira_details)=$object->get_integration_setting($jira_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $jira_details=$jira_details[0];
            
            $blesta_filter='integration_type=36 AND is_enabled=1';
            list($count, $blesta_details)=$object->get_integration_setting($blesta_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $blesta_details=$blesta_details[0];
			
			$capcrm_filter='integration_type=41 AND is_enabled=1';
			list($count, $capcrm_details)=$object->get_integration_setting($capcrm_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$capcrm_details=$capcrm_details[0];
			
			$redmine_filter='integration_type=37 AND is_enabled=1';
			list($count, $redmine_details)=$object->get_integration_setting($redmine_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$redmine_details=$redmine_details[0];
			
			$exotel_filter='integration_type=38 AND is_enabled=1';
			list($count, $exotel_details)=$object->get_integration_setting($exotel_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$exotel_details=$exotel_details[0];
			
			$gcal_filter='integration_type=42 AND is_enabled=1';
			list($count, $gcal_details)=$object->get_integration_setting($gcal_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$gcal_details=$gcal_details[0];
			 
			$crisp_filter='integration_type=46 AND is_enabled=1';
			list($count, $crisp_details)=$object->get_integration_setting($crisp_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);  
			$crisp_details=$crisp_details[0];
			
			$aircall_filter='integration_type=50 AND is_enabled=1';
			list($count, $aircall_details)=$object->get_integration_setting($aircall_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$aircall_details=$aircall_details[0];
			
			$xero_filter='integration_type=56 AND is_enabled=1';
			list($count, $xero_details)=$object->get_integration_setting($xero_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$xero_details=$xero_details[0];
		
			include(VIS_PATH_TEMPLATE.'staffgroup_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	function staff_permissions($operation){
		global $vis_language;
        $id=$operation['vis_group_id'];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $filter=VIS_TABLE_PREFIX.'staff_group.group_id='.$id;
        list($staffgroup_info, $staffgroup_details)=$object->get_staffgroup($filter, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staffgroup_details=$staffgroup_details[0];
        $staffgroup_access=array_map('intval', explode(',', $staffgroup_details['module']));
        $group_access=explode(',', $staffgroup_details['access']);
        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';
        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';
        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';
        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';
        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';
        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';
        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';
        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';
        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';
        list($count, $twilio_details)=$object->get_integration_setting($twilio_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $twilio_details=$twilio_details[0];
        
        include(VIS_PATH_TEMPLATE.'staffgroup_details.php');
        return true;

    }
    function mailqueue_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'mailqueue.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=")";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'domain.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($domain_info, $domain_details)=$object->get_domain('', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($department_info,$department_details)=$sub_object->get_department('','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($mailqueue_info, $mailqueue_details)=$object->get_mailqueue($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($mailqueue_info['total']==0)?0:ceil($mailqueue_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $mailqueue_info['mailqueue_count']=(!$mailqueue_details || $mailqueue_details==-1)?0:count($mailqueue_details);
        $mailqueue_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $operation['view_title']=$vis_language['TXTEMAILQUEUE'];
		$operation['vis_current_operation']='view_mailqueue';
        $operation['vis_current_module']='setting';
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'mailqueue_list.php');
			$mailqueue_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'=>$mailqueue_info['total'], 'paging' => $select, 'list'=> $mailqueue_list));
		}else
        include(VIS_PATH_TEMPLATE.'mailqueue.php');
        return true;
    }

    function view_mailqueue($operation) {
        $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']:'';
         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_email']!='') $and_operations['email like "%'] = $data['vis_email'].'%"';
		   if($data['vis_department']!='')$and_operations['department_id="'] = $data['vis_department'].'"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		    if($data['vis_fetchtype']!='')$and_operations['mailqueue_type="'] = $data['vis_fetchtype'].'"';
        }
        return $this->mailqueue_display($operation, $and_operations, '', '', $page, $sort_by);
    }

    function mailqueue_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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            list($department_info, $department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'mailqueue.mailqueue_id='.$action[4];
            list($mailqueue_info, $mailqueue_details)=$object->get_mailqueue($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $mailqueue_details=$mailqueue_details[0];
            $operation['view_title']=$vis_language['TXTEMAILQUEUE'];
            include(VIS_PATH_TEMPLATE.'mailqueue_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    /*function view_smtp_details($operation) {
        global $vis_language;
        if(!isset($operation['vis_department'])) {
            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');
        $object=new class_setting($database);
        $filter=' department_id='.$operation['vis_department'];
        $smtp_details=$object->get_smtp_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($smtp_details!=-1) $smtp_details=$smtp_details[0];
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'smtp_details.php');
        return true;
    }*/

    function sla_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
		global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'sla.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'sla.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") ";
        }
	    $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($sla_info, $sla_details)=$object->get_sla($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($sla_info['total']==0)?0:ceil($sla_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $sla_info['sla_count']=(!$sla_details || $sla_details==-1)?0:count($sla_details);
        $sla_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTDOMAIN'];
		$operation['vis_current_operation']='view_sla';
		$operation['vis_current_module']='setting';
        $operation['view_title']=$vis_language['TXTSLA'];
		$operation['vis_operation']="new_sla";
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'sla_list.php');
			$sla_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'=>$sla_info['total'], 'paging' => $select, 'list'=> $sla_list));
			
		}else
        include(VIS_PATH_TEMPLATE.'sla.php');
        return true;
    }

    function view_sla($operation) {
        global $vis_language;
        $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']:'';
        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_sla']!='') $and_operations['sla_name like "%'] = $data['vis_sla'].'%"';
		 if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		}
	    return $this->sla_display($operation,$and_operations, '', '', $page, $sort_by);
    }

    function sla_details($operation) {
        global $vis_language;
 	    $operation['view_title']=$vis_language['TXTSLA'];
        $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.'setting.php');
            $object=new class_setting($database);
            list($schedule_info, $schedule_details)=$object->get_schedule('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'sla.sla_id='.$action[4];
            list($sla_info, $sla_details)=$object->get_sla($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $sla_details=$sla_details[0];
            include(VIS_PATH_TEMPLATE.'sla_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function schedule_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'schedule.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'schedule.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($schedule_info, $schedule_details)=$object->get_schedule($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($schedule_info1, $schedule_details1)=$object->get_schedule('', '', '', $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($schedule_info['total']==0)?0:ceil($schedule_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $schedule_info['schedule_tot_count']=(!$schedule_details1 || $schedule_details1==-1)?0:count($schedule_details1);
        $schedule_info['schedule_count']=(!$schedule_details || $schedule_details==-1)?0:count($schedule_details);
        $schedule_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTSCHEDULE'];
		$operation['vis_current_operation']='view_schedule';
		$operation['vis_current_module']='setting';
        include(VIS_PATH_TEMPLATE.'schedule.php');
        return true;
    }

    function view_schedule($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $operation['view_title']=$vis_language['TXTSCHEDULE'];
		$operation['vis_current_operation']='view_schedule';
		$operation['vis_current_module']='setting';
		$operation['vis_operation']="new_schedule";
        $database->database_disconnect();
        return $this->schedule_display($operation, '', '', '', $page, $sort_by);
    }

    function schedule_details($operation) {
        global $vis_language;
 	    $operation['view_title']=$vis_language['TXTSCHEDULE'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $filter=VIS_TABLE_PREFIX.'schedule.schedule_id='.$action[4];
        list($schedule_info, $schedule_details)=$object->get_schedule($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $schedule_details=$schedule_details[0];
        include(VIS_PATH_TEMPLATE.'schedule_view.php');
        return true;
    }

    function holiday_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'holiday.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'holiday.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($holiday_info, $holiday_details)=$object->get_holiday($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($holiday_info1, $holiday_details1)=$object->get_holiday('', '', '', $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($holiday_info['total']==0)?0:ceil($holiday_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $holiday_info['holiday_tot_count']=(!$holiday_details1 || $holiday_details1==-1)?0:count($holiday_details1);
        $holiday_info['holiday_count']=(!$holiday_details || $holiday_details==-1)?0:count($holiday_details);
        $holiday_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTHOLIDAYS'];
		$operation['vis_current_operation']='view_holiday';
		$operation['vis_current_module']='setting';
        include(VIS_PATH_TEMPLATE.'holiday.php');
        return true;
    }

    function view_holiday($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $operation['view_title']=$vis_language['TXTHOLIDAYS'];
		$operation['vis_current_operation']='view_holiday';
		$operation['vis_current_module']='setting';
		$operation['vis_operation']="new_holiday";
        $database->database_disconnect();
        return $this->holiday_display($operation, '', '', '', $page, $sort_by);
    }

    function language_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'language.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'language.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($language_info, $language_details)=$object->get_language($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($language_info['total']==0)?0:ceil($language_info['total']/$view_info['page_count']);
       
        $language_info['language_count']=(!$language_details || $language_details==-1)?0:count($language_details);
        $language_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTLANGUAGE'];
								
								for($i=0;$i<$language_info['language_count'];$i++) {
								$lang_values_total=$object->get_language_values_count('is_custom=0 and language_id='.$language_details[$i]['language_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
								$language_details[$i]['val_avilabilty']=($lang_values_total['total']>200)?1:0;
								}
								 $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'language.php');
        return true;
    }

    function view_language($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $operation['view_title']=$vis_language['TXTLANGUAGE'];
        $database->database_disconnect();
        return $this->language_display($operation, '', '', '', $page, $sort_by);
    }

    function language_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.'setting.php');
            $object=new class_setting($database);
            $filter=VIS_TABLE_PREFIX.'language.language_id='.$action[4].' ';
            list($language_info, $language_details)=$object->get_language($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $language_details=$language_details[0];
            include(VIS_PATH_TEMPLATE.'language_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function module_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'module.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'module.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter='is_custom=1';
        list($module_info, $module_details)=$object->get_module($filter, $limit, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($module_info['total']==0)?0:ceil($module_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $module_info['module_count']=(!$module_details || $module_details==-1)?0:count($module_details);
        $module_info['page']=$page;
        $view_info['view_count']=count($view_details);
        include(VIS_PATH_TEMPLATE.'modules.php');
        return true;
    }

    function view_modules($operation) {
        global $vis_language;
        $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']:'';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $operation['view_title']=$vis_language['TXTMODULE'];
        $operation['vis_operation']='new_module';
		$operation['vis_current_operation']='view_modules';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDMODULE'];
        $database->database_disconnect();
        return $this->module_display($operation, '', '', '', $page, $sort_by);
    }

    function module_details($operation){
        global $vis_language;
        $operation['view_title']=$vis_language['TXTMODULE'];
        if(!isset($operation['vis_module_id']) || !is_numeric($operation['vis_module_id'])) {
            $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
            $action=explode($spliter, $operation['vis_action']);
            $operation['vis_module_id']=$action[4];
        }
        if(isset($operation['vis_module_id']) && $operation['vis_module_id']!='' && is_numeric($operation['vis_module_id'])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $object=new class_setting($database);
            $filter=VIS_TABLE_PREFIX.'module.module_id='.$operation['vis_module_id'].' ';
            list($module_info, $module_details)=$object->get_module($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $module_details=$module_details[0];
            $module_sel=(isset($operation['vis_module_id']) && is_numeric($operation['vis_module_id']))?$operation['vis_module_id']:$module_details['module_id'];
			$module_setting=$object->get_module_setting(' module_id='.$module_sel, VIS_STAFF_ID, VIS_LOCATION_AREA);
            include(VIS_PATH_TEMPLATE.'module_view.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function etemplate_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'emailtemplate.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=")";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'emailtemplate.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter = ($filter!='')?$filter.' and language=1 ':' language=1 ';
        list($etemplate_info, $etemplate_details)=$object->get_etemplate($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($etemplate_info['total']==0)?0:ceil($etemplate_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $etemplate_info['etemplate_count']=(!$etemplate_details || $etemplate_details==-1)?0:count($etemplate_details);
        $etemplate_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $operation['view_title']=$vis_language['TXTEMAILTEMPLATES'];
		$operation['vis_current_operation']='view_etemplates';
        $operation['vis_current_module']='setting';
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'email_template_list.php');
			$email_template_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'=>$etemplate_info['total'], 'paging' => $select, 'list'=> $email_template_list));
		}else
        include(VIS_PATH_TEMPLATE.'email_template.php');
        return true;
    }

    function view_etemplates($operation) {
        global $vis_language;
        $operation['vis_current_operation']='view_etemplates';
        $operation['vis_current_module']='setting';
        $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']:'';
        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['etemplate_name like "%'] = $data['vis_title'].'%"';
		   if($data['vis_subject']!='')$and_operations['subject like"%'] = $data['vis_subject'].'%"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
       return $this->etemplate_display($operation,$and_operations, '', '', $page, $sort_by);
    }

    function etemplate_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTEMAILTEMPLATES'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if((isset($action[4]) && $action[4]!='' && is_numeric($action[4])) || $operation['vis_lang']!='') {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $object=new class_setting($database);
            list($language_info, $language_list)=$object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            if(isset($operation['vis_lang']) && $operation['vis_lang']!='')
            $filter='('.VIS_TABLE_PREFIX.'emailtemplate.parent_id='.$operation['vis_template_id'].' or '.VIS_TABLE_PREFIX.'emailtemplate.etemplate_id='.$operation['vis_template_id'].') and language='.$operation['vis_lang'].' ';
            else
            $filter=VIS_TABLE_PREFIX.'emailtemplate.etemplate_id='.$action[4].' ';
            list($etemplate_info, $etemplate_details)=$object->get_etemplate($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $etemplate_details=$etemplate_details[0];
            if(defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR==0) $etemplate_details['content'] = get_plain_text($etemplate_details['content']);
            $signature['content'] = $etemplate_details['content'];
            if(!isset($operation['vis_lang']) && $operation['vis_lang']==''){
				include(VIS_PATH_TEMPLATE.'email_template_view.php');
		    }
            else{
				if(!empty($etemplate_details)){
					 echo json_encode(array(
						'res' => $etemplate_details
					));
				} else {
					echo json_encode(array(
						'res' => 0
					));
				}
            }
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function customfield_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'customfield.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'customfield.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter .= ' location != 4 ';
        list($customfield_info, $customfield_details)=$object->get_customfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($customfield_info['total']==0)?0:ceil($customfield_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $customfield_info['customfield_count']=(!$customfield_details || $customfield_details==-1)?0:count($customfield_details);
        $customfield_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCUSTOMFIELD'];
		 if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'customfield_list.php');
			$staff_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'=>$customfield_info['total'], 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'customfields.php');
        return true;
    }

    function view_customfield($operation) {
        global $vis_language;
        $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']:'';
        $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);
        $operation['view_title']=$vis_language['TXTCUSTOMFIELD'];
        $operation['vis_operation']='new_custom_field';
		$operation['vis_current_operation']='view_customfield';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDNEWCUSTOMFIELD'];

		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_custom_field_group']!='')
			{
				$filter = "1 having customgroup_name like '%".$data['vis_custom_field_group']."%'"  ;
				$custom_group = $setting_object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
				$and_operations['customgroup_id'] = ' IN (';
				if($custom_group!=-1) {
				for($i=0;$i< (count($custom_group));$i++)
					$and_operations['customgroup_id'] .= $custom_group[$i]['customgroup_id'].',';
				$and_operations['customgroup_id'] = trim($and_operations['customgroup_id'],',');
				$and_operations['customgroup_id'] .= ')';
				}else $and_operations['customgroup_id'] .= '0)';
			}
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
        $database->database_disconnect(VIS_STAFF_ID, VIS_LOCATION_AREA);
        return $this->customfield_display($operation, $and_operations, '', '', $page, $sort_by);
    }

    function view_custom_groups($operation){
        global $vis_language;
        $operation['view_title']=$vis_language['TXTCUSTOMGROUP'];
        $operation['vis_operation']='new_custom_group';
		$operation['vis_current_operation']='view_custom_groups';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDCUSTOMGROUP'];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
 		$staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
   		$filter = "location!=4";
		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(isset($data['vis_grouptype']) && $data['vis_grouptype'] != "")
             {
                if($filter != '') {$filter .= " and location =".$data['vis_grouptype']; }
                else if($filter == ''){$filter .= " location =".$data['vis_grouptype']; }
            }
            else $filter .= "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        $custom_group_details=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        $custom_group_total=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $custom_group_total=(!$custom_group_total || $custom_group_total==-1)?0:count($custom_group_total);
		$group_info['group_count']= $custom_group_total;
		$view_info['page_count']=($custom_group_total==0)?0:ceil($custom_group_total/$view_info['page_count']);
        $database->database_disconnect();
		$group_info['page']=$page;
		 if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'custom_group_list.php');
			$staff_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'=>$custom_group_total, 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'custom_group.php');
    }

    function customfield_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTCUSTOMFIELD'];
        $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.'setting.php');
            $object=new class_setting($database);
            $filter1 = " location != 4 and is_enabled=1";
            $custom_group_details=$object->get_custom_group_list($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'customfield.field_group='.$action[4].' ';
            list($customfield_info, $customfield_details)=$object->get_customfield(1, $filter, '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA,'editpage');
			 $customfield_lang=$object->get_translation(22, 'data_id='.$customfield_details[0]['field_group'],VIS_STAFF_ID, VIS_LOCATION_AREA);
			 list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			 for($i=0;$i<count($customfield_details);$i++)
          { $customfield_option_lang=$object->get_translation(28, 'data_id='.$customfield_details[$i]['customfield_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);	 
			 $customfield_array_lang[]= $customfield_option_lang;
            }
            include(VIS_PATH_TEMPLATE.'custom_field_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGMISSINFO'];
            return false;
        }
    }
    function custom_group_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTCUSTOMGROUP'];
        $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.'setting.php');
			 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			 $sub_object=new class_subsetting($database);
			 list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'customgroup.customgroup_id='.$action[4].' ';
            $custom_group_details=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,'','editpage');
            $custom_department=explode(',', $custom_group_details[0]['department_access']);
			 $customgroup_lang=$object->get_translation(23, 'data_id='.$custom_group_details[0]['customgroup_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
            include(VIS_PATH_TEMPLATE.'custom_group_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function view_statuses($operation) {
        global $vis_language;
  		$database=new class_database();
  		 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
 		$staff=new class_staff($database);
        $object=new class_ticket($database);
        $setting_object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
   		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = " title like '%".$data['vis_title']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
		if(VIS_ADMIN_ACCESS_LEVEL==1)
        list($ticket_info, $status_details)=$object->get_ticket_status_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        else{
			
			list($ticket_info, $status_details)=$setting_object->get_properties('get_status', $filter,$limit,$data);
		}
        $view_info['page_count']=($ticket_info['total']==0)?0:ceil($ticket_info['total']/$view_info['page_count']);
        $ticket_info['ticket_count']=(!$status_details || $status_details==-1)?0:count($status_details);
		$ticket_info['page']=$page;
		$database->database_disconnect();
        $operation['view_title']=$vis_language['TXTSTATUS'];
        $operation['option_id']=1;
        $operation['vis_operation']='new_status';
		$operation['vis_current_operation']='view_statuses';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDSTATUS'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'status_list.php');
			$status_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'=>$ticket_info['total'], 'paging' => $select, 'list'=> $status_list ,'title'=> $operation['view_title']));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
        return true;
    }

    function status_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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket_object=new class_ticket($database);
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'ticket_status.status_id='.$action[4].' ';
            $status_details=$ticket_object->get_status_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $status_lang=$object->get_translation(0, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $status_details=$status_details[0];
            $staus_department=explode(',', $status_details['department_access']);
            $operation['view_title']=$vis_language['TXTSTATUS'];
			$ticket_object=new class_ticket($database);
			$ticket_status_details=$ticket_object->get_status_list('',VIS_STAFF_ID, VIS_LOCATION_AREA);
			$status_info['status_count']=(!$ticket_status_details || $ticket_status_details==-1)?0:count($ticket_status_details);
           include(VIS_PATH_TEMPLATE.'status_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

     function view_priorities($operation) {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_ticket($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = " title like '%".$data['vis_title']."%'"  ;
                //   $filter.= " and data_id=status_id";
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
			$filter = "";
			$data= "";
		}
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($ticket_info, $priority_details)=$object->get_ticket_priorities_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        else
			list($ticket_info, $priority_details)=$setting_object->get_properties('get_priorities', $filter,$limit,$data);
		
        $view_info['page_count']=($ticket_info['total']==0)?0:ceil($ticket_info['total']/$view_info['page_count']);
        $ticket_info['ticket_count']=(!$priority_details || $priority_details==-1)?0:count($priority_details);
		$ticket_info['page']=$page;
        $database->database_disconnect();
        $ticket_info['page']=$page;
        $operation['view_title']=$vis_language['TXTPRIORITY'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_priority';
        $operation['vis_current_operation']='view_priorities';
        $operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDPRIORITY'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'priority_list.php');
			$priority_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'=>$ticket_info['total'], 'paging' => $select, 'list'=> $priority_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
    }



      function view_flags($operation) {
        global $vis_language;
  		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
 		$staff=new class_staff($database);
        $object=new class_ticket($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
						$filter = "( title like '%".$data['vis_title']."%') ";
                       $filter.=' and '.VIS_TABLE_PREFIX.'language_data.data_id='.VIS_TABLE_PREFIX.'ticket_flag.flag_id and '.VIS_TABLE_PREFIX.'language_data.location=3 and '.VIS_TABLE_PREFIX.'language_data.language_id='.VIS_LANGUAGE;
				    
				  
				   
                //   $filter.= " and data_id=status_id";
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
			$filter = "";
			$data= "";
		} 
   		if(VIS_ADMIN_ACCESS_LEVEL==1)
   		{
			$flag_details=$object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA,$filter,'',$limit);
			$flag_details_total=$object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA,$filter,'');
				if($flag_details==-1 || empty($flag_details))
					$flag_total=0;
				else
				$flag_total=count($flag_details_total);
		 
		}
		else
		{
			list($flag_details_total, $flag_details)=$setting_object->get_properties('get_flags', '',$limit);
			if($flag_details==-1 || empty($flag_details))
					$flag_total=0;
				else
				$flag_total=count($flag_details_total);
			//$flag_total=count($flag_details_total); 	  
		}
		$ticket_info['ticket_count']= $flag_total;
		$view_info['page_count']=($flag_total==0)?0:ceil($flag_total/$view_info['page_count']);
        $database->database_disconnect();
		$ticket_info['page']=$page;
        $operation['view_title']=$vis_language['TXTFLAG'];
        $operation['option_id']=3;
        $operation['vis_operation']='new_flag';
		$operation['vis_current_operation']='view_flags';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDFLAG'];
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'flag_list.php');
			$flag_list = ob_get_clean();
			ob_end_flush();
			echo $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'=> $flag_total, 'paging' => $select, 'list'=> $flag_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
   }

    function view_types($operation) {
         global $vis_language;
  		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
 		$staff=new class_staff($database);
        $object=new class_ticket($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = " title like '%".$data['vis_title']."%'"  ;
                //   $filter.= " and data_id=status_id";
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
		if(VIS_ADMIN_ACCESS_LEVEL==1)
		list($ticket_info, $type_details)=$object->get_ticket_type_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		else
		list($ticket_info, $type_details)=$setting_object->get_properties('get_types', $filter,$limit,$data);
        $view_info['page_count']=($ticket_info['total']==0)?0:ceil($ticket_info['total']/$view_info['page_count']);
        $ticket_info['ticket_count']=(!$type_details || $type_details==-1)?0:count($type_details);
		$ticket_info['page']=$page;
        $database->database_disconnect();
		$ticket_info['page']=$page;
        $operation['view_title']=$vis_language['TXTTICKETTYPE'];
        $operation['option_id']=4;
        $operation['vis_operation']='new_type';
		$operation['vis_current_operation']='view_types';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDTICKETTYPE'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'type_list.php');
			$type_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'=>$ticket_info['total'], 'paging' => $select, 'list'=> $type_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
    }

    function view_channels($operation) {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
 		$staff=new class_staff($database);
        $object=new class_ticket($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
 		//$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']) && $view_info['page_count']>=$operation['vis_page'])?$operation['vis_page']:0;
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
   		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = " channel_name like '%".$data['vis_title']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
   		{
			$channel_details=$object->get_channel($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$channel_details_total=$object->get_channel($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
 
			if($channel_details==-1 )
			$channel_total= 0;	
 
			if($channel_details_total==-1 || empty($channel_details_total))
			$channel_total=0;
			else		
			$channel_total=count($channel_details_total);
		}else
		{
			list($channel_details_total, $channel_details)=$setting_object->get_properties('get_channel', '',$limit);
			if($channel_details_total==-1 || empty($channel_details_total))
			$channel_total = 0;
		    else
			$channel_total=$channel_details_total['total'];
		}
		$ticket_info['ticket_count']= $channel_total;
		$view_info['page_count']=($channel_total==0)?0:ceil($channel_total/$view_info['page_count']);
        $database->database_disconnect();
		$ticket_info['page']=$page;
		$operation['view_title']=$vis_language['TXTCHANNEL'];
        $operation['option_id']=5;
        $operation['vis_operation']='new_channel';
        $operation['vis_current_operation']='view_channels';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDCHANNEL'];
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'channel_list.php');
			$channel_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'=>$channel_total, 'paging' => $select, 'list'=> $channel_list ,'title'=> $operation['view_title']));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
        return true;
    }


    function workflow_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'workflow.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'workflow.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($workflow_info, $workflow_details)=$object->get_workflow($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($workflow_info['total']==0)?0:ceil($workflow_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $workflow_info['workflow_count']=(!$workflow_details || $workflow_details==-1)?0:count($workflow_details);
        $workflow_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTWORKFLOW'];
        $operation['vis_operation']='new_workflow';
		$operation['vis_current_operation']='view_workflow';
		$operation['vis_current_module']='setting';
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'workflow_list.php');
			$workflow_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'=>$workflow_info['total'], 'paging' => $select, 'list'=> $workflow_list));
		}else
        include(VIS_PATH_TEMPLATE.'workflow.php');
        return true;
    }

    function view_workflow($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTWORKFLOW'];
		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['workflow_name like "%'] = $data['vis_title'].'%"';
		 if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		}
       return $this->workflow_display($operation,$and_operations, '', '', $page, $sort_by);
    }

    function workflow_details($operation) {
        global $vis_language;
 	    $operation['view_title']=$vis_language['TXTWORKFLOW'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        //$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.'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');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket=new class_ticket($database);
            $client=new class_client($database);
            $staff=new class_staff($database);
            $setting=new class_setting($database);
            $sub_object=new class_subsetting($database);
            //list($info, $etemplate)=$setting->get_etemplate('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($workflow_info, $workflow_details)=$setting->get_workflow('workflow_id='.$action[4],'',0,0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $workflow_details=$workflow_details[0];
            if($workflow_details!='')
            {
            $workflow_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(',', $workflow_details['event']);
            for($i=0;$i<count($event);$i++) $workflow_event[$event[$i]]=1;
            $workflow_criteria=$setting->get_workflow_criteria($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $workflow_action=$setting->get_workflow_action($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            //print_r($workflow_action);
            //$forwardto=explode(',', $workflow_action[13]['content']);
            //print_r($forwardto);
            
            $domains=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);  $domains= $domains[1];
            for($i=0;$i<count($domains);$i++){
				$domain_list[]=$domains[$i]['domain_id'];
				$domain_ids=implode(",",$domain_list);
			}
			$user_groups=$client->get_client_group('is_enable=1 and (domain_id in ('.$domain_ids.') or domain_id=0 )', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $departments=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA); $departments=$departments[1];
            list($sla_count,$sla)=$setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($schedule_count,$schedule)=$setting->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($etemplate_count,$etemplate)=$setting->get_etemplate('is_enabled=1 and language=1','',0,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($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 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) {
			$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');
			$flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=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');
			list($category_info,$ticket_category)=$setting->get_ticket_category_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($subcategory_info,$ticket_subcategory)=$setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($item_info,$ticket_item)=$setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($level_info,$ticket_level)=$setting->get_ticket_level_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			} 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', 'is_enabled=1');	$label_details=$label_details[1];
			$channel_details=$setting->get_properties('get_channel', 'is_enabled=1');$channel_details=$channel_details[1];
			$ticket_category=$setting->get_properties('get_ticket_category', 'is_enabled=1');$ticket_category=$ticket_category[1];
			$ticket_subcategory=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1');$ticket_subcategory=$ticket_subcategory[1];
			$ticket_item=$setting->get_properties('get_ticket_item', VIS_TABLE_PREFIX.'ticket_item.is_enabled=1');$ticket_item=$ticket_item[1];
			$ticket_level=$setting->get_properties('get_ticket_level', 'is_enabled=1');$ticket_level=$ticket_level[1];
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			}
            //list($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            include(VIS_PATH_TEMPLATE.'workflow_details.php');
            return true;
			}
            else
			{
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
				return false;
			}
			//}
    }

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

    function get_backup($operation){
        set_time_limit(0);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $tmp=$object->db_details($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($dbname, $db)=$tmp;
        include(VIS_PATH_TEMPLATE.'db_backup.php');
        $database->database_disconnect();
        return true;
    }

    function module_setting($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staffobject=new class_staff($database);
        list($dpinfo, $department)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($dminfo, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_sel=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
        $filter=VIS_TABLE_PREFIX.'module.module_id='.$operation['vis_module_id'].' ';
        list($module_info, $module_details)=$object->get_module('module_id='.$operation['vis_module_id'], 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $module_details=$module_details[0];
        $module_sel=(isset($operation['vis_module_id']) && is_numeric($operation['vis_module_id']))?$operation['vis_module_id']:$module_details['module_id'];
        $module_setting=$object->get_module_setting('domain_id='.$domain_sel.' and module_id='.$module_sel, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff_filter=VIS_TABLE_PREFIX.'staff.is_enabled=1';
        list($staff_count,$staff_list)=$object->get_staff($staff_filter,'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staffgroup_info, $staff_group)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$staff_owner=is_numeric($module_setting['vis_staff_access'])?array(0=>$module_setting['vis_staff_access']):explode(',', $module_setting['vis_staff_access']);
        $team_owner=is_numeric($module_setting['vis_staff_group_access'])?array(0=>$module_setting['vis_staff_group_access']):explode(',', $module_setting['vis_staff_group_access']);
		if($module_details['module'] == 'solutions') $module_details['module'] = 'selfhelp';
        if(!file_exists(VIS_PATH_TEMPLATE.$module_details['module'].'_module_setting.php')) {
           // echo $vis_language['MSGSETTUNAVIL'];
		    echo -1;
            return -1;
        }
        include(VIS_PATH_TEMPLATE.$module_details['module'].'_module_setting.php');
        $database->database_disconnect();
        return true;
    }

    function priority_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTPRIORITY'];
        $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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket_object=new class_ticket($database);
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'ticket_priority.priority_id='.$action[4].' ';
            $priority_details=$ticket_object->get_priorities_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter);
            $priority_lang=$object->get_translation(1, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $priority_details=$priority_details[0];
            $priority_department=explode(',', $priority_details['department_access']);
            include(VIS_PATH_TEMPLATE.'priority_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function type_details($operation) {
        global $vis_language;
	 	 $operation['view_title']=$vis_language['TXTTICKETTYPE'];
        $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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket_object=new class_ticket($database);
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'ticket_type.type_id='.$action[4].' ';
            $type_details=$ticket_object->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter);
            $type_lang=$object->get_translation(2, 'data_id='.$action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info, $language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $type_details=$type_details[0];
            $type_department=explode(',', $type_details['department_access']);
            include(VIS_PATH_TEMPLATE.'type_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function flag_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTFLAG'];
        $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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$sub_object=new class_subsetting($database);
            $ticket_object=new class_ticket($database);
            $object=new class_setting($database);
            $filter=VIS_TABLE_PREFIX.'ticket_flag.flag_id='.$action[4].' ';
            $flag_details=$ticket_object->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter);
            $flag_lang=$object->get_translation(3, 'data_id='.$action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info, $language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $flag_details=$flag_details[0];
            $flag_department=explode(',', $flag_details['department_access']);
            include(VIS_PATH_TEMPLATE.'flag_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
    function label_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTLABEL'];
        $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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $sub_object=new class_subsetting($database);
            $ticket_object=new class_ticket($database);
            $object=new class_setting($database);
            $label_details=$ticket_object->get_labels_list('label_id="'.$action[4].'"', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $label_lang=$object->get_translation(3, 'data_id='.$action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info, $language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $label_details=$label_details[0];
            $label_department=explode(',', $label_details['department_access']);
            include(VIS_PATH_TEMPLATE.'label_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function holiday_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTHOLIDAYS'];
        $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.'setting.php');
            $object=new class_setting($database);
            list($schedule_info, $schedule_details)=$object->get_schedule('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'holiday.holiday_id='.$action[4].' ';
            $holiday_details=$object->get_holiday_list(VIS_STAFF_ID, VIS_LOCATION_AREA, $filter);
            $holiday_details=$holiday_details[0];
            include(VIS_PATH_TEMPLATE.'holiday_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function get_flag_delete($operation) {
        global $vis_language;
        if($operation['vis_flag_id']==1) {
            $message_info['vis_form_title']=$vis_language['TXTDELFLAG'];
            $message_info['vis_message']=$tinfo['total'].' '.$vis_language['MSGDELETEDEF'];
            $message_info['vis_event']='';
            include(VIS_PATH_TEMPLATE.'confirm_delete.php');
            return true;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        list($tinfo, $tickets)=$object->get_ticket(VIS_TABLE_PREFIX.'ticket.flag_id='.$operation['vis_flag_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($tickets!=-1) {
            $message_info['vis_form_title']=$vis_language['TXTDELFLAG'];
            $message_info['vis_message']=$tinfo['total'].' '.$vis_language['MSGFLCNDEL'];
            $message_info['vis_event']='';
        }
        else {
            $message_info['vis_form_title']=$vis_language['TXTDELFLAG'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
			$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
			if($operation['count'] > 1)
	            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_flag', 'vis_flag_id':".$operation['vis_flag_id'].",'vis_page':'".$vis_page."'})";
			else
				 $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_flag', 'vis_flag_id':".$operation['vis_flag_id']."})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function get_staff_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_staff';
        $operation['vis_current_module']='subsetting';
        $message_info['vis_form_title']=$vis_language['TXTDELSTAFF'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_staff_id':".$operation['vis_staff_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function get_staffgroup_delete($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($tinfo, $tickets)=$object->get_staff(VIS_TABLE_PREFIX.'staff_group.group_id='.$operation['vis_staffgroup_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($tickets!=-1) {
            $message_info['vis_form_title']=$vis_language['TXTDELSTAFFGROUP'];
            $message_info['vis_message']=$vis_language['MSGSFCNDEL'];
            $message_info['vis_event']='';
        }
        else {
            $message_info['vis_form_title']=$vis_language['TXTDELSTAFFGROUP'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_staffgroup', 'vis_staffgroup_id':".$operation['vis_staffgroup_id']."})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function view_sentmail($operation) {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $database=new class_database();
        $object_ticket = new class_ticket($database);
        $staff=new class_staff($database);
        $object=new class_setting($database);
        $department_details = $object_ticket->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1',VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(isset($operation['vis_page']) && $operation['vis_page'] != '') $page=(is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        else if(isset($operation['pageing'])) $page = $operation['pageing'];
        else $page=0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
         if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_sub']) && $data['vis_sub'] != "")
            {
                   $filter = " subject like '%".$data['vis_sub']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_to']) && $data['vis_to'] != "")
            {
                if($filter != '') {$filter .= " and mail_to like '%".$data['vis_to']."%'";}
                else if($filter == ''){$filter .= " mail_to like '%".$data['vis_to']."%'"; }
            }
            else $filter .= "";
            if((isset($data['from_date']) && $data['from_date'] != "") && (isset($data['to_date']) && $data['to_date'] != ""))
            {
				$from=date('Y-m-d h:i:s',  strtotime($data['from_date']));
                $to=date('Y-m-d h:i:s',  strtotime($data['to_date']));
                if($filter != '') {$filter .= " and send_date between unix_timestamp('".$from."')  AND unix_timestamp('".$to."')";}
                else if($filter == ''){$filter .= " send_date between unix_timestamp('".$from."') AND unix_timestamp('".$to."')"; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
        if($operation['is_inbox']==1){
			    $is_inbox_page=1;
                if($filter != '') {$filter .= " and staff_id=".VIS_STAFF_ID." "; }
                else if($filter == ''){$filter .= " staff_id=".VIS_STAFF_ID." "; }
        }else if(isset($operation['vis_action'])){
            $actions=explode("/", $operation['vis_action']);
            if(isset($actions[4]) && is_numeric($actions[4])) {
                $is_inbox_page=1;
                if($filter != '') {$filter .= " and staff_id=".VIS_STAFF_ID." "; }
                else if($filter == ''){$filter .= " staff_id=".VIS_STAFF_ID." "; }
            }
            else $is_inbox_page=0;
        }
        list($sentlog_info, $sentlog_details)=$object->get_sentmail($filter, $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($sentlog_info['total']==0)?0:ceil($sentlog_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTSENTMAILLOG'];
        $operation['vis_operation']='get_sentmail_delete';
		$operation['vis_current_operation']='view_sentmail';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTDELETE'];
        if($operation['is_inbox']==1)  $operation['vis_action']='#/setting/view_sentmail/Sent email/'.VIS_STAFF_ID;
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
            if($operation['is_inbox']==1) $is_inbox_page=1;
			include(VIS_PATH_TEMPLATE.'sentmail_list.php');
			$mail_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'=>$sentlog_info['total'], 'paging' => $select, 'list'=> $mail_list));
		}else include(VIS_PATH_TEMPLATE.'sentmail.php');
        return true;
    }

    function sentmail_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTSENTMAIL'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
        list($sentlog_info, $sentlog_details)=$object->get_sentmail('sent_mail_id='.$action[4], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $sentlog_details=$sentlog_details[0];
        $database->database_disconnect();
        $is_inbox_page=1;
        include(VIS_PATH_TEMPLATE.'sentmail_details.php');
        return true;
    }
	
	function sentmail_details_log($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTSENTMAILLOG'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
        list($sentlog_info, $sentlog_details)=$object->get_sentmail('sent_mail_id='.$action[4], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $sentlog_details=$sentlog_details[0];
        $database->database_disconnect();
        $is_inbox_page=0;
        include(VIS_PATH_TEMPLATE.'sentmail_details.php');
        return true;
    }

    function get_sentmail_delete($operation) {
        global $vis_language;
		$operation['vis_action'] = str_replace(",","&", $operation['vis_action']);
        if(isset($operation['vis_sentmail_area']) && $operation['vis_sentmail_area']==0) {
            $message_info['vis_form_title']=$vis_language['MSGMTMLOG'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'empty_sentmail'})";
        }
        else {
            $message_info['vis_form_title']=$vis_language['MSGDELMLOG'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('submit_form', {'vis_module':'setting', 'vis_operation':'delete_sentmail', 'vis_action':'".$operation['vis_action']."', 'vis_form':'vis_sentmail_form'})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function empty_sentmail($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->empty_table('sent_mail_log', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_sentmail_delete_area").dialog("close"); </script>';
        }
        else {
			$activity_log=$object->add_staff_activity_log("Empty sent mail log list", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_sentmail"}); </script>';
		}
        $database->database_disconnect();
        return $ret;
    }

    function view_errorlog($operation) {
        global $vis_language;
        $filename=VIS_PATH_LOG.'vis_error_log';
        $size=filesize($filename);
        if($size==0) $error_log="\n\n------------------ ".$vis_language['MSGERRLGEMT']." ------------------\n\n";
        else {
            $error_log="\n\n------------------ ".$vis_language['TXTERRORLOG']." ------------------\n\n";
            $fhandle=fopen($filename, 'r');
            $error_log.=fread($fhandle, $size);
            fclose($fhandle);
        }
        $filename=VIS_PATH_LOG.'vis_exception_log';
        $size=filesize($filename);
        if($size==0) $error_log.="\n\n------------------ ".$vis_language['MSGEXPLGEMT']." ------------------\n\n";
        else {
            $error_log.="\n\n------------------ ".$vis_language['TXTEXPLOG']." ------------------\n\n";
            $fhandle=fopen($filename, 'r');
            $error_log.=fread($fhandle, $size);
            fclose($fhandle);
        }
        $error_log=nl2br($error_log);
        include(VIS_PATH_TEMPLATE.'error_log.php');
        return true;
    }

    function get_error_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELERRLOG'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_errorlog'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function view_parser_log($operation) {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_setting($database);
        $client_object=new class_client($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_sub']) && $data['vis_sub'] != "")
            {
                   $filter = " subject like '%".$data['vis_sub']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_from']) && $data['vis_from'] != "")
            {
                if($filter != '') {$filter .= " and from_email like '%".$data['vis_from']."%'";}
                else if($filter == ''){$filter .= " from_email like '%".$data['vis_from']."%'"; }
            }
            else $filter .= "";
             if((isset($data['from_date']) && $data['from_date'] != "") && (isset($data['to_date']) && $data['to_date'] != ""))
            {
				$from=date('Y-m-d h:i:s',  strtotime($data['from_date']));
                $to=date('Y-m-d h:i:s',  strtotime($data['to_date']));
                if($filter != '') {$filter .= " and entry_date between unix_timestamp('".$from."')  AND unix_timestamp('".$to."')";}
                else if($filter == ''){$filter .= " entry_date between unix_timestamp('".$from."') AND unix_timestamp('".$to."')"; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
        list($parserlog_info, $parserlog_details)=$object->get_parser_log($filter, $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        //list($client_info, $client_details)=$client_object->get_client('parent_id = 0', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($parserlog_info['total']==0)?0:ceil($parserlog_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTPARSERLOG'];
        $operation['vis_operation']='get_parserlog_delete';
		$operation['vis_current_operation']='view_parser_log';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTDELETE'];
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'parser_log_list.php');
			$parser_log_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'=>$parserlog_info['total'], 'paging' => $select, 'list'=> $parser_log_list));
		}else
        include(VIS_PATH_TEMPLATE.'parser_log.php');
        return true;
    }

    function parserlog_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTPARSERLOG'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
        list($parserlog_info, $parserlog_details)=$object->get_parser_log('parserlog_id='.$action[4], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
       
        $parserlog_details=$parserlog_details[0];
        $filename = $parserlog_details['filename'];
         if($filename!='')
         {
		$fpath=VIS_PATH_PARSERLOG.$filename;		
        $source_file = fopen($fpath, "r" ) or die("Couldn't open $filename");
		while (!feof($source_file)) {
			$buffer.= fread($source_file,filesize($fpath)); 				   
			}
		}else
		{$log_detail=$object->get_parser_data($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);}     
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'parserlog_details.php');
        return true;
    }

    function get_parserlog_delete($operation) {
        global $vis_language;
        $operation['vis_action'] = str_replace(",","&", $operation['vis_action']);
        if(isset($operation['vis_parserlog_area']) && $operation['vis_parserlog_area']==0) {
            $message_info['vis_form_title']=$vis_language['TXTEMTPARSLOG'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'empty_parserlog'})";
        }
        else {
            $message_info['vis_form_title']=$vis_language['TXTDELPARSLOG'];
            $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('submit_form', {'vis_module':'setting', 'vis_operation':'delete_parserlog', 'vis_form':'vis_parserlog_form', 'vis_action':'".$operation['vis_action']."','vis_page':'".$vis_page."'})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function empty_parserlog($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->empty_table('parserlog', VIS_STAFF_ID, VIS_LOCATION_AREA) && $object->empty_table('parser_data', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_parserlog_delete_area").dialog("close"); </script>';
        }
        else {
			$activity_log=$object->add_staff_activity_log("Empty parser log list", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_parser_log"}); </script>';
		}
        $database->database_disconnect();
        return $ret;
    }
     function breakline_display($operation, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
       if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'breaklines.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'domain.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
        list($breaklines_info, $breaklines)=$object->get_breaklines($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($breaklines_info['total']==0)?0:ceil($breaklines_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $breaklines_info['breaklines_count']=(!$breaklines || $breaklines==-1)?0:count($breaklines);
        $breaklines_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $operation['view_title']=$vis_language['TXTBREAKLINES'];
		$operation['vis_current_operation']='view_breaklines';
        $operation['vis_current_module']='setting';
        include(VIS_PATH_TEMPLATE.'breakline.php');
        return true;
    }
    function view_breaklines($operation) {
		$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']:'';
        return $this->breakline_display($operation, '',  $page, $sort_by);
    }

    function get_breakline_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_breakline';
        $operation['vis_current_module']='setting';
        $message_info['vis_form_title']=$vis_language['TXTDELBREAKLINE'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_breakline_id':".$operation['vis_breakline_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }



    function migrations($operation) {
        include(VIS_PATH_TEMPLATE.'migration.php');
        return true;
    }

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

    function migration_vision_final($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!isset($data['vision_details'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGMGRTDANTSEL'].'"); </script>';
            include(VIS_PATH_TEMPLATE.'migration_vision_one.php');
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($success, $ret)=$object->migrate_vision2($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'].'<br />'.$ret.'"); </script>';
            return false;
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
        return true;
    }



    function get_workflow_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELWRKFLOW'];
        $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':'setting', 'vis_operation':'delete_workflow', 'vis_workflow_id':".$operation['vis_workflow_id'].", 'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function view_single_login($operation){
        include(VIS_PATH_TEMPLATE.'single_login.php');
    }

    function single_login_details($operation){
	    $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $currentPage = $action[3];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $vis_login_type=$action[4];
        include(VIS_PATH_TEMPLATE.'single_login_view.php');
        return true;
        }
    }
	function single_login_domain_details($operation) {
        global $vis_language;
	    if(!isset($operation['vis_department'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDOMAINNOTFOUND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $filter=' login_type='.$operation['vis_login_type'].' and domain_id='.$operation['vis_department'];
        $smtp_details=$object->get_single_login_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $smtp_details=$smtp_details[0];
        $database->database_disconnect();
        if($operation['vis_login_type']==15) {
			 include(VIS_PATH_TEMPLATE.'single_login_details_ad.php');
		} else if($operation['vis_login_type']==16 || $operation['vis_login_type']==17 || $operation['vis_login_type']==18 || $operation['vis_login_type']==19 || $operation['vis_login_type']==20 || $operation['vis_login_type']==21 || $operation['vis_login_type']==23 || $operation['vis_login_type']==26) {
			include(VIS_PATH_TEMPLATE.'single_login_social_setting.php');
		} else {
			include(VIS_PATH_TEMPLATE.'single_login_details.php');
		}
        return true;
    }

    function view_integration($operation){
        include(VIS_PATH_TEMPLATE.'integration.php');
    }

    function integration_details($operation){
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_setting($database);
        $object_staff=new class_staff($database);
        list($view_info, $view_details)=$object_staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($whmcs_info, $whmcs_details)=$object->get_integration_details($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$view_info['page_count']=($whmcs_info['total']==0)?0:ceil($whmcs_info['total']/$view_info['page_count']);
        list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);

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

    function integration_domain_details($operation) {
        global $vis_language;
        if(!isset($operation['vis_department']) && $_REQUEST['vis_integration_id']!=4) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGDOMAINNOTFOUND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        $twitter_details=-1;
        $domain=$operation['vis_department'];
        $filter=($_REQUEST['vis_integration_id']!=4)?('integration_type='.$_REQUEST['vis_integration_id'].' and domain_id='.$domain):('integration_type='.$_REQUEST['vis_integration_id']);
        $smtp_details=$object->get_integration_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $department)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.$domain, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($smtp_details!=-1 && $_REQUEST['vis_integration_id']!=4) $smtp_details=$smtp_details[0];
        if($_REQUEST['vis_integration_id']==1) include(VIS_PATH_TEMPLATE.'integration_details.php');
        elseif($_REQUEST['vis_integration_id']==2) {
            $twitter_details=$smtp_details;
            include(VIS_PATH_TEMPLATE.'tw_integration_details.php');
        }
        elseif($_REQUEST['vis_integration_id']==3) {
            $sms_details=$smtp_details;
            include(VIS_PATH_TEMPLATE.'sms_integration_details.php');
        }
        elseif($_REQUEST['vis_integration_id']==4) {
            $facebook_details=$smtp_details;
            $setting=$object->get_settings('title="fb_app_id" or title="fb_secret" or title="fb_canvas_url"', VIS_STAFF_ID, VIS_LOCATION_AREA);
            include(VIS_PATH_TEMPLATE.'fb_integration_details.php');
        }
        $database->database_disconnect();
        return true;
    }

	 function staff_signature($operation) {
		$data=parse_form_array($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.'setting.php');
        $object=new class_setting($database);
        $object1=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff_object=new class_staff($database);
        list($forum_info, $forum_modules)=$object->get_module('is_enabled=1 and module_id=12 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($forum_modules!=-1) $mod_forum=1;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
        list($dpinfo, $department)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '',0, VIS_TABLE_PREFIX.'domain.domain_id asc,'.VIS_TABLE_PREFIX.'department.department_id asc ', VIS_STAFF_ID, VIS_LOCATION_AREA);
        /*$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($staff_details[$i]['department_access']==0){
                 $staff_details[$i]['department'] = $object->get_department_access(VIS_TABLE_PREFIX.'department.is_enabled=1', 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 = 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 .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                }else $filter=VIS_TABLE_PREFIX.'department.is_enabled=1';
                $staff_details[$i]['department'] = $object->get_department_access($filter, 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 .=' ) and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
                $staff_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            }
        }*/
        list($dmin, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, ' domain_id asc ', 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);
		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'];
					}
			//elseif($signature[$i]['is_forum']==1)
			  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.'staff_signature.php');
        return true;
    }

    function get_customgroup_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETECUSTOMGROUP'];
        $message_info['vis_message']=$vis_language['MSGCUSTOMGRPDEL'];
		$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_customgroup', 'vis_customgroup_id':".$operation['vis_customgroup_id'].", 'vis_page':".$vis_page."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
    function get_customfield_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETECUSTOMFIELD'];
        $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':'setting', 'vis_operation':'delete_customfield', 'vis_fieldgroup_id':".$operation['vis_fieldgroup_id'].", 'vis_page':".$vis_page."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function get_etemplate_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_etemplate';
		$operation['vis_current_module']='setting';
        $message_info['vis_form_title']=$vis_language['TXTDELETEETEMPLATE'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_etemplate', 'vis_etemplate_id':".$operation['vis_etemplate_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function toggle_breakline($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->toggle_breakline($operation['vis_line_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>';
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_module_setting_div").tabs("load", $("#vis_module_setting_div").tabs("option", "selected")); </script>';
        return $ret;
    }

    function get_delete_smtp($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETESMTP'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_smtp', 'vis_smtp_id':".$operation['vis_smtp_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

	function view_license($operation) {
        include(VIS_PATH_TEMPLATE.'license.php');
        return true;
    }

    function portal_setting($operation) {
		
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($info, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_id=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
		$setting=$object->get_settings('(title like "vis_head_menu_%" or title="vis_theme_color" or title="vis_portal_logo" or title="vis_portal_text" or title="vis_portal_text_bold" or title="vis_portal_text_italic" or title="vis_portal_text_colour" or title="vis_manage_logo" or title="vis_date_format" or title="vis_datetime_format" or title="vis_satellite_helpdesk" or title="vis_favicon") and (domain_id='.$domain_id.' or domain_id=0)', VIS_STAFF_ID, VIS_LOCATION_AREA);
        	
        $default_set=$object->get_settings('title="vis_default_home_operation" and domain_id='.$domain_id, VIS_CLIENT_ID, VIS_LOCATION_AREA);
        $default_set_after_login=$object->get_settings('title="vis_default_page_after_login" and domain_id='.$domain_id, VIS_CLIENT_ID, VIS_LOCATION_AREA);
        list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
	
		$filter=VIS_TABLE_PREFIX.'domain.domain_id='.$domain_id.' ';
        list($domain_info, $domain_details)=$object->get_domain($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_details=$domain_details[0];
		
        foreach($modules as $var) $module[$var['module']]=1;
		$default_home = ($default_set == -1) ? 'selfhelp:home' : $default_set[0]['content'];
		$default_home_after_login = $default_set_after_login[0]['content'];
        $database->database_disconnect();
	    if($setting!=-1) for($i=0;$i<count($setting);$i++) {
            if(preg_match('/vis_head_menu_(.*)/', $setting[$i]['title'], $match)) {
                $poral_setting[strtolower($match[1])]=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_theme_color') {
                $poral_setting['theme_color']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_portal_logo') {
                $poral_setting['vis_portal_logo']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_portal_text') {
                $poral_setting['vis_portal_text']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_bold') {
                $poral_setting['vis_portal_text_bold']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_italic') {
                $poral_setting['vis_portal_text_italic']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_colour') {
                $poral_setting['vis_portal_text_colour']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_logo') {
                $poral_setting['vis_manage_logo']=$setting[$i]['content'];
            }
			 elseif($setting[$i]['title']=='vis_date_format') {
                $poral_setting['vis_date_format']=$setting[$i]['content'];
            }
			 elseif($setting[$i]['title']=='vis_datetime_format') {
                $poral_setting['vis_datetime_format']=$setting[$i]['content'];
            }
			 elseif($setting[$i]['title']=='vis_satellite_helpdesk') {
               $poral_setting['vis_satellite_helpdesk']=$setting[$i]['content'];
            }
           elseif($setting[$i]['title']=='vis_favicon') {
                $poral_setting['vis_favicon']=$setting[$i]['content'];
            }
        }
        if(!isset($poral_setting['home'])) $poral_setting['home']=1;
        if(!isset($poral_setting['submitticket'])) $poral_setting['submitticket']=1;
        if(!isset($poral_setting['viewticket'])) $poral_setting['viewticket']=1;
        if(!isset($poral_setting['billing'])) $poral_setting['billing']=0;
        if(!isset($poral_setting['selfhelp'])) $poral_setting['selfhelp']=1;
		 if(!isset($poral_setting['forum'])) $poral_setting['forum']=1;
        if(!isset($poral_setting['register'])) $poral_setting['register']=1;		
		if(!isset($poral_setting['service'])) $poral_setting['service']=1;
		if(!isset($poral_setting['rating'])) $poral_setting['rating']=1;
        if(!isset($poral_setting['staffnm'])) $poral_setting['staffnm']=1;
		if(!isset($poral_setting['theme_color'])) $poral_setting['theme_color']="#588f27";
		if(!isset($poral_setting['vis_manage_logo'])) $poral_setting['vis_manage_logo']='image';
		if(!isset($poral_setting['vis_satellite_helpdesk'])) $poral_setting['vis_satellite_helpdesk'] = 1;
        if(!isset($poral_setting['login'])) $poral_setting['login']=1;
        if(!isset($poral_setting['close_ticket'])) $poral_setting['close_ticket']=1;
        if(!isset($poral_setting['solution_ticket_search'])) $poral_setting['solution_ticket_search']=1;
		
		$themes=array();
		if ($d=@dir(VIS_PATH_CLIENT_THEME)) while (false!==($entry = $d->read())) if(@is_dir(VIS_PATH_CLIENT_THEME.$entry) && $entry!='.' && $entry!='..') $themes[]=$entry;
        $operation['view_title']=$vis_language['TXTCLIENTPORTAL'];
		$operation['vis_current_operation']='portal_setting';
		$operation['vis_current_module']='setting';
		if($operation['vis_satellite_helpdesk']) { 
			include(VIS_PATH_TEMPLATE.'portal_setting_form.php');
		}
		else
        {include(VIS_PATH_TEMPLATE.'portal_setting.php');}
        return true;
    }

    function etemplates_mapping($operation) {
		 global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        list($info, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_id=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
        list($etemplate_info, $etemplates)=$object->get_etemplate('is_enabled=1 and language=1 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $setting=$object->get_settings('title="vis_etemplate_map" and domain_id='.$domain_id, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $template_map_a=($setting==-1)?'1,2,3,4,5,6,9,10,11,12,18,17,19':$setting[0]['content'];
        $template_map=explode(',', $template_map_a);
		 include(VIS_PATH_TEMPLATE.'etemplate_map.php');
	}
    function etemplates_view($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        foreach($modules as $var) $module[$var['module']]=1;
        list($info, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_id=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
		list($etemplate_info, $etemplates)=$object->get_etemplate('is_enabled=1 and language=1 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $setting=$object->get_settings('title="vis_etemplate_map" and domain_id='.$domain_id, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $template_map_a=($setting==-1)?'1,2,3,4,5,6,9,10,11,12,18,17,19':$setting[0]['content'];
        $template_map=explode(',', $template_map_a);
		include(VIS_PATH_TEMPLATE.'etemplate_view.php');
        return true;
    }

    function save_twitter_details($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(trim($data['vis_title'])=='' || trim($data['vis_conkey'])=='' || trim($data['vis_conskey'])=='' || trim($data['vis_usrkey'])=='' || trim($data['vis_usrskey'])=='') {
            echo $vis_language['MSGINFOMISS'];
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->save_twitter($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>';
        }
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $(this).visInterface("remove_tab", "vis_module_setting_div"); </script>';
        return $ret;
    }

    function staff_password_reset($operation) {
		$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);
	    include(VIS_PATH_TEMPLATE.'staff_pass_reset.php');
        return true;
    }

    function upload_logo($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $portal='';
        if(isset($operation['portal']) && $operation['portal']=='manage')
        { $portal='manage';}
        else if(isset($operation['portal']) && $operation['portal']=='favicon')
        {$portal='favicon';}
        else if(isset($operation['portal']) && $operation['portal']=='manage_favicon')
        {$portal='manage_favicon';}
         
        $ret=$object->upload_file($_FILES, $operation, VIS_DOMAIN, 0, VIS_STAFF_ID, VIS_LOCATION_AREA, $portal);
      
        $database->database_disconnect();
        if(!$ret) { ?>
            <script> parent.$("#vis_global_msg_div").visInterface("load_global_message", "<?= $vis_language['MSGERROPRT']; ?>"); </script>; <?
            return false;
        }
        else {
			$clear_client_logo_Btn = $clear_manage_logo_Btn =$message='';
			$clear_manage_favicon_Btn=$message='';
			$clear_client_favicon_Btn=$message='';
			$message.='<img height=\"80px\" src=\"'.VIS_PATH_PROFILE.$ret.'\" />';
			//$message1.='<img height=\"80px\" src=\"'.VIS_PATH_MANAGE.$ret.'\" />';
			//$message2.='<img height=\"80px\" src=\"'.VIS_PATH.$ret.'\" />';
			$clear_client_logo_Btn.= '<button type=\"button\" id=\"clear_client_logo_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_logo();\">'.$vis_language['TXTCLEAR'].'</button>';
			$clear_manage_logo_Btn.= '<button type=\"button\" id=\"clear_manage_logo_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_manage_logo();\">'.$vis_language['TXTCLEAR'].'</button>';
			$clear_client_favicon_Btn.= '<button type=\"button\" id=\"clear_client_favicon_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_favicon();\">'.$vis_language['TXTCLEAR'].'</button>';
			$clear_manage_favicon_Btn.= '<button type=\"button\" id=\"clear_manage_favicon_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_manage_favicon();\">'.$vis_language['TXTCLEAR'].'</button>';
			 if($operation['portal']=='manage'){	?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_manage_logo_Btn ?>","vis_manage_portal":1}); </script>
            <? } else if($operation['portal']=='favicon') {?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_client_favicon_Btn ?>","vis_favicon_client_portal":1}); </script>; <? }
            else if($operation['portal']=='manage_favicon') {?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_manage_favicon_Btn ?>","vis_favicon_manage_portal":1}); </script>; <? }
            else {?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_client_logo_Btn ?>","vis_client_portal":1}); </script>; <? }
        }
        return true;
    }

     function fb_integration($operation){
		global $vis_language;
		if(isset($operation['vis_action'])){
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$integration_id = $action[3];
		}
		else{
			$integration_id = $_REQUEST['integration_id'];
		}
	    $filter='integration_id='.$integration_id;
		$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.'subsetting.php');
		$sub_object=new class_subsetting($database);
        list($fb_count,$settings)=$object->get_fb_details($filter, $limit='', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		if(!isset($settings[0]['host_name']) || trim($settings[0]['host_name'])=='' || !isset($settings[0]['api_key']) || trim($settings[0]['api_key'])=='' || !isset($settings[0]['billing_url']) || trim($settings[0]['billing_url'])=='') {
           echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGFACEBOOKERROR'].'"); </script>';
		   return false;
        }
		$app_id = $settings[0]['host_name'];
		$app_secret = base64_decode($settings[0]['api_key']);
        if($settings[0]['user_name']==NULL){			
			$my_url=$settings[0]['billing_url'].'manage/?vis_module=setting&vis_operation=fb_integration&integration_id='.$integration_id;
			$code = $_REQUEST["code"];
			if(empty($code)) {
				$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
				 $dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
				. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
				. $_SESSION['state'] . "&scope=manage_pages,user_posts,publish_actions";
	
			   echo '<script language="javascript">window.open("'.$dialog_url.'", "_self");</script>';
			}else {
				 $token_url = "https://graph.facebook.com/oauth/access_token?"
				. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
				. "&client_secret=" . $app_secret . "&code=" . $code;
				$response = file_get_contents($token_url);
				$params = null;
				//parse_str($response, $params);
				$params=json_decode($response,true);
				$_SESSION['access_token'] = $params['access_token'];
				 $graph_url = "https://graph.facebook.com/me/accounts?type=page&access_token=". $params['access_token'];
				$user = json_decode(file_get_contents($graph_url));
				$pages=count($user->data);
				if($pages==0) {
					header("Location: ?#/setting/integration_list/".$vis_language['TXTFACEBOOK']."/4");
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "Pages not found"); </script>';
				}
				else {
					$facebook=array();
					for($i=0;$i<$pages;$i++) {
						$user->data[$i]->name.' id: '.$user->data[$i]->id.' had access_token as '.$user->data[$i]->access_token.'<br />';
						$facebook[$i]['name']=$user->data[$i]->name;
						$facebook[$i]['id']=$user->data[$i]->id;
						$facebook[$i]['token']=$user->data[$i]->access_token;
						$facebook[$i]['vis_integration_id'] = $integration_id;
						$facebook[$i]['vis_department'] = 1;
						$facebook[$i]['vis_status'] = 0;
					}
					$tdata['vis_access_token']=$params['access_token'];
					$tdata['vis_token']=$settings[0]['db_password'];
					$tdata['fb_app_id']=$app_id;
					$tdata['fb_canvas_url']=$settings[0]['billing_url'];
					$tdata['fb_secret']=$app_secret;
					$filter1='integration_id='.$integration_id;
					$ret=$sub_object->update_fb($filter1, $tdata, VIS_STAFF_ID, VIS_LOCATION_AREA);
					for($f=0;$f<count($facebook);$f++){
					$filter = 'unique_page_id='.$facebook[$f]['id'];
						list($pages_info,$pages_details)=$object->get_pages($filter,$limit='',VIS_STAFF_ID, VIS_LOCATION_AREA);
						if(($pages_details==-1 && isset($facebook[$f]['id']))){
							$ret=$sub_object->add_pages($facebook[$f], VIS_STAFF_ID, VIS_LOCATION_AREA);
						}
					}
					if($pages_details!=-1 || isset($ret)){
						header("Location: ?#/setting/fb_pages/pages/".$integration_id);
					}else{
						header("Location: ?#/setting/integration_list/".$vis_language['TXTFACEBOOK']."/4");
					}
					$database->database_disconnect();               
				}
			}
		}else{
			    $graph_url = "https://graph.facebook.com/me/accounts?type=page&access_token=".$settings[0]['user_name'];				
				$user = json_decode(file_get_contents($graph_url));
				$pages=count($user->data);
				if($pages==0) {
					header("Location: ?#/setting/integration_list/".$vis_language['TXTFACEBOOK']."/4");
					echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "Pages not found"); </script>';
				}
				else{
					$facebook=array();
					for($i=0;$i<$pages;$i++) {
						$user->data[$i]->name.' id: '.$user->data[$i]->id.' had access_token as '.$user->data[$i]->access_token.'<br />';
						$facebook[$i]['name']=$user->data[$i]->name;
						$facebook[$i]['id']=$user->data[$i]->id;
						$facebook[$i]['token']=$user->data[$i]->access_token;
						$facebook[$i]['vis_integration_id'] = $integration_id;
						$facebook[$i]['vis_department'] = 1;
						$facebook[$i]['vis_status'] = 0;
					}
					for($f=0;$f<count($facebook);$f++){
						echo $f;
					    $filter = 'unique_page_id='.$facebook[$f]['id'];
						list($pages_info,$pages_details)=$object->get_pages($filter,$limit='',VIS_STAFF_ID, VIS_LOCATION_AREA);
						if(($pages_details==-1 && isset($facebook[$f]['id']))){
							$ret=$sub_object->add_pages($facebook[$f], VIS_STAFF_ID, VIS_LOCATION_AREA);
						}
					}
					if($pages_details!=-1 || isset($ret)){
						echo '<script> $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTFACEBOOK'].'",{"vis_module":"setting", "vis_operation":"fb_pages","vis_action":"#/setting/fb_pages/pages/'.$integration_id.'"}); </script>';
					}else{
						header("Location: #/setting/integration_list/".$vis_language['TXTFACEBOOK']."/4");
					}
					$database->database_disconnect();               
				}
			
		}
		return true;
	}

    function view_labels($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
 		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
 		$staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = " label_name like '%".$data['vis_title']."%'"  ;
                //   $filter.= " and data_id=status_id";
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        else
        {
			$filter = "";
			$data= "";
		}
		if(VIS_ADMIN_ACCESS_LEVEL==1)
   		{
			$labels=$object->get_labels($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$label_details_total=$object->get_labels($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			if($label_details_total==-1 || empty($label_details_total))
			$label_total=0;
			else
			$label_total=count($label_details_total);
			
		}
		else
		{
			list($label_details_total, $labels)=$object->get_properties('get_labels', '',$limit);
			if($label_details_total==-1 || empty($label_details_total))
			$label_total=0;
			else
			$label_total=$label_details_total['total'];
		}
		$ticket_info['ticket_count']= $label_total;
		$view_info['page_count']=($label_total==0)?0:ceil($label_total/$view_info['page_count']);
        $database->database_disconnect();
		$ticket_info['page']=$page;
        $operation['view_title']=$vis_language['TXTLABEL'];
		$operation['option_id']=6;
        $operation['vis_operation']='new_label';
		$operation['vis_current_operation']='view_labels';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDLABEL'];
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'label_list.php');
			$label_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'=>$label_total, 'paging' => $select, 'list'=> $label_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'ticket_options.php');
   		
    }

    /***Billing settings ** @param mixed $operation */
    function products_list($operation) {
        global $vis_language;
        $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.'billing.php');
        $object=new class_billing($database);
        $filter=(VIS_LOCATION_AREA==1)?('is_enabled=1 and domain_id='.VIS_DOMAIN):'';
        $setting_prod_module = 1; // set flag variable to get domain name for displaying domain name under Settings > Products
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff = new class_staff($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($productInfo, $product)=$object->get_product($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, $setting_prod_module,$limit);
        $view_info['page_count']=($productInfo['total']==0)?0:ceil($productInfo['total']/$view_info['page_count']);
        $database->database_disconnect();
        $operation['vis_current_operation']='products_list';
        $operation['vis_current_module']='setting';
        $view_info['page'] = $page;
        if(VIS_LOCATION_AREA==1) {
            $header_title=$vis_language['TXTBILLING'];
            include(VIS_PATH_TEMPLATE.'header.php');
            include(VIS_PATH_TEMPLATE.'view_product.php');
            include(VIS_PATH_TEMPLATE.'footer.php');
        }
        else include(VIS_PATH_TEMPLATE.'product_list.php');
        return true;
    }

    function edit_product($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();
			$operation['vis_product_id'] = $action[4];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'billing.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_billing($database);
			$set_object=new class_setting($database);
			$domain=$set_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$domain=$domain[1];
			if($domain==-1) return false;
			list($productCnt, $product_info)=$object->get_product('product_id='.$operation['vis_product_id'], VIS_STAFF_ID, VIS_LOCATION_AREA,'','0,1');
			$database->database_disconnect();
			if($product_info!=-1) $product_info=$product_info[0];
			include(VIS_PATH_TEMPLATE.'product_edit.php');
			return true;
		}
		else
		{
            $this->error=$vis_language['MSGINFOMISS'];			
            return false;
		}
    }

    function tax_list($operation) {
		$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.'billing.php');
        $object=new class_billing($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($taxInfo, $tax)=$object->get_tax('', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        $view_info['page_count']=($taxInfo['total']==0)?0:ceil($taxInfo['total']/$view_info['page_count']);
        $database->database_disconnect();
        $operation['vis_current_operation']='tax_list';
        $operation['vis_current_module']='setting';
        $view_info['page'] = $page;
        include(VIS_PATH_TEMPLATE.'tax_list.php');
        return true;
    }

    function edit_tax($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])) {
			$operation['vis_tax_id'] = $action[4];
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'billing.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_billing($database);
			$set_object=new class_setting($database);
			$domain=$set_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$domain=$domain[1];
			if($domain==-1) return false;
			$limit = '0,1';
			list($tax_count, $tax_info)=$object->get_tax('tax_id='.$operation['vis_tax_id'], VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$database->database_disconnect();
			if($tax_info!=-1) $tax_info=$tax_info[0];
			include(VIS_PATH_TEMPLATE.'tax_edit.php');
			return true;
		}
		else
		{
			$this->error=$vis_language['MSGINFOMISS'];	
            return false;
		}
    }

    function billing_setting($operation) {
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'billing.php');
        $set_object=new class_setting($database);
        $bill_object=new class_billing($database);
        $domain=$set_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain=$domain[1];
        $domain_sel=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
        $payment_gateway = (isset($operation['vis_gateway'])) ? $operation['vis_gateway'] : 'paypal_email';
        $gateway_mode = ( $payment_gateway == 'authorize.net' && isset($operation['gateway_mode'] ) ) ? $operation['gateway_mode'] : 1;
        $billing_setting=$bill_object->get_domain_setting('domain_id='.$domain_sel, $payment_gateway, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($domain==-1) return false;
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'billing_setting.php');
        return true;
    }

    function fb_mapping($operation) {
        $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.'setting.php');
        $set_object=new class_setting($database);
        $domain=$tkt_object->get_department('', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($domain==-1) return false;
        $integation=$set_object->get_integration_details('integration_id='.$operation['vis_integration_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($integation==-1) return false;
        else $integation=$integation[0];
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'fb_details.php');
        return true;
    }
    function twitter_details_setting($operation) {
        $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.'setting.php');
        $set_object=new class_setting($database);
        $filter=VIS_TABLE_PREFIX.'domain.domain_id='.$operation['vis_domain'];
        $department=$tkt_object->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($department==-1) return false;
        $twitter=$set_object->get_integration_details('integration_id='.$operation['vis_integration_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($twitter==-1) return false;
        $twitter=$twitter[0];
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'twitter_setting.php');
        return true;
    }

    function save_fb_settings($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])) $data=parse_form_array($operation['vis_action']);
        else $data=$operation;
        if($data['fb_app_id']=='' || $data['fb_secret']=='' || $data['fb_canvas_url']=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); $("#vis_tw_setting").dialog("close"); </script>';
            return false;
        }
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object = new class_setting($database);
        $result = $object->save_fb_settings($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($result) echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $(this).visInterface("remove_tab", "vis_module_setting_div"); </script>';
        else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_tw_setting").dialog("close"); </script>';
        return $result;
    }

    function edit_fb_app($operation) {
        $database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
        $settings=$set_object->get_settings('title="fb_app_id" or title="fb_secret" or title="fb_canvas_url"', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $setting=array();
        for($i=0;$i<count($settings);$i++) $setting[$settings[$i]['title']]=$settings[$i]['content'];
        if(!isset($setting['fb_app_id']) || trim($setting['fb_app_id'])=='' || !isset($setting['fb_secret']) || trim($setting['fb_secret'])=='' || !isset($setting['fb_canvas_url']) || trim($setting['fb_canvas_url'])=='') {
            return $this->integration_domain_details($operation);
        }
        else include(VIS_PATH_TEMPLATE.'fb_app_details.php');
        return true;
    }

    function view_transactions_log($operation) {
        global $vis_language;
		include_once( VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'staff.php' );
        include_once( VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'setting.php' );
        $database = new class_database();
        $staff = new class_staff($database);
        $setting = new class_setting( $database );
        list($view_info, $view_details ) = $staff->get_ticket_view( VIS_STAFF_ID, VIS_LOCATION_AREA );
		$page = ( isset($operation['vis_page']) && is_numeric($operation['vis_page']) ) ? $operation['vis_page'] : 0;
		 $limit = ( $page * $view_info['page_count'] ) . ',' . $view_info['page_count'];
		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(isset($data['vis_gateway_id']) && $data['vis_gateway_id'] != "")
            {
				if($filter != '') {$filter .= " and  gateway_id=".$data['vis_gateway_id'];}
                else if($filter == ''){$filter .= " gateway_id=".$data['vis_gateway_id']; }
            }
			if(isset($data['vis_invoice_id']) && $data['vis_invoice_id'] != "")
			{   //$filter = " content like '%".$data['vis_content']."%'"  ;
				if($filter != '') {$filter .= " and  L.invoice_hash=".$data['vis_invoice_id'];}
                else if($filter == ''){$filter .= " L.invoice_hash like '%".$data['vis_invoice_id']."%'"; }
			}
			if((isset($data['from_date']) && $data['from_date'] != "") && (isset($data['to_date']) && $data['to_date'] != ""))
            {
				$from=date('Y-m-d h:i:s',  strtotime($data['from_date']));
                $to=date('Y-m-d h:i:s',  strtotime($data['to_date']));
                if($filter != '') {$filter .= " and L.entry_date between unix_timestamp('".$from."')  AND unix_timestamp('".$to."')";}
                else if($filter == ''){$filter .= " L.entry_date between unix_timestamp('".$from."') AND unix_timestamp('".$to."')"; }
            }           
		}
        list($log_info, $log_details) = $setting->get_transactions_log($filter, $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(!isset($log_info['total'])) $log_info['total']=0;
        $view_info['page_count'] = ($log_info['total'] == 0 ) ? 0 : ceil($log_info['total'] / $view_info['page_count']);
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTGATEWAYTRANSACTIONSLOG'];
        $operation['vis_operation']='get_gateway_log_delete';
		$operation['vis_current_operation']='view_transactions_log';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTDELETE'];
          if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'transaction_log_list.php');
			$staff_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'=>$log_info['total'], 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else  include(VIS_PATH_TEMPLATE.'transactions_log.php');       
        return true;
    }

    function gateway_transaction_details($operation){
        global $vis_language;
        $operation['view_title']=$vis_language['TXTGATEWAYTRANSACTIONSLOG'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
		include_once( VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'setting.php' );
        $database = new class_database();
        $object = new class_setting( $database );
        list($log_info, $log_details) = $object->get_transactions_log('log_id = ' . $action[4], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $log_details = $log_details[0];
        $database->database_disconnect();
        include( VIS_PATH_TEMPLATE . 'transactions_log_details.php' );
        return true;
    }

    function empty_gateway_log($operation) {
        global $vis_language;
        $database = new class_database();
        include_once( VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'setting.php' );
        $object = new class_setting($database);
        $ret = $object->empty_table( 'gateway_log', VIS_STAFF_ID, VIS_LOCATION_AREA );
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_gateway_log_delete_area").dialog("close"); </script>';
        }
        else {
			$activity_log=$object->add_staff_activity_log("Empty Gatway log list", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_transactions_log"}); </script>';
		}
        $database->database_disconnect();
        return $ret;
    }

    function check_mailque_connecton($data){
    	$conn = 1;
    	switch($data['fetchtype']){
    		case 1:
    		case 2:
    		case 3: // pop3
					$conn = 1;
					include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'pop3.php');
					$pop3 = new pop3();
					$connect = $pop3->connect($data['host'], $data['port'], "25" , "10,500", $data['fetchtype']);
					if(!$connect) { $conn = 3; } /* connection err */
					else if(!$pop3->login($data['user'], $data['password'])) {
						$conn = (stristr($pop3->error, 'Username') || stristr($pop3->error, 'password')) ? 2 : 3;
					}
					$pop3->close();
					break;
			case 4:
			case 5:
			case 6: // imap
					include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'imap.php');
					$imap = new class_imap($data['user'], $data['password'], $data['user'], $data['host'], 'imap', $data['port'], $data['fetchtype']);
					$imap->connect();
					//if(!$imap->marubox){ $conn = 2; } // authentication err
					if(strstr(imap_last_error(), 'Connection timed out') || strstr(imap_last_error(), 'connection broken')) $conn = 3; // connection err
					if(strstr(imap_last_error(), 'Invalid credentials')) $conn = 2;	// authentication err
					$conn = 1;
					$imap_errors = imap_errors(); // When imap_errors() is called, the error stack is subsequently cleared.
					if(!empty($imap_errors)){
						$conn = (stristr(end($imap_errors), 'Invalid credentials')) ? 2 : 3;
					}
					$imap->close_mailbox();
					break;
    	}
    	return $conn;
    }

    function verify_emailqueue($operation) {
		$list_chk = '';
		global $vis_language;
		$options = parse_form_array($operation['vis_action']);
		foreach ($options as $data => $value)
			if (preg_match('/vis_global_mass_chk_[0-9]/', $data))
				$list_chk .= $value . ',';
		if($list_chk == '') {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "' . $vis_language['MSGERROPRT'] . '"); </script>';
			return false;
		}
		$database = new class_database();
		$operation['vis_current_operation']='view_mailqueue';
        $operation['vis_current_module']='setting';
		include_once( VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'setting.php' );
        $setting = new class_setting($database);
		list($mailqueue_info,$mailqueue_details) = $setting->get_mailqueue('mailqueue_id IN ( ' . rtrim($list_chk, ",") . ')', '', 0, 0, 0, VIS_LOCATION_AREA);
		if($mailqueue_details != -1){
            for($i=0; $i<count($mailqueue_details); $i++){
				$conn = 0;
				$conn = $this->check_mailque_connecton(array('host' => $mailqueue_details[$i]['host_name'], 'port' => $mailqueue_details[$i]['port_number'], 'user' => $mailqueue_details[$i]['user_name'], 'password' => password_decrypt($mailqueue_details[$i]['authentication'],VIS_PASSWORD_KEY), 'email' => $mailqueue_details[$i]['email'], 'fetchtype' => $mailqueue_details[$i]['mailqueue_type']));
				if($conn != $mailqueue_details[$i]['is_enabled']){
				   $status_change=($conn==1) ? 'enable' : (($conn==2) ? 'authentication error': (($conn==3) ? 'connection error' : 'disable'));
				   $setting->update_mailqueue_status(array('is_enabled' => $conn, 'mailqueue_id' => $mailqueue_details[$i]['mailqueue_id']));
				   $setting->add_staff_activity_log("Changed ".$mailqueue_details[0]['email']." mailqueue status as ".$status_change, 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['TXTEMAILQUEUE'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
	}

	function manage_portal_setting($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $setting=$object->get_settings('(title="vis_manage_portal_theme" or title="vis_manage_portal_logo" or title="vis_manage_favicon" OR title like "vis_manage_logo" OR title like "vis_manage_portal_text" or title="vis_manage_portal_text_bold" or title="vis_manage_portal_text_italic" or title="vis_manage_portal_text_colour" OR title like "vis_manage_portal_language" OR title like "vis_date_format" OR title like "vis_datetime_format" OR title like "vis_html_editor_status" OR title like "vis_left_panel_view" OR title like "vis_help_panel_view") and domain_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($setting!=-1) for($i=0;$i<count($setting);$i++) {
            if($setting[$i]['title']=='vis_manage_portal_theme') {
                $poral_setting['vis_manage_portal_theme']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_portal_logo') {
                $poral_setting['vis_manage_portal_logo']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_portal_text') {
                $poral_setting['vis_manage_portal_text']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_manage_portal_text_bold') {
                $poral_setting['vis_manage_portal_text_bold']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_manage_portal_text_italic') {
                $poral_setting['vis_manage_portal_text_italic']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_manage_portal_text_colour') {
                $poral_setting['vis_manage_portal_text_colour']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_logo') {
                $poral_setting['vis_manage_logo']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_portal_language') {
                $poral_setting['vis_manage_language']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_date_format') {
                $poral_setting['vis_date_format']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_datetime_format') {
                $poral_setting['vis_datetime_format']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_html_editor_status') {
                $poral_setting['vis_html_editor_status']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_left_panel_view') {
                $poral_setting['vis_left_panel_view']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_help_panel_view') {
                $poral_setting['vis_help_panel_view']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_favicon') {
                $poral_setting['vis_manage_favicon']=$setting[$i]['content'];
            }
        }
        list($language_info, $language_list)=$object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $themes=array();
        if ($d=dir(VIS_PATH_MANAGE_THEME)) {
            $i=$j=0;
            while (false !== ($entry = $d->read())) {
                if(!is_dir(VIS_PATH_MANAGE_THEME.$entry) && $entry != 'index.html' && $entry != 'vh-icons.css') {
                    $themes[$i]['theme'] = substr_replace($entry, "", -4);
                    switch($themes[$i]['theme']){
                        case 'blue': $themes[$i]['style'] = "background-color: #7ABAF2; color: #ffffff;"; break;
                        case 'cheery': $themes[$i]['style'] = "background-color: #690011; color: #ff3657;"; break;
                        case 'dave': $themes[$i]['style'] = "background-color: #A62152; color: #eda6c0;"; break;
                        case 'explorer': $themes[$i]['style'] = "background-color: #0E6313; color: #56e75e;"; break;
                        case 'filibonik': $themes[$i]['style'] = "background-color: #16A3A3; color: #94f1f1;"; break;
                        case 'green': $themes[$i]['style'] = "background-color: #96ED89; color: #ffffff;"; break;
                        case 'grey': $themes[$i]['style'] = "background-color: #929E88; color: #f9faf8;"; break;
                        case 'human': $themes[$i]['style'] = "background-color: #F2D0C4; color: #ffffff;"; break;
                        case 'default': $themes[$i]['style'] = "background-color: #588F27; color: #bfe49e;"; break;
                        case 'mango': $themes[$i]['style'] = "background-color: #F58026; color: #fef2e9;"; break;
                        case 'nikeair': $themes[$i]['style'] = "background-color: #F25EB0; color: #ffffff;"; break;
                        case 'zoo': $themes[$i]['style'] = "background-color: #837979; color: #e5e3e3;"; break;
                        case 'dark': $themes[$i]['style'] = "background-color: #111111; color: #777777;"; break;
                        case 'dark_blue': $themes[$i]['style'] = "background-color: #177bbb; color: #aad7f4;"; break;
						case 'red': $themes[$i]['style'] = "background-color: #B40E0F; color: #fbc6c7;"; break;
						case 'yellow': $themes[$i]['style'] = "background-color: #fff72e; color: #7b7600;"; break;
                    }
                    $i++;
                }
            }
        }
        sort($themes);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'manage_portal_setting.php');
        return true;
    }

	function integration_list($operation){
		if(isset($operation['vis_integration_type']) && $operation['vis_integration_type'] != ''){
				$integration_type=$operation['vis_integration_type'];
		}
		elseif(isset($operation['vis_action']) && $operation['vis_action'] != ''){
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$integration_type=$action[4];
		}
        $filter='integration_type='.$integration_type;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$object=new class_setting($database);
		$object_staff=new class_staff($database);
		list($view_info, $view_details)=$object_staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		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_domain']!=''){$filter= 'domain_name like "%'.$data['vis_domain'].'%" and '.$filter;}
		if($data['vis_billingurl']!=''){$filter= 'billing_url like "%'.$data['vis_billingurl'].'%" and '.$filter;}
		if($data['vis_status']!=''){$filter= 'avis_integration.is_enabled="'.$data['vis_status'].'" and '.$filter;}
		if($data['vis_host']!=''){$filter= 'avis_integration.host_name="'.$data['vis_host'].'" and '.$filter;}
		}
		list($integration_info, $integration_details)=$object->get_integration_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, $limit);
		$integration_info['page_count']=($integration_info['total']==0)?0:ceil($integration_info['total']/$view_info['page_count']);
		list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($twitter_info, $twitter_details)=$object->get_twitter_details($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$twitter_info['page_count']=($twitter_info['total']==0)?0:ceil($twitter_info['total']/$view_info['page_count']);
        if(isset($operation['vis_api']) && isset($operation['vis_integration_type']) && isset($operation['vis_domain']))
        {
			$filter='integration_type='.$integration_type.' and '.VIS_TABLE_PREFIX.'integration.domain_id=0 and host_name='.$operation['vis_api'];
			$sms_details=$object->get_sms_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, 1);
			if($sms_details==-1){
				$filter='integration_type='.$integration_type.' and '.VIS_TABLE_PREFIX.'integration.domain_id='.$operation['vis_domain'].' and host_name='.$operation['vis_api'];
				$sms_details=$object->get_sms_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			$hostNm = '';
			if($sms_details == -1)
			{
				$hostNm = $operation['vis_api'];
			}
			$domain = $operation['vis_domain'];
		}
		else
		{	
			$filter2 =$filter.' AND '.VIS_TABLE_PREFIX.'integration.domain_id=0';
			$sms_details=$object->get_sms_details($filter2, VIS_STAFF_ID, VIS_LOCATION_AREA, 1);
			
			if($sms_details==-1){
				$sms_details=$object->get_sms_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			$domain = $department[0]['domain_id'];
		}
		if(isset($operation['vis_domain']))
		{
			$domainId = $operation['vis_domain'];
		}
		else
		{
			$domainId = $domain;
		}
		list($fb_info, $fb_details)=$object->get_fb_details($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$fb_info['page_count']=($fb_info['total']==0)?0:ceil($fb_info['total']/$view_info['page_count']);
		list($twilio_info, $twilio_details)=$object->get_integration_setting('integration_type=27 AND is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$database->database_disconnect();
	   
		
		switch($integration_type){
			case '1':
				global $vis_language;
				$integration_type = 1;
				$txt_integration_name = $vis_language['TXTWHMCS'];
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				$operation['vis_current_operation']='integration_list';
                $operation['vis_current_module']='setting';
				if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			    ob_start();
			    include(VIS_PATH_TEMPLATE.'integration_list.php');
			    $integration_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'=>$integration_info['total'], 'paging' => $select, 'list'=> $integration_list));
		        }else
				include(VIS_PATH_TEMPLATE.'view_integration.php');
			break;
			case '2':
				$integration_type = 2;
				$twitter_info['twitter_count']=(!$twitter_details || $twitter_details==-1)?0:count($twitter_details);
				$twitter_info['page']=$page;
				$twitter_info['view_count']=count($twitter_details);
				include(VIS_PATH_TEMPLATE.'view_twitter.php');
			break;
			case '3':
			    $integration_type = 3;
				include(VIS_PATH_TEMPLATE.'view_sms.php');
			break;
			case '4':
				$integration_type = 4;
				$fb_info['fb_count']=(!$fb_details || $fb_details==-1)?0:count($fb_details);
				$fb_info['page']=$page;
				$fb_info['view_count']=count($fb_details);
				include(VIS_PATH_TEMPLATE.'view_fb.php');
			break;
			case '10': // case 10 for clientexec integration
			    global $vis_language;
				$integration_type = 10;
				$txt_integration_name = $vis_language['TXTCLIENTEXEC'];
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
			    $integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_integration.php');
			break;
			case '31':   // case 31 for magento
				global $vis_language;
				$integration_type = 31;
				
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_magento.php');
			break;
			case '29':
				global $vis_language; 
				$integration_type = 29;
				$txt_integration_name = $vis_language['TXTFRESHBOOKS'];
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_integration.php');
			break;
			case '33':
				global $vis_language; 
				$integration_type = 33;
				$txt_integration_name = $vis_language['TXTINSIGHTLY'];
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_insightly.php');
			break;
			case '34':   // case 34 for bigcommerce
				global $vis_language;
				$integration_type = 34;
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_bigcommerce.php');
			break;
			case '36':
				global $vis_language;
				$integration_type = 36;
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_blesta.php');
			break;
			case '39':
				$integration_type = 39;
				$hipchat_details = $integration_details[0];
				include(VIS_PATH_TEMPLATE.'view_hipchat.php');
				break;
			case '40':
				$integration_type = 40;
				$slack_details = $integration_details[0];
				include(VIS_PATH_TEMPLATE.'view_slack.php');
			    break;
			case '41':
				global $vis_language;
				$integration_type = 41;
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_capsulecrm.php');
				break;	
			case '47':
				global $vis_language;
				$integration_type = 47;
					$intercom_details = $integration_details[0];
				include(VIS_PATH_TEMPLATE.'view_intercom.php');
				break;
			case '48': //Vtiger
				global $vis_language;
				$integration_type = 48;
				$integration_info['integration_count']=(!$integration_details ||$integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_vtiger.php');
				break;	
            case '55'://sso
			    global $vis_language;
				$integration_type = 55;
				$integration_info['integration_count']=(!$integration_details || $integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				$operation['vis_current_operation']='integration_list';
                $operation['vis_current_module']='setting';
				if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			    ob_start();
			    include(VIS_PATH_TEMPLATE.'sso_integration_list.php');
			    $integration_list = ob_get_clean();
			    ob_end_flush();
				$select='';
			    $select .= "<div class=\"pull-right\">";
			    $select .= "<select name=\"paging\" id=\"paging\" class=\"form-control input-sm selectpicker pull-right paging v-middle\"  onchange=\"javascript:vis_apply_filter(this.value);\">";
			    for($i=0;$i<$integration_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_count'=>$integration_info['total'], 'paging' => $select, 'list'=> $integration_list));
		        }else
				include(VIS_PATH_TEMPLATE.'view_sso.php');
			break;	
			case '56': // Xero
				global $vis_language;
				$integration_type = 56;
				$integration_info['integration_count']=(!$integration_details ||$integration_details==-1)?0:count($integration_details);
				$integration_info['page']=$page;
				$integration_info['view_count']=count($integration_details);
				include(VIS_PATH_TEMPLATE.'view_xero.php');
				break;			
			default: $integration_type = '';
			include(VIS_PATH_TEMPLATE.'integration_type_blank.php');
		}
		return true;
	}

    function integration_sms($operation){
		if(!isset($operation['vis_api']) || $operation['vis_api']=='')$operation['vis_api']=1;
        $filter='integration_type='.$operation['vis_integration_type'] .' and host_name='.$operation['vis_api'].' and '.VIS_TABLE_PREFIX.'integration.domain_id='.$operation['vis_domain'];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$all_domain = ($operation['vis_domain']==0)?1:0;
		$sms_details=$object->get_sms_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, $all_domain);
		
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'sms_new.php');
        
    }
    function integration_update($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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$sub_object=new class_subsetting($database);
			$filter='integration_id='.$action[4];
			list($integration_info, $integration_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$integration_details=$integration_details[0];
			if($integration_details['integration_type']==1) {
				$integration_name = $vis_language['TXTWHMCS'];
				$integration_type = 1;
			}
			if($integration_details['integration_type']==10){
				$integration_type = 10;
		   		$integration_name = $vis_language['TXTCLIENTEXEC'];
		   	}
		   	if($integration_details['integration_type']==29){
				$integration_type = 29;
		   		$integration_name = $vis_language['TXTFRESHBOOKS'];
		   	}
			list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.domain_id='.$integration_details['domain_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$department=$department[0];
			if($integration_details['integration_type']==29) include(VIS_PATH_TEMPLATE.'freshbook_integration_update.php');
			else include(VIS_PATH_TEMPLATE.'integration_update.php');
			return true;
		}
		else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
		}
    }
    function twitter_details($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$action[4];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			$filter='integration_id='.$action[4];
			list($twitter_info, $twitter_details)=$object->get_twitter_details($filter, $limit='', $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$twitter_details=$twitter_details[0];
			include(VIS_PATH_TEMPLATE.'twitter_update.php');
			return true;
		}
		else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
		}
    }

    function get_twitter_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELTWITTER'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_twitter', 'vis_integration_id':".$operation['vis_integration_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function sms_details($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$action[4];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			$filter2='integration_id='.$action[4].' AND '.VIS_TABLE_PREFIX.'integration.domain_id=0 ';
			$sms_details=$object->get_sms_details($filter2, VIS_STAFF_ID, VIS_LOCATION_AREA, 1);
			if($sms_details==-1){
				$filter='integration_id='.$action[4];
				$sms_details=$object->get_sms_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
			$sms_details=$sms_details[0];
			include(VIS_PATH_TEMPLATE.'update_sms.php');
			return true;
		}
		else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
		}
    }

    function get_sms_delete($operation){
        global $vis_language;
        if(isset($operation['vis_all_domains']) && $operation['vis_all_domains']==1){
			$operation['vis_all_domains']=1;
		}
		else{
			$operation['vis_all_domains']=0;
		}
        $message_info['vis_form_title']=$vis_language['TXTDELSMS'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_sms', 'vis_all_domains':".$operation['vis_all_domains'].", 'vis_domain':".$operation['vis_domain'].",'vis_integration_id':".$operation['vis_integration_id'].",'vis_api':".$operation['vis_api']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function fb_details($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$action[4];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			$filter='integration_id='.$action[4];
			list($fb_count, $fb_details)=$object->get_fb_details($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$fb_details=$fb_details[0];
			include(VIS_PATH_TEMPLATE.'fb_update.php');
			return true;
		}
		else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
		}
    }

    function get_fb_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELFACEBOOK'];
        $message_info['vis_message']=$vis_language['MSGDELFBPAGES'].' <br> '.$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_fb', 'vis_integration_id':".$operation['vis_integration_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function fb_pages ($operation){
		global $vis_language;
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
		$action=explode($spliter, $operation['vis_action']);
		$integration_id = $action[4];
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$object_staff=new class_staff($database);
		list($view_info, $view_details)=$object_staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$sub_object=new class_subsetting($database);
		$filter = 'app_id='.$integration_id;
		list($pages_info,$pages_details)=$object->get_pages($filter,$limit,$userid, $user);
		list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$view_info['page_count'] = ($pages_info['total'] == 0 ) ? 0 : ceil($pages_info['total'] / $view_info['page_count']);
		include(VIS_PATH_TEMPLATE.'fb_pages.php');
	}

	function smtpmail_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting = new class_setting($database);
		$settingmanage=$setting->get_settings('(title like "vis_queue_outgoing_mail_status") and domain_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if($key=='department_id="') $filter.=' ((FIND_IN_SET('.substr($value,0,-1).', '.VIS_TABLE_PREFIX.'smtpmail.department_id)>0) or  '.VIS_TABLE_PREFIX.'smtpmail.department_id=0) '.' and ';
                else{
                    if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'smtpmail.';
                    $filter.=$key.$value." and ";
                }
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'domain.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($smtpmail_info, $smtpmail_details)=$object->get_smtpmail($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA,'1');
        if($smtpmail_details!=-1) for($i=0;$i<count($smtpmail_details);$i++){
            $smtpmail_details[$i]['department']=array();
            if($smtpmail_details[$i]['department_id']==0){
                $smtpmail_details[$i]['department'][0]['domain_name']='';
                $smtpmail_details[$i]['department'][0]['department_name'] = $vis_language['TXTALLDEPARTMENTS'];
            }
            else{
                $smtp_department = explode(',', $smtpmail_details[$i]['department_id']);
                $filter = '(';
                for($j=0;$j<count($smtp_department); $j++)
                $filter .= ' department_id='.$smtp_department[$j].' or';
                $filter = substr($filter,0, -2);
                $filter .=' )';
                $smtpmail_details[$i]['department'] = $object->get_department_access($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
            }
        }
        $department_details=$object->get_smtp_department( '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($domain_info, $domain_details)=$object->get_domain('', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($department_info,$department_detail)=$sub_object->get_department('','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($smtpmail_info['total']==0)?0:ceil($smtpmail_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $smtpmail_info['smtpmail_count']=(!$smtpmail_details || $smtpmail_details==-1)?0:count($smtpmail_details);
        $smtpmail_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $operation['view_title']=$vis_language['TXTSMTP'];
		$operation['vis_current_operation']='view_smtp';
        $operation['vis_current_module']='setting';
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'smtpmail_list.php');
			$smtpmail_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'=>$smtpmail_info['total'], 'paging' => $select, 'list'=> $smtpmail_list));
		}else
        include(VIS_PATH_TEMPLATE.'smtp.php');
        return true;
    }
    function view_smtp($operation){
		$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']:'';
         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_department']!='')$and_operations['department_id="'] = $data['vis_department'].'"';
		    if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
			if($data['vis_host']!='')$and_operations['smtp_host="'] = $data['vis_host'].'"';
			if($data['vis_username']!='')$and_operations['smtp_user="'] = $data['vis_username'].'"';
        }
        return $this->smtpmail_display($operation, $and_operations, '', '', $page, $sort_by);
    }
	function smtp_details($operation) {
        global $vis_language;
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $data=parse_form_array($operation['vis_action']);
        $allUsedDepartment = '';
        $deptCondition= '';
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4]))
        {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$sub_object=new class_subsetting($database);
			list($smtpmail_info, $smtpmail_details)=$object->get_smtpmail('smtp_id='.$action[4], '', 0, '', VIS_SMTP_ID, VIS_LOCATION_AREA);
			list($allSmtpmailInfo, $allSmtpmailDetails)=$object->get_smtpmail('is_enabled = 1 and smtp_id !='.$action[4], '', 0, '', VIS_SMTP_ID, VIS_LOCATION_AREA);
			if($allSmtpmailDetails!= -1)
			{
				foreach($allSmtpmailDetails as $row){
					if($row['department_id']!='')$allUsedDepartment .= $row['department_id'] .',';
				}	
				 $allUsedDepartment=substr($allUsedDepartment, 0, -1);
			}
			if($allUsedDepartment!= '') $deptCondition =  'department_id NOT IN ('.$allUsedDepartment.')';
            $smtp_details=$object->get_smtp_details('department_id="'.$smtpmail_details[0]['department_id'].'"', VIS_STAFF_ID, VIS_LOCATION_AREA);
            if($smtp_details!=-1) $smtp_details=$smtp_details[0];
			list($department_info, $department_details)=$sub_object->get_department($deptCondition, '', 0, '', VIS_SMTP_ID, VIS_LOCATION_AREA);
			
			$department=$department_details;
			$database->database_disconnect();
			$operation['view_title']=$vis_language['TXTSMTP'];
			include(VIS_PATH_TEMPLATE.'smtp_view.php');
			return true;
		 }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	function ticket_base($operation)
	{
		global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($dpinfo, $department)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($dminfo, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $filter=VIS_TABLE_PREFIX.'module.module_id='.$operation['vis_module_id'].' ';
        list($module_info, $module_details)=$object->get_module('module_id=5', 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $module_details=$module_details[0];
		include(VIS_PATH_TEMPLATE.'ticket_base.php');
        $database->database_disconnect();
        return true;
	}

    function change_admin_type($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.'setting.php');
        $object=new class_setting($database);
        $ret=$object->change_admin_type($operation['vis_switch'],$operation['vis_admin_type'], $list_chk, 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 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'].'"}); </script>';
        return $ret;
    }
    function display_localisation($operation)
    {
          global $vis_language;
          set_time_limit(0);
          $data = parse_form_array($operation['vis_action']);
          $database=new class_database();
          include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
          $object=new class_setting($database);
          $language_details = $object->get_language('is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
          if(isset($operation['vis_form']) && $operation['vis_form']=='vis_language_variable_form')
          {
			 $data = parse_form_array($operation['vis_action']);
             $page = $operation['vis_page'];
             $filter = 'language_id = 1';
             $view_info['page_count'] = 20;
             $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
			 if(isset($operation['criteria']) && $operation['criteria']!='')
			 {
				 $language_variable_arr = array();
				 $criteria=$operation['criteria'];
				 $filter = 'language_id ='.$data['vis_language_id'].' and description like "%'.$operation['criteria'].'%"';
				 $language_variable_arr1 = $object->get_language_variables_details($filter,$limit, $page ,VIS_STAFF_ID, $data['vis_location_id'],$criteria);
			     $language_variable_arr[0]['total_count']=$language_variable_arr1[0]['total_count'];
				 $language_total_count = $language_variable_arr[0]['total_count'];
				 $view_data=explode(',',$limit);
				 $start=$page*$view_info['page_count']+1;
				 $end=($page*$view_info['page_count'])+$view_info['page_count'];
				 $j = 0;
				 for($i=$start; $i<=$end;$i++) {
					 if(!empty($language_variable_arr1[1][$i])){ $j++; $language_variable_arr[1][$j]=$language_variable_arr1[1][$i];}
				 }
				 echo "<script>$('#vis_criteria').val('".$criteria."');</script>";
			 }
			 else
			 {
				 $filter = 'language_id ='.$data['vis_language_id'];
				 $language_variable_arr = $object->get_language_variables_details($filter,$limit, $page ,VIS_STAFF_ID, $data['vis_location_id'], '');
				 $language_total_count = $language_variable_arr[0]['total_count'];
				  echo "<script>$('#vis_criteria').val('');</script>";
		     }

             $language_variables = $language_variable_arr[1];
             $language_detail = $object->get_language('language_id ='.$data['vis_language_id'], '', '', '', VIS_STAFF_ID, $data['vis_location_id']);
             $language_details['page']=$page;
             $view_info['page_count']=($language_total_count==0)?0:ceil($language_total_count/$view_info['page_count']);
             $vis_page_title =  $vis_language['TXTUPDATE'].' '.$language_detail[1][0]['language_name'].' '.$vis_language['TXTLANGUAGE'] ;
             $vis_title = $language_detail[1][0]['language_name'] ;
             $view_info['view_count']=count($language_variables);
             include(VIS_PATH_TEMPLATE.'language_variables.php');
          }
          else
          {
              $language_details = $language_details[1];

              include(VIS_PATH_TEMPLATE.'language_variable_update.php');
          }
    }

	function get_localization_delete($operation)
	{
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELLOCAL'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_localization', 'vis_variable_id':".$operation['vis_variable_id'].", 'vis_language_id':".$operation['vis_language_id'].", 'vis_langauge_location':".$operation['vis_langauge_location']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

      function channel_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.'ticket.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$sub_object=new class_subsetting($database);
            $ticket_object=new class_ticket($database);
            $filter=VIS_TABLE_PREFIX.'channel.channel_id='.$action[4].' ';
            $channel_details=$ticket_object->get_channel($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $channel_details=$channel_details[0];
            $channel_department=explode(',', $channel_details['department_access']);
			include(VIS_PATH_TEMPLATE.'channel_update.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function get_channel_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELCHANNEL'];
		$operation['vis_current_operation']='delete_channel';
        $operation['vis_current_module']='setting';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_ticket($database);
        list($tinfo, $tickets)=$object->get_ticket(VIS_TABLE_PREFIX.'ticket.channel_id='.$operation['vis_channel_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($tickets!=-1) {
            $message_info['vis_form_title']=$vis_language['TXTDELCHANNEL'];
            $message_info['vis_message']=$vis_language['MSGCHNCNDEL'];
            $message_info['vis_event']='';
        }
        else {
            $message_info['vis_form_title']=$vis_language['TXTDELCHANNEL'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
			$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
			if($operation['count'] > 1)
				$message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_channel_id':".$operation['vis_channel_id'].", 'vis_page':'".$vis_page."'})";
			else
				$message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_channel_id':".$operation['vis_channel_id']."})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function remove_logo($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->clear_logo($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) { ?>
            <script> $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>; <?
            return false;
        }
        else {
			$clearBtn = $message=$message1='';
            $message.='<img height=\"80px\" src=\"'.VIS_PATH_IMAGES.'vh-logo.svg?ver=02122014'.'\" />';
             $message1.='<img height=\"80px\" src=\"'.VIS_PATH_IMAGES.'favicon.ico'.'\" />';
          
          if($operation['vis_manage']==1 )
		{?>
			<script> $('#clear_manage_logo_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_manage_portal":1}); </script><?
            }else if($operation['vis_favicon_clear']==1){?>
				<script> $('#clear_client_favicon_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message1; ?>","vis_favicon_client_portal":1}); </script><?
            }else if($operation['vis_manage_favicon_clear']==1){?>
				<script> $('#clear_manage_favicon_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message1; ?>","vis_favicon_manage_portal":1}); </script><?
            }else{?>
          <script> $('#clear_client_logo_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_client_portal":1}); </script><? }

        }
        return true;
    }
    function view_gamification($operation)
    {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $filter = '';
        $point_details = $object->get_point_criteria($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $level_details = $object->get_level_points($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
        include(VIS_PATH_TEMPLATE.'add_points_form.php');
        return true;
    }

    function quest_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'quest.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'quest.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter = '';
        list($quest_info, $quest_details)= $object->get_quest_list($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA)  ;
		$view_info['page_count']=($quest_info['total']==0)?0:ceil($quest_info['total']/$view_info['page_count']);
        
        for($i=0;$i<count($quest_details);$i++){
                $teams = explode(',', $quest_details[$i]['group_id']);
                $filter = '(';
                for($j=0;$j<count($teams); $j++)
                $filter .= ' group_id='.$teams[$j].' or';
                $filter = substr($filter,0, -2);
                $filter .=' )';
                list($team_info, $team_details)=$object->get_staffgroup($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
                $quest_details[$i]['staff_group_name'] = $team_details;
                
        }
        $database->database_disconnect();
		$quest_info['quest_count']=(!$quest_details || $quest_details==-1)?0:count($quest_details);
        $quest_info['page']=$page;

        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTWORKFLOW'];
        $operation['vis_operation']='new_quest';
        $operation['vis_current_operation']='view_quest';
        $operation['vis_current_module']='setting';
        include(VIS_PATH_TEMPLATE.'quest.php');
        return true;
    }
     function view_quest($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTWORKFLOW'];
        return $this->quest_display($operation, '', '', '', $page, $sort_by);
    }

    function get_quest_delete($operation){

        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELQUEST'];
        $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':'setting', 'vis_operation':'delete_quest', 'vis_quest_id':".$operation['vis_quest_id'].", 'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function quest_details($operation)
    {
        global $vis_language;
        $database=new class_database();
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        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');
        $ticket=new class_ticket($database);
        $client=new class_client($database);
        $staff=new class_staff($database);
        $object=new class_setting($database);
        $quest_id = $action[4];
        list($quest_info, $quest_details) = $object->get_quest_list('quest_id = '.$action[4], '',0,0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $quest_criteria=$object->get_quest_criteria($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $quest_details=$quest_details[0];
        list($staffgroup_info, $staff_group)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($stfinfo, $staff_details)=$object->get_staff(VIS_TABLE_PREFIX.'staff.is_enabled=1','', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ticket_types=$ticket->get_type_list(VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($sla_count,$sla)=$object->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,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, 'is_enabled=1');
        $flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=1');
        include(VIS_PATH_TEMPLATE.'quest_details.php');
        return true;
    }

    function set_quest_image($operation)
    {
        include(VIS_PATH_TEMPLATE.'quest_image_gallery.php');
        return true;
    }
    function security_details($operation){ // security ip listing and updation form
		global $vis_language;

        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;

		$filter2=VIS_TABLE_PREFIX.'settings.title="vis_security_active"';
		$security_ip_active=$object->get_settings($filter2, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filter3=VIS_TABLE_PREFIX.'settings.title="vis_security_ip"';
		$security_ip_details=$object->get_settings($filter3, VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($security_ip_details[0]['content']==0){
			$security_ip_details=-1;
		}else{
			$ip_data=explode(',',$security_ip_details[0]['content']);
			$total_count=count($ip_data);
			$total_pages=ceil($total_count/SECURITY_DATA_PER_PAGE);
			$start_security_count =(1 - 1) * SECURITY_DATA_PER_PAGE;
		}
		$database->database_disconnect();
		$operation['view_title']=$vis_language['TXTSECURITY'];
		include(VIS_PATH_TEMPLATE.'security_details.php');
		return true;
    }
    function display_security_page($operation) // pagination page for security ip
	{
        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_ip"';
		$security_ip_details=$object->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$start_security_count =($operation['vis_page'] - 1) * SECURITY_DATA_PER_PAGE;
		$database->database_disconnect();
		$operation['view_title']=$vis_language['TXTSECURITY'];
		include(VIS_PATH_TEMPLATE.'security_pagi.php');

    }

    function security_password_form($operation) { // security password form
		$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_details=$object_setting->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'security_password.php');
        return true;
    }

	function get_security_ip_delete($operation) { // delete security ip action/
        global $vis_language;
        $operation['vis_current_operation']='delete_security_ip';
        $operation['vis_current_module']='setting';
        $message_info['vis_form_title']=$vis_language['TXTDELSECURITY'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_ip_address':'".$operation['vis_ip_address']."','security_ip_active':'".$operation['security_ip_active']."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

    function view_activity_log($operation) {  // activity log list
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
         include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_setting($database);
        $client_object=new class_client($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_content']) && $data['vis_content'] != "")
            {
                $filter = " content like '%".$data['vis_content']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_staff']) && $data['vis_staff'] != "")
            {
				$staff_flname = strpos($data['vis_staff'], ' ');
				if($staff_flname !== false){
					$staff_flname=explode(' ',$data['vis_staff']);
					$staff_filter="(first_name like '%".$staff_flname[0]."%' or last_name like '%".$staff_flname[1]."%') or ( first_name like '%".$staff_flname[1]."%' or last_name like '%".$staff_flname[0]."%' )";
				}else{
					$staff_filter="first_name like '%".$data['vis_staff']."%' or last_name like '%".$data['vis_staff']."%'";
				}
				$staff_details = $staff->get_list_staff($staff_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				if(isset($staff_details[0]['staff_id'])){
					$staff_name="";
					for($i=0;$i<count($staff_details);$i++){
						$staff_name .="user_id=".$staff_details[$i]['staff_id']." or ";
					}
					 $staff_name=substr($staff_name, 0, -3);
				}
				else{$staff_name="user_id=0";}
                if($filter != '') {$filter .= " and (".$staff_name.")";}
                else if($filter == ''){$filter .= " (".$staff_name.")";}
            }
            else $filter .= "";  
			/* if($data['from_date']!="" &&  $data['to_date']=="")
			 {
				 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "' . $vis_language['TXTPLEASESELECTTODATE'] . '"); </script>';
												return false;
			 }elseif($data['from_date']=="" && $data['to_date']!="")
			 {
				 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "' . $vis_language['TXTPLEASESELECTFROMDATE'] . '"); </script>';
												return false;
			 }*/
             if((isset($data['from_date']) && $data['from_date'] != "") && (isset($data['to_date']) && $data['to_date'] != ""))
            {
				$from=date('Y-m-d h:i:s',  strtotime($data['from_date']));
                $to=date('Y-m-d h:i:s',  strtotime($data['to_date']));
                if($filter != '') {$filter .= " and activity_date between unix_timestamp('".$from."')  AND unix_timestamp('".$to."')";}
                else if($filter == ''){$filter .= " activity_date between unix_timestamp('".$from."') AND unix_timestamp('".$to."')"; }
            }
            else $filter .= "";
            if(isset($data['vis_module_id']) && $data['vis_module_id'] != "")
            {
				if($filter != '') {$filter .= " and  module_id=".$data['vis_module_id'];}
                else if($filter == ''){$filter .= " module_id=".$data['vis_module_id']; }
            }
            else $filter .= "";
        }
        else
        {
        $filter = "";
        $data= "";
		}
        list($activitylog_info, $activitylog_details)=$object->get_activity_log($filter, $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($activitylog_info['total']==0)?0:ceil($activitylog_info['total']/$view_info['page_count']);
        $operation['view_title']=$vis_language['TXTACTIVITYLOG'];
        $operation['vis_operation']='get_activitylog_delete';
		$operation['vis_current_operation']='view_activity_log';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTDELETE'];
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'activity_log_list.php');
			$activity_log_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'=>$activitylog_info['total'], 'paging' => $select, 'list'=> $activity_log_list));
		}else
        include(VIS_PATH_TEMPLATE.'activity_log.php');
        $database->database_disconnect();
        return true;
    }
    function get_activitylog_delete($operation) { // activity log delete action
        global $vis_language;
        $operation['vis_action'] = str_replace(",","&", $operation['vis_action']);
        if(isset($operation['vis_activitylog_area']) && $operation['vis_activitylog_area']==0) {
            $message_info['vis_form_title']=$vis_language['TXTACTIVITYLOG'];
            $message_info['vis_message']=$vis_language['MSGSURE'];
            $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'empty_activitylog'})";
        }
        else {
            $message_info['vis_form_title']=$vis_language['TXTACTIVITYLOG'];
            $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('submit_form', {'vis_module':'setting', 'vis_operation':'delete_activitylog', 'vis_form':'vis_activitylog_form', 'vis_action':'".$operation['vis_action']."','vis_page':'".$vis_page."'})";
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

	function empty_activitylog($operation) { // empty activity log list
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret=$object->empty_table('activitylog', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); $("#vis_activitylog_delete_area").dialog("close"); </script>';
        }
        else {
			$activity_log=$object->add_staff_activity_log("Empty activity log list", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_activity_log"}); </script>';
		}
        $database->database_disconnect();
        return $ret;
    }

    function livechatinc($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':','; 
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}
	}
	
	function tawkto($operation)
	{   //print_r($operation);
		global $vis_language;
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}

	}
	
	function olark($operation)
	{   //print_r($operation);
		global $vis_language;
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}

	}
	
	function livechatinc_setting($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$filter='integration_type='.$operation['vis_integration_type'].' AND domain_id='.$operation['vis_domain'];
			list($livechat_info, $livechat_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$livechat_details=$livechat_details[0];
			include(VIS_PATH_TEMPLATE.'livechatinc_setting.php');
			$database->database_disconnect();
			return true;

    }

	function system_cleanup($operation) {
        global $vis_language;
        include(VIS_PATH_TEMPLATE.'system_cleanup.php');
		return true;
	}
	function get_system_cleanup($operation){
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!isset($data['vis_error_log'])){
         if(isset($data['vis_date']) && trim($data['vis_date'])=='') {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['TXTDATEMISS'].'");</script>';
			return false;
		}
		}
        if(trim($data['vis_date'])=='' && ( isset($data['vis_sentmail_log']) || isset($data['vis_audit_log']) || isset($data['vis_transction_gatway_log']) || isset($data['vis_activity_log']) || isset($data['vis_parser_log']))) {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['TXTDATEMISS'].'");</script>';
			return false;
		}
		if(!isset($data['vis_error_log'])){
			if(trim($data['vis_date'])!='' && !isset($data['vis_audit_log']) &&  !isset($data['vis_sentmail_log']) && !isset($data['vis_transction_gatway_log']) && !isset($data['vis_activity_log']) && !isset($data['vis_parser_log'])) {
			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);

        if(trim($data['vis_date'])!=''){
			$dt=strtotime($data['vis_date']);
			if(isset($data['vis_activity_log'])){
				$filter = " activity_date <= '".$dt."'";
				$ret=$setting_object->delete_activitylog($filter, $userid, $user);
			}
			if(isset($data['vis_parser_log'])){
				$filter = " entry_date <= '".$dt."'";
				$ret=$setting_object->delete_parserlog('', $userid, $user, $filter);
				$activity_log=$setting_object->add_staff_activity_log("Removed parser log till ".$data['vis_date'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			}
			if(isset($data['vis_sentmail_log'])){
				$filter = " send_date <= '".$dt."'";
				$ret=$setting_object->delete_sentmail($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				$activity_log=$setting_object->add_staff_activity_log("Removed sentmail log till ".$data['vis_date'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			}
			if(isset($data['vis_transction_gatway_log'])){
				$filter = " entry_date <= '".$dt."'";
				$ret=$setting_object->delete_gateway_log($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				$activity_log=$setting_object->add_staff_activity_log("Removed gateway transaction log till ".$data['vis_date'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			}
			if(isset($data['vis_audit_log'])){
				$filter = " entry_date <= '".$dt."'";
				$ret=$setting_object->delete_audit_log($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				$activity_log=$setting_object->add_staff_activity_log("Removed audit log till  ".$data['vis_date'], VIS_STAFF_ID,'',VIS_LOCATION_AREA);
			}
		}
		if(isset($data['vis_error_log'])){
				$filename=VIS_PATH_LOG.'vis_error_log';
				$f1=fopen($filename, 'w');
				$filename=VIS_PATH_LOG.'vis_exception_log';
				$f2=fopen($filename, 'w');
				$ret=true;
				$activity_log=$setting_object->add_staff_activity_log("Removed error log ", VIS_STAFF_ID,'',VIS_LOCATION_AREA);
		}
		if($ret)
		{
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTSYSTEMCLEANUP'].'",{"vis_module":"setting", "vis_operation":"system_cleanup"});</script>';
			return true;
		}
    }
	function livezilla($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}

    }
    function import_staffs($operation)
    {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $database=new class_database();
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
        list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staffgroup_info, $staff_group)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $email_templates)=$object->get_etemplate('is_enabled=1 and language=1 ', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'staff_import.php');
        return true;
    }
    function import_staff_list($operation){
          global $vis_language;
          $database = new class_database();
          $data=parse_form_array($operation['vis_action']);
          include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
          $object=new class_client($database);
          include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
          $staff_object=new class_staff($database);
          $arr_attachment = explode(',',$data['vis_import_attachments']);
          $filter = 'parent_type=4 and attachment_id='.$arr_attachment[0] ;
          $attach = $object->get_attachment($filter, VIS_STAFF_ID, VIS_LOCATION_AREA) ;
		  if($attach!=-1){
             for($i=0;$i<count($attach);$i++){
                     $file_name =VIS_PATH_FILES.$attach[$i]['content'];
                     $file_handle = fopen($file_name, "r");
                     $first_row = fgetcsv($file_handle, 1000, ";");
                     while (!feof($file_handle) ){
                          $line_of_text = fgetcsv($file_handle);
                          if(trim($line_of_text[3]) != "" ){
							$staff =$staff_object->get_staff('(email="'.$line_of_text[3].'" || user_name="'.$line_of_text[3].'")', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
							if($staff ==-1) {
								if(trim($line_of_text[0]) == ""){
									$explode=explode('@', $line_of_text[3]);
									$data['vis_firstname'] = $explode[0];
								}else{
									$data['vis_firstname'] = $line_of_text[0];
								}
								$data['vis_lastname'] = $line_of_text[1];

								if(trim($line_of_text[2]) == ""){
									$data['vis_username'] = $line_of_text[3];
								}else{
									$data['vis_username'] = $line_of_text[2];
								}
								$data['vis_password'] = generate_random('alfanum', 8);
                                $data['vis_email'] = $line_of_text[3];
                                include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
								$setting_object=new class_setting($database);
								 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
								$subsetting_object=new class_subsetting($database);
                                $ret=$subsetting_object->add_staff($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
								if($ret && isset($data['vis_send_email']) && $data['vis_send_email']!=0) {
									list($info, $template)=$setting_object->get_etemplate('etemplate_id='.$data['vis_send_email'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
									list($info, $domain)=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
									if($template!=-1 && $domain!=-1) {
										include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'mail.php');
										$mail=new class_mail($database);
										$body=$template[0]['content'];
										$pattarns=array('/{staff_name}/','/{user_name}/','/{password}/','/{link}/');
										$replace=array($data['vis_firstname'].' '.$data['vis_lastname'], $data['vis_username'], $data['vis_password'], $domain[0]['domain_url']);
										$body=preg_replace($pattarns,$replace,$body);
										$mail->send_mail(0, $domain[0]['domain_id'], $domain[0]['default_email'], $data['vis_email'], $template[0]['subject'], $body);
									}
								}
								$activity_log=$setting_object->add_staff_activity_log("Imported new staff ".$data['vis_firstname']." ".$data['vis_lastname']." ( ".$data['vis_email']." ) ", 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['TXTIMPORT'].'",{"vis_module":"setting", "vis_operation":"view_staff"});</script>';
         }
         else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
   }
   function userlike($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}

    }
	function remoteaccess($operation){
	    global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter_meeting='integration_type=23 AND domain_id=0 AND is_enabled=1';

		list($cnt_info, $meeting_details)=$object->get_integration_setting($filter_meeting, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$meeting_details=$meeting_details[0];

		$filter_assist='integration_type=24 AND domain_id=0 AND is_enabled=1';
		list($cnt_info, $assist_details)=$object->get_integration_setting($filter_assist, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$assist_details=$assist_details[0];

		$filter_webex='integration_type=26 AND domain_id=0 AND is_enabled=1';
		list($cnt_info, $webex_details)=$object->get_integration_setting($filter_webex, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$webex_details=$webex_details[0];

		$filter_teamviewer='integration_type=25 AND domain_id=0 AND is_enabled=1';
		list($cnt_info, $teamviewer_details)=$object->get_integration_setting($filter_teamviewer, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$teamviewer_details=$teamviewer_details[0];

		/*$filter_twilio='integration_type=27 AND domain_id=0 AND is_enabled=1';
		list($cnt_info, $twilio_details)=$object->get_integration_setting($filter_twilio, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$twilio_details=$twilio_details[0];*/

		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'remoteaccess.php');
		return true;
	}
   function remote_access_setting($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			if($operation['vis_domain']=='all'){$operation['vis_domain']=0;}
			
			$filter_meeting='integration_type=23 AND domain_id='.$operation['vis_domain'];
			list($cnt_info, $meeting_details)=$object->get_integration_setting($filter_meeting, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$meeting_details=$meeting_details[0];

			$filter_assist='integration_type=24 AND domain_id='.$operation['vis_domain'];
			list($cnt_info, $assist_details)=$object->get_integration_setting($filter_assist, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$assist_details=$assist_details[0];

			$filter_teamviewer='integration_type=25 AND domain_id='.$operation['vis_domain'];
			list($cnt_info, $teamviewer_details)=$object->get_integration_setting($filter_teamviewer, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$teamviewer_details=$teamviewer_details[0];

			$filter_webex='integration_type=26 AND domain_id='.$operation['vis_domain'];
			list($cnt_info, $webex_details)=$object->get_integration_setting($filter_webex, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$webex_details=$webex_details[0];

			/*$filter_twilio='integration_type=27 AND domain_id='.$operation['vis_domain'];
			list($cnt_info, $twilio_details)=$object->get_integration_setting($filter_twilio, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$twilio_details=$twilio_details[0];*/

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

	function view_survey($operation){
        global $vis_language;
        $operation['view_title']=$vis_language['TXTSURVEY'];
        $operation['vis_operation']='new_survey';
		$operation['vis_current_operation']='view_survey';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDSURVEY'];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
 		$staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
   		$filter = "location = 4";
		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_status']!='')
		   	$filter.= ' and is_enabled='.$data['vis_status'];
						
		    if($data['vis_survey']!='')
				$filter .= " having customgroup_name like '%".$data['vis_survey']."%'"  ;
		   
        }
        $custom_group_details=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        $custom_group_total=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $custom_group_total=(!$custom_group_total || $custom_group_total==-1)?0:count($custom_group_total);
		$group_info['group_count']= $custom_group_total;
		$view_info['page_count']=($custom_group_total==0)?0:ceil($custom_group_total/$view_info['page_count']);
        $database->database_disconnect();
		$group_info['page']=$page;
		 if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'survey_list.php');
			$staff_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><script>$('.selectpicker').selectpicker();</script>";
			echo json_encode( array('total_cnt'=>$custom_group_total, 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'survey.php');
    }

    function survey_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTSURVEY'];
        $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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $filter=VIS_TABLE_PREFIX.'customgroup.customgroup_id='.$action[4].' ';
            $custom_group_details=$object->get_custom_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,'','edit_page');
             $customgroup_lang=$object->get_translation(23, 'data_id='.$custom_group_details[0]['customgroup_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
            $custom_department=explode(',', $custom_group_details[0]['department_access']);
            include(VIS_PATH_TEMPLATE.'survey_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

    function surveyfield_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'customfield.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'customfield.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $filter .= ' location = 4 ';
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($customfield_info, $customfield_details)=$object->get_customfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($customfield_info['total']==0)?0:ceil($customfield_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $customfield_info['customfield_count']=(!$customfield_details || $customfield_details==-1)?0:count($customfield_details);
        $customfield_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTSURVEYFIELD'];
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'survey_field_list.php');
			$staff_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'=>$customfield_info['customfield_count'], 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'survey_field.php');
        return true;
    }

    function view_surveyfield($operation) {
        global $vis_language;
        $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']:'';
        $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);
        $operation['view_title']=$vis_language['TXTSURVEYFIELD'];
        $operation['vis_operation']='new_surveyfield';
		$operation['vis_current_operation']='view_surveyfield';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDSURVEYFIELD'];

		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_survey_field']!='')
			{
				$filter = "1 having customgroup_name like '%".$data['vis_survey_field']."%'"  ;
				$custom_group = $setting_object->get_custom_group_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
				$and_operations['customgroup_id'] = ' IN (';
				if($custom_group!=-1) {
				for($i=0;$i< (count($custom_group));$i++)
					$and_operations['customgroup_id'] .= $custom_group[$i]['customgroup_id'].',';
				$and_operations['customgroup_id'] = trim($and_operations['customgroup_id'],',');
				$and_operations['customgroup_id'] .= ')';
				}else $and_operations['customgroup_id'] .= '0)';
			}
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
        $database->database_disconnect(VIS_STAFF_ID, VIS_LOCATION_AREA);
        return $this->surveyfield_display($operation, $and_operations, '', '', $page, $sort_by);
    }

    function surveyfield_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTSURVEYFIELD'];
        $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.'setting.php');
            $object=new class_setting($database);
            $filter = " location = 4 and is_enabled=1";
            $custom_group_details=$object->get_custom_group_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,'','edit_page');
            $filter=VIS_TABLE_PREFIX.'customfield.field_group='.$action[4].' ';
            list($customfield_info, $customfield_details)=$object->get_customfield(1, $filter, '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA,'edit_page');
            $customfield_lang=$object->get_translation(22, 'data_id='.$customfield_details[0]['field_group'],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			for($i=0;$i<count($customfield_details);$i++)
			{ $customfield_option_lang=$object->get_translation(28, 'data_id='.$customfield_details[$i]['customfield_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);	 
			 $customfield_array_lang[]= $customfield_option_lang;
            }
            include(VIS_PATH_TEMPLATE.'survey_field_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGMISSINFO'];
            return false;
        }
    }
    function get_surveyfield_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETESURVEYFIELD'];
        $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':'setting', 'vis_operation':'delete_customfield', 'vis_fieldgroup_id':".$operation['vis_fieldgroup_id'].", 'is_survey':'1','vis_page':".$vis_page."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }

	function comm100($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {

			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'livechatinc.php');
			return true;
		}
    }
    function twilio($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		list($vis_all_domain, $twilio_details)=$object->integation_app_availability('27', 'none');
		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$twilio_details = $twilio_details[0];
		include(VIS_PATH_TEMPLATE.'twilio_setting.php');
		return true;
	}
	function twilio_setting($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		if($operation['vis_domain']=='all'){$operation['vis_domain']=0;}
		$filter='integration_type=27 AND domain_id='.$operation['vis_domain'];
		list($twilio_info, $twilio_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$twilio_details = $twilio_details[0];
		include(VIS_PATH_TEMPLATE.'twilio_setting_details.php');
		return true;
	}
	function twilio_number($operation) {  // activity log list
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        
        list($number_count, $twilio_number)=$object->get_twilio_number('', $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$view_info['page_count']=($number_count['total']==0)?0:ceil($number_count['total']/$view_info['page_count']);
        
        include(VIS_PATH_TEMPLATE.'twilio_number.php');
        $database->database_disconnect();
        return true;
    }
	function new_twilio_phone($operation){
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		       
		$filter='integration_type=27 AND is_enabled=1';
		list($integration_info, $integration_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        $database->database_disconnect();
		include(VIS_PATH_TEMPLATE.'twilio_add_new_number.php');
		return true;
    }
	
	function get_twilio_call_department($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.'ticket.php');
        $ticket=new class_ticket($database);
        $filter ='';
		if($operation['integration_id']!=0){
			$filter1='integration_type=27 AND integration_id='.$operation['integration_id'];
			list($twilio_info, $twilio_details)=$object->get_integration_setting($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			if($twilio_details[0]['domain_id']!=0){
				$filter .= VIS_TABLE_PREFIX.'domain.domain_id='.$twilio_details[0]['domain_id'].' AND ';
			}
		}
        $filter .=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
        $departments=$ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
        $departmentid = $departments[0]['department_id'];
        if(isset($operation['integration_id'])){
			include(VIS_PATH_TEMPLATE.'twilio_add_call_details.php');
		}
       return true;
	}
	function get_department_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='is_enabled=1';
        $staff=$object->get_staff($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, $operation['department_id']);
		include(VIS_PATH_TEMPLATE.'twilio_add_number_details.php');
		return true;
	}
	function twilio_details($operation){
		global $vis_language;
        $operation['view_title']=$vis_language['TXTFLAG'];
        $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.'setting.php');
            $setting_object=new class_setting($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);
			
            $filter='twilio_id='.$action[4].' ';
			list($number_count, $twilio_details)=$setting_object->get_twilio_number($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($twilio_details==-1){
				$this->error=$vis_language['MSGINFOMISS'];
				return false;
			}
			$twilio_details = $twilio_details[0];
			$filter='twilio_id='.$action[4].' ';
            $key_details = $setting_object->get_twilio_key($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			list($integration_info, $integration_details)=$setting_object->get_integration_setting('integration_type=27 AND is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
			$filter ='';
            if($twilio_details['integration_id']!=0){
				$filter1='integration_type=27 AND integration_id='.$twilio_details['integration_id'];
				list($twilio_info, $twilio_intgration)=$setting_object->get_integration_setting($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
				
				if($twilio_intgration[0]['domain_id']!=0){
					$filter .= VIS_TABLE_PREFIX.'domain.domain_id='.$twilio_intgration[0]['domain_id'].' AND ';
				}
			}
			$filter .=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$ticket_object->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$departmentid = $departments[0]['department_id'];
			
            include(VIS_PATH_TEMPLATE.'twilio_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
	}
	//************IMPACT SECTION STARTS************************************
	function view_impact($operation) {
        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.'setting.php');
        $object=new class_setting($database);
        $staff=new class_staff($database);
		
        $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']:'';
        $operation['view_title']=$vis_language['TXTIMPACT'];

		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_name']!=''){
				$filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_impact.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }
        
		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($impact_info, $impact_details)=$object->get_impact($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($impact_info, $impact_details)=$object->get_properties('get_impacts', $filter,$limit);
			if($impact_details[0]=='') {$impact_info['total']=0;$impact_details=-1;}
		}
        
        $view_info['page_count']=($impact_info['total']==0)?0:ceil($impact_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $impact_info['impact_count']=(!$impact_details || $impact_details==-1)?0:count($impact_details);
        $impact_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTIMPACT'];
        $operation['vis_current_operation']='view_impact';
        $operation['vis_current_module']='setting';
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'impact_list.php');
			$impact_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'=>$impact_info['total'], 'paging' => $select, 'list'=> $impact_list));
		}else
			include(VIS_PATH_TEMPLATE.'impact.php');
        return true;
    }

	function impact_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_impact_id'])) $action[4]=$operation['vis_impact_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_impact.impact_id='.$action[4].' ';
			list($impact_info, $impact_details)=$object->get_impact($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $impact_details=$impact_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$impact_department=explode(',', $impact_details['department_access']);

			$impact_lang=$object->get_translation(9, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTIMPACT'];
            include(VIS_PATH_TEMPLATE.'impact_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

	//************RISK SECTION STARTS************************************
	function view_risk($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTRISK'];
        $filter = "";
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {

            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_name']) && $data['vis_name'] != "")
            {
                   $filter .= VIS_TABLE_PREFIX."language_data.title like '%".$data['vis_name']."%' and "  ;
                //   $filter.= " and data_id=status_id";
            }
            
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                
               $filter .= VIS_TABLE_PREFIX."itil_risk.is_enabled =".$data['vis_status'].' and '; 
            }
            $filter=substr($filter,0,-4);
        }
      	$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($risk_info, $risk_details)=$object->get_risk($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($risk_info, $risk_details)=$object->get_properties('get_risks', $filter,$limit);
	    	if($risk_details[0]=='') {$risk_info['total']=0;$risk_details=-1;}
		}
	    $view_info['page_count']=($risk_info['total']==0)?0:ceil($risk_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTRISK'];

        $database->database_disconnect();
        $risk_info['risk_count']=(!$risk_details || $risk_details==-1)?0:count($risk_details);
        $risk_info['page']=$page;
        $operation['vis_current_operation']='view_risk';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'risk_list.php');
			$risk_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'=>$risk_info['total'], 'paging' => $select, 'list'=> $risk_list));
		}else
			include(VIS_PATH_TEMPLATE.'risk.php');
        return true;
    }

	function risk_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_risk_id'])) $action[4]=$operation['vis_risk_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_risk.risk_id='.$action[4].' ';
			list($risk_info, $risk_details)=$object->get_risk($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $risk_details=$risk_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$risk_department=explode(',', $risk_details['department_access']);

			$risk_lang=$object->get_translation(10, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTRISK'];
            include(VIS_PATH_TEMPLATE.'risk_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************CHANGE TYPE SECTION STARTS************************************
	function view_change_type($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTCHANGETYPE'];

		$filter = "";
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_name']) && $data['vis_name'] != "")
            {
                   $filter .= VIS_TABLE_PREFIX."language_data.title like '%".$data['vis_name']."%' and "  ;
                //   $filter.= " and data_id=status_id";
            }
            
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                
               $filter .= VIS_TABLE_PREFIX."itil_change_type.is_enabled =".$data['vis_status'].' and '; 
            }
            $filter=substr($filter,0,-4);
        }
      	$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
        
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($change_type_info, $change_type_details)=$object->get_change_type($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($change_type_info, $change_type_details)=$object->get_properties('get_change_type', $filter,$limit);
			if($change_type_details[0]=='') {$change_type_info['total']=0;$change_type_details=-1;}
		}
		
        $view_info['page_count']=($change_type_info['total']==0)?0:ceil($change_type_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCHANGETYPE'];

        $database->database_disconnect();
        $change_type_info['change_type_count']=(!$change_type_details || $change_type_details==-1)?0:count($change_type_details);
        $change_type_info['page']=$page;
        $operation['vis_current_operation']='view_change_type';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'change_type_list.php');
			$change_type_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'=>$change_type_info['total'], 'paging' => $select, 'list'=> $change_type_list));
		}else
			include(VIS_PATH_TEMPLATE.'change_type.php');
        return true;
    }

	function change_type_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_change_type_id'])) $action[4]=$operation['vis_change_type_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_change_type.change_type_id='.$action[4].' ';
			list($change_type_info, $change_type_details)=$object->get_change_type($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $change_type_details=$change_type_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$change_type_department=explode(',', $change_type_details['department_access']);

			$change_type_lang=$object->get_translation(11, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTCHANGETYPE'];
            include(VIS_PATH_TEMPLATE.'change_type_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************RELEASE TYPE SECTION STARTS************************************
	function view_release_type($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTRELEASETYPE'];

		$filter = "";
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_name']) && $data['vis_name'] != "")
            {
                   $filter .= VIS_TABLE_PREFIX."language_data.title like '%".$data['vis_name']."%' and "  ;
                //   $filter.= " and data_id=status_id";
            }
           
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                
               $filter .= VIS_TABLE_PREFIX."itil_release_type.is_enabled =".$data['vis_status'].' and '; 
            }
            $filter=substr($filter,0,-4);
        }

      	$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($release_type_info, $release_type_details)=$object->get_release_type($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($release_type_info, $release_type_details)=$object->get_properties('get_release_type', $filter,$limit);
			if($release_type_details[0]=='') {$release_type_info['total']=0;$release_type_details=-1;}
		}
				
        $view_info['page_count']=($release_type_info['total']==0)?0:ceil($release_type_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTRELEASETYPE'];

        $database->database_disconnect();
        $release_type_info['release_type_count']=(!$release_type_details || $release_type_details==-1)?0:count($release_type_details);
        $release_type_info['page']=$page;
        $operation['vis_current_operation']='view_release_type';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'release_type_list.php');
			$release_type_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'=>$release_type_info['total'], 'paging' => $select, 'list'=> $release_type_list));
		}else
			include(VIS_PATH_TEMPLATE.'release_type.php');
        return true;
    }

	function release_type_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_release_type_id'])) $action[4]=$operation['vis_release_type_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_release_type.release_type_id='.$action[4].' ';
			list($release_type_info, $release_type_details)=$object->get_release_type($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $release_type_details=$release_type_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$release_type_department=explode(',', $release_type_details['department_access']);

			$release_type_lang=$object->get_translation(12, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTRELEASETYPE'];
            include(VIS_PATH_TEMPLATE.'release_type_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************ASSET STATE SECTION STARTS************************************
	function view_asset_state($operation) {
        global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		
        $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']:'';
        $operation['view_title']=$vis_language['TXTASSETSTATE'];

		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_name']!=''){
				$filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_asset_state.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($asset_state_info, $asset_state_details)=$object->get_asset_state($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($asset_state_info, $asset_state_details)=$object->get_properties('get_asset_state', $filter,$limit);
			if($asset_state_details[0]=='') {$asset_state_info['total']=0;$asset_state_details=-1;}
		}
		
        $view_info['page_count']=($asset_state_info['total']==0)?0:ceil($asset_state_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTASSETSTATE'];

        $database->database_disconnect();
        $asset_state_info['asset_state_count']=(!$asset_state_details || $asset_state_details==-1)?0:count($asset_state_details);
        $asset_state_info['page']=$page;
        $operation['vis_current_operation']='view_asset_state';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'asset_state_list.php');
			$asset_state_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'=>$asset_state_info['total'], 'paging' => $select, 'list'=> $asset_state_list));
		}else
			include(VIS_PATH_TEMPLATE.'asset_state.php');
        return true;
    }

	function asset_state_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_asset_id'])) $action[4]=$operation['vis_asset_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_asset_state.asset_id='.$action[4].' ';
			list($asset_state_info, $asset_state_details)=$object->get_asset_state($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $asset_state_details=$asset_state_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$asset_state_department=explode(',', $asset_state_details['department_access']);

			$asset_state_lang=$object->get_translation(6, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTASSETSTATE'];
            include(VIS_PATH_TEMPLATE.'asset_state_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************CONTRACT TYPE SECTION STARTS************************************
	function view_contract_type($operation) {
        global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		
        $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']:'';
        $operation['view_title']=$vis_language['TXTCONTRACTTYPE'];

		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_name']!=''){
				$filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_contract_type.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($contract_type_info, $contract_type_details)=$object->get_contract_type($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($contract_type_info, $contract_type_details)=$object->get_properties('get_contract_type', $filter,$limit);
			if($contract_type_details[0]=='') {$contract_type_info['total']=0;$contract_type_details=-1;}
		}
			  
		$view_info['page_count']=($contract_type_info['total']==0)?0:ceil($contract_type_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCONTRACTTYPE'];

        $database->database_disconnect();
        $contract_type_info['contract_type_count']=(!$contract_type_details || $contract_type_details==-1)?0:count($contract_type_details);
        $contract_type_info['page']=$page;
        $operation['vis_current_operation']='view_contract_type';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'contract_type_list.php');
			$contract_type_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'=>$contract_type_info['total'], 'paging' => $select, 'list'=> $contract_type_list));
		}else
			include(VIS_PATH_TEMPLATE.'contract_type.php');
        return true;
    }

	function contract_type_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_contract_type_id'])) $action[4]=$operation['vis_contract_type_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_contract_type.contract_type_id='.$action[4].' ';
			list($contract_type_info, $contract_type_details)=$object->get_contract_type($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $contract_type_details=$contract_type_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$contract_type_department=explode(',', $contract_type_details['department_access']);

			$contract_type_lang=$object->get_translation(8, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTCONTRACTTYPE'];
            include(VIS_PATH_TEMPLATE.'contract_type_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************VENDORS SECTION STARTS************************************
	function view_vendor($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTVENDOR'];
		$filter='';
		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_name']!='')$filter.=VIS_TABLE_PREFIX.'itil_vendor.name like "%'.$data['vis_name'].'%" and ';
			if($data['vis_status']!='')$filter.=VIS_TABLE_PREFIX.'itil_vendor.is_enabled='.$data['vis_status'].' and ';
		    $filter=substr($filter,0,-4);
        }
		
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        if(VIS_ADMIN_ACCESS_LEVEL==1)
			 list($vendor_info, $vendor_details)=$object->get_vendor($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($vendor_info, $vendor_details)=$object->get_properties('get_vendor', $filter,$limit);
			if($vendor_details[0]=='') {$vendor_info['total']=0;$vendor_details=-1;}
		}  
        
        $view_info['page_count']=($vendor_info['total']==0)?0:ceil($vendor_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTVENDOR'];

        $database->database_disconnect();
        if(VIS_LOCATION_AREA == 0) {
			if($vendor_details!=-1) echo get_xml($vendor_details, 'vendor');
			else echo $vis_language['MSGDATANOTFND'];
		}
        $vendor_info['vendor_count']=(!$vendor_details || $vendor_details==-1)?0:count($vendor_details);
        $vendor_info['page']=$page;
        $operation['vis_current_operation']='view_vendor';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'vendor_list.php');
			$vendor_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'=>$vendor_info['total'], 'paging' => $select, 'list'=> $vendor_list));
		}else
			include(VIS_PATH_TEMPLATE.'vendor.php');
        return true;
    }

	function vendor_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }

        if(!isset($action[4]) && isset($operation['vis_vendor_id'])) $action[4]=$operation['vis_vendor_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_vendor.vendor_id='.$action[4].' ';
			list($vendor_info, $vendor_details)=$object->get_vendor($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $vendor_details=$vendor_details[0];
			
			$operation['vis_section_area'] = 'vendor';
		    $database->database_disconnect();
		    $operation['view_title']=$vis_language['TXTVENDOR'];
			if(isset($operation['vis_tab_profile']))
				include(VIS_PATH_TEMPLATE.'vendor_profile.php');
			else
            	include(VIS_PATH_TEMPLATE.'vendor_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************REQUEST STAGE SECTION STARTS************************************
	function view_request_stage($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTREQUESTSTAGE'];

		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_name']!='') $and_operations['name like "%'] = $data['vis_name'].'%"';
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }

        return $this->request_stage_display($operation, $and_operations,'', '', $page, $sort_by);
    }

	function request_stage_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'itil_request_stage.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        $filter=substr($filter,0,-4);

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($request_stage_info, $request_stage_details)=$object->get_request_stage($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        
        $view_info['page_count']=($request_stage_info['total']==0)?0:ceil($request_stage_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTREQUESTSTAGE'];

        $database->database_disconnect();
        $request_stage_info['request_stage_count']=(!$request_stage_details || $request_stage_details==-1)?0:count($request_stage_details);
        $request_stage_info['page']=$page;
        $operation['vis_current_operation']='view_request_stage';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'request_stage_list.php');
			$request_stage_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'=>$request_stage_info['total'], 'paging' => $select, 'list'=> $request_stage_list));
		}else
			include(VIS_PATH_TEMPLATE.'request_stage.php');
        return true;
    }

	function request_stage_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_request_stage_id'])) $action[4]=$operation['vis_request_stage_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_request_stage.request_stage_id='.$action[4].' ';
			list($request_stage_info, $request_stage_details)=$object->get_request_stage($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $request_stage_details=$request_stage_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$request_stage_department=explode(',', $request_stage_details['department_access']);

			$request_stage_lang=$object->get_translation(1, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTREQUESTSTAGE'];
            include(VIS_PATH_TEMPLATE.'request_stage_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }

	//************LICENSE TYPE SECTION STARTS************************************
	function view_license_type($operation) {
        global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		
        $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']:'';
        $operation['view_title']=$vis_language['TXTLICENSETYPE'];
		
		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_name']!=''){
				$filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_license_type.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }
		
		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			 list($license_type_info, $license_type_details)=$object->get_license_type($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($license_type_info, $license_type_details)=$object->get_properties('get_license_type', $filter,$limit);
			if($license_type_details[0]=='') {$license_type_info['total']=0;$license_type_details=-1;}
		}  
		
        $view_info['page_count']=($license_type_info['total']==0)?0:ceil($license_type_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTLICENSETYPE'];
        $database->database_disconnect();
        $license_type_info['license_type_count']=(!$license_type_details || $license_type_details==-1)?0:count($license_type_details);
        $license_type_info['page']=$page;
        $operation['vis_current_operation']='view_license_type';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'license_type_list.php');
			$license_type_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'=>$license_type_info['total'], 'paging' => $select, 'list'=> $license_type_list));
		}else
			include(VIS_PATH_TEMPLATE.'license_type.php');
        return true;
    }

	function license_type_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_license_type_id'])) $action[4]=$operation['vis_license_type_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_license_type.license_type_id='.$action[4].' ';
			list($license_type_info, $license_type_details)=$object->get_license_type($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $license_type_details=$license_type_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$license_type_department=explode(',', $license_type_details['department_access']);

			$license_type_lang=$object->get_translation(7, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTLICENSETYPE'];
            include(VIS_PATH_TEMPLATE.'license_type_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************CI PRODUCT STATUS SECTION STARTS************************************
	function view_product_status($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTCIPRODSTATUS'];

		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_name']!=''){
				 $filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_ci_product_status.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }
		
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($product_status_info, $product_status_details)=$object->get_product_status($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($product_status_info, $product_status_details)=$object->get_properties('get_product_status', $filter,$limit); 
			if($product_status_details[0]=='') {$product_status_info['total']=0;$product_status_details=-1;}
		}
		        
		$view_info['page_count']=($product_status_info['total']==0)?0:ceil($product_status_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCIPRODSTATUS'];
		
        $database->database_disconnect();
        $product_status_info['product_status_count']=(!$product_status_details || $product_status_details==-1)?0:$product_status_info['total'];
        $product_status_info['page']=$page;
		
        $operation['vis_current_operation']='view_product_status';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'product_status_list.php');
			$product_status_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'=>$product_status_info['total'], 'paging' => $select, 'list'=> $product_status_list));
		}else
			include(VIS_PATH_TEMPLATE.'product_status.php');
        return true;
    }

	function product_status_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_product_status_id'])) $action[4]=$operation['vis_product_status_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_ci_product_status.product_status_id='.$action[4].' ';
			list($product_status_info, $product_status_details)=$object->get_product_status($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $product_status_details=$product_status_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$product_status_department=explode(',', $product_status_details['department_access']);

			$product_status_lang=$object->get_translation(13, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTCIPRODSTATUS'];
            include(VIS_PATH_TEMPLATE.'product_status_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************MODE OF PROCUREMENT SECTION STARTS************************************
	function view_procure_mode($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTPROCUREMODE'];
		$filter="";
		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_name']!=''){
				 $filter .= VIS_TABLE_PREFIX.'language_data.title like "%'.$data['vis_name'].'%" and ';
			}
			if($data['vis_status']!=''){
				$filter .= VIS_TABLE_PREFIX.'itil_procurement_mode.is_enabled='.$data['vis_status'].' and ';
			}
			$filter=substr($filter, 0, -4);
        }
		
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($procure_mode_info, $procure_mode_details)=$object->get_procure_mode($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($procure_mode_info, $procure_mode_details)=$object->get_properties('get_procure_mode',$filter,$limit); 
			if($procure_mode_details[0]==''){
				$procure_mode_info['total']=0;
				$procure_mode_details=-1;
			}
		}
		
	    $view_info['page_count']=($procure_mode_info['total']==0)?0:ceil($procure_mode_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTPROCUREMODE'];

        $database->database_disconnect();
        $procure_mode_info['procure_mode_count']=(!$procure_mode_details || $procure_mode_details==-1)?0:count($procure_mode_details);
        $procure_mode_info['page']=$page;
        $operation['vis_current_operation']='view_procure_mode';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'procure_mode_list.php');
			$procure_mode_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'=>$procure_mode_info['total'], 'paging' => $select, 'list'=> $procure_mode_list));
		}else
			include(VIS_PATH_TEMPLATE.'procure_mode.php');
        return true;
    }

	function procure_mode_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_procurement_id'])) $action[4]=$operation['vis_procurement_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_procurement_mode.procurement_id='.$action[4].' ';
			list($procure_mode_info, $procure_mode_details)=$object->get_procure_mode($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $procure_mode_details=$procure_mode_details[0];

			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$procure_mode_department=explode(',', $procure_mode_details['department_access']);

			$procure_mode_lang=$object->get_translation(14, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);

            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTPROCUREMODE'];
            include(VIS_PATH_TEMPLATE.'procure_mode_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	
	//*********************CI PRODUCT SECTION STARTS************************************
	function view_ci_product($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTPRODUCTCATALOG'];
		$filter="";
		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_name']!='')$filter.=VIS_TABLE_PREFIX.'itil_ci_product.name like "%'.$data['vis_name'].'%" and ';
			if($data['vis_status']!='')$filter.=VIS_TABLE_PREFIX.'itil_ci_product.is_enabled='.$data['vis_status'].' and ';
		    $filter=substr($filter,0,-4);
        }

        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
		$staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);

		list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        
		if(VIS_ADMIN_ACCESS_LEVEL==1)
			list($ci_product_info, $ci_product_details)=$object->get_ci_product($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        else{
			list($ci_product_info, $ci_product_details)=$object->get_properties('get_ci_product',$filter,$limit);
			if($ci_product_details[0]=='') {$ci_product_info['total']=0;$ci_product_details=-1;}
		}
			  
		$view_info['page_count']=($ci_product_info['total']==0)?0:ceil($ci_product_info['total']/$view_info['page_count']);
		$view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTPRODUCTCATALOG'];

        $database->database_disconnect();
        $ci_product_info['ci_product_count']=(!$ci_product_details || $ci_product_details==-1)?0:count($ci_product_details);
        $ci_product_info['page']=$page;
        $operation['vis_current_operation']='view_ci_product';
        $operation['vis_current_module']='setting';
        if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'ci_product_list.php');
			$ci_product_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'=>$ci_product_info['total'], 'paging' => $select, 'list'=> $ci_product_list));
		}else
			include(VIS_PATH_TEMPLATE.'ci_product.php');
        return true;
    }

	function ci_product_details($operation) {
        global $vis_language;
        if(isset($operation['vis_action'])){
            if(is_array($operation['vis_action'])){
                $action=$operation['vis_action'];
            }
            else{
                $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
                $action=explode($spliter, $operation['vis_action']);
            }
        }
        if(!isset($action[4]) && isset($operation['vis_product_id'])) $action[4]=$operation['vis_product_id'];
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
            $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.'subsetting.php');
			$sub_object=new class_subsetting($database);

            $filter=VIS_TABLE_PREFIX.'itil_ci_product.product_id='.$action[4].' ';
			list($ci_product_info, $ci_product_details)=$object->get_ci_product($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $ci_product_details=$ci_product_details[0];

			$citype_details=$object->get_configuration_item_category('','is_enabled=1');
			//$citype_details=$object->get_configuration_item(" and is_enabled=1", 0, -1, $sort_by='', '');
			list($productstatus_info,$productstatus_details)=$object->get_product_status(VIS_TABLE_PREFIX.'itil_ci_product_status.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($procuremode_info,$procuremode_details)=$object->get_procure_mode(VIS_TABLE_PREFIX.'itil_procurement_mode.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$ci_product_department=explode(',', $ci_product_details['department_access']);
			$operation['vis_section_area'] = 'product';
            $database->database_disconnect();
            $operation['view_title']=$vis_language['TXTPRODUCTCATALOG'];
			if(isset($operation['vis_tab_product']))
				include(VIS_PATH_TEMPLATE.'edit_product.php');
			else
            	include(VIS_PATH_TEMPLATE.'ci_product_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	//************CI TYPE SECTION STARTS************************************
	function get_config_delete($operation){
        global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'cmdb.php');
        $cmdb_object=new class_cmdb($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
		$filter1 = VIS_TABLE_PREFIX.'itil_ci_product.ci_type_id='.$operation['vis_item_id'];
		list($ci_product_info, $ci_product_details)=$setting_object->get_ci_product($filter1, $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filter = VIS_TABLE_PREFIX.'itil_cmdb_assets.ci_type_id='.$operation['vis_item_id'];
		$assets_details=$cmdb_object->get_assets($filter, $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($assets_details!=-1 || $ci_product_details!=-1){
			$message_info['vis_form_title']=$vis_language['TXTDELCONFIGURATIONITEM'];
			$message_info['vis_message']=$vis_language['TXTITILDELCITYPEERROR'];
			$message_info['vis_event']="";
			include(VIS_PATH_TEMPLATE.'confirm_delete.php');
		}else{
			$operation['vis_current_operation']='delete_config_item';
			$operation['vis_current_module']='subsetting';
			$message_info['vis_form_title']=$vis_language['TXTDELCONFIGURATIONITEM'];
			$message_info['vis_message']=$vis_language['MSGSURE'];
			$message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_item_id':".$operation['vis_item_id']."})";
			include(VIS_PATH_TEMPLATE.'confirm_delete.php');
			return true;
		}
    }
	function view_configuration($operation) {
		global $vis_language;
        $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']:'';
		$operation['view_title']=$vis_language['TXTCONFIGURATIONITEMTYPE'];
		if(isset( $operation['vis_set']) && $operation['vis_set']=='1'){
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			$config_details=$object->get_configuration_item(' and is_enabled = 1', 0, -1, $sort_by='', VIS_LOCATION_AREA);
			include(VIS_PATH_TEMPLATE.'config_item_select.php');
		}else
        return $this->configuration_display($operation, '', '', $page, $sort_by);
    }
	
	function configuration_display($operation,$filter='', $page=0, $sort_by=''){
		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.'subsetting.php');
		$sub_object=new class_subsetting($database);
		
		list($department_info,$departments)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(isset($operation['vis_department_id']) && $operation['vis_department_id']!=0 ) $department_id=$operation['vis_department_id'];
		else $department_id=$departments[0]['department_id'];
		
		$filter .= " and (".VIS_TABLE_PREFIX."itil_configuration_item.department_access = 0 OR FIND_IN_SET($department_id, ".VIS_TABLE_PREFIX."itil_configuration_item.department_access)>0)";
		
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                  $filter = " name like '%".$data['vis_title']."%'"  ;
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
        }

	    $config_details=$object->get_configuration_item($filter, 0, -1, $sort_by='', '');
	    if(VIS_LOCATION_AREA==0) {
			if($config_details!='') echo get_xml($config_details, 'config_details');
			else echo $vis_language['MSGDATANOTFND'];
			return true;
		}
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'configuration_list.php');
			$configuration_list = ob_get_clean();
			ob_end_flush();
			$select='';
			//echo json_encode( array('total_cnt'=>$config_total, 'paging' => $select, 'list'=> $configuration_list));
		}else
        include(VIS_PATH_TEMPLATE.'configuration.php');
        return true;
	}
	function edit_config_item($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTCONFIGURATIONITEMTYPE'];
        $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.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $config_details=$object->get_configuration_item_category($action[4],'');
         	$parent_item_details=$object->get_configuration_item_category($config_details[0]['parent_id'],'');
		    $priority_lang=$object->get_translation(5, 'data_id='.$action[4],VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            $config_details=$config_details[0];
            $config_department=explode(',', $config_details['department_access']);
            include(VIS_PATH_TEMPLATE.'edit_config_item.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	function view_cifield($operation) {
        global $vis_language;
		$operation['vis_section']='configuration';
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $operation['view_title']=$vis_language['TXTCICUSTOMFIELD'];
        $operation['vis_operation']='new_cifield';
		$operation['vis_current_operation']='view_cifield';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTCICUSTOMFIELD'];
        return $this->cifield_display($operation, '', $page, $sort_by);
    }
	function cifield_display($operation, $filter, $page, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter = 'ci_type=1';
		list($customfield_info, $customfield_details)=$object->get_itil_customfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$config_item_details=$object->get_configuration_item_category('','');
	    $view_info['page_count']=($customfield_info['total']==0)?0:ceil($customfield_info['total']/$view_info['page_count']);
	    $database->database_disconnect();
   		$customfield_info['customfield_count']=(!$customfield_details || $customfield_details==-1)?0:count($customfield_details);
        $customfield_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCICUSTOMFIELD'];
        include(VIS_PATH_TEMPLATE.'ci_custom_field.php');
        return true;
    }
	function get_cifield_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_cifield';
        $operation['vis_current_module']='subsetting';
		if($operation['vis_section']=='service')
        	$message_info['vis_form_title']=$vis_language['TXTDELSERVICECUSTOMFIELD'];
		else
			$message_info['vis_form_title']=$vis_language['TXTDELCICUSTOMFIELD'];

        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_cifield_id':".$operation['vis_cifield_id'].", 'vis_section':'".$operation['vis_section']."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function edit_cicustomfield($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTCICUSTOMFIELD'];
		$operation['vis_section']='config';
        $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.'setting.php');
            $object=new class_setting($database);
            $filter = "";
            $filter=VIS_TABLE_PREFIX.'customfield.field_group='.$action[4].' ';
            list($customfield_info, $customfield_details)=$object->get_cicustomfield(1, $filter, '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA,'edit_page');
			$parent_item_details=$object->get_configuration_item_category($customfield_details[0]['customgroup_id'],'');
			 $lang_filter = " order by `language_data_id` desc limit 0,1 ";
			 $customfield_lang=$object->get_translation(29, 'data_id='.$customfield_details[0]['field_group']. " ".$lang_filter ,VIS_STAFF_ID, VIS_LOCATION_AREA);
			 list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			 for($i=0;$i<count($customfield_details);$i++)
            { 
				$customfield_option_lang=$object->get_translation(30, 'data_id='.$customfield_details[$i]['customfield_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);	 
				$customfield_array_lang[]= $customfield_option_lang;
            }
			
			
            include(VIS_PATH_TEMPLATE.'edit_cifield.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGMISSINFO'];
            return false;
        }
    }
	//************FINANCE SECTION STARTS************************************
	function view_finance_management($operation) {
	    global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        $staff=new class_staff($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter = '';
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " name like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= " is_enabled =".$data['vis_status'].' and ';
            }
          $filter=substr($filter, 0, -4);
        }
        
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $finance=new class_setting($database);
		$finance_info = array();
		
		if(VIS_ADMIN_ACCESS_LEVEL==1){
			$finance_details=$finance->get_finance_management_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			$finance_count=$finance->get_finance_management_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,'');	
			$view_info['page_count']=($finance_count==-1)?0:ceil(count($finance_count)/$view_info['page_count']);
			$finance_info['finance_count']=(!$finance_details || $finance_details==-1)?0:count($finance_count);
		}else{
			list($finance_count, $finance_details)=$finance->get_properties('get_finance_management_list', $filter,$limit);
			if($finance_details[0]=='') {$finance_count['total']=0;$finance_details=-1;}
			$view_info['page_count']=($finance_count==-1)?0:ceil($finance_count['total']/$view_info['page_count']);
			$finance_info['finance_count']=(!$finance_details || $finance_details==-1)?0:$finance_count['total'];
		}		
		$finance_info['page']=$page;
        $database->database_disconnect();
		$operation['view_title']= $vis_language['TXTFINANCEMANAGEMENT'].'-'.$vis_language['TXTITILDEPRECIATIONTYPE'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_finance';
        $operation['vis_current_operation']='view_finance_management';
        $operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'finance_management_list.php');
			$finance_management_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><script> $('.selectpicker').selectpicker(); </script>";
			echo json_encode( array('total_cnt'=>$finance_info['finance_count'], 'paging' => $select, 'list'=> $finance_management_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'finance.php');
    }
	//************LOCATION SECTION STARTS************************************
	function view_location($operation) {
		global $vis_language;
        $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']:'';
		$operation['view_title']=$vis_language['TXTLOCATION'];
		if(isset( $operation['vis_set']) && $operation['vis_set']=='1'){
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			$config_details=$object->get_locations($filter, 0, -1, $sort_by='', VIS_LOCATION_AREA);
			include(VIS_PATH_TEMPLATE.'location_select.php');
		}else
        return $this->location_display($operation, '', '', $page, $sort_by);
    }
	
	function location_display($operation,$filter='', $page=0, $sort_by=''){
		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');
		$sub_object=new class_subsetting($database);
		
		list($department_info,$departments)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(isset($operation['vis_department_id']) && $operation['vis_department_id']!=0 ) $department_id=$operation['vis_department_id'];
		else $department_id=$departments[0]['department_id'];
		
		$filter .= " and (".VIS_TABLE_PREFIX."itil_location.department_access = 0 OR FIND_IN_SET($department_id, ".VIS_TABLE_PREFIX."itil_location.department_access)>0)";
		
		if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                  $filter = " name like '%".$data['vis_title']."%'"  ;
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
	    $config_details=$object->get_locations($filter, 0, -1, $sort_by='', '');
	    if(VIS_LOCATION_AREA==0) {
			if($config_details!='') echo get_xml($config_details, 'config_details');
			else echo $vis_language['MSGDATANOTFND'];
			return true;
		}
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'location_list.php');
			$configuration_list = ob_get_clean();
			ob_end_flush();
			$select='';
			//echo json_encode( array('total_cnt'=>$config_total, 'paging' => $select, 'list'=> $configuration_list));
		}else
        include(VIS_PATH_TEMPLATE.'location.php');
        return true;
	}

    function two_factor_auth_form($operation) { // Two factor auth form
		$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_two_factor_auth"';
		$two_factor_details=$object_setting->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'two_factor_auth.php');
        return true;
    }
	//************ENDS************************************
	function get_ciproduct_list($operation){
		global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_ticket($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $ciproduct=new class_setting($database);
		$ciproduct_info = array();
	
		//list($ci_product_info, $ci_product_details)=$ciproduct->get_ci_product($filter='', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(isset($operation['vis_product_id'])){
			$filter = 'p.product_id='.$operation['vis_product_id'].' and '.VIS_TABLE_PREFIX.'itil_vendor.is_enabled=1';
			$operation['vis_section'] = 'product';
		}else{
			$filter = 'p.vendor_id='.$operation['vis_vendor_id'].' and '.VIS_TABLE_PREFIX.'itil_ci_product.is_enabled=1';
			$operation['vis_section'] = 'vendor';
		}
        $ciproduct_details=$ciproduct->get_ciproduct_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		$view_info['page_count']=($ciproduct_details==-1)?0:ceil(count($ciproduct_details)/$view_info['page_count']);
        $ciproduct_info['total_count']=(!$ciproduct_details || $ciproduct_details==-1)?0:count($ciproduct_details);
		$ciproduct_info['page']=$page;
        $database->database_disconnect();
        $ciproduct_info['page']=$page;
		include(VIS_PATH_TEMPLATE.'product_vendor_list.php');
	}
	function add_ciproduct($operation) {
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
		//$filter = 'vendor_id='.$operation['vis_vendor_id'].'';
		$departmentaccess=$operation['vis_departmentacc'];
		
		
        if(isset($operation['vis_product_id'])) {
			if(strpos($departmentaccess,','))
			{
				$depts=explode(',',$departmentaccess);
				foreach($depts as $dept)
				{
					$cond[]='find_in_set('.$dept.','.VIS_TABLE_PREFIX.'itil_vendor.department_access)';
				}
				if(count($cond)>1){
				$cond=implode(' or ',$cond);
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_vendor.department_access=0 or '.$cond.')';}
				else
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_vendor.department_access=0 or '.$cond[0].')';	
					
			}
			else if($departmentaccess!=0)
			{
				$cond='find_in_set('.$operation['vis_departmentacc'].','.VIS_TABLE_PREFIX.'itil_vendor.department_access)';
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_vendor.department_access=0 or '.$cond.')';
			}
			else
			{
				$cond1='';
			}
			
			list($vendor_info, $civendor_details)=$object->get_vendor($filter='is_enabled=1'.$cond1, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		else 
		{
		
			if(strpos($departmentaccess,','))
			{
				$depts=explode(',',$departmentaccess);
				foreach($depts as $dept)
				{
					$cond[]='find_in_set('.$dept.','.VIS_TABLE_PREFIX.'itil_ci_product.department_access)';
				}
				if(count($cond)>1)
				{ $cond=implode(' or ',$cond);
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_ci_product.department_access=0 or '.$cond.')'; }
				else 
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_ci_product.department_access=0 or '.$cond[0].')';
			}
			else if($departmentaccess!=0)
			{
				$cond='find_in_set('.$operation['vis_departmentacc'].','.VIS_TABLE_PREFIX.'itil_ci_product.department_access)';
				$cond1=' and ('.VIS_TABLE_PREFIX.'itil_ci_product.department_access=0 or '.$cond.')';
			}
			else
			{
				$cond1='';
			}
			list($ci_product_info, $ci_product_details)=$object->get_ci_product($filter=VIS_TABLE_PREFIX.'itil_ci_product.is_enabled=1'.$cond1, $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		include(VIS_PATH_TEMPLATE.'add_ciproduct_form.php');
	}
	function edit_ciproduct($operation) {
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $object=new class_setting($database);
		$filter1 = 'p.product_vendor_id='.$operation['vis_product_vendor_id'].'';
		$product_vendor_details = $object->get_ciproduct_list($filter1,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$product_vendor_details = $product_vendor_details[0];
        if($operation['vis_section_area']=='product')
			list($vendor_info, $civendor_details)=$object->get_vendor($filter='', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		else
			list($ci_product_info, $ci_product_details)=$object->get_ci_product($filter='', $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'edit_ciproduct_form.php');
	}
	function view_service_category($operation) {
        global $vis_language;
		$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.'staff.php');
        $staff=new class_staff($database);
		
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter='';
				
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " name like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= " is_enabled =".$data['vis_status'].' and '; 
            }
			$filter=substr($filter, 0, -4);
        }

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $sub_object=new class_subsetting($database);
		$service_info = array();
		list($domain_info, $domain_details)=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $service_details=$setting->get_service_category_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		$service_count=$setting->get_service_category_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,'');
		$view_info['page_count']=($service_count==-1)?0:ceil(count($service_count)/$view_info['page_count']);
        $service_info['service_count']=(!$service_details || $service_details==-1)?0:count($service_count);
		$service_info['page']=$page;
        $database->database_disconnect();
        $service_info['page']=$page;
        $operation['view_title']=$vis_language['TXTSERVICECATEGORY'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_service_category';
        $operation['vis_current_operation']='view_service_category';
        $operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'service_category_list.php');
			$service_category_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'=>$service_info['service_count'], 'paging' => $select, 'list'=> $service_category_list ,'filter'=> $filter ));
		}else
        include(VIS_PATH_TEMPLATE.'service_category.php');
    }
	function new_service_category($operation){
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
	    $database=new class_database();
        $operation['view_title']=$vis_language['TXTSERVICECATEGORY'];
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
		list($domain_info, $domain_details)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		//list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
	    include(VIS_PATH_TEMPLATE.'new_service_category.php');
        return true;
    }
	function view_service_item($operation){
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        $staff=new class_staff($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter = "";
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != "")
            {
                   $filter = VIS_TABLE_PREFIX."itil_service_item.name like '%".$data['vis_title']."%' and "  ;
                //   $filter.= " and data_id=status_id";
            }
            else $filter = "";
            if(isset($data['vis_status']) && $data['vis_status']!= "")
            {
                $filter .= VIS_TABLE_PREFIX."itil_service_item.status =".$data['vis_status'].' and '; 
                
            }
            else $filter .= "";
        }
		$filter=substr($filter,0,-4);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		$service_info = array();
        $service_details=$setting->get_service_item_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		$service_count=$setting->get_service_item_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,'');
		$view_info['page_count']=($service_count==-1)?0:ceil(count($service_count)/$view_info['page_count']);
        $service_info['service_count']=(!$service_details || $service_details==-1)?0:count($service_count);
		$service_info['page']=$page;
        //$database->database_disconnect();
        //$service_info['page']=$page;	
        $operation['view_title']=$vis_language['TXTSERVICEITEM'];
        $operation['vis_operation']='new_service_item';
        $operation['vis_current_operation']='view_service_item';
        $operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'service_item_list.php');
			$service_item_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><script> $('.selectpicker').selectpicker(); </script>";
			echo json_encode( array('total_cnt'=>$service_info['service_count'], 'paging' => $select, 'list'=> $service_item_list ,'title'=> $operation['view_title'] ));
		}else
        include(VIS_PATH_TEMPLATE.'service.php');
    }
	function new_service_item($operation){
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
        $operation['view_title']=$vis_language['TXTSERVICEITEM'];
        $object=new class_setting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		$ticket_object=new class_ticket($database);
		if($operation['vis_category_id']!='')
		{
			$filter=' '.VIS_TABLE_PREFIX.'itil_service_category.category_id='.$operation['vis_category_id'].'  ';
		}else{$filter='';}
		$service_details=$object->get_service_category_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		
		//list($ci_product_info, $product_detail)=$object->get_properties('get_ci_product', '');
		//list($ci_product_info, $product_detail)=$object->get_ci_product($filter='', $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
		//list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($service_details[0]['domain_id']==0)
		{$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1  ';}
		else{$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.$service_details[0]['domain_id'].'  ';}
        $department_details=$ticket_object->get_department($filter_dpt, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
		
		
		//print_r($department_details);
        $database->database_disconnect();
		if($operation['flag']!=1)        
		{include(VIS_PATH_TEMPLATE.'new_service_item.php');}
		else
		{	
					$select='';
					$select .= '<select name="vis_domain_department" id="vis_domain_department" class="form-control input-sm selectpicker">';
					for($i=0;$i<count($department_details);$i++)
					{
						$select.='<option value="'.$department_details[$i]['department_id'].','.$department_details[$i]['domain_id'].'">'.$department_details[$i]['department_name'].'</option>';
					}
					$select .= "</select>";
					echo json_encode( array('depts' => $select));
		}
		return true;
    }
	function edit_service_item($operation){
		 global $vis_language;
        $operation['view_title']=$vis_language['TXTSERVICECATEGORY'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
			$ticket_object=new class_ticket($database);
			$operation['view_title']=$vis_language['TXTSERVICEITEM'];
			$object=new class_setting($database);
			$service_details=$object->get_service_item_list($filter='item_id='.$action[4],$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			if($operation['vis_category_id']!='')
			{
				$filter=' '.VIS_TABLE_PREFIX.'itil_service_category.category_id='.$operation['vis_category_id'].'  ';
			}else{$filter='';}
			$service_cat_details=$object->get_service_category_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		
			//list($ci_product_info, $product_details)=$object->get_properties('get_ci_product', '');
			//list($ci_product_info, $product_details)=$object->get_ci_product($filter='', $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$service_details=$service_details[0];
			
			//list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($service_cat_details[0]['domain_id']==0)
			{$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1  ';}
			else{$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.$service_cat_details[0]['domain_id'].'  ';}
			$department_details=$ticket_object->get_department($filter_dpt, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$database->database_disconnect();
			
	
			if($operation['flag']!=1)        
			{
				include(VIS_PATH_TEMPLATE.'edit_service_item.php');}
			else
			{	
				$select='';
				$select .= '<select name="vis_domain_department" id="vis_domain_department" class="form-control input-sm selectpicker">';
				for($i=0;$i<count($department_details);$i++)
				{if($service_details['item_department_id']==$department_details[$i]['department_id'])
						$chk1='selected="selected"';
						else
						$chk1='';
					$select.='<option '.$chk1.' value="'.$department_details[$i]['department_id'].'">'.$department_details[$i]['department_name'].'</option>';	
				}
					$select .= "</select>";
				echo json_encode( array('depts' => $select));
			}
		
        	return true;
	    }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	function view_service_field($operation) {
        global $vis_language;
		$operation['vis_section']='service';
	    $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $operation['view_title']=$vis_language['TXTSERVICECUSTOMFIELD'];
        $operation['vis_operation']='new_servicefield';
		$operation['vis_current_operation']='view_service_field';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTSERVICECUSTOMFIELD'];
        return $this->servicefield_display($operation, '', $page, $sort_by);
    }
	function servicefield_display($operation, $filter, $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter = 'ci_type=2';
		list($customfield_info, $customfield_details)=$object->get_itil_customfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$service_item_details=$object->get_service_item_list($filter1='',$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
	    $view_info['page_count']=($customfield_info['total']==0)?0:ceil($customfield_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $customfield_info['customfield_count']=(!$customfield_details || $customfield_details==-1)?0:count($customfield_details);
        $customfield_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTSERVICECUSTOMFIELD'];
        include(VIS_PATH_TEMPLATE.'ci_custom_field.php');
        return true;
    }
	function view_services($operation){
		if(IS_LOGIN==0){
                if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
                include(VIS_PATH_TEMPLATE.'login.php');
                include(VIS_PATH_TEMPLATE.'footer.php');
                break;
        }
		if(VIS_MODULE_ACCESS_ITIL==1){
			global $vis_language;
			$breadcrumb['Home'] = 'index.php'; 
            $breadcrumb[$vis_language['TXTITILSERVICECATALOG']] = ''; 
            $vis_title = $vis_language['TXTITILSERVICECATALOG'];
			$header_title=$vis_language['TXTITILSERVICECATALOG'];
			$operation['vis_heading']=$vis_language['TXTITILSERVICECATALOG'];
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$database=new class_database();
			$object=new class_setting($database);
			$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1';
			$service_details=$object->get_service_item_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
			$vis_c = $services_count=($service_details==-1)?0:count($service_details);
			//$filter = 'domain_id='.VIS_DOMAIN;
			//$service_category_details=$object->get_service_category_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
			//$database->database_disconnect();
			$header_title=$vis_language['TXTITILSERVICECATALOG'];
			// Code for api - start
			if(VIS_LOCATION_AREA==0) {
				echo get_xml($service_details, 'Service');
				return true;
			}
			// Code for api - end
			include(VIS_PATH_TEMPLATE.'header.php');
			include(VIS_PATH_TEMPLATE.'view_services.php');
			include(VIS_PATH_TEMPLATE.'footer.php');
			return true;
		}else{
			include(VIS_PATH_TEMPLATE.'header.php');
			//include(VIS_PATH_TEMPLATE.'view_services.php');
			include(VIS_PATH_TEMPLATE.'footer.php');
		}
    }
	function view_service_detail($operation){
		if(IS_LOGIN==0){
                if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
                include(VIS_PATH_TEMPLATE.'login.php');
                include(VIS_PATH_TEMPLATE.'footer.php');
                break;
        }
		global $vis_language;
		$header_title=$vis_language['TXTITILSERVICECATALOG'];
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $database=new class_database();
        $object=new class_setting($database);
		$sub_setting=new class_subsetting($database);
		$client=new class_client($database);
		$ticket_object=new class_ticket($database);
		$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1 and item_id='.$action[3];
		$service_details=$object->get_service_item_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$service_details = $service_details[0];
		$filter1=VIS_TABLE_PREFIX.'itil_service_category.category_id='.$service_details['category_id'];
		$service_cat_details=$object->get_service_category_list($filter1,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$department_id = $service_cat_details[0]['department_id'];
		 if($service_details['domain_id']==0) $domain_id = VIS_DOMAIN; else $domain_id = $service_details['domain_id'];
		list($dpinf, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.domain_id='.$domain_id, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		//$domain = $ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1',VIS_CLIENT_ID, VIS_LOCATION_AREA);
		$filter = 'is_enabled = 1 and ci_type=2 and customgroup_id='.$service_details['item_id'].' GROUP BY field_group';
		list($customfield_info, $custom_fields_details)=$object->get_cicustomfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		 $breadcrumb['Home'] = 'index.php'; 
        $breadcrumb[$vis_language['TXTITILSERVICECATALOG']] = '?/setting/view_services';
		 $breadcrumb[ucfirst($service_details['name'])] = ''; 
        $vis_title = $vis_language['TXTITILSERVICECATALOG']; /*list($department_info,$department_details)=$sub_setting->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);*/
		 //$domains = $ticket->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1',VIS_STAFF_ID, VIS_LOCATION_AREA);
		//print_r($customfield_details);
		//$type=array('', 'Textbox', 'Password', 'Textarea', 'Checkbox', 'Radio', 'Select', 'Listbox','Date Time','File');
		//echo 'tejas'.VIS_LOCATION_AREA;
		if($custom_fields_details != -1 && count($custom_fields_details)>0){
			$custom_field_var = $this->get_customfield_data_list($custom_fields_details,$service_details['item_id'],VIS_STAFF_ID,VIS_LOCATION_AREA);	
		}else $custom_field_var='';
		include(VIS_PATH_TEMPLATE.'header.php');
		$filter3='parent_id = 0 and '.VIS_TABLE_PREFIX.'client.client_id ='.VIS_CLIENT_ID;
		list($client_info, $client_detail)=$client->get_client($filter3, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$client_detail = $client_detail[0];
	    $userid=VIS_CLIENT_ID;
		if($client_detail['department_access']!=0){
       	 	$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'department.department_id in ('.$client_detail['department_access'].') ';
		}else{
			$filter_dpt=VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'department.domain_id='.VIS_DOMAIN.' ';
		}
		
        $department_details=$ticket_object->get_department($filter_dpt, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id'); 
		include(VIS_PATH_TEMPLATE.'view_service_detail.php');
		include(VIS_PATH_TEMPLATE.'footer.php');
        return true;
    }
	function get_department($operation){
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$database=new class_database();
        $object=new class_subsetting($database);
		$filter2=VIS_TABLE_PREFIX.'department.is_enabled=1 AND '.VIS_TABLE_PREFIX.'department.domain_id='.$operation['vis_domain'];
		list($department_info,$department_details)=$object->get_department($filter2,'',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$database->database_disconnect();
		global $vis_language;
		if(count($department_details) > 10) $sel_cnt='data-live-search="true"'; else $sel_cnt='';
		$select= '<label class="col-sm-2 control-label">'.$vis_language['TXTDEPARTMENTACCESS'].'</label>
					<div class="col-sm-10">';
		$select.='<select class="form-control input-sm selectpicker" name="vis_department_id" id="vis_department_id" '.$sel_cnt.' >';
		//$select.='<option value="0">-- '.$vis_language['TXTSELECTDEPARTMENT'].' --</option>';
		for($i=0;$i<count($department_details);$i++){
			$select.='<option value="'.$department_details[$i]['department_id'].'">'.$department_details[$i]['department_name'].'</option> ';

		}
		$select.='</select>
					</div>';
		echo $select;
	}
	function filter_services($operation){
		$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1 ';
		if(isset($operation['vis_filter_enable']))
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_filter']) && $data['vis_filter'] != ""){
                 $filter = " ".VIS_TABLE_PREFIX."itil_service_item.name like '%".$data['vis_filter']."%'"  ;
            }
            else $filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1 ';
        }
        global $vis_language;
		$operation['vis_heading']=$vis_language['TXTSERVICESEARCHRESULT'];
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
        $object=new class_setting($database);
		if(isset($operation['vis_filter_enable'])){
			$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1 and '.$filter;
		}
		$service_details=$object->get_service_item_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$services_count=($service_details==-1)?0:count($service_details);
	    //$database->database_disconnect();
		include(VIS_PATH_TEMPLATE.'view_services.php');
	    return true;
    }
	function services_category($operation){
		if(IS_LOGIN==0){
                if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
                include(VIS_PATH_TEMPLATE.'login.php');
                include(VIS_PATH_TEMPLATE.'footer.php');
                break;
        }
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
        $object=new class_setting($database);
		$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1';
		$service_details=$object->get_service_item_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$services_count=($service_details==-1)?0:count($service_details);
		$filter1 = VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1';
        $service_cat_details=$object->get_service_category_list($filter1,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		if($service_cat_details==-1) $services_count=0;
		$breadcrumb['Home'] = 'index.php'; 
        $breadcrumb[$vis_language['TXTITILSERVICECATALOG']] = '?/setting/view_services'; 
        $breadcrumb[$vis_language['TXTSERVICECATEGORY']] = ''; 
        $vis_title = $vis_language['TXTITILSERVICECATALOG'];
		 $header_title = $vis_language['TXTSERVICECATEGORY'];
        $vis_count = $services_count;
        $database->database_disconnect();
	    include(VIS_PATH_TEMPLATE.'header.php');
		include(VIS_PATH_TEMPLATE.'service_category.php');
		include(VIS_PATH_TEMPLATE.'footer.php');
        return true;
    }
	function get_service_cost_update($operation) {
        global $vis_language;

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
        $object=new class_setting($database);
		$operation['vis_current_operation']='update_service_cost'; 
        $operation['vis_current_module']='subsetting';
	    $message_info['vis_event']="$('#vis_global_msg_div').visExecution('submit_form', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_form':'vis_service_cost_form'})";
		$filter = 'ci_type=2 and customgroup_id='.$operation['vis_service_item_id'].' GROUP BY field_group';
		list($customfield_info, $custom_fields_details)=$object->get_cicustomfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		//print_r($customfield_details);
		//$type=array('', 'Textbox', 'Password', 'Textarea', 'Checkbox', 'Radio', 'Select', 'Listbox','Date Time','File');
		//echo 'tejas'.VIS_LOCATION_AREA;
		if($custom_fields_details != -1 && count($custom_fields_details)>0){
			$custom_field_var = $this->get_customfield_data_list($custom_fields_details,$operation['vis_service_id'],VIS_STAFF_ID,VIS_LOCATION_AREA);	
		}else $custom_field_var=''; 
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'service_cost_update.php');
        return true;
    }
	
	function attach_problem_cmdb($operation) {
        global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
      	$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'attach_cmdb_problem.php');
        return true;
    }
	
	function get_attach_problem_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_attach_problem'; 
        $operation['vis_current_module']='subsetting'; 
        $message_info['vis_form_title']=$vis_language['TXTITILDETACHLINKPROBLEM'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_attach_id':".$operation['vis_attach_id'].", 'vis_ticket_id':".$operation['vis_ticket_id'].", 'vis_dept_id':".$operation['vis_dept_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function get_attach_changes_delete($operation) {
        global $vis_language;
        $operation['vis_current_operation']='delete_attach_change'; 
        $operation['vis_current_module']='subsetting'; 
        $message_info['vis_form_title']=$vis_language['TXTITILDETACHLINKCHANGES'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'".$operation['vis_current_module']."', 'vis_operation':'".$operation['vis_current_operation']."', 'vis_attach_id':".$operation['vis_attach_id'].", 'vis_ticket_id':".$operation['vis_ticket_id'].", 'vis_dept_id':".$operation['vis_dept_id'].", 'vis_ticket':'".$operation['vis_ticket']."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function get_customfield_data_list($custom_fields_details,$service_item_id,$userid,$user){
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
	    $database=new class_database();
        $object=new class_setting($database);
		$ticket_object=new class_ticket($database);
		$cc_count=0;
			//$custom_field_var .='<div class="line b-b line-lg pull-in"></div><br><div class="form-group"><label class="col-sm-2 control-label" for="'.$citype_details['name'].'"><strong>'.$citype_details['name'].'</strong></label></div>';  
			for($j=0; $j<count($custom_fields_details); $j++){
				// $custom_field_var.='<input type="hidden" value="'.$custom_fields_details[$j]['customfield_id'].'" id="custom_field_id" name="custom_field_id[]" class="form-control input-sm">';
				 $val='';
				if($custom_fields_details[$j]['field_type']<4 || $custom_fields_details[$j]['field_type']==8){
					if(VIS_LOCATION_AREA==2){
						$custom_data = $ticket_object->get_customfield_data($custom_fields_details[$j]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);
						if($custom_data != -1)  $val = $custom_data['content'];
						else $val = $custom_fields_details[$j]['default_value']; 
					}else $val = $custom_fields_details[$j]['default_value']; 
					$req = ($custom_fields_details[$j]['is_required']==1)?' *':'';
					if($custom_fields_details[$j]['field_type']==1)
					{
					  
						if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))  
						{
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><input type="text" value="'.$val.'" id="field'.$custom_fields_details[$j]['customfield_id'].'" name="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm"></div></div>';
						}
						else
						{
							 $custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" title="'.$custom_fields_details[$j]['field_description'].'" for="'.$custom_fields_details[$j]['field_name'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><input type="text" value="'.$val.'" readonly name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm"></div></div>';
						}
				   }
					if($custom_fields_details[$j]['field_type']==2)
					{
					   if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))  
						{
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><input type="password" name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" value="'.$val.'"></div></div>';
						} 
						else
						{
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><input type="password" name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" value="'.$val.'" readonly ></div></div>';
						}  
					}
					if( $custom_fields_details[$j]['field_type']==3)
					{
						if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))  
						{
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><textarea name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" >'.$val.'</textarea></div></div>';
						}
						else
						{
							 $custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><textarea name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" readonly>'.$val.'</textarea></div></div>';
						}  
					}
					if($custom_fields_details[$j]['field_type']==8)
					{
					   if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))  
						{
							 $custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><span class="input-group-addon no-padder no-borders start"><input type="text" name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" value="'.$val.'"></span></div></div><script>$(".start").datetimepicker({}); </script>';
						}
						else
						{
							 $custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" title="'.$custom_fields_details[$j]['field_description'].'">'.$custom_fields_details[$j]['field_name'].$req.'</label><div class="col-sm-8"><span class="input-group-addon no-padder no-borders"><input type="text" name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control input-sm" value="'.$val.'" readonly ></span></div></div>';
						}
						  
					}                          
					$cc_count++;
				}
				else{
					 $flag = array();     
					$filter='field_group='.$custom_fields_details[$j]['field_group'].' and ci_type=2';
					list($customfield_info, $sub_customfields_details)=$object->get_cicustomfield(0,$filter, $limit='', $page='', $sort_by='', VIS_STAFF_ID, VIS_LOCATION_AREA);
					//echo '<pre>';
					//print_r($sub_customfields_details);
					if($sub_customfields_details != -1){
						if($custom_fields_details[$j]['field_type']==4){
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8">';
							if(VIS_LOCATION_AREA==2){
								for($cnt=0;$cnt< count($sub_customfields_details);$cnt++)
								{
									  $custom_data = $ticket_object->get_customfield_data($sub_customfields_details[$cnt]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);  
									  if($custom_data != -1)  
									  {
												 $flag[$cnt] =  1;
									  }
								}
							}
							for($k=0;$k< count($sub_customfields_details);$k++){
								if(VIS_LOCATION_AREA==2){
								   $custom_data = $ticket_object->get_customfield_data($sub_customfields_details[$k]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);   
									if(($custom_data['content'] === $sub_customfields_details[$k]['default_value'])) $sel = 'checked="checked"';
									elseif(count($flag) <= 0 &&  $sub_customfields_details[$k]['is_selected'] == 1)  $sel = 'checked="checked"';   
									  else $sel='';
								}elseif(count($flag) <= 0 &&  $sub_customfields_details[$k]['is_selected'] == 1)  $sel = 'checked="checked"';
								else $sel='';
								 if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))                                 		 {
									$custom_field_var.='<label class="checkbox-inline i-checks"><input type="checkbox" '.$sel.' name="field'.$sub_customfields_details[$k]['customfield_id'].'" id="field'.$sub_customfields_details[$k]['customfield_id'].'" value="'.$sub_customfields_details[$k]['default_value'].'" > <i></i> '.$sub_customfields_details[$k]['default_value'].'</label> ';
								}
								else 
								{
									$custom_field_var.='<label class="checkbox-inline i-checks"><input type="checkbox" '.$sel.' name="field'.$sub_customfields_details[$k]['customfield_id'].'" id="field'.$sub_customfields_details[$k]['customfield_id'].'" value="'.$sub_customfields_details[$k]['default_value'].'" disabled="disabled"> <i></i> '.$sub_customfields_details[$k]['default_value'].'</label> ';
								}
								$cc_count++;
							}
							$custom_field_var .= '</div></div>';
						}
						if($custom_fields_details[$j]['field_type']==5){
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8">';
							for($k=0;$k<count($sub_customfields_details);$k++){
								if(VIS_LOCATION_AREA==2){
									$custom_data = $ticket_object->get_customfield_data($sub_customfields_details[$k]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);  
									if(($custom_data['content']== $sub_customfields_details[$k]['default_value']) || $sub_customfields_details[$k]['is_selected'] == 1) $sel = 'checked="checked"';
									else $sel='';
								}else $sel='';
								 if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))                                 		 {
								  $custom_field_var.='<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" '.$sel.' name="field'.$custom_fields_details[$j]['customfield_id'].'[]" id="field'.$sub_customfields_details[$k]['customfield_id'].'" value="'.addslashes($sub_customfields_details[$k]['customfield_id'].'-'.$sub_customfields_details[$k]['default_value']).'"> <i></i> '.$sub_customfields_details[$k]['default_value'].'</label></div>';
								 }
								 else
								 {
									$custom_field_var.='<div class="radio i-checks m-r-lg pull-left"><label><input type="radio" '.$sel.' name="field'.$custom_fields_details[$j]['customfield_id'].'[]" id="field'.$sub_customfields_details[$k]['customfield_id'].'" value="'.addslashes($sub_customfields_details[$k]['customfield_id'].'-'.$sub_customfields_details[$k]['default_value']).'" disabled="disabled"> <i></i> '.$sub_customfields_details[$k]['default_value'].'</label></div>';
								 }
								$cc_count++;
							}
							$custom_field_var .= '</div></div>';
						}
						if($custom_fields_details[$j]['field_type']==6){
						if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))                                 	 {
							$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8"><select name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control selectpicker">';
							 }
							 else
							 {
								 $custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8"><select disabled="disabled" name="field'.$custom_fields_details[$j]['customfield_id'].'" id="field'.$custom_fields_details[$j]['customfield_id'].'" class="form-control selectpicker">';
							 }
							 
							for($k=0;$k<count($sub_customfields_details);$k++) {
								if(VIS_LOCATION_AREA==2){
									$custom_data = $ticket_object->get_customfield_data($custom_fields_details[$j]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);
									if(($custom_data['content']== $sub_customfields_details[$k]['default_value']) || $sub_customfields_details[$k]['is_selected'] == 1) $sel = 'selected="selected"'; 
									else $sel='';
								}else $sel='';
								$custom_field_var.='<option value="'.addslashes($sub_customfields_details[$k]['default_value']).'" '.$sel.'>'.addslashes($sub_customfields_details[$k]['default_value']).'</option>';
							}
							
							$custom_field_var.='</select></div></div>';
							$cc_count++;
						}
						if($custom_fields_details[$j]['field_type']==7){
						if(($custom_fields_details[$j]['is_staff_editable'] == 1  &&  VIS_LOCATION_AREA == 2 ) || ($custom_fields_details[$j]['is_user_editable'] == 1 &&  VIS_LOCATION_AREA == 1))                               	 {
								$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8"><select name="field'.$custom_fields_details[$j]['customfield_id'].'[]" id="field'.$custom_fields_details[$j]['customfield_id'].'" multiple="multiple" class="form-control">';
							 }
							 else
							 {
								$custom_field_var.='<div class="form-group"><label class="col-sm-2 control-label" for="'.$custom_fields_details[$j]['field_name'].'" title="'.$custom_fields_details[$j]['field_description'].'">'.addslashes($custom_fields_details[$j]['field_name']).'</label><div class="col-sm-8"><select disabled="disabled" name="field'.$custom_fields_details[$j]['customfield_id'].'[]" id="field'.$custom_fields_details[$j]['customfield_id'].'" multiple="multiple" size="5" class="form-control input-sm selectpicker">';
							 }
							if(VIS_LOCATION_AREA==2){ 
								for($cnt=0;$cnt< count($sub_customfields_details);$cnt++)
								{
									  $custom_data = $ticket_object->get_customfield_data($sub_customfields_details[$cnt]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);  
									  if($custom_data != -1)  
									  {
												 $flag[$cnt] =  1;
									  }
								}
							}
							for($k=0;$k<count($sub_customfields_details);$k++) {
								if(VIS_LOCATION_AREA==2){
									$custom_data = $ticket_object->get_customfield_data($sub_customfields_details[$k]['customfield_id'],$service_item_id,VIS_LOCATION_AREA);
									
									if(($custom_data['content']== $sub_customfields_details[$k]['default_value'])) {$sel = 'selected="selected"'; }
									else $sel='';  
								}else $sel='';
								if(count($flag) == 0 && $sub_customfields_details[$k]['is_selected'] == 1)$sel = 'selected="selected"'; 
								   $custom_field_var.='<option value="'.addslashes($sub_customfields_details[$k]['customfield_id'].'-'.$sub_customfields_details[$k]['default_value']).'" '.$sel.'>'.addslashes($sub_customfields_details[$k]['default_value']).'</option>';
							}
							$custom_field_var.='</select></div></div>';
							$cc_count++;
						}
					}
				}
			}
			return $custom_field_var;
	}		
	
	function reset_staff($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTUPDATESTAFFDEPARTMENT'];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
	    $database=new class_database();
	    $setting_object=new class_setting($database);
	    $sub_object=new class_subsetting($database);
	    $filter=VIS_TABLE_PREFIX.'staff.staff_id='.$operation['vis_staff_id'];
        list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($staff_info, $staff_details)=$setting_object->get_staff($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $staff=$staff_details[0];
        $department_access=explode(',',$staff_details[0]['department_access']);
	    list($staffgroup_info, $staff_group)=$setting_object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
      	$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'update_staff_department.php');
        return true;
    }
	function get_page_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELFACEBOOKPAGE'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_facebook_page', 'vis_page_id':".$operation['vis_page_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function get_page_edit($operation){
        global $vis_language;
        //$message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_facebook_page', 'vis_page_id':".$operation['vis_page_id']."})";
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
	    $database=new class_database();
	    $setting_object=new class_setting($database);
	    $sub_object=new class_subsetting($database);
		$filter = 'page_id='.$operation['vis_page_id'];
		list($pages_info,$pages_details)=$setting_object->get_pages($filter,$limit,$userid, $user);
		list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'facebook_page_edit.php');
        return true;
    }
	function ticket_service_item_list($operation) {
        global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
		$setting_object=new class_setting($database);	    
      	$filter = VIS_TABLE_PREFIX.'itil_service_item.status=1 and '.VIS_TABLE_PREFIX.'itil_service_category.is_enabled=1 and '.VIS_TABLE_PREFIX.'itil_service_item.category_id='.$operation['vis_category_id'];
		$service_details=$setting_object->get_service_item_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'ticket_service_request.php');
        return true;
    }
    function language_export($operation) {
        global $vis_language;
								if(isset($operation['vis_action']) && $operation['vis_action'] != ""){
            $action=explode("/", $operation['vis_action']);
            if(count($action)>4 && isset($action[4]) && is_numeric($action[4]))
                $language_id_active = $action[4];
        }else{
									$language_id_active='';
								}
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
	    $setting_object=new class_setting($database);	   
        list($language_info, $language_details)=$setting_object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'language_export.php');
        return true;
	}
	 function language_export_report($operation) {
		global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $database=new class_database();
	    $setting_object=new class_setting($database);
	    list($language_info, $language_details)=$setting_object->get_language('is_enabled=1 and language_id='.$operation['vis_language_id'], '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $language_name=$language_details[0]['language_name'];
	    $report = $setting_object->get_details_language_variables($operation['vis_language_id'], $language_name);
	    if($report!=-1){
	    include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'export.php');
        $export=new export(); 
	    for($i=0;$i<=count($report);$i++) {
			foreach($report[$i] as $key=>$val) {
				if($key=='location_area' || $key=='variable' || $key=='default_value' || $key==$language_name ) $report_exp[$i][$key]=$val;
			}
		}
        return $export->language_export_csv($report_exp, $language_name); 
		}
		else {
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
			
		}  
		$database->database_disconnect();
	 }
    function import_language($operation)
    {
		global $vis_language;
		
		if(isset($operation['vis_action']) && $operation['vis_action'] != ""){
            $action=explode("/", $operation['vis_action']);
            if(count($action)>4 && isset($action[4]) && is_numeric($action[4]))
                $language_id_active = $action[4];
        }else{
									$language_id_active='';
								}
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$database=new class_database();
		$setting_object=new class_setting($database);
		list($listCount, $languageDetails)=$setting_object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID,VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'import_language.php');
        return true;
	}
	function import_language_variables($operation)
	{
		global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$database=new class_database();
		$setting_object=new class_setting($database);
		$data=parse_form_array($operation['vis_action']);   
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');  
	    $object=new class_client($database);
	     
	    $arr_attachment = explode(',',$data['vis_import_attachments']);
	   
	    for($j=0; $j<count($arr_attachment);$j++){if($arr_attachment[$j] !='')
	    $filter = 'parent_type=4 and attachment_id='.$arr_attachment[$j] ;}
	   
	    $attach = $object->get_attachment($filter, VIS_STAFF_ID, VIS_LOCATION_AREA) ;
	    if($attach==-1)
	    {
			 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
		}
		else 
		{
			for($i=0;$i<count($attach);$i++)
			{ 
				 $file_name =VIS_PATH_FILES.$attach[$i]['content'];
				 $file_handle = fopen($file_name, "r");
				 $first_row = fgetcsv($file_handle, 1000, ";");
				 $count=1;
				 while (!feof($file_handle) )
				 {
					 $line_of_text = fgetcsv($file_handle); 
					 $line_of_text = array_map("utf8_encode",$line_of_text);
					 $line_of_text[0];
					 
						 $data['description'] = ($line_of_text[3]=='')?$line_of_text[2]:$line_of_text[3];
						 $filter = 'title ="'.$line_of_text[1].'" and location_area = "'.$line_of_text[0].'"';
						 $variableResult =  $setting_object->get_import_language_variable($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
						
						 $data['variable_id'] = $variableResult[0]['variable_id'];
						 if($variableResult!= -1)
						 {
							$valueFilter =  VIS_TABLE_PREFIX . 'language_values.language_id ="'.$data['vis_laguage_id'].'" and '.VIS_TABLE_PREFIX . 'language_values.variable_id = "'.$data['variable_id'].'" and title="'.$line_of_text[1].'"';
							 $valueResult =  $setting_object->get_import_language_values($valueFilter, VIS_STAFF_ID, VIS_LOCATION_AREA);
							 if($valueResult == -1)
							 {
								$setting_object->set_import_language_value($data,VIS_STAFF_ID, VIS_LOCATION_AREA);
							 }
						 }
				}
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_area",{"vis_module":"setting", "vis_operation":"view_language"}); </script>';
			}
		}
	}
	function api_integration($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'api_integration.php');
			return true;
		}
	}
	function api_integration_setting($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$filter='integration_type='.$operation['vis_integration_type'].' AND domain_id='.$operation['vis_domain'];
			$data['vis_domainname'] = $operation['vis_domain'];
			list($integration_info, $integration_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$integration_details=$integration_details[0];
			include(VIS_PATH_TEMPLATE.'api_integration_setting.php');
			$database->database_disconnect();
			return true;
    }
   
    function clone_department($operation){
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(isset($action[3]) && $action[3]!='' && is_numeric($action[3])){
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
            $filter=VIS_TABLE_PREFIX.'department.department_id='.$action[3];
            list($department_info, $department_details)=$sub_object->get_department($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $department_lang =$object->get_translation(15, 'data_id='.$action[3],VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($staffgroup_info, $staff_group)=$object->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1 and FIND_IN_SET('.$action[3].', department_access)>0', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $department_details=$department_details[0];        
			$filter=VIS_TABLE_PREFIX.'staff.is_enabled=1 and FIND_IN_SET('.$action[3].', '.VIS_TABLE_PREFIX.'staff.department_access)>0 ';
            list($domain,$staff_list)=$object->get_staff($filter,'','','',VIS_STAFF_ID, VIS_LOCATION_AREA);
            $data['vis_domain']=$department_details['domain_id'];
            $data['vis_departmentname']=$department_details['department_name'];
            $data['vis_autorespond_id']=$department_details['autoresponder_id'];
            $data['vis_displayorder']=$department_details['display_order'];
            $data['vis_access'] =$department_details['access_type'];
            $data['vis_paid'] =$department_details['is_paid'];
            $data['vis_autorespond']=$department_details['autoresponder'];
            $data['vis_registered']=$department_details['registration'];
            $data['vis_status']=($department_details['is_enabled']==1)?'on':0;
            $data['signature'] =$department_details['signature'];
            if($department_lang!=1)
                foreach($department_lang as $key => $val)
                    $data['vis_language_'.$key]=$val;
            if($staff_group!=1)
                for($i=0;$i<count($staff_group);$i++)
                    $data['vis_staff_department_access'][$i]=$staff_group[$i]['group_id'];
            if($staff_list!=1)
                for($i=0;$i<count($staff_list);$i++)
                    $data['vis_staff_access'][$i]=$staff_list[$i]['staff_id'];
            list($domain_info, $domain_details)=$object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id='.$data['vis_domain'], $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $ret=$sub_object->add_department($data, VIS_STAFF_ID, VIS_LOCATION_AREA,1);
        }
        $database->database_disconnect();
        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 new ".$data['vis_departmentname']. " department of ".$domain_details[0]['domain_name']." domain", 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['TXTDEPARTMENT'].'",{"vis_module":"setting", "vis_operation":"department_details", "vis_dept_id":'.$ret.', "vis_dept_name":"'.$data['vis_departmentname'].'", "vis_domain_name":"'.$domain_details[0]['domain_name'].'"})</script>';
		}
        return $ret;
    }
    function clickdesk($operation){
                        global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'clickdesk.php');
			return true;
		}

    }
    function clickdesk_setting($operation){
                        global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$filter='integration_type='.$operation['vis_integration_type'].' AND domain_id='.$operation['vis_domain'];
			list($livechat_info, $clickdesk_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$clickdesk_details=$clickdesk_details[0];
			include(VIS_PATH_TEMPLATE.'clickdesk_setting.php');
			$database->database_disconnect();
			return true;

    }
    function zopim($operation){
                        global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			$vis_integration_type=$action[4];
			include(VIS_PATH_TEMPLATE.'zopim.php');
			return true;
		}

    }
    function zopim_setting($operation){
            global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$filter='integration_type='.$operation['vis_integration_type'].' AND domain_id='.$operation['vis_domain'];
			list($livechat_info, $zopim_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$zopim_details=$zopim_details[0];
			include(VIS_PATH_TEMPLATE.'zopim_setting.php');
			$database->database_disconnect();
			return true;

    }
	function widget($operation){
		global $vis_language;
		$spliter=(strstr($operation['vis_action'], 'vbreak'))?'vbreak':'vbreak';
		$action=explode($spliter, $operation['vis_action']);
		$wedget_website_URL= $action[1];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket=new class_ticket($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	    $setting=new class_setting($database);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object_selfhelp=new class_selfhelp($database);
		list($articles_info, $selfhelp)=$object_selfhelp->get_article(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and display_status!=2', VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',' entry_date desc ');
		list($featured_articles_info, $featured_articles)=$object_selfhelp->get_article(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and is_stick=1', VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',' entry_date desc ');
		$filter=VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'department.is_enabled=1';
        $departments=$ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
		$filter='module_id=11 AND domain_id='.VIS_DOMAIN;
		$widget_details=$setting->get_widget_setting($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'widget.php');
		//include(VIS_PATH_TEMPLATE.'widget.php');
		//include(VIS_PATH_TEMPLATE.'footer.php');
	}	
	function view_widget($operation) {
        global $vis_language;
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			include(VIS_PATH_TEMPLATE.'widget.php');
			return true;		
    }
	function get_widget_setting($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting=new class_setting($database);
			$filter='module_id=11 AND domain_id='.$operation['vis_domain'];
		    $widget_details=$setting->get_widget_setting($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
			//list($articles_info, $selfhelp)=$setting->get_article('display_status!=2 and '.$filter, VIS_DOMAIN, VIS_LOCATION_AREA);
			list($dpinf, $domain)=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.domain_id='.$operation['vis_domain'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			include(VIS_PATH_TEMPLATE.'widget_setting.php');
			$database->database_disconnect();
			return true;
    }
	
	function active_directory($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');
		$object_staff=new class_staff($database);
		
		list($dmin, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		list($view_info, $view_details)=$object_staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter=' login_type=15';
        list($active_dir_info, $active_dir_details)=$object->get_active_directory($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, $limit);
		
		$active_dir_info['page_count']=($active_dir_info['total']==0)?0:ceil($active_dir_info['total']/$view_info['page_count']);
		
        $database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'view_active_directory.php');
		
		return true;
	}
	function new_active_directory($operation){
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
		$currentPage = urldecode($action[3]);
		
        $database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		list($dpinf, $domain_list)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$active_dir_details=-1;
		$single_login_id = '';
        if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			$filter=' login_type=15 and single_login_id='.$action[4];
			list($active_dir_info, $active_dir_details)=$object->get_active_directory($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$active_dir_details =$active_dir_details[0];
			$single_login_id=($active_dir_details!=-1) ? $active_dir_details['single_login_id'] : '';
		}
    
        include(VIS_PATH_TEMPLATE.'new_active_directory.php');
		$database->database_disconnect();
		return true;
	}
	function ticket_service_item_custom_field($operation){
		global $vis_language;
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$filter = 'is_enabled=1 and ci_type=2 and customgroup_id='.$operation['vis_item_id'].' GROUP BY field_group';
		list($customfield_info, $custom_fields_details)=$object->get_cicustomfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		if($custom_fields_details != -1 && count($custom_fields_details)>0){
			$custom_field_var = $this->get_customfield_data_list($custom_fields_details,$operation['vis_item_id'],VIS_STAFF_ID,VIS_LOCATION_AREA);	
		}else $custom_field_var='';
		$database->database_disconnect();
		echo $custom_field_var;
	}
	
	/* start code for 9-10-15*/
	function manage_portal_setting_popup($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $settings=$object->get_settings('(title="vis_manage_portal_theme" or title="vis_manage_portal_logo" OR title like "vis_manage_logo" OR title like "vis_manage_portal_text" or title="vis_manage_portal_text_bold" or title="vis_manage_portal_text_italic" or title="vis_manage_portal_text_colour" OR title like "vis_manage_portal_language") and domain_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($settings!=-1) for($i=0;$i<count($settings);$i++) {
            if($settings[$i]['title']=='vis_manage_portal_theme') {
                $poral_settingm['vis_manage_portal_theme']=$settings[$i]['content'];
            }
            elseif($settings[$i]['title']=='vis_manage_portal_logo') {
                $poral_settingm['vis_manage_portal_logo']=$settings[$i]['content'];
            }
            elseif($settings[$i]['title']=='vis_manage_portal_text') {
                $poral_settingm['vis_manage_portal_text']=$settings[$i]['content'];
            }
			elseif($settings[$i]['title']=='vis_manage_portal_text_bold') {
                $poral_settingm['vis_manage_portal_text_bold']=$settings[$i]['content'];
            }
			elseif($settings[$i]['title']=='vis_manage_portal_text_italic') {
                $poral_settingm['vis_manage_portal_text_italic']=$settings[$i]['content'];
            }
			elseif($settings[$i]['title']=='vis_manage_portal_text_colour') {
                $poral_settingm['vis_manage_portal_text_colour']=$settings[$i]['content'];
            }
            elseif($settings[$i]['title']=='vis_manage_logo') {
                $poral_settingm['vis_manage_logo']=$settings[$i]['content'];
            }
            elseif($settings[$i]['title']=='vis_manage_portal_language') {
                $poral_settingm['vis_manage_language']=$settings[$i]['content'];
            }
			
        }
        $themesm=array();
        if ($dm=dir(VIS_PATH_MANAGE_THEME)) {
            $i=$j=0;
            while (false !== ($entrym = $dm->read())) {
                if(!is_dir(VIS_PATH_MANAGE_THEME.$entrym) && $entrym != 'index.html' && $entrym != 'vh-icons.css') {
                    $themesm[$i]['theme'] = substr_replace($entrym, "", -4);
                    switch($themesm[$i]['theme']){
                        case 'blue': $themesm[$i]['style'] = "background-color: #7ABAF2; color: #ffffff;"; break;
                        case 'cheery': $themesm[$i]['style'] = "background-color: #690011; color: #ff3657;"; break;
                        case 'dave': $themesm[$i]['style'] = "background-color: #A62152; color: #eda6c0;"; break;
                        case 'explorer': $themesm[$i]['style'] = "background-color: #0E6313; color: #56e75e;"; break;
                        case 'filibonik': $themesm[$i]['style'] = "background-color: #16A3A3; color: #94f1f1;"; break;
                        case 'green': $themesm[$i]['style'] = "background-color: #96ED89; color: #ffffff;"; break;
                        case 'grey': $themesm[$i]['style'] = "background-color: #929E88; color: #f9faf8;"; break;
                        case 'human': $themesm[$i]['style'] = "background-color: #F2D0C4; color: #ffffff;"; break;
                        case 'default': $themesm[$i]['style'] = "background-color: #588F27; color: #bfe49e;"; break;
                        case 'mango': $themesm[$i]['style'] = "background-color: #F58026; color: #fef2e9;"; break;
                        case 'nikeair': $themesm[$i]['style'] = "background-color: #F25EB0; color: #ffffff;"; break;
                        case 'zoo': $themesm[$i]['style'] = "background-color: #837979; color: #e5e3e3;"; break;
                        case 'dark': $themesm[$i]['style'] = "background-color: #111111; color: #777777;"; break;
                        case 'dark_blue': $themesm[$i]['style'] = "background-color: #177bbb; color: #aad7f4;"; break;
                    }
                    $i++;
                }
            }
        }
        sort($themesm);
		// start client setting
        list($info, $domain)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_id=(isset($operation['vis_domain_id']) && is_numeric($operation['vis_domain_id']))?$operation['vis_domain_id']:$domain[0]['domain_id'];
		
        $setting=$object->get_settings('(title like "vis_head_menu_%" or title="vis_theme_color" or title="vis_portal_logo" or title="vis_portal_text" or title="vis_portal_text_bold" or title="vis_portal_text_italic" or title="vis_portal_text_colour" or title="vis_manage_logo") and (domain_id='.$domain_id.' or domain_id=0)', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        $default_set=$object->get_settings('title="vis_default_home_operation" and domain_id='.$domain_id, VIS_CLIENT_ID, VIS_LOCATION_AREA);
        list($info, $modules)=$object->get_module('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$filter=VIS_TABLE_PREFIX.'domain.domain_id='.$domain_id.' ';
        list($domain_info, $domain_details)=$object->get_domain($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain_details=$domain_details[0];
		
        foreach($modules as $var) $module[$var['module']]=1;
		$default_home = ($default_set == -1) ? ((isset($module['solutions']) && $module['solutions'] == 1 ) ? 'selfhelp:view_selfhelp_group' : 'home:home') : $default_set[0]['content'];
        $database->database_disconnect();
	    if($setting!=-1) for($i=0;$i<count($setting);$i++) {
            if(preg_match('/vis_head_menu_(.*)/', $setting[$i]['title'], $match)) {
                $poral_setting[strtolower($match[1])]=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_theme_color') {
                $poral_setting['theme_color']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_portal_logo') {
                $poral_setting['vis_portal_logo']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_portal_text') {
                $poral_setting['vis_portal_text']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_bold') {
                $poral_setting['vis_portal_text_bold']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_italic') {
                $poral_setting['vis_portal_text_italic']=$setting[$i]['content'];
            }
			elseif($setting[$i]['title']=='vis_portal_text_colour') {
                $poral_setting['vis_portal_text_colour']=$setting[$i]['content'];
            }
            elseif($setting[$i]['title']=='vis_manage_logo') {
                $poral_setting['vis_manage_logo']=$setting[$i]['content'];
            }
			 
        }    
		
		if(!isset($poral_setting['theme_color'])) $poral_setting['theme_color']="#588f27";   
		
		$themes=array();
		if ($d=@dir(VIS_PATH_CLIENT_THEME)) while (false!==($entry = $d->read())) if(@is_dir(VIS_PATH_CLIENT_THEME.$entry) && $entry!='.' && $entry!='..') $themes[]=$entry;
        $operation['view_title']=$vis_language['TXTCLIENTPORTAL'];
		$operation['vis_current_operation']='portal_setting';
		$operation['vis_current_module']='setting';
		
		$database->database_disconnect();
        include(VIS_PATH_TEMPLATE.'manage_portal_setting_popup.php');
        return true;
    }
	
	
	function mailqueue_details_popup($operation) {
        global $vis_language;
        $database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		$object=new class_setting($database);
		$sub_object=new class_subsetting($database);
		list($department_info, $department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($domain_info, $domain_details)=$object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id=1', $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$filter=VIS_TABLE_PREFIX.'mailqueue.mailqueue_id=1';
		list($mailqueue_info, $mailqueue_details)=$object->get_mailqueue($filter, 1, 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$mailqueue_details=$mailqueue_details[0];
		
		if(isset($domain_details[0]['domain_name']))
		{
			$subdomain_name=explode('.',$domain_details[0]['domain']);
		}
		$operation['view_note']='<div class="notes"><p>With the default setup we have created a test email support@'.$subdomain_name[0].'.visionhelpdesk.com You can choose to use the same email for testing incoming emails by sending it some test email or you can setup your company email something@yourdomain.com<p>        
		<p>In order to use your company email please set email forwarding <span id="companyemailid">something@yourdomain.com</span> to support@'.$subdomain_name[0].'.visionhelpdesk.com</p>
		<p>if you wish to set incoming email mail with POP3 or IMAP please add it from Settings &gt;&gt; Email queue section</p>
		</div>';
		include(VIS_PATH_TEMPLATE.'mailqueue_details_popup.php');
		return true;
       
    }
	
	function upload_logo_popup($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$ret=$object->upload_file_popup($_FILES, $operation, VIS_DOMAIN, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) { ?>
            <script> parent.$("#vis_global_msg_div").visInterface("load_global_message", "<?= $vis_language['MSGERROPRT']; ?>"); </script>; <?
            return false;
        }
        else {
			$clear_client_logo_Btn = $clear_manage_logo_Btn =$message='';
			$message.='<img height=\"80px\" src=\"'.VIS_PATH_PROFILE.$ret.'\" />';
			$clear_client_logo_Btn.= '<button type=\"button\" id=\"clear_client_logo_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_logo();\">'.$vis_language['TXTCLEAR'].'</button>';
			$clear_manage_logo_Btn.= '<button type=\"button\" id=\"clear_manage_logo_Btn\" class=\"btn btn-primary btn-xs pull-left m-t-lg\" onclick=\"javascript:clear_manage_logo();\">'.$vis_language['TXTCLEAR'].'</button>';
			 if($operation['portal']=='manage'){	?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_manage_logo_Btn ?>","vis_manage_portal":1}); </script>
            <? } else {?>
            <script> parent.$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message ?>", "vis_button":"<? echo $clear_client_logo_Btn ?>","vis_client_portal":1}); </script>; <? }
        }
        return true;
    }
	
	function remove_logo_popup($operation) {
        global $vis_language;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        $ret1=$object->clear_logo($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$operation['vis_manage']='';
		$ret=$object->clear_logo($operation,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(!$ret) { ?>
            <script> $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>'; <?
            return false;
        }
        else {
			$clearBtn = $message='';
            $message.='<img height=\"80px\" src=\"'.VIS_PATH_IMAGES.'vh-logo.svg?ver=02122014'.'\" />';
          if($operation['vis_manage']==1 )
		{?>
<script>$('#clear_manage_logo_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_manage_portal":1});</script><? }else{?>
<script>$('#clear_client_logo_Btn').remove();$("#vis_global_msg_div").visExecution("load_profile", {"vis_message":"<? echo $message; ?>","vis_client_portal":1});</script> <? }

        }
        return true;
    }
	
	
/*Incident functions*/	
function view_ticket_category($operation) {
	
        global $vis_language;
		
		$database=new class_database();
      	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
		
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter='';
				
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " title like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= " is_enabled =".$data['vis_status'].' and '; 
            }
			$filter=substr($filter, 0, -4);
        }

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $sub_object=new class_subsetting($database);
		
		$ticket_cat_info = array();
		list($department_info, $department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(VIS_ADMIN_ACCESS_LEVEL==1)
          list($ticket_cat_count,$ticket_cat_details)=$setting->get_ticket_category_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        else{
			
		  list($ticket_cat_count,$ticket_cat_details)=$setting->get_properties('get_ticket_category', $filter,$limit,$data);
		}
        list($ticket_subcat_count,$ticketsubcatdetail)=$setting->get_ticket_subcategory_list($filter='is_enabled=1',$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
		$view_info['page_count']=($ticket_cat_count['total']==-1)?0:ceil($ticket_cat_count['total']/$view_info['page_count']);
        $ticket_cat_info['ticket_cat_count']=(!$ticket_cat_details || $ticket_cat_details==-1)?0:$ticket_cat_count['total'];
		$ticket_cat_info['ticket_subcat_count']=(!isset($ticket_subcat_count['total']))?0:$ticket_subcat_count['total'];
		$ticket_cat_info['page']=$page;
        $database->database_disconnect();
        $ticket_cat_info['page']=$page;
        $operation['view_title']=$vis_language['TXTTICKETCATEGORY'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_ticket_category';
        $operation['vis_current_operation']='view_ticket_category';
		$operation['vis_suboperation']='view_ticket_subcategory';
		$operation['vis_subitemoperation']='view_ticket_item';
        $operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
		
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'ticket_category_list.php');
			$ticket_category_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'=>$ticket_cat_info['ticket_cat_count'], 'paging' => $select, 'list'=> $ticket_category_list ,'filter'=> $filter ));
		}else
		include(VIS_PATH_TEMPLATE.'ticket_category.php');
	}
	function new_ticket_category($operation){
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
	    $database=new class_database();
        $operation['view_title']=$vis_language['TXTTICKETCATEGORY'];
        $object=new class_setting($database);
		$sub_object=new class_subsetting($database);
		$staffobj=new class_staff($database);
		list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		$staff_details=$staffobj->get_staff($filter='',VIS_STAFF_ID, VIS_LOCATION_AREA,$department='');
		list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
	    include(VIS_PATH_TEMPLATE.'new_ticket_category.php');
        return true;
    }
	
	function view_ticket_subcategory($operation) {
	
        global $vis_language;
		 global $vis_language;
		$database=new class_database();
      	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
		
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter='';
				
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " title like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= VIS_TABLE_PREFIX."ticket_subcategory.is_enabled =".$data['vis_status'].' and '; 
            }
			if(isset($data['vis_parent_id']) && $data['vis_parent_id'] != "0"){
                $filter .= VIS_TABLE_PREFIX."ticket_subcategory.category_id =".$data['vis_parent_id'].' and '; 
            }
			$filter=substr($filter, 0, -4);
        }

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $sub_object=new class_subsetting($database);
		
		$ticket_subcat_info = array();
		list($domain_info, $domain_details)=$setting->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($filter=='') $filter = VIS_TABLE_PREFIX.'ticket_category.is_enabled=1';
		else $filter .= ' and '.VIS_TABLE_PREFIX.'ticket_category.is_enabled=1';
        if(VIS_ADMIN_ACCESS_LEVEL==1){
          list($ticket_subcat_count,$ticket_subcat_details)=$setting->get_ticket_subcategory_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
          list($parent_categoryc,$parent_category)=$setting->get_ticket_category_list('is_enabled=1',$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		}else{
			
		  list($ticket_subcat_count,$ticket_subcat_details)=$setting->get_properties('get_ticket_subcategory', $filter,$limit,$data);
		  list($parent_categoryc,$parent_category)=$setting->get_properties('get_ticket_category', 'is_enabled=1','','');
		}
		$view_info['page_count']=($ticket_subcat_count['total']==-1)?0:ceil($ticket_subcat_count['total']/$view_info['page_count']);
        $ticket_subcat_info['ticket_subcat_count']=(!$ticket_subcat_details || $ticket_subcat_details==-1)?0:$ticket_subcat_count['total'];	
		
		$ticket_subcat_info['page']=$page;
        $database->database_disconnect();
        $ticket_subcat_info['page']=$page;
        $operation['view_title']=$vis_language['TXTTICKETSUBCATEGORY'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_ticket_subcategory';
        $operation['vis_current_operation']='view_ticket_subcategory';
		$operation['vis_suboperation']='view_ticket_item';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'ticket_subcategory_list.php');
			$ticket_subcategory_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'=>$ticket_subcat_info['ticket_subcat_count'], 'paging' => $select, 'list'=> $ticket_subcategory_list ,'filter'=> $filter ));
		}else
		include(VIS_PATH_TEMPLATE.'ticket_subcategory.php');
	}
	
	function new_ticket_subcategory($operation){
			global $vis_language;
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$database=new class_database();
			$operation['view_title']=$vis_language['TXTTICKETSUBCATEGORY'];
			$object=new class_setting($database);
			$filter = VIS_TABLE_PREFIX.'ticket_category.is_enabled=1';
			list($parent_count,$parent_category)=$object->get_ticket_category_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
			list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
			$database->database_disconnect();
			include(VIS_PATH_TEMPLATE.'new_ticket_subcategory.php');
			return true;
    }
	
	
	function view_ticket_item($operation) {
	
        global $vis_language;
		 global $vis_language;
		$database=new class_database();
      	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
		
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter='';
				
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " title like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= VIS_TABLE_PREFIX."ticket_item.is_enabled =".$data['vis_status'].' and '; 
            }
			if(isset($data['vis_subcategory_id']) && $data['vis_subcategory_id'] != "0"){
                $filter .= VIS_TABLE_PREFIX."ticket_item.subcategory_id =".$data['vis_subcategory_id'].' and '; 
            }
			$filter=substr($filter, 0, -4);
        }

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $sub_object=new class_subsetting($database);
		if($filter=='') $filter = VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1';
		else $filter .= ' and '.VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1';
		$ticket_item_info = array();
		if(VIS_ADMIN_ACCESS_LEVEL==1){
         list($ticket_item_count,$ticket_item_details)=$setting->get_ticket_item_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
         list($subcategory_count,$subcategory_list)=$setting->get_ticket_subcategory_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
        }else{
			
	     list($ticket_item_count,$ticket_item_details)=$setting->get_properties('get_ticket_item', $filter,$limit,$data);
		 list($subcategory_count,$subcategory_list)=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','','');
		}
		$view_info['page_count']=($ticket_item_count['total']==-1)?0:ceil($ticket_item_count['total']/$view_info['page_count']);
        $ticket_item_info['ticket_item_count']=(!$ticket_item_details || $ticket_item_details==-1)?0:$ticket_item_count['total'];
		$ticket_item_info['page']=$page;
        $database->database_disconnect();
        $ticket_item_info['page']=$page;
        $operation['view_title']=$vis_language['TXTTICKETITEM'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_ticket_item';
        $operation['vis_current_operation']='view_ticket_item';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'ticket_item_list.php');
			$ticket_item_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'=>$ticket_item_info['ticket_item_count'], 'paging' => $select, 'list'=> $ticket_item_list ,'filter'=> $filter ));
		}else
		include(VIS_PATH_TEMPLATE.'ticket_item.php');
	}
	
	function new_ticket_item($operation){
		global $vis_language;
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$database=new class_database();
        $operation['view_title']=$vis_language['TXTTICKETITEM'];
        $object=new class_setting($database);
		$filter = VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1';
		list($subcat_count,$subcategory_list)=$object->get_ticket_subcategory_list($filter,$data='',VIS_STAFF_ID, VIS_LOCATION_AREA,$limit='');
		list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
	    include(VIS_PATH_TEMPLATE.'new_ticket_item.php');
        return true;
    }
	// ticket level
	function view_ticket_level($operation) {
	
        global $vis_language;
		$database=new class_database();
      	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $staff=new class_staff($database);
		
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
		$filter='';
				
        if(isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)
        {
            $data = parse_form_array($operation['vis_action']);
            if(isset($data['vis_title']) && $data['vis_title'] != ""){
                $filter .= " title like '%".$data['vis_title']."%' and ";
            }
            if(isset($data['vis_status']) && $data['vis_status'] != ""){
                $filter .= " is_enabled =".$data['vis_status'].' and '; 
            }
			$filter=substr($filter, 0, -4);
        }

		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting=new class_setting($database);
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
        $sub_object=new class_subsetting($database);
		list($department_info, $department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$ticket_level_info = array();
		if(VIS_ADMIN_ACCESS_LEVEL==1)
         list($ticket_level_count,$ticket_level_details)=$setting->get_ticket_level_list($filter,$data,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        else{
			
	     list($ticket_level_count,$ticket_level_details)=$setting->get_properties('get_ticket_level', $filter,$limit,$data);
		}
        
		
		$view_info['page_count']=($ticket_level_count['total']==-1)?0:ceil($ticket_level_count['total']/$view_info['page_count']);
        $ticket_level_info['ticket_level_count']=(!$ticket_level_details || $ticket_level_details==-1)?0:$ticket_level_count['total'];
		$ticket_level_info['page']=$page;
        $database->database_disconnect();
        $ticket_level_info['page']=$page;
        $operation['view_title']=$vis_language['TXTTICKETLEVEL'];
        $operation['option_id']=2;
        $operation['vis_operation']='new_ticket_level';
        $operation['vis_current_operation']='view_ticket_level';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADD'];
		
         if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'ticket_level_list.php');
			$ticket_level_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'=>$ticket_level_info['ticket_level_count'], 'paging' => $select, 'list'=> $ticket_level_list ,'filter'=> $filter ));
		}else
		include(VIS_PATH_TEMPLATE.'ticket_level.php');
	}
	
	function new_ticket_level($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$sub_object=new class_subsetting($database);
		$object=new class_setting($database);
		list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($department_info,$department_details)=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $operation['view_title']=$vis_language['TXTTICKETLEVEL'];
        include(VIS_PATH_TEMPLATE.'new_ticket_level.php');
        return true;
    }
	function show_message($operation){
		 global $vis_language;
		 $message_info['vis_title']=$vis_language['TXTNOTE'];
		 if(isset($operation['vis_show_category']) && $operation['vis_show_category']==1)
			 $message_info['vis_message']=$vis_language['MSGENABLETICKETCATEGORY'];
		 else if(isset($operation['vis_show_level']) && $operation['vis_show_level']==1)
			 $message_info['vis_message']=$vis_language['MSGENABLETICKETLEVEL'];
		 include(VIS_PATH_TEMPLATE.'show_message.php');
        return true;
	 }
	##Exotel
	 function exotel_details($operation){ 
		global $vis_language;
        $operation['view_title']=$vis_language['TXTFLAG'];
        $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.'setting.php');
            $setting_object=new class_setting($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);
			$departments = $setting_object->get_all_dept();	
            $filter='exotel_id='.$action[4].' ';
			list($number_count, $exotel_details)=$setting_object->get_exotel_apps($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			if($exotel_details==-1){
				$this->error=$vis_language['MSGINFOMISS'];
				return false;
			}
			$exotel_details = $exotel_details[0];
			//$filter='exotel_id='.$action[4].' ';
           // $key_details = $setting_object->get_twilio_key($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			list($integration_info, $integration_details)=$setting_object->get_integration_setting('integration_type=38 AND is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
			$filter ='';
            if($exotel_details['integration_id']!=0){
				$filter1='integration_type=38 AND integration_id='.$exotel_details['integration_id'];
				list($exotel_info, $exotel_intgration)=$setting_object->get_integration_setting($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
				
				if($exotel_intgration[0]['domain_id']!=0){
					$filter .= VIS_TABLE_PREFIX.'domain.domain_id='.$exotel_intgration[0]['domain_id'].' AND ';
				}
			}
			$filter .=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$ticket_object->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$departmentid = $departments[0]['department_id'];
			
            include(VIS_PATH_TEMPLATE.'exotel_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
	}
	 function exotel($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		list($vis_all_domain, $exotel_details)=$object->integation_app_availability('38', 'none');
		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$exotel_details = $exotel_details[0];
		include(VIS_PATH_TEMPLATE.'exotel_setting.php');
		return true;
	}
	 function exotel_setting($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		if($operation['vis_domain']=='all'){$operation['vis_domain']=0;}
		$filter='integration_type=38 AND domain_id='.$operation['vis_domain'];
		list($exotel_info, $exotel_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$exotel_details = $exotel_details[0];
		include(VIS_PATH_TEMPLATE.'exotel_setting_details.php');
		return true;
	}
	 function exotel_apps($operation) {  // activity log list
	    $action = explode('/',$operation['vis_action']); 
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        
        list($number_count, $exotel_apps)=$object->get_exotel_apps(VIS_TABLE_PREFIX.'exotel_apps.integration_id ='.$action[4], $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$view_info['page_count']=($number_count['total']==0)?0:ceil($number_count['total']/$view_info['page_count']);
        include(VIS_PATH_TEMPLATE.'exotel_app.php');
        $database->database_disconnect();
        return true;
    }
	function new_exotel_app($operation){ 
		$database=new class_database();
		$action = explode('/',$operation['vis_action']); 
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$departments = $object->get_all_dept();	
		$filter='integration_type=38 AND is_enabled=1';
		list($integration_info, $integration_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);		
        $database->database_disconnect();
		include(VIS_PATH_TEMPLATE.'exotel_add_new_app.php');
		return true;
    }
	function get_dept($dom_dept){
		$database=new class_database();
		$arr = explode(':',$dom_dept);
		$domain_id = $arr[0];
		$department_id = $arr[1];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$dept_res = $object->get_all_dept(" AND dept.department_id = ".$department_id);
		$database->database_disconnect();
		return $dept_res; 
	}
	###Exotel	 	
	##Form creation tool
	function view_form_groups($operation){ //form group listing
        global $vis_language;
        $operation['view_title']=$vis_language['TXTFORMGROUP'];
        $operation['vis_operation']='new_form_group';
		$operation['vis_current_operation']='view_form_groups';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDFORMGROUP'];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
 		$staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
 		$view_info['page_count'];
		$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
   		$limit=($page*$view_info['page_count']).','.$view_info['page_count'];
   		$filter = "";
		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(isset($data['vis_grouptype']) && $data['vis_grouptype'] != "")
             {
                if($filter != '') {$filter .= " and location =".$data['vis_grouptype']; }
                else if($filter == ''){$filter .= " location =".$data['vis_grouptype']; }
            }
            else $filter .= "";
            if(isset($data['vis_status']) && $data['vis_status'] != "")
            {
                if($filter != '') {$filter .= " and is_enabled =".$data['vis_status']; }
                else if($filter == ''){$filter .= " is_enabled =".$data['vis_status']; }
            }
            else $filter .= "";
        }
        $custom_group_details=$object->get_form_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
        $custom_group_total=$object->get_form_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $custom_group_total=(!$custom_group_total || $custom_group_total==-1)?0:count($custom_group_total);
		$group_info['group_count']= $custom_group_total;
		$view_info['page_count']=($custom_group_total==0)?0:ceil($custom_group_total/$view_info['page_count']);
        $database->database_disconnect();
		$group_info['page']=$page;
		 if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'form_group_list.php');
			$staff_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'=>$custom_group_total, 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else 
        include(VIS_PATH_TEMPLATE.'form_group.php');
    }
	function get_formgroup_delete($operation) { 
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETEFORM'];
        $message_info['vis_message']=$vis_language['MSGFORMGRPDEL'];
		$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_formgroup', 'vis_formgroup_id':".$operation['vis_formgroup_id'].", 'vis_page':".$vis_page."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function form_group_details($operation) { 
        global $vis_language;
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');		
        $operation['view_title']=$vis_language['TXTFORMGROUP'];
        $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.'setting.php');
			 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $object=new class_setting($database);
			$sub_object=new class_subsetting($database);
			$ticket=new class_ticket($database);
			$filter= (VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			if(VIS_LOCATION_AREA==2 && isset($operation['vis_domain_id']) && $operation['vis_domain_id']!='') $filter.=' and '.VIS_TABLE_PREFIX.'department.domain_id='.$operation['vis_domain_id'];
			if(isset($operation['vis_client']) && $operation['vis_client']==1)
			$filter.=' and '.VIS_TABLE_PREFIX.'domain.domain_id='.$operation['vis_domain_id'];	
			$departments=$ticket->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, '');
		
            $filter=VIS_TABLE_PREFIX.'formgroup.formgroup_id='.$action[4].' ';
            $custom_group_details=$object->get_form_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA,'','edit_page');			
			$domain_detaiis = $object->get_domain_list($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			 list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			 $formfieldgroup_lang=$object->get_translation(29, 'data_id='.$custom_group_details[0]['formgroup_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
            include(VIS_PATH_TEMPLATE.'form_group_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
    }
	
	 function view_formfield($operation) {
        global $vis_language;
        $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']:'';
        $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);
        $operation['view_title']=$vis_language['TXTFORMFIELD'];
        $operation['vis_operation']='new_form_field';
		$operation['vis_current_operation']='view_formfield';
		$operation['vis_current_module']='setting';
        $operation['vis_message']=$vis_language['TXTADDNEWFORMFIELD'];

		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_form_field_group']!='')
			{
				$filter = " formgroup_name like '%".$data['vis_form_field_group']."%'"  ;
				$form_group = $setting_object->get_form_group_list($filter,VIS_STAFF_ID, VIS_LOCATION_AREA);
				$and_operations['formgroup_id'] = ' IN (';
				if($form_group!=-1) {
				for($i=0;$i< (count($form_group));$i++)
					$and_operations['formgroup_id'] .= $form_group[$i]['formgroup_id'].',';
				$and_operations['formgroup_id'] = trim($and_operations['formgroup_id'],',');
				$and_operations['formgroup_id'] .= ')';
				}else $and_operations['formgroup_id'] .= '0)';
			}
		   if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
        }
        $database->database_disconnect(VIS_STAFF_ID, VIS_LOCATION_AREA);		
        return $this->formfield_display($operation, $and_operations, '', '', $page, $sort_by);
    }
	function formfield_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
		$action = explode('/',$operation['vis_action']);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'formfield.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") and ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'formfield.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") and ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        //$filter .= ' location != 4 ';
		if($action[4]!=''){ $filter .= ' '.VIS_TABLE_PREFIX.'formfield.formgroup_id='.$action[4]; }
		list($customfield_info, $customfield_details)=$object->get_formfield(0,$filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
		//echo '<pre>';print_r($customfield_info); print_r($customfield_details); echo '</pre>';
        $view_info['page_count']=($customfield_info['total']==0)?0:ceil($customfield_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $customfield_info['customfield_count']=(!$customfield_details || $customfield_details==-1)?0:count($customfield_details);
        $customfield_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTCUSTOMFIELD'];
		 if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'formfield_list.php');
			$staff_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'=>$customfield_info['total'], 'paging' => $select, 'list'=> $staff_list ,'vis_filter_enable' => '1'));
		}else
        include(VIS_PATH_TEMPLATE.'formfields.php');
        return true;
    }
	function get_formfield_delete($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETEFORMFIELD'];
        $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':'setting', 'vis_operation':'delete_formfield', 'vis_fieldgroup_id':".$operation['vis_fieldgroup_id'].", 'vis_page':".$vis_page."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	function formfield_details($operation) {
        global $vis_language;
        $operation['view_title']=$vis_language['TXTFORMFIELD'];
        $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.'setting.php');
            $object=new class_setting($database);
            //$filter1 = " location != 4 and is_enabled=1";
             list($language_info,$language_details)=$object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
             
            $form_group_details=$object->get_form_group_list($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
          
			//echo '<pre>'; print_r($form_group_details); echo '</pre>'; 
            $filter=VIS_TABLE_PREFIX.'formfield.field_group='.$action[4].' ';
            list($formfield_info, $formfield_details)=$object->get_formfield(1, $filter, '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA,'edit_page');	
             $formgroup_lang=$object->get_translation(26, 'data_id='.$formfield_details[0]['field_group'],VIS_STAFF_ID, VIS_LOCATION_AREA);	 
             for($i=0;$i<count($formfield_details);$i++)
          { $formfield_lang=$object->get_translation(27, 'data_id='.$formfield_details[$i]['formfield_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);	 
			 $formfield_array_lang[]= $formfield_lang;
            }
            include(VIS_PATH_TEMPLATE.'form_field_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGMISSINFO'];
            return false;
        }
    }
	###Form creation tool
	
    // Hipchat integration function - start
	function integration_hipchat($operation){		
        $filter='integration_type='.$operation['vis_integration_type'] .' and '.VIS_TABLE_PREFIX.'integration.domain_id='.$operation['vis_domain'];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$all_domain = ($operation['vis_domain']==0)?1:0;
		$hipchat_details=$object->get_hipchat_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$hipchat_details = $hipchat_details[0];
		
        $database->database_disconnect();
        include_once(VIS_PATH_TEMPLATE.'add_hipchat.php');

	}
	 function get_hipchat_delete($operation){
        global $vis_language;
        if(isset($operation['vis_all_domains']) && $operation['vis_all_domains']==1){
			$operation['vis_all_domains']=1;
		}
		else{
			$operation['vis_all_domains']=0;
		}
        $message_info['vis_form_title']=$vis_language['TXTDELHIPCHAT'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_hipchat', 'vis_all_domains':".$operation['vis_all_domains'].", 'vis_domain':".$operation['vis_domain'].",'vis_integration_id':".$operation['vis_integration_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
    // Hipchat integration function - End
    
    // Slack integration function - Start
    function integration_slack($operation){		
        $filter='integration_type='.$operation['vis_integration_type'] .' and '.VIS_TABLE_PREFIX.'integration.domain_id='.$operation['vis_domain'];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$all_domain = ($operation['vis_domain']==0)?1:0;
		$slack_details=$object->get_slack_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$slack_details = $slack_details[0];
		
        $database->database_disconnect();
        include_once(VIS_PATH_TEMPLATE.'add_slack.php');

	}
    function get_slack_delete($operation){
        global $vis_language;
        if(isset($operation['vis_all_domains']) && $operation['vis_all_domains']==1){
			$operation['vis_all_domains']=1;
		}
		else{
			$operation['vis_all_domains']=0;
		}
        $message_info['vis_form_title']=$vis_language['TXTDELSLACK'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_slack', 'vis_all_domains':".$operation['vis_all_domains'].", 'vis_domain':".$operation['vis_domain'].",'vis_integration_id':".$operation['vis_integration_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
    // Slack integration function - End
    function googleapp($operation){
	    global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		$filter_gcal='integration_type=42 AND domain_id=0';

		list($cnt_info, $gcal_details)=$object->get_integration_setting($filter_gcal, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$gcal_details=$gcal_details[0];

		include(VIS_PATH_TEMPLATE.'view_googleapp.php');
		return true;
	}
	
	function get_outgoingcron_message($operation)
	{ global $vis_language;
	$message_info['vis_form_title'] = $vis_language['TXTNOTE'];
        $message_info['vis_message']    = '<span class="vh-red">For download license you are required to set cron or scheduler on your server to run every 3 minutes. (For setting cron or scheduler check our help section or contact our support team)</span><br><br>
<span class="vh-red">For SaaS license cron on already setup on our cloud server</span>
';
								
        $message_info['vis_event']      = "$('#enable_status').visExecution('load_area', {'vis_module':'setting', 'vis_operation':'queue_outgoing_mail_update', 'vis_status':".$operation['vis_status']."});";
        include(VIS_PATH_TEMPLATE . 'confirm_delete.php');
        return true;
	}
	
	function get_reportcron_message($operation)
	{ global $vis_language;
	$message_info['vis_form_title'] = $vis_language['TXTNOTE'];
        $message_info['vis_message']    = '<span class="vh-red">For download license you are required to set cron or scheduler on your server to run every 30 minutes. (For setting cron or scheduler check our help section or contact our support team)</span><br><br>
<span class="vh-red">For SaaS license cron on already setup on our cloud server</span>
';
								$message_info['vis_displaycancel']=0;
								$message_info['vis_displayok']=1;
        $message_info['vis_event']      = "";
        include(VIS_PATH_TEMPLATE . 'note_popup.php');
        return true;
	}
	
	function get_emailcroncron_message($operation)
	{ global $vis_language;
	$message_info['vis_form_title'] = $vis_language['TXTNOTE'];
        $message_info['vis_message']    = '<span class="vh-red">For download license you are required to set cron or scheduler on your server to run every 5 minutes. (For setting cron or scheduler check our help section or contact our support team)</span><br><br>
<span class="vh-red">For SaaS license cron on already setup on our cloud server</span>
';
								$message_info['vis_displaycancel']=0;
								$message_info['vis_displayok']=1;
        $message_info['vis_event']      = "";
        include(VIS_PATH_TEMPLATE . 'note_popup.php');
        return true;
	}
	 function roundrobin_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'roundrobin.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'roundrobin.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($roundrobin_info, $roundrobin_details)=$object->get_roundrobin($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($roundrobin_info['total']==0)?0:ceil($roundrobin_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $roundrobin_info['roundrobin_count']=(!$roundrobin_details || $roundrobin_details==-1)?0:count($roundrobin_details);
        $roundrobin_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTROUNDROBIN'];
        $operation['vis_operation']='new_roundrobin';
		$operation['vis_current_operation']='view_roundrobin';
		$operation['vis_current_module']='setting';
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'roundrobin_list.php');
			$roundrobin_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'=>$roundrobin_info['total'], 'paging' => $select, 'list'=> $roundrobin_list));
		}else
        include(VIS_PATH_TEMPLATE.'roundrobin.php');
        return true;
    }

    function view_roundrobin($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTROUNDROBIN'];
		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['roundrobin_name like "%'] = $data['vis_title'].'%"';
		 if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		}
       return $this->roundrobin_display($operation,$and_operations, '', '', $page, $sort_by);
    }
	function rounrobin_details($operation) {
        global $vis_language;
 	    $operation['view_title']=$vis_language['TXTROUNDROBIN'];
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        //$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.'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');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket=new class_ticket($database);
            $client=new class_client($database);
            $staff=new class_staff($database);
            $setting=new class_setting($database);
            $sub_object=new class_subsetting($database);
            list($stfinfo, $staff_details)=$setting->get_staff(VIS_TABLE_PREFIX.'staff.is_enabled=1','', 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($info, $etemplate)=$setting->get_etemplate('is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($roundrobin_info, $roundrobin_details)=$setting->get_roundrobin('roundrobin_id='.$action[4],'',0,0, VIS_STAFF_ID, VIS_LOCATION_AREA);
            $roundrobin_details=$roundrobin_details[0];
            if($roundrobin_details!='')
            {
            $roundrobin_criteria=$setting->get_roundrobin_criteria($action[4], VIS_STAFF_ID, VIS_LOCATION_AREA);
            $roundrobin_action=$setting->get_roundrobin_action($action[4], 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];
            for($i=0;$i<count($domains);$i++){
				$domain_list[]=$domains[$i]['domain_id'];
				$domain_ids=implode(",",$domain_list);
			}
			$user_groups=$client->get_client_group('is_enable=1 and (domain_id in ('.$domain_ids.') or domain_id=0 )', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $departments=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA); $departments=$departments[1];
            list($schedule_count,$schedule)=$setting->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($sla_count,$sla)=$setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($etemplate_count,$etemplate)=$setting->get_etemplate('is_enabled=1 and language=1','',0,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($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 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) {
			$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');
			$flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=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');
			list($category_info,$ticket_category)=$setting->get_ticket_category_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($subcategory_info,$ticket_subcategory)=$setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($item_info,$ticket_item)=$setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($level_info,$ticket_level)=$setting->get_ticket_level_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			} 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', 'is_enabled=1');	$label_details=$label_details[1];
			$channel_details=$setting->get_properties('get_channel', 'is_enabled=1');$channel_details=$channel_details[1];
			$ticket_category=$setting->get_properties('get_ticket_category', 'is_enabled=1');$ticket_category=$ticket_category[1];
			$ticket_subcategory=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1');$ticket_subcategory=$ticket_subcategory[1];
			$ticket_item=$setting->get_properties('get_ticket_item', VIS_TABLE_PREFIX.'ticket_item.is_enabled=1');$ticket_item=$ticket_item[1];
			$ticket_level=$setting->get_properties('get_ticket_level', 'is_enabled=1');$ticket_level=$ticket_level[1];
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			}
            //print_r($workflow_action);
            //$forwardto=explode(',', $workflow_action[13]['content']);
            //print_r($forwardto);
           
            //list($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $database->database_disconnect();
            include(VIS_PATH_TEMPLATE.'roundrobin_details.php');
            return true;
			}
            else
			{
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
				return false;
			}
			//}
    }
    function get_roundrobin_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELROUNDROBIN'];
        $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':'setting', 'vis_operation':'delete_roundrobin', 'vis_roundrobin_id':".$operation['vis_roundrobin_id'].", 'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
	 
	
	 function crispapp($operation){
		//  print_r($operation);
		global $vis_language;
			  $spliter=(strstr($operation['vis_action'], '/'))?'/':','; 
			$action=explode($spliter, $operation['vis_action']);
			  $currentPage = $action[3];
 
			 if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			 
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);  
			$vis_integration_type=$action[4];
			$data['vis_domain']=$operation['vis_domain'];
			 $filter='integration_type='.$vis_integration_type;
			list($crisp_info, $crisp_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); 
			$crisp_details=$crisp_details[0]; 
			include(VIS_PATH_TEMPLATE.'crispapp.php');
			 
			return true;
			 }
	} 
	/*function crisp_setting($operation){
		global $vis_language;
			$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			$filter='integration_type='.$operation['vis_integration_type'].' AND domain_id='.$operation['vis_domain'];
			list($crisp_info, $crisp_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); 
			$crisp_details=$crisp_details[0]; 
			include(VIS_PATH_TEMPLATE.'livechatinc_setting.php');
			$database->database_disconnect();
			return true;

    }*/
				
	 // Slack integration function - Start
    function integration_intercom($operation){		
        $filter='integration_type='.$operation['vis_integration_type'] .' and '.VIS_TABLE_PREFIX.'integration.domain_id='.$operation['vis_domain'];
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
        list($dmin, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$all_domain = ($operation['vis_domain']==0)?1:0;
		$intercom_details=$object->get_slack_details($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$intercom_details = $intercom_details[0];
		
        $database->database_disconnect();
        include_once(VIS_PATH_TEMPLATE.'add_intercom.php');

	}
    function get_intercom_delete($operation){
        global $vis_language;
        if(isset($operation['vis_all_domains']) && $operation['vis_all_domains']==1){
			$operation['vis_all_domains']=1;
		}
		else{
			$operation['vis_all_domains']=0;
		}
        $message_info['vis_form_title']=$vis_language['TXTDELINTERCOM'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
        $message_info['vis_event']="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module':'setting', 'vis_operation':'delete_intercom', 'vis_all_domains':".$operation['vis_all_domains'].", 'vis_domain':".$operation['vis_domain'].",'vis_integration_id':".$operation['vis_integration_id']."})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
    // Slack integration function - End
	
	##Aircall
	 function aircall($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		list($vis_all_domain, $aircall_details)=$object->integation_app_availability('50', 'none');
		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$filter = 'integration_type=50 and domain_id=0';
		$aircalldetails = $object->get_integrationdetails($filter);
		
		$aircall_details = $aircall_details[0];
		include(VIS_PATH_TEMPLATE.'aircall_setting.php');
		return true;
	}
	function aircall_setting($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		if($operation['vis_domain']=='all'){$operation['vis_domain']=0;}
		$filter='integration_type=50 AND domain_id='.$operation['vis_domain'];
		list($aircall_info, $aircall_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$aircall_details = $aircall_details[0];
		include(VIS_PATH_TEMPLATE.'aircall_setting_details.php');
		return true;
	}
	###Aircall
	
	function dropbox($operation){
		global $vis_language;
		 
	 
		 $spliter=(strstr($operation['vis_action'], '/'))?'/':','; 
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			 
			 if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			 
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);  
			$vis_integration_type=$action[4];
			$data['vis_domain']=$operation['vis_domain'];
			
			 $filter='integration_type='.$vis_integration_type;
			list($dropbox_info, $dropbox_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); 
			$dropbox_details=$dropbox_details[0]; 
			include(VIS_PATH_TEMPLATE.'dropbox.php');
			 
			return true;
			 } 
	}
			 
	function box($operation){
		global $vis_language;
		 
	 
		 $spliter=(strstr($operation['vis_action'], '/'))?'/':','; 
			$action=explode($spliter, $operation['vis_action']);
			$currentPage = $action[3];
			
			 if(isset($action[4]) && $action[4]!='' && is_numeric($action[4])) {
			 
			$database=new class_database();
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
			$object=new class_setting($database);
			list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);  
			$vis_integration_type=$action[4];
			$data['vis_domain']=$operation['vis_domain'];
			 $filter='integration_type='.$vis_integration_type;
			list($box_info, $box_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); 
			$box_details=$box_details[0]; 
			include(VIS_PATH_TEMPLATE.'box.php');
			 
			return true;
			 } 
		
		 
	}
	
	##Asterisk
	
	function asterisk($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		list($vis_all_domain, $asterisk_details)=$object->integation_app_availability('51', 'none');
		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$filter = 'integration_type=51 and domain_id=0';
		$asteriskdetails = $object->get_integrationdetails($filter);
		
		$asterisk_details = $asterisk_details[0];
		include(VIS_PATH_TEMPLATE.'asterisk_setting.php');
		return true;
	} 
	function asterisk_setting($operation){
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$object=new class_setting($database);
		if($operation['vis_domain']=='all'){$operation['vis_domain']=0;}
		$filter='integration_type=51 AND domain_id='.$operation['vis_domain'];
		list($asterisk_info, $asterisk_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$asterisk_details = $asterisk_details[0];
		include(VIS_PATH_TEMPLATE.'asterisk_setting_details.php');
		return true;
	}
	 function asterisk_dialplan($operation) {  // activity log list
	    $action = explode('/',$operation['vis_action']); 
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $database=new class_database();
        $staff=new class_staff($database);
        $object=new class_setting($database);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
		
        $page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        //'asterisk_dialplan.integration_id ='.$action[4]
		$filter = ' intg.integration_type =51 ';
        list($number_count, $asterisk_dialpalns)=$object->get_asterisk_dialpalns($filter, $limit, $page, '', VIS_STAFF_ID, VIS_LOCATION_AREA);
		//echo '<pre>'; print_r($asterisk_dialpalns); echo '</pre>';
		$view_info['page_count']=($number_count['total']==0)?0:ceil($number_count['total']/$view_info['page_count']);
        include(VIS_PATH_TEMPLATE.'asterisk_dialplan.php');
        $database->database_disconnect();
        return true;
    }
	function new_asterisk_dialplan($operation){ 
		$database=new class_database();
		$action = explode('/',$operation['vis_action']); 
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket=new class_ticket($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$departments = $object->get_all_dept();	
		$filter='integration_type=51 AND `integration_id` = '.$action[4];
		list($integration_info, $integration_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);	
		list($dpinf, $department)=$object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);		
        $database->database_disconnect();
		include(VIS_PATH_TEMPLATE.'asterisk_add_new_dialplan.php');
		return true;
    }
	 function asterisk_details($operation){ 
		global $vis_language;
        $operation['view_title']=$vis_language['TXTFLAG'];
        $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.'setting.php');
            $setting_object=new class_setting($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);
			$departments = $setting_object->get_all_dept();	
            $filter='asterisk_id='.$action[4].' ';
			list($number_count, $asterisk_details)=$setting_object->get_asterisk_dialpalns($filter, '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
			
			if($asterisk_details==-1){
				$this->error=$vis_language['MSGINFOMISS'];
				return false;
			}
			$asterisk_details = $asterisk_details[0];
			//$filter='asterisk_id='.$action[4].' ';
           // $key_details = $setting_object->get_twilio_key($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
			list($dpinf, $department)=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA);	
			list($integration_info, $integration_details)=$setting_object->get_integration_setting('integration_type=51 AND is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		
			$filter ='';
            if($asterisk_details['integration_id']!=0){
				$filter1='integration_type=51 AND integration_id='.$asterisk_details['integration_id'];
				list($asterisk_info, $asterisk_intgration)=$setting_object->get_integration_setting($filter1, VIS_STAFF_ID, VIS_LOCATION_AREA);
				
				if($asterisk_intgration[0]['domain_id']!=0){
					$filter .= VIS_TABLE_PREFIX.'domain.domain_id='.$asterisk_intgration[0]['domain_id'].' AND ';
				}
			}
			$filter .=(VIS_TABLE_PREFIX.'department.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.is_enabled=1');
			$departments=$ticket_object->get_department($filter, VIS_STAFF_ID, VIS_LOCATION_AREA, VIS_TABLE_PREFIX.'domain.domain_id');
			$departmentid = $departments[0]['department_id'];
			
            include(VIS_PATH_TEMPLATE.'asterisk_details.php');
            return true;
        }
        else {
            $this->error=$vis_language['MSGINFOMISS'];
            return false;
        }
	}
	###Asterisk
	function new_tax_rule_setting($operation)
	{
		global $vis_language;
		$database = new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'billing.php');
        $billing_object=new class_billing($database);
        $domain=$set_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $domain=$domain[1];
        if($domain==-1) return false;
        $operation['vis_domain']=($operation['vis_domain_id'])?$operation['vis_domain_id']:$domain[0]['domain_id'];
        $tax_details=$billing_object->get_tax_setting($operation, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $tax_info = $tax_details[0];
        list($tax_cnt,$tax_details1)=$billing_object->get_tax('is_enabled=1 and domain_id='.$operation['vis_domain'], VIS_STAFF_ID, VIS_LOCATION_AREA,'');
        $tax_info1 = $tax_details1;
        $database->database_disconnect();
        if(isset($operation['vis_domain_id']) && $operation['vis_domain_id']!='')
        include(VIS_PATH_TEMPLATE.'tax_setting.php');
        else
		include(VIS_PATH_TEMPLATE.'tax_rule_setting.php');
        return true;
	}
	### Task Automation
	function view_autotask($operation) {
        global $vis_language;
        $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']:'';
        $operation['view_title']=$vis_language['TXTTASKAUTO'];
		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['autotask_name like "%'] = $data['vis_title'].'%"';
			if($data['vis_status']!='')$and_operations['is_enabled="'] = $data['vis_status'].'"';
		}
       return $this->autotask_display($operation,$and_operations, '', '', $page, $sort_by);
    }
	function autotask_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $database=new class_database();
        if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'autotask.';
                $filter.=$key.$value." and ";
            }
            $filter=substr($filter, 0, -4);
            $filter.=") ";
        }
        if($or_conditions!="" && count($or_conditions)!=0) {
            $filter.="(";
            foreach($or_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'autotask.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=") ";
        }
        $staff=new class_staff($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $object=new class_setting($database);
		$object->remove_dummy_data(VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($view_info, $view_details)=$staff->get_ticket_view(VIS_STAFF_ID, VIS_LOCATION_AREA);
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        list($autotask_info, $autotask_details)=$object->get_autotask($filter, $limit, $page, $sort_by, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count']=($autotask_info['total']==0)?0:ceil($autotask_info['total']/$view_info['page_count']);
        $database->database_disconnect();
        $autotask_info['autotask_count']=(!$autotask_details || $autotask_details==-1)?0:count($autotask_details);
        $autotask_info['page']=$page;
        $view_info['view_count']=count($view_details);
        $view_info['view_title']=$vis_language['TXTTASKAUTO'];
        $operation['vis_operation']='new_autotask';
		$operation['vis_current_operation']='view_autotask';
		$operation['vis_current_module']='setting';
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'autotask_list.php');
			$autotask_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'=>$autotask_info['total'], 'paging' => $select, 'list'=> $autotask_list));
		}else
        include(VIS_PATH_TEMPLATE.'autotask.php');
        return true;
    }
	### Automation task - Edit / Updates
	function autotask_details($operation) {
		global $vis_language;
 	    $operation['view_title']=$vis_language['TXTTASKAUTO'];
        $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');
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'subsetting.php');
            $ticket=new class_ticket($database);
            $client=new class_client($database);
            $staff=new class_staff($database);
            $setting=new class_setting($database);
            $sub_object=new class_subsetting($database);
            list($autotask_info, $autotask_details)=$setting->get_autotask('autotask_id='.$action[4],'',0,0, VIS_STAFF_ID, VIS_LOCATION_AREA);
			$autotask_details=$autotask_details[0];
			list($autosubtask_info, $autosubtask_details)=$setting->get_autosubtask_details('autotask_flag=1 and autotask_id='.$action[4],'',VIS_STAFF_ID, VIS_LOCATION_AREA);
			if($autotask_details!='')
            {
            $autotask_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(',', $autotask_details['event']);
            for($i=0;$i<count($event);$i++) $autotask_event[$event[$i]]=1;
            $autotask_criteria=$setting->get_autotask_criteria($action[4], 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];
            for($i=0;$i<count($domains);$i++){
				$domain_list[]=$domains[$i]['domain_id'];
				$domain_ids=implode(",",$domain_list);
			}
			$user_groups=$client->get_client_group('is_enable=1 and (domain_id in ('.$domain_ids.') or domain_id=0 )', VIS_STAFF_ID, VIS_LOCATION_AREA);
            $departments=$sub_object->get_department(VIS_TABLE_PREFIX.'department.is_enabled=1','','','', VIS_STAFF_ID, VIS_LOCATION_AREA); $departments=$departments[1];
            list($sla_count,$sla)=$setting->get_sla(VIS_TABLE_PREFIX.'sla.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($schedule_count,$schedule)=$setting->get_schedule(VIS_TABLE_PREFIX.'schedule.is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
            list($etemplate_count,$etemplate)=$setting->get_etemplate('is_enabled=1 and language=1','',0,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($staffgroup_info, $staff_group)=$setting->get_staffgroup(VIS_TABLE_PREFIX.'staff_group.is_enabled=1', '', 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) {
			$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');
			$flags=$ticket->get_flags_list(VIS_STAFF_ID, VIS_LOCATION_AREA, 'is_enabled=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');
			list($category_info,$ticket_category)=$setting->get_ticket_category_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($subcategory_info,$ticket_subcategory)=$setting->get_ticket_subcategory_list(VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($item_info,$ticket_item)=$setting->get_ticket_item_list(VIS_TABLE_PREFIX.'ticket_item.is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			list($level_info,$ticket_level)=$setting->get_ticket_level_list('is_enabled=1','',VIS_STAFF_ID, VIS_LOCATION_AREA,'');
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			} 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', 'is_enabled=1');	$label_details=$label_details[1];
			$channel_details=$setting->get_properties('get_channel', 'is_enabled=1');$channel_details=$channel_details[1];
			$ticket_category=$setting->get_properties('get_ticket_category', 'is_enabled=1');$ticket_category=$ticket_category[1];
			$ticket_subcategory=$setting->get_properties('get_ticket_subcategory', VIS_TABLE_PREFIX.'ticket_subcategory.is_enabled=1');$ticket_subcategory=$ticket_subcategory[1];
			$ticket_item=$setting->get_properties('get_ticket_item', VIS_TABLE_PREFIX.'ticket_item.is_enabled=1');$ticket_item=$ticket_item[1];
			$ticket_level=$setting->get_properties('get_ticket_level', 'is_enabled=1');$ticket_level=$ticket_level[1];
			$location=$setting->get_locations(" AND (".VIS_TABLE_PREFIX."itil_location.department_access = 0)",0, -1, '', VIS_STAFF_ID);
			}
            $database->database_disconnect();
            include(VIS_PATH_TEMPLATE.'autotask_details.php');
            return true;
			}
            else
			{
				echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
				return false;
			}
			//}
    }	
	## Delete autotask 
	    function get_autotask_delete($operation){
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETETASK'];
        $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':'setting', 'vis_operation':'delete_autotask', 'vis_autotask_id':".$operation['vis_autotask_id'].", 'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
}
?>
