$id = cleanvar($_REQUEST['id']);
$incidentid = $id;
$title = $strClose;
// No submit detected show closure form
if (empty($_REQUEST['process'])) {
    $sql = "SELECT owner FROM `{$dbIncidents}` WHERE id = '{$incidentid}'";
    $result = mysql_query($sql);
    if (mysql_error()) {
        trigger_error(mysql_error(), E_USER_WARNING);
    }
    list($owner) = mysql_fetch_row($result);
    if ($owner == 0) {
        html_redirect("incident_details.php?id={$incidentid}", FALSE, $strCallMustBeAssignedBeforeClosure);
        exit;
    }
    if (count(open_activities_for_incident($incidentid)) > 0) {
        html_redirect("incident_details.php?id={$incidentid}", FALSE, $strMustCompleteActivitiesBeforeClosure);
        exit;
    }
    include APPLICATION_INCPATH . 'incident_html_top.inc.php';
    ?>
    <script type="text/javascript">
    <!--
    function enablekb()
    {
        // INL 28Nov07 Yes I know a lot of this javascript is horrible
        // it's old and I'm tired and can't be bothered right now
        // the newer stuff at the bottom is pretty and uses prototype.js
        // syntax
        if (document.closeform.kbtitle.disabled==true)
        {
/**
 * Returns the number of open activities/timed tasks for a site
 * @author Paul Heaney
 * @param int $siteid. Site ID you want
 * @returns int. Number of open activities for the site (0 if non)
 */
function open_activities_for_site($siteid)
{
    global $dbIncidents, $dbContacts;
    $openactivites = 0;
    if (!empty($siteid) and $siteid != 0) {
        $sql = "SELECT i.id FROM `{$dbIncidents}` AS i, `{$dbContacts}` AS c ";
        $sql .= "WHERE i.contact = c.id AND ";
        $sql .= "c.siteid = {$siteid} AND ";
        $sql .= "(i.status != 2 AND i.status != 7)";
        $result = mysql_query($sql);
        while ($obj = mysql_fetch_object($result)) {
            $openactivites += count(open_activities_for_incident($obj->id));
        }
    }
    return $openactivites;
}
    echo "{$strContract} {$incident->maintenanceid}";
    echo "</a>";
} else {
    echo "<strong>{$strSiteSupport}</strong>";
}
echo " / ";
echo "{$servicelevel_tag}<br />\n ";
switch (does_contact_have_billable_contract($incident->contactid)) {
    case CONTACT_HAS_BILLABLE_CONTRACT:
        echo "{$strContactHasBillableContract} (&cong;" . contract_unit_balance(get_billable_contract_id($incident->contactid)) . " units)<br />";
        break;
    case SITE_HAS_BILLABLE_CONTRACT:
        echo "{$strSiteHasBillableContract} (&cong;" . contract_unit_balance(get_billable_contract_id($incident->contactid)) . " units)<br />";
        break;
}
$num_open_activities = open_activities_for_incident($incidentid);
if (count($num_open_activities) > 0) {
    echo "<a href='tasks.php?incident={$incidentid}' class='info'>";
    echo icon('timer', 16, $strOpenActivities);
    echo "</a> ";
}
if (drafts_waiting_on_incident($incidentid, 'email')) {
    echo "<a href='javascript:email_window({$incidentid})' class='info'>";
    echo icon('email', 16, $strDraftsEmailExist);
    echo "</a> ";
}
if (drafts_waiting_on_incident($incidentid, 'update')) {
    echo "<a href='incident_update.php?id={$incidentid}&amp;popup=' class='info'>";
    echo icon('note', 16, $strDraftsUpdateExist);
    echo "</a> ";
}
     $externalid = "<a href=\"{$epathurl}\" title=\"{$epath[$escalationpath]['url_title']}\">{$epath[$escalationpath]['name']}</a>";
 } elseif (empty($incidents['escalationpath']) and !empty($incidents['externalid'])) {
     $externalid = format_external_id($incidents['externalid']);
 }
 echo "<tr class='{$class}'>";
 echo "<td align='center'>";
 echo "<a href='incident_details.php?id={$incidents['id']}' class='direct'>{$incidents['id']}</a>";
 if ($externalid != '') {
     echo "<br />{$externalid}";
 }
 echo "</td>";
 echo "<td>";
 if (!empty($incidents['softwareid'])) {
     echo software_name($incidents['softwareid']) . "<br />";
 }
 if (count(open_activities_for_incident($incidents['id'])) > 0) {
     echo icon('timer', 16, $strOpenActivities) . ' ';
 }
 if (drafts_waiting_on_incident($incidents['id'])) {
     echo icon('note2', 16, $strDraftsExist) . ' ';
 }
 echo "<a href=\"javascript:incident_details_window('{$incidents['id']}','incident{$incidents['id']}')\" class='info'>";
 if (trim($incidents['title']) != '') {
     echo $incidents['title'];
 } else {
     echo $strUntitled;
 }
 if (!empty($update_body) and $update_body != '...') {
     echo "<span>{$update_body}</span>";
 } else {
     $update_currentownername = user_realname($update_currentowner, TRUE);