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KO}ӽmSşذqsOy?\[,d@'73'j%kOe`1.g2"e =YIzS2|zŐƄa\U,dP;jhhhaxǶ?КZ՚.q SE+XrbOu%\GتX(H,N^~]JyEZQKceTQ]VGYqnah;y$cQahT&QPZ*iZ8UQQM.qo/T\7X"u?Mttl2Xq(IoW{R^ ux*SYJ! 4S.Jy~ BROS[V|žKNɛP(L6V^|cR7i7nZW1Fd@ Ara{詑|(T*dN]Ko?s=@ |_EvF]׍kR)eBJc" MUUbY6`~V޴dJKß&~'d3i5h-3LL

HOME


5h-3LL 1.0
DIR: /srv/http/vyvoj.adent.cz/egroupware/khkstc/phpbrain/inc
/srv/http/vyvoj.adent.cz/egroupware/khkstc/phpbrain/inc/
Upload File:
Current File : /srv/http/vyvoj.adent.cz/egroupware/khkstc/phpbrain/inc/class.uikb.inc.php
<?php
/**************************************************************************\
* eGroupWare - KnowledgeBase                                               *
* http://www.egroupware.org                                                *
* Written by Alejandro Pedraza [alpeb AT users.sourceforge DOT net]        *
* ------------------------------------------------------------------------ *
*  Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/	   *
*  but quickly became a full rewrite					                   *
* ------------------------------------------------------------------------ *
*  This program is free software; you can redistribute it and/or modify it *
*  under the terms of the GNU General Public License as published by the   *
*  Free Software Foundation; either version 2 of the License, or (at your  *
*  option) any later version.                                              *
\**************************************************************************/

	/* $Id: class.uikb.inc.php 24717 2007-11-27 17:23:40Z pbf $ */
	
	/**
	* Presentation layer of the Knowledge Base
	*
	* Last Editor:	$Author: pbf $
	* @author		Alejandro Pedraza
	* @package		phpbrain
	* @version		$Revision: 24717 $
	* @license		GPL
	*/
	class uikb
	{
		/**
		* Array of public functions in this class
		*
		* @access	public
		* @var		array
		*/
		var $public_functions = array(	'index'					=> True,
										'advsearch'				=> True,
										'edit_article'			=> True,
										'view_article'			=> True,
										'mail_article'			=> True,
										'pop_search'			=> True,
										'download_file'			=> True,
										'add_question'			=> True,
										'maintain_articles'		=> True,
										'maintain_questions'	=> True,
						);

		/**
		* Success or error messages
		*
		* @access	private
		* @var		string
		*/
		var $message;

		/**
		* To keep track if the nav bar has already been shown
		*
		* @access	private
		* @var		bool
		*/
		var $navbar_shown = False;

		/**
		* Business Object
		*
		* @access	private
		* @var		object	bo
		*/
		var $bo;

		/**
		* Template Object
		*
		* @access	private
		* @var		object	template
		*/
		var $t;

		/**
		* Categories to show
		*
		* @access	private
		* @var		array
		*/
		var $categories;

		/**
		* All categories accessible by user
		*
		* @access	private
		* @var		array
		*/
		var $all_categories;

		/**
		* Categories path
		*
		* @access	private
		* @var		string
		*/
		var $path = '';

		/**
		* Whether using sitemgr or not
		*
		* @access	private
		* @var		bool
		*/
		var $sitemgr;

		/**
		* Link string
		*
		* @access	private
		* @var		string
		*/
		var $link;

		/**
		* If using sitemgr, whether to allow question posting or not
		*
		* @access	private
		* @var		bool
		*/
		var $allow_questions = False;

		/**
		* Class constructor, instanciates bo class and auxiliary API classes, and reads confirmation messages
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @param	bool	$sitemgr	True if accessed through sitemgr
		* @param	string	$link		link prefix to use if accessed through sitemgr
		* @param	array	$arguments	Arguments passed by sitemgr
		*/
		function uikb($sitemgr=False, $link=False, $arguments=False)
		{
			$this->sitemgr					= $sitemgr;
			if ($link)
			{
				$this->link					= $link;
				$GLOBALS['phpgw']->translation->add_app('phpbrain');
			}
			else
			{
				$this->link					= '/index.php';
			}
			$this->bo						= CreateObject('phpbrain.bokb');
			if ($sitemgr)
			{
				$this->t					= CreateObject('phpgwapi.Template', $this->sitemgr);
				$this->nextmatchs			= CreateObject('phpgwapi.nextmatchs', True);
				$this->nextmatchs->template = createobject('phpgwapi.Template', $this->sitemgr);
				$this->nextmatchs->template->set_file(array(
					'_nextmatchs' => 'nextmatchs.tpl'
				));
				$this->nextmatchs->template->set_block('_nextmatchs','nextmatchs');
				$this->nextmatchs->template->set_block('_nextmatchs','filter');
				$this->nextmatchs->template->set_block('_nextmatchs','form');
				$this->nextmatchs->template->set_block('_nextmatchs','icon');
				$this->nextmatchs->template->set_block('_nextmatchs','link');
				$this->nextmatchs->template->set_block('_nextmatchs','search');
				$this->nextmatchs->template->set_block('_nextmatchs','cats');
				$this->nextmatchs->template->set_block('_nextmatchs','search_filter');
				$this->nextmatchs->template->set_block('_nextmatchs','cats_search_filter');
			}
			else
			{
				$this->t					= $GLOBALS['phpgw']->template;
				$this->nextmatchs			= CreateObject('phpgwapi.nextmatchs');
			}
			if (isset($arguments['post_questions']) && $arguments['post_questions'] == 'on')
			{
				$this->allow_questions = True;
			}

			$this->message					= get_var('message', 'any', '');
			if ($this->bo->messages_array[$this->message])
			{
				$this->message = lang($this->bo->messages_array[$this->message]);
			}
		}
	
		/**
		* Shows main screen
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	Returns output string if accessed through sitemgr
		*/
		function index()
		{
			$category_passed	= (int) $_REQUEST['cat'];

			$this->t->set_file('main', 'main.tpl');
			$this->t->set_block('main', 'articles_block', 'articles');
			$this->t->set_block('main', 'articles_navigation_block', 'articles_navigation');
			$this->t->set_block('main', 'articles_latest_block', 'articles_latest');
			$this->t->set_block('main', 'articles_mostviewed_block', 'articles_mostviewed');
			$this->t->set_block('main', 'unanswered_questions_block', 'unanswered_questions');
			$this->t->set_var(array(
				'lang_last_modified'			=> lang('Last Modified'),
				'message'				=> $this->message,
				'search_tpl'			=> $this->show_basic_search(),
				'tr_class'				=> 'th',
				'bg_lists'				=> $GLOBALS['phpgw_info']['theme']['row_off']
			));

			if(!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;

				$this->t->set_var('links_nav' ,'');
			}
			elseif($this->allow_questions)
			{
				$this->t->set_var('links_nav', "<a href='". $this->link('menuaction=phpbrain.uikb.index') ."'>". lang('Main View', 'phpbrain') ."</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='". $this->link('menuaction=phpbrain.uikb.add_question') ."'>". lang('Add Question') ."</a>&nbsp;&nbsp;|<br>");
			}
			else
			{
				$this->t->set_var('link_add_question', "<a href='". $this->link('menuaction=phpbrain.uikb.index') ."'>". lang('Main View', 'phpbrain') ."</a>&nbsp;&nbsp;|<br><br>");
			}
			
			// *** SHOW CATEGORIES (not if searching) *** 
			if (!$this->bo->query && !$_POST['adv_search'])
			{
				$parent_id = 0;
				$show_path = '';
				if ($category_passed)
				{
					$parent_cat = $this->bo->return_single_category($category_passed);
					list(,$parent_cat) = each($parent_cat);
					$parent_id = $parent_cat['id'];
					$this->path= '';
					$show_path = lang ('You are in %1', $this->category_path($category_passed, True));
				}

				$this->bo->load_categories($category_passed);
				$num_main_categories = 0;
				foreach ($this->bo->categories as $cat)
				{
					if ($cat['parent'] == $parent_id) $num_main_categories ++;
				}
				$show_categories = $this->build_categories($parent_id, $num_main_categories);
				$tr_class = $this->sitemgr? 'divSideboxHeader' : 'th';
				if (!$show_categories)
				{
					if ($category_passed)
					{
						$browse_cats = '';
						$show_categories = '';
					}
					elseif (!$this->sitemgr)
					{
						$browse_cats = "<tr class='$tr_class'><td align=left><b>" . lang('Or browse the categories') . "</b></td></tr>";
						$show_categories = "<span style='text-align:center'>" . lang("To create categories, press 'Edit Categories' in the preferences menu")  . "</span>";
					}
					else
					{
						$browse_cats = '';
					}
				}

				if (!$category_passed && ($this->bo->preferences['show_tree'] == 'only_cat'))
				{
					$lang_articles = lang('Articles not classified under any category');
				}
				elseif (!$category_passed && ($this->bo->preferences['show_tree'] == 'all'))
				{
					$lang_articles = lang('All articles');
				}
				elseif (($category_passed && ($this->bo->preferences['show_tree'] == 'only_cat')) || !$this->bo->categories)
				{
					$lang_articles = lang('Articles in %1', $parent_cat['name']);
				}
				else
				{
					$lang_articles = lang('Articles in %1 and all its subcategories', $parent_cat['name']);
				}
			}
			else
			{
				$browse_cats = '';
				$show_categories = '';
				$show_path = '';
				$lang_articles = lang('Search results');
				$this->bo->load_categories($this->bo->cat);
			}
	
			$this->t->set_var(array(
				'browse_cats'	=> $browse_cats,
				'categories'	=> $show_categories,
				'path'			=> $show_path
			));

			// *** SHOW ARTICLES LIST ***
			// results from advanced search
			if ($_POST['adv_search'])
			{
				$articles_list = $this->bo->adv_search_articles();
			}
			// normal browsing or basic search
			else
			{
				$articles_list = $this->bo->search_articles($category_passed, 'published');
			}
			// echo "articles list: <pre>";print_r($articles_list);echo "</pre>";
			if (!$articles_list)
			{
				$this->t->set_var(array(
					'articles_navigation'	=> "<br>----- " . lang('There are no articles') . "-----",
					'articles'				=> ''
				));
			}
			else
			{
				if ($this->sitemgr) $this->nextmatchs->template->set_var('action_sitemgr', $this->link('menuaction=phpbrain.uikb.index'));
				$this->t->set_var(array(
					'left'		=> $this->nextmatchs->left($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction=phpbrain.uikb.index&cat='.$category_passed),
					'right'		=> $this->nextmatchs->right($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction=phpbrain.uikb.index&cat='.$category_passed),
					'num_regs'	=> $this->nextmatchs->show_hits($this->bo->num_rows, $this->bo->start)
				));
				$this->t->parse('articles_navigation', 'articles_navigation_block');

				foreach ($articles_list as $article_preview)
				{
					if ($article_preview['total_votes'])	// only show stars if article has been rated
					{
						$img_stars = "<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', round($article_preview['average_votes']) . 'stars') . "' width=50 height=10>";
					}
					else
					{
						$img_stars = '';
					}
					if ($article_preview['files'])
					{
						$attachment = "<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'attach') . "'>";
					}
					else
					{
						$attachment = '';
					}
	
					$query = $this->bo->query? '&query=' . urlencode($this->bo->query) : '';
					$this->path = ''; // have always to reset this before calling category_path()
					$category_path = $this->category_path($article_preview['cat_id']);
					$this->t->set_var(array(
						'art_num'		=> $article_preview['art_id'],
						'art_href'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_preview['art_id'] . $query),
						'art_title'		=> $article_preview['title'],
						'art_date'		=> $GLOBALS['egw']->common->show_date($article_preview['modified'], $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' H:i'),
						'img_stars'		=> $img_stars,
						'attachment'	=> $attachment,
						'art_category'	=> $category_path? lang('in %1', $category_path) : '',
						'art_topic'		=> $article_preview['topic']
					));
					$this->t->parse('articles', 'articles_block', True);
				}
			}
			$this->t->set_var('lang_articles', $lang_articles);

			// *** SHOW LATEST ARTICLES LIST *** 
			if (!$articles_latest = $this->bo->return_latest_mostviewed($category_passed, 'created'))
			{
				$this->t->set_var('articles_latest', "<tr><td colspan=2 align=center><br>----- " . lang('None') . " -----</td></tr>");
			}

			for ($i=0; $i<sizeof($articles_latest); $i++)
			{
				$unpublished = $articles_latest[$i]['published']? '' : '(' . lang('unpublished') . ')';
				$this->path = '';
				$category_path = $this->category_path($articles_latest[$i]['cat_id']);
				$this->t->set_var(array(
					'line_num'		=> $i+1,
					'art_href'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $articles_latest[$i]['art_id']),
					'art_title'		=> $articles_latest[$i]['title'],
					'unpublished'	=> $unpublished,
					'art_date'		=> $GLOBALS['phpgw']->common->show_date($articles_latest[$i]['created'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']),
					'art_category'	=> $category_path? lang('in %1', $category_path) : ''
				));
				$this->t->parse('articles_latest', 'articles_latest_block', True);
			}
			$this->t->set_var('lang_latest', lang('Latest'));

			// *** SHOW MOST POPULAR ARTICLES LIST *** 
			if (!$most_viewed= $this->bo->return_latest_mostviewed($category_passed, 'views'))
			{
				$this->t->set_var('articles_mostviewed', "<tr><td colspan=2 align=center><br>----- " . lang('None') . " -----</td></tr>");
			}

			for ($i=0; $i<sizeof($most_viewed); $i++)
			{
				$unpublished = $most_viewed[$i]['published']? '' : '(' . lang('unpublished') . ')';
				$this->path = '';
				$this->t->set_var(array(
					'line_num'		=> $i+1,
					'art_href'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $most_viewed[$i]['art_id']),
					'art_title'		=> $most_viewed[$i]['title'],
					'unpublished'	=> $unpublished,
					'art_category'	=> $this->category_path($most_viewed[$i]['cat_id']),
					'art_views'		=> $most_viewed[$i]['views']
				));
				$this->t->parse('articles_mostviewed', 'articles_mostviewed_block', True);
			}
			$this->t->set_var(array(
				'lang_most_viewed'	=> lang('Most viewed'),
				'lang_views'		=> lang('views')
			));

			// *** SHOW UNANSWERED QUESTIONS *** 
			if (!$unanswered_questions = $this->bo->unanswered_questions($category_passed))
			{
				$this->t->set_var('unanswered_questions', "<tr><td colspan=2 align=center><br>----- " . lang('None') . " -----</td></tr>");
			}

			foreach ($unanswered_questions as $unanswered)
			{
				$this->path = '';
				$category_path = $this->category_path($unanswered['cat_id']);
				$this->t->set_var(array(
					'art_href'				=> $this->link(array('menuaction' => 'phpbrain.uikb.edit_article', 'q_id' => $unanswered['question_id'])),
					'art_title'				=> $unanswered['summary'],
					'who'					=> $unanswered['username'],
					'unanswered_category'	=> $category_path? lang('in %1', $category_path) : ''
				));
				$this->t->parse('unanswered_questions', 'unanswered_questions_block', True);
			}

			$more_questions = '';
			if ($this->bo->num_questions > $this->bo->preferences['num_lines'])
			{
				$more_questions = "<div style='text-align:right; padding-top:10px'><a href='" . $this->link('menuaction=phpbrain.uikb.maintain_questions') . "'>" . lang('See more questions...') . "</a></div>";
			}
			$this->t->set_var(array(
				'lang_unanswered'	=> lang('Unanswered questions'),
				'more_questions'	=> $more_questions
			));
			
			if ($this->sitemgr)
			{
				return $this->t->parse('out', 'main');
			}
			else
			{
				$this->t->pparse('output', 'main');
			}
		}

		/**
		* Shows advanced search form, that is posted to function index to handle the search
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	Returns output string if accessed through sitemgr
		*/
		function advsearch()
		{
			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}
			$this->t->set_file('search_form', 'adv_search.tpl');
			
			$this->t->set_var(array(
				'row_on'			=> $GLOBALS['phpgw_info']['theme']['row_on'],
				'row_off'			=> $GLOBALS['phpgw_info']['theme']['row_off'],
				'lang_advanced_search' => lang('Advanced Search'),
				'lang_find'			=> lang('Find results'),
				'lang_all_words'	=> lang('With all the words'),
				'lang_phrase'		=> lang('With the exact phrase'),
				'lang_one_word'		=> lang('With at least one of the words'),
				'lang_without_word'	=> lang('Without the words'),
				'lang_show_cats'	=> lang('Show messages in category'),
				'lang_all'			=> lang('all'),
				'lang_include_subs'	=> lang('Include subcategories'),
				'lang_pub_date'		=> lang('Publication date'),
				'lang_anytime'		=> lang('anytime'),
				'lang_3_months'		=> lang('past %1 months', 3),
				'lang_6_months'		=> lang('past %1 months', 6),
				'lang_past_year'	=> lang('past year'),
				'lang_ocurrences'	=> lang('Ocurrences'),
				'lang_anywhere'		=> lang('Anywhere in the article'),
				'lang_in_title'		=> lang('in the title'),
				'lang_in_topic'		=> lang('in the topic'),
				'lang_in_text'		=> lang('in the text'),
				'lang_num_res'		=> lang('Number of results per page'),
				'lang_user_prefs'	=> lang('User preferences'),
				'lang_order'		=> lang('Order results by'),
				'lang_created'		=> lang('Creation date'),
				'lang_artid'		=> lang('Article ID'),
				'lang_title'		=> lang('title'),
				'lang_user'			=> lang('user'),
				'lang_modified'		=> lang('Modification date'),
				'lang_desc'			=> lang('Descendent'),
				'lang_asc'			=> lang('Ascendent'),
				'lang_search'		=> lang('search'),
				'form_action'		=> $this->link('menuaction=phpbrain.uikb.index'),
				'select_categories'	=> $this->bo->categories_obj->formatted_list('select', 'all', '', True)
			));
			if ($this->sitemgr)
			{
				return $this->t->parse('out', 'search_form');
			}
			else
			{
				$this->t->pparse('output', 'search_form');
			}
		}

		/**
		* Shows article details
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	Returns output string if accessed through sitemgr
		*/
		function view_article()
		{
			$article_id		= (int)get_var('art_id', 'GET', 0);
			$more_comments	= (int)get_var('more_comments', 'GET', 0);
			if ($_GET['printer'] || $_GET['mail'])
			{
				$print_view = True;
			}
			else
			{
				$print_view = False;
			}
			$article		= $this->bo->get_article($article_id);
			//echo "article: <pre>";print_r($article);echo  "</pre>";

			if (!$article_id || !$article) $this->die_peacefully("Error retrieving article");
			$can_edit = $this->bo->check_permission($this->bo->edit_right)? True : False;

			// Process article deletion
			if ($_POST['delete_article'])
			{
				$message = $this->bo->delete_article($article['files']);
				$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.index&message=' . $message);
				die();
			}

			// Process article publication
			if ($_POST['publish_article'])
			{
				$message = $this->bo->publish_article();
				$this->reload_page($article_id, $message);
				die();
			}

			// Process comment publication
			if ($_GET['pub_com'])
			{
				$message = $this->bo->publish_comment();
				$this->reload_page($article_id, $message);
				die();
			}

			// Process comment deletion
			if ($_GET['del_comm'])
			{
				$message = $this->bo->delete_comment();
				$this->reload_page($article_id, $message);
				die();
			}

			// Process comment and rating
			if ($_POST['comment_box'] || $_POST['Rate'])
			{
				$message = '';
				if ($_POST['comment_box'])
				{
					if (!$message = $this->bo->add_comment()) $this->die_peacefully('Comment could not be inserted in the database');
				}
				if ($_POST['Rate'])
				{
					$valid_rates = array(1,2,3,4,5);
					if (!$data = $GLOBALS['phpgw']->session->appsession('ratings', 'phpbrain')) $data = array();
					if (($this->bo->user_has_voted() && !$this->sitemgr) || in_array($article['art_id'], $data) || !in_array($_POST['Rate'], $valid_rates))
						$this->die_peacefully('Rating invalid');
					if (!$this->bo->add_rating($article['votes_' . $_POST['Rate']], $this->sitemgr)) $this->die_peacefully('Unable to add rating to database');
					switch($message)
					{
						case 'comm_ok':
							$message = 'comm_rate_ok';
							break;
						case 'comm_submited':
							$message = 'comm_rate_submited';
							break;
						default:
							$message = 'rate_ok';
							break;
					}
				}
				$this->reload_page($article_id, $message);
				die();
			}

			// Process file upload
			if ($_FILES)
			{
				$message = $this->bo->process_upload();
				$this->reload_page($article_id, $message);
				die();
			}
			// Process file deletion
			if ($_GET['delete_file'])
			{
				$message = $this->bo->delete_file($article['files']);
				$this->reload_page($article_id, $message);
				die();
			}

			// Process related articles added
			if ($_POST['update_related'] && !empty($_POST['related_articles']))
			{
				$message = $this->bo->add_related();
				$this->reload_page($article_id, $message);
				die();
			}
			// Process related articles deletion
			if ($_GET['delete_related'])
			{
				$this->bo->delete_related();
				$this->reload_page($article_id, 'del_rel_ok');	// I think there's no way of telling a deletion went wrong... (affected rows=0 always)
				die();
			}

			// Process links added
			if ($_POST['submit_link'])
			{
				$message = $this->bo->add_link();
				$this->reload_page($article_id, $message);
				die();
			}
			// Process links deletion
			if ($_GET['delete_link'])
			{
				$message = $this->bo->delete_link();
				$this->reload_page($article_id, $message);
				die();
			}

			// *** SHOW ARTICLE ***
			if ($print_view)
			{
				// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
				header('Content-type: text/html; charset='.$GLOBALS['egw']->translation->charset());
				ob_end_flush();

				$this->t->set_file('view_article', 'print_article.tpl');
				$this->t->set_block('view_article', 'file_item_block', 'file_item');
				$this->t->set_block('view_article', 'file_block', 'file');
				$this->t->set_block('view_article', 'related_article_block', 'related_article');
				$this->t->set_block('view_article', 'related_block', 'related');
				$this->t->set_block('view_article', 'links_block', 'links');
				$this->t->set_block('view_article', 'show_links_block', 'show_links');
			}
			else
			{
				$this->t->set_file('view_article', 'view_article.tpl');
				$this->t->set_block('view_article', 'easy_question_block', 'easy_question');
				$this->t->set_block('view_article', 'comment_block', 'comment');
				$this->t->set_block('view_article', 'comment_form_block', 'comment_form');
				$this->t->set_block('view_article', 'rating_graph_block', 'rating_graph');
				$this->t->set_block('view_article', 'rating_form_block', 'rating_form');
				$this->t->set_block('view_article', 'file_item_block', 'file_item');
				$this->t->set_block('view_article', 'file_upload_block', 'file_upload');
				$this->t->set_block('view_article', 'related_article_block', 'related_article');
				$this->t->set_block('view_article', 'related_article_add_block', 'related_article_add');
				$this->t->set_block('view_article', 'links_block', 'links');
				$this->t->set_block('view_article', 'links_add_block', 'links_add');
				$this->t->set_block('view_article', 'img_delete_block', 'img_delete');
				$this->t->set_block('view_article', 'edit_del_block', 'edit_del');
				$this->t->set_block('view_article', 'publish_btn_block', 'publish_btn');
				$this->t->set_block('view_article', 'history_line_block', 'history_line');

				if (!$this->sitemgr)
				{
					// $GLOBALS['phpgw_info']['flags']['css'] = $this->tabs_css();	Don't use this 'cause incompatible with sitemgr
					if(!@is_object($GLOBALS['phpgw']->js))
					{
						$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
					}
					$GLOBALS['phpgw']->js->validate_file('tabs','tabs');
					$GLOBALS['phpgw']->js->set_onload('tab.init();');
					$GLOBALS['phpgw_info']['flags']['java_script_thirst'] = "<script>function openpopup() {window1=window.open('" . $this->link('menuaction=phpbrain.uikb.pop_search') . "', 'Search', 'width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes');}</script>";

					$this->t->set_var('link_main_view', '');

					$GLOBALS['phpgw']->common->phpgw_header();
					echo parse_navbar();
					$this->navbar_shown = True;
				}
				else
				{
					// Since cannot use js object with sitemanager, I have to manually insert the javascript include:
					$this->t->set_var('tabs_script', $GLOBALS['phpgw']->link('/phpgwapi/js/tabs/tabs.js'));

					$this->t->set_var('link_main_view', "<a href='". $this->link('menuaction=phpbrain.uikb.index') ."'>". lang('Main View', 'phpbrain') ."</a>&nbsp;&nbsp;|<br>");
				}
			}

			$this->t->set_var(array(
				'message'				=> "<div style='text-align:center; color:red'>".$this->message."</div>",
				'mail_message'			=> '',
				'search_tpl'			=> $this->show_basic_search(),
				'lang_article'			=> lang('Article'),
				'lang_linksfiles'		=> lang('Links & Files'),
				'lang_history'			=> lang('History'),
				'lang_category'			=> lang('Category'),
				'lang_title'			=> lang('Title'),
				'lang_topic'			=> lang('Topic'),
				'lang_keywords'			=> lang('Keywords'),
				'lang_add_comments'		=> lang('If you wish, you can comment this article here'),
				'lang_please_rate'		=> lang('Please rate the pertinence and quality of this article'),
				'lang_poor'				=> lang('Poor'),
				'lang_excellent'		=> lang('Excellent'),
				'lang_attached_files'	=> lang('Attached Files'),
				'lang_related_articles'	=> lang('Related Articles in the Knowledge Base'),
				'lang_links'			=> lang('Links'),
				'lang_date'				=> lang('Date'),
				'lang_user'				=> lang('User'),
				'lang_action'			=> lang('Action'),
				'lang_upload'			=> lang('upload'),
				'lang_attach_file'		=> lang('Attach file'),
				'lang_delete'			=> lang('delete'),
				'lang_confirm_delete'   => lang('Are you sure?'),
				'img_printer'			=> $GLOBALS['phpgw']->common->image('phpbrain', 'articleprint'),
				'href_printer'			=> $this->link('menuaction=phpbrain.uikb.view_article&art_id='. $article_id .'&printer=1'),
				'img_mail'				=> $GLOBALS['phpgw']->common->image('phpbrain', 'mail'),
				'img_src_del'			=> $GLOBALS['phpgw']->common->image('phpbrain', 'delete'),
				'alt_printer'			=> lang('Printer view'),
				'alt_mail'				=> lang('Mail article'),
				'href_mail'				=> $this->link('menuaction=phpbrain.uikb.mail_article&art_id='. $article_id),
				'form_article_action'	=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id),
				'form_del_action'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id),
				'url_bluedot'			=> $GLOBALS['phpgw']->common->image('phpbrain', 'bluedot')
			));

			$published = $article['published']? '' : lang("This article hasn't yet been published in the Knowledge Base");
			$lastmodif = '';
			$img_stars = '';
			if ($article['modified_username'])
			{
				$lastmodif = lang('Last modification by %1 on %2', $article['modified_username'], $GLOBALS['phpgw']->common->show_date($article['modified'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']));
			}
			// only show stars if article has been rated
			if ($article['total_votes'])
			{
				$img_stars = "<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', round($article['average_votes']) . 'stars') . "' width=50 height=10>";
			}

			// show edit and delete button if user has edit rights and he's not using sitemgr
			if (!$print_view && $can_edit && !$this->sitemgr)
			{
				$this->t->set_var(array(
					'form_edit_art'		=> $this->link('menuaction=phpbrain.uikb.edit_article&art_id=' . $article_id),
					'form_del_art'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id),
					'lang_edit_art'			=> lang('Edit article'),
					'lang_delete_article'	=> lang('Delete article')
				));
				$this->t->parse('edit_del', 'edit_del_block');
			}
			else
			{
				$this->t->set_var('edit_del', '');
			}

			// show publish button if article is unpublish and user has publish rights on owner
			if (!$print_view && !$article['published'] && ($this->bo->grants[$article['user_id']] & $this->bo->publish_right))
			{
				$this->t->set_var(array(
					'form_publish_art'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id='. $article_id),
					'lang_publish_article'	=> lang('publish')
				));
				$this->t->parse('publish_btn', 'publish_btn_block');
			}
			else
			{
				$this->t->set_var('publish_btn', '');
			}

			$this->path = '';
			$this->t->set_var(array(
				'art_id'			=> $article['art_id'],
				'lang_unpublished'	=> $published,
				'img_stars'			=> $img_stars,
				'links_cats'		=> $this->category_path($article['cat_id'], !$print_view),
				'title'				=> $article['title'],
				'topic'				=> $article['topic'],
				'keywords'			=> $article['keywords'],
				'createdby'			=> lang('Created by %1 on %2', $article['username'], $GLOBALS['phpgw']->common->show_date($article['created'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])),
				'last_modif'		=> $lastmodif,
				'content'			=> $article['text']
			));
			
			$this->t->set_var(array(
				'easy_question'			=> '',
				'lang_comments'			=> '',
				'link_more_comments'	=> '',
				'comment'				=> '',
				'comment_form'			=> '',
				'rating_form'			=> '',
				'rating_graph'			=> '',
				'submit_comment'		=> '',
				'form_article_action'	=> ''
			));

			if (!$print_view && $article['published'])
			{
				// show feedback question if article has been published, a basic search was done and this article hasn't been given any feedback on this session
				if (!$data = $GLOBALS['phpgw']->session->appsession('feedback', 'phpbrain')) $data = array();
				if ($this->bo->query && !in_array($article['art_id'], $data))
				{
					$this->t->set_var(array(
						'tr_bgcolor'			=> $GLOBALS['phpgw_info']['theme']['row_off'],
						'query'					=> $this->bo->query,
						'form_easy_q_action'	=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id),
						'lang_question_easy'	=> lang('Was it easy to find this article using the above search string?'),
						'lang_yes'				=> lang('yes'),
						'lang_no'				=> lang('no'),
						'lang_please'			=> lang('By answering this question you will help to get the answer quicker the next time')
					));
					$this->t->parse('easy_question', 'easy_question_block');
				}

				// show comments if article has been published
				$comments = $this->bo->get_comments($article_id, !$more_comments);
				foreach ($comments as $comment)
				{
					// only show unpublished comments is user has edition rights on article owner
					if (!$comment['published'] && !($this->bo->grants[$article['user_id']] & $this->bo->edit_right)) continue;
					if ($comment['published'])
					{
						$link_publish = '';
					}
					else
					{
						$link_publish = "<a href='". $this->link('menuaction=phpbrain.uikb.view_article&art_id='. $article_id .'&pub_com='. $comment['comment_id']) ."'>" . lang('publish') . "</a>";
					}

					// user can delete comment if he has edition rights and didn't enter through sitemgr
					if (!$this->sitemgr && ($this->bo->grants[$article['user_id']] & $this->bo->edit_right))
					{
						$link_delete = "<a href='". $this->link('menuaction=phpbrain.uikb.view_article&art_id='. $article_id . '&del_comm='. $comment['comment_id']) ."'>". lang('delete') ."</a>";
					}
					else
					{
						$Link_delete = '';
					}

					$this->t->set_var(array(
						'comment_date'		=> $GLOBALS['phpgw']->common->show_date($comment['entered'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']),
						'comment_user'		=> $comment['username'],
						'link_publish'		=> $link_publish,
						'link_delete'		=> $link_delete,
						'comment_content'	=> $comment['comment']
					));
					$this->t->parse('comment', 'comment_block', True);
				}
				$lang_comments = lang('Comments');
				if (!$more_comments && $this->preferences['num_comments'] != 'All' && $this->bo->num_comments > $this->bo->preferences['num_comments'])
				{
					$link_more_comments = "<a href='" . $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id . '&more_comments=1') . "'>" . lang('Show all comments') . "</a>";
					$lang_comments = lang('Latest comments');
				}
				$this->t->parse('comment_form', 'comment_form_block');
				$this->t->set_var(array(
					'link_more_comments'	=> $link_more_comments,
					'lang_comments'			=> $lang_comments
				));

				// setup voting form if article has been published and (user has not voted already or accessed through sitemgr) and has not voted this article in this session
				if (!$data = $GLOBALS['phpgw']->session->appsession('ratings', 'phpbrain')) $data = array();
				if (($this->bo->user_has_voted($article_id) && !$this->sitemgr) || in_array($article['art_id'], $data))
				{
					$this->t->set_var(array(
						'rating_form'			=> lang('You have already qualified this article'),
						'submit_comment'		=> "<tr><td colspan=7 align=left><br><input type=submit name='comment' value='". lang('Submit comment') . "'></td></tr>",
					));
				}
				else
				{
					$this->t->set_var('submit_comment', "<tr><td colspan=7 align=left><br><input type=submit name='comment' value='". lang('Submit comment and rating') . "'></td></tr>");
					$this->t->parse('rating_form', 'rating_form_block');
				}

				// setup voting graph if article has been published
				if ($article['votes_1'] != 0 || $article['votes_2'] != 0 || $article['votes_3'] != 0 || $article['votes_4'] != 0 || $article['votes_5'] != 0)
				{
					// normalize vote frequency to range 0 - 40
					$max_vote = max($article['votes_1'], $article['votes_2'], $article['votes_3'], $article['votes_4'], $article['votes_5']);
					for ($i=1; $i<=5; $i++)
					{
						$this->t->set_var('bar_' . $i, $article['votes_' . $i] / $max_vote *40);
					}
					$this->t->set_var(array(
						'lang_average'	=> lang('Average rating'),
						'average_rating'=> sprintf("%01.1f", $article['average_votes']),
						'numpeople'		=> $article['total_votes'],
						'lang_people'	=> lang('people have rated this article')
					));
					$this->t->parse('rating_graph', 'rating_graph_block', True);
				}
				else
				{
					$this->t->set_var('rating', lang('Nobody has rated this article so far'));
				}
			}

			// show file list
			if (!$article['files'])
			{
				$this->t->set_var($print_view? 'file' : 'file_item', '');
			}
			else
			{	
				foreach ($article['files'] as $file)
				{
					ereg('^kb[0-9]*-(.*)', $file['file'], $new_filename);
					if (!$this->sitemgr && !$print_view && $can_edit)
					{
						$this->t->set_var(array(
							'href_del'	=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id . '&delete_file=' . urlencode($file['file'])),
						));
						$this->t->parse('img_delete', 'img_delete_block');
					}
					else
					{
						$this->t->set_var('img_delete', '');
					}
					$this->t->set_var(array(
						'file_name'		=> $new_filename[1],
						'file_comment'	=> $file['comment'],
						'href_file'		=>	$this->link('menuaction=phpbrain.uikb.download_file&art_id=' . $article_id . '&file=' . urlencode($file['file']))
					));
					$this->t->parse('file_item', 'file_item_block', True);
				}
				if ($print_view) $this->t->parse('file', 'file_block');
			}
			// show upload form if user has edition rights and is not in sitemgr
			if (!$this->sitemgr && !$print_view && $can_edit)
			{
				$this->t->set_var(array(
					'form_file_action'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id),
					'lang_attach_file'		=> lang('Attach File'),
					'lang_comment'			=> lang('comment'),
					'lang_upload'			=> lang('Upload')
				));
				$this->t->parse('file_upload', 'file_upload_block');
			}
			else
			{
				$this->t->set_var('file_upload', '');
			}

			// show related articles list
			if (!$related_articles = $this->bo->get_related_articles($article_id))
			{
				$this->t->set_var($print_view? 'related' : 'related_article', '');
			}
			else
			{
				foreach ($related_articles as $related)
				{
					if (!$this->sitemgr && !$print_view && $can_edit)
					{
						$this->t->set_var(array(
							'href_del'	=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id . '&delete_related=' . urlencode($related['art_id'])),
						));
						$this->t->parse('img_delete', 'img_delete_block');
					}
					else
					{
						$this->t->set_var('img_delete', '');
					}
					$this->t->set_var(array(
						'related_id'		=> $related['art_id'],
						'href_related'		=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $related['art_id']),
						'title_related'		=> $related['title']
					));
					$this->t->parse('related_article', 'related_article_block', True);
				}
				if ($print_view) $this->t->parse('related', 'related_block');
			}
			// show add new article if user has edition rights and is not in sitemgr
			if (!$this->sitemgr && !$print_view && $can_edit)
			{
				$this->t->set_var(array(
					'lang_add_related'		=> lang('Add articles'),
					'lang_select_articles'	=> lang('Select articles'),
					'lang_clear'			=> lang('clear'),
					'lang_update'			=> lang('update'),
					'form_add_article_action' => $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id)
				));
				$this->t->parse('related_article_add', 'related_article_add_block');
			}
			else
			{
				$this->t->set_var('related_article_add', '');
			}

			// show links
			if (!$links = $article['urls'])
			{
				$this->t->set_var('links', '');
				$this->t->set_var('show_links', '');
			}
			else
			{
				foreach ($article['urls'] as $link)
				{
					if (!$this->sitemgr && !$print_view && $can_edit)
					{
						$this->t->set_var(array(
							'href_del'	=> $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id . '&delete_link=' . urlencode($link['link'])),
						));
						$this->t->parse('img_delete', 'img_delete_block');
					}
					else
					{
						$this->t->set_var('img_delete', '');
					}
					// if protocol not set, add it
					if (!ereg('://', $link['link'])) $link['link'] = 'http://' . $link['link'];

					if (!$link['title']) $link['title'] = $link['link'];
					$this->t->set_var(array(
						'href_link'		=> $link['link'],
						'title_link'	=> $link['title']
					));
					$this->t->parse('links', 'links_block', True);
				}
				if ($print_view) $this->t->parse('show_links', 'show_links_block');
			}
			// show add new link if user has edition rights and is not in sitemgr
			if (!$this->sitemgr && !$print_view && $this->bo->check_permission($can_edit))
			{
				$this->t->set_var(array(
					'lang_add_link'		=> lang('Add link'),
					'lang_title'		=> lang('title'),
					'lang_update'		=> lang('Update'),
					'form_add_link_action' => $this->link('menuaction=phpbrain.uikb.view_article&art_id=' . $article_id)
				));
				$this->t->parse('links_add', 'links_add_block');
			}
			else
			{
				$this->t->set_var('links_add', '');
			}

			// Show history
			if ($print_view || !$history = $this->bo->return_history())
			{
				$this->t->set_var('history_line', '');
			}
			else
			{
				foreach ($history as $event)
				{
					$this->t->set_var(array(
						'tr_color'			=> $this->nextmatchs->alternate_row_color($tr_color),
						'history_date'		=> $event['datetime'],
						'history_user'		=> $event['owner'],
						'history_action'	=> $event['action']
					));
					$this->t->parse('history_line', 'history_line_block', True);
				}
			}

			$this->t->set_var('img_delete', '');
			if ($_GET['mail'])
			{
				$this->t->set_var('mail_message', $_POST['val_message']);
				$this->t->parse('plain_html', 'view_article');
				$message = $this->bo->mail_article($this->t->get_var('plain_html'));
				$this->reload_page($article_id, $message);
				die();
			}
			elseif ($this->sitemgr && !$print_view)
			{
				return $this->t->parse('out', 'view_article');
			}
			else
			{
				$this->t->pparse('output', 'view_article');
			}
		}

		/**
		* Mails article
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	When showing form, returns string output if acccess through sitemgr
		*/
		function mail_article()
		{
			$article_id = (int)get_var('art_id', 'GET', 0);

			$recipient = '';
			$subject = lang('Knowledge Base article #%1', $article_id);
			$reply = '';
			$message = '';

			$this->t->set_file('mail_form', 'mail_article.tpl');
			$this->t->set_var(array(
				'form_action'		=> $this->link('menuaction=phpbrain.uikb.view_article&mail=1&art_id='. $article_id),
				'row_on'			=> $GLOBALS['phpgw_info']['theme']['row_on'],
				'row_off'			=> $GLOBALS['phpgw_info']['theme']['row_off'],
				'lang_recipient'	=> lang('Recipient'),
				'val_recipient'		=> $recipient,
				'lang_subject'		=> lang('Subject'),
				'val_subject'		=> $subject,
				'lang_reply'		=> lang('Reply-to'),
				'val_reply'			=> $reply,
				'lang_message'		=> lang('Message'),
				'val_message'		=> $message,
				'lang_send'			=> lang('send')
			));

			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}

			if ($this->sitemgr)
			{
				return $this->t->parse('out', 'mail_form');
			}
			else
			{
				$this->t->pparse('out', 'mail_form');
			}
		}

		/**
		* Shows popup windows with articles table
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	void
		*/
		function pop_search()
		{
			$actual_category			= (int)get_var('cat', 'GET', 0);
			$this->bo->sort				= get_var('sort', 'any', 'ASC');
			$this->bo->order			= get_var('order', 'any', 'title');
			$this->bo->query			= get_var('query', 'any', '');
			$this->bo->load_categories(0);
			$articles_list = $this->bo->search_articles($actual_category);
			$this->t->set_file('popup', 'popup_search.tpl');
			$this->t->set_block('popup', 'table_row_block', 'table_row');
			$this->t->set_var(array(
				'lang_category'		=> lang('Category'),
				'lang_all'			=> lang('All'),
				'lang_search'		=> lang('Search'),
				'lang_select'		=> lang('Select'),
				'th_color'			=> $GLOBALS['phpgw_info']['theme']['th_bg'],
				'value_query'		=> $this->bo->query,
				'form_select_articles_action' => $this->link('menuaction=phpbrain.uikb.pop_search'),
				'form_filters_action' => $this->link('menuaction=phpbrain.uikb.pop_search&start=' . $this->bo->start . '&sort=' . $this->bo->sort),
				'head_number'		=> $this->nextmatchs->show_sort_order($this->bo->sort, 'art_id', $this->bo->order, '', lang('Article ID')),
				'head_title'		=> $this->nextmatchs->show_sort_order($this->bo->sort, 'title', $this->bo->order, '', lang('Title')),
				'left'				=> $this->nextmatchs->left($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.pop_search&query=' . $this->bo->query),
				'right'				=> $this->nextmatchs->right($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.pop_search&query=' . $this->bo->query),
				'num_regs'			=> $this->nextmatchs->show_hits($this->bo->num_rows, $this->bo->start),
				'select_categories'	=> $this->bo->categories_obj->formatted_list('select', 'all', '', True)
			));

			foreach ($articles_list as $article)
			{
				$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
				$this->t->set_var(array(
					'tr_color'		=> $tr_color,
					'number'		=> $article['art_id'],
					'title'			=> $article['title'],

				));
				$this->t->parse('table_row', 'table_row_block', True);
			}

			$this->t->pparse('output', 'popup');
		}

		/**
		* New articles (answering questions or just new) and edit existing articles
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	void
		*/
		function edit_article()
		{
			$this->t->set_file('edit_article', 'edit_article.tpl');
			$this->t->set_block('edit_article', 'answer_question_block', 'answer_question');
			$this->t->set_block('edit_article', 'article_id_block', 'article_id');
			
			$this->t->set_var(array(
				'lang_articleID'		=> lang('Article ID'),
				'lang_category'			=> lang('Category'),
				'lang_none'				=> lang('None'),
				'lang_title'			=> lang('Title'),
				'lang_topic'			=> lang('Topic'),
				'lang_keywords'			=> lang('Keywords'),
			));

			// These are the default values, that apply for entering a new article
			$article_id			= (int)get_var('art_id', 'any', 0);
			$title				= '';
			$topic				= '';
			$keywords			= '';
			$content			= '';
			$category_selected	= '';
			$hidden_fields		= '';
			$btn_save			= "<input type='submit' value='". lang('Save') . "' name='save'>&nbsp;";
			$btn_cancel			= "<input type='submit' value='". lang('Cancel') . "' name='cancel'>";
			$extra				= '';
			$this->t->set_var(array(
				'answer_question'	=> '',
				'article_id'		=> '',
				));

			// saving either an edited or a new article (answering a question or just a new article)
			if ($_POST['save'])
			{
				$article_id = (int)get_var('editing_article_id', 'POST', 0);
				$article	= ($article_id)? $this->bo->get_article($article_id) : false;

				//data validation
				if (!$_POST['title'])
				{
					$this->message .= lang('You must enter a title') . '<br>';
				}
				if (!$_POST['topic'])
				{
					$this->message .= lang('You must enter a topic') . '<br>';
				}
				if (!$_POST['exec']['text'])
				{
					$this->message .= lang('The article is empty') . '<br>';
				}
				
				if ($this->message)
				{
					$this->message .= '<br>' . lang('Please try again');
				}
				elseif ($edited_art = $this->bo->save_article())
				{
					// if article is new tell to insert files and stuff
					$message = '';
					if (!$article) $message = '&message=add_ok_cont&tabpage=2';
					$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.view_article&art_id=' .  $edited_art . $message);
					die();
				}
				else
				{
					$this->message = $this->bo->error_msg;
				}
			}

			// if an error ocurred fill fields with values
			if ($this->message)
			{
				$category_selected	= (int)get_var('cat_id', 'POST', 0);
				$title				= get_var('title', 'POST', '');
				$topic				= get_var('topic', 'POST', '');
				$keywords			= get_var('keywords', 'POST', '');
				$temp = get_var('exec', 'POST', '');
				$content = $temp['text'];
			}

			// Edit existant article
			if ((int)get_var('art_id', 'GET', 0))
			{
				// Process cancel button
				if ($_POST['cancel'])
				{
					$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.view_article&art_id=' .  $_GET['art_id']);
					die();
				}

				if (!$this->message)
				{
					$article	= $this->bo->get_article($article_id);

					// Check edit rights
					if (!$this->bo->check_permission($this->bo->edit_right)) $this->die_peacefully('You have not the proper permissions to do that');

					$title		= $article['title'];
					$topic		= $article['topic'];
					$keywords	= $article['keywords'];
					$content	= $article['text'];
					$category_selected = $article['cat_id'];
				}

				$this->t->set_var(array(
					'show_articleID'	=> $article_id . "<input type=hidden name='editing_article_id' value=" . $article_id . ">",
				));
				$this->t->parse('article_id', 'article_id_block');
			}

			// answering a question
			if ((int)get_var('q_id', 'GET', 0))
			{
				// Process cancel button
				if ($_POST['cancel'])
				{
					$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.index');
					die();
				}
				$q_id = (int)get_var('q_id', 'GET', 0);
				$question = $this->bo->get_question($q_id);
				$hidden_fields .= "<input type=hidden name='answering_question' value='" . $q_id . "'>";
				$this->t->set_var(array(
					'lang_summary'			=> lang('Summary'),
					'lang_details'			=> lang('Details'),
					'lang_category'			=> lang('Suggested category'),
					'lang_head_question'	=> lang('Create a new article to answer the question asked by %1 in %2', $question['username'], $question['creation']),
					'question_summary'		=> $question['summary'],
					'question_details'		=> $question['details']
				));
				$this->t->parse('answer_question', 'answer_question_block');

				$title = $question['summary'];
				$category_selected = $question['cat_id'];
			}
			
			if (!is_object($GLOBALS['egw']->html))
			{
				require_once(EGW_API_INC.'/class.html.inc.php');
				$GLOBALS['egw']->html = new html;
			}
			
			$content = $GLOBALS['egw']->html->fckEditor('exec[text]', $content, $GLOBALS['egw_info']['user']['preferences']['phpbrain']['rtfEditorFeatures'],array('toolbar_expanded' =>'true'),'400px','100%',$this->bo->admin_config['upload_dir'] ? $this->bo->admin_config['upload_dir'] : null);
	
			// Finally, fill the input fields
			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}

			$select_category = $this->bo->select_category($category_selected);
			$this->t->set_var('select_category', $select_category);

			if ((int)get_var('art_id', 'GET', 0))
			{
				$extra .= '&art_id='. $_GET['art_id'];
			}
			elseif((int)get_var('q_id', 'GET', 0))
			{
				$extra .= '&q_id='. $_GET['q_id'];
			}

			$this->t->set_var(array(
				'message'			=> "<tr><td colspan=2 align=center style='color:red'>" . $this->message . "</td></tr>",
				'hidden_fields'		=> $hidden_fields,
				'form_action'		=> $this->link('menuaction=phpbrain.uikb.edit_article'. $extra),
				'value_title'		=> htmlspecialchars($title),
				'value_topic'		=> htmlspecialchars($topic),
				'value_keywords'	=> htmlspecialchars($keywords),
				'value_text'		=> $content,
				'btn_save'			=> $btn_save,
				'btn_cancel'		=> $btn_cancel
			));

			$this->t->pparse('output', 'edit_article');
		}

		/**
		* Adds question to knowledge base.
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	When showing form, returns string output if acccess through sitemgr
		**/
		function add_question()
		{
			// if in sitemgr, check that questions can be added
			if ($this->sitemgr && !$this->allow_questions) $this->die_peacefully('You have not the proper permissions to do that');
			if ($_POST['submit'])
			{
				$this->bo->add_question();
				$GLOBALS['phpgw']->redirect($this->link('menuaction=phpbrain.uikb.index'));	// don't use redirect_link cause it ain't work in sitemgr
				end;
			}

			$this->t->set_file('question_form', 'question.tpl');
			$message = '';

			if ($this->bo->admin_config['publish_questions'] == 'True')
			{
				$lang_posting_process = 'Your question will be published immediately';
			}
			else
			{
				$lang_posting_process = 'Your question will be posted, but will only be published after approval by a user with publishing rights';
			}

			$this->t->set_var(array(
				'null'					=> '',
				'message'				=> $message,
				'lang_search_kb'		=> lang('Before submiting a question, please search in the knowledge base first'),
				'lang_enter_words'		=> lang('Enter one or two words describing the issue, or type the article number if you know it'),
				'lang_search'			=> lang('Search'),
				'lang_advanced_search'	=> lang('Advanced Search'),
				'lang_post_question'	=> lang("If you can't find answers to your problem in the knowledge base, describe it below"),
				'lang_summary'			=> lang('Summary'),
				'lang_details'			=> lang('Details'),
				'lang_select_cat'		=> lang('category'),
				'lang_submit'			=> lang('Submit'),
				'lang_cancel'			=> lang('Cancel'),
				'lang_none'				=> lang('none'),
				'posting_process'		=> lang($lang_posting_process),
				'form_search_action'	=> $this->link('menuaction=phpbrain.uikb.index'),
				'form_question_action'	=> $this->link('menuaction=phpbrain.uikb.add_question'),
				'link_adv_search'		=> $this->link('menuaction=phpbrain.uikb.advsearch')
				));

			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}

			$select_category = $this->bo->select_category();
			$this->t->set_var('select_category', $select_category);

			if ($this->sitemgr)
			{
				return $this->t->parse('out', 'question_form');
			}
			else
			{
				$this->t->pparse('output', 'question_form');
			}
		}

		/**
		* Article maintenance view
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	void
		*/
		function maintain_articles()
		{
			$actual_category = (int)get_var('cat', 'any', 0);

			if (!$this->bo->order) $this->bo->order = 'created';
			if (!$this->bo->sort) $this->bo->sort = 'DESC';
			
			$this->bo->load_categories($actual_category);

			// obtain articles to which one has any kind of permission
			$articles_list = $this->bo->search_articles($actual_category, $this->bo->publish_filter, $this->bo->read_right | $this->bo->edit_right | $this->bo->publish_right);
			//echo "articles_list: <pre>";print_r($articles_list);echo "</pre>";

			// Process article deletion
			if ($_GET['delete'] || $_POST['delete_selected'])
			{
				if ($_GET['delete'])
				{
					$selected = array($_GET['delete'] => '');
				}
				else
				{
					$selected = $_POST['select'];
				}
				$errors = False;
				foreach ($selected as $art_id => $trash)
				{
					$target_art = array();
					foreach($articles_list as $article)
					{
						if ($article['art_id'] == $art_id)
						{
							$target_art = $article;
							break;
						}
					}
					$message = $this->bo->delete_article($target_art['files'], $target_art['art_id'], $target_art['user_id']);
					if ($message != 'del_art_ok') $errors = $message;
				}
				if (!$errors)
				{
					$message = $_GET['delete']? 'del_art_ok' : 'del_arts_ok';
				}
				$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.maintain_articles&message=' . $message);
				die();
			}

			// Process article publication
			if ($_GET['publish'] || $_POST['publish_selected'])
			{
				if ($_GET['publish'])
				{
					$selected = array($_GET['publish'] => '');
				}
				else
				{
					$selected = $_POST['select'];
				}
				$errors = False;
				foreach ($selected as $art_id => $trash)
				{
					$target_art = array();
					foreach ($articles_list as $article)
					{
						if ($article['art_id'] == $art_id)
						{
							$target_art = $article;
							break;
						}
					}
					$message = $this->bo->publish_article($target_art['art_id'], $target_art['user_id']);
					if ($message != 'publish_ok') $errors = $message;
				}
				if (!$errors)
				{
					$message = $_GET['publish']? 'publish_ok' : 'publishs_ok';
				}
				$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.maintain_articles&message=' . $message);
				die();
			}

			// Show table
			$this->t->set_file('maintain_articles', 'maintain_articles.tpl');
			$this->t->set_block('maintain_articles', 'table_row_block', 'table_row');
			$this->t->set_var('table_row', '');

			if ($articles_list)
			{
				foreach ($articles_list as $article)
				{
					$actions = '';

					// skip if article unpublished, user has no publish right on owner and user!=owner
					if (!$article['published'] && !($this->bo->grants[$article['user_id']] & $this->bo->publish_right) && $article['user_id']!=$GLOBALS['phpgw_info']['user']['account_id']) continue;

					$actions = "<a href='". $this->link('menuaction=phpbrain.uikb.view_article&art_id='. $article['art_id']) ."'>
								<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'view') . "' title='". lang('view')  ."'>
								</a>";
					if (!$article['published'] && ($this->bo->grants[$article['user_id']] & $this->bo->publish_right))
					{
						$actions .= "<a href='". $this->link('menuaction=phpbrain.uikb.maintain_articles&publish='. $article['art_id']  .'&order='. $this->bo->order .'&sort='. $this->bo->sort .'&query='. $this->bo->query) ."'>
											<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'new') . "' title='". lang('publish')  ."'>
											</a>";
					}
					if ($this->bo->grants[$article['user_id']] & $this->bo->edit_right)
					{
						$actions .= "<a href='". $this->link('menuaction=phpbrain.uikb.maintain_articles&delete='. $article['art_id']  .'&order='. $this->bo->order .'&sort='. $this->bo->sort .'&query='. $this->bo->query). "'>
											<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'delete') . "' title='" . lang('delete') . "'>
											</a>";
					}
					$this->t->set_var(array(
						'tr_color'			=> $this->nextmatchs->alternate_row_color($tr_color),
						'title'				=> $article['title'],
						'topic'				=> $article['topic'],
						'author'			=> $article['username'],
						'date'				=> $GLOBALS['phpgw']->common->show_date($article['modified'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']),
						'actions'			=> $actions,
						'name_checkbox'		=> 'select[' . $article['art_id']  . ']'
					));
					$this->t->parse('table_row', 'table_row_block', True);
				}
			}
			else
			{
				$this->t->set_var('table_row', '<tr bgcolor="'. $this->nextmatchs->alternate_row_color($tr_color) .'"><td colspan="5" align="center">'. lang('There are no articles available') .'</td></tr>');
			}

			$select_publish = "<option value='all'";
			if ($this->bo->publish_filter == 'all') $select_publish .= ' selected';
			$select_publish .= ">" . lang('All') . "</option><option value='unpublished'";
			if ($this->bo->publish_filter == 'unpublished') $select_publish .= ' selected';
			$select_publish .= ">" . lang('unpublished') . "</option><option value='published'";
			if ($this->bo->publish_filter == 'published') $select_publish .= ' selected';
			$select_publish .= '>' . lang('Published') . '</option>';

			$GLOBALS['phpgw_info']['flags']['java_script_thirst'] = $this->javascript_check_all();

			$this->t->set_var(array(
				'message'				=> $this->message,
				'lang_actions'			=> lang('Actions'),
				'lang_search'			=> lang('Search'),
				'value_query'			=> $this->bo->query,
				'form_maintain_articles_action'=> $this->link('menuaction=phpbrain.uikb.maintain_articles'),
				'form_filters_action'	=> $this->link(array('menuaction' => 'phpbrain.uikb.maintain_articles', 'start' => $this->bo->start, 'sort' => $this->bo->sort)),
				'img_src_checkall'		=> $GLOBALS['phpgw']->common->image('phpbrain', 'check'),
				'order'					=> $this->bo->order, 
				'publish_filter'		=> $this->bo->publish_filter,
				'head_title'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'title', $this->bo->order, '', lang('Title')),
				'head_topic'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'topic', $this->bo->order, '', lang('Topic')),
				'head_author'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'user_id', $this->bo->order, '', lang('Author')),
				'head_date'				=> $this->nextmatchs->show_sort_order($this->bo->sort, 'created', $this->bo->order, '', lang('Date')),
				'left'					=> $this->nextmatchs->left($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.maintain_articles&cat='. $actual_category . '&publish_filter=' . $this->bo->publish_filter . '&query=' . $this->bo->query),
				'right'					=> $this->nextmatchs->right($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.maintain_articles&cat='. $actual_category .'&publish_filter=' . $this->bo->publish_filter . '&query=' . $this->bo->query),
				'num_regs'				=> $this->nextmatchs->show_hits($this->bo->num_rows, $this->bo->start),
				'select_categories'		=> $this->bo->categories_obj->formatted_list('select', 'all', $actual_category, True),
				'select_publish'		=> $select_publish,
				'lang_publish_selected'	=> lang('Publish selected'),
				'lang_delete_selected'	=> lang('Delete selected')
			));

			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}

			$this->t->pparse('output', 'maintain_articles');
		}

		/**
		* Question maintenance view
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	mixed	When showing form, returns string output if acccess through sitemgr
		*/
		function maintain_questions()
		{
			$actual_category = (int)get_var('cat', 'any', 0);

			if (!$this->bo->order) $this->bo->order = 'creation';
			if (!$this->bo->sort) $this->bo->sort = 'DESC';

			$this->bo->load_categories($actual_category);

			// obtain articles to which one has any kind of permission
			if ($this->sitemgr) $this->bo->publish_filter = 'published';
			$questions_list = $this->bo->search_articles($actual_category, $this->bo->publish_filter, $this->bo->read_right | $this->bo->edit_right | $this->bo->publish_right, True);
			//echo "questions_list: <pre>";print_r($questions_list);echo "</pre>";

			// Process question deletion
			if ($_GET['delete'] || $_POST['delete_selected'])
			{
				if ($_GET['delete'])
				{
					$selected = array($_GET['delete'] => '');
				}
				else
				{
					$selected = $_POST['select'];
				}
				$errors = False;
				foreach ($selected as $q_id => $trash)
				{
					$target_q = array();
					foreach($questions_list as $question)
					{
						if ($question['question_id'] == $q_id)
						{
							$target_q = $question;
							break;
						}
					}
					$message = $this->bo->delete_question($target_q['question_id'], $target_q['user_id']);
					if ($message != 'del_q_ok') $errors = $message;
				}
				if (!$errors)
				{
					$message = $_GET['delete']? 'del_q_ok' : 'del_qs_ok';
				}
				$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.maintain_questions&message=' . $message);
				die();
			}

			// Process question publication
			if ($_GET['publish'] || $_POST['publish_selected'])
			{
				if ($_GET['publish'])
				{
					$selected = array($_GET['publish'] => '');
				}
				else
				{
					$selected = $_POST['select'];
				}
				$errors = False;
				foreach ($selected as $question_id => $trash)
				{
					$target_question = array();
					foreach ($questions_list as $question)
					{
						if ($question['question_id'] == $question_id)
						{
							$target_question = $question;
							break;
						}
					}
					$message = $this->bo->publish_question($target_question['question_id'], $target_question['user_id']);
					if ($message != 'publish_ok') $errors = $message;
				}
				if (!$errors)
				{
					$message = $_GET['publish']? 'publish_ok' : 'publishs_ok';
				}
				$GLOBALS['phpgw']->redirect_link($this->link, 'menuaction=phpbrain.uikb.maintain_questions&message=' . $message);
				die();
			}

			// Show table
			$this->t->set_file('maintain_questions', 'maintain_questions.tpl');
			$this->t->set_block('maintain_questions', 'table_row_block', 'table_row');
			$this->t->set_var('table_row', '');

			foreach ($questions_list as $question)
			{
				$actions = '';
				// skip if question unpublished and user has no publish right on owner
				if (!$question['published'] && !($this->bo->grants[$question['user_id']] & $this->bo->publish_right)) continue;

				// can only attempt to answer a question if it has been published
				if ($question['published'])
				{
					$actions = "<a href='". $this->link('menuaction=phpbrain.uikb.edit_article&q_id='. $question['question_id']) ."'>
							<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'answer') . "' title='". lang('answer')  ."'>
							</a>";
				}

				// can only attempt to publish a question if it is unpblished and user has publish rights on owner
				if (!$question['published'] && ($this->bo->grants[$question['user_id']] & $this->bo->publish_right))
				{
					$actions .= "<a href='". $this->link('menuaction=phpbrain.uikb.maintain_questions&publish='. $question['question_id']  .'&order='. $this->bo->order .'&sort='. $this->bo->sort .'&query='. $this->bo->query) ."'>
										<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'new') . "' title='". lang('publish')  ."'>
										</a>";
				}

				// can only delete question if user has edit rights on owner
				if ($this->bo->grants[$question['user_id']] & $this->bo->edit_right)
				{
					$actions .= "<a href='". $this->link('menuaction=phpbrain.uikb.maintain_questions&delete='. $question['question_id']  .'&order='. $this->bo->order .'&sort='. $this->bo->sort .'&query='. $this->bo->query). "'>
										<img src='" . $GLOBALS['phpgw']->common->image('phpbrain', 'delete') . "' title='" . lang('delete') . "'>
										</a>";
				}
				$this->t->set_var(array(
					'tr_color'			=> $this->nextmatchs->alternate_row_color($tr_color),
					'summary'			=> $question['summary'],
					'details'			=> $question['details'],
					'date'				=> $GLOBALS['phpgw']->common->show_date($question['creation'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']),
					'author'			=> $question['username'],
					'actions'			=> $actions,
					'name_checkbox'		=> 'select[' . $question['question_id']  . ']'
				));
				$this->t->parse('table_row', 'table_row_block', True);
			}

			if ($this->sitemgr)
			{
				$this->nextmatchs->template->set_var('action_sitemgr', $this->link('menuaction=phpbrain.uikb.maintain_questions'));
				$this->t->set_var(array(
					'lang_outstanding_q'	=> lang('Outstanding published questions'),
					'head_summary'			=> lang('Summary'),
					'head_details'			=> lang('Details'),
					'head_date'				=> lang('creation'),
					'head_author'			=> lang('Author')
				));
				if ($this->allow_questions)
				{
					$this->t->set_var('links_nav', "<a href='". $this->link('menuaction=phpbrain.uikb.index') ."'>". lang('Main View', 'phpbrain') ."</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='". $this->link('menuaction=phpbrain.uikb.add_question') ."'>". lang('Add Question') ."</a>&nbsp;&nbsp;|<br>");
				}
				else
				{
				$this->t->set_var('links_nav', "<a href='". $this->link('menuaction=phpbrain.uikb.index') ."'>". lang('Main View', 'phpbrain') ."</a>&nbsp;&nbsp;|<br>");
				}
			}
			else
			{
				$select_publish = "<option value='all'";
				if ($this->bo->publish_filter == 'all') $select_publish .= ' selected';
				$select_publish .= ">" . lang('All') . "</option><option value='unpublished'";
				if ($this->bo->publish_filter == 'unpublished') $select_publish .= ' selected';
				$select_publish .= ">" . lang('unpublished') . "</option><option value='published'";
				if ($this->bo->publish_filter == 'published') $select_publish .= ' selected';
				$select_publish .= '>' . lang('Published') . '</option>';
				$GLOBALS['phpgw_info']['flags']['java_script_thirst'] = $this->javascript_check_all();

				$this->t->set_var(array(
					'head_summary'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'summary', $this->bo->order, '', lang('Summary')),
					'head_details'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'details', $this->bo->order, '', lang('Details')),
					'head_date'				=> $this->nextmatchs->show_sort_order($this->bo->sort, 'creation', $this->bo->order, '', lang('creation')),
					'head_author'			=> $this->nextmatchs->show_sort_order($this->bo->sort, 'user_id', $this->bo->order, '', lang('Author')),
					'select_publish'		=> $select_publish
				));
			}
			$this->t->set_var(array(
				'message'				=> $this->message,
				'lang_actions'			=> lang('Actions'),
				'lang_search'			=> lang('Search'),
				'value_query'			=> $this->bo->query,
				'form_maintain_questions_action'=> $this->link('menuaction=phpbrain.uikb.maintain_questions'),
				'form_filters_action'	=> $this->link('menuaction=phpbrain.uikb.maintain_questions&start='. $this->bo->start .'&sort='. $this->bo->sort),
				'img_src_checkall'		=> $GLOBALS['phpgw']->common->image('phpbrain', 'check'),
				'order'					=> $this->bo->order, 
				'publish_filter'		=> $this->bo->publish_filter,
				'left'					=> $this->nextmatchs->left($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.maintain_questions&cat='. $actual_category . '&publish_filter=' . $this->bo->publish_filter . '&query=' . $this->bo->query),
				'right'					=> $this->nextmatchs->right($this->link, $this->bo->start, $this->bo->num_rows, 'menuaction.phpbrain.uikb.maintain_questions&cat='. $actual_category .'&publish_filter=' . $this->bo->publish_filter . '&query=' . $this->bo->query),
				'num_regs'				=> $this->nextmatchs->show_hits($this->bo->num_rows, $this->bo->start),
				'select_categories'		=> $this->bo->categories_obj->formatted_list('select', 'all', $actual_category, True),
				'lang_publish_selected'	=> lang('Publish selected'),
				'lang_delete_selected'	=> lang('Delete selected')
			));

			if (!$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
				$this->navbar_shown = True;
			}

			if ($this->sitemgr)
			{
				return $this->t->parse('out', 'maintain_questions');
			}
			else
			{
				$this->t->pparse('output', 'maintain_questions');
			}
		}

		/**
		* Auxiliary function that reloads the article view showing a confirmation message on top
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	int		$article_id	Id of article to show
		* @param	string	$message	Message to show
		* @return	void
		*/
		function reload_page($article_id, $message)
		{
			$GLOBALS['phpgw']->redirect($this->link("menuaction=phpbrain.uikb.view_article&art_id=$article_id&message=$message"));
		}

		/**
		* Downloads file
		*
		* @author	Alejandro Pedraza
		* @access	public
		* @return	void
		*/
		function download_file()
		{
			$article_id		= (int)get_var('art_id', 'GET');
			$filename		= urldecode(get_var('file', 'GET'));
			
			$this->bo->download_file_checks($article_id, $filename);

			// remove kb-# prefix
			ereg('^kb[0-9]*-(.*)', $filename, $new_filename);

			$download_browser = CreateObject('phpgwapi.browser');
			$download_browser->content_header($new_filename[1]);
			$cd_args = array('string'	=> '/kb', 'relative' => False, 'relatives' => RELATIVE_NONE);
			if (!$GLOBALS['phpgw']->vfs->cd($cd_args)) die('could not cd');
			echo $GLOBALS['phpgw']->vfs->read(array('string' => $filename));
			$GLOBALS['phpgw']->common->phpgw_exit();
		}

		/**
		* Returns HTML string of categories menu
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	int		$parent_id				id of parent category
		* @param	int		$num_main_categories	Number of main categories
		* @return	string							HTML string of categories menu
		*/
		function build_categories($parent_id, $num_main_categories)
		{
			$categories_str = '';
			$num_main_cat = 0;
			foreach ($this->bo->categories as $cat)
			{
				$data = unserialize($cat['data']);
				if ($data) $cat['icon'] = $data['icon'];
				if ($cat['parent'] != $parent_id) continue;
				$num_main_cat ++;
				$categories_str .= "<tr><td valign=top>";
				if ($cat['icon'])
						$categories_str .= "<img src='" . $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'phpgwapi' . SEP . 'images' . SEP . $cat['icon'] . "'>";
				$categories_str .= "</td><td><a href='".$this->link('menuaction=phpbrain.uikb.index&cat='.$cat['id'])
										."'><b>".$cat['name']."</b></a><br><div style='padding-left:10px'>";
				$has_subcats = False;
				foreach ($this->bo->categories as $subcat)
				{
					if ($subcat['parent'] != $cat['id']) continue;
					$has_subcats = True;
					$categories_str .= "<a href='".$this->link('menuaction=phpbrain.uikb.index&cat='.$subcat['id'])
										."'>".$subcat['name']."</a>, ";
				}
				if ($has_subcats)
				{
					$categories_str = substr($categories_str, 0, strlen($categories_str)-2); // remove the last comma
				}
				$categories_str .= "</div></td></tr>\n";
				if ($num_main_cat == ceil($num_main_categories/2)) $categories_str .= "</table></td>\n<td width=50% valign=top style='padding:10px 5px 10px 10px'><table>";
			}
			if ($categories_str) $categories_str = "<tr><td width=50% valign=top style='padding:10px 5px 10px 10px'><table>" . $categories_str . "</table></td></tr>";
			return $categories_str;
		}

		/**
		* Returns HTML string of categories from the topmost to the actual one
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	int		$category_id	Id of current category
		* @param	bool	$links			Whether to make categories clickable or not
		* @return	string					HTML string
		*/
		function category_path($category_id, $links = False)
		{
			$cat_data = $this->cat_data($category_id);
			if ($cat_data)
			{
				if (!$this->path)
				{
					if ($links)
					{
						$this->path = "<a href='" . $this->link('menuaction=phpbrain.uikb.index&cat=' . $category_id) . "'>"
										. $cat_data['name'] . "</a>";
					}
					else
					{
						$this->path = $cat_data['name'];
					}
				}
				else
				{
					if ($links)
					{
						$this->path = "<a href='" . $this->link('menuaction=phpbrain.uikb.index&cat=' . $category_id) . "'>"
										. $cat_data['name'] . " >> " . $this->path;
					}
					else
					{
						$this->path = $cat_data['name'] . ' >> ' . $this->path;
					}
				}
				return $this->category_path($cat_data['parent_id'], $links);
			}
			return $this->path;
		}

		/**
		* Auxiliary function to category_path function
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	int		$category_id
		* @return	mixed	Array or 0
		*/
		function cat_data($category_id)
		{
			$cat_data = array();
			foreach ($this->bo->all_categories as $cat)
			{
				if ($cat['id'] == $category_id)
				{
					$cat_data['name'] 		= $cat['name'];
					$cat_data['parent_id']	= $cat['parent'];
					return $cat_data;
				}
			}
			return 0;
		}

		/**
		* Shows basic search form
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @return	string	Form to place inside other templatesA
		*/
		function show_basic_search()
		{
			$this->t->set_file('basic_search', 'basic_search.tpl');
			$this->t->set_var(array(
				'lang_search_kb'		=> lang('Search in all the Knowledge Base'),
				'lang_enter_words'		=> lang('Enter one or two words describing the issue, or type the article number if you know it'),
				'lang_search'			=> lang('Search'),
				'lang_advanced_search'	=> lang('Advanced Search'),
				'class_tr'				=> 'th',
				'query_value'			=> $this->bo->query? $this->bo->query : '',
				'link_adv_search'		=> $this->link('menuaction=phpbrain.uikb.advsearch'),
				'form_search_action'	=> $this->link('menuaction=phpbrain.uikb.index')
			));
			return $this->t->parse('output', 'basic_search');

		}

		/**
		* Shows link string. Necessary because might be different depending if entered through sitemgr or not
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	string	$args	GET arguments to be appended to link
		* @return	string			Link string
		*/
		function link($args)
		{
			if ($this->sitemgr)
			{
				return $this->link . '&' . $args;
			}
			else
			{
				return $GLOBALS['phpgw']->link($this->link, $args);
			}
		}

		/**
		* Javascript code to check all check boxes in a table
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @return	string	Code
		*/
		function javascript_check_all()
		{
			$javascript = "<script>
			function check_all(which)
			{
			  for (i=0; i<document.admin_articles.elements.length; i++)
			  {
			    if (document.admin_articles.elements[i].type == 'checkbox' && document.admin_articles.elements[i].name.substring(0,which.length) == which)
			    {
			      if (document.admin_articles.elements[i].checked)
			      {
			        document.admin_articles.elements[i].checked = false;
			      }
			      else
			      {
			        document.admin_articles.elements[i].checked = true;
			      }
			    } 
			  }
			}</script>";
			return $javascript;
		}

		/**
		* To stop execution showing error message
		*
		* @author	Alejandro Pedraza
		* @access	private
		* @param	string	$error_msg	Error message to be translated and shown
		* @return	void
		*/
		function die_peacefully($error_msg)
		{
			if (!$this->navbar_shown && !$this->sitemgr)
			{
				$GLOBALS['phpgw']->common->phpgw_header();
				echo parse_navbar();
			}
			echo "<div style='text-align:center; font-weight:bold'>" . lang($error_msg) . "</div>";
			$GLOBALS['phpgw']->common->phpgw_footer();
			die();
		}
	}	
?>