global $messageStack;
            $msg = "Authentication failed with error: <code>" . $response->getConnectionError() . '<br>' . strip_tags($response->getResponseBody) . '</code>';
            $messageStack->add_session($msg, 'error');
        }
        $gbhttp->close();
    } else {
        zen_redirect(gb_get_authentication_url());
    }
}
if (zen_not_null($action)) {
    if ($action == 'options') {
        $gb->editOptions();
    } else {
        if ($action == 'revoke' && $is_authenticated) {
            require_once DIR_FS_CATALOG_MODULES . 'googlebase/library/gb-authentication.php';
            $gbhttp = googlebase::getGbaseHttpRequest();
            gb_revoke_session_token($gb->getOption('token'), $gbhttp);
            $gbhttp->close();
            $gb->setOption('token', null);
            $is_authenticated = false;
        }
    }
}
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php 
echo HTML_PARAMS;
?>
>
<head>
 function updateProducts($productIds, $orderId = null)
 {
     global $db;
     if (!$this->isEnabled()) {
         return;
     }
     if ($orderId !== null) {
         $result = $db->Execute("select products_id from " . TABLE_ORDERS_PRODUCTS . " where orders_id = {$orderId}");
         $productIds = array();
         while (!$result->EOF) {
             $productIds[] = (int) $result->fields['products_id'];
             $result->MoveNext();
         }
     }
     $items = googlebase::getGbaseItemsFromDb($productIds);
     if (empty($items)) {
         return;
     }
     $query = "select products_quantity as quantity, products_id as id\n              from " . TABLE_PRODUCTS . "\n              where products_id in (" . implode(', ', $productIds) . ")";
     $result = $db->Execute($query);
     $gbhttp = googlebase::getGbaseHttpRequest();
     $gbatch = new GoogleBaseBatchRequest();
     while (!$result->EOF) {
         $id = (int) $result->fields['id'];
         if (array_key_exists($id, $items)) {
             $quantity = $items[$id]->getGbaseAttribute('quantity');
             if (is_object($quantity[0])) {
                 $quantity[0]->setValue($result->fields['quantity']);
             }
             $gbatch->addItemForUpdate($items[$id]);
         }
         $result->MoveNext();
     }
     $response = $gbatch->post($this->getOption('token'), $gbhttp);
     googlebase::updateExpirationTimeInDb($response);
     // TODO: handle errors / log somewhere
     #echo "<xmp>"; var_dump($gbatch->getXml()); echo "</xmp>";
     #echo "<xmp>"; var_dump($response->getParsedXmlResponseBody()); echo "</xmp>";
     $gbhttp->close();
 }