get('vmlastvisitedcategoryid', 0, 'vm'); } /** * @author Max Milbers */ public function setLastVisitedCategoryId($categoryId){ $session = JFactory::getSession(); return $session->set('vmlastvisitedcategoryid', (int) $categoryId, 'vm'); } /** * function to create a div to show the prices, is necessary for JS * * @author Max Milbers * @author Patrick Kohl * @param string name of the price * @param String description key * @param array the prices of the product * return a div for prices which is visible according to config and have all ids and class set */ public function createPriceDiv($name,$description,$product_price){ //Console::logSpeed('hopFunctionsF::createPriceDiv called'); //This could be easily extended by product specific settings if(VmConfig::get($name) =='1'){ if(!empty($product_price[$name])){ $vis = "block"; $calculator = calculationHelper::getInstance(); $product_price[$name] = $calculator->priceDisplay($product_price[$name]); } else { $vis = "none"; } $descr = ''; if(VmConfig::get($name.'Text',true)) $descr = JText::_($description); return '
'.$descr.''.$product_price[$name].'
'; } } /** * function to create a hyperlink * * @author RolandD * @param string $link * @param string $text * @param string $target * @param string $title * @param array $attributes * @return string */ public function hyperLink( $link, $text, $target='', $title='', $attributes='' ) { $options = array(); if( $target ) { $options['target'] = $target; } if( $title ) { $options['title'] = $title; } if( $attributes ) { $options = array_merge($options, $attributes); } return JHTML::_('link', $link, $text, $options); } /** * Writes a PDF icon * @author RolandD, Christopher Roussel * @param string $link * @param boolean $use_icon */ function PdfIcon( $link, $use_icon=true ) { if (VmConfig::get('pshop_pdf_button_enable', 1) == '1' && !JRequest::getVar('pop')) { $folder = (VmConfig::isJ15()) ? '/images/M_images/' : '/media/system/images/'; $link .= '&pop=1'; if ( $use_icon ) { $text = JHtml::_('image.site', 'pdf_button.png', $folder, null, null, JText::_('CMN_PDF')); } else { $text = JText::_('CMN_PDF') .' '; } return self::vmPopupLink($link, $text, 640, 480, '_blank', JText::_('CMN_PDF')); } } /** * Writes an Email icon * @author RolandD, Christopher Roussel * @param string $link * @param boolean $use_icon */ function EmailIcon( $product_id, $use_icon=true ) { if (VmConfig::get('vm_show_emailfriend', 1) == '1' && !JRequest::getVar('pop') && $product_id > 0 ) { $folder = (VmConfig::isJ15()) ? '/images/M_images/' : '/media/system/images/'; //Todo this is old stuff and must be adjusted $link = JRoute::_('index2.php?page=shop.recommend&product_id='.$product_id.'&pop=1&tmpl=component'); if ( $use_icon ) { $text = JHtml::_('image.site', 'emailButton.png', $folder, null, null, JText::_('CMN_EMAIL')); } else { $text = ' '. JText::_('CMN_EMAIL'); } return self::vmPopupLink($link, $text, 640, 480, '_blank', JText::_('CMN_EMAIL'), 'screenX=100,screenY=200'); } } /** * @author RolandD, Christopher Roussel */ function PrintIcon( $link='', $use_icon=true, $add_text='' ) { global $cur_template, $Itemid; if (VmConfig::get('vm_show_printicon', 1) == '1') { $folder = (VmConfig::isJ15()) ? '/images/M_images/' : '/media/system/images/'; if( !$link ) { //Todo this is old stuff and must be adjusted $query_string = str_replace( 'only_page=1', 'only_page=0', JRequest::getVar('QUERY_STRING')); $link = 'index2.php?'.$query_string.'&pop=1&tmpl=component'; } // checks template image directory for image, if non found default are loaded if ( $use_icon ) { $filter = JFilterInput::getInstance(); $text = JHtml::_('image.site', 'printButton.png', $folder, null, null, JText::_('CMN_PRINT')); $text .= $filter->clean($add_text); } else { $text = '| '. JText::_('CMN_PRINT'). ' |'; } $isPopup = JRequest::getVar( 'pop' ); if ( $isPopup ) { // Print Preview button - used when viewing page $html = ' '. $text .' '; return $html; } else { // Print Button - used in pop-up window return self::vmPopupLink($link, $text, 640, 480, '_blank', JText::_('CMN_PRINT')); } } } /** * A function to create a XHTML compliant and JS-disabled-safe pop-up link * * @author RolandD * @param string $link The HREF attribute * @param string $text The link text * @param int $popupWidth * @param int $popupHeight * @param string $target The value of the target attribute * @param string $title * @param string $windowAttributes * @return string */ public function vmPopupLink( $link, $text, $popupWidth=640, $popupHeight=480, $target='_blank', $title='', $windowAttributes='' ) { if( $windowAttributes ) { $windowAttributes = ','.$windowAttributes; } return self::hyperLink( $link, $text, '', $title, array("onclick" => "void window.open('$link', '$target', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=$popupWidth,height=$popupHeight,directories=no,location=no".$windowAttributes."');return false;" )); } /** * //Todo this is old stuff and must be adjusted * Checks to see if an image exists in the current templates image directory * if it does it loads this image. Otherwise the default image is loaded. * Also can be used in conjunction with the menulist param to create the chosen image * load the default or use no image */ function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name=NULL, $type=1, $align='middle', $title=NULL, $admin=NULL ) { $mainframe = JFactory::getApplication(); $cur_template = $mainframe->getTemplate(); $name = ( $name ? ' name="'. $name .'"' : '' ); $title = ( $title ? ' title="'. $title .'"' : '' ); $alt = ( $alt ? ' alt="'. $alt .'"' : ' alt=""' ); $align = ( $align ? ' align="'. $align .'"' : '' ); // change directory path from frontend or backend if ($admin) { $path = '/administrator/templates/'. $cur_template .'/images/'; } else { $path = '/templates/'. $cur_template .'/images/'; } if ( $param ) { $image = JURI::base(). $param_directory . $param; if ( $type ) { $image = ''; } } else if ( $param == -1 ) { $image = ''; } else { if ( file_exists( JPATH_SITE . $path . $file ) ) { $image = JURI::base() . $path . $file; } else { // outputs only path to image $image = JURI::base(). $directory . $file; } // outputs actual html tag if ( $type ) { $image = ''; } } return $image; } /** * Sends the mail joomla conform * TODO people often send media with emails. Like pictures, serials,... * * @author Max Milbers * @param $body the html body to send, the content of the email * @param $recipient the recipients of the mail, can be array also * @param $mediaToSend an array for the paths which holds the files which should be sent to * @param $vendorId default is 1 (mainstore) */ function sendMail($body,$recipient,$subject='TODO set subject', $vendor_id=1, $mediaToSend = false ){ $mailer =& JFactory::getMailer(); //This is now just without multivendor $config =& JFactory::getConfig(); $sender = array( $config->getValue( 'config.mailfrom' ), $config->getValue( 'config.fromname' ) ); $mailer->setSender($sender); $mailer->addRecipient($recipient); $mailer->setSubject($subject); // Optional file attached //this information must come from the cart if($mediaToSend){ //Test if array, if not make an array out of it foreach ($mediaToSend as $media){ //Todo test and such things. $mailer->addAttachment($media); } } $mailer->isHTML(true); $mailer->setBody($body); // Optionally add embedded image //TODO Test it $vendor = $this->getModel('vendor','VirtuemartModel'); $vendor->setId($vendor_id); $_store = $vendor->getVendor(); $mailer->AddEmbeddedImage( VmConfig::get('media_path').DS.$_store->vendor_full_image, 'base64', 'image/jpeg' ); return $mailer->Send(); //Perfect Exampel for a misplaced return message. The function is used in different locations, so the messages should be set there! // if ( $send !== true ) { // echo 'Error sending email: ' . $send->message; // } else { // echo 'Mail sent'; // } } /** * This function sets the right template on the view * @author Max Milbers */ function setVmTemplate($view,$catTpl=0,$prodTpl=0,$catLayout=0,$prodLayout=0){ //Lets get here the template set in the shopconfig, if there is nothing set, get the joomla standard $template = VmConfig::get('vmtemplate','default'); //Set specific category template if(!empty($catTpl) && empty($prodTpl)){ if(is_Int($catTpl)){ $db = JFactory::getDBO(); $q = 'SELECT `category_template` FROM `#__vm_category` WHERE `category_id` = "'.$catTpl.'" '; $db->setQuery($q); $temp = $db->loadResult(); if ($temp) $template = $temp; } else { $template = $catTpl; } } //Set specific product template if(!empty($prodTpl)){ if(is_Int($prodTpl)){ $db = JFactory::getDBO(); $q = 'SELECT `product_template` FROM `#__vm_product` WHERE `product_id` = "'.$prodTpl.'" '; $db->setQuery($q); $temp = $db->loadResult(); if($temp) $template = $temp; } else { $template = $prodTpl; } } shopFunctionsF::setTemplate($template); //Lets get here the layout set in the shopconfig, if there is nothing set, get the joomla standard $layout = VmConfig::get('vmlayout','default'); //Set specific category layout if(!empty($catLayout) && empty($prodLayout)){ if(is_Int($catLayout)){ $db = JFactory::getDBO(); $q = 'SELECT `layout` FROM `#__vm_category` WHERE `category_id` = "'.$catLayout.'" '; $db->setQuery($q); $temp = $db->loadResult(); if ($temp) $layout = $temp; } else { $layout = $catLayout; } } //Set specific product layout if(!empty($prodLayout)){ if(is_Int($prodLayout)){ $db = JFactory::getDBO(); $q = 'SELECT `layout` FROM `#__vm_category` WHERE `category_id` = "'.$catLayout.'" '; $db->setQuery($q); $temp = $db->loadResult(); if ($temp) $layout = $temp; } else { $layout = $prodLayout; } } $view->setLayout(strtolower($layout)); } /** * Final setting of template * * @author Max Milbers */ function setTemplate( $template ){ if(!empty($template) && $template!='default'){ if (is_dir(JPATH_THEMES.DS.$template)) { //$this->addTemplatePath(JPATH_THEMES.DS.$template); $mainframe = JFactory::getApplication('site'); $mainframe->set('setTemplate', $template); } else{ JError::raiseWarning(412,'The choosen template couldnt found on the filesystem: '.$template); } } else{ //JError::raiseWarning('No template set : '.$template); } } function dumpIt($var,$desc){ global $dumper; $dumper[] = $desc.':
'.print_r($var,true).'
'; //
'.print_r(debug_backtrace(),true).' 
'; } function displayDumps(){ global $dumper; if(is_array($dumper)){ foreach($dumper as $dump){ echo $dump.'
'; } } } } // pure php no closing tag