<?php
if(!defined('_VIS_')) die('Error: Call from undefined function');
class selfhelp {
    var $error;

    function view_selfhelp($operation, $area=0) { 
        global $vis_language;	
        $quick_insert=(isset($operation['vis_ticket_id']))?$operation['vis_ticket_id']:-1;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $staff=new class_staff($database);		
        $object=new class_selfhelp($database);
        $setting_object=new class_ticket($database);
        $domains=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($domains!= -1)
        {
			for($cnt =0 ;$cnt < count($domains) ; $cnt++) 
			{ 
				$domain_access .= $domains[$cnt]['domain_id'].',';
			};
			$domain_access=substr($domain_access,0,-1);
        }
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(!isset($operation['vis_domain_id'])) $domain_id=$action[4]; else  $domain_id=$operation['vis_domain_id'];
        $domain=$domain_id;
        list($articles_info, $articles)=$object->get_article( VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.') and '.VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA);	
        list($recent_articles_info, $selfhelp)=$object->get_article('is_stick=0 and '. VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')', VIS_DOMAIN, VIS_LOCATION_AREA);
		$order = VIS_TABLE_PREFIX.'selfhelp_article.entry_date '.DESC .','.VIS_TABLE_PREFIX.'selfhelp_article.article_id '. DESC;
		list($recent_articles_info, $recent_articles)=$object->get_article(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and '. VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.') and '.VIS_TABLE_PREFIX.'selfhelp_article.language=1 ', VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',$order);
		list($featured_articles_info, $selfhelp)=$object->get_article('is_stick=1 and domain_id='.VIS_DOMAIN, VIS_DOMAIN, VIS_LOCATION_AREA);
		list($featured_articles_info, $featured_articles)=$object->get_article(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and  '. VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.') and is_stick=1  and '.VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id=0', VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',$order);
		$comments_info=$object->get_comment(VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')','','', VIS_STAFF_ID, VIS_LOCATION_AREA,'',1);	
		$categories_info=$object->get_category(VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
        $attachmentids = isset($operation['attachment_ids']) ? $operation['attachment_ids'] : '';
		
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTSELFHELP'];
		$operation['vis_current_operation']='view_selfhelp';
		$operation['vis_current_module']='selfhelp';		
        $operation['vis_message']=$vis_language['TXTADDARTICLE'];
		$operation['vis_operation1']='view_selfhelp';			
		$operation['vis_operation2']='view_articles';
		$operation['vis_operation3']='view_categories';
		$operation['vis_operation4']='view_comments';
		
        if(VIS_LOCATION_AREA==2){
          /*  if($quick_insert!=-1) include(VIS_PATH_TEMPLATE.'selfhelp_quick.php');
            else*/
			if($area==0)
				include(VIS_PATH_TEMPLATE.'selfhelp_summary.php');						 
            elseif($area==1) include(VIS_PATH_TEMPLATE.'selfhelp_list.php');
        }
        return true;
    }
	function article_display($operation, $and_conditions, $or_conditions, $filter='', $page=0, $sort_by='') {
        global $vis_language;
		if($and_conditions!='' && count($and_conditions)!=0) {
            $filter="(";
            foreach($and_conditions as $key => $value) {
                if(!strstr($key, '.')) $filter.=VIS_TABLE_PREFIX.'selfhelp_category.';
                $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.'selfhelp_category.';
                $filter.=$key.$value." or ";
            }
            $filter=substr($filter, 0, -3);
            $filter.=")";
        }
        $data=parse_form_array($operation['vis_action']);
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        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');
        $staff=new class_staff($database);		
        $object=new class_selfhelp($database);
	    $setting_object=new class_ticket($database);
		
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $domains=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($categories_info,$categories)=$object->get_category('avis_selfhelp_category.is_enabled = 1 ', VIS_STAFF_ID, VIS_LOCATION_AREA);
		 if($domains!= -1)
        {
			for($cnt =0 ;$cnt < count($domains) ; $cnt++) 
			{ 
				$domain_access .= $domains[$cnt]['domain_id'].',';
			};
			$domain_access=substr($domain_access,0,-1);
        }
		if(!isset($operation['vis_domain'])) $domain_id=$action[4]; else  $domain_id=$operation['vis_domain'];
        $domain=$domain_id;
        $selfhelp=$object->get_selfhelp( VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.') and '.VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1', 0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
        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['criteria']) && $operation['criteria']!='')
		{	
			$filter=' (article_title like "%'.addslashes($operation['criteria']).'%" or article_keywords LIKE "%'.addslashes($operation['criteria']).'%") ';
			$criteria = $operation['criteria'];
        }  
        if(isset($operation['vis_form']) && $operation['vis_form']=='vis_view_selfhelp_form')
        {
			$filter=VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')';
		}
		if(isset($operation['vis_featured_article']) && $operation['vis_featured_article']==1 || $action[4] == 'vis_featured_article')
		{
			$filter=VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.') and '.VIS_TABLE_PREFIX.'selfhelp_article.is_stick=1';
		}
		else if($action[4]!='' || isset($action[4]))
		$filter=VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')';
		
