예제 #1
0
 /**
  * Creates a PDF document and sends this pricelist to the client
  *
  * Unfortunately, ezpdf does not return anything after printing the
  * document, so there's no way to tell whether it has succeeded.
  * Thus, you should not rely on the return value, except when it is
  * false -- in that case, loading of some data failed.
  * @return  boolean           False on failure, true on supposed success
  */
 function send_as_pdf()
 {
     global $objInit, $_ARRAYLANG;
     if (!$this->load()) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_PRICELIST_ERROR_LOADING']);
     }
     $objPdf = new \Cezpdf('A4');
     $objPdf->setEncryption('', '', array('print'));
     $objPdf->selectFont(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseLibraryPath() . '/ezpdf/fonts/' . $this->font);
     $objPdf->ezSetMargins(0, 0, 0, 0);
     // Reset margins
     $objPdf->setLineStyle(0.5);
     $marginTop = 30;
     $biggerCountTop = $biggerCountBottom = 0;
     $arrHeaderLeft = $arrHeaderRight = $arrFooterLeft = $arrFooterRight = array();
     if ($this->header) {
         // header should be shown
         $arrHeaderLeft = explode("\n", $this->header_left);
         $arrHeaderRight = explode("\n", $this->header_right);
         $countLeft = count($arrHeaderLeft);
         $countRight = count($arrHeaderRight);
         $biggerCountTop = $countLeft > $countRight ? $countLeft : $countRight;
         $marginTop = $biggerCountTop * 14 + 36;
     }
     // Bottom margin
     $marginBottom = 20;
     $arrFooterRight = array();
     if ($this->footer) {
         // footer should be shown
         // Old, obsolete:
         $this->footer_left = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left);
         $this->footer_right = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right);
         // New:
         $this->footer_left = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left);
         $this->footer_right = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right);
         $arrFooterLeft = explode("\n", $this->footer_left);
         $arrFooterRight = explode("\n", $this->footer_right);
         $countLeft = count($arrFooterLeft);
         $countRight = count($arrFooterRight);
         $biggerCountBottom = $countLeft > $countRight ? $countLeft : $countRight;
         $marginBottom = $biggerCountBottom * 20 + 20;
     }
     // Borders
     if ($this->border) {
         $linesForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         $objPdf->setStrokeColor(0, 0, 0, 1);
         $objPdf->rectangle(10, 10, 575.28, 821.89);
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($linesForAllPages, 'all');
     }
     // Header
     $headerArray = array();
     $startpointY = 0;
     if ($this->header) {
         $objPdf->ezSetY(830);
         $headerForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         for ($i = 0; $i < $biggerCountTop; ++$i) {
             $headerArray[$i] = array('left' => isset($arrHeaderLeft[$i]) ? $arrHeaderLeft[$i] : '', 'right' => isset($arrHeaderRight[$i]) ? $arrHeaderRight[$i] : '');
         }
         $tempY = $objPdf->ezTable($headerArray, '', '', array('showHeadings' => 0, 'fontSize' => $this->font_size_header, 'shaded' => 0, 'width' => 540, 'showLines' => 0, 'xPos' => 'center', 'xOrientation' => 'center', 'cols' => array('right' => array('justification' => 'right'))));
         $tempY -= 5;
         if ($this->border) {
             $objPdf->setStrokeColor(0, 0, 0);
             $objPdf->line(10, $tempY, 585.28, $tempY);
         }
         $startpointY = $tempY - 5;
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($headerForAllPages, 'all');
     }
     // Footer
     $pageNumbersX = $pageNumbersY = $pageNumbersFont = 0;
     if ($this->footer) {
         $footerForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         $tempY = $marginBottom - 5;
         if ($this->border) {
             $objPdf->setStrokeColor(0, 0, 0);
             $objPdf->line(10, $tempY, 585.28, $tempY);
         }
         // length of the longest word
         $longestWord = 0;
         foreach ($arrFooterRight as $line) {
             if ($longestWord < strlen($line)) {
                 $longestWord = strlen($line);
             }
         }
         for ($i = $biggerCountBottom - 1; $i >= 0; --$i) {
             if (empty($arrFooterLeft[$i])) {
                 $arrFooterLeft[$i] = '';
             }
             if (empty($arrFooterRight[$i])) {
                 $arrFooterRight[$i] = '';
             }
             if ($arrFooterLeft[$i] == '<--PAGENUMBER-->' || $arrFooterLeft[$i] == '[PAGENUMBER]') {
                 $pageNumbersX = 65;
                 $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer;
                 $pageNumbersFont = $this->font_size_list;
             } else {
                 $objPdf->addText(25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterLeft[$i]);
             }
             if ($arrFooterRight[$i] == '<--PAGENUMBER-->' || $arrFooterRight[$i] == '[PAGENUMBER]') {
                 $pageNumbersX = 595.28 - 25;
                 $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer;
                 $pageNumbersFont = $this->font_size_list;
             } else {
                 // Properly align right
                 $width = $objPdf->getTextWidth($this->font_size_footer, $arrFooterRight[$i]);
                 $objPdf->addText(595.28 - $width - 25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterRight[$i]);
             }
         }
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($footerForAllPages, 'all');
     }
     // Page numbers
     if (isset($pageNumbersX)) {
         $objPdf->ezStartPageNumbers($pageNumbersX, $pageNumbersY, $pageNumbersFont, '', $_ARRAYLANG['TXT_SHOP_PRICELIST_FORMAT_PAGENUMBER'], 1);
     }
     // Margins
     $objPdf->ezSetMargins($marginTop, $marginBottom, 30, 30);
     // Product table
     if (isset($startpointY)) {
         $objPdf->ezSetY($startpointY);
     }
     $objInit->backendLangId = $this->lang_id;
     $_ARRAYLANG = $objInit->loadLanguageData('Shop');
     Currency::setActiveCurrencyId($this->currency_id);
     $currency_symbol = Currency::getActiveCurrencySymbol();
     $category_ids = $this->category_ids();
     if ($category_ids == '*') {
         $category_ids = null;
     }
     $count = 1000;
     // Be sensible!
     // Pattern is "%" because all-empty parameters will result in an
     // empty array!
     $arrProduct = Products::getByShopParams($count, 0, null, $category_ids, null, '%', null, null, '`category_id` ASC, `name` ASC');
     $arrCategoryName = ShopCategories::getNameArray();
     $arrOutput = array();
     foreach ($arrProduct as $product_id => $objProduct) {
         $categoryIds = explode(',', $objProduct->category_id());
         $arrCategoryNames = array();
         foreach ($categoryIds as $categoryId) {
             $arrCategoryNames[] = $arrCategoryName[$categoryId];
         }
         //$objProduct = new Product();
         $arrOutput[$product_id] = array('product_name' => self::decode($objProduct->name()), 'category_name' => self::decode(implode(', ', $arrCategoryNames)), 'product_code' => self::decode($objProduct->code()), 'product_id' => self::decode($objProduct->id()), 'price' => ($objProduct->discount_active() ? "S " . Currency::formatPrice($objProduct->discountprice()) : Currency::formatPrice($objProduct->price())) . ' ' . $currency_symbol);
     }
     $objPdf->ezTable($arrOutput, array('product_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_NAME']) . '</b>', 'category_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_CATEGORY_NAME']) . '</b>', 'product_code' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_CODE']) . '</b>', 'product_id' => '<b>' . self::decode($_ARRAYLANG['TXT_ID']) . '</b>', 'price' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRICE']) . '</b>'), '', array('showHeadings' => 1, 'fontSize' => $this->font_size_list, 'width' => 530, 'innerLineThickness' => 0.5, 'outerLineThickness' => 0.5, 'shaded' => 2, 'shadeCol' => array(hexdec(substr($this->row_color_1, 0, 2)) / 255, hexdec(substr($this->row_color_1, 2, 2)) / 255, hexdec(substr($this->row_color_1, 4, 2)) / 255), 'shadeCol2' => array(hexdec(substr($this->row_color_2, 0, 2)) / 255, hexdec(substr($this->row_color_2, 2, 2)) / 255, hexdec(substr($this->row_color_2, 4, 2)) / 255), 'cols' => array('product_name' => array('width' => 255), 'category_name' => array('width' => 130), 'product_code' => array('width' => 50), 'product_id' => array('width' => 40, 'justification' => 'right'), 'price' => array('width' => 55, 'justification' => 'right'))));
     $objPdf->ezStream();
     // Never reached
     return true;
 }
