<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	class Chart {
		var $total;
		var $items = Array();
		var $width = "100%";
		var $max_v = 0;
		function Chart($width = "100%", $relative = false) {
			$this->width = $width;
			$this->relative = $relative;
		}
		function addItem($text, $value) {
			$this->items[] = Array (
				"text" => $text,
				"value" => $value
			);
			$this->total += $value;
			if ($value > $this->max_v) $this->max_v = $value;
		}
		function make($style = null, $itotal = true) {
				if ($this->total) {
				$p = 100/$this->total;
				$buff = "";
				switch ($style) {
					default:
						foreach ($this->items as $item) {
							$perc = $item["value"]*$p;
							$buff .= "{$item["text"]} - ".round($perc,1)."% ({$item["value"]})<div class=\"bar\"><div class=\"progress\" style=\"width:".round($this->relative ? ($item["value"]*100/$this->max_v) : $perc)."%;\"></div></div>\n";
						}
					break;
				}
				// include total?
				if ($itotal) $buff .= "<b>"._l("L_TOTAL")."</b>: {$this->total}";

				return "<div class=\"chart\" style=\"width:{$this->width};\">".$buff."</div>";
			}
			return "";
		}
	}

?>