<?php

class bilanMod1
{
	var $listPatID;
	var $listConsuID;

	function bilanMod1($listPat, $listConsu)
	{
		$this->listPatID = array();
		$this->listConsu = array();

		$this->listPatID = $listPat;
		$this->listConsuID = $listConsu;
	}

	function getMulti($title, $array, $table, $field, $opt = "")
	{
		if (!empty($opt))
			$opt = " && " . $opt;

		$q = "SELECT id_consult, " . $field . ", COUNT(" . $field . ") as total FROM " . $table . " WHERE id_consult IN (" . implode(", ", $this->listConsuID) . ")" . $opt ." GROUP BY " . $field . " ASC";
		$datas = queryList($q);

		echo "<tr>";
		echo "<td colspan=\"3\"><span class=\"bold\">" . $title . "</span></td>";
		echo "</tr>";

		foreach ($datas as $data)
		{
			$label = isset($array[$data[$field]]) ? $array[$data[$field]] : "-";

			echo "<tr>";
			echo "<td><ul><li>" . $label . "</li></ul></td>";
			echo "<td>" . $data["total"] . "</td>";
			echo "</tr>";
		}
	}

	function getMultiTableDebut($title, $array, $field, $opt = "", $table = "debut")
	{
		if (!empty($opt))
			$opt = " && " . $opt . " ";

		$q = "SELECT " . $field . ", COUNT(" . $field . ") as total FROM " . $table . " WHERE id_pat IN (" . implode(", ", $this->listPatID) . ")" . $opt . " GROUP BY " . $field . " ASC";
		$datas = queryList($q);

		echo "<tr>";
		echo "<td colspan=\"3\"><span class=\"bold\">" . $title . "</span></td>";
		echo "</tr>";

		foreach ($datas as $data)
		{
			$label = isset($array[$data[$field]]) ? $array[$data[$field]] : "-";
			echo "<tr>";
			echo "<td><ul><li>" . $label . "</li></ul></td>";
			echo "<td colspan=\"2\">" . $data["total"] . "</td>";
			echo "</tr>";
		}
	}

	function getMoyenne($title, $table, $field, $round = 0, $opt = "")
	{
		if (!empty($opt))
			$opt = " WHERE 1 && " . $opt . " ";
		else
			$opt = " WHERE 1";

		$q = "SELECT AVG(" . $field . ") as total FROM " . $table . $opt . " && id_consult IN (" . implode(", ", $this->listConsuID) . ")";
		$total = queryOneField($q);

		echo "<tr>";
		echo "<td>" . $title . "</td>";
		echo "<td>" . round($total, $round) . "</td>";
		echo "</tr>";
	}

	function getSingle($title, $table, $field, $opt = "")
	{
		if (!empty($opt))
			$opt = "&& " . $opt . " ";

		if ($field == "*")
			$groupBY = "";
		else
			$groupBY = "GROUP BY " . $field . " ASC";

		$q = "SELECT COUNT(" . $field . ") as total FROM " . $table . " WHERE id_consult IN (" . implode(", ", $this->listConsuID) . ") " . $opt . $groupBY;
		$total = queryOneField($q);

		echo "<tr>";
		echo "<td>" . $title . "</td>";
		echo "<td>" . ($total ? $total : 0). "</td>";
		echo "</tr>";
	}

	function titre($title)
	{
		echo "<tr>";
		echo "<td colspan=\"3\"><span class=\"bold\">" . $title . "</span></td>";
		echo "</tr>";
	}

}

?>