<?php
include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../illt/inc_serviceunit.inc.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");
include_once ("../locating/xServer.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "mode", "actionObjType", "actionObjId", "rootStockSU", "crvhId", "currDay", "hour", "hourUnit", "timeslots", "jbId", "csId", "content", "crvhSidMovedTo",
                         "filter_1", "filter_2", "filter_3", "filter_4", "filter_5", "containerCssWidth"));

if ($mode != "") :
   header("Content-Type: text/html; charset=ISO-8859-1\n");
endif;
                           
// echo "alert('" . $mode . " ' + '" . $actionObjType . " ' + '" . $actionObjId . " ' + '" . $currDay . " ' + '" . $jbId . " ');";


// Default CSS
// ----------------
// Constants
$constMenuItemWidth = "100px";
$constMenuColWidth  = "100px";
$constBackground = "#CDD9FD";
$constMenuBackground = array();
  $constMenuBackground[0] = "#1b12b9";
  $constMenuBackground[1] = "#1b12b9";
  $constMenuBackground[2] = "#4e45ec";
  $constMenuBackground[3] = "#97bcFF";
$constMenuBackgroundImage = array();
  $constMenuBackgroundImage[0] = "spacer_blue_menu_01.jpg";
  $constMenuBackgroundImage[1] = "spacer_blue_menu_01.jpg";
  $constMenuBackgroundImage[2] = "spacer_blue_menu_02.jpg";
  $constMenuBackgroundImage[3] = "spacer_blue_menu_03.jpg";
$constMenuColor = array();
  $constMenuColor[0] = "#FFFFFF";
  $constMenuColor[1] = "#FFFFFF";
  $constMenuColor[2] = "#FFFFFF";
  $constMenuColor[3] = "#FFFFFF";
$constMaincontentBackground = "#CDD9FD";
$constMaincontent2Background = "#CDD9FD";
$constButtonBackground = "#1b12b9";
$constButtonColor = "#FFFFFF";
$constButtonColor2 = "#4e45ec";
$constButtonOnMouseOverColor = "#97bcFF";
$constListBgCol1 = "#AAAAFF";
$constListBgCol2 = "#AAAAFF";
$constListBgCol3 = "#CCCCFF";
$constListBgCol4 = "#CCCCFF";
$constPageHeadlineBgCol = "#1b12b9";
$constTickerBgCol = "#CDD9FD";

$atiColsTypesArray = array();   // Represents the fields ati_data_01, ati_data_02, ..., ati_data_xx only!
$atiColsTypes = getParameterValue("0", "STK_ATI_COLUMN_TYPES", $hq_id);
if ($atiColsTypes != "") :
   $atiColsTypesArray = spliti(",", $atiColsTypes);
else :
   // Default
   $atiColsTypesArray = array("varchar","number","number","date","integer","float2","integer","float2","float2","","","","","","","","","","integer","integer");
endif;

$colArray = array();
$colArray["bg"] = $constBackground;
$colArray["blue"]   = "#0000FF";
$colArray["green"]  = "#00FF00";
$colArray["red"]    = "#FF0000";
$colArray["white"]  = "#FFFFFF";
$colArray["yellow"] = "#FFFF00";
$colArray["black"]  = "#000000";
$colArray["gray"]   = "#DDDDDD";
$colArray["gold"]   = "#969325";
$colArray["beige"]  = "#EFE4B0";
$colArray["light_red"]    = "#FF8888";
$colArray["light_green"]  = "#88FF88";
$colArray["light_blue"]   = "#8888FF";
$colArray["light_yellow"] = "#FFFF88";
$colArray["light_gray"]   = "#EEEEEE";

if ($containerCssWidth == "") : $containerCssWidth = "900"; endif;

// Number of data fields in "articleitem" (ati_data_01, ati_data_02, ...)
$maxNumOfAtiDataFields = getParameterValue("0", "MAX_NUM_OF_ATI_DATA_FIELDS", $hq_id);
if ($maxNumOfAtiDataFields == "" || !is_numeric($maxNumOfAtiDataFields)) :
   $maxNumOfAtiDataFields = "30";
endif;

// Init array for threshold values
$f_tv = array();

// ----------------


// Output service unit message data
function outSuMsgData($actionObjId, $outDataArray) {
	global $colArray, $containerCssWidth;
  $outputData = "";
  $outDataArrayLen = count($outDataArray);
  $outputData .= "<table>\n"
               . "<tr>\n"
               . "  <td class=\"f10bp1_blue\">" . getLngt("BETRIEBSMELDUNGEN:") . "&nbsp;&nbsp;&nbsp;&nbsp;</td>\n"
               . "</tr>\n"
               . "</table><br>\n";  
  if ($outDataArrayLen > 0) :
     $outputData .= "<table width=\"" . $containerCssWidth . "px\" border=\"1\">"
                  . "  <tr>"
                  . "    <td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $actionObjId . "<b></td>"
                  . "  </tr>"
                  . "  <tr>"
                  . "    <td class=\"f8np1\" style=\"width:100;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Code") . "</b></td>"
                  . "    <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Beschreibung") . "</td>"
                  . "    <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Text") . "</td>"
                  . "  </tr>";
     for ($j = 0; $j < $outDataArrayLen; $j++) :
         $outputData .= $outDataArray[$j];
     endfor;
     $outputData .= "</table>";
  endif;
  return $outputData;
}

