<?php

/*
#======================================================
|    <#TAG_NAME_TAG#>
|    =====================================
|    <#TAG_DEVELOPERS_TAG#>
|    <#TAG_COPYRIGHT_TAG#>
|    <#TAG_URL_TAG#>
|    =====================================
|    Email: <#TAG_EMAIL_TAG#>
#======================================================
|    @ Version: <#TAG_VER_HUMAN_TAG#>
|    @ Version Int: <#TAG_VER_INT_TAG#>
|    @ Version Num: <#TAG_VER_NUM_TAG#>
|    @ Build: <#TAG_VER_BUILD_TAG#>
#======================================================
|    | Sources :: Knowledge Base
#======================================================
*/

class td_source_knowledgebase {

	#=======================================
	# @ Auto Run
	#=======================================

	public function auto_run()
	{
		#=============================
		# Security Checks
		#=============================

		if ( ! $this->trellis->cache->data['settings']['kb']['enable'] ) $this->trellis->skin->error('kb_disabled');

		if ( ! $this->trellis->user['g_kb_access'] || $this->trellis->user['ban_kb'] )
		{
			$this->trellis->log( 'security', "Blocked Access Knowledge Base" );

			$this->trellis->skin->error('banned_kb');
		}

		#=============================
		# Initialize
		#=============================

		$this->trellis->load_lang('knowledgebase');

		switch( $this->trellis->input['act'] )
    	{
    		case 'view':
				$this->view_article();
    		break;
    		case 'cat':
				$this->show_category();
    		break;
    		case 'search':
				$this->do_search();
    		break;

    		case 'editcomment':
				$this->edit_comment();
    		break;

    		case 'doaddcomment':
				$this->do_add_comment();
    		break;
    		case 'doeditcomment':
				$this->do_edit_comment();
    		break;
    		case 'dodeletecomment':
				$this->do_delete_comment();
    		break;
    		case 'dorate':
				$this->do_rate();
    		break;

    		default:
    			$this->show_categories();
    		break;
		}
	}

	#=======================================
	# @ Show Categories
	#=======================================

