/** * Sets up the Shop Navbar content and returns it as a string * * Note that {@see init()} must have been called before. * The content is created once and stored statically. * Repeated calls will always return the same string, unless either * a non-empty template is given, or $use_cache is set to false. * @global array $_ARRAYLANG * @global array $themesPages * @global array $_CONFIGURATION * @staticvar string $strContent Caches created content * @param type $template Replaces the default template * ($themesPages['shopnavbar']) and sets * $use_cache to false unless empty. * Defaults to NULL * @param type $use_cache Does not use any cached content, but builds * it new from scratch if false. * Defaults to true. * @return string The Shop Navbar content * @static */ static function getNavbar($template = NULL, $use_cache = true) { global $_ARRAYLANG, $themesPages; static $strContent = NULL; if (!$use_cache) { $strContent = NULL; } // Note: This is valid only as long as the content is the same every // time this method is called! if ($strContent) { return $strContent; } $objTpl = new \Cx\Core\Html\Sigma('.'); $objTpl->setErrorHandling(PEAR_ERROR_DIE); $objTpl->setTemplate(empty($template) ? $themesPages['shopnavbar'] : $template); $objTpl->setGlobalVariable($_ARRAYLANG); $loginInfo = $loginStatus = $redirect = ''; //\DBG::log("Shop::getNavbar(): Customer: ".(self::$objCustomer ? "Logged in" : "nada")); if (self::$objCustomer) { if (self::$objCustomer->company()) { $loginInfo = self::$objCustomer->company() . '<br />'; } else { $loginInfo = $_ARRAYLANG['TXT_SHOP_' . strtoupper(self::$objCustomer->gender())] . ' ' . self::$objCustomer->lastname() . '<br />'; } $loginStatus = $_ARRAYLANG['TXT_LOGGED_IN_AS']; // Show link to change the password if ($objTpl->blockExists('shop_changepass')) { $objTpl->touchBlock('shop_changepass'); } } else { // Show login form if the customer is not logged in already. $loginStatus = $_ARRAYLANG['TXT_LOGGED_IN_AS_SHOP_GUEST']; // $redirect contains something like "section=Shop&cmd=details&productId=1" if (isset($_REQUEST['redirect'])) { $redirect = $_REQUEST['redirect']; } else { $queryString = $_SERVER['QUERY_STRING']; $redirect = base64_encode(preg_replace('/\\&?act\\=\\w*/', '', $queryString)); } $objTpl->setVariable('SHOP_LOGIN_ACTION', \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'login') . '?redirect=' . $redirect); } $objTpl->setVariable(array('SHOP_LOGIN_STATUS' => $loginStatus, 'SHOP_LOGIN_INFO' => $loginInfo)); // Currencies if (self::$show_currency_navbar && $objTpl->blockExists('shopCurrencies')) { $curNavbar = Currency::getCurrencyNavbar(); if (!empty($curNavbar)) { $objTpl->setVariable('SHOP_CURRENCIES', $curNavbar); } } if ($objTpl->blockExists('shopNavbar')) { $selectedCatId = 0; if (isset($_REQUEST['catId'])) { $selectedCatId = intval($_REQUEST['catId']); $objCategory = ShopCategory::getById($selectedCatId); if (!$objCategory) { $selectedCatId = 0; } } if (empty($selectedCatId) && isset($_REQUEST['productId'])) { $product_id = intval($_REQUEST['productId']); if (isset($_REQUEST['referer']) && $_REQUEST['referer'] == 'cart') { $product_id = Cart::get_product_id($product_id); } $objProduct = Product::getById($product_id); if ($objProduct) { $selectedCatId = $objProduct->category_id(); $selectedCatId = preg_replace('/,.+$/', '', $selectedCatId); } } // If there is no distinct Category ID, use the previous one, if any if (is_numeric($selectedCatId)) { $_SESSION['shop']['previous_category_id'] = $selectedCatId; } else { if (isset($_SESSION['shop']['previous_category_id'])) { $selectedCatId = $_SESSION['shop']['previous_category_id']; } } // Only the visible ShopCategories are present $arrShopCategoryTree = ShopCategories::getTreeArray(false, true, true, $selectedCatId, 0, 0); // The trail of IDs from root to the selected ShopCategory, // built along with the tree array when calling getTreeArray(). $arrTrail = ShopCategories::getTrailArray($selectedCatId); // Display the ShopCategories foreach ($arrShopCategoryTree as $arrShopCategory) { $level = $arrShopCategory['level']; // Skip levels too deep: if ($level >= 2) { continue; } $id = $arrShopCategory['id']; $style = 'shopnavbar' . ($level + 1); if (in_array($id, $arrTrail)) { $style .= '_active'; } $objTpl->setVariable(array('SHOP_CATEGORY_STYLE' => $style, 'SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => str_repeat(' ', 3 * $level) . str_replace('"', '"', $arrShopCategory['name']))); $objTpl->parse("shopNavbar"); } } // Only show the cart info when the JS cart is not active! if (!self::$use_js_cart) { $objTpl->setVariable(array('SHOP_CART_INFO' => self::cart_info())); } // if ($objTpl->blockExists('shopJsCart')) { // $objTpl->touchBlock('shopJsCart'); // } $strContent = $objTpl->get(); return $strContent; }
/** * Edit a pricelist * @global ADOConnection $objDatabase * @global array $_ARRAYLANG * @return boolean True on success, false otherwise */ static function view_pricelist_edit() { global $_ARRAYLANG; $list_id = null; $objList = PriceList::getFromPost(); if ($objList) { $result = $objList->store(); if ($result) { if (isset($_REQUEST['list_id'])) { unset($_REQUEST['list_id']); } //die("Showing lists"); return self::view_pricelists(); } } $list_id = isset($_GET['list_id']) ? $_GET['list_id'] : null; $objList = PriceList::getById($list_id); if (!$objList) { $objList = new PriceList(null); } $list_id = $objList->id(); self::$objTemplate->loadTemplateFile("module_shop_pricelist_details.html"); self::$objTemplate->setGlobalVariable($_ARRAYLANG); self::$objTemplate->setVariable(array('SHOP_PRICELIST_EDIT' => $_ARRAYLANG[$list_id ? 'TXT_SHOP_PRICELIST_EDIT' : 'TXT_SHOP_PRICELIST_ADD'], 'SHOP_PRICELIST_ID' => $list_id, 'SHOP_PRICELIST_LINK_PDF' => $list_id ? PriceList::getUrl($list_id) : '', 'SHOP_PRICELIST_NAME' => $objList->name(), 'SHOP_PRICELIST_LANGUAGE_MENUOPTIONS' => \Html::getOptions(\FWLanguage::getNameArray(), $objList->lang_id()), 'SHOP_PRICELIST_BORDER_CHECKED' => $objList->border() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_PRICELIST_HEADER_CHECKED' => $objList->header() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_PRICELIST_HEADER_LEFT' => $objList->header_left(), 'SHOP_PRICELIST_HEADER_RIGHT' => $objList->header_right(), 'SHOP_PRICELIST_FOOTER_CHECKED' => $objList->footer() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_PRICELIST_FOOTER_LEFT' => $objList->footer_left(), 'SHOP_PRICELIST_FOOTER_RIGHT' => $objList->footer_right())); $category_ids = $objList->category_ids(); $category_all = false; if (empty($category_ids) || $category_ids == '*') { $category_all = true; self::$objTemplate->setVariable('SHOP_PRICELIST_CATEGORY_ALL_CHECKED', \Html::ATTRIBUTE_CHECKED); } // Get all categories $arrCategories = ShopCategories::getTreeArray(true, false); if (empty($arrCategories)) { Message::warning($_ARRAYLANG['TXT_SHOP_WARNING_NO_CATEGORIES']); } $i = 0; foreach ($arrCategories as $objCategory) { $category_id = $objCategory['id']; $selected = $category_all || preg_match('/(?:^|,)\\s*' . $category_id . '\\s*(?:,|$)/', $category_ids); //DBG::log("Category ID $category_id, ".($selected ? "selected" : "NOT")); self::$objTemplate->setVariable(array('SHOP_CATEGORY_ID' => contrexx_raw2xhtml($category_id), 'SHOP_CATEGORY_NAME' => contrexx_raw2xhtml($objCategory['name']), 'SHOP_CATEGORY_LEVELSPACE' => str_repeat('|----', $objCategory['level']), 'SHOP_CATEGORY_DISABLED' => $category_all ? \Html::ATTRIBUTE_DISABLED : '', 'SHOP_CATEGORY_CHECKED' => $selected ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_CATEGORY_ROWCLASS' => 'row' . (++$i % 2 + 1))); self::$objTemplate->parse('shop_category'); } return true; }
/** * Parse the category/product breadcrumb * * Parses the template block shopNavbar and shop_breadcrumb based on * the currently selected category and product. * * @param \Cx\Core\Html\Sigma $objTpl The template object to be used to parse the breadcrumb on. * @param integer $selectedCatId The ID of the currently selected category. * @param Product $product The currently selected product. */ static function parseBreadcrumb($objTpl, $selectedCatId = 0, $product = null) { // Only the visible ShopCategories are present $arrShopCategoryTree = ShopCategories::getTreeArray(false, true, true, $selectedCatId, 0, 0); // The trail of IDs from root to the selected ShopCategory, // built along with the tree array when calling getTreeArray(). $arrTrail = ShopCategories::getTrailArray($selectedCatId); // Display the ShopCategories foreach ($arrShopCategoryTree as $arrShopCategory) { $level = $arrShopCategory['level']; // Skip levels too deep: if ($level >= 2) { continue; } $id = $arrShopCategory['id']; $style = 'shopnavbar' . ($level + 1); if (in_array($id, $arrTrail)) { $style .= '_active'; } // parse shopNavbar if ($objTpl->blockExists('shopNavbar')) { $objTpl->setVariable(array('SHOP_CATEGORY_STYLE' => $style, 'SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => str_repeat(' ', 3 * $level) . str_replace('"', '"', $arrShopCategory['name']))); $objTpl->parse("shopNavbar"); } // skip shop_breadcrumb parsing in case the required template blocks are missing if (!$objTpl->blockExists('shop_breadcrumb') || !$objTpl->blockExists('shop_breadcrumb_part')) { continue; } // skip shop_breadcrumb parsing in case the category is not part of the selected category tree if (!in_array($id, $arrTrail)) { continue; } // parse the category in shop_breadcrumb $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('catId' => $id))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($arrShopCategory['name']))); $objTpl->parse('shop_breadcrumb_part'); } // skip shop_breadcrumb parsing in case the required template blocks are missing if (!$objTpl->blockExists('shop_breadcrumb') && !$objTpl->blockExists('shop_breadcrumb_part')) { return; } // parse Product in shop_breadcrumb if a product is being viewed if ($product) { $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('productId' => $product->id()))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($product->name()))); $objTpl->parse('shop_breadcrumb_part'); } // show or hide the shop_breadcrumb template block, depending on if a category // has been selected or a product is being viewed if (array_intersect(array_keys($arrShopCategoryTree), $arrTrail) || $product) { $objTpl->touchBlock('shop_breadcrumb'); } else { $objTpl->hideBlock('shop_breadcrumb'); } }
/** * Produces the Categories overview * @return boolean True on success, false otherwise */ function view_categories() { global $_ARRAYLANG; if (isset($_REQUEST['tpl'])) { if ($_REQUEST['tpl'] == 'pricelists' || $_REQUEST['tpl'] == 'pricelist_edit') { return self::view_pricelists(); } } $this->delete_categories(); $this->store_category(); $this->update_categories(); $this->toggle_category(); $i = 1; self::$pageTitle = $_ARRAYLANG['TXT_CATEGORIES']; self::$objTemplate->loadTemplateFile('module_shop_categories.html'); self::$objTemplate->setGlobalVariable($_ARRAYLANG); // ID of the category to be edited, if any $category_id = isset($_REQUEST['category_id']) ? intval($_REQUEST['category_id']) : 0; // Get the tree array of all ShopCategories $arrShopCategories = ShopCategories::getTreeArray(true, false, false); // Default to the list tab $flagEditTabActive = false; $parent_id = 0; $name = ''; $desc = ''; $active = true; $virtual = false; $pictureFilename = NULL; $picturePath = $thumbPath = self::$defaultImage; if ($category_id) { // Edit the selected category: Flip view to the edit tab $flagEditTabActive = true; $objCategory = ShopCategory::getById($category_id); if ($objCategory) { $parent_id = $objCategory->parent_id(); $name = contrexx_raw2xhtml($objCategory->name()); $desc = $objCategory->description(); $active = $objCategory->active(); $virtual = $objCategory->virtual(); $pictureFilename = $objCategory->picture(); if ($pictureFilename != '') { $picturePath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $pictureFilename; $thumbPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . \ImageManager::getThumbnailFilename($pictureFilename); } } } $max_width = intval(\Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_width', 'Shop')); $max_height = intval(\Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_height', 'Shop')); if (empty($max_width)) { $max_width = 100000.0; } if (empty($max_height)) { $max_height = 100000.0; } $count = ShopCategories::getTreeNodeCount(); self::$objTemplate->setVariable(array('TXT_SHOP_CATEGORY_ADD_OR_EDIT' => $category_id ? $_ARRAYLANG['TXT_SHOP_CATEGORY_EDIT'] : $_ARRAYLANG['TXT_SHOP_CATEGORY_NEW'], 'TXT_ADD_NEW_SHOP_GROUP' => $category_id ? $_ARRAYLANG['TXT_EDIT_PRODUCT_GROUP'] : $_ARRAYLANG['TXT_ADD_NEW_PRODUCT_GROUP'], 'SHOP_CATEGORY_ID' => $category_id, 'SHOP_CATEGORY_NAME' => $name, 'SHOP_CATEGORY_MENUOPTIONS' => ShopCategories::getMenuoptions($parent_id, false), 'SHOP_THUMB_IMG_HREF' => $thumbPath, 'SHOP_CATEGORY_IMAGE_FILENAME' => $pictureFilename == '' ? $_ARRAYLANG['TXT_SHOP_IMAGE_UNDEFINED'] : $pictureFilename, 'SHOP_PICTURE_REMOVE_DISPLAY' => $pictureFilename == '' ? \Html::CSS_DISPLAY_NONE : \Html::CSS_DISPLAY_INLINE, 'SHOP_CATEGORY_VIRTUAL_CHECKED' => $virtual ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_CATEGORY_ACTIVE_CHECKED' => $active ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_CATEGORY_DESCRIPTION' => $desc, 'SHOP_CATEGORY_EDIT_ACTIVE' => $flagEditTabActive ? 'active' : '', 'SHOP_CATEGORY_EDIT_DISPLAY' => $flagEditTabActive ? 'block' : 'none', 'SHOP_CATEGORY_LIST_ACTIVE' => $flagEditTabActive ? '' : 'active', 'SHOP_CATEGORY_LIST_DISPLAY' => $flagEditTabActive ? 'none' : 'block', 'SHOP_IMAGE_WIDTH' => $max_width, 'SHOP_IMAGE_HEIGHT' => $max_height, 'SHOP_TOTAL_CATEGORIES' => $count)); if ($pictureFilename) { self::$objTemplate->setVariable(array('SHOP_PICTURE_IMG_HREF' => $picturePath)); } // mediabrowser $mediaBrowserOptions = array('type' => 'button', 'data-cx-mb-startmediatype' => 'shop', 'data-cx-mb-views' => 'filebrowser', 'id' => 'media_browser_shop', 'style' => 'display:none'); self::$objTemplate->setGlobalVariable(array('MEDIABROWSER_BUTTON' => self::getMediaBrowserButton($mediaBrowserOptions, 'setSelectedImage'))); self::$objTemplate->parse('category_edit'); // TODO: Add controls to fold parent categories // $level_prev = null; $arrLanguages = \FWLanguage::getActiveFrontendLanguages(); // Intended to show an edit link for all active frontend languages. // However, the design doesn't like it. Limit to the current one. $arrLanguages = array(FRONTEND_LANG_ID => $arrLanguages[FRONTEND_LANG_ID]); foreach ($arrShopCategories as $arrShopCategory) { $category_id = $arrShopCategory['id']; $level = $arrShopCategory['level']; self::$objTemplate->setGlobalVariable(array('SHOP_ROWCLASS' => 'row' . (++$i % 2 + 1), 'SHOP_CATEGORY_ID' => $category_id, 'SHOP_CATEGORY_NAME' => htmlentities($arrShopCategory['name'], ENT_QUOTES, CONTREXX_CHARSET), 'SHOP_CATEGORY_ORD' => $arrShopCategory['ord'], 'SHOP_CATEGORY_LEVELSPACE' => str_repeat('|----', $level), 'SHOP_CATEGORY_ACTIVE' => $arrShopCategory['active'] ? $_ARRAYLANG['TXT_ACTIVE'] : $_ARRAYLANG['TXT_INACTIVE'], 'SHOP_CATEGORY_ACTIVE_VALUE' => intval($arrShopCategory['active']), 'SHOP_CATEGORY_ACTIVE_CHECKED' => $arrShopCategory['active'] ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_CATEGORY_ACTIVE_PICTURE' => $arrShopCategory['active'] ? 'status_green.gif' : 'status_red.gif', 'SHOP_CATEGORY_VIRTUAL_CHECKED' => $arrShopCategory['virtual'] ? \Html::ATTRIBUTE_CHECKED : '')); // All languages active foreach ($arrLanguages as $lang_id => $arrLanguage) { self::$objTemplate->setVariable(array('SHOP_CATEGORY_LANGUAGE_ID' => $lang_id, 'SHOP_CATEGORY_LANGUAGE_EDIT' => sprintf($_ARRAYLANG['TXT_SHOP_CATEGORY_LANGUAGE_EDIT'], $lang_id, $arrLanguage['lang'], $arrLanguage['name']))); self::$objTemplate->parse('category_language'); } // TODO: Implement a folded hierarchy view // self::$objTemplate->touchBlock('category_row'); // if ($level !== $level_prev) { // self::$objTemplate->touchBlock('folder'); // } // $level_prev = $level; self::$objTemplate->parse('category_row'); } return true; }