/**
 * @package admin
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: product.php 4279 2006-08-26 03:31:29Z drbyte $
 */
require 'includes/application_top.php';
require DIR_WS_MODULES . 'prod_cat_header_code.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
if (zen_not_null($action)) {
    ///////////////////// BEGIN GOOGLEBASE /////////////////////////////
    require_once DIR_FS_CATALOG_MODULES . 'googlebase/googlebase.php';
    if ($action == 'delete_product_confirm') {
        $gb = new googlebase();
        #echo $action.'<br>'.zen_db_insert_id(); die;
        if (zen_not_null($_POST['products_id'])) {
            $gb->handleProductModification($action, $_POST['products_id']);
        }
    }
    ///////////////////// END GOOGLEBASE /////////////////////////////
    switch ($action) {
        case 'setflag':
            if ($_GET['flag'] == '0' || $_GET['flag'] == '1') {
                if (isset($_GET['pID'])) {
                    zen_set_product_status($_GET['pID'], $_GET['flag']);
                }
            }
            zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $_GET['cPath'] . '&pID=' . $_GET['pID'] . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
            break;
 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();
 }
<?php

/**
 * @package admin
 * @version $Id: googlebase.php 0 Sep 5, 2007 3:38:26 PM pablif@gmail.com $
 */
require 'includes/application_top.php';
if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
}
require_once DIR_FS_CATALOG_MODULES . 'googlebase/library/gb-http.php';
require_once DIR_FS_CATALOG_MODULES . 'googlebase/googlebase.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
$token = isset($_GET['token']) ? $_GET['token'] : '';
$gb = new googlebase();
$is_authenticated = $gb->getOption('token') != null;
//TODO: && is_valid_token
if (!$is_authenticated && zen_not_null($action) && $action == 'auth' || zen_not_null($token)) {
    require_once DIR_FS_CATALOG_MODULES . 'googlebase/library/gb-authentication.php';
    if (zen_not_null($token)) {
        $gbhttp = googlebase::getGbaseHttpRequest();
        $response = gb_get_session_token($token, $gbhttp);
        if (!$response->hasErrors()) {
            $gb->setOption('token', $response->getParsedToken());
            $is_authenticated = true;
        } else {
            global $messageStack;
            $msg = "Authentication failed with error: <code>" . $response->getConnectionError() . '<br>' . strip_tags($response->getResponseBody) . '</code>';
            $messageStack->add_session($msg, 'error');
        }
        $gbhttp->close();
        $k = max($oiheight / $small_height, $oiwidth / $small_width);
        //use smallest size
        $small_width = round($oiwidth / $k);
        $small_height = round($oiheight / $k);
        $k = max($oiheight / $medium_height, $oiwidth / $medium_width);
        //use smallest size
        $medium_width = round($oiwidth / $k);
        $medium_height = round($oiheight / $k);
        $large_width = $oiwidth;
        $large_height = $oiheight;
        $products_image = zen_get_products_image((int) $products_id);
        $products_image_extension = substr($products_image, strrpos($products_image, '.'));
        $products_image_base = ereg_replace($products_image_extension, '', $products_image);
        $filename_medium = DIR_FS_CATALOG . DIR_WS_IMAGES . 'medium/' . $products_image_base . IMAGE_SUFFIX_MEDIUM . '.' . $fname[2];
        $filename_large = DIR_FS_CATALOG . DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . '.' . $fname[2];
        // ImageMagick
        if (IMAGE_MANAGER_HANDLER == '1') {
            copy($src, $filename_large);
            copy($src, $filename_medium);
            exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $large_width . " " . $filename_large);
            exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $medium_width . " " . $filename_medium);
            exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $small_width . " " . $filename_small);
        }
    }
    ////////////////// BEGIN GOOGLEBASE /////////////////////////
    require_once DIR_FS_CATALOG_MODULES . 'googlebase/googlebase.php';
    $gb = new googlebase();
    $gb->handleProductModification($action, $products_id);
    ////////////////// END GOOGLEBASE /////////////////////////
    zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
}