$result = mysql_query($sql);
        if (mysql_error()) {
            trigger_error(mysql_error(), E_USER_WARNING);
        }
        echo "<tr><th colspan='2'>{$strPriority}</th><th>{$strInitialResponse}</th>";
        echo "<th>{$strProblemDefinition}</th><th>{$strActionPlan}</th><th>{$strResolutionReprioritisation}</th>";
        echo "<th>{$strReview}</th><th>{$strTimed}</th><th>{$strOperation}</th></tr>";
        while ($sla = mysql_fetch_object($result)) {
            echo "<tr>";
            echo "<td align='right'>" . priority_icon($sla->priority) . "</td>";
            echo "<td>" . priority_name($sla->priority) . "</td>";
            echo "<td>" . format_workday_minutes($sla->initial_response_mins) . "</td>";
            echo "<td>" . format_workday_minutes($sla->prob_determ_mins) . "</td>";
            echo "<td>" . format_workday_minutes($sla->action_plan_mins) . "</td>";
            // 480 mins in a working day
            echo "<td>" . format_workday_minutes($sla->resolution_days * 480) . "</td>";
            echo "<td>" . sprintf($strXDays, $sla->review_days) . "</td>";
            if ($sla->timed == 'yes') {
                echo "<td>{$strYes}</td>";
            } else {
                echo "<td>{$strNo}</td>";
            }
            echo "<td><a href='service_level_edit.php?tag={$sla->tag}&amp;priority={$sla->priority}'>{$strEdit}</a></td>";
            echo "</tr>\n";
        }
    }
    echo "</table>";
} else {
    echo "<p class='error'>{$strNoRecords}</p>";
}
include APPLICATION_INCPATH . 'htmlfooter.inc.php';
 if ($targettype != '') {
     if ($slaremain > 0) {
         echo sprintf($strSLAInX, $targettype, format_workday_minutes($slaremain));
     } elseif ($slaremain < 0) {
         echo " " . sprintf($strSLAXLate, $targettype, format_workday_minutes(0 - $slaremain));
     } else {
         echo " " . sprintf($strSLAXDueNow, $targettype);
     }
 }
 if ($reviewremain > 0 && $reviewremain <= 2400) {
     // Only display if review is due in the next five days
     if ($slaremain != 0) {
         echo "<br />";
     }
     // only need a line sometimes
     printf($strReviewIn, format_workday_minutes($reviewremain));
 } elseif ($reviewremain <= 0) {
     if ($slaremain != 0) {
         echo "<br />";
     }
     // only need a line sometimes
     echo $strReviewDueNow;
 }
 if ($servicelevel->timed == 'yes') {
     echo "<br />";
     switch (count($num_open_activities)) {
         case 0:
             //start
             echo "<a href='task_add.php?incident={$id}'>{$strStartNewActivity}</a>";
             break;
         case 1:
        }
        echo "<tr class='{$class}'>";
        echo "<td>";
        echo icon($slatypes[$history['targetsla']]['icon'], 16) . " ";
        echo target_type_name($history['targetsla']) . "</td>";
        echo "<td>";
        if (!empty($history['userid'])) {
            echo user_realname($history['userid'], TRUE);
        }
        echo "</td>";
        echo "<td>" . format_workday_minutes($history['targettime']) . "</td>";
        echo "<td>";
        if ($history['timestamp'] == 0) {
            echo "<em>";
        }
        echo format_workday_minutes($history['actualtime']);
        if ($history['timestamp'] == 0) {
            echo "</em>";
        }
        echo "</td>";
        echo "<td>";
        if ($history['timestamp'] > 0) {
            echo ldate($CONFIG['dateformat_datetime'], $history['timestamp']);
        }
        echo "</td>";
    }
    echo "</table>\n";
} else {
    echo "<p align='center'>{$strNothingToDisplay}.<p>";
}
//start status summary
        }
    } else {
        echo $strNone;
    }
    echo "</td>";
    // Final column
    if ($reviewremain > 0 && $reviewremain <= 2400) {
        // Only display if review is due in the next five days
        echo "<td align='center'>";
        echo sprintf($strReviewIn, format_workday_minutes($reviewremain));
    } elseif ($reviewremain <= 0) {
        echo "<td align='center' class='review'>";
        if ($reviewremain > -86400) {
            echo "" . icon('review', 16) . " {$strReviewDueNow}";
        } else {
            echo "" . icon('review', 16) . " " . sprintf($strReviewDueAgo, format_workday_minutes($reviewremain * -1));
        }
    } else {
        echo "<td align='center'>";
        if ($incidents['status'] == 2) {
            echo "{$strAge}: " . format_seconds($incidents["duration_closed"]);
        } else {
            echo sprintf($strXold, format_seconds($incidents["duration"]));
        }
    }
    echo "</td>";
    echo "</tr>\n";
}
echo "</table><br /><br />\n\n";
echo "<table class='incidentkey'><tr>";
echo "<td class='shade1'>{$strOpen}</td>";
             $csv .= "<td>{$obj->id}</td><td>{$obj->title}</td>";
             $csv .= "<td>{$obj->forenames} {$obj->surname}</td>";
             $csv .= "<td>" . software_name($obj->softwareid) . "</td>";
             $csv .= "<td>" . incidentstatus_name($obj->status) . "</td>";
             $csv .= "<td>" . user_realname($obj->owner) . "</td>";
             $csv .= "<td>" . format_date_friendly($obj->opened) . "</td>";
             $csv .= "<td>";
             if ($obj->closed > 0) {
                 $csv .= format_date_friendly($obj->closed);
             } else {
                 $csv .= $strCurrentlyOpen;
             }
             $csv .= "</td>";
             $csv .= "<td>";
             if ($obj->closed > 0) {
                 $csv .= format_workday_minutes($obj->closed - $obj->opened);
             }
             $csv .= "</td>";
             $csv .= "<td>{$obj->servicelevel}</td>";
             $csv .= "</tr>";
             if ($shade1 == 'shade1') {
                 $shade1 = 'shade2';
             } else {
                 $shade1 = 'shade1';
             }
         }
         $csv .= "</table>";
         $csv .= "</td></tr>";
     }
 }
 if ($shade == 'shade1') {