<?php
/**
* @package Mambo Open Source
* @copyright (C) 2005 - 2006 Mambo Foundation Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*
* Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure
* that Mambo remained free Open Source software owned and managed by the community.
* Mambo is Free Software
*/ 

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$this->registerFunction( 'onBeforeDisplayContent', 'botVoting' );

function botVoting( &$row, &$params, $page=0 ) {
	global $mosConfig_live_site, $mosConfig_absolute_path, $cur_template;
	global $Itemid;
	if (get_class($row) != 'mosExtendedContent') return;
	if (is_callable(array($row,'getId'))) $id = $row->getId();
	else $id = $row->id;
	$option = 'com_content';
	$task = mosGetParam( $_REQUEST, 'task', '' );

	$html = '';
	if ($params->get( 'rating' ) && !$params->get( 'popup' )){
		if (is_callable(array($row,'getRating'))) $rating = $row->getRating();
		else $rating = $row->rating;
		if (is_callable(array($row,'getRatingCount'))) $rating_count = $row->getRatingCount();
		else $rating_count = $row->rating_count;
		$html .= '<form method="post" action="' . sefRelToAbs( 'index.php' ) . '">';
		$img = '';
		
		// look for images in template if available
		$mainframe =& mosMainFrame::getInstance();
		$starImageOn = $mainframe->ImageCheck( 'rating_star.png', '/images/M_images/' );
		$starImageOff = $mainframe->ImageCheck( 'rating_star_blank.png', '/images/M_images/' );

		for ($i=0; $i < $rating; $i++) {
			$img .= $starImageOn;
		}
		for ($i=$rating; $i < 5; $i++) {
			$img .= $starImageOff;
		}
		$html .= '<span class="content_rating">';
		$html .= T_('User Rating') . ':' . $img . '&nbsp;/&nbsp;';
		$html .= intval( $rating_count );
		$html .= "</span>\n<br />\n";
		$url = @$_SERVER['REQUEST_URI'];
		$url = ampReplace( $url );
		
		if (!$params->get( 'intro_only' ) && $task != "blogsection") {
			$html .= '<span class="content_vote">';
			$html .= T_('Poor');
			$html .= '<input type="radio" alt="'.T_('vote 1 star').'" name="user_rating" value="1" />';
			$html .= '<input type="radio" alt="'.T_('vote 2 star').'" name="user_rating" value="2" />';
			$html .= '<input type="radio" alt="'.T_('vote 3 star').'" name="user_rating" value="3" />';
			$html .= '<input type="radio" alt="'.T_('vote 4 star').'" name="user_rating" value="4" />';
			$html .= '<input type="radio" alt="'.T_('vote 5 star').'" name="user_rating" value="5" checked="checked" />';
			$html .= T_('Best');
			$html .= '&nbsp;<input class="button" type="submit" name="submit_vote" value="'. T_('Rate') .'" />';
			$html .= '<input type="hidden" name="task" value="vote" />';
			$html .= '<input type="hidden" name="pop" value="0" />';
			$html .= '<input type="hidden" name="option" value="com_content" />';
			$html .= '<input type="hidden" name="Itemid" value="'. $Itemid .'" />';
			$html .= '<input type="hidden" name="cid" value="'. $id .'" />';
			$html .= '<input type="hidden" name="url" value="'. $url .'" />';
			$html .= '</span>';
		}
		$html .= "</form>\n";
	}
	return $html;
}
?>
