<?php

$defaultView = true;

if (ZEN_MAGICTHUMB_STATUS == 'true') {

    require_once(DIR_FS_CATALOG . DIR_WS_MODULES . 'magictoolbox/magictoolbox_addons.php');
    /* load module */
    $mod = & magictoolboxLoadModule('MagicThumb');

    if(!$mod->params->checkValue('use-effect-on-whats-new-block', 'No')) {
        if (!$GLOBALS["MAGICTHUMB_HEADERS_LOADED"]) {
            echo $mod->headers(DIR_WS_CATALOG . DIR_WS_TEMPLATE . 'jscript', DIR_WS_CATALOG . DIR_WS_TEMPLATE . 'css');
        }
        $defaultView = false;

        $content = "";
        $whats_new_box_counter = 0;
        while (!$random_whats_new_sidebox_product->EOF) {
            $whats_new_box_counter++;
     //           print_r($random_whats_new_sidebox_product); die();
      /*          $query = "select p.* from (" . TABLE_PRODUCTS . " p
                               left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id )
                               where p.products_id = pd.products_id
                               and p.products_status = 1 and p.products_id = " . intval($random_whats_new_sidebox_product->fields['products_id']);

    //  $random_whats_new_sidebox_product = zen_random_select($random_whats_new_sidebox_product_query);
               // $product = $db->Execute($query);
    //print_r($product); die();
    */
            $products_image = $random_whats_new_sidebox_product->fields['products_image'];
            $products_image_extension = substr($products_image, strrpos($products_image, '.'));
            $products_image_base = str_replace($products_image_extension, '', $products_image);
            //$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;
            $products_image_large = $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extension;

            $whats_new_price = zen_get_products_display_price($random_whats_new_sidebox_product->fields['products_id']);

            if(file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . str_replace(DIR_WS_IMAGES, '', $products_image_large))) {
                $image = str_replace(DIR_WS_IMAGES, '', $products_image_large);
            } else {
                $image = str_replace(DIR_WS_IMAGES, '', $products_image);
            }



            if(isset($image) && !empty($image) && file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $image) && !$mod->params->checkValue("use-effect-on-product-page", "No")) {
                $img = DIR_WS_CATALOG . DIR_WS_IMAGES . $image;
                $thumb = DIR_WS_CATALOG . magictoolboxGetThumb($image, $mod->params->getValue('thumb-size-whats-new-block'), $mod->params->getValue('thumb-size-depends-on'), $mod->params->getValue('image-magick-path'));

                $id = 'whatsNew' . $random_whats_new_sidebox_product->fields['products_id'];
                $title = $random_whats_new_sidebox_product->fields['products_name'];
                $link = '';

               

                $sm = $mod->params->getValue('show-message');
                $mod->params->set('show-message', 'No');

                $content .= '<div class="sideBoxContent centeredContent">';
                $content .= $mod->template(compact("img","thumb","id","title","link"));
                $content .= '<br />' . $random_whats_new_sidebox_product->fields['products_name'] . '</a>';
                $content .= '<div>' . $whats_new_price . '</div>';
                $content .= '</div>';

                $mod->params->set('show-message', $sm);
            } else { // default
                $content .= '<div class="sideBoxContent centeredContent">';
                $content .= '<a href="' . zen_href_link(zen_get_info_page($random_whats_new_sidebox_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_whats_new_sidebox_product->fields['master_categories_id']) . '&products_id=' . $random_whats_new_sidebox_product->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $random_whats_new_sidebox_product->fields['products_image'], $random_whats_new_sidebox_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
                $content .= '<br />' . $random_whats_new_sidebox_product->fields['products_name'] . '</a>';
                $content .= '<div>' . $whats_new_price . '</div>';
                $content .= '</div>';
            }
            $random_whats_new_sidebox_product->MoveNextRandom();
        }
    }
}
if($defaultView) {
  // default
  $content = "";
  $whats_new_box_counter = 0;
  while (!$random_whats_new_sidebox_product->EOF) {
    $whats_new_box_counter++;
    $whats_new_price = zen_get_products_display_price($random_whats_new_sidebox_product->fields['products_id']);
    $content .= '<div class="sideBoxContent centeredContent">';
    $content .= '<a href="' . zen_href_link(zen_get_info_page($random_whats_new_sidebox_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_whats_new_sidebox_product->fields['master_categories_id']) . '&products_id=' . $random_whats_new_sidebox_product->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $random_whats_new_sidebox_product->fields['products_image'], $random_whats_new_sidebox_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
    $content .= '<br />' . $random_whats_new_sidebox_product->fields['products_name'] . '</a>';
    $content .= '<div>' . $whats_new_price . '</div>';
    $content .= '</div>';
    $random_whats_new_sidebox_product->MoveNextRandom();
  }
}

?>
