62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php #ajax/get.php
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set("display_errors", 1);
|
|
|
|
require_once "../../db/conf.php";
|
|
|
|
$query = "select distinct year(Alarmierungszeit) sy from Einsätze order by sy desc";
|
|
$res = $mysqli->query($query);
|
|
$years = array();
|
|
while ($year = $res->fetch_assoc()) {
|
|
$years[] = $year["sy"];
|
|
}
|
|
|
|
$name = isset($_POST["section"]) && $_POST["section"]!="" ? $_POST["section"] : ($years[0] ?? 2017);
|
|
|
|
$table = "<table><tr><th>Einsatzart</th><th>Anzahl Einsätze</th></tr><tr><td colspan=2> </td></tr>";
|
|
|
|
$query = "select count(*) c,k.Name kn,k.Farbe,a.Name an from Einsätze b "
|
|
."left join Einsatzarten a on a.ID=b.Einsatzart "
|
|
."left join Einsatzkategorien k on k.ID=a.Einsatzkategorie "
|
|
."where year(Alarmierungszeit) = ? group by b.Einsatzart order by k.ID asc ";
|
|
$gesamt = array("Gesamt" => 0);
|
|
if ($stmt = $mysqli->prepare($query)) {
|
|
$stmt->bind_param("i", $name);
|
|
$stmt->execute();
|
|
$res = $stmt->get_result();
|
|
while ($stat = $res->fetch_assoc()) {
|
|
$table.= "<tr style='background-color: ".$stat["Farbe"].";'><td>".$stat["an"]."</td><td>".$stat["c"]."</td></tr>";
|
|
$gesamt["Gesamt"]+= $stat["c"];
|
|
|
|
if (!isset($gesamt[$stat["kn"]])) {
|
|
$gesamt[$stat["kn"]] = 0;
|
|
}
|
|
$gesamt[$stat["kn"]]+= $stat["c"];
|
|
}
|
|
} else {
|
|
$table.= "<tr><td colspan=2>".$mysqli->error."</td></tr>";
|
|
}
|
|
$table.= "<tr><td colspan=2> </td></tr><tr><th colspan=2>Summen</th></tr><tr><td colspan=2> </td></tr>";
|
|
foreach ($gesamt as $k => $v) {
|
|
$table.= "<tr><td>".$k."</td><td>".$v."</td></tr>";
|
|
}
|
|
$table.= "</table>";
|
|
|
|
$article = $_POST["article"] ?? "Empty";
|
|
|
|
$id = preg_replace('/\s+/', '', $article."_".$name);
|
|
|
|
?>
|
|
<footer>
|
|
<?php if (count($years)>1) { ?>
|
|
<h1><?=$article;?></h1>
|
|
<ul>
|
|
<?php foreach ($years as $y) { ?>
|
|
<a href='javascript:loadArticle("<?=basename(__FILE__);?>", "<?=$article;?>", "<?=$y;?>")'<?=($y==$name ? " class='current'" : "");?>><li><?=$y;?></li></a>
|
|
<?php } ?>
|
|
</ul>
|
|
<?php } ?>
|
|
</footer>
|
|
<section id='<?=$id;?>'><?=$table;?></section>
|