		if($filter==''){
			$filter=$filter.VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id=0 ';
		}else{
			$filter=VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id=0 and '.$filter;
		}
		list($articles_info, $articles)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA,$limit,' entry_date desc ',$domains); 
	    $view_info['page_count']=($articles_info['total']==0)?0:ceil($articles_info['total']/$view_info['page_count']);
		$articles_info['articles_count']=(!$articles || $articles==-1)?0:count($articles);	
	    $articles_info['page']=$page;	
		/*if($page==$view_info['page_count'])
		{
				$operation['vis_page']=0;
				return $this->view_articles($operation);
		}	*/
        $attachmentids = isset($operation['attachment_ids']) ? $operation['attachment_ids'] : '';
        $database->database_disconnect();
		$operation['vis_domain_id'] = $operation['vis_domain'];
        $operation['view_title']=$vis_language['TXTARTICLES'];
        $operation['vis_operation']='new_article';		
		$operation['vis_current_operation']='view_articles';
		$operation['vis_current_module']='selfhelp';
		$operation['vis_operation1']='view_selfhelp';			
		$operation['vis_operation2']='view_articles';
		$operation['vis_operation3']='view_categories';
		$operation['vis_operation4']='view_comments';					
        
		if((isset($operation['vis_filter_enable']) && $operation['vis_filter_enable']==1)){
			ob_start();
			include(VIS_PATH_TEMPLATE.'article_list.php');
			$article_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'=>$articles_info['total'], 'paging' => $select, 'list'=> $article_list));
		}
		else{
        if(VIS_LOCATION_AREA==2){
			 include(VIS_PATH_TEMPLATE.'articles.php');
         }
		}
        return true;
	}
	function view_articles($operation) {
        global $vis_language;	
        $quick_insert=(isset($operation['vis_ticket_id']))?$operation['vis_ticket_id']:-1;
        $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.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $staff=new class_staff($database);		
        $object=new class_selfhelp($database);
        $setting_object=new class_ticket($database);
		$database->database_disconnect();
		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['avis_selfhelp_article.article_title like "%'] = addslashes($data['vis_title']).'%"';
		if($data['vis_domain']!='')$and_operations['domain_id="'] = $data['vis_domain'].'"';
		if($data['vis_category']!='')$and_operations['selfhelp_id="'] = $data['vis_category'].'"';
		if($data['vis_status']!='')$and_operations['avis_selfhelp_article.is_enabled="'] = $data['vis_status'].'"';
		
        }
        return $this->article_display($operation,$and_operations, '', '', $page, $sort_by);
		
    }
	function view_comments($operation) { 
        global $vis_language;	
        $quick_insert=(isset($operation['vis_ticket_id']))?$operation['vis_ticket_id']:-1;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $staff=new class_staff($database);		
        $object=new class_selfhelp($database);
        $setting_object=new class_ticket($database);
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $domains=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if(!isset($operation['vis_domain'])) $domain_id=$action[4]; else  $domain_id=$operation['vis_domain'];
		if($domains!= -1)
        {
			for($cnt =0 ;$cnt < count($domains) ; $cnt++) 
			{ 
				$domain_access .= $domains[$cnt]['domain_id'].',';
			};
			$domain_access=substr($domain_access,0,-1);
        }
        $domain=$domain_id;
        //$domain=(isset($operation['vis_domain']) && is_numeric($operation['vis_domain']))?$operation['vis_domain']:$domains[0]['domain_id'];
        $selfhelp=$object->get_selfhelp('domain_id='.$domain, 0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
        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']; 	
        $sort_by=$operation['vis_sorted_by'];
		$filter=(isset($operation['vis_sorted_by']) && !is_numeric($operation['vis_sorted_by']))?$operation['vis_sorted_by']:'';
		if(isset($action[4]) || $action[4]!='')
			$filter= VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.$domain;
		else if(isset($operation['vis_form']) && $operation['vis_form']=='vis_view_selfhelp_form'){		
		if($filter=='')
			$filter=(isset($operation['vis_form']))?VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')':'';
		else	
			$filter=(isset($operation['vis_form']))?$filter.' and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id in ('.$domain_access.')':'';}
		list($comments_info, $comments)=$object->get_comment($filter,$domains,'desc', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		$view_info['page_count']=($comments_info['total']==0)?0:ceil($comments_info['total']/$view_info['page_count']);	
		$comments_info['comment_count']=(!$comments || $comments==-1)?0:count($comments);		
		$comments_info['page']=$page;
		list($approved_comments_info, $approved_comments)=$object->get_comment(VIS_TABLE_PREFIX.'selfhelp_comment.is_approved=1',$domains,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		list($disapproved_comments_info, $disapproved_comments)=$object->get_comment(VIS_TABLE_PREFIX.'selfhelp_comment.is_approved=0',$domains,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		list($spam_comments_info, $spam_comments)=$object->get_comment(VIS_TABLE_PREFIX.'selfhelp_comment.is_spam=1',$domains,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		list($remove_spam_comments_info, $remove_spam_comments)=$object->get_comment(VIS_TABLE_PREFIX.'selfhelp_comment.is_spam=0',$domains,'', VIS_STAFF_ID, VIS_LOCATION_AREA,$limit);
		$quick_view=$object->get_comment_sortng_counts($domains, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $attachmentids = isset($operation['attachment_ids']) ? $operation['attachment_ids'] : '';
        $database->database_disconnect();
		
        $operation['view_title']=$vis_language['TXTCOMMENTS'];
		$operation['vis_current_operation']='view_comments';
		$operation['vis_current_module']='selfhelp';
		$operation['vis_operation1']='view_selfhelp';			
		$operation['vis_operation2']='view_articles';
		$operation['vis_operation3']='view_categories';
		$operation['vis_operation4']='view_comments';					
        if(VIS_LOCATION_AREA==2){
			 include(VIS_PATH_TEMPLATE.'comments.php');
        }
        return true;
    }
	function view_categories($operation) {
        global $vis_language;	
							
        $quick_insert=(isset($operation['vis_ticket_id']))?$operation['vis_ticket_id']:-1;
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $object=new class_selfhelp($database);
        $setting_object=new class_ticket($database);
        $domains=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        if(!isset($operation['vis_domain_id'])) $domain_id=$action[4]; else  $domain_id=$operation['vis_domain_id'];
        $domain=$domain_id;
        $selfhelp=$object->get_selfhelp('domain_id='.$domain, 0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($categories_info, $categories)=$object->get_category('domain_id='.$domain, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$categories_info['categories_count']=(!$categories || $categories==-1)?0:count($categories);
		$parent_category_details=$object->get_category('selfhelp_id='.$selfhelp['parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $parent_category_details=$parent_category_details[1][0];
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
        $language_details = $set_object->get_language('language_id='.$categories['language_id'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $attachmentids = isset($operation['attachment_ids']) ? $operation['attachment_ids'] : '';
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTCATEGORIES'];
		$operation['vis_current_operation']='view_categories';
		$operation['vis_current_module']='selfhelp';
		$operation['vis_operation1']='view_selfhelp';			
		$operation['vis_operation2']='view_articles';
		$operation['vis_operation3']='view_categories';
		$operation['vis_operation4']='view_comments';					
        if(VIS_LOCATION_AREA==2){
			if(isset( $operation['vis_set']) && $operation['vis_set']=='1')
			include(VIS_PATH_TEMPLATE.'parent_list.php');
			else if(isset( $operation['vis_set']) && $operation['vis_set']=='2')
			include(VIS_PATH_TEMPLATE.'clone_cat_list.php');
			else
			 include(VIS_PATH_TEMPLATE.'categories.php');
        }
        return true;	
	}

	function view_selfhelp_group($operation) { 
		global $vis_language;
        if(isset($operation['vis_action']) && $operation['vis_action']!='')
        {
			$is_nofollow=1;
			$data = explode('/',$operation['vis_action']);
			$operation['vis_parent_id'] = $data[4];
		}
		if (isset($operation['vis_sorted_by']) && $operation['vis_sorted_by'] != '') {
            $sort = $operation['vis_sorted_by'];
        } else
            $sort = '';
        $parentid=(isset($operation['vis_parent_id']) && is_numeric($operation['vis_parent_id']))?$operation['vis_parent_id']:0;
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        if(VIS_LOCATION_AREA==1){
			include_once(VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'client.php');
			$object_client = new class_client($database); 
			$filter=VIS_TABLE_PREFIX."client.client_id=".VIS_CLIENT_ID;
			list($client_info, $client_details) = $object_client->get_client($filter); 
			$grp_id=$client_details[0]['group_id'];
			if(VIS_SATELLITE_HELPDESK == 2)
			{$option_domainn_id=$client_details[0]['optionB_domain_id'];}else{$option_domainn_id=$client_details[0]['domain_id'];}
			
		  $filter='is_stick=0 and domain_id='.$option_domainn_id.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE;
			
            list($recent_articles_info, $selfhelp)=$object->get_article($filter, VIS_DOMAIN, VIS_LOCATION_AREA);
			
			
			
            for($i=0;$i<count($selfhelp);$i++) {
                $order=VIS_TABLE_PREFIX.'selfhelp_article.entry_date '.DESC .','.VIS_TABLE_PREFIX.'selfhelp_article.article_id '. DESC;                
            
				if(IS_LOGIN==0)
				{
				  $filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0) and '.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display=""';	

			    }
				else
				{
				  $filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0) and (('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="") or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))';
				}
$recent_articles=array();
                list($recent_articles_info, $recent_articles1)=$object->get_article($filter.' and '.VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_article.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',$order);
				if(IS_LOGIN!=0){
					if(count($recent_articles1)>0){
				for($f=0; $f<count($recent_articles1); $f++){
					$maincat='';
					$maincat=$this->getcategoryfirstid($recent_articles1[$f]['parent_id'],$strt='');
					 list($recent_cat_info, $recent_cat)=$object->get_category(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1  and '.VIS_TABLE_PREFIX.'selfhelp_category.selfhelp_id='.$maincat.' and ('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="" or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))' , VIS_STAFF_ID, VIS_LOCATION_AREA,'');
					
					 if($recent_cat!=-1){$recent_articles[]=$recent_articles1[$f]; }
					}
					}else{
						$recent_articles=$recent_articles1;
						
					}
				}else{
					$recent_articles=$recent_articles1;
				}
					
            }
       
	      $filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)';
	
		  list($featured_articles_info, $selfhelp)=$object->get_article($filter, VIS_DOMAIN, VIS_LOCATION_AREA);
		  
            for($i=0;$i<count($selfhelp);$i++) {
                $order=VIS_TABLE_PREFIX.'selfhelp_article.entry_date '.DESC .','.VIS_TABLE_PREFIX.'selfhelp_article.article_id '. DESC;                
                   
                 if(IS_LOGIN==0)
				{
					$filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0) and '.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display=""';

				}
				else
				{	
			          $filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0) and '.' ('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="" or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))';
				}				   
				list($featured_articles_info, $featured_articles1)=$object->get_article($filter.' and '.VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and  is_stick=1 and '.VIS_TABLE_PREFIX.'selfhelp_article.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_STAFF_ID, VIS_LOCATION_AREA,'',$order); 

                $featured_articles=array();				
				if(IS_LOGIN!=0){
					if(count($featured_articles1)>0){
				for($f=0; $f<count($featured_articles1); $f++){
					$maincat='';
					$maincat=$this->getcategoryfirstid($featured_articles1[$f]['parent_id'],$strt='');
					 list($recent_cat_info, $recent_cat)=$object->get_category(VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1  and '.VIS_TABLE_PREFIX.'selfhelp_category.selfhelp_id='.$maincat.' and ('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="" or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))' , VIS_STAFF_ID, VIS_LOCATION_AREA,'');
					
					 if($recent_cat!=-1){$featured_articles[]=$featured_articles1[$f]; }
					}
					}else{
						$featured_articles=$featured_articles1;
						
					}
				}else{
					$featured_articles=$featured_articles1;
				}
            } 
        }
	 	
        if(VIS_LOCATION_AREA==1){
			$page=(isset($operation['vis_page']) && is_numeric($operation['vis_page']))?$operation['vis_page']:0;
			$limit=($page*10).',10';
		}
	
	     	if(IS_LOGIN==0)
			{
			$filter=' display_status=0 and '.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display=""';
			}
			 elseif(IS_LOGIN==1)
			{
			 $filter=' display_status!=2 and ('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="" or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))';
			}
		
        $selfhelp=$object->get_selfhelp($filter.' and is_enabled=1', $parentid, -1, true, VIS_DOMAIN, VIS_LOCATION_AREA,$limit,$sort);
		
		for($i=0;$i<count($selfhelp);$i++){
            for($j=0;$j<count($selfhelp[$i]['subcat']);$j++) {
                $ids=$object->get_selfhelpcategoryids($selfhelp[$i]['subcat'][$j]['selfhelp_id'],VIS_DOMAIN, VIS_LOCATION_AREA); 
                $idsarr=explode(',',trim($ids,','));
                $count=count($idsarr);
                for($m=0;$m<$count;$m++) if($idsarr[$m]=='') unset($idsarr[$m]); // echo "<pre>";print_r($idsarr);
                list($category_count,$category_details)=$object->get_category('selfhelp_id='.$data[4], VIS_STAFF_ID, VIS_LOCATION_AREA); 
                $category_details=$category_details[0];
                list($parent_count,$parent_category_details)=$object->get_category('selfhelp_id='.$category_details['parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
                $parent_category_details=$parent_category_details[0];   
                $is_enabled=' and is_enabled=1';				
                $selfhelp[$i]['subcat'][$j]['toatlarticlecount']=$object->get_selfhelparticlecount(implode(',',$idsarr),VIS_DOMAIN, VIS_LOCATION_AREA,$is_enabled);
            }
        }
        if(VIS_LOCATION_AREA==1){
			$total_count=$selfhelp[0]['article'][0]['total'];
			$page_count=($total_count==0)?0:ceil($total_count/10);
		}
        $database->database_disconnect();
        if(VIS_LOCATION_AREA==1) {
			$vis_title=$vis_language['TXTSELFHELP'];	
			$breadcrumb['Home'] = 'index.php';
			$breadcrumb[$vis_language['TXTSELFHELP']] = '?/selfhelp/categories';
        	if((IS_LOGIN==0 && VIS_DEFAULT_HOME_MODULE != $operation['vis_module']) || (IS_LOGIN==1 && VIS_DEFAULT_HOME_MODULE_AFTER_LOGIN != $operation['vis_module']))$breadcrumb[$vis_language['TXTSELFHELP']] = '';
			if($operation['vis_parent_id']!=''){
				if((IS_LOGIN==0 && VIS_DEFAULT_HOME_MODULE != $operation['vis_module']) || (IS_LOGIN==1 && VIS_DEFAULT_HOME_MODULE_AFTER_LOGIN != $operation['vis_module']))$breadcrumb[$vis_language['TXTSELFHELP']] = '?/selfhelp/categories';
				if($parent_category_details['parent_id']!=0)$breadcrumb['..'] = '';
				if(!empty($parent_category_details))$breadcrumb[$parent_category_details['selfhelp_title']] = '?/selfhelp/categories/'.$parent_category_details['selfhelp_title'].'/'.$parent_category_details['selfhelp_id'];
				$breadcrumb[$data[3]] = '';
			}
			
            $header_title=($parentid==0)?$vis_language['TXTSELFHELP']:$selfhelp[0]['selfhelp_title'];
            $max_article_count=3;
            $url_rewrite=defined('VIS_SELFHELP_URL_REWRITE')?VIS_SELFHELP_URL_REWRITE:0;
            if(isset($operation['vis_sorted_by'])){
					include(VIS_PATH_TEMPLATE.'selfhelp_category.php');
			}
			else {
				if(!defined('IS_WHMCS')){ if(!isset($operation['vis_page']) && $operation['vis_page']=='') include(VIS_PATH_TEMPLATE.'header.php');}
				else echo '<link href="'.VIS_PATH_STYLE.'vis_style.css" rel="stylesheet" />';
				include(VIS_PATH_TEMPLATE.'selfhelp_category.php');
				if(!isset($operation['vis_page']) && $operation['vis_page']=='')
				if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'footer.php');
			}
        }
        return true;
    }
    function refresh_category($operation) {
        return $this->view_selfhelp($operation, 1);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $selfhelp=$object->get_selfhelp('',0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $quick_insert = (isset($operation['vis_ticket_id']))?$operation['vis_ticket_id']:'0';
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_list.php');
        return true;
    }

    function view_article($operation) {
		global $vis_language;	
		if(isset($operation['vis_action']) && $operation['vis_action']!='')
        {
			$data = explode('/',$operation['vis_action']);
		}
		if((isset($data['4'])  || isset($data['5'])) && ($data['4']=='success' || $data['5']=='success'))
		{
			$is_nofollow=1;
			$operation['message']='<div class="vis_message">'.$vis_language['MSGSUCCOPRT'].'</div>';
		}
		if(is_numeric($data['4']))
		{
				$operation['vis_static_url']=1;
		}else   $operation['vis_static_url']=0;
		
        $operation['view_title']=$vis_language['TXTARTICLES'];		
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
        $clobject=new class_client($database);
        $staff_object=new class_staff($database);
        $staff=$staff_object->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);		
        if(VIS_LOCATION_AREA==1) {
            list($clinfo, $client)=$clobject->get_client('client_id='.VIS_CLIENT_ID, '', 0, '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
        }
        $object=new class_selfhelp($database);
								
							
		 
		$spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $data['vis_article_id']=isset($operation['vis_article_id'])?$operation['vis_article_id']:$action[4];
		
		// settype($action[4], 'integer');
        // if(isset($operation['vis_article_id'])) settype($operation['vis_article_id'], 'integer');
        // $filter='article_id='.((isset($operation['vis_article_id']) && $operation['vis_article_id']!='')?$operation['vis_article_id']:$action[4]);
        
        if(VIS_LOCATION_AREA==1) 
         {
			 $filter='article_url='.(isset($operation['vis_article_url'])?'"'.$operation['vis_article_url'].'"':'"'.$action[3].'"').' and language='.VIS_LANGUAGE;
			 if($data['vis_article_id']!='' && $action[4]!='success')
			 {
				 $filter.=' and article_id='.$data['vis_article_id'];
			 }
			 
		 }
         if(VIS_LOCATION_AREA==2) 
         {
			$filter = ' article_id='.((isset($operation['vis_article_id']) && $operation['vis_article_id']!='')?$operation['vis_article_id']:$action[4]);
		 }
		list($articles_info, $article)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);   
        
		//$data['vis_article_id']=$operation['vis_article_id'];
		//$data['vis_article_id']=$action[4];
		$data['vis_article_url']=$action[3];
		$data['vis_article_id']=$article[0]['article_id'];
		
		
	   if($article[0]['author_type']==0)
        {
			$authorDetails=$staff_object->get_staff('staff_id='.$article[0]['author_id'], $article[0]['author_id'], VIS_LOCATION_AREA);
			$authorDetails=$authorDetails[0]['image_name'];
		}
        else
        {
			$authorDetails=$clobject->get_client('client_id='.$article[0]['author_id'], '', 0, '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
			$authorDetails=$authorDetails[1][0]['image_path'];
		}
        if($article==-1 || (VIS_LOCATION_AREA==1 && $article[0]['display_status']==1 && VIS_CLIENT_ID==0) || (VIS_LOCATION_AREA==1 && $article[0]['display_status']==2)) {
            if(VIS_LOCATION_AREA==1) {
                if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
                else echo '<link href="'.VIS_PATH_STYLE.'vis_style.css" rel="stylesheet" />';
                if((VIS_LOCATION_AREA==1 && $article[0]['display_status']==1 && VIS_CLIENT_ID==0) || (VIS_LOCATION_AREA==1 && $article[0]['display_status']==2)) echo '<script> $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html("'.$vis_language['MSGACCSSDND'].'");</script>';
                else echo '<div class="vis_error_message"><br/>'.$vis_language['TXTNOMATCHFOUND'].'<br/><br/></div>';
                if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'footer.php');
                break;
            }
        }
		list($parent_count,$parent_category_details)=$object->get_category('selfhelp_id='.$article[0]['parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA); 
		$parent_category_details=$parent_category_details[0]; 
		
		
		$articles=$article[0];
		//$articalid=($articles['art_parent_id']==0)?((isset($operation['vis_article_id']) && $operation['vis_article_id']!='')?$operation['vis_article_id']:$action[4]):$articles['art_parent_id'];
		$articalid=($articles['art_parent_id']==0)?((isset($operation['vis_article_id']) && $operation['vis_article_id']!='')?$operation['vis_article_id']:$data['vis_article_id']):$articles['art_parent_id'];
		
        $filter='('.VIS_TABLE_PREFIX.'selfhelp_article.article_id='.$articalid.' or '.VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id='.$articalid.') and is_approved=1 and is_spam=0';
        list($comments_info, $comment)=$object->get_comment($filter, '', 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $article=$article[0];
        $setting_obj=new class_setting($database);
        $filter='module_id=4 and title="vis_captcha" and domain_id='.VIS_DOMAIN;
        $setting_details=$setting_obj->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $filter='module_id=4 and title="vis_allow_comments" and domain_id='.VIS_DOMAIN;
        $setting_details_for_comment=$setting_obj->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $filter='module_id=4 and title="vis_allow_ratings" and domain_id='.VIS_DOMAIN;
        $setting_details_for_rating=$setting_obj->get_settings($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $attachment=$object->get_attachment('parent_id='.$article['article_id'].' and parent_type=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		//
		list($articles_count, $check_article_rating_setting)= $object->get_article(VIS_TABLE_PREFIX.'selfhelp_article.article_url='.'"'.$article['article_url'].'" and article_id='.$data['vis_article_id'].'', VIS_DOMAIN, VIS_LOCATION_AREA);	
		//							
		list($right_articles_info, $right_selfhelp)=$object->get_article(VIS_TABLE_PREFIX.'selfhelp_article.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_article.parent_id='.$article['parent_id'].' and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_DOMAIN, VIS_LOCATION_AREA);
							
								
        $database->database_disconnect();
		$operation['vis_operation1']='view_selfhelp';
        if(VIS_LOCATION_AREA==1) {
									
            $header_title=$article['article_title'];
            $vis_title=$vis_language['TXTSELFHELP'];	
			$breadcrumb['Home'] = 'index.php'; 
			$breadcrumb[$vis_language['TXTSELFHELP']] = '?/selfhelp/categories';
			if((IS_LOGIN==0 && VIS_DEFAULT_HOME_MODULE != $operation['vis_module']) || (IS_LOGIN==1 && VIS_DEFAULT_HOME_MODULE_AFTER_LOGIN != $operation['vis_module'])) $breadcrumb[$vis_language['TXTSELFHELP']] = '?/selfhelp/categories';
			if(!empty($parent_category_details))$breadcrumb[$parent_category_details['selfhelp_title']] = '?/selfhelp/categories/'.$parent_category_details['selfhelp_title'].'/'.$parent_category_details['selfhelp_id'];
			$breadcrumb[$article['article_title']] = '';
            if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
            else echo '<link href="'.VIS_PATH_STYLE.'vis_style.css" rel="stylesheet" />';
        }
		 
		 
        include(VIS_PATH_TEMPLATE.'selfhelp_article.php');
		
		
        if(VIS_LOCATION_AREA==1) {
            if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'footer.php');
        }
        return true;
    }

    function selfhelp_search($operation) {
		$is_nofollow=1;
        global $vis_language;
            $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
            $object=new class_selfhelp($database);
			 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'forum.php');
            $forum_object=new class_forum($database);
			
			
            if(VIS_LOCATION_AREA==2)
                $filter = '(article_title like "%'.addslashes($operation['vis_search_text']).'%" or content like "%'.addslashes($operation['vis_search_text']).'%") and domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN) ;
            else {
     			    include_once(VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'client.php');
					$object_client = new class_client($database); 
					$filter=VIS_TABLE_PREFIX."client.client_id=".VIS_CLIENT_ID;
					list($client_info, $client_details) = $object_client->get_client($filter); 
					
					$grp_id=$client_details[0]['group_id'];
					
				// $art_filter=(IS_LOGIN)?'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)':'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)'; //previous
				
				if(IS_LOGIN){
					//$art_filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)'
					
					$art_filter=' display_status!=2 and ('.VIS_TABLE_PREFIX.'selfhelp_category.client_display="" and '.VIS_TABLE_PREFIX.'selfhelp_category.org_display="" or (find_in_set("'.VIS_CLIENT_ID.'",'.VIS_TABLE_PREFIX.'selfhelp_category.client_display) or find_in_set("'.$grp_id.'",'.VIS_TABLE_PREFIX.'selfhelp_category.org_display)))';
				}
				else{
					$art_filter='('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)'; 
			        }
				 
                 $filter = $art_filter.' and (article_title like "%'.addslashes($operation['vis_search_text']).'%" or content like "%'.addslashes($operation['vis_search_text']).'%") and domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN) . ' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE;
				
				 $forum_filter = '(title like "%'.addslashes($operation['vis_search_text']).'%" or '.VIS_TABLE_PREFIX.'forum_topic.description like "%'.addslashes($operation['vis_search_text']).'%") and domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN).' and '.VIS_TABLE_PREFIX.'forum_topic.is_approved=1 and '.VIS_TABLE_PREFIX.'forum_topic.is_spam=0';
			}
            if((VIS_HEAD_MENU_SELFHELP==1 || (VIS_HEAD_MENU_SELFHELP==2 && IS_LOGIN)) && VIS_MODULE_ACCESS_SELFHELP==1) list($articles_info, $selfhelp)=$object->get_article('display_status!=2 and '.$filter, VIS_DOMAIN, VIS_LOCATION_AREA);
			 $forumTopic = -1;			 
		     if((VIS_HEAD_MENU_FORUM==1 || (VIS_HEAD_MENU_FORUM==2 && IS_LOGIN)) && VIS_MODULE_ACCESS_FORUM==1)  list($forumInfo, $forumTopic) = $forum_object->get_topic($forum_filter,'', VIS_DOMAIN, VIS_LOCATION_AREA);
			
            $ticket_details=-1;
            if(VIS_LOCATION_AREA==1 && VIS_CLIENT_ID!=0 && VIS_HEAD_MENU_VIEWTICKET==1 && (VIS_VIEW_TICKET==1 || VIS_VIEW_SELFTICKET==1 || VIS_REPLY_TICKET==1)) {
                include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
                $ticket_object=new class_ticket($database);
                include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');
                $client_object=new class_client($database);
                //$filter = '(subject like "%'.addslashes($operation['vis_search_text']).'%" or ticket_hash like "%'.addslashes($operation['vis_search_text']).'%") and '.VIS_TABLE_PREFIX.'ticket.domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN);
                
                list($client_info, $clientdetails)=$client_object->get_client('client_id='.VIS_CLIENT_ID, '', 0, '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
                 $clientdetails=$clientdetails[0];
                 if($clientdetails['is_manager']==1 )
					{
				
				  $filter = '(subject like "%'.addslashes($operation['vis_search_text']).'%" or ticket_hash like "%'.addslashes($operation['vis_search_text']).'%") and '.VIS_TABLE_PREFIX.'ticket.domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN).' and  ('.VIS_TABLE_PREFIX.'client.group_id='.$clientdetails['group_id'];
						//$is_manager=$clientdetails['is_manager'];
					}
					else
					$filter = '(subject like "%'.addslashes($operation['vis_search_text']).'%" or ticket_hash like "%'.addslashes($operation['vis_search_text']).'%") and '.VIS_TABLE_PREFIX.'ticket.domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN);
					
                
                if(VIS_VIEW_TICKET==0 && VIS_VIEW_SELFTICKET==0 && VIS_REPLY_TICKET==0) {
                    include(VIS_PATH_TEMPLATE.'header.php');
                    echo '<script> $("#vis_submit_err_div").show(); $("#vis_submit_err_div").html("'.$vis_language['MSGACCSSDND'].'");</script>';
                    include(VIS_PATH_TEMPLATE.'footer.php');
                    break;
                }elseif((VIS_VIEW_TICKET==1 || VIS_REPLY_TICKET==1) && VIS_VIEW_SELFTICKET==0) {
					
                    $parent=(VIS_CLIENT_PARENT==0 || VIS_CLIENT_PARENT==-1)?VIS_CLIENT_ID:VIS_CLIENT_PARENT;
                    $client='';
                    $client_details=$client_object->get_client_list('parent_id='.$parent, '', 0, '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
                    if($client_details!=-1) for($i=0;$i<count($client_details);$i++) if($client_details[$i]['client_id']!=VIS_CLIENT_ID) $client.=$client_details[$i]['client_id'].',';
                    if($client!='') $filter.=' and is_deleted=0 and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.client_id in ('.$client.$parent.')';
                    else $filter.=' and is_deleted=0 and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.client_id='.$parent;
                }
                elseif((VIS_VIEW_TICKET==1 || VIS_REPLY_TICKET==1) && VIS_VIEW_SELFTICKET==1) {
					
                    $parent=(VIS_CLIENT_PARENT==0 || VIS_CLIENT_PARENT==-1)?VIS_CLIENT_ID:VIS_CLIENT_PARENT;
                    $client='';
                    $client_details=$client_object->get_client_list('parent_id='.$parent, '', 0, '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
                    if($client_details!=-1) for($i=0;$i<count($client_details);$i++) $client.=$client_details[$i]['client_id'].',';
                    if($client!=''){
						if($clientdetails['is_manager']==1 ){ $filter.=' or '.VIS_TABLE_PREFIX.'ticket.client_id in ('.$client.$parent.')) and is_deleted=0 and draft_id=0';}
						 else $filter.=' and is_deleted=0 and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.client_id in ('.$client.$parent.')';
						}
                 
                    else {if($clientdetails['is_manager']==1 ){ $filter.=' or '.VIS_TABLE_PREFIX.'ticket.client_id='.VIS_CLIENT_ID.')  and is_deleted=0 and draft_id=0 ';}
						else $filter.='  and is_deleted=0 and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.client_id='.VIS_CLIENT_ID;}
                }
                else $filter.=' and is_deleted=0 and draft_id=0 and '.VIS_TABLE_PREFIX.'ticket.client_id='.VIS_CLIENT_ID;
                list($ticket_info, $ticket_details)=$ticket_object->get_ticket($filter, '', '', '', VIS_CLIENT_ID, VIS_LOCATION_AREA);
            }
            $header_title=$vis_language['TXTSEARCH'];
            if(VIS_LOCATION_AREA==1){
				$vis_title=$vis_language['TXTSEARCHRESULT'];	
				$breadcrumb['Home'] = 'index.php'; 
				$breadcrumb[$vis_language['TXTSEARCHRESULT']] = '';
			}
            if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
            else echo '<link href="'.VIS_PATH_STYLE.'vis_style.css" rel="stylesheet" />';
            include(VIS_PATH_TEMPLATE.'article_list.php');
            if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'footer.php');
    }

    function add_quick_article($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($articles_info, $article)=$object->get_article('article_id='.$operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        echo $article[0]['content'];
        return true;
    }

    function view_category($operation) {
        global $vis_language;	
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $operation['vis_category_id']=($operation['vis_category_id']!='')?$operation['vis_category_id']:$action[4];	
        $operation['view_title']=$vis_language['TXTCATEGORIES'];		
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $language_details = $setting_object->get_language('is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $language_details =$language_details[1];
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $category=$category[0];
		
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');

		$client_object=new class_client($database);
		
		$filter=' (domain_id='.$operation['vis_domain_id'].' or domain_id=0 ) and is_enable=1';
		
		$client_group=$client_object->get_client_group($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$clientDisplay =$category['client_display'];
		
		if(substr($clientDisplay,-1)==',')
		{
		$clientDisplay=substr($clientDisplay,0,-1);
		}
		
		$clientids=explode(',',$clientDisplay);
		
	    $filter=VIS_TABLE_PREFIX.'client.client_id in ('.$clientDisplay.')';
		list($client_info, $client_details) = $client_object->get_client($filter);
				
        list($categories_info, $parent_category)=$object->get_category('domain_id='.$category['domain_id'].' and selfhelp_id!='.$operation['vis_category_id'].' and is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $parent_category_details=$object->get_category('selfhelp_id='.$category['parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $parent_category_details=$parent_category_details[1][0];
								$cat_lang=$setting_object->get_translation(25, 'data_id='.$operation['vis_category_id'],VIS_STAFF_ID, VIS_LOCATION_AREA);
								list($language_info,$language_details1)=$setting_object->get_language('is_custom=1 and is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
		$operation['vis_operation1']='view_selfhelp';			
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_category.php');
        return true;
    }

    function add_category($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
		
		if(!empty($data['vis_staff_team']) && $data['vis_staff_team']!="")
		{  $org_count=count($data['vis_staff_team']);
	       $org_ids="";
	       for($i=0;$i<$org_count;$i++)
		   {
			   if($i==($org_count-1))
			   {
				$org_ids.=$data['vis_staff_team'][$i];   
			   }
			   else
			   {
				   $org_ids.=$data['vis_staff_team'][$i].",";   
			   }
		   }
			$data['organisation_ids']=$org_ids;
		}
		
        if(!isset($data['vis_category_title']) || trim($data['vis_category_title'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        $database=new class_database();
        $data['vis_category_title'] = preg_replace('/\s+/', ' ',trim($data['vis_category_title']));
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $ret=$object->add_category($data, VIS_STAFF_ID, VIS_LOCATION_AREA); 
        $operation['vis_current_operation']='view_categories';
		$operation['vis_current_module']='selfhelp';			
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Added new solution category ".$data['vis_category_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTCATEGORIES'].'/'.$operation['vis_domain_id'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function update_category($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
		
		if(!empty($data['vis_staff_team']) && $data['vis_staff_team']!="")
		{  $org_count=count($data['vis_staff_team']);
	       $org_ids="";
	       for($i=0;$i<$org_count;$i++)
		   {
			   if($i==($org_count-1))
			   {
				$org_ids.=$data['vis_staff_team'][$i];   
			   }
			   else
			   {
				   $org_ids.=$data['vis_staff_team'][$i].",";   
			   }
		   }
			$data['organisation_ids']=$org_ids;
		}
		
        if(!isset($data['vis_category_title']) || trim($data['vis_category_title'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        $database=new class_database();
        $data['vis_category_title'] = preg_replace('/\s+/', ' ',trim($data['vis_category_title']));
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $ret=$object->set_category($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_categories';
		$operation['vis_current_module']='selfhelp';			
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Modified solution category ".$data['vis_category_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");  $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTCATEGORIES'].'/'.$operation['vis_domain_id'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function delete_category($operation) {
        global $vis_language;
        if(!(isset($operation['vis_category_id']) && is_numeric($operation['vis_category_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ret=$object->delete_category($operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!isset($ret)) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Removed solution category ".$category[0]['selfhelp_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTCATEGORIES'].'/'.$operation['vis_domain_id'].'",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_categories"}); </script>'; 
		}
        $database->database_disconnect();
        return true;
    }

     function edit_article($operation) {
        global $vis_language;	
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);	
        $operation['view_title']=$vis_language['TXTARTICLES'];	
        $operation['vis_article_id']=($operation['vis_article_id']!='')?$operation['vis_article_id']:$action[4];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
										include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
								
        list($articles_info, $article)=$object->get_article('article_id='.$operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		$categories=$object->get_category('', VIS_STAFF_ID, VIS_LOCATION_AREA);		
        $article=$article[0];	
        $parent_category_details=$object->get_category('selfhelp_id='.$article['parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $parent_category_details=$parent_category_details[1][0];
        //list($categories_info, $parent_category)=$object->get_category('is_enabled=1 and domain_id='.$category['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
								list($language_info, $language_list)=$set_object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $attachments=$object->get_attachment('parent_id='.$article['article_id'].' and parent_type=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
		$operation['vis_operation1']='view_selfhelp';
		if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1) {  	
			$article['content'] = get_plain_text($article['content']);	
		}
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_article_edit.php');
        return true;
    }

    function delete_article($operation) {
        global $vis_language;
        if(!(isset($operation['vis_article_id']) && is_numeric($operation['vis_article_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($cnt, $article)=$object->get_article('article_id='.$operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $activity_msg="Removed article ".$article[0]['article_title'];
        $ret=$object->delete_article($operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_articles';
		$operation['vis_current_module']='selfhelp';			
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log($activity_msg, VIS_STAFF_ID ,2, 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_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function update_article($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!isset($data['vis_article_title']) || trim($data['vis_article_title'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        } if(!isset($data['vis_article_url']) || trim($data['vis_article_url'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDARTICLEURL'].'"); </script>';
            return false;
        }
        if(!(isset($data['vis_article_id']) && is_numeric($data['vis_article_id']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_article_content']) || trim(strip_tags($data['vis_article_content'],"<img>"))=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDCOT'].'"); </script>';
            return false;
        }
         $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
       
        ///////////checking URL Exist 
		$filt=' article_url='.'"'.$data['vis_article_url'].'"'.' and article_id != '.$data['vis_article_id'].' and art_parent_id != '.$data['vis_article_id'];
		list($articles,$result)=$object->get_article($filt,VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($result!=-1)
		{
			 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGURLEXIST'].'"); </script>';
           return false;
			
		}

        ///////////
        $data['vis_article_title'] = preg_replace('/\s+/', ' ',trim($data['vis_article_title']));
		$data['vis_category_id']=(isset($data['vis_category_id']))?$data['vis_category_id']:'';
		$data['vis_article_keywords']=(isset($data['vis_article_keywords']))?trim($data['vis_article_keywords']):'';
		$data['vis_article_content']=(isset($data['vis_article_content']))?$data['vis_article_content']:'';
        $data['vis_article_comment']=(isset($data['vis_article_comment']) && $data['vis_article_comment']==1)?1:0;
        $data['vis_article_rating']=(isset($data['vis_article_rating']) && $data['vis_article_rating']==1)?1:0;
        $data['vis_article_stick']=(isset($data['vis_article_stick']) && $data['vis_article_stick']==1)?1:0;
        $data['vis_article_attach']=(isset($data['vis_article_attach']) && $data['vis_article_attach']==1)?1:0;
        $data['vis_article_login']=(isset($data['vis_article_login']) && $data['vis_article_login']==1)?1:0;
        $data['vis_article_subscribe']=(isset($data['vis_article_subscribe']) && $data['vis_article_subscribe']==1)?1:0;
        if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1) 
        $data['vis_article_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_article_content']);
        $ret=$object->set_article($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_article';
		$operation['vis_current_module']='selfhelp';			
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Modified  article ".$data['vis_article_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$data['vis_article_url']."/".$data['vis_article_id'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'","vis_action":"'.$data['vis_action'].'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function set_comment($operation) {
        global $vis_language;
        $data=(isset($operation['vis_action']) && $operation['vis_action']!='')?parse_form_array($operation['vis_action']):array_map("addslashes", $operation);
        $data = (!empty($data))?$data:$operation;
        if(!(isset($data['vis_article_id']) && is_numeric($data['vis_article_id']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); </script>';
            return false;
        }
        $data['vis_fullname']=strip_tags($data['vis_fullname']);
        $data['vis_email']=strip_tags($data['vis_email']);
        $operation['vis_article_url']=$data['vis_article_title'];
		$operation['vis_article_id']=$data['vis_article_id'];
		
        if(VIS_LOCATION_AREA!=2 && $data['vis_fullname']=='') {
			$operation['error_message']='<div class="vis_error_message">'.$vis_language['MSGINFOMISS'].'</div>';
			return $this->view_article($operation);
        }
        if(VIS_LOCATION_AREA == 1 && $data['vis_honeypot']!='') {
			$operation['error_message']='<div class="vis_error_message">'.$vis_language['MSGERROPRT'].'</div>';
			return $this->view_article($operation);
			return false;
		}   
		 if(VIS_LOCATION_AREA==1 && (isset($data['vis_email']) || trim($data['vis_email'])!=''))
		 {
			list($message, $flag) = check_email_validation($data['vis_email']);
			if(!$flag) {
				$operation['error_message']='<div class="vis_error_message">'.$message.'</div>';
              return $this->view_article($operation);
			} 
		 }
        if($data['vis_selfhelp_comment']=='') {
            if(VIS_LOCATION_AREA==2) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); </script>';
                return false;
            }
            else {
                $operation['error_message']='<div class="vis_error_message">'.$vis_language['MSGINFOMISS'].'</div>';
                return $this->view_article($operation);
            }
        }
        if(VIS_LOCATION_AREA == 1 && (isset($data['captchacode']) && ((trim($data['captchacode'])!=strtoupper($_SESSION['random_number'])) && (trim($data['captchacode'])!=$_SESSION['random_number'])))) {
			$operation['error_message']='<div class="vis_error_message">'.$vis_language['MSGIMGVERIFY'].'</div>';
			return $this->view_article($operation);
			return false;
		}
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($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');
        $setting_object=new class_setting($database);
        $filter='article_id='.$data['vis_article_id'];
        list($articles_info, $article)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_article_url']=$article[0]['article_url'];
        $staff_info=$staff->get_staff('staff_id='.$article[0]['author_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $data['vis_selfhelp_comment'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_selfhelp_comment']);
        if(VIS_LOCATION_AREA==1 || VIS_LOCATION_AREA==2)
        $ret=$object->set_comment($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(VIS_LOCATION_AREA==2) {
            if(!$ret) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
			else{
				global $operation_hnd;
                $operation=array_merge($operation, $data);
                $operation_hnd->check_automation($operation, $database);
               if(VIS_GAMIFICATION_ACCESS == 1) { 
				   $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_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\':\'selfhelp\', \'vis_operation\':\'view_article\', \'vis_article_id\':'.$data['vis_article_id'].',\'vis_action\':\''.$data['vis_action'].'\'}) </script>';
            
            }
            $activity_log=$setting_object->add_staff_activity_log("Added new comment to article ".$article[0]['article_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
		}
        elseif(VIS_LOCATION_AREA==1) {
            if($ret) {
                global $operation_hnd;
                $operation=array_merge($operation, $data);
                $operation_hnd->check_automation($operation, $database);
            }
            if(VIS_GAMIFICATION_ACCESS == 1) { 
				   $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA); 
				   
            }
            if(!$ret)
            $operation['error_message']='<div class="vis_error_message">'.$vis_language['MSGERROPRT'].'</div>';
            else
             $operation['message']='<div class="vis_message">'.$vis_language['MSGSUCCOPRT'].'</div>';
            
            
			 if($operation['vis_static_url']==1)
             { 
				 header("Location:?/selfhelp/view-article/".$data['vis_article_title']."/".$data['vis_article_id']."/success");
			 }
             else
             { 
				 header("Location:?/selfhelp/view-article/".$data['vis_article_title']."/success");
			 }
             return $this->view_article($operation);
        }
        $database->database_disconnect();
        return true;
    }

    function show_comment($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($comments_info, $comments)=$object->get_comment('', $operation['vis_domain'], 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_comment_list.php');
        return true;
    }

    function toggle_approval($operation) {
        global $vis_language;
        if(!(isset($operation['vis_comment_id']) && is_numeric($operation['vis_comment_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        $ret=$object->toggle_approval($operation['vis_comment_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_comments';
		$operation['vis_current_module']='selfhelp';	
		$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 {
			list($cnt, $comment)=$object->get_comment('comment_id='.$operation['vis_comment_id'], '', 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$status_value=($operation['vis_value']==0) ? 'Approve' : 'Disapprove';
			$activity_log=$setting_object->add_staff_activity_log("Changed comment status as ".$status_value, VIS_STAFF_ID ,2, 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_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'", "vis_page":"'.$vis_page.'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function toggle_spam_mark($operation) {
        global $vis_language;
        if(!(isset($operation['vis_comment_id']) && is_numeric($operation['vis_comment_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        $ret=$object->toggle_spam_mark($operation['vis_comment_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $operation['vis_current_operation']='view_comments';
		$operation['vis_current_module']='selfhelp';	
		$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 {
			list($cnt, $comment)=$object->get_comment('comment_id='.$operation['vis_comment_id'], '', 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$status_value=($operation['vis_value']==0) ? 'Spam' : 'Not spam';
			$activity_log=$setting_object->add_staff_activity_log("Changed comment status as ".$status_value, VIS_STAFF_ID ,2, 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_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'", "vis_page":"'.$vis_page.'"}); </script>';
		}
        $database->database_disconnect();
		return true;
    }

    function edit_comment($operation) {
        global $vis_language;	
        if(!(isset($operation['vis_comment_id']) && is_numeric($operation['vis_comment_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($comments_info, $comment)=$object->get_comment('comment_id='.$operation['vis_comment_id'], '', 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $comment=$comment[0];
        $comment['content'] = get_plain_text($comment['content']);
        $database->database_disconnect();
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_edit_comment.php');
        return true;
    }

    function update_comment($operation) {
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!(isset($data['vis_comment_id']) && is_numeric($data['vis_comment_id']))) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGINFOMISS'].'"); </script>';
            return false;
        }
        if((isset($data['vis_content']) && $data['vis_content']=="")) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        $data['vis_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_content']);
        $ret=$object->update_comment($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$operation['vis_current_operation']='view_comments';
		$operation['vis_current_module']='selfhelp';				
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			list($cnt, $article)=$object->get_article('article_id='.$data['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Modified comment for article ".$article[0]['article_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $(".modal").modal("toggle"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTCOMMENT'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"'.$operation['vis_current_operation'].'"}); </script>';
		}
        $database->database_disconnect();
        return true;
    }

    function delete_comment($operation) {
        global $vis_language;
        if(!(isset($operation['vis_comment_id']) && is_numeric($operation['vis_comment_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($comments_info, $comment)=$object->get_comment('comment_id='.$operation['vis_comment_id'], '', 'desc', VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($cnt, $article)=$object->get_article('article_id='.$comment[0]['article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $activity_msg="Removed comment of article ".$article[0]['article_title'];
		$ret=$object->delete_comment($operation['vis_comment_id'], 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 {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $setting_object=new class_setting($database);
            $activity_log=$setting_object->add_staff_activity_log($activity_msg, VIS_STAFF_ID ,2, 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_comments"}); </script>'; 
		}
        $database->database_disconnect();
        return true;
    }

    function new_article($operation) {
        global $vis_language;
         $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);
        $operation['vis_category_id']=(isset($operation['vis_category_id']))?$operation['vis_category_id']:$action[4];	
        if(VIS_LOCATION_AREA==1) $operation['vis_category_id']=$action[3];	
        $operation['view_title']=$vis_language['TXTARTICLES'];	
        $database=new class_database();
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);
        list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $category=$category[0];
        $domain=(!isset($operation['vis_domain_id']))?$category['domain_id']:$operation['vis_domain_id'];
		list($categories_info, $categories)=$object->get_category('is_enabled=1 and domain_id='.$category['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domains=$ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		list($all_categories_info, $all_categories)=$object->get_category('is_enabled=1 and domain_id='.$operation['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $set_object=new class_setting($database);
        $language_details = $set_object->get_language('language_id='.$category['language_id'], '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $language_details= $language_details[1][0];
								list($language_info, $language_list)=$set_object->get_language('is_enabled=1', '', 0, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$header_title=$vis_language['TXTADDARTICLE'];
		$operation['vis_operation1']='view_selfhelp';	
		if(VIS_LOCATION_AREA==1) {
			$vis_title=$vis_language['TXTSELFHELP'];	
			$breadcrumb['Home'] = 'index.php'; 
			  
			if((IS_LOGIN==0 && VIS_DEFAULT_HOME_MODULE != $operation['vis_module']) || (IS_LOGIN==1 && VIS_DEFAULT_HOME_MODULE_AFTER_LOGIN != $operation['vis_module'])) $breadcrumb[$vis_language['TXTSELFHELP']] = '?/selfhelp/categories';
			$breadcrumb['Add article'] = '';	
		}	
        if(VIS_LOCATION_AREA==1) include(VIS_PATH_TEMPLATE.'header.php');
        include(VIS_PATH_TEMPLATE.'selfhelp_new_article.php');
        if(VIS_LOCATION_AREA==1) include(VIS_PATH_TEMPLATE.'footer.php');
        //if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_new_article.php');
        return true;
    }
	function get_category_list($operation)
	{
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($all_categories_info, $all_categories)=$object->get_category('is_enabled=1 and domain_id='.$operation['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        return true;
	}
    function add_new_category($operation) {
        global $vis_language;	
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';
        $action=explode($spliter, $operation['vis_action']);	
        $operation['vis_parent_id']=(isset($operation['vis_parent_id']))?$operation['vis_parent_id']:$action[4];
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $setting_object=new class_setting($database);
        $language_details = $setting_object->get_language('is_enabled=1', '', '', '', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $language_details = $language_details[1];
								list($language_info,$language_details1)=$setting_object->get_language('is_custom=1 and is_enabled=1','',0,0,VIS_STAFF_ID, VIS_LOCATION_AREA);
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'client.php');

		$client_object=new class_client($database);
		
		$filter='(domain_id='.$operation['vis_domain_id'].' or  domain_id=0) and is_enable=1';
		
		$client_group=$client_object->get_client_group($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);						
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $category=$category[0];
        $domain=(!isset($operation['vis_domain_id']))?$category['domain_id']:$operation['vis_domain_id'];
        if(!isset($operation['vis_domain_id'])) $domain=(!isset($action[4]) && $action[4]=='')?VIS_DOMAIN :'';
        $parent_category_details=$object->get_category('selfhelp_id='.$operation['vis_parent_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $parent_category_details=$parent_category_details[1][0];
        list($categories_info, $parent_category)=$object->get_category('is_enabled=1 and domain_id='.$category['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        $operation['view_title']=$vis_language['TXTCATEGORIES'];	
		$operation['vis_operation1']='view_selfhelp';				
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_new_category.php');
        return true;
    }

    function add_article($operation) {
		
        global $vis_language;
        $data=parse_form_array($operation['vis_action']);
        if(!isset($data['vis_article_title']) || trim($data['vis_article_title'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDTIT'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_article_url']) || trim($data['vis_article_url'])=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDARTICLEURL'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_parent']) || trim($data['vis_parent'])==0) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDCATEGORY'].'"); </script>';
            return false;
        }
        if(!isset($data['vis_article_content']) || trim(strip_tags($data['vis_article_content'],"<img>"))=='') {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGREQFLDCOT'].'"); </script>';
            return false;
        }
         $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
       
		if(!isset($operation['vis_domain_id']) || $operation['vis_domain_id']=="")
		{
			$domainid=$data['vis_domain_id'];
		}
		else
		{
			$domainid=$operation['vis_domain_id'];
		}
			
		
		$filt=' article_url='.'"'.$data['vis_article_url'].'" and domain_id='.$domainid;

		list($articles,$result)=$object->get_article($filt,VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		if($result!=-1)
		{
			 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGURLEXIST'].'"); </script>';
           return false;
			
		}
        
        $data['vis_article_title'] = preg_replace('/\s+/', ' ',trim($data['vis_article_title']));
		$data['vis_article_keywords']=(isset($data['vis_article_keywords']))?trim($data['vis_article_keywords']):'';
		$data['vis_article_content']=(isset($data['vis_article_content']))?$data['vis_article_content']:'';
        $data['vis_article_comment']=(isset($data['vis_article_comment']) && $data['vis_article_comment']==1)?1:0;
        $data['vis_article_rating']=(isset($data['vis_article_rating']) && $data['vis_article_rating']==1)?1:0;
        $data['vis_article_stick']=(isset($data['vis_article_stick']) && $data['vis_article_stick']==1)?1:0;
        $data['vis_article_attach']=(isset($data['vis_article_attach']) && $data['vis_article_attach']==1)?1:0;
        $data['vis_article_login']=(isset($data['vis_article_login']) && $data['vis_article_login']==1)?1:0;
        $data['vis_article_subscribe']=(isset($data['vis_article_subscribe']) && $data['vis_article_subscribe']==1)?1:0;
        $data['vis_category_id']=(isset($data['vis_category_id']))?$data['vis_category_id']:$data['vis_parent'];
        if (defined('VIS_HTML_EDITOR') && VIS_HTML_EDITOR != 1) 
        $data['vis_article_content'] = str_replace(array("\r\n","\r","\n"),"<br>",$data['vis_article_content']);
        $ret=$object->add_article($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$operation['vis_current_module']='selfhelp';			
        if(!$ret) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			 global $operation_hnd;
			 $operation['vis_domain_id']=(isset($operation['vis_domain_id']) && $operation['vis_domain_id']!='')?$operation['vis_domain_id']:$data['vis_domain_id'];
             $operation['vis_article_id']=$ret;
             $operation['vis_operation']='add_article';
             $operation_hnd->check_automation($operation, $database);
			 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
             $setting_object=new class_setting($database);
			 if(VIS_GAMIFICATION_ACCESS == 1) 
                {
                    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
                    $staff=new class_staff($database);
                    $staff_info=$staff->get_staff('staff_id='.VIS_STAFF_ID, VIS_STAFF_ID, VIS_LOCATION_AREA);
                    $points = $setting_object->calculate_points($staff_info[0],6,IS_STAFF_ID,VIS_LOCATION_AREA); 
                    $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA);
                    
                }
            $activity_log=$setting_object->add_staff_activity_log("Added new article ".$data['vis_article_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
			$domain_id=(isset($data['vis_domain_id']))?$data['vis_domain_id']:$operation['vis_domain_id'];
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#vis_workpanel_div").visExecution("load_module","'.$vis_language['TXTARTICLES'].'",{"vis_module":"'.$operation['vis_current_module'].'", "vis_operation":"view_articles"}); </script>';
        }
        $database->database_disconnect();
        return true;
    }



    function add_carticle($operation) {
        global $vis_language;
        if(!(defined('VIS_CLIENT_ID') && VIS_CLIENT_ID!=0)) {
            $operation['vis_error_message']=$vis_language['MSGACCSSDND'];
            echo json_encode( array('vis_msg' => $operation['vis_error_message']) );
            return false;
        }
        $operation['vis_article_title']=strip_tags($operation['vis_article_title']);
        if(!(isset($operation['vis_category_id']) && is_numeric($operation['vis_category_id']))) {
            $operation['vis_error_message']=$vis_language['MSGINFOMISS'];
            echo json_encode( array('vis_msg' => $operation['vis_error_message']) );
            return false;
        }
        if(!isset($operation['vis_article_title']) || $operation['vis_article_title']=='') {
            $operation['vis_error_message']=$vis_language['MSGREQFLDTIT'];
			echo json_encode( array('vis_msg' => $operation['vis_error_message']) ); 
            return false;
        }
        $operation['vis_article_comment']=1;
        $operation['vis_article_rating']=1;
        $operation['vis_article_stick']=0;
        $operation['vis_article_attach']=0;
        $operation['vis_article_login']=0;
        $operation['vis_article_subscribe']=0;
        $operation['vis_article_content']=nl2br($operation['vis_article_content']);
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $userid=(defined('VIS_CLIENT_ID') && VIS_CLIENT_ID!=0 && VIS_CLIENT_ID!=-1)?VIS_CLIENT_ID:VIS_STAFF_ID;
        $ret=$object->add_article($operation, $userid, VIS_LOCATION_AREA);
        if(!$ret) $operation['vis_error_message']=$vis_language['MSGERROPRT'];
        else {
            global $operation_hnd;
            $operation['vis_article_id']=$ret;
            $operation['vis_operation']='add_article';
            $operation_hnd->check_automation($operation, $database);
            $operation['vis_msg']=$vis_language['MSGSUCCOPRT'];
        }
         echo json_encode( array('vis_msg' => ($operation['vis_msg']!='')?1:$operation['vis_error_message']) );
        $database->database_disconnect();
        return $ret;
    }

    function confirm_delete($operation) {
        global $vis_language;
        $message_info['vis_module']='selfhelp';
        if(!(isset($operation['vis_area']) && is_numeric($operation['vis_area']))) return false;
        if($operation['vis_area']==0) {
            $message_info['vis_form_title']=$vis_language['TXTDELCATEGORY'];
            $message_info['vis_event']="$(this).visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'delete_category', 'vis_category_id':".$operation['vis_category_id'].", 'vis_domain_id':".$operation['vis_domain_id']."})";
            $message_info['vis_message']=$vis_language['MSGDELCAT'];


            if(!(isset($operation['vis_category_id']) && is_numeric($operation['vis_category_id']))) return false;
        }
        else if($operation['vis_area']==2) {
            $message_info['vis_form_title']=$vis_language['TXTDELCOMMENT'];
            $message_info['vis_event']="$(this).visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'delete_comment', 'vis_comment_id':".$operation['vis_comment_id']."})";
            $message_info['vis_message']=$vis_language['MSGSURE'];
            if(!(isset($operation['vis_comment_id']) && is_numeric($operation['vis_comment_id']))) return false;
        }
		else {
            $message_info['vis_form_title']=$vis_language['TXTDELARTICLE'];
            $message_info['vis_event']="$(this).visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'delete_article', 'vis_article_id':".$operation['vis_article_id']."})";
            $message_info['vis_message']=$vis_language['MSGDELART'];
            if(!(isset($operation['vis_article_id']) && is_numeric($operation['vis_article_id']))) return false;
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
function confirm_delete_drive($operation)
{	global $vis_language;
	    if(!(isset($operation['vis_area']) && is_numeric($operation['vis_area']))) return false;
	    if($operation['vis_area']==1) {
           $message_info['vis_form_title']=$vis_language['TXTDELSELFDRIVE'];
            
             $message_info['vis_event']="$(this).visExecution('load_operations',{'vis_module':'selfhelp', 'vis_operation':'delete_self_drive', 'vis_drive_id':".$operation['vis_drive_id'].",'vis_drive_owner':".$operation['vis_drive_owner']."})";
           
            $message_info['vis_message']=$vis_language['MSGDELSELFDRIVE'];

			if(!(isset($operation['vis_drive_id']) && is_numeric($operation['vis_drive_id']))) return false;
        }
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
        
	
}
 function delete_self_drive($operation) {
        global $vis_language;
        if(!(isset($operation['vis_drive_id']) && is_numeric($operation['vis_drive_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($drive_info, $drive)=$object->get_drive('drive_id='.$operation['vis_drive_id'].' and owner='.$operation['vis_drive_owner'],'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $ret=$object->delete_self_drive($drive_info[0]['drive_id'],$drive_info[0]['owner'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        if($ret!=1) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'"); </script>';
            return false;
        }
        else {
			include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
			$setting_object=new class_setting($database);
			$activity_log=$setting_object->add_staff_activity_log("Removed self uploaded file ".$drive_info[0]['file_name'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
	//echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");
		//	$("#drive-view").visExecution("load_area",{"vis_module":"'.$operation['vis_module'].'", "vis_operation":"view_drive","vis_del_action":"1", "vis_page":"'.$vis_page.'"}); </script>';
echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");
var del=del_'.$drive_info[0]["drive_id"].';
$(del).next().remove();
$(del).remove();
</script>';
			}
        $database->database_disconnect();
        return true;
    }
    function quick_view($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        $object=new class_staff($database);
        $selfhelp=$object->get_recent_audit('location=2', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if(VIS_LOCATION_AREA==2) include(VIS_PATH_TEMPLATE.'selfhelp_quickview.php');
        return true;
    }

    function set_rating($operation) {
        global $vis_language;
        $data=(isset($operation['vis_action']) && $operation['vis_action']!='')?parse_form_array($operation['vis_action']):$operation;
        $data = (!empty($data))?$data:$operation;
        if(VIS_LOCATION_AREA == 1 && (isset($operation['vis_action']) && $operation['vis_action']!=''))
		{
			$dataArr = explode("/",$operation['vis_action']);
			$data['vis_article_id'] = $dataArr[4];
			$operation['vis_rating']=$data['vis_rating'] = $dataArr[5];
		}
		if(VIS_LOCATION_AREA == 1 && !isset($operation['vis_action'])){
			$data['vis_article_id']=$operation['vis_article_id'];
			$data['vis_rating']=$operation['vis_rating'];
		}
        if(!(isset($data['vis_article_id']) && is_numeric($data['vis_article_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($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');
        $setting_object=new class_setting($database);
       
        $staff_info=$staff->get_staff('staff_id='.$article[0]['author_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        
        $ret=$object->set_rating($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
         $filter='article_id='.$data['vis_article_id'];
        list($articles_info, $article)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $article = $article[0];
        setcookie('article_id_'.$data['vis_article_id'],1, time()+86400);
        if(VIS_LOCATION_AREA==2) {
            if(!$ret) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
            else {
				
				  if(VIS_GAMIFICATION_ACCESS == 1) 
                  {  
					
						 if($data['vis_rating'] > 3)
						 {
							 $event = 4 ;
						 }
						 else if($data['vis_rating'] < 3)
						 {
							  $event = 5;
						 }
						 $points = $setting_object->calculate_points($staff_info[0],$event,IS_STAFF_ID,VIS_LOCATION_AREA);
						 $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA);
                 }
                 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $(\'#vis_selfhelp_details_div\').visExecution(\'load_area\', {\'vis_module\':\'selfhelp\', \'vis_operation\':\'view_article\', \'vis_article_id\':'.$data['vis_article_id'].'}) </script>';
              
          }
            
        }
        elseif(VIS_LOCATION_AREA==1) {
			 if(VIS_GAMIFICATION_ACCESS == 1) 
                  {  
					if($data['vis_rating'] >= 3)
                     {
                        $event = 4 ;
                     }
                     else if($data['vis_rating'] < 3)
                     {
                        $event = 5;
                     }
                     if($event!='')
                     { $points = $setting_object->calculate_points($staff_info[0],$event,IS_STAFF_ID,VIS_LOCATION_AREA);}
                     $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA);
                } 
             
			   $operation['message']=(!$ret)?'<div class="vis_error_message">'.$vis_language['MSGERROPRT'].'</div>':'<div class="vis_message">'.$vis_language['MSGSUCCOPRT'].'</div>';
               $rate1=$rate=''; for($cn=0;$cn<$article['rating'];$cn++){ $cnt= $cn+1;
			   if(!isset($_COOKIE['article_id_'.$article['article_id']]) && $article['can_rate']==1 && !isset($operation['vis_rating'])) { 
			   $rate.='<a href="javascript:void(0);" onclick="set_rating('.$cnt.');"><i class="vh vh-2x vh-star"></i></a>';
			   } else { $rate1.='<i class="vh vh-2x vh-star"></i>'; }
			   }
			   for($cn=$article['rating'];$cn<5;$cn++){$cnt= $cn+1;
				  if(!isset($_COOKIE['article_id_'.$article['article_id']]) && $article['can_rate']==1 && !isset($operation['vis_rating'])) { 
					  $rate.='<a href="javascript:void(0);" onclick="set_rating('.$cnt.');"><i class="vh vh-2x vh-star-empty"></i></a>'; 
					  } else { $rate1.='<i class="vh vh-2x vh-star-empty"></i>'; }
			   } 
			   echo json_encode( array('vis_message' => $operation['message'] ,'vis_success' => (($ret)?'true':'false'), 'list' => $rate.$rate1) );
        }
        $database->database_disconnect();
        return true;
    }

    function suggest_help($operation) {
        if($operation['vis_topic']=='') return true;
        $data=explode(' ', $operation['vis_topic']);
        $filter=VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE.' and domain_id='.VIS_DOMAIN.' and display_status!=2 and (';
        $count=count($data);
        for($i=0;$i<$count;$i++) {
            $filter.=' (';
            $sfilter='';
            for($j=0;$j<$count-$i;$j++) if(trim($data[$j])!='' && strlen($data[$j])>2) $sfilter.=' content like "%'.$data[$j].'%" and';
            $filter.=substr($sfilter, 0, -3).') or ';
        }
        $sfilter=' (';
        for($j=0;$j<$count;$j++) $sfilter.=' content like "%'.$data[$j].'%" or ';
        $filter.=substr($sfilter, 0, -3).')) limit 5';
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        list($articles_info, $selfhelp)=$object->get_article($filter, VIS_CLIENT_ID, VIS_LOCATION_AREA);
        $database->database_disconnect();
        if($selfhelp!=-1 && count($selfhelp)>0) include(VIS_PATH_TEMPLATE.'selfhelp_suggest_list.php');
        return true;
    }

    function add_quick_attachments($operation) {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $filter = 'parent_type=1 and parent_id='.$operation['vis_article_id'];
        if($operation['attachment_ids'] != '')
			$filter .= ' OR attachment_id IN (' . rtrim($operation['attachment_ids'], ',') . ')';
        $attachments = $object->get_attachment($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        
        $atts='';
        $att_text='';
        if($attachments!=-1) {
            for($i=0;$i<count($attachments);$i++) {
                $atts.=$attachments[$i]['attachment_id'].',';
					$att_text .= '<div class="btn-group wrapper-xxs"><label class="btn btn-xs alert-success">'.$attachments[$i]['file_name'].'</label><button class="btn btn-xs alert-success" type="button" data-dismiss="alert" onclick=\'$(this).parent().remove();vis_remove_attachment('.$attachments[$i]['attachment_id'] .',"",'.$operation['vis_ticket_id'].');\'><i class="vh vh-cross"></i></button></div>';
            }
        }
        $position = isset($operation['vis_forward']) ? 'vis_forward_attachments' : ((isset($operation['vis_ticket_reply']) && $operation['vis_ticket_reply']==1)?'vis_reply_attachments' : 'vis_new_ticket_attachments');

        if((isset($operation['vis_ticket_action']) && $operation['vis_ticket_action']==1)){
			echo json_encode( array('vis_attachment_ids' => $atts, 'vis_attachment_html' => $att_text) );
		}
		else{
			$attachment = isset($operation['vis_forward']) ? 'vis_fattachments' : 'vis_attachments';
			echo '<script> $("#vis_ticket_post_'.$operation['vis_ticket_id'].'").append("'.addslashes($article[0]['content']).'"); $("#'.$position.'").last().append("'.addslashes($att_text).'"); $("#'.$attachment.'").val("'.($atts).'"); </script>';
			return true;
		}
    }
    function get_mass_delete($operation) {
        global $vis_language;
		if($operation['vis_delete']==1)
		{
			$message_info['vis_form_title']=$vis_language['TXTDELARTICLE'];
			$message_info['vis_message']=$vis_language['MSGDELART'];
		}
		else
		{
			$message_info['vis_form_title']=$vis_language['TXTDELCOMMENT'];
			$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':'selfhelp', 'vis_operation':'mass_action', 'vis_form':'".$operation['vis_form']."','vis_switch':'".$operation['vis_switch']."','vis_page':'".$vis_page."','vis_article_id':'".$operation['vis_article_id']."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }	
    function mass_action($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.'selfhelp.php');
        $object=new class_selfhelp($database);
        $ret=$object->mass_action($operation['vis_switch'], $operation['vis_value'], $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 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":"'.$options['vis_current_operation'].'", "vis_page":"'.$vis_page.'"}); </script>';
        return $ret;
    }	
   function get_delete_comment($operation) {
        global $vis_language;
        $message_info['vis_form_title']=$vis_language['TXTDELETESELFHELPCOMMENT'];
        $message_info['vis_message']=$vis_language['MSGSURE'];
		$vis_page=(isset($operation['vis_page']))?$operation['vis_page']:'';									
        $message_info['vis_event']="$(this).visExecution('load_operations', {'vis_module':'selfhelp', 'vis_operation':'delete_article_comment', 'vis_article_id':".$operation['vis_article_id'].",'vis_comment_id':".$operation['vis_comment_id'].",'vis_page':'".$vis_page."'})";
        include(VIS_PATH_TEMPLATE.'confirm_delete.php');
        return true;
    }
     function delete_article_comment($operation) {
        global $vis_language;
        if(!isset($operation['vis_article_id']) && !isset($operation['vis_comment_id']) && isset($operation['vis_action']) && $operation['vis_action']!='')
        {
			$data = explode('/',$operation['vis_action']);
			$operation['vis_article_id'] = $data[3];
			$operation['vis_comment_id'] = $data[4];
		}  
        if(!isset($operation['vis_article_id'])) {
            echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGARTICLEIDNTFND'].'"); </script>';
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        $article=$object->get_article('article_id='.$operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $comment_details=$object->get_comment('comment_id='.$operation['vis_comment_id'],'', '', $userid, $user, $limit='');
        if(VIS_LOCATION_AREA == 2){
        if($article[1][0]['author_id']==VIS_STAFF_ID || $comment_details[1][0]['poster_id']==VIS_STAFF_ID)
        { 
			$ret=$object->delete_article_comment($operation['vis_article_id'],$operation['vis_comment_id'], 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
				{
					include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
					$setting_object=new class_setting($database);
					$activity_log=$setting_object->add_staff_activity_log("Removed comment of article ".$article[1][0]['article_title'], VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
					echo '<script> location.reload(); $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); </script>';
				}
		}
		else echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGACCSSDND'].'"); </script>';
		}
		else if(VIS_LOCATION_AREA == 1){
        if($comment_details[1][0]['poster_id']==VIS_CLIENT_ID)
        { 
			$ret=$object->delete_article_comment($operation['vis_article_id'],$operation['vis_comment_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
			$operation['reg_message']=(!$ret)?('<div class="vis_error_message">'.$vis_language['MSGERROPRT'].'</div>'):('<div class="vis_message">'.$vis_language['MSGSUCCOPRT'].'</div>');
			$this->view_article($operation);       
		}
		else echo '<div class="vis_error_message">'.$vis_language['MSGACCSSDND'].'</div>';
		}
        $database->database_disconnect();
        return true;
    }
    
    function add_quick_url($operation,$email='') {
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		$setting_object=new class_setting($database);
        list($articles_info, $article)=$object->get_article('article_id='.$operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        list($info, $domain)=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id='.$article[0]['domain_id'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		$article_url = $article[0]['article_url'].'/'.$article[0]['article_id'];
		if($email==''){
						//
						$database=new class_database();
						include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
						$object=new class_selfhelp($database);
       
						$filter=' article_url='.'"'.$article[0]['article_url'].'"'.' and language='.VIS_LANGUAGE;
						list($art_info, $art)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);  
						if(count($art)>=2):
						
							$lnk=$article[0]['article_url'].'/'.$article[0]['article_id'];	
						else:
						
							$lnk=$article[0]['article_url'];
						endif;
						//
			echo "<a href='".$domain[0]['domain_url']."?/selfhelp/view-article/".$lnk."'>".$domain[0]['domain_url']."?/selfhelp/view-article/".$lnk."</a>";
			return true;
		}
		else return "<a href='".$domain[0]['domain_url']."?/selfhelp/view-article/".$lnk."'>".$article[0]['article_title']."</a>";
    }
	function widget_selfhelp_search($operation) {
        	global $vis_language;
		    $database=new class_database();
            include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
            $object=new class_selfhelp($database);
			if(isset($operation['vis_search_text']) && $operation['vis_search_text']!=''){
				$filter = '(article_title like "%'.addslashes($operation['vis_search_text']).'%" or content like "%'.addslashes($operation['vis_search_text']).'%") and domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN);
				if(VIS_MODULE_ACCESS_SELFHELP==1) list($articles_info, $selfhelp)=$object->get_article('display_status!=2 and '.$filter, VIS_DOMAIN, VIS_LOCATION_AREA);
				if($selfhelp!=-1){
					for($s=0;$s<count($selfhelp);$s++){
						echo ' <li><a href="javascript:void(0);" class="link" onclick="get_selphelp_detail('.$selfhelp[$s]['article_id'].');">'.$selfhelp[$s]['article_title'].'</a></li>';
					}
				}else{
					echo '<div class="h4 text-center">'.$vis_language['TXTWIDNORECORDFOUND'].'</div>';
				}
			}
			if(isset($operation['vis_article_id']) && $operation['vis_article_id']!=''){
				$filter = '(article_id="'.$operation['vis_article_id'].'" ) and domain_id='.(isset($operation['domain_id']) ? $operation['domain_id'] : VIS_DOMAIN);
				if(VIS_MODULE_ACCESS_SELFHELP==1) list($articles_info, $selfhelp)=$object->get_article('display_status!=2 and '.$filter, VIS_DOMAIN, VIS_LOCATION_AREA);
				echo '<div class="post-title h3 l-h-1x">'.$selfhelp[0]['article_title'].'</div>
						<div class="m-b m-t m-r-n">
						  <span class="m-r-md">
							  <span class="font-bold">Posted by</span> : <span class="m-l-xs">'.$selfhelp[0]['author'].'</span>
						  </span>						  
						</div>
						<div class="m-b m-t m-r-n">
						  <span class="m-r-md">
							<span class="font-bold">Posted on</span> : <span class="text-muted m-l-xs">'.format_datetime($selfhelp[0]['entry_date']).'</span>
						  </span>
					    </div>
						<div>'.$selfhelp[0]['content'].'</div>';
						 // print_r($selfhelp);
			}
						
	}
	 
	function get_article_list($operation){
		global $vis_language;
		$database=new class_database();
	    include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
       $selfhelp_object=new class_selfhelp($database);
	   
		//$filter = VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.$operation['vis_domain_id'].' AND ';
	$filter = VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.$operation['vis_domain_id'].' AND '.VIS_TABLE_PREFIX.'selfhelp_article.art_parent_id = 0 ';
        if(isset($operation['vis_filter_enable'])){ 
			 
			$filter .= ' AND '.VIS_TABLE_PREFIX."selfhelp_article.article_title like '%".$operation['vis_filter']."%'  ";
		}
		//$filter=substr($filter, 0, -4);		
	    list($articles_info, $selfhelp)=$selfhelp_object->get_article($filter, VIS_DOMAIN, VIS_LOCATION_AREA);
		 
		 
		$location = (isset($operation['vis_ticket_id']) && $operation['vis_ticket_id']!='') ? $operation['vis_ticket_id'] : 0;
		$position = (isset($operation['vis_forward']) && $operation['vis_forward'] == 1)?'vis_forward_attachments':((isset($operation['vis_reply']) && $operation['vis_reply'] == 1)?'vis_reply_attachments':'vis_new_ticket_attachments');
        $tbl_data='';
		if($selfhelp!=-1){
        $tbl_data .= '';
			for($i=0;$i<count($selfhelp);$i++){
				$catarr='';
				$catarr=$this->getcategorybreadcrumb($selfhelp[$i]['parent_id'],$catarr);
				
					$tbl_data.='<i class="vh vh-lg vh-file-text m-r-md"></i><a href="javascript:void(0);" onclick="show_link('.$i.');" class="link ">'.$selfhelp[$i]['article_title'].'</a><span class="pull-right m-r article_links" id="show_link_'.$i.'" style="display:none;"><a href="javascript:void(0);" onclick="vis_quick_insert_selfhelp_search('.$selfhelp[$i]['article_id'].','.$location.');add_quick_attachments(\''.$position.'\','.$selfhelp[$i]['article_id'].','.$location.');" class="link m-l-xs">'.$vis_language['TXTADDARTICLE'].'</a>';
					
					if($selfhelp[$i]['display_status']!=2) {$tbl_data.=' |'.'<a href="javascript:void(0);" onclick="vis_quick_insert_article_url('.$selfhelp[$i]['article_id'].','.$location.');" class="link m-l-xs">'.$vis_language['TXTADDURL'].'</a>';}
					$tbl_data.='</span>';
					 $tbl_data .='<div class="m-l-lg text-xs" style="padding-left: 8px;">'.$catarr.'</div>';
					if(count($selfhelp)-1> $i) {$tbl_data .='<div class="line-solid b-b line-lg pull-in"></div>';}
			}
		}
		 
		 
		if($tbl_data==''){
				$tbl_data .='<div style="text-align:center;">'.$vis_language['TXTNOMATCHFOUND'].'</div>';
				$tbl_data .='<input type="hidden" name="total_itemrecord" id="total_itemrecord" value="0">';
		}else{
			$tbl_data .='<input type="hidden" name="total_itemrecord" id="total_itemrecord" value="'.count($selfhelp).'">';
			
		}
		if($operation['vis_tab']==1)
		{
		echo json_encode(array('list' => $tbl_data));	
		}
		else{ echo $tbl_data;
	    }
        return true;
	}
	
	function getcategorybreadcrumb($parentid,$retarr=''){ 
$database=new class_database();
include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
$selfhelp_object=new class_selfhelp($database);

	if($parentid!=0){
	list($catinfo,$listparent)=$selfhelp_object->get_category('selfhelp_id='.$parentid,VIS_STAFF_ID, VIS_LOCATION_AREA);

	if($listparent!=-1){
		if(empty($retarr))
		$retarr =$listparent[0]['selfhelp_title'];
		else
		$retarr =$listparent[0]['selfhelp_title'].' <i class="vh vh-angle-double-right"></i> '.$retarr;
	if($listparent[0]['parent_id']!=0){$retarr =$this->getcategorybreadcrumb($listparent[0]['parent_id'],$retarr);}
		}
	}
	return $retarr;
}

	function clone_article($operation) {
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
		 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);
     list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $category=$category[0];
        $domain=(!isset($operation['vis_domain_id']))?$category['domain_id']:$operation['vis_domain_id'];
		list($categories_info, $categories)=$object->get_category('is_enabled=1 and domain_id='.$category['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domains=$ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$selfhelp=$object->get_selfhelp('domain_id='.$domain, 0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'clone_article.php');
	}
	function add_clone_article($operation) {
       global $vis_language;
							$data=parse_form_array($operation['vis_action']);
        if(!isset($data['vis_parent']) || trim($data['vis_parent'])==0) {
           			echo $vis_language['MSGREQFLDCATEGORY'];
            return false;
        }
	$database=new class_database();
	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
	$object=new class_selfhelp($database);
	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	$setting_object=new class_setting($database);
	list($articles_info, $articles)=$object->get_article( VIS_TABLE_PREFIX.'selfhelp_article.article_id ='.$data['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);	
	if($articles_info!=-1){$article_title=$articles[0]['article_title'];}else{$article_title='';}
		$ret=$object->clone_article($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo $vis_language['MSGERROPRT'];
            return false;
        }else{
									$activity_log=$setting_object->add_staff_activity_log("Clone article ".$article_title, VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
								echo '1';
								}
								
								
	}
	
function get_articaldetailsby_language($operation)
{ global $vis_language; 
		$database=new class_database();
  include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
  $object=new class_selfhelp($database);
		$data=parse_form_array($operation['vis_action']);
		$filter='(art_parent_id='.$data['vis_article_id'].' or article_id='.$data['vis_article_id'].') and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.$data['vis_art_language'].' LIMIT 0,1';
		$artical_data=$object->get_articaldetailsby_language($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
		$attachments=$object->get_attachment('parent_id='.$artical_data[0]['article_id'].' and parent_type=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		if($attachments!=-1){
			$atts=$attach_con='';
			for($i=0;$i<count($attachments);$i++) {
				$atts.=$attachments[$i]['attachment_id'].','; 
				$name=$attachments[$i]['file_name'];
				$id=$attachments[$i]['attachment_id'];
				$attach_con.="<div class=\"btn-group wrapper-xxs\"><label class=\"btn btn-xs alert-success\">".$name."</label><button class=\"btn btn-xs alert-success\" type=\"button\" data-dismiss=\"alert\" onclick=\"$(this).parent().remove(); $(this).visExecution(\'load_operations\', {\'vis_module\':\'ticket\', \'vis_attachment_id\':".$id.", \'vis_operation\':\'remove_attachment\'}); vis_remove_attachment(".$id.", \'vis_attachments\');\">&times;</button></div>";
			}
		}
			if($artical_data!=-1){
				$art_lang['art_title']=$artical_data[0]['article_title'];
				$art_lang['art_url']=$artical_data[0]['article_url'];
				$art_lang['art_content']=$artical_data[0]['content'];
				$art_lang['article_id']=$artical_data[0]['article_id'];
				$art_lang['article_keywords']=$artical_data[0]['article_keywords'];
		}
		$res='';
		if($art_lang['art_title']!=''){
		$res .="$('#vis_article_title').val('".addslashes(trim(preg_replace('/\s+/', ' ',$art_lang['art_title'])))."');";	
		}else{
		$res .='$("#vis_article_title").val("");';
		}
		if($art_lang['article_id']!=''){
		$res .="$('#vis_art_parent_id').val('".$art_lang['article_id']."');";	
		}else{
		$res .='$("#vis_art_parent_id").val("");';
		}
		
		if($art_lang['art_url']!=''){
		$res .="$('#vis_article_url').val('".$art_lang['art_url']."');";	
		}else{
		$res .='$("#vis_article_url").val("");';
		}
		if(isset($art_lang['article_keywords']) && $art_lang['article_keywords']!=''){ 
			$res .="$('#vis_keyword').val('".$art_lang['article_keywords']."');";
		}else{
			$res .='$("#vis_keyword").val("");';
		}
		if($atts!=''){
			$res .="$('#vis_attachments').val('".$atts."');";
			$res .="$('#vis_selfhelp_attachments').html('".$attach_con."');";
		}else{
			$res .='$("#vis_attachments").val("");';
			$res .='$("#vis_selfhelp_attachments").html("");';
		}
		if($art_lang['art_content']!=''){
					if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) {
							$res .= "$('#vis_new_article_content').redactor('code.set','".addslashes(trim(preg_replace('/\s+/', ' ',$art_lang['art_content'])))."');";
						}else{
							$res .= "$('#vis_new_article_content').val('".addslashes(trim(preg_replace('/\s+/', ' ', $art_lang['art_content'])))."');";
						}
		}else{
						if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) {
							$res .= '$("#vis_new_article_content").redactor("code.set", "");';
						}else{
							$res .= '$("#vis_new_article_content").val("");';
						}
		}//end if
		
			echo '<script>'.$res.'</script>';
}


function clone_category($operation) {
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
		 include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'ticket.php');
        $ticket_object=new class_ticket($database);
     list($categories_info, $category)=$object->get_category('selfhelp_id='.$operation['vis_category_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
        $category=$category[0];
        $domain=(!isset($operation['vis_domain_id']))?$category['domain_id']:$operation['vis_domain_id'];
		list($categories_info, $categories)=$object->get_category('is_enabled=1 and domain_id='.$category['domain_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		$domains=$ticket_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1', VIS_STAFF_ID, VIS_LOCATION_AREA);
		$selfhelp=$object->get_selfhelp('domain_id='.$domain, 0, -1, true, VIS_STAFF_ID, VIS_LOCATION_AREA);
		include(VIS_PATH_TEMPLATE.'clone_category.php');
	}
	function add_clone_category($operation) {
       global $vis_language;
							$data=parse_form_array($operation['vis_action']);
							
        if(!isset($data['vis_parent']) || trim($data['vis_parent'])==0) {
           			echo $vis_language['MSGREQFLDCATEGORY'];
            return false;
        }
	$database=new class_database();
	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
	$object=new class_selfhelp($database);
	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	$setting_object=new class_setting($database);
		list($categories_info, $categories)=$object->get_category(VIS_TABLE_PREFIX.'selfhelp_category.selfhelp_id='.$data['vis_cat_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
if($categories_info!=-1){$category_title=$categories[0]['selfhelp_title'];}else{$category_title='';}
		$ret=$object->clone_category($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) {
            echo $vis_language['MSGERROPRT'];
            return false;
        }else{
									$activity_log=$setting_object->add_staff_activity_log("Clone category ".$category_title, VIS_STAFF_ID ,2, VIS_LOCATION_AREA);
								echo '1';
								}
								
								
	}
	
	function get_selfhelp_search_keywords($operation){
	    global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
		$object=new class_selfhelp($database);
	  
		$selfhelp=$object->get_article_auto_keywords($operation['vis_ticket_id'], $operation['domain_id'], $operation['vis_language_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
		
		$location = (isset($operation['vis_ticket_id'])) ? $operation['vis_ticket_id'] : 0;
		include(VIS_PATH_TEMPLATE.'quick_insert_selfhelp_search.php');
		return true;
	}
	
	function home($operation) {
        global $vis_language;	
								
								$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
								include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
            $object_setting=new class_setting($database);
            $settingres=$object_setting->get_settings('title="vis_head_menu_disable_portal" and domain_id='.VIS_DOMAIN, 0, VIS_LOCATION_AREA);
									if($settingres!=-1){ $disable_client_portal=$settingres[0]['content'];}else{  $disable_client_portal=0;}
									
        if(VIS_LOCATION_AREA==1){
									$header_title=VIS_DOMAIN_NAME;
			
            list($recent_articles_info, $selfhelp)=$object->get_article('is_stick=0 and domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_DOMAIN, VIS_LOCATION_AREA);
            for($i=0;$i<count($selfhelp);$i++) {
                $order=VIS_TABLE_PREFIX.'selfhelp_article.entry_date '.DESC .','.VIS_TABLE_PREFIX.'selfhelp_article.article_id '. DESC;                
                $filter=(IS_LOGIN)?'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)':'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)';
                list($recent_articles_info, $recent_articles)=$object->get_article($filter.' and '.VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_article.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_STAFF_ID, VIS_LOCATION_AREA,'0,5',$order);
            }
            list($featured_articles_info, $selfhelp)=$object->get_article('is_stick=1 and domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_DOMAIN, VIS_LOCATION_AREA);
            for($i=0;$i<count($selfhelp);$i++) {
                $order=VIS_TABLE_PREFIX.'selfhelp_article.entry_date '.DESC .','.VIS_TABLE_PREFIX.'selfhelp_article.article_id '. DESC;                
                $filter=(IS_LOGIN)?'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=1 or '.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)':'('.VIS_TABLE_PREFIX.'selfhelp_category.display_status=0)';
                list($featured_articles_info, $featured_articles)=$object->get_article($filter.' and '.VIS_TABLE_PREFIX.'selfhelp_category.is_enabled=1 and  is_stick=1 and '.VIS_TABLE_PREFIX.'selfhelp_article.is_enabled=1 and '.VIS_TABLE_PREFIX.'selfhelp_category.domain_id='.VIS_DOMAIN.' and '.VIS_TABLE_PREFIX.'selfhelp_article.language='.VIS_LANGUAGE, VIS_STAFF_ID, VIS_LOCATION_AREA,'',$order);	
            }
        }
								
								if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'header.php');
				else echo '<link href="'.VIS_PATH_STYLE.'vis_style.css" rel="stylesheet" />';
				if($disable_client_portal!=1){
				include(VIS_PATH_TEMPLATE.'client_home.php');
				}
				if(!isset($operation['vis_page']) && $operation['vis_page']=='')
				if(!defined('IS_WHMCS')) include(VIS_PATH_TEMPLATE.'footer.php');
				
								
	}
	
	function set_viewcount($operation)
	{
								global $vis_language;	
								$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
								$ret=$object->set_viewcount($operation['vis_article_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
								return $ret;
	}
	
	function set_articlelike($operation) {
        global $vis_language;
        $data=(isset($operation['vis_action']) && $operation['vis_action']!='')?parse_form_array($operation['vis_action']):$operation;
        $data = (!empty($data))?$data:$operation;
        
		if(VIS_LOCATION_AREA == 1 && !isset($operation['vis_action'])){
			$data['vis_article_id']=$operation['vis_article_id'];
			$data['vis_ratingflag']=$operation['vis_ratingflag'];
		}
        if(!(isset($data['vis_article_id']) && is_numeric($data['vis_article_id']))) {
            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.'selfhelp.php');
        $object=new class_selfhelp($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');
        $setting_object=new class_setting($database);
       
                
        $ret=$object->set_articlelike($data, VIS_STAFF_ID, VIS_LOCATION_AREA);
         $filter='article_id='.$data['vis_article_id'];
        list($articles_info, $article)=$object->get_article($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
        $article = $article[0];
								$staff_info=$staff->get_staff('staff_id='.$article[0]['author_id'], VIS_STAFF_ID, VIS_LOCATION_AREA);
								
        setcookie('article_id_'.$data['vis_article_id'],1, time()+86400);
        if(VIS_LOCATION_AREA==2) {
            if(!$ret) {
                echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", " '.$vis_language['MSGERROPRT'].'"); </script>';
                return false;
            }
            else {
				
				  if(VIS_GAMIFICATION_ACCESS == 1) 
                  {  
					
						 if($data['vis_ratingflag'] > 3)
						 {
							 $event = 4 ;
						 }
						 else if($data['vis_ratingflag'] < 3)
						 {
							  $event = 5;
						 }
						 $points = $setting_object->calculate_points($staff_info[0],$event,IS_STAFF_ID,VIS_LOCATION_AREA);
						 $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA);
                 }
                 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $(\'#vis_selfhelp_details_div\').visExecution(\'load_area\', {\'vis_module\':\'selfhelp\', \'vis_operation\':\'view_article\', \'vis_article_id\':'.$data['vis_article_id'].'}) </script>';
              
          }
            
        }
        elseif(VIS_LOCATION_AREA==1) {
			 if(VIS_GAMIFICATION_ACCESS == 1) 
                  {  
					if($data['vis_ratingflag'] == 1)
                     {
                        $event = 4 ;
                     }
                     else if($data['vis_ratingflag'] == 0)
                     {
                        $event = 5;
                     }
                     if($event!='')
                     { $points = $setting_object->calculate_points($staff_info[0],$event,IS_STAFF_ID,VIS_LOCATION_AREA);}
                     $details_quest =  $setting_object->calculate_game_points($data,$staff_info[0],2,IS_STAFF_ID, VIS_LOCATION_AREA);
                } 
             
			   $operation['message']=(!$ret)?'<div class="vis_error_message">'.$vis_language['MSGERROPRT'].'</div>':'<div class="vis_message">'.$vis_language['MSGSUCCOPRT'].'</div>';
               $rate1=$rate=''; 
			   if($ret) { 
			   $rate.='<a class="btn btn-empty bg-white b-a" style="cursor:text;" ><i class="vh vh-thumbs-up vh-lg bg-white"></i></a>&nbsp;<a class="btn btn-empty bg-white b-a " style="cursor:text;" ><i class="vh vh-thumbs-up vh-lg vh-rotate-180 bg-white"></i></a>';
			   } 
			   $liketext=$article['art_likes'].' '.$vis_language['TXTOUTOF'].' '.$article['like_count'].' '.$vis_language['TXTFOUNDTHISHELPFUL'];
			   
			   echo json_encode( array('vis_message' => $operation['message'] ,'vis_success' => (($ret)?'true':'false'), 'list' => $rate, 'liketext'=>$liketext) );
        }
        $database->database_disconnect();
        return true;
    }
	///Drive module function
	 function view_drive($operation) {

		global $vis_language;		
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
          $spliter=(strstr($operation['vis_action'], '/'))?'/':',';       
         $action=explode($spliter, $operation['vis_action']);       
        $operation['filter_id']= (isset($action[4]))?$action[4]:$operation['vis_filter_id'];
        if(isset($operation['vis_filter_id'])) $action[4]=$operation['vis_filter_id'];
        $database=new class_database();
        $object=new class_staff($database);
        $selfhelp_obj=new class_selfhelp($database);
        $sett_object=new class_setting($database);
		
		 list($info, $domain)=$sett_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		
		$domainurl=$domain[0]['domain_url']; 
		
  if(isset($operation['criteria']) && $operation['criteria']!='')
		{
			$actionc=1;
			$filter='file_name like "%'.addslashes($operation['criteria']).'%" ';
			$criteria = $operation['criteria'];
   }             
  if(isset($operation['vis_tab']) && $operation['vis_tab']==4 && (!isset($operation['criteria']) && $operation['criteria']=='')){
			$actionc=1;
			$filter='department_id=0 ';
  } 
  if(isset($operation['vis_tab']) && $operation['vis_tab']==5 && (!isset($operation['criteria']) && $operation['criteria']=='')){
			$actionc=1;
			
			$filter='department_id IN (0,1)and owner= '.VIS_STAFF_ID;
   }  
		if(isset($operation['vis_tab']) && $operation['vis_tab']==1 && (!isset($operation['criteria']) && $operation['criteria']=='')){
			$actionc=1;
			$filter='department_id!=1';
   }
			if((!isset($operation['criteria']) && $operation['criteria']=='') && (!isset($operation['vis_tab']) && $operation['vis_tab']=='')){
			$filter='department_id!=1';
			$actionc=1;
			}
        
         $page=(isset($operation['vis_page']) && $operation['vis_page']!='')?$operation['vis_page']:0;
         $area='drive_view';
        $module_setting=$sett_object->get_module_setting('module_id=13', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'] = (isset($module_setting['vis_drive_list_count']) && $module_setting['vis_drive_list_count']!='')?$module_setting['vis_drive_list_count']:10;
        
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        
        list($drive_info,$drive_details)=$selfhelp_obj->get_drive($filter,$actionc,$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
      
		$pagination = $page>0?$page*$view_info['page_count']:$page*10;
         
        ($drive_details[0]['count'] > ($pagination+$view_info['page_count']))?$remain = 1:$remain=0;
        
        $total_cnt='<script> $("#total_cnt").html("'.$drive_details[0]['count'].'"); </script>';
     
					 //THIS ONE FOR AUTH URL ADDED
		$gcal_filter='integration_type=42 AND is_enabled=1 AND ('.VIS_TABLE_PREFIX.'integration.domain_id=0)';
        list($gcal_info, $gcal_details)=$sett_object->get_integration_setting($gcal_filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
	    $gcal_details=$gcal_details[0]; 
	    if(count($gcal_details)>0 && $gcal_details!=-1){
			include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_CalendarService.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_TasksService.php');
			include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_DriveService.php');//THIS ONE FOR THE DRIVE API 
			$client = new Google_Client();
			$client->setClientId($gcal_details['host_name']);
			$client->setClientSecret($gcal_details['user_name']);
			$client->setRedirectUri($gcal_details['billing_url']);
			$client->setDeveloperKey($gcal_details['db_name']);
			$cal = new Google_CalendarService($client);
			$tasksService= new Google_TasksService($client);
			$driveService= new Google_DriveService($client);//THIS ONE FOR THE DRIVE API
			if (isset($query_str[1])) {
			  $client->authenticate($query_str[1]);
			  $_SESSION['token'] = $client->getAccessToken();
			}
			if (isset($_SESSION['token'])) {
			  $client->setAccessToken($_SESSION['token']);
			}
			else {
				  $authUrl = $client->createAuthUrl();				 
				 
			}
		}
        //THIS ONE FOR AUTH URL END
		$filter='integration_type=49';
		list($dropbox_info, $dropbox_details)=$sett_object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); // echo '<pre>';print_r($dropbox_details);
		$dropbox_details = $dropbox_details[0];
		$filter='integration_type=50';
		list($box_info, $box_details)=$sett_object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); // echo '<pre>';print_r($dropbox_details);
		$box_details = $box_details[0];
        $database->database_disconnect();
		
        $database->database_disconnect();
	
		
        if(isset($operation['vis_action']) && $operation['vis_action']=='insert_ticket') include(VIS_PATH_TEMPLATE.'mydrive_list_insert.php');
		else
		if((isset($operation['vis_action']) && $operation['vis_action']=='no_load') || $operation['vis_action']=='delete_self_drive' || $operation['vis_action']=='add_drive'){ include(VIS_PATH_TEMPLATE.'mydrive_list.php');}
		else
		if(isset($operation['vis_action']) && $operation['vis_action']=='load') include(VIS_PATH_TEMPLATE.'mydrive_list_load.php');
		else
		include(VIS_PATH_TEMPLATE.'drive.php');
        return true; 
      
    }
     
	function upload_file($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']);
        $database->database_disconnect();
		
        include(VIS_PATH_TEMPLATE.'upload_drive.php');
        return true;
	}
	function upload1_file($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']);
        $database->database_disconnect();
		
        include(VIS_PATH_TEMPLATE.'upload_driveticket.php');
        return true;
	}
	 
	function upload_drive_file($operation) {
       
		 global $vis_language; 
        $database=new class_database();
		
         include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object=new class_selfhelp($database);
        
       $is_editor_image_upload = $operation['is_editor_image_upload'] = (isset($operation['vis_static_area']) && $operation['vis_static_area']=='editor_image_upload') ? 1 : 0;
      
     
        
			$file_data = array();	
			
			
			if(!empty($_FILES['files'])){	
			
				$file_data['files']['name'][] = $_FILES['files']['name'];
				$file_data['files']['tmp_name'][] = $_FILES['files']['tmp_name'];
				$file_data['files']['size'][] = $_FILES['files']['size'];
				$file_data['files']['type'][] = $_FILES['files']['type'];
				$vis_file_extension=pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION);
			}
			else 
		    { 
				
				$file_data['files']['name'][] = $_FILES['file']['name'];
				$file_data['files']['tmp_name'][] = $_FILES['file']['tmp_name'];
				$file_data['files']['size'][] = $_FILES['file']['size'];
				$file_data['files']['type'][] = $_FILES['file']['type'];
				$vis_file_extension=pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
				$is_editor_image_upload = ($operation['vis_static_area']=='editor_file_upload')?1:0;
		    }
			
			$_FILES = $file_data;
			
		 $vis_file_extension=pathinfo($_FILES['files']['name'][0], PATHINFO_EXTENSION);
		  //echo"<script>alert('".$_FILES['files']['name'][0]."');</\script> ";
      	
		$ret=$object->upload_file($_FILES, $operation, VIS_DOMAIN, 0, VIS_STAFF_ID, VIS_LOCATION_AREA);
        if(!$ret) { ?>
            <script> parent.$("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>'; <?
            return false;
        }
        else {
            $message='';
            $attach='';
            $attach_area = $remove_attachment_arg = '';
            

            if(isset($operation['vis_attachments'])) $attach_area = 'vis_attachments';
                    
            $imgCnt = $fileCnt = 0;
            for($i=0;$i<count($ret);$i++) {
				
                $remove_attachment_arg = $ret[$i]['attachment_id'];
                if($attach_area != '') $remove_attachment_arg  .= ',\"'.$attach_area.'\"';
                if($operation['vis_ticket_id'] != '' || $operation['vis_ticket_id'] != 0) $remove_attachment_arg  .= ','.$operation['vis_ticket_id'];
                $attach.=$ret[$i]['attachment_id'].',';
                
             
						
						$message2.='<div class=\"col-xs-6 col-sm-4 col-md-3\"><button data-dismiss=\"alert\" class=\"close m-r-sm m-t-xs\" type=\"button\" onclick=\'$(this).parent().remove(); $(this).visExecution(\"load_operations\", {\"vis_module\":\"ticket\", \"vis_operation\":\"remove_attachment\", \"vis_attachment_id\":'.$ret[$i]['attachment_id'].'}); vis_remove_attachment('.$remove_attachment_arg.');\'><span aria-hidden=\"true\">准/span><span class=\"sr-only\">Close</span></button><div class=\"thumbnail\"><img src=\"'.VIS_PATH_FILES.$ret[$i]['attachment_content'].'\" class=\"bg-white img-responsive\" /></div></div>';	
						
						
					
					
						//$message3.='<div class=\"btn-group wrapper-xxs\"><span class=\"btn btn-xs alert-success\">'.$ret[$i]['attachment_name'].'</span><button class=\"btn btn-xs alert-success\" type=\"button\" data-dismiss=\"alert\" onclick=\'$(this).parent().remove(); $(this).visExecution(\"load_operations\", {\"vis_module\":\"ticket\", \"vis_operation\":\"remove_attachment\", \"vis_attachment_id\":'.$ret[$i]['attachment_id'].'}); vis_remove_attachment('.$remove_attachment_arg.');\'><i class=\"vh vh-cross\"></i></button></div>';	
						
					
						$message.='<div class=\"btn-group wrapper-xxs\"><span class=\"btn btn-xs alert-success\">'.$ret[$i]['attachment_name'].'</span><button class=\"btn btn-xs alert-success\" type=\"button\" data-dismiss=\"alert\" onclick=\'$(this).parent().remove(); $(this).visExecution(\"load_operations\", {\"vis_module\":\"ticket\", \"vis_operation\":\"remove_attachment\", \"vis_attachment_id\":'.$ret[$i]['attachment_id'].'});vis_remove_attachment('.$remove_attachment_arg.');\'><i class=\"vh vh-cross\"></i></button></div>';
														
							// echo"<script>alert($message);</\script>";
            }
           
            $database->database_disconnect();
          
				echo '<script>parent.$("#vis_global_msg_div").visExecution("load_file_message", {"vis_message":"'.$message.'", "vis_attachments":"'.$attach.'"}); parent.$("#add_link").removeAttr("disabled"); </script>'; 
				return true; 
			
				
        }     
	}
	 function remove_attachment($operation) {
        global $vis_language;
        if(!isset($operation['vis_attachment_id']) || !is_numeric($operation['vis_attachment_id'])) { ?>
            <script> $("#vis_global_msg_div").visInterface("load_global_message", "<? echo $vis_language['MSGERROPRT']; ?>"); </script>'; <?
            return false;
        }
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
		$attachmentid =$operation['vis_attachment_id'];
		if(substr($attachmentid,-1)==','){
		$attachmentid=substr($attachmentid,0,-1);
		}
		$attachmentids=explode(',',$attachmentid); 
        $selfhelp_object=new class_selfhelp($database);
        $ret=$selfhelp_object->remove_file($attachmentid, 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 echo '<script> $("#vis_global_msg_div").visInterface("load_global_message", "File removed successfully");</script>';
        return true;
    }
	function add_drive($operation)
	{
		global $vis_language; 
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);
        $data=parse_form_array($operation['vis_action']);
if($data['vis_attachments']=='' && $data['vis_attachmentsd']=='')
{
	 echo '<script>$("#vis_blab_post_hidden").val("");$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGPLZSELFILE'].'");</script>';
     return false;
}	
        $result=$object1->add_drive($operation['drive_id'],$data['vis_access'],VIS_STAFF_ID);
		 
         if(!$result) {
                echo '<script>$("#vis_blab_post_hidden").val("");$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGPLZSELFILE'].'");</script>';
                return false;
            }
            else {
				include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
				$setting_object=new class_setting($database);
				$activity_log=$setting_object->add_staff_activity_log("Added new Drive ", VIS_STAFF_ID,2, VIS_LOCATION_AREA);
				 
				if(isset($operation['vis_insert']) && $operation['vis_insert']=='insert_ticket'){
					echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'");$("#vis_details_list").visExecution("load_operations",{"vis_module":"selfhelp", "vis_operation":"view_drive", "vis_action": "insert_ticket","vis_tab":"1"});$("#insrtbtndiv").show();$(".rtpcls").removeClass("btn-primary"); $( ".rtpcls" ).first().addClass("btn-primary");</script>';
				}else{
				echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGSUCCOPRT'].'"); $("#drive-view").visExecution("load_area",{"vis_module":"selfhelp", "vis_operation":"view_drive" ,"vis_action":"add_drive","vis_page":"'.$vis_page.'"}); $(".modal").modal("hide");$(".rtpcls").removeClass("btn-primary"); $( ".rtpcls" ).first().addClass("btn-primary");</script>';
				}
			} 
        return true;
	}
	function delete_drive($operation){
		global $vis_language; 
        $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);
		 $drive_id =$operation['drive_id'];
		if(substr($drive_id,-1)==','){
		$drive_id=substr($drive_id,0,-1);
		}
		$drive_ids=explode(',',$drive_id); 
        $result=$object1->delete_drive($drive_id,VIS_STAFF_ID, VIS_LOCATION_AREA);
		 
         if(!$result) {
                echo '<script>$("#vis_global_msg_div").visInterface("load_global_message", "'.$vis_language['MSGERROPRT'].'");</script>';
                return false;
            }
            else {
				include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
				$setting_object=new class_setting($database);
				$activity_log=$setting_object->add_staff_activity_log("Removed cancel uploaded file ", VIS_STAFF_ID,2, VIS_LOCATION_AREA);
			}
			
        return true;
	}
	function mydrive_details($operation)
	{
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);       
		include(VIS_PATH_TEMPLATE.'my_drive_details.php');
	}
	 function view_ticket_attachments($operation) {
		global $vis_language;		
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'staff.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
        $spliter=(strstr($operation['vis_action'], '/'))?'/':',';       
        $action=explode($spliter, $operation['vis_action']);       
        $operation['filter_id']= (isset($action[4]))?$action[4]:$operation['vis_filter_id'];
        if(isset($operation['vis_filter_id'])) $action[4]=$operation['vis_filter_id'];
        $database=new class_database();
        $object=new class_staff($database);
        $selfhelp_obj=new class_selfhelp($database);
        $sett_object=new class_setting($database);
								
		 list($info, $domain)=$sett_object->get_domain(VIS_TABLE_PREFIX.'domain.is_enabled=1 and '.VIS_TABLE_PREFIX.'domain.domain_id='.VIS_DOMAIN, '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		
		$domainurl=$domain[0]['domain_url']; 
         if(isset($operation['criteria']) && $operation['criteria']!='')
		{
			$actionc=1;
			$filter='file_name like "%'.$operation['criteria'].'%" ';
			$criteria = $operation['criteria'];
        }             
        
         $page=(isset($operation['vis_page']) && $operation['vis_page']!='')?$operation['vis_page']:0;
         $area='drive_view';
        $module_setting=$sett_object->get_module_setting('module_id=13', VIS_STAFF_ID, VIS_LOCATION_AREA);
        $view_info['page_count'] = (isset($module_setting['vis_drive_list_count']) && $module_setting['vis_drive_list_count']!='')?$module_setting['vis_drive_list_count']:10;
        $limit=($page*$view_info['page_count']).','.$view_info['page_count'];
        $filter='parent_id!=0';
        list($ticket_attach_info,$ticket_attach_details)=$selfhelp_obj->get_ticket_attachments($filter,$actionc,$limit, $page,VIS_STAFF_ID, VIS_LOCATION_AREA);
         $pagination = $page>0?$page*$view_info['page_count']:$page*10;
          
        ($ticket_attach_details[0]['count'] > ($pagination+$view_info['page_count']))?$remain = 1:$remain=0;
    
        $database->database_disconnect();
       
		if(isset($operation['vis_action']) && $operation['vis_action']=='insert_ticket') {include(VIS_PATH_TEMPLATE.'ticket_attachments_list_insert.php');}
		else if(isset($operation['vis_action']) && $operation['vis_action']=='no_load') include(VIS_PATH_TEMPLATE.'ticket_attachments_list.php');
		else if(isset($operation['vis_action']) && $operation['vis_action']=='load') include(VIS_PATH_TEMPLATE.'ticket_attachments_load_list.php');
		else
		include(VIS_PATH_TEMPLATE.'drive.php');
        return true; 
      
    }
    function ticket_attachments_details($operation)
	{
		$database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);       
		include(VIS_PATH_TEMPLATE.'ticket_attachments_details.php');
	}
	
	//THIS ONE
	function mygoogledrive_details($operation)
	{
		 $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);
       
	include(VIS_PATH_TEMPLATE.'my_googledrive_details.php');
	}
					
function get_file_list($operation) {
   
	global $vis_language;
	$database=new class_database();
	$data=explode('/',$operation['vis_action']);
	$operation['vis_check_id'] = $data[4];
	
	$criteria=$operation['criteria'];
	if($data[3]==$criteria && $data[2]=='get_file_list')
	{
	$operation['vis_search_attr'] = 1;
	}
	include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
	$object=new class_setting($database);
	$filter='integration_type=42 AND is_enabled=1';
	list($gcal_info, $gcal_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA);
	$vis_domain = $gcal_details[0]['domain_id'];
		
	if(count($gcal_details)>0 && $gcal_details!=-1){ 
	
	foreach($gcal_details as $gcal){

	include(VIS_PATH_PLUGINS.'gmail_login/src/Google_Client.php');
	include(VIS_PATH_PLUGINS.'gmail_login/src/contrib/Google_DriveService.php');
	$client = new Google_Client();
	
	$client->setClientId($gcal['host_name']);
	$client->setClientSecret($gcal['user_name']);
	$client->setRedirectUri($gcal['billing_url']);
	$client->setDeveloperKey($gcal['db_name']);
	$service = new Google_DriveService($client);
    	
	if (isset($_SESSION['code'])) {
	$client->authenticate($_SESSION['code']);
	$_SESSION['token'] = $client->getAccessToken();
	 
	unset($_SESSION['code']);
	}
	if (isset($_SESSION['token'])) {
	$client->setAccessToken($_SESSION['token']);
	}
	
	if ($client->getAccessToken())
  {
	$result = array();$pagetoken_data=0;
	$pageToken = NULL;
	do {
			try
			{ 
			  if($operation['criteria'])
			  {
				  $text=$operation['criteria'];
				  $parameters['q']="fullText contains '".$text."'";
				  
			  }
			  
				if ($operation['vis_pagetoken']) 
				{
				$parameters['pageToken'] = $operation['vis_pagetoken'];
				}
				elseif($pageToken)
				{   
					$parameters['pageToken'] =$pageToken;
				}
				 //$parameters['maxResults']=1000;//THIS IS MAX PROPERTY
				 
				$files = $service->files->listFiles($parameters);
				$parent_array=array();
				$countvar=0;

				for($i=0;$i<count($files['items']);$i++)
				{
					if($files['items'][$i]['mimeType']=='application/vnd.google-apps.folder')
					{
						$parent_array[$i]['title']=$files['items'][$i]['title'];
						$parent_array[$i]['id']=$files['items'][$i]['id'];
						$parent_array[$i]['mimeType']=$files['items'][$i]['mimeType'];
					    $parent_array[$i]['isRoot']=$files['items'][$i]['parents'][0]['isRoot'];
						$parent_array[$i]['parent_id']=$files['items'][$i]['parents'][0]['id'];
					
					}
					else
					{
						$parent_array[$i]['title']="";
						$parent_array[$i]['id']="";
						$parent_array[$i]['mimeType']="";
					    $parent_array[$i]['isRoot']="";
						$parent_array[$i]['parent_id']="";
					}
						$countvar=$countvar+1;
				}

				$list_array=array();
				$filecount=count($files['items']);
			
				for($i=0;$i<count($files['items']);$i++)
				{
					$rootdata=$files['items'];
					$file_parent_id=$files['items'][$i]['parents'][0]['id'];
					$result=$this->search_parent($parent_array,$file_parent_id,$rootdata,$countvar);
                    
					if($result)
					{
					$list_array[$i]['title']=$result."/".$files['items'][$i]['title'];	
					}
					else
					{
					$list_array[$i]['title']=$files['items'][$i]['title'];
					}

					if($files['items'][$i]['mimeType']=='application/vnd.google-apps.folder')
					{
					$list_array[$i]['mimeType']="Directory";	
					}
					else
					{
					$list_array[$i]['mimeType']=$files['items'][$i]['mimeType'];	
					}

					$list_array[$i]['createdDate']=$files['items'][$i]['createdDate'];
					$list_array[$i]['fileSize']=$files['items'][$i]['fileSize'];
					$list_array[$i]['downloadUrl']=$files['items'][$i]['webContentLink'];
					$list_array[$i]['thumbnailLink']=$files['items'][$i]['thumbnailLink'];
					$list_array[$i]['iconLink']=$files['items'][$i]['iconLink'];
					$list_array[$i]['alternateLink']=$files['items'][$i]['alternateLink'];
					$list_array[$i]['ownername']=$files['items'][$i]['owners'][0]['displayName'];
					
					
			}
	       		$file_list=$list_array;
			 
    			$pageToken = $files['nextPageToken'];
			 		if($pageToken)
					{
					$pagetoken_data=$pagetoken_data+1;
					} 
				     
					if(($operation['vis_load_more']==$operation['vis_pagetoken_data']) && isset($pageToken) && isset($operation['vis_load_more']))
					{ 
					ob_start();
					include(VIS_PATH_TEMPLATE.'gdrive_file_list_paging.php'); 
					$tkt_list = ob_get_clean();
					ob_end_flush();
					echo json_encode( array('list'=> $tkt_list,'page_token'=>$pageToken,'pagetoken_data'=>$pagetoken_data,'vis_module'=>'selfhelp','vis_operation'=>'get_file_list','file_count'=>$filecount));
					exit;
					}else{
					if(isset($operation['vis_check_id']) && $operation['vis_check_id']==2)
					{
						$operation['vis_tab']=3;
						$drive_info=$file_list;
						include(VIS_PATH_TEMPLATE.'drive.php');
					}
					elseif(isset($operation['vis_search_attr']) && $operation['vis_search_attr'] == 1)
					{
						$operation['vis_tab']=3;
						$drive_info=$file_list;
						include(VIS_PATH_TEMPLATE.'drive.php');
					} 
					else { 
						if(isset($operation['vis_action']) && $operation['vis_action']=='insert_ticket'){ include(VIS_PATH_TEMPLATE.'get_file_list_insert.php');}
						else{ 	
						include(VIS_PATH_TEMPLATE.'gdrive_file_list.php'); }
					}
					exit;				 
					} 
			}
			catch (Exception $e)
			{
				print "An error occurred: " . $e->getMessage();
				$pageToken = NULL;
			}
	} while ($pageToken);
    
	}else
		{
		$authUrl = $client->createAuthUrl();
		}
		 
	}
  }
}

function search_parent($parent_array,$file_parent_id,$rootdata,$countvar,$temp="")
	{    
		for($i=0;$i<$countvar;$i++)
		{  
	       $str1=$parent_array[$i]['id'];
		   if((strcmp($str1,$file_parent_id))==0)
			{	
           	return $parent_array[$i]['title'];
			}
		}
	}	
	
	//THIS ONE FOR LIST THE DRIVE FOLDERS ENDS
	
	
	function dropbox_details1($operation)
	{
		 $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);
       
	include(VIS_PATH_TEMPLATE.'dropbox_detail.php');
	}
		
	
	
	
	function dropbox_details($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);
		$database=new class_database();
		 
		$filter='integration_type=49';
		list($dropbox_info, $dropbox_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); // echo '<pre>';print_r($dropbox_details);
		$dropbox_details = $dropbox_details[0]; 
		   
		   
		
		if(isset($_SESSION['code_dropbox'])){
	 $code=$_SESSION['code_dropbox'];
		 }else{
	 $code=$operation['vis_code_dropbox'];
		 }
		  
		 
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.dropbox.com/1/oauth2/token?code='.$code.'&grant_type=authorization_code&client_id='.$dropbox_details['admin_user'].'&client_secret='.$dropbox_details['api_key'].'&redirect_uri='.$dropbox_details['billing_url'].'' );
		//curl_setopt($curl,CURLOPT_URL, 'https://api.dropbox.com/1/oauth2/token?code='.$code.'&grant_type=authorization_code&client_id=n2bwx24us4jb99l&client_secret=ub9qdov5siawag3&redirect_uri=https://suyashservice.visionhelpdesk.com/manage' );
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		$access_token = curl_exec($curl);
		$access_token1=json_decode($access_token,true);  
		//print_r($access_token1);
		 if($dropbox_details['db_name']==''){
		$update=$object->update_dropbox($access_token1, $userid, $user); 
		 
		 }
		 $filter=' integration_type=49';
		 $dropbox_data=$object->intergration_dropbox($data, $userid, $user,$filter); 
		 $dropbox_data=$dropbox_data[0]; 
		 
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.dropboxapi.com/2/files/list_folder');
		//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization: Bearer '.$dropbox_data['db_name']));
		curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json","Authorization: Bearer ".$access_token1['access_token'] ));
		//curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json","Authorization: Bearer syfw2V8O1QAAAAAAAAAEE7FHk6SNyHfP1zsW3EfjfKV0Adi4UYeE4aRXm8kYwDDT"));
		$data1=json_encode(array('path'=> '/dropapps',
		'include_media_info'=> false,
		'include_deleted'=> false,
		'include_has_explicit_shared_members'=> false
			)); 
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data1); 
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		$file_get1 = curl_exec($curl);
		$dropbox_list=json_decode($file_get1,true);
		//echo '<pre>';
		//print_r($dropbox_list);
		
		 
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.dropbox.com/1/account/info');
		//curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token1['access_token']));
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$dropbox_data['db_name']));
		//curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
		//curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
		$file_get12345 = curl_exec($curl);
		$client_info=json_decode($file_get12345,true);
	 
		
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.dropboxapi.com/2/sharing/list_shared_links');
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization: Bearer '.$dropbox_data['db_name']));
		//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization: Bearer '.$access_token1['access_token']));
		$share_link=$dropbox_list['cursor'];
		$data1=json_encode(array('cursor'=> $share_link
		)); 
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data1); 
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		$file_get12 = curl_exec($curl);
		$share_link=json_decode($file_get12,true);
		//echo '<pre>';
		//print_r($share_link);
	 
		// $share_link['links'][0]['url']
		/*for($i=0;$i<count($share_link['links'][$i]);$i++){
			 
		 
		$curl = curl_init();
		
		//curl_setopt($curl,CURLOPT_URL, 'https://api.dropboxapi.com/1/metadata/auto/'.$share_link['links'][$i]['url']);
		curl_setopt($curl,CURLOPT_URL, 'https://api.dropbox.com/1/metadata/link?link='.$share_link['links'][$i]['url']);
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization: Bearer '.$dropbox_data['db_name']));
		
		$data1=json_encode(array('link'=> 'https://www.dropbox.com/s/euf9brdxznc90pw/Desert.jpg?dl=0'
		)); 
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data2); 
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		$file_get1234 = curl_exec($curl); 
 
		$share_linkdetail=json_decode($file_get1234,true);
		//echo'<pre>';
	//print_r($share_linkdetail);
		}*/
		 
		 
		
	if(isset($operation['vis_action']) && $operation['vis_action']=='insert_ticket') include(VIS_PATH_TEMPLATE.'dropbox_list_insert.php');
		else
			include(VIS_PATH_TEMPLATE.'dropbox_list.php');
	}
	
	function box_details1($operation)
	{
		 $database=new class_database();
        include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
        $object1=new class_selfhelp($database);
       
	include(VIS_PATH_TEMPLATE.'box_detail.php');
	}
	
	
	function box_details($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);
		$database=new class_database();
		 
		 $filter='integration_type=50';
		list($box_info, $box_details)=$object->get_integration_setting($filter, VIS_STAFF_ID, VIS_LOCATION_AREA); // echo '<pre>';print_r($dropbox_details);
		$box_details = $box_details[0]; 
		   
		    
		
		if(isset($_SESSION['code_box'])){
	 $code=$_SESSION['code_box'];
		 }else{
	 $code=$operation['vis_code_box'];
		 }
		 
		 $curl = curl_init();
	 
	curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/oauth2/token');
	curl_setopt($curl, CURLOPT_POSTFIELDS,"grant_type=authorization_code&code=".$code."&client_id=".$box_details['admin_user']."&client_secret=".$box_details['api_key']);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_POST, true);
	$access_token = curl_exec($curl); 
	//print_r($access_token);
		$access_token1=json_decode($access_token,true); //print_r($access_token1); 
		if($access_token1['access_token']!=''){
		$update=$object->update_box($access_token1, $userid, $user); 
		 
		 }
		 $filter=' integration_type=50';
		 $box_data=$object->intergration_box($data, $userid, $user,$filter);  
		 $box_data1=$box_data[0]; 
		 
		  
		 
	 	$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/2.0/folders/0');
		curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$box_data1['db_name']));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		$folder_info = curl_exec($curl);
		$folder_info1=json_decode($folder_info,true);  
		
		   
		 
		 
		 $curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/2.0/folders/0');
		curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$box_data1['db_name']));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		$folder_info = curl_exec($curl); 
		$folder_info1=json_decode($folder_info,true);  
		//print_r($folder_info1);
	 	 $folder_id=$folder_info1['item_collection']['entries'][0]['id'];

		 $file_id=array();
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/2.0/folders/'.$folder_id.'/items?limit=4&offset=0');
		curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$box_data1['db_name']));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		//curl_setopt($curl, CURLOPT_POST, true);
		$folder_info12 = curl_exec($curl); 
	//	echo '<pre>';
		$folder_info123=json_decode($folder_info12,true);  //print_r($folder_info123);
		 
		 for($i=0;$i<count($folder_info123['entries'][$i]);$i++)
		  {
			  
			  $file_id[$i]['id']=$folder_info123['entries'][$i]['id'];
			  
		  }
		$file_list=$file_id;
		   
		 
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/2.0/folders/11064766702/items?limit=4&offset=0');
		curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$box_data1['db_name']));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		//curl_setopt($curl, CURLOPT_POST, true);
		$folder_info12 = curl_exec($curl); 
	//	echo '<pre>';
		$folder_info123=json_decode($folder_info12,true); //print_r($folder_info123);
		
		
		 
 	  
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL, 'https://api.box.com/2.0/files/'.$file_list[$i]['id']);
		curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$box_data1['db_name']));
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		$file_info = curl_exec($curl); //echo '<pre>';
		$file_info1=json_decode($file_info,true);  //print_r($file_info1);
		 
		  
		 
		   
		 
		 include(VIS_PATH_TEMPLATE.'box_list.php');
		 
	}
	//THIS ONE FOR CLIENT LISTING IN A ORG -> START
	function client_listing($operation) 
	{  
		global $vis_language;
		$database=new class_database();
		$domain_id=$operation['vis_domain_id'];
		if(!isset($operation['vis_task_assign']) && $operation['vis_task_assign']!=""){
			$filter=VIS_TABLE_PREFIX . 'client.parent_id=0 and '.VIS_TABLE_PREFIX.'client.domain_id='.$domain_id.' and (first_name like "%'.$operation['vis_data'].'%" or last_name like "%'.$operation['vis_data'].'%" or email like "%'.$operation['vis_data'].'%")';
		}else{
			$filter=VIS_TABLE_PREFIX . 'client.parent_id=0 and '.VIS_TABLE_PREFIX.'client.domain_id='.$domain_id.' and (first_name like "%'.$operation['vis_data'].'%" or last_name like "%'.$operation['vis_data'].'%" or email like "%'.$operation['vis_data'].'%")';
		}

		include_once(VIS_PATH_CLASS . VIS_CLASS_PREFIX . 'client.php');
		$object = new class_client($database); 
		list($client_info, $client_details) = $object->get_client($filter); 

        include_once(VIS_PATH_FUNCTION.VIS_FUNCTION_PREFIX.'ticket.php');
        $database->database_disconnect();
        if(empty($client_details))$client_details = -1;
		$count=count($client_details);
        $result='[';
		if($client_details!=-1)
        {
			$result.='{"full_name":"Clients","id":"00","type":"heading"},';
			for($i=0;$i<$count;$i++) {
				$result.='{"id":"'.$client_details[$i]['client_id'].'", "full_name":"'.str_replace("\'","'",trim($client_details[$i]['first_name'])).' '.str_replace("\'","'",trim($client_details[$i]['last_name'])).'","type":"normal"},';
			}
		} 
    
    	$result=substr($result, 0, -1);
        if($result==''){ $result = "[]"; echo $result; return true;}
        $result.=']';
		echo $result;
		return true;
	}
	//THIS ONE FOR CLIENT LISTING IN A ORG -> ENDS
	
	//add drive in create ticket editor
	  function add_quick_url_drive($operation,$email='') {
		  global $vis_language;
		  $database=new class_database();
		  include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
          $object=new class_selfhelp($database);
          include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		  $setting_object=new class_setting($database);
		  $action=explode(',', $operation['vis_drive_id']);
		  
		  $count=count($action);
          for($m=0;$m<$count;$m++)
          {
			  
			   list($drive_info, $drive_details)=$object->get_drive('drive_id='.$action[$m],'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
			  
			    list($info, $domain)=$setting_object->get_domain(VIS_TABLE_PREFIX.'domain.domain_id='.$drive_info[0]['owner'], '', 0, '', VIS_STAFF_ID, VIS_LOCATION_AREA,1);
		$drive_filename = $drive_info[0]['content'];
		
			echo "<a target='_blank' href='".$domain[0]['domain_url']."attachment/".$drive_filename."'>".$domain[0]['domain_url']."attachment/".$drive_filename."</a> </br>";
			
		   }
       
		
    }
    function add_token($operation)
    {
		  global $vis_language;
		  $database=new class_database();
		  include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
          $object=new class_selfhelp($database);
          include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'setting.php');
		  $setting_object=new class_setting($database);
		 $vals_arr=explode('<br>',$operation['vis_value']);
		 $token_idarr=json_decode($operation['token_idarr'],true);
		if($operation['vis_as_val']==1 || $operation['vis_as_val']==2 || $operation['vis_as_val']==5)
			{
			foreach($token_idarr as $key=>$val)
			{
				$token_id=$val;
				if($operation['vis_as_val']==1 || $operation['vis_as_val']==5 )
				{
					$attachtype=1;
					list($drive_info, $drive_details)=$object->get_drive(VIS_TABLE_PREFIX.'drive.drive_id='.$key,0,'',0,0, 0);
				}
				else if($operation['vis_as_val']==2)
				{
					$attachtype=0;
					list($drive_info, $drive_details)=$object->get_ticket_attachments(VIS_TABLE_PREFIX.'attachment.attachment_id='.$key,0,'', 0,0,0);
				}
				$file_name=$drive_info[0]['file_name'];
				$token=$object->add_token($token_id,$file_name,$attachtype,$key, VIS_STAFF_ID, VIS_LOCATION_AREA);
			}
		}
		 
	}
function token_details($operation)
	{
		global $vis_language;
		$database=new class_database();
		include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
		$object=new class_selfhelp($database);
		$token=$operation['vis_action_data'][3];
		$tokendetails=$object->get_token_ticket($token);
		$filename1=$tokendetails[0]['filename'];
		if (strpos($filename1, '%20') !== false) 
		{
			$filename = str_replace('%20', ' ', $filename1);
		}
		else
		{ 
			$filename=$filename1;
		}
		if($tokendetails[0]['attach_type']=='1') //drive
		{
			list($drive_info, $drive_details)=$object->get_drive('drive_id='.$tokendetails[0]['attach_id'],'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		if($tokendetails[0]['attach_type']=='0') //attachment
		{
			list($drive_info, $drive_details)=$object->get_ticket_attachments('attachment_id='.$tokendetails[0]['attach_id'],'','','', VIS_STAFF_ID, VIS_LOCATION_AREA);
		}
		
		if(!file_exists(VIS_PATH_FILES. $drive_info[0]['content']) || $drive_info==-1) 
		{
			echo '<h3 class="m-b-xs text-black">File not found</h3>';
		}
		else
		{
			if(strpos($drive_info[0]['file_name'],$filename)!==false)
			 {
				
				$type=$drive_info[0]['file_type'];
				$file_new=$drive_info[0]['file_name'];
				$size=$drive_info[0]['file_size'];
				$contentname=$drive_info[0]['content'];
				$filepath= VIS_PATH_FILES. $contentname;
				$file_new=str_replace(" ","_",$file_new);
				header("Content-Type: $type");
				header("Content-Length: ".$size);
				header("Content-Disposition: attachment;filename=".$file_new);   
				header('Content-Length: '.filesize(VIS_PATH_FILES. $contentname));    
				readfile(VIS_PATH_FILES. $contentname);
				exit();
			 }
		}
		
	}
	function getcategoryfirstid($parentid,$retarr=''){ 
$database=new class_database();
include_once(VIS_PATH_CLASS.VIS_CLASS_PREFIX.'selfhelp.php');
$selfhelp_object=new class_selfhelp($database);

	if($parentid!=0){
	list($catinfo,$listparent)=$selfhelp_object->get_category('selfhelp_id='.$parentid,VIS_STAFF_ID, VIS_LOCATION_AREA);

	if($listparent!=-1){
		if($listparent[0]['parent_id']!=0){
		if(empty($retarr))
		$retarr =$listparent[0]['parent_id'];
		else
		$retarr =$listparent[0]['parent_id'];
		}
	if($listparent[0]['parent_id']!=0){$retarr =$this->getcategoryfirstid($listparent[0]['parent_id'],$retarr);}
		}
	}
	return $retarr;
}
	
}
?>
