+function getArchive($db,$year,$month,$day,$id,$type,$param) {
+
+ global $filter;
+
+ $y = intval($year);
+ $m = intval($month);
+ $d = intval($day);
+
+ $date = strval($y).'-'.strval($m).'-'.strval($d);
+
+ if ($param == "*") {
+
+ $sql = "
+ SELECT s.id s_id,p.id p_id, p.st_name p_name
+ FROM sensors s,sensor_types t, st_parameters p
+ WHERE s.st_id=t.id and p.st_id=t.id and s_id=:id and t.st_abbr=:type ".$filter."
+ ";
+
+ $q = $db -> prepare( $sql );
+ $q -> bindParam(':id',$id,PDO::PARAM_STR);
+ $q -> bindParam(':type',$type,PDO::PARAM_STR);
+ $q -> execute();
+ $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
+
+ $results = array();
+
+ foreach ($sensors as $sensor) {
+
+ $result[$sensor['p_name']] = getArchiveValues($db,$year,$month,$day,$sensor['s_id'],$sensor['p_id']);
+
+ }
+
+ return $result;
+
+ } else {
+
+ $sql = "
+ SELECT s.id s_id,p.id p_id
+ FROM sensors s,sensor_types t, st_parameters p
+ WHERE s.st_id=t.id and p.st_id=t.id and s_id=:id and t.st_abbr=:type and p.st_name=:param ".$filter."
+ ";
+
+ $q = $db -> prepare( $sql );
+ $q -> bindParam(':id',$id,PDO::PARAM_STR);
+ $q -> bindParam(':type',$type,PDO::PARAM_STR);
+ $q -> bindParam(':param',$param,PDO::PARAM_STR);
+ $q -> execute();
+ $sensor = $q -> fetch(PDO::FETCH_ASSOC);
+
+ return getArchiveValues($db,$year,$month,$day,$sensor['s_id'],$sensor['p_id']);
+
+ }
+
+}
+