예제 #2
0
 /**
  * Show Products
  */
 function view_product_overview()
 {
     global $_ARRAYLANG;
     if (isset($_POST['bsubmit'])) {
         $this->update_products();
     }
     if (isset($_POST['multi_action'])) {
         if ($_POST['multi_action'] == 'activate') {
             Products::set_active($_POST['selectedProductId'], true);
         } elseif ($_POST['multi_action'] == 'deactivate') {
             Products::set_active($_POST['selectedProductId'], false);
         }
     }
     self::$objTemplate->addBlockfile('SHOP_PRODUCTS_FILE', 'shop_products_block', 'module_shop_product_catalog.html');
     self::$objTemplate->setGlobalVariable($_ARRAYLANG);
     $category_id = empty($_REQUEST['category_id']) ? null : intval($_REQUEST['category_id']);
     //DBG::log("Requested Category ID: $category_id");
     $manufacturer_id = empty($_REQUEST['manufacturer_id']) ? null : intval($_REQUEST['manufacturer_id']);
     $flagSpecialoffer = isset($_REQUEST['specialoffer']);
     $searchTerm = empty($_REQUEST['searchterm']) ? null : trim(contrexx_input2raw($_REQUEST['searchterm']));
     $url = \Html::getRelativeUri();
     // TODO: Strip URL parameters: Which?
     //        \Html::stripUriParam($url, '');
     $arrSorting = array('`product`.`id`' => $_ARRAYLANG['TXT_SHOP_ID'], '`product`.`active`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_ACTIVE'], '`product`.`ord`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_ORDER'], 'name' => $_ARRAYLANG['TXT_SHOP_PRODUCT_NAME'], 'code' => $_ARRAYLANG['TXT_SHOP_PRODUCT_CODE'], '`product`.`discountprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_DISCOUNTPRICE'], '`product`.`normalprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_NORMALPRICE'], '`product`.`resellerprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_RESELLERPRICE'], '`product`.`distribution`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_DISTRIBUTION'], '`product`.`stock`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_STOCK']);
     $objSorting = new \Sorting($url, $arrSorting, false, 'order_shop_product');
     $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_products_per_page_backend', 'Shop');
     $tries = 2;
     while ($tries--) {
         // have to set $count again because it will be set to 0 in Products::getByShopParams
         $count = $limit;
         // Mind that $count is handed over by reference.
         $arrProducts = Products::getByShopParams($count, \Paging::getPosition(), 0, $category_id, $manufacturer_id, $searchTerm, $flagSpecialoffer, false, $objSorting->getOrder(), null, true);
         if (count($arrProducts) > 0 || \Paging::getPosition() == 0) {
             break;
         }
         \Paging::reset();
     }
     self::$objTemplate->setVariable(array('SHOP_CATEGORY_MENU' => \Html::getSelect('category_id', array(0 => $_ARRAYLANG['TXT_ALL_PRODUCT_GROUPS']) + ShopCategories::getNameArray(), $category_id), 'SHOP_SEARCH_TERM' => $searchTerm, 'SHOP_PRODUCT_TOTAL' => $count));
     if (empty($arrProducts)) {
         self::$objTemplate->touchBlock('no_product');
         return true;
     }
     self::$objTemplate->setVariable(array('SHOP_PRODUCT_PAGING' => \Paging::get($url, '<b>' . $_ARRAYLANG['TXT_PRODUCTS'] . '</b>', $count, $limit, true), 'SHOP_HEADING_PRODUCT_ID' => $objSorting->getHeaderForField('`product`.`id`'), 'SHOP_HEADING_PRODUCT_ACTIVE' => $objSorting->getHeaderForField('`product`.`active`'), 'SHOP_HEADING_PRODUCT_ORD' => $objSorting->getHeaderForField('`product`.`ord`'), 'SHOP_HEADING_PRODUCT_NAME' => $objSorting->getHeaderForField('name'), 'SHOP_HEADING_PRODUCT_CODE' => $objSorting->getHeaderForField('code'), 'SHOP_HEADING_PRODUCT_DISCOUNTPRICE' => $objSorting->getHeaderForField('`product`.`discountprice`'), 'SHOP_HEADING_PRODUCT_NORMALPRICE' => $objSorting->getHeaderForField('`product`.`normalprice`'), 'SHOP_HEADING_PRODUCT_RESELLERPRICE' => $objSorting->getHeaderForField('`product`.`resellerprice`'), 'SHOP_HEADING_PRODUCT_DISTRIBUTION' => $objSorting->getHeaderForField('`product`.`distribution`'), 'SHOP_HEADING_PRODUCT_STOCK' => $objSorting->getHeaderForField('`product`.`stock`')));
     $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]);
     $i = 0;
     foreach ($arrProducts as $objProduct) {
         $productStatus = '';
         $productStatusValue = '';
         $productStatusPicture = 'status_red.gif';
         if ($objProduct->active()) {
             $productStatus = \Html::ATTRIBUTE_CHECKED;
             $productStatusValue = 1;
             $productStatusPicture = 'status_green.gif';
         }
         $discount_active = '';
         $specialOfferValue = '';
         if ($objProduct->discount_active()) {
             $discount_active = \Html::ATTRIBUTE_CHECKED;
             $specialOfferValue = 1;
         }
         self::$objTemplate->setGlobalVariable(array('SHOP_ROWCLASS' => 'row' . (++$i % 2 + 1), 'SHOP_PRODUCT_ID' => $objProduct->id(), 'SHOP_PRODUCT_CODE' => $objProduct->code(), 'SHOP_PRODUCT_NAME' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_PRODUCT_PRICE1' => Currency::formatPrice($objProduct->price()), 'SHOP_PRODUCT_PRICE2' => Currency::formatPrice($objProduct->resellerprice()), 'SHOP_PRODUCT_DISCOUNT' => Currency::formatPrice($objProduct->discountprice()), 'SHOP_PRODUCT_SPECIAL_OFFER' => $discount_active, 'SHOP_SPECIAL_OFFER_VALUE_OLD' => $specialOfferValue, 'SHOP_PRODUCT_VAT_MENU' => Vat::getShortMenuString($objProduct->vat_id(), 'taxId[' . $objProduct->id() . ']'), 'SHOP_PRODUCT_VAT_ID' => $objProduct->vat_id() ? $objProduct->vat_id() : 'NULL', 'SHOP_PRODUCT_DISTRIBUTION' => $objProduct->distribution(), 'SHOP_PRODUCT_STOCK' => $objProduct->stock(), 'SHOP_PRODUCT_SHORT_DESC' => $objProduct->short(), 'SHOP_PRODUCT_STATUS' => $productStatus, 'SHOP_PRODUCT_STATUS_PICTURE' => $productStatusPicture, 'SHOP_ACTIVE_VALUE_OLD' => $productStatusValue, 'SHOP_SORT_ORDER' => $objProduct->ord(), 'SHOP_DISTRIBUTION' => $_ARRAYLANG['TXT_DISTRIBUTION_' . strtoupper($objProduct->distribution())], 'SHOP_SHOW_PRODUCT_ON_START_PAGE_CHECKED' => $objProduct->shown_on_startpage() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_SHOW_PRODUCT_ON_START_PAGE_OLD' => $objProduct->shown_on_startpage() ? '1' : '', 'SHOP_PRODUCT_NAME' => contrexx_raw2xhtml($objProduct->name())));
         // All languages active
         foreach ($arrLanguages as $lang_id => $arrLanguage) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_LANGUAGE_ID' => $lang_id, 'SHOP_PRODUCT_LANGUAGE_EDIT' => sprintf($_ARRAYLANG['TXT_SHOP_PRODUCT_LANGUAGE_EDIT'], $lang_id, $arrLanguage['lang'], $arrLanguage['name'])));
             self::$objTemplate->parse('product_language');
         }
         self::$objTemplate->touchBlock('productRow');
         self::$objTemplate->parse('productRow');
     }
     return true;
 }