/**
 * Update the order status and the order status history in database
 * @param int $orderId
 * @param array $status
 * @param string $comment
 */
function updateOrderStatus($PnagInvoice, $orderId, $status, $comment, $time, $newTotal, $isReanimatedInvoice = false)
{
    $comments = '';
    if (!$orderId) {
        exit("No order_id given to function updateOrderStatus(). Exit!");
    }
    if ($newTotal) {
        $comments = insertNewTotalCommentToHistory($orderId, $status, $time, $newTotal);
    }
    $SofortOrderSynchronisation = new sofortOrderSynchronisation();
    $SofortOrderSynchronisation->editArticlesShop($PnagInvoice, $orderId);
    $completeInvoiceStatus = $PnagInvoice->getState();
    if (!commentIsValid($orderId, $completeInvoiceStatus) && !$isReanimatedInvoice) {
        echo MODULE_PAYMENT_SOFORT_SR_STATUSUPDATE_UNNECESSARY;
        return $comments;
    }
    xtc_db_query('UPDATE ' . HelperFunctions::escapeSql(TABLE_ORDERS) . ' SET orders_status = "' . HelperFunctions::escapeSql($status) . '", last_modified = now() WHERE orders_id = ' . (int) $orderId . ';');
    $sqlDataArray = array('orders_id' => (int) $orderId, 'orders_status_id' => $status, 'date_added' => 'sqlcommand:now()', 'customer_notified' => 0, 'comments' => $comment . ' ' . MODULE_PAYMENT_SOFORT_SR_TRANSLATE_TIME . ': ' . $time);
    xtc_db_query(HelperFunctions::getEscapedInsertInto(TABLE_ORDERS_STATUS_HISTORY, $sqlDataArray));
    echo MODULE_PAYMENT_SOFORT_SUCCESS_CALLBACK;
    return $comments;
}