functions.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * DON'T REMOVE THE FOLLOWING LICENSE
  4. * INFORMATION!
  5. * ----------------------------------
  6. * Copyright by
  7. * Dennis Ritz
  8. * Author: Dennis Ritz
  9. * dennis.ritz@gmx.net
  10. * 2007-2008
  11. * ----------------------------------
  12. */
  13. function getFileExtension ($filename)
  14. {
  15. $path_parts = pathinfo($filename) ;
  16. return strtolower($path_parts['extension']);
  17. }
  18. function module_autoload($p_comp){
  19. while(substr($p_comp,0,1) == "/" || substr($p_comp,0,1) == ".") {
  20. $p_comp = substr($p_comp,1);
  21. }
  22. if(file_exists(ROOT_DIR."apps/".$p_comp."/".$p_comp.".class.inc")) {
  23. include (ROOT_DIR."apps/".$p_comp."/".$p_comp.".class.inc");
  24. if(class_exists($p_comp,false)) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. } else {
  30. return false;
  31. }
  32. }
  33. spl_autoload_register("module_autoload");
  34. function umwandeln($var) {
  35. $var = str_replace("%","",$var);
  36. $var = str_replace(".","",$var);
  37. $var = str_replace(",",".",$var);
  38. $var = floatval($var);
  39. return $var;
  40. }
  41. function getImgAlarmstufeSrc($aktwert,$niedriger,$hoher,$positiv) {
  42. $aktwert = umwandeln($aktwert);
  43. $niedriger = umwandeln($niedriger);
  44. $hoher = umwandeln($hoher);
  45. $differenz = $hoher - $niedriger;
  46. $faktor = 8;
  47. if ($hoher == 0 || $niedriger == 0) {
  48. $hoher = $hoher + 0.001;
  49. $niedriger = $niedriger + 0.001;
  50. }
  51. if ($positiv=="J") {
  52. $basis = pow($faktor,(1/7));
  53. if (($aktwert-$niedriger) > ($differenz/$faktor)) {
  54. $exp = log10((($aktwert-$niedriger) / $differenz) * $faktor) / log10($basis);
  55. } elseif ($aktwert > $niedriger) {
  56. $exp = 0;
  57. } else {
  58. $exp = -1;
  59. }
  60. } else {
  61. $basis = pow((1/$faktor),(1/7));
  62. if (($hoher-$aktwert) > ($differenz/$faktor)) {
  63. $exp = log10(-(($aktwert-$hoher) / ($differenz * $faktor))) / log10($basis);
  64. $exp = ceil(13 - $exp);
  65. } elseif ($aktwert < $hoher) {
  66. $exp = -0;
  67. } else {
  68. $exp = -1;
  69. }
  70. }
  71. $stufe = floor($exp+0.001);
  72. if ($stufe < 7) {
  73. $stufe = 7 - $stufe;
  74. if ($stufe > 8) { $stufe = 8; }
  75. $farbe = "red";
  76. } else {
  77. $stufe = round($stufe - 6);
  78. if ($stufe > 7) { $stufe = 7; }
  79. $farbe = "green";
  80. }
  81. return substr($farbe,0,1) . $stufe;
  82. }
  83. function utf8_to_latin1($string) {
  84. if (function_exists('mb_convert_encoding')) {
  85. return mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
  86. } else {
  87. return utf8_encode($string);
  88. }
  89. }
  90. function latin1_to_utf8($string) {
  91. if (function_exists('mb_convert_encoding')) {
  92. return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
  93. } else {
  94. return utf8_decode($string);
  95. }
  96. }
  97. ?>