registerTask ('recommend', 'MailForm');
$this->registerTask ('askquestion', 'MailForm');
}
function display() {
$format = JRequest::getWord ('format', 'html');
if ($format == 'pdf') {
$viewName = 'Pdf';
} else {
$viewName = 'Productdetails';
}
$view = $this->getView ($viewName, $format);
$view->display ();
}
/**
* Send the ask question email.
*
* @author Kohl Patrick, Christopher Roussel
* @author Max Milbers
*/
public function mailAskquestion () {
JRequest::checkToken () or jexit ('Invalid Token');
$app = JFactory::getApplication ();
if(!VmConfig::get('ask_question',false)){
$app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
}
$view = $this->getView ('askquestion', 'html');
if (!class_exists ('shopFunctionsF')) {
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
}
$vars = array();
$min = VmConfig::get ('asks_minimum_comment_length', 50) + 1;
$max = VmConfig::get ('asks_maximum_comment_length', 2000) - 1;
$commentSize = JRequest::getString ('comment');
if (function_exists('mb_strlen')) {
$commentSize = mb_strlen($commentSize);
} else {
$commentSize = strlen($commentSize);
}
$validMail = filter_var (JRequest::getVar ('email'), FILTER_VALIDATE_EMAIL);
if ($commentSize < $min or $commentSize > $max or !$validMail) {
$errmsg = JText::_ ('COM_VIRTUEMART_COMMENT_NOT_VALID_JS');
if ($commentSize < $min) {
$errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MIN');
;
} else {
if ($commentSize > $max) {
$errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MAX');
;
} else {
if (!$validMail) {
$errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_INV_MAIL');
;
}
}
}
$this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), $errmsg);
return;
}
if(JFactory::getUser()->guest == 1 and VmConfig::get ('ask_captcha')){
$recaptcha = vRequest::getVar ('recaptcha_response_field');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$recaptcha);
$session = JFactory::getSession();
if(!$res[0]){
$askquestionform = array('name' => vRequest::getVar ('name'), 'email' => vRequest::getVar ('email'), 'comment' => vRequest::getString ('comment'));
$session->set('askquestion', $askquestionform, 'vm');
$errmsg = vmText::_('PLG_RECAPTCHA_ERROR_INCORRECT_CAPTCHA_SOL');
$this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . vRequest::getInt ('virtuemart_product_id', 0)), $errmsg);
return;
} else {
$session->set('askquestion', 0, 'vm');
}
}
$user = JFactory::getUser ();
if (empty($user->id)) {
$fromMail = JRequest::getVar ('email'); //is sanitized then
$fromName = JRequest::getVar ('name', ''); //is sanitized then
$fromMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromMail);
$fromName = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromName);
} else {
$fromMail = $user->email;
$fromName = $user->name;
}
$vars['user'] = array('name' => $fromName, 'email' => $fromMail);
$virtuemart_product_id = vRequest::getInt ('virtuemart_product_id', 0);
$productModel = VmModel::getModel ('product');
$vars['product'] = $productModel->getProduct ($virtuemart_product_id);
$vendorModel = VmModel::getModel ('vendor');
$VendorEmail = $vendorModel->getVendorEmail ($vars['product']->virtuemart_vendor_id);
if (shopFunctionsF::renderMail ('askquestion', $VendorEmail, $vars, 'productdetails')) {
$string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
} else {
$string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
}
$app->enqueueMessage (JText::_ ($string));
$view->setLayout ('mail_confirmed');
$view->display ();
}
/**
* Send the Recommend to a friend email.
*
* @author Kohl Patrick
* @author Max Milbers
*/
public function mailRecommend () {
JRequest::checkToken () or jexit ('Invalid Token');
$app = JFactory::getApplication ();
if(!VmConfig::get('show_emailfriend',false)){
$app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=recommend&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
}
if(JFactory::getUser()->guest == 1 and VmConfig::get ('ask_captcha')){
$recaptcha = vRequest::getVar ('recaptcha_response_field');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance();
$res = $dispatcher->trigger('onCheckAnswer',$recaptcha);
$session = JFactory::getSession();
if(!$res[0]){
$mailrecommend = array('email' => vRequest::getVar ('email'), 'comment' => vRequest::getString ('comment'));
$session->set('mailrecommend', $mailrecommend, 'vm');
$errmsg = vmText::_('PLG_RECAPTCHA_ERROR_INCORRECT_CAPTCHA_SOL');
$this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=recommend&virtuemart_product_id=' . vRequest::getInt ('virtuemart_product_id', 0)), $errmsg);
return;
} else {
$session->set('mailrecommend', 0, 'vm');
}
}
if (!class_exists ('shopFunctionsF')) {
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
}
if(!class_exists('ShopFunctions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'shopfunctions.php');
$vars = array();
$toMail = JRequest::getVar ('email'); //is sanitized then
$toMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $toMail);
if (shopFunctionsF::renderMail ('recommend', $toMail, $vars, 'productdetails', TRUE)) {
$string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
} else {
$string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
}
$app->enqueueMessage (JText::_ ($string));
// Display it all
$view = $this->getView ('recommend', 'html');
$view->setLayout ('mail_confirmed');
$view->display ();
}
/**
* Ask Question form
* Recommend form for Mail
*/
public function MailForm () {
if (JRequest::getCmd ('task') == 'recommend') {
$view = $this->getView ('recommend', 'html');
} else {
$view = $this->getView ('askquestion', 'html');
}
/* Set the layout */
$view->setLayout ('form');
// Display it all
$view->display ();
}
/**
* Add or edit a review
*/
public function review () {
$msg="";
$model = VmModel::getModel ('ratings');
$virtuemart_product_id = vRequest::getInt('virtuemart_product_id',0);
$allowReview = $model->allowReview($virtuemart_product_id);
$allowRating = $model->allowRating($virtuemart_product_id);
if($allowReview || $allowRating){
$return = $model->saveRating ();
if ($return !== FALSE) {
$errors = $model->getErrors ();
if (empty($errors)) {
$msg = JText::sprintf ('COM_VIRTUEMART_STRING_SAVED', JText::_ ('COM_VIRTUEMART_REVIEW'));
}
foreach ($errors as $error) {
$msg = ($error) . '
';
}
if (!class_exists ('ShopFunctionsF')) {
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
}
$data = vRequest::getPost();
if($allowReview){
}
shopFunctionsF::sendRatingEmailToVendor($data);
}
}
$this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $virtuemart_product_id, FALSE), $msg);
}
/**
* Json task for recalculation of prices
*
* @author Max Milbers
* @author Patrick Kohl
*
*/
public function recalculate () {
//$post = JRequest::get('request');
// echo '
'.print_r($post,1).''; jimport ('joomla.utilities.arrayhelper'); $virtuemart_product_idArray = JRequest::getVar ('virtuemart_product_id', array()); //is sanitized then if(is_array($virtuemart_product_idArray)){ JArrayHelper::toInteger ($virtuemart_product_idArray); $virtuemart_product_id = $virtuemart_product_idArray[0]; } else { $virtuemart_product_id = $virtuemart_product_idArray; } $customPrices = array(); $customVariants = JRequest::getVar ('customPrice', array()); //is sanitized then //echo '
'.print_r($customVariants,1).''; //MarkerVarMods foreach ($customVariants as $customVariant) { //foreach ($customVariant as $selected => $priceVariant) { //In this case it is NOT $selected => $variant, because we get it that way from the form foreach ($customVariant as $priceVariant => $selected) { //Important! sanitize array to int $selected = (int)$selected; $customPrices[$selected] = $priceVariant; } } $quantityArray = JRequest::getVar ('quantity', array()); //is sanitized then JArrayHelper::toInteger ($quantityArray); $quantity = 1; if (!empty($quantityArray[0])) { $quantity = $quantityArray[0]; } $product_model = VmModel::getModel ('product'); //VmConfig::$echoDebug = TRUE; $prices = $product_model->getPrice ($virtuemart_product_id, $customPrices, $quantity); $priceFormated = array(); if (!class_exists ('CurrencyDisplay')) { require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); } $currency = CurrencyDisplay::getInstance (); foreach ($prices as $name => $product_price) { // echo 'Price is '.print_r($name,1).'