<?php
/*
 * DON'T REMOVE THE FOLLOWING LICENSE
 *           INFORMATION!
 * ----------------------------------
 * Copyright by
 * Dennis Ritz
 * Author: Dennis Ritz
 * dennis.ritz@gmx.net
 * 2007-2008
 * ----------------------------------
 */
 function getFileExtension ($filename) 
 { 
 $filename = strtolower($filename) ; 
 $exts = split("[/\\.]", $filename) ; 
 $n = count($exts)-1; 
 $exts = $exts[$n]; 
 return $exts; 
 }

function __autoload($p_comp){
	
	while(substr($p_comp,0,1) == "/" || substr($p_comp,0,1) == ".") {
		$p_comp = substr($p_comp,1);
	}
	if(file_exists(ROOT_DIR."apps/".$p_comp."/".$p_comp.".class.inc")) {
		include (ROOT_DIR."apps/".$p_comp."/".$p_comp.".class.inc");
		if(class_exists($p_comp,false)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
function umwandeln($var) {
     $var = str_replace("%","",$var);
     $var = str_replace(".","",$var);
     $var = str_replace(",",".",$var);
     $var = floatval($var);
     return $var;
}
function getImgAlarmstufeSrc($aktwert,$niedriger,$hoher,$positiv) {
     $aktwert = umwandeln($aktwert);
     $niedriger = umwandeln($niedriger);
     $hoher = umwandeln($hoher);
     $differenz = $hoher - $niedriger;
     $faktor = 8;

     if ($hoher == 0 || $niedriger == 0) {
          $hoher = $hoher + 0.001;
          $niedriger = $niedriger + 0.001;
     }
     if ($positiv=="J") {
          $basis = pow($faktor,(1/7));
          if (($aktwert-$niedriger) > ($differenz/$faktor)) {
               $exp = log10((($aktwert-$niedriger) / $differenz) * $faktor) / log10($basis);
          } elseif ($aktwert > $niedriger) {
               $exp = 0;
          } else {
               $exp = -1;
          }
     } else {
          $basis = pow((1/$faktor),(1/7));
          if (($hoher-$aktwert) > ($differenz/$faktor)) {
               $exp = log10(-(($aktwert-$hoher) / ($differenz * $faktor))) / log10($basis);
               $exp = ceil(13 - $exp);
          } elseif ($aktwert < $hoher) {
               $exp = -0;
          } else {
               $exp = -1;
          }
     }
     $stufe = floor($exp+0.001);

     if ($stufe < 7) {
          $stufe = 7 - $stufe;
          if ($stufe > 8) { $stufe = 8; }
          $farbe = "red";
     } else {
          $stufe = round($stufe - 6);
          if ($stufe > 7) { $stufe = 7; }
          $farbe = "green";
     }
     return substr($farbe,0,1) . $stufe;
}
?>