	private function show_categories()
	{
		#=============================
		# Grab Categories
		#=============================

		$this->trellis->load_functions('categories');

		$categories = $this->trellis->func->categories->get( array( 'select' => array( 'id', 'name', 'description', 'articles' ), 'where' => array( 'parent_id', '=', 0 ), 'order' => array( 'position' => 'asc' ) ) );

		#=============================
		# Do Output
		#=============================

		$this->trellis->skin->set_var( 'categories', $categories );

		$this->nav = array(
						   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb">'. $this->trellis->lang['knowledge_base'] .'</a>',
						   );

		$this->trellis->skin->set_var( 'sub_tpl', 'knowledge_base.tpl' );

		$this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] ) );
	}

	#=======================================
	# @ Show Category
	#=======================================

	private function show_category()
	{
		#=============================
		# Grab Category
		#=============================

		$this->trellis->load_functions('categories');

		if ( ! $c = $this->trellis->func->categories->get_single_by_id( array( 'id', 'name', 'description', 'articles' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_category');

		$this->trellis->skin->set_var( 'c', $c );

		#=============================
		# Grab Sub-Categories
		#=============================

		$categories = $this->trellis->func->categories->get( array( 'select' => array( 'id', 'name', 'description', 'articles' ), 'where' => array( 'parent_id', '=', $this->trellis->input['id'] ), 'order' => array( 'position' => 'asc' ) ) );

		$this->trellis->skin->set_var( 'categories', $categories );

		#=============================
		# Grab Articles
		#=============================

		$this->trellis->load_functions('articles');

		$articles = $this->trellis->func->articles->get( array( 'select' => array( 'id', 'title', 'description', 'rating', 'views', 'comments' ), 'where' => array( 'cid', '=', $c['id'] ), 'order' => array( 'title' => 'asc' ) ) );

		$this->trellis->skin->set_var( 'articles', $articles );

		#=============================
		# Do Output
		#=============================

		$this->nav = array(
						   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb">'. $this->trellis->lang['knowledge_base'] .'</a>',
						   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb&amp;act=cat&amp;id='. $this->trellis->input['id'] .'">'. $c['name'] .'</a>',
						   );

		$this->trellis->skin->set_var( 'sub_tpl', 'kb_category.tpl' );

		$this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $c['name'] ) );
	}

	#=======================================
	# @ Show Article
	#=======================================

	private function view_article($alert="", $error="")
	{
		#=============================
		# Grab Article
		#=============================

		$this->trellis->load_functions('articles');

		if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'description', 'content', 'rating_average', 'votes', 'views', 'comments', 'html', 'date', 'modified', 'allow_comments', 'allow_rating' ), $this->trellis->input['id'] ) )
		{
			$this->trellis->log( 'error', "Article Not Found ID: ". $this->trellis->input['id'] );

			$this->trellis->skin->error('no_article');
		}

		#=============================
		# Fix Up Information
		#=============================

		$a['date_human'] = $this->trellis->td_timestamp( array( 'time' => $a['date'], 'format' => 'short' ) );

		$aoutput_params = array( 'linkify' => 1 );

		if ( $a['html'] )
		{
			$aoutput_params['html'] = 1;
		}
		else
		{
			$aoutput_params['paragraphs'] = 1;
			$aoutput_params['nl2br'] = 1;
		}

		$a['content'] = $this->trellis->prepare_output( $a['content'], $aoutput_params );

		#=============================
		# Can We Rate?
		#=============================

		if ( $this->trellis->cache->data['settings']['kb']['rating'] && $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_rating'] && $a['allow_rating'] )
		{
			if ( $this->trellis->user['id'] && $this->trellis->user['g_kb_rate'] ) # TODO: allow guests to rate
			{
				if ( $this->trellis->func->articles->get_single_rating( array( 'id' ), array( array( 'aid', '=', $a['id'] ), array( 'uid', '=', $this->trellis->user['id'], 'and' ) ) ) )
				{
					$rate = $this->rate_stars( $a['rating_average'], 0, $a['id'] );
				}
				else
				{
					$rate = $this->rate_stars( $a['rating_average'], 1, $a['id'] );
				}
			}
			else
			{
				$rate = $this->rate_stars( $a['rating_average'], 0, $a['id'] );
			}

			$this->trellis->skin->set_var( 'rate', $rate );
		}

		#=============================
		# Grab Comments?
		#=============================

		$comments = $this->trellis->db->get( array(
														 'select'	=> array(
													   				    	 'c' => 'all',
												   					    	 'u' => array( array( 'name' => 'uname' ) ),
													   			    		 ),
														 'from'	    => array( 'c' => 'article_comments' ),
														 'join'	    => array( array( 'from' => array( 'u' => 'users' ), 'where' => array( 'c' => 'uid', '=', 'u' => 'id' ) ) ),
														 'where'	=> array( array( 'c' => 'aid' ), '=', $a['id'] ),
														 'order'    => array( 'date' => array( 'c' => 'asc' ) ),
                                                  ), 'id' );

		if ( $comments )
		{
		    foreach ( $comments as $c )
		    {
				#=============================
				# Fix Up Information
				#=============================

				$comments[ $c['id'] ]['time_ago'] = $this->trellis->td_timestamp( array( 'time' => $comments[ $c['id'] ]['date'], 'format' => 'relative' ) );

				$comments[ $c['id'] ]['date_human'] = $this->trellis->td_timestamp( array( 'time' => $comments[ $c['id'] ]['date'], 'format' => 'short' ) );

        		$coutput_params = array( 'linkify' => 1 );

			    if ( $c['html'] )
				{
					$coutput_params['html'] = 1;
				}
				else
				{
					$coutput_params['paragraphs'] = 1;
					$coutput_params['nl2br'] = 1;
				}

				// Permissions for Templates
				if ( $c['uid'] == $this->trellis->user['id'] )
				{
					if ( $this->trellis->user['g_kb_com_edit'] ) $comments[ $c['id'] ]['can_edit'] = 1;
					if ( $this->trellis->user['g_kb_com_delete'] ) $comments[ $c['id'] ]['can_delete'] = 1;
				}

        		$comments[ $c['id'] ]['message'] = $this->trellis->prepare_output( $c['message'], $coutput_params );
		    }

			$this->trellis->skin->set_var( 'comments', $comments );
		}

		#=============================
		# Stats
		#=============================

		$this->trellis->func->articles->increase_count( $a['id'], 1, 'views' );

		#=============================
		# Do Output
		#=============================

		if ( $error ) $this->trellis->skin->set_var( 'error', $this->trellis->lang[ 'err_'. $error ] );
		if ( $alert ) $this->trellis->skin->set_var( 'alert', $this->trellis->lang[ 'alert_'. $alert ] );

		// Permissions for Templates
		if ( $this->trellis->cache->data['settings']['kb']['comments'] && $this->trellis->user['g_kb_comment'] && $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_comments'] && $a['allow_comments'] ) $a['can_comment'] = 1;

		$this->trellis->skin->set_var( 'a', $a );

		$this->nav = array(
						   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb'>{$this->trellis->lang['knowledge_base']}</a>",
						   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=cat&amp;id={$a['cid']}'>{$this->trellis->cache->data['categories'][ $a['cid'] ]['name']}</a>",
						   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=view&amp;id={$a['id']}'>{$a['title']}</a>",
						   );

		if ( $type == 'print' )
		{
			$this->trellis->skin->set_var( 'sub_tpl', 'kb_print_article.tpl' );

			$this->trellis->skin->do_print( array( 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $a['name'] ) );
		}
		else
		{
			$this->trellis->skin->set_var( 'sub_tpl', 'kb_article.tpl' );

			$this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $a['name'] ) );
		}
	}

	#=======================================
	# @ Submit Comment
	#=======================================

	private function do_add_comment()
	{
		#=============================
		# Security Checks
		#=============================

		$this->trellis->load_functions('articles');

		if ( ! $this->trellis->input['message'] ) $this->view_article( null, 'no_message' );

		if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'allow_comments' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_article');

		if ( ! $this->trellis->cache->data['settings']['kb']['comments'] || ! $this->trellis->user['g_kb_comment'] || ! $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_comments'] || ! $a['allow_comments'] ) $this->trellis->skin->error('no_perm');

		#=============================
		# Add Comment
		#=============================

		$db_array = array(
						  'aid'			=> $a['id'],
						  'uid'			=> $this->trellis->user['id'],
						  'message'		=> $this->trellis->input['message'],
						  'date'		=> time(),
						  'ipadd'		=> $this->trellis->input['ip_address'],
						 );

		$comment_id = $this->trellis->func->articles->add_comment( $db_array, $a['id'] );

		#=============================
		# Redirect
		#=============================

		$this->trellis->skin->redirect( '?page=kb&act=view&id='. $a['id'] .'#com'. $comment_id, 'submit_comment_success' );
	}

	#=======================================
	# @ Do Search
	#=======================================

	function do_search()
	{
		#=============================
		# Search!
		#=============================

		# TODO: improve / finish search!

		$this->trellis->check_token('search');

		$searchstring = $this->trellis->input['keywords'];

		#$sql = "SELECT *, MATCH(name, description, article) AGAINST ('$searchstring') AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring') ORDER BY score DESC";

		$sql = "SELECT *, ( 1.6 * ( MATCH(keywords) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + 0.9 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 0.6 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
		#$sql = "SELECT *, ( 1.6 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 0.9 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
		#$sql = "SELECT *, ( 0.9 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 1.6 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";

		#$sql = "SELECT *, ( (1.3 * (MATCH(name) AGAINST ('+{$searchtitle}' IN BOOLEAN MODE))) + (0.6 * (MATCH(article) AGAINST ('+$searchstring' IN BOOLEAN MODE))) ) AS score FROM ". DB_PRE ."articles WHERE ( MATCH(name,article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) HAVING score > 0 ORDER BY score DESC";

		$this->trellis->db->query( $sql );

		$art = ""; // Initialize for Security

		while( $m = $this->trellis->db->fetch_row() )
		{
		   	if ( $m['score'] > $max_score )
		   	{
		   		$max_score = $m['score'];
		   	}

		   	$art[] = $m;
		}

		$articles = array(); // Initialize for Security
		$row_count = 0; // Initialize for Security

		if ( is_array( $art ) )
		{
			while ( list( , $a ) = each( $art ) )
		    {
				#=============================
				# Fix Up Information
				#=============================

				$row_count ++;

				( $row_count & 1 ) ? $a['class'] = 1 : $a['class'] = 2;

				$a['date'] = $this->trellis->a5_date( $a['date'] );

				$a['score'] = @ round( ( $a['score'] / $max_score ) * 100 ) ."%";

		    	$articles[] = $a;
		    }

		    $this->trellis->skin->set_var( 'results', $articles );
	    }

	    #=============================
		# Do Output
		#=============================

		$this->nav = array(
						   "<a href='{$this->trellis->config['hd_url']}/index.php?act=kb'>{$this->trellis->lang['knowledge_base']}</a>",
						   "<a href='{$this->trellis->config['hd_url']}/index.php?act=kb&amp;code=search'>{$this->trellis->lang['search_results']}</a>",
						   );

		$this->trellis->skin->set_var( 'sub_tpl', 'kb_search_results.tpl' );

		$this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $this->trellis->lang['search_results'] ) );
	}

	#=======================================
	# @ Do Rate
	#=======================================

	private function do_rate()
	{
		#=============================
		# Security Checks
		#=============================

		$this->trellis->load_functions('articles');

		if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'rating_total', 'votes', 'allow_rating' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_article');

		if ( ! $this->trellis->user['id'] )
		{
			$this->trellis->log( 'security', "Article Rating Blocked From Guest &#039;". $a['name'] ."&#039;", 1, $a['id'] );

			$this->trellis->skin->error( 'must_be_user', 1 );
		}

		$allowed_ratings = array( 1, 2, 3, 4, 5 );

		if ( ! in_array( $this->trellis->input['amount'], $allowed_ratings ) )
		{
			$this->trellis->log( 'security', "Invalid Article Rating Amount &#039;". $a['name'] ."&#039;", 1, $a['id'] );

			$this->trellis->skin->error('invalid_rate_value');
		}

		if ( ! $this->trellis->cache->data['settings']['kb']['rating'] || ! $this->trellis->user['g_kb_rate'] || ! $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_rating'] || ! $a['allow_rating'] ) $this->trellis->skin->error('no_perm');  # TD LOG no perm

		if ( $this->trellis->func->articles->get_single_rating( array( 'id' ), array( array( 'aid', '=', $a['id'] ), array( 'uid', '=', $this->trellis->user['id'], 'and' ) ) ) )
		{
			$this->trellis->log( 'security', "Already Rated Article By User &#039;". $a['name'] ."&#039;", 1, $a['id'] );

			#$this->trellis->skin->error('already_rated');
		}

		#=============================
		# Add Rating
		#=============================

		$this->trellis->func->articles->add_rating( $this->trellis->input['amount'], $a['id'], array( 'rating_total' => $a['rating_total'], 'votes' => $a['votes'] ) );

		$this->trellis->log( 'user', "Article Rating Value ". $this->trellis->input['amount'] ." Added &#039;". $a['name'] ."&#039;", 1, $a['id'] );

	    #=============================
		# Do Output
		#=============================

		$this->view_article( 'rating_added' );
	}

	#=======================================
	# @ Edit Comment
	# Show edit comment form.
	#=======================================

	function edit_comment($error="")
	{
		#=============================
		# Security Checks
		#=============================

		$this->trellis->input['id'] = intval( $this->trellis->input['id'] );

		$this->trellis->db->construct( array(
											  	 'select'	=> 'all',
											  	 'from'		=> 'article_comments',
							 				  	 'where'	=> array( 'id', '=', $this->trellis->input['id'] ),
							 				  	 'limit'	=> array( 0, 1 ),
							 		  	  ) 	);

		$this->trellis->db->execute();

		if ( ! $this->trellis->db->get_num_rows() )
		{
			$this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );

			$this->trellis->skin->error('no_comment');
		}

		$c = $this->trellis->db->fetch_row();

		if ( ! $this->trellis->user['g_kb_com_edit'] || $c['uid'] != $this->trellis->user['id'] )
		{
			$this->trellis->log( 'security', "Blocked Editing of Comment" );

			$this->trellis->skin->error('no_perm_com_edit');
		}

		$this->trellis->skin->set_var( 'comment', $c );

		#=============================
		# Do Output
		#=============================

		if ( $error )
		{
			$this->trellis->skin->set_var( 'error', $this->trellis->lang[ 'err_'. $error ] );
		}

		$this->nav = array(
						   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb'>{$this->trellis->lang['knowledge_base']}</a>",
						   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=edit&amp;id={$c['id']}'>{$this->trellis->lang['edit_comment']}</a>",
						   );

		$this->trellis->skin->set_var( 'sub_tpl', 'kb_edit_comment.tpl' );

		$this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $this->trellis->lang['edit_comment'] ) );
	}

	#=======================================
	# @ Do Edit Comment
	# Edit comment. :P
	#=======================================

	function do_edit_comment()
	{
		#=============================
		# Security Checks
		#=============================

		$this->trellis->load_functions('articles');

		$this->trellis->input['id'] = intval( $this->trellis->input['id'] );

		$this->trellis->db->construct( array(
											  	 'select'	=> 'all',
											  	 'from'		=> 'article_comments',
							 				  	 'where'	=> array( 'id', '=', $this->trellis->input['id'] ),
							 				  	 'limit'	=> array( 0, 1 ),
							 		  	  ) 	);

		$this->trellis->db->execute();

		if ( ! $this->trellis->db->get_num_rows() )
		{
			$this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );

			$this->trellis->skin->error('no_comment');
		}

		$c = $this->trellis->db->fetch_row();

		if ( ! $this->trellis->user['g_kb_com_edit'] || $c['uid'] != $this->trellis->user['id'] )
		{
			$this->trellis->log( 'security', "Blocked Editing of Comment" );

			$this->trellis->skin->error('no_perm_com_edit');
		}

		#=============================
		# Update Comment
		#=============================

		$this->trellis->func->articles->edit_comment( array( 'message' => $this->trellis->input['message'] ), $c['id'] );

		$this->trellis->log( 'user', "Article Comment Edited ID #". $c['id'], 1, $c['id'] );

		#=============================
		# Do Output
		#=============================

		$this->trellis->skin->redirect( '?page=kb&act=view&id='. $c['aid'] .'#com'. $c['id'], 'edit_comment_success' );
	}

	#=======================================
	# @ Do Delete Comment
	# Delete comment. :(
	#=======================================

	function do_delete_comment()
	{
		#=============================
		# Security Checks
		#=============================

		$this->trellis->load_functions('articles');

		$this->trellis->input['id'] = intval( $this->trellis->input['id'] );

		$this->trellis->db->construct( array(
											  	 'select'	=> 'all',
											  	 'from'		=> 'article_comments',
							 				  	 'where'	=> array( 'id', '=', $this->trellis->input['id'] ),
							 				  	 'limit'	=> array( 0, 1 ),
							 		  	  ) 	);

		$this->trellis->db->execute();

		if ( ! $this->trellis->db->get_num_rows() )
		{
			$this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );

			$this->trellis->skin->error('no_comment');
		}

		$c = $this->trellis->db->fetch_row();

		if ( ! $this->trellis->user['g_kb_com_delete'] || $c['uid'] != $this->trellis->user['id'] )
		{
			$this->trellis->log( 'security', "Blocked Deleting of Comment" );

			$this->trellis->skin->error('no_perm_com_delete');
		}

		#=============================
		# Delete Comment
		#=============================

		$this->trellis->func->articles->delete_comment( $c['id'], array( 'aid' => $c['aid'] ) );

		$this->trellis->log( 'user', "Article Comment Deleted ID #". $c['id'], 2, $c['id'] );

		#=============================
		# Do Output
		#=============================

		$this->trellis->skin->redirect( '?page=kb&act=view&id='. $c['aid'], 'delete_comment_success' );
	}

	#=======================================
	# @ rate_stars()
	#=======================================

	function rate_stars($rating, $rate=0, $fid=0)
	{
		# TODO: move to templates

		$half = 0; // Initialize for Security

		if ( strstr( $rating, '.' ) )
		{
			$half = 1;
		}

		$real_rating = $rating;

		for ( $x = 1; $x < $rating + 1; $x++ )
	    {
	    	if ( $half && $x == $rating )
	    	{
		    	if ( $rate )
		    	{
		    		$a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_half.gif' alt='". $this->trellis->lang['half_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
		    	}
		    	else
		    	{
		    		$a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_half.gif' alt='". $this->trellis->lang['half_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
		    	}
	    	}
	    	else
	    	{
	    		if ( $rate )
		    	{
		    		$a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_on.gif' alt='". $this->trellis->lang['lang.full_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
		    	}
		    	else
		    	{
		    		$a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_on.gif' alt='". $this->trellis->lang['full_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
		    	}
	    	}
	    }

	    for ( $x = $x; $x <= 5; $x++ )
	    {
	    	if ( $rate )
	    	{
	    		$a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_off.gif' alt='". $this->trellis->lang['no_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
	    	}
	    	else
	    	{
	    		$a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_off.gif' alt='". $this->trellis->lang['no_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
	    	}
	    }

		return $a5_html;
	}

}

?>