<?php
/*
* prepare statsgraph-form
* $Id: statsgraphprepare.inc.php,v 1.3 2008-01-18 16:17:07 zerwes Exp $
* package: traffstats
* (c) Klaus Zerwes zero-sys.net
*/
$debug->filestart(__FILE__);
if(!isset($traffstats) || !is_a($traffstats, "traffstats")){
die (__FILE__." requires object traffstats");
}
//$debug->debugarray($_SESSION, "SESSION_AT_STARTOF_".__FILE__);
// graph: how to handle sel
$handlearr = array(
0 => $language->translate("select_separate"),
1 => $language->translate("select_separateinverted"),
2 => $language->translate("select_sumup"),
3 => $language->translate("select_sumupinverted"),
4 => $language->translate("select_ignore")
);
if(!array_key_exists("statsgraph", $_SESSION)) {
$_SESSION["statsgraph"] = array();
}
// POST data
$countstatsgraph = 0;
for($i=1; $i<=3; $i++){
if(array_key_exists("s_".$i, $_REQUEST)) {
$_SESSION["statsgraph"]["s_".$i] = $_REQUEST["s_".$i];
$debug->msg("s_".$i." set to count ".count($_SESSION["statsgraph"]["s_".$i]));
} else {
if(count($_POST) > 0) {
$_SESSION["statsgraph"]["s_".$i] = array();
} else {
if(!array_key_exists("s_".$i, $_SESSION["statsgraph"])) {
$_SESSION["statsgraph"]["s_".$i] = array();
}
}
}
$countstatsgraph += count($_SESSION["statsgraph"]["s_".$i]);
if(array_key_exists("h_".$i, $_REQUEST)) {
$_SESSION["statsgraph"]["h_".$i] = $_REQUEST["h_".$i];
} else {
if(!array_key_exists("h_".$i, $_SESSION["statsgraph"])) {
if($i == 1) {
$_SESSION["statsgraph"]["h_".$i] = 0; // 0 means separate
} else {
$_SESSION["statsgraph"]["h_".$i] = count($handlearr)-1; // means ignore!
}
}
}
if($_SESSION["statsgraph"]["h_".$i] < 0) {
$_SESSION["statsgraph"]["h_".$i] = count($handlearr)-1; // means ignore!
}
}
//$debug->debugarray($_SESSION, "SESSION_AFTER_POSTPARSE_IN_".__FILE__);
// if selected ifaces have changed
$ifaceschanged = false;
if(array_key_exists("traffstatsifaces", $_SESSION)) {
if(count($_SESSION["traffstatsifaces"]) == $countstatsgraph) {
$debug->msg("equal ifaces count: ".count($_SESSION["traffstatsifaces"])." == ".$countstatsgraph);
for($i=1; $i<=3; $i++){
$debug->msg("loop s_".$i." ...");
foreach($_SESSION["statsgraph"]["s_".$i] as $ifacekey) {
$debug->msg("iface $ifacekey ...");
if(!in_array($ifacekey, $_SESSION["traffstatsifaces"])) {
$ifaceschanged = true;
$debug->msg("loop s_".$i." :: iface $ifacekey NOT FOUND!");
break 2;
}
}
}
} else {
$debug->msg("ifaces changed :: diff in count: ".count($_SESSION["traffstatsifaces"])." != ".$countstatsgraph);
$ifaceschanged = true;
}
}
$debug->msg("ifaces changed: ".core::bool2str($ifaceschanged));
if($ifaceschanged) {
$_SESSION["statsgraph"]["s_1"] = $_SESSION["traffstatsifaces"];
$_SESSION["statsgraph"]["s_2"] = array();
$_SESSION["statsgraph"]["s_3"] = array();
}
unset($countstatsgraph);
unset($ifaceschanged);
//$debug->debugarray($_SESSION, "SESSION_AT_ENDOF_".__FILE__);
$debug->fileend(__FILE__);
?>