$params = array();
     $params['subject'] = $subject;
     $params['status'] = $newStatusId;
     $params['priority'] = $_POST['priorities'];
     $params['department'] = $deptid;
     $params['contact'] = $sirportlyContact;
     ## Custom field params
     foreach ($customfield as $cf => $value) {
         $params["custom[{$cf}]"] = $value;
     }
     ## Submit the ticket to Sirportly
     $sirportlyTicket = _doSirportlyAPICall('tickets/submit', $params);
     ## Check to see if we encountered any errors
     if (checkForSirportlyErrors($sirportlyTicket)) {
         $step = 2;
         $formattedErrorMessages = formatSirportlyErrors($ticket['errors']);
         $ca->assign('errormessage', $formattedErrorMessages);
         $ca->setTemplate('/templates/sirportly/supportticketsubmit-steptwo.tpl');
         $ca->output();
         return;
     }
     ## Add the first update
     $sirportlyTicketUpdate = _doSirportlyAPICall('tickets/post_update', array('ticket' => $sirportlyTicket['reference'], 'authenticated' => true, 'attachments' => implode($attachedFiles), 'contact' => $sirportlyTicket['contact']['id'], 'message' => $message));
     ## Set the ticket variables
     $_SESSION['tempticketdata'] = array('tid' => $sirportlyTicket['reference'], 'c' => $sirportlyTicket['id'], 'subject' => $sirportlyTicket['subject']);
     ## Redirect to the next step
     redir("step=4");
     break;
 case '4':
     $ca->assign("tid", $_SESSION['tempticketdata']['tid']);
     $ca->assign("c", $_SESSION['tempticketdata']['c']);
if ($postreply) {
    check_token();
    if (!$replymessage) {
        $errormessage .= "<li>" . $_LANG['supportticketserrornomessage'];
    }
    $ca->assign('postingReply', isset($postreply));
    $ca->assign('errormessage', $errormessage);
    ## If we're error free attempt to submit the update to Sirportly
    if (!$errormessage) {
        ## Upload any attachments and store their tokens
        $attachedFiles = sirportly_upload_attachments($_FILES['attachments']);
        ## Submit the update
        $sirportlyTicketUpdate = _doSirportlyAPICall('tickets/post_update', array('ticket' => $tid, 'message' => $replymessage, 'attachments' => implode($attachedFiles), 'contact' => $sirportlyContact));
        ## Check to see if we encountered any errors
        if (checkForSirportlyErrors($sirportlyTicketUpdate)) {
            $formattedErrorMessages = formatSirportlyErrors($update['errors']);
            $ca->assign('errormessage', $formattedErrorMessages);
        } else {
            redir("tid=" . $tid . "&c=" . $c);
        }
    }
}
## Setup the updates
$updates = array();
foreach ($response['updates'] as $update) {
    if (!$update['private']) {
        ## Sort the attachments
        $attachments = array();
        foreach ($update['attachments'] as $attachment) {
            $attachments[] = array('id' => $attachment['id'], 'name' => $attachment['name']);
        }