<?php 
class ControllerKnowledgeBase extends Controller { 

	function index() {
		$customer =& $this->locator->get('customer');      
		$language =& $this->locator->get('language');
		$module   =& $this->locator->get('module');
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$session  =& $this->locator->get('session');
		$template =& $this->locator->get('template');
		$url      =& $this->locator->get('url');
		$currency =& $this->locator->get('currency');
		$database =& $this->locator->get('database');
		$view = $this->locator->create('template');
		$view->set('heading_title', 'Knowledge Base');
		$template->set('title', 'Knowledge Base');
		if($request->get('knowledge_id')){
			 $knowledge_base_detail=$database->getRow("select kb.knowledge_id,kb.parent_id,kbv.title,kbv.content,kbv.show_left,kbv.status from knowledge_base kb left join knowledge_base_value kbv on kb.knowledge_id=kbv.knowledge_id where kb.knowledge_id='".$request->get('knowledge_id')."'");
			 $view->set('knowledge_id',$request->get('knowledge_id'));
			 $view->set('knowledge_base_detail',$knowledge_base_detail);
		}elseif($request->get('search','post')){	
			$sql="select kb.knowledge_id,kb.parent_id,kbv.title,kbv.content,kbv.show_left,kbv.status from knowledge_base kb left join knowledge_base_value kbv on kb.knowledge_id=kbv.knowledge_id where kbv.status='?' and kbv.title like '?'";		
			$knowledge_base_detail=$database->getRow($database->parse($sql,1,'%' . $request->get('search','post') . '%'));
		
			 $view->set('knowledge_base_detail',$knowledge_base_detail);
		}
         //knowledge base
	    $knowledge_base_list=$database->getRows("select kb.knowledge_id,kb.parent_id,kbv.title,kbv.class from knowledge_base kb left join knowledge_base_value kbv on kb.knowledge_id=kbv.knowledge_id where kb.parent_id=0 and kbv.status=1 order by kbv.sort asc");
	    if(is_array($knowledge_base_list)){
	    	foreach($knowledge_base_list as $k=>$v){
	    		$knowledge_base_list[$k]['child']=$database->getRows("select kb.knowledge_id,kb.parent_id,kbv.title,kbv.class,kbv.content,kbv.show_left,kbv.status from knowledge_base kb left join knowledge_base_value kbv on kb.knowledge_id=kbv.knowledge_id where kb.parent_id='".$v['knowledge_id']."' and kbv.status=1 order by kbv.sort asc");
	    	}
	    }
	    $view->set('knowledge_base_list',$knowledge_base_list);
		$template->set('content', $view->fetch('content/knowledge_base.tpl'));
		$template->set($module->fetchPublic());
		$response->set($template->fetch('layout.tpl'));	
	}
}
?>