View Reported Outages

query(“call GetCatName(‘$catID’)”))
{
$row = $res->fetch_assoc();
$catName = $row[‘Category_Text’];
}
else
{
$log->logError(“Error getting series name: (” . $mysqli->errno . “) ” . $mysqli->error);
}
echo(“

“);
echo(“
“);

$rowAlt = false;
$rowAltColor = “#DDDDDD”;

$catID = ‘170’;
$questionIDs = array();

$headerRow = array();
$headerReference = array();

// SO COMMANDS AREN’T OUT OF SYNC
$mysqli->next_result();

// get the question names column headers
if($res = $mysqli->query(“call GetQuestionNamesForCategory(‘$catID’)”))
{
// we are creating sort of a reverse associative array (the column names as the IDs and the
// array position as the values) so we know where each column is located
// $headerRow holds the display names of the columns, $headerReference holds the
// the question IDs (because questions could possibly have the same name)
$headerRow[“Ticket ID”] = 0;
$headerRow[“Date”] = 1;
$headerRow[“Time”] = 2;

// for some reason headerRow does not return the above hard-coded values, but headerReference
// does. ????????????????????????????????
$headerReference[“Ticket ID”] = 0;
$headerReference[“Date”] = 1;
$headerReference[“Time”] = 2;

// create a counter to keep track of the index of each field
$counter = 3;

// fetch all the question names for the selected category
while($row = $res->fetch_assoc())
{
$headerRow[$row[‘Question_Name’]] = $counter;
$headerReference[$row[‘Question_ID’]] = $counter;
$counter++;
}

$log->logInfo(“Created headerRow array”);

echo(“

“);
foreach($headerRow as $key => $value)
{
echo(“

“);
}
echo(“

“);
echo(“

“);
echo(“

“);
}
else
{
$log->logError(“Error getting question header names: (” . $mysqli->errno . “) ” . $mysqli->error);
}

$mysqli->next_result();

// get the list of Ticket IDs that are not active (ie: they are completed)
if($res = $mysqli->query(“call GetCompletedSessionIDs(‘$catID’)”))
{
// fetch all the question rows
for($i = 0; $i < 25; $i++) { $row = $res->fetch_assoc();
if($row != null){
$log->logInfo(“Creating sessionAnswers array. session index: (” . $headerReference[“Ticket ID”] . “), user index: (” . $headerReference[“User ID”] . “)”);
$sessionAnswers = array();
// we manually fill in the session and user IDs
$sessionAnswers[$headerReference[“Ticket ID”]] = $row[‘Session_ID’];

$sessionID = $row[‘Session_ID’];
//$curRow = “”;

$mysqli->next_result();

$log->logInfo(“Calling GetAnswersFromSession: (” . $sessionID . “)”);

// get the answers for the selected Ticket ID
if($res2 = $mysqli->query(“call GetAnswersFromSession(‘$sessionID’)”))
{
$dateCompleted = “”;

while($row2 = $res2->fetch_assoc())
{
// we want the date that the last answer was added
$dateCompleted = $row2[‘Date_Added’];

$log->logInfo(“Date completed in while: (” . $dateCompleted . “)”);

// get the array position for the answer from the header reference array, given the question ID
$answerPosition = $headerReference[$row2[‘Question_ID’]];

$log->logInfo(“Answer position: (” . $answerPosition . “)”);
$log->logInfo(“Answer text: (” . $row2[‘Answer_Body’] . ” ” . $row2[‘Answer_Text’] . “)”);

// if there is already an answer in the current answerPosition (we have multiple answers
// for that question) append the new answer onto it
if($sessionAnswers[$answerPosition] != null)
{
if($row2[‘Answer_Text’] == null){
$sessionAnswers[$answerPosition] .= “, ” . $row2[‘Answer_Body’];}
else{
$sessionAnswers[$answerPosition] .= “, ” . $row2[‘Answer_Text’];}
}
else
{
if($row2[‘Answer_Text’] == null){
$sessionAnswers[$answerPosition] .= ” ” . $row2[‘Answer_Body’];}
else{
$sessionAnswers[$answerPosition] .= ” ” . $row2[‘Answer_Text’];}
}
}
$log->logInfo(“GetAnswersFromSession while loop complete”);
$log->logInfo(“Date completed above loop: (” . $headerReference[“Date Completed”] . “) (” . $dateCompleted . “)”);
// we add the date here because it will be the date of the last answer by now
$dateCompleted = strtotime($dateCompleted);
$ticketDate = date(‘n/j/Y’, $dateCompleted);
$ticketTime = date(‘g:i A’, $dateCompleted);
$sessionAnswers[$headerReference[“Date”]] = $ticketDate;
$sessionAnswers[$headerReference[“Time”]] = $ticketTime;

// make every other row a different color
if($rowAlt)
{
echo(“

“);
$rowAlt = false;
}
else
{
echo(“
“);
$rowAlt = true;
}

$log->logInfo(“Starting to loop through answers”);

// make sure that the $headerRow array is in ascending order, based on the values of the array
sort($headerRow);

foreach($headerRow as $key => $answerIndex)
{
$log->logInfo(“Adding answer: (” . $answerIndex . “), (” . $sessionAnswers[$answerIndex] . “)”);
if($answerIndex == 6 && $sessionAnswers[$answerIndex] != ”){
echo(“

“);
}
else{
echo(“

“);
}
}
echo(“

“);
echo(“

“);
echo(“

“);
}
else
{
$log->logError(“Error getting answers from session: (” . $mysqli->errno . “) ” . $mysqli->error);
}
}
}
}
else
{
$log->logError(“Error getting Ticket IDs for category [catID=” . $catID . “]: (” . $mysqli->errno . “) ” . $mysqli->error);
}

echo(“

” . $key . “ View as XML View as Ticket
XXX-XXX-“.substr($sessionAnswers[$answerIndex],-4) . “ ” . $sessionAnswers[$answerIndex] . “ view XML view ticket

“);
$mysqli->close();
?>