1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function smarty_function_rating_result($params, $smarty)
9{
10	global $prefs;
11	$ratinglib = TikiLib::lib('rating');
12	$votings = $ratinglib->votings($params['id'], $params['type']);
13	$smiles = ($prefs['rating_smileys'] == 'y' ? $ratinglib->get_options_smiles($params['type'], $params['id'], true) : null);
14	$tableBody = "";
15
16	if ($prefs['rating_results_detailed'] == 'y') {
17		foreach ($votings as $vote => $voting) {
18			if ($prefs['rating_results_detailed_percent'] == 'y') {
19				$extra_info = '/' . $voting['percent'] . '%)';
20			} else {
21				$extra_info = ')';
22			}
23			$tableBody .= '<td style="width:' . $voting['percent'] . '%; text-align: center;">
24				<div class="ui-widget-content">' .
25					($prefs['rating_smileys'] == 'y' ? '<img src="' . $smiles[$vote]['img'] . '"/> ' : '<b>' . $vote . '</b> ') .
26					'(' . $voting['votes'] . $extra_info .
27					($prefs['rating_smileys'] == 'y' ? '<div style="background-color: ' . $smiles[$vote]['color'] . ';">&nbsp;</div>' : '') .
28				'</div>
29			</td>';
30		}
31	} elseif ($votings) {
32		// $smarty->loadPlugin('function_rating_result_avg'); apparently "plugin function_rating_result_avg is not a valid name format"
33		include_once('lib/smarty_tiki/function.rating_result_avg.php');
34		return smarty_function_rating_result_avg($params, $smarty);
35	}
36
37	return "<table class='ratingDeliberationResultTable' style='width:100%;'><tr>" . $tableBody . "</tr></table>";
38}
39