getDbConnection(); $Smarty = new CSmarty($DbConnection); $Smarty->assign("product_area", $_SESSION['product_area'] ); include 'lang.php'; mysql_query('SET NAMES utf8'); //Remove Language and Unit Systems preferences, they are strored in server variables $query_string = $_SERVER['QUERY_STRING']; $query_string = preg_replace('/&?(lang|unit_system)=[a-z]+/', '', $query_string); $Smarty->assign('query_string', $query_string); $prefs = $Config->listPreferences(); $Smarty->assign("prefs", $prefs); // Unit system if (isset($_GET['unit_system']) and $_GET['unit_system']) { $unit_system = $_GET['unit_system']; } elseif (isset($_SESSION['unit_system']) and $_SESSION['unit_system']) { $unit_system = $_SESSION['unit_system']; } else { $unit_system = $prefs['default_unit_system']; } // Check if Login is required if ($prefs['login_required'] == 'yes') { $UserLoggedIn = checkAccess($DbConnection, $administratorRequired=FALSE); } // Step 1: Initialize current product main info $ThisProduct = new CProduct($DbConnection, $pid); $Smarty->assign("sellable", $ThisProduct->isProductSellable()); $productVersions = $ThisProduct->getProductVersions(); $singleVersionProduct = (count($productVersions) < 2); if ($singleVersionProduct) { $singleProductVersionId = $productVersions[0]['product_version_id']; $Smarty->assign("single_product_version_id", $singleProductVersionId); } $Smarty->assign("single_version_product", $singleVersionProduct); $Smarty->assign("product_versions", $productVersions); $areaCoverageProduct = FALSE; $versionSelect = array('' => '-Select-'); $productCoverage = array(); foreach ($productVersions as $versionId=>$version) { if ($version['area_coverage']) { $areaCoverageProduct = TRUE; } $productCoverage[$version['product_version_id']] = $version['area_coverage']; $descriptionLength = strlen($version['description']); if ($descriptionLength > 20) { $optionDescription = substr($version['description'], 0 , 20) . '...'; } else { $optionDescription = $version['description']; } $versionSelect[$version['product_version_id']] = $optionDescription; } $Smarty->assign("product_title", $ThisProduct->getTitle($lang)); // $description = str_replace("\n","
\n",$ThisProduct->getDescription($lang)); $description = $ThisProduct->getDescription($lang); $Smarty->assign("product_description", $description); $Smarty->assign("product_id", $ThisProduct->getID()); $Smarty->assign("gift_certificate", $ThisProduct->isGiftCertificate()); $Smarty->assign("areaCoverageProduct", $areaCoverageProduct); $Smarty->assign("versionSelect", $versionSelect); $Smarty->assign("productCoverage", $productCoverage); // // Related Products // $RelatedProducts = $ThisProduct->listRelatedProducts(); $relatedProductTitles = array(); $relatedProductThumbnails = array(); foreach ($RelatedProducts as $Product) { $relatedProductTitles[$Product->getID()] = htmlentities($Product->getTitle()); $PrimaryPicture = $Product->getPrimaryPicture(); if ($PrimaryPicture) { $relatedProductThumbnails[$Product->getID()] = $PrimaryPicture->getPicture($prefs['related_thumb_width_size'],$prefs['related_thumb_height_size'], 0, $wm, $prefs['watermark_transparency']); } else { $relatedProductThumbnails[$Product->getID()] = "pictures/noimage.gif"; } } $Smarty->assign("relatedProductTitles", $relatedProductTitles); $Smarty->assign("relatedProductThumbnails", $relatedProductThumbnails); $Smarty->assign("relatedProductsWidth", $prefs['related_thumb_width_size'] + 30 . "px"); // // Find the Toplevel Category // // TODO - Put the Top Level Category and Bread Crumb stuff in // in a function. It is common with main.php // if (isset($prefs['top_level_category_is_server_name']) and $prefs['top_level_category_is_server_name'] == 'yes') { $Category = new CCategory($DbConnection); $serverName = preg_replace('/www\./i', '', $_SERVER['SERVER_NAME']); $topLevelCatIds = $Category->findCategoriesByTitle($serverName, 0); if (count($topLevelCatIds) == 1) { $topLevelCatId = $topLevelCatIds[0]; } else { trigger_error("Unable to find the parent category for server '$serverName'.", ERROR); $topLevelCatId = 0; } $cat_id = ($cat_id) ? $cat_id : $topLevelCatId; } else if (isset($prefs['top_level_home_categories']) and $prefs['top_level_home_categories'] == 'yes') { $Category = new CCategory($DbConnection); if (isset($_GET['product_area']) and $_GET['product_area'] != '') { $topLevelCategory = $_GET['product_area']; } else if (isset($_SESSION['product_area']) and $_SESSION['product_area'] != '') { $topLevelCategory = $_SESSION['product_area']; } else { $topLevelCategory = ''; } $_SESSION['product_area'] = $topLevelCategory; if ($topLevelCategory == '') { $SubCategories = $Category->listCategories($ordered=TRUE); $topLevelCatId = $SubCategories[0]->getID(); } else { $topLevelCatIds = $Category->findCategoriesByTitle($topLevelCategory, 0); if (count($topLevelCatIds) == 1) { $topLevelCatId = $topLevelCatIds[0]; } else { trigger_error("Unable to find the parent category '$topLevelCategory'.", ERROR); $SubCategories = $Category->listCategories($ordered=TRUE); $topLevelCatId = $SubCategories[0]->getID(); } } $cat_id = ($cat_id) ? $cat_id : $topLevelCatId; } else { $cat_id = isset($cat_id) ? $cat_id : 0; $topLevelCatId = 0; } $Smarty->assign("product_area", $topLevelCategory ); $Smarty->assign("cat_id", $cat_id); // // Current category // $ThisCategory = new CCategory($DbConnection, $cat_id); // // Bread Crumb // $parents = array(); $ThisCategory->getParents($parents); $parentList = array(); for ($i = count($parents)-1; $i >= 0; $i--) { $parentId = $parents[$i]; if ($parentId == 0) { if (!$topLevelCatId) { $parentList = array(); $parentList[0] = ''; } } else if ($parentId == $topLevelCatId) { $parentList = array(); $Parent = new CCategory($DbConnection, $parentId); $parentList[$parentId] = ''; } else { $Parent = new CCategory($DbConnection, $parentId); $parentList[$parentId] = $Parent->getName(); } } if ($cat_id != 0) { $parentList[$cat_id] = ($cat_id != $topLevelCatId) ? $ThisCategory->getName() : ''; } $Smarty->assign("parentList", $parentList); $logged_in = false; if ($prefs['allow_reg_login'] == "yes" && $user != "") { $List = new CUserList($DbConnection); $User = $List->getUser($user); if (isset($User)) { if ($User->authenticate($user, $passwd, $error_msg)) { $logged_in = true; } else { $logged_in = false; } } } $Smarty->assign("logged_in", $logged_in); $cur_location = $PHP_SELF ."?". $QUERY_STRING; $Smarty->assign("cur_location", urlencode($cur_location)); // Step 2: Initialize current product extended info // Get all the optional fields for the product array($field_val['field_name'], $field_val['field_text'], $field_val['field_type'], $field_val['field_id'], $field_val['user_editable'], $field_val['edit_rows'], $field_val['comment']); $optional_fields = array(); $field_list = $ThisProduct->ListAttributes(false, false, false, $lang); $Units = new CUnits($DbConnection); foreach ($field_list as $field) { $attr = $ThisProduct->getAttribute($field[0], TRUE, $lang); $displayAs = ''; // Units if ($field[2] == "units") { $showField = TRUE; if ($attr['value']) { list($value, $unitName, $displayAs) = $Units->convertValue($attr['value'], $unit_system, $attr['unit_id']); } else { $options = array(); } } else if ($field[2] == "select") { if ($prefs["per_product_options_enabled"] == "yes") { $options = $ThisProduct->listOptions($field[3],1); $showField = (count($options) > 0); } else { $options = array(); $showField = FALSE; } } else { $options = array(); $showField = TRUE; } if ($attr['enabled'] and $showField) { array_push($field, $attr['value']); array_push($field, $displayAs); $optional_fields[] = $field; } if ($options) { for ($i=0; $ifieldHasSwatch($field[3]); } } } $Smarty->assign("product_field_options_values", $product_field_options_values); $Smarty->assign("product_field_options_text", $product_field_options_text); $Smarty->assign("product_field_options_swatch", $product_field_options_swatch); $Smarty->assign("product_field_has_swatch", $product_field_has_swatch); if ($prefs['allow_prices'] == "yes") { $Price = new CPrice($DbConnection, $ThisProduct->getID()); $unformatted = FALSE; $noLineBreaks = ($singleVersionProduct) ? TRUE : FALSE; if ($prefs['require_login'] == "yes" && !$logged_in) { $priceRange = NULL; $prices = NULL; } else { $defaultPriceCategory = isset($prefs['default_price_cat']) ? $prefs['default_price_cat'] : NULL; $userPriceCategory = ($logged_in and $User->getAttribute("price_cat_id")) ? $User->getAttribute("price_cat_id") : $defaultPriceCategory; $userDiscount = ($logged_in) ? $User->getAttribute("discount") : 0.0; $displayLowestPrice = ($prefs['display_lowest_price'] == "yes") ? TRUE : FALSE; $priceRange = $Price->getPriceRange($defaultPriceCategory, $userPriceCategory, $userDiscount, $displayLowestPrice, $onSale); $prices = $Price->getVersionPrices($defaultPriceCategory, $userPriceCategory, $userDiscount, $displayLowestPrice, $unformatted, $noLineBreaks, $addSale=TRUE); } } $Smarty->assign("priceRange", $priceRange); $Smarty->assign("prices", $prices); $Smarty->assign("onSale", $onSale); $prefs['watermark_images'] == "yes" ? $wm = true : $wm = false; // Get primary picture for the product $ThisPicture = $ThisProduct->getPrimaryPicture(); if ($ThisPicture) { $primary_picture = $ThisPicture->getPicture($prefs['product_width_size'],0, 0,$wm, $prefs['watermark_transparency']); $primary_picture_popup = $ThisPicture->getPicture($prefs['picture_popup_width'],$prefs['picture_popup_height'],0,$wm, $prefs['watermark_transparency']); $primary_pic_description = htmlentities($ThisPicture->getAttribute("description")); $primary_pic_description = preg_replace("/\r\n/", '
', $primary_pic_description); $primary_pic_id = $ThisPicture->getID(); } else { $primary_picture = "pictures/noimage.gif"; } // Get the rest of the pictures $AllPictures = $ThisProduct->listPictures(); $thumbnails = array(); $thumbnails_popups = array(); $primaryPic = TRUE; foreach ($AllPictures as $ThisPicture) { if ($primaryPic) { $primaryPic = FALSE; } else { $thumbnails[] = $ThisPicture->getPicture($prefs['filmstrip_width_size'],$prefs['filmstrip_height_size'], 0, $wm, $prefs['watermark_transparency']); $thumbnails_popups[] = $ThisPicture->getPicture($prefs['picture_popup_width'],$prefs['picture_popup_height'],0,$wm, $prefs['watermark_transparency']); } $pictures[] = $ThisPicture->getPicture($prefs['product_width_size'],0, 0, $wm, $prefs['watermark_transparency']); $description = htmlentities($ThisPicture->getAttribute("description")); $description = preg_replace("/\r\n/", '
', $description); $pic_descriptions[] = $description; $pic_id[] = $ThisPicture->getID(); } $Smarty->assign("field_list", $field_list); $Smarty->assign("optional_fields", $optional_fields); $Smarty->assign("thumbnails", $thumbnails); $Smarty->assign("thumbnails_popups", $thumbnails_popups); $Smarty->assign("pictures", $pictures); $Smarty->assign("pic_id", $pic_id); $Smarty->assign("pic_descriptions", $pic_descriptions); $Smarty->assign("primary_pic_description", $primary_pic_description); $Smarty->assign("primary_picture", $primary_picture); $Smarty->assign("primary_picture_popup", $primary_picture_popup); $Smarty->assign("primary_picture_id", $primary_pic_id); $Smarty->assign("num_pictures", count($pictures)); $AttachmentList = new CAttachmentList($DbConnection); $Attachments = $AttachmentList->getList($ThisProduct->getID()); if (count($Attachments) > 0) { foreach ($Attachments as $Attachment) { if ($prefs['enable_french']) { $filename = $Attachment->getAttribute("filename"); if ($lang == 'en') { if (preg_match('/english/i', $filename)) { $attachment_name[] = $Attachment->getLink('View the complete brochure.'); } } else if ($lang == 'fr') { if (preg_match('/french|francais/i', $filename)) { $attachment_name[] = $Attachment->getLink('Voir la brochure complète.'); } } } else { $attachment_name[] = $Attachment->getLink(); } } } $Smarty->assign("attachment_name", $attachment_name); //Find the product before and after this one $PrevProduct = $ThisCategory->getOffsetProduct($ThisProduct->getID(), -1); $NextProduct = $ThisCategory->getOffsetProduct($ThisProduct->getID(), 1); if ($PrevProduct) $Smarty->assign("prev_id",$PrevProduct->getID()); else $Smarty->assign("prev_id",0); if ($NextProduct) $Smarty->assign("next_id",$NextProduct->getID()); else $Smarty->assign("next_id",0); $Smarty->assign("view", $view); if ($prefs['builder_title'] != "") { $Smarty->assign("builder_title", $prefs['builder_title']); } else { $title = $Config->getValue("builder_title"); $Smarty->assign("builder_title", $title); } // Step 2: Render page $Smarty->display("product.tpl"); ?>