示例#1
0
/**
 * Creates an incident based on an 'tempincoming' table entry
 * @author Kieran Hogg
 * @param int $incomingid the ID of the tempincoming entry
 * @return int|bool returns either the ID of the contract or FALSE if none
 */
function create_incident_from_incoming($incomingid)
{
    global $dbTempIncoming, $dbMaintenance, $dbServiceLevels, $dbSoftwareProducts, $CONFIG;
    $rtn = TRUE;
    $incomingid = intval($incomingid);
    $sql = "SELECT * FROM `{$dbTempIncoming}` ";
    $sql .= "WHERE id = '{$incomingid}'";
    $result = mysql_query($sql);
    if (mysql_error()) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $row = mysql_fetch_object($result);
    $contact = $row->contactid;
    $contract = guess_contract_id($contact);
    if (!$contract) {
        // we have no contract to log against, update stays in incoming
        return TRUE;
    }
    $subject = $row->subject;
    $update = $row->updateid;
    $sql = "SELECT servicelevelid, tag, product, softwareid ";
    $sql .= "FROM `{$dbMaintenance}` AS m, `{$dbServiceLevels}` AS s, ";
    $sql .= "`{$dbSoftwareProducts}` AS sp ";
    $sql .= "WHERE m.id = '{$contract}' ";
    $sql .= "AND m.servicelevelid = s.id ";
    $sql .= "AND m.product = sp.productid LIMIT 1";
    $result = mysql_query($sql);
    if (mysql_error()) {
        trigger_error(mysql_error(), E_USER_ERROR);
        $rtn = FALSE;
    }
    $row = mysql_fetch_object($result);
    $sla = $row->tag;
    $product = $row->product;
    $software = $row->softwareid;
    $incident = create_incident($subject, $contact, $row->tag, $contract, $product, $software);
    if (!move_update_to_incident($update, $incident)) {
        $rtn = FALSE;
    }
    if ($CONFIG['auto_assign_incidents']) {
        $user = suggest_reassign_userid($incident);
        if (!reassign_incident($incident, $user)) {
            $rtn = FALSE;
        }
    }
    return $rtn;
}
        if (empty($updateid)) {
            echo "<table class='vertical'>";
            echo "<tr><th>{$strUpdate}</th><td><textarea name='bodytext' rows='20' ";
            echo "cols='60'></textarea></td></tr>";
            echo "<tr><th>{$strStatus}</th><td>" . incidentstatus_drop_down("newstatus", 1);
            echo "</td></tr>\n";
            echo "</table>";
        } else {
            echo "<p align='center'>{$strReopenIncidentAndAddUpdate}</p>";
        }
        echo "<p><input name='submit' type='submit' value='{$strReopen}' /></p>";
        echo "</form>";
        include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';
    } else {
        $reopen = reopen_incident($id);
        $move = true;
        // Default so we dont get an error if there is no updateid on a reopen (as is the case when reopening from incident_details)
        if (!empty($updateid)) {
            $move = move_update_to_incident($updateid, $id) and delete_holding_queue_update($updateid);
        }
        if (!($result and $move)) {
            include APPLICATION_INCPATH . 'incident_html_top.inc.php';
            echo "<p class='error'>{$strUpdateIncidentFailed}</p>\n";
            include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';
        } else {
            html_redirect($returnurl);
        }
    }
} else {
    html_redirect($returnurl, FALSE, $strServiceLevelPreventsReopen);
}