// Output log data
function outSuHistoryData($actionObjType, $actionObjId, $rootStockSU, $outDataArray, $filter_1) {
	global $colArray, $containerCssWidth;
  $outputData = "";
  $outDataArrayLen = count($outDataArray);
  $outputData .= "<table>\n"
               . "<tr>\n"
               . "  <td class=\"f10bp1_blue\">" . getLngt("ZUSTANDSVERLAUF:") . "&nbsp;&nbsp;&nbsp;&nbsp;</td>\n"
               . "  <td>\n"
               . "    <select name=\"f_suhd_filter_1\" onChange=\"ajaxRequestContainerHtmlGet('../illt/ajaxReqIllt.php', 'cc_01', 'mode=getSuHistoryData&actionObjType=" . $actionObjType . "&actionObjId=" . $actionObjId . "&filter_1=' + getSelectedValue('f_suhd_filter_1') + '&rootStockSU=" . $rootStockSU . "');\">\n"
       	       . "      <option value=\"0\" " . ($filter_1 == "0" ? "selected" : "") . ">" . getLngt("Alle Zustandsdatensätze") . "</option>\n"
       	       . "      <option value=\"1\" " . ($filter_1 == "1" ? "selected" : "") . ">" . getLngt("Kritische Zustandsdatensätze (mindestens ein Wert)") . "</option>\n"
       	       . "      <option value=\"2\" " . ($filter_1 == "2" ? "selected" : "") . ">" . getLngt("Unkritische Zustandsdatensätze (alle Werte)") . "</option>\n"
               . "    </select>&nbsp;&nbsp;&nbsp;&nbsp;\n"
               . "  </td>\n"
               . "  <td>\n"
               . defineButtonType08("Aktualisieren", "action_log_reload", "finishPage('processAction');", "140", "", "", "", "", "", "", "1")
               . "  </td>\n"
               . "</tr>\n"
               . "</table><br>\n";
  if ($outDataArrayLen > 0) :
     $outputData .= "<table width=\"" . $containerCssWidth . "px\" border=\"1\">"
                  . "  <tr><td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $actionObjId . "<b></td></tr>"
                  . "  <tr>"
                  . "    <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('0');\"><b>" . getLngt("Zeitpunkt") . "</b></td>"
                  . "    <td class=\"f8np1\" style=\"width: 60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('1');\"><b>" . getLngt("BEK") . "</td>"
                  . "    <td class=\"f8np1\" style=\"width: 60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('2');\"><b>" . getLngt("MEK") . "</td>"
                  . "    <td class=\"f8np1\" style=\"width: 60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('3');\"><b>" . getLngt("H1") . "</td>"
                  . "    <td class=\"f8np1\" style=\"width: 60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('4');\"><b>" . getLngt("H2") . "</td>"
                  . "    <td class=\"f8np1\" style=\"width: 60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('5');\"><b>" . getLngt("H3") . "</td>"
                  . "  </tr>";
     for ($j = 0; $j < $outDataArrayLen; $j++) :
         $outputData .= $outDataArray[$j];
     endfor;
     $outputData .= "</table>";
  endif;
  return $outputData;
}


// ***********
// * ACTIONS *
// ***********
if ($mode == "getSuMessageData") :

   // Service unit messages
   $retVal = "";
   if ($actionObjId != "") :
      $outMessageArray = array();
      getSuMessageData($actionObjId);
      $retVal = outSuMsgData($actionObjId, $outMessageArray);
   endif;
   echo $retVal;


elseif ($mode == "getSuHistoryData") :

   $retVal = "";
   if ($actionObjType != "" && $actionObjId != "" && $rootStockSU != "") :   

      // Get vector of article(type) IDs ("at_id") of service units
      // $suAtIdArray = getColVectorFromDB2ArrayByClause("phoenix.article", "at_id", "at_group = '," . $suGroupId . ",'", "", "at_id");
      $suAtIdString = getParameterValue("0", "SU_AT_TYPES_FOR_TV", $hq_id);
      $suAtIdArray = explode(",", $suAtIdString);
      $suAtIdArrayLen = count($suAtIdArray);
      
      // Get thresholdvalues
      getThresholdValues($suAtIdArray);
      
      // Get type of the service unit for corresponding threashold values
      $atId = getFieldValueFromId("phoenix.articleitem", "ati_serialno ", $actionObjId, "at_id");      

      /*
      $jsTv = "";
      for ($j = 1; $j <= $maxNumOfAtiDataFields; $j++) :
          if ($f_tv[$atId][$j] != "" && is_numeric($f_tv[$atId][$j])) :
             $jsTv .= "&value_". pad($j,2) . "=" . $f_tv[$atId][$j];
          endif;
      endfor;
      */
      if ($filter_1 == "") : $filter_1 = "0"; endif;
      $f_log_filter_1 = $filter_1;
      $outLogArray = array();
      getSuHistoryData("0", "AND stk.stk_pre_id = '" . $rootStockSU . "' AND atih.atih_serialno = '" . $actionObjId . "'");
      $retVal = outSuHistoryData($actionObjType, $actionObjId, $rootStockSU, $outLogArray, $filter_1);
   endif;
   echo $retVal;

endif;

?>