function onAction() { global $application; $this->topics = modApiFunc('Request', 'getValueByKey', 'topic'); if (empty($this->topics)) { $this->topics = array(); } $SessionPost = array(); $this->email = trim(modApiFunc('Request', 'getValueByKey', 'email')); if (modApiFunc('Users', 'isValidEmail', $this->email)) { if (modApiFunc('Subscriptions', 'canClientUnsubscribe')) { $ViewState = $this->changeSubscriptions(); } else { $ViewState = $this->addSubscriptions(); } $SessionPost['ViewState'] = $ViewState; if ($this->signed_in) { $params = array('account' => $this->account, 'email' => $this->email); execQuery('SUBSCR_LINK_SUBSCRIPTION_TO_CUSTOMER', $params); } else { modApiFunc('Subscriptions', 'setCustomerSubscribedEmail', $this->email); } } else { $SessionPost['ViewState']['ErrorsArray'][] = getMsg('SUBSCR', 'ERROR_SUBSCR_INVALID_EMAIL'); } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); $r = new Request(); $r->setView(CURRENT_REQUEST_URL); $r->setAnchor('subscribe_box'); $application->redirect($r); }
/** * Returns Review info tag value */ function getReviewTagValue($tag) { $output = ''; // if productid is incorrect returns '' in any case if ($this->_productid_invalid) { return ''; } switch ($tag) { case 'number': $output = modApiFunc('Customer_Reviews', 'getProductCustomerReviewNumber', $this->_productid); if (!$this->checkReviewAvail(6, 7)) { $output = 0; } break; case 'averagerating': $output = modApiFunc('Customer_Reviews', 'getTotalProductRating', $this->_productid); $output = $output['total_rating']; if (!$this->checkReviewAvail(7)) { $output = 0; } break; case 'link': $cid = modApiFunc('CProductListFilter', 'getCurrentCategoryId'); $r = new Request(); $r->setView('ProductInfo'); $r->setAction('SetCurrentProduct'); $r->setKey('prod_id', $this->_productid); $r->setProductID($this->_productid); $r->setCategoryID($cid); $r->setAnchor('customer_reviews_' . $this->_productid); return $r->getURL(); } return $output; }
function onAction() { global $application; $SessionPost = array('ViewState' => array()); if ($this->signed_in) { $this->email = modApiFunc('Request', 'getValueByKey', 'email'); $emails = modApiFunc('Subscriptions', 'getCustomerSubscriptionEmails', $this->account); if (in_array($this->email, $emails)) { execQuery('SUBSCR_LINK_SUBSCRIPTION_TO_CUSTOMER', array('email' => $this->email, 'customer_id' => 0)); execQuery('SUBSCR_UNSUBSCRIBE_FROM_ALL', array('email' => $this->email)); $SessionPost['ViewState']['Messages'][] = getMsg('SUBSCR', 'MSG_SUBSCR_EMAIL_REMOVED'); } } else { } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); $r = new Request(); $r->setView(CURRENT_REQUEST_URL); $r->setAnchor('subscribe_box'); $application->redirect($r); }
function onAction() { global $application; $request =& $application->getInstance('Request'); // getting posted review data $review_data = array('author' => $request->getValueByKey('author'), 'review' => $request->getValueByKey('review'), 'rating' => $request->getValueByKey('rating'), 'product_id' => $request->getValueByKey('product_id')); // saving product_id in stand alone variable // we will need it while redirecting $product_id = $review_data['product_id']; // getting settings for customer reviews // if customer reviews are enabled $reviews_enable = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_ENABLE'); // if only registered customers can post the reviews $reviews_writing = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_WRITING'); // if multiple reviews from the same IP is enabled $reviews_multiple = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_MULTIPLE'); $reviews_approving = modApiFunc('Settings', 'getParamValue', 'CUSTOMER_REVIEWS', 'CUSTOMER_REVIEWS_APPROVING'); // the number of reviews for the product posted from the IP $ip_reviews = modApiFunc('Customer_Reviews', 'getReviewsCountForProductByIP', $product_id, $_SERVER['REMOTE_ADDR']); // getting the product data $product_data = modApiFunc('Customer_Reviews', 'getBaseProductInfo', array('product_id' => $product_id)); // getting the list of rates $rating = modApiFunc('Customer_Reviews', 'getCustomerReviewsRates', 0, 'Y'); // validating the data $error = ''; $review_data['error'] = ''; // checking the author if ($review_data['author'] == '') { $error = 'no_author'; $review_data['error'] .= "\n" . $this->_errors[$error]; } // checking the review if ($review_data['review'] == '' && in_array($product_data['product_cr'], array(5, 6))) { $error = 'no_review'; $review_data['error'] .= "\n" . $this->_errors[$error]; } // checking the rating if (is_array($rating) && !empty($rating) && in_array($product_data['product_cr'], array(5, 7))) { if (!is_array($review_data['rating'])) { $error = 'no_rating'; } else { foreach ($rating as $k => $v) { if (!isset($review_data['rating'][$v['cr_rl_id']])) { $error = 'no_rating'; } else { $rating[$k]['rate'] = $review_data['rating'][$v['cr_rl_id']]; } } } } // filling the error (to avoid several messages) if ($error == 'no_rating') { $review_data['error'] .= "\n" . $this->_errors[$error]; } // checking the product_id // abnormal error... if ($product_id <= 0) { $error = 'no_product'; $review_data['error'] .= "\n" . $this->_errors[$error]; } // if posting reviews is still available // use case: settings have been changed // before customer submits the form if ($reviews_enable == 'NO' || $reviews_writing == 'NONE' || !in_array($product_data['product_cr'], array(5, 6, 7))) { $error = 'disabled'; $review_data['error'] .= "\n" . $this->_errors[$error]; } // if multiple reviews from the same IP is disabled // while a review for the IP exists if ($reviews_multiple == 'NO' && $ip_reviews > 0) { $error = 'multiple'; $review_data['error'] .= "\n" . $this->_errors[$error]; } // if the customer is anonymous while writing reviews is available // for signed in customers if ($reviews_writing == 'REGONLY' && !modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) { $error = 'anonymous'; $review_data['error'] .= "\n" . $this->_errors[$error]; } $moduleexists = modApiFunc('Modules_Manager', 'isModulePresentInAvactisExtensionsFolder', 'captcha'); if ($moduleexists == 1) { if (!modApiFunc('Captcha', 'validateCaptcha', 'review')) { $error = 'captcha'; $review_data['error'] .= "\n" . getMsg('CS', 'E_INCORRECT_CAPTCHA'); } } // if any error save the error in review_data if ($error) { $review_data['error'] = _ml_substr($review_data['error'], 1); } else { // no errors, we are ready to save the data // filling the missing information before saving // datetime $review_data['datetime'] = '\'' . date('Y-m-d H:i:s') . '\''; // status (depending if the review needs to be approved) $review_data['status'] = 'P'; if ($reviews_approving == 'NONE' || $reviews_approving == 'ANONYMOUS' && modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) { $review_data['status'] = 'A'; } // IP address $review_data['ip_address'] = $_SERVER['REMOTE_ADDR']; // inserting fake review execQuery('INSERT_FAKE_CUSTOMER_REVIEW', array()); $mysql =& $application->getInstance('DB_MySQL'); $review_data['cr_id'] = $mysql->DB_Insert_Id(); $this->_cr_id_posted = $review_data['cr_id']; // updating the data execQuery('UPDATE_CUSTOMER_REVIEW_RECORD', $review_data); // saving the rating if (is_array($rating)) { foreach ($rating as $v) { execQuery('INSERT_CUSTOMER_REVIEW_RATE_RECORD', array('cr_id' => $review_data['cr_id'], 'cr_rl_id' => $v['cr_rl_id'], 'rate' => $v['rate'])); } } // review has been changed, setting up the success message // depending on the status // other data is not needed so we clear it if ($review_data['status'] == 'A') { $review_data = array('success' => $this->_success['added']); } else { $review_data = array('success' => $this->_success['accepted']); } } // saving the review_data in the session if (modApiFunc('Session', 'is_set', 'PostingReviewData')) { $posting_review_data = modApiFunc('Session', 'get', 'PostingReviewData'); } else { $posting_review_data = array(); } $posting_review_data[$product_id] = $review_data; modApiFunc('Session', 'set', 'PostingReviewData', $posting_review_data); // all is done, redirecting... $return_url = $request->getValueByKey('return_url'); // removing the anchor if any if (_ml_strpos($return_url, '#') !== false) { $return_url = _ml_substr($return_url, 0, _ml_strpos($return_url, '#')); } if ($return_url != '') { $req_to_redirect = new Request($return_url); } else { // abnormal situation... $req_to_redirect = new Request(); $req_to_redirect->setView(CURRENT_REQUEST_URL); $req_to_redurect->setAction('SetCurrentProduct'); $req_to_redirect->setKey('prod_id', $product_id); } // setting the anchor $req_to_redirect->setAnchor('add_review_' . $product_id); // redirecting $application->redirect($req_to_redirect); }
/** * Outputs Forbidden Template * use case: customer is anonyous while posting a review * is available for signed-in customers */ function outputForbidden() { global $application; if ($this->_view == CURRENT_REQUEST_URL) { $return_url = modApiFunc('Request', 'selfURL'); if (_ml_strpos($return_url, '#') !== false) { $return_url = _ml_substr($return_url, 0, _ml_strpos($return_url, '#')); } $return_url .= '#add_review_' . $this->_product_data['product_id']; } else { $r = new Request(); $r->setView($this->_view); $r->setAction('SetCurrentProduct'); $r->setKey('prod_id', $this->_product_data['product_id']); $r->setAnchor('add_review_' . $this->_product_data['product_id']); $return_url = $r->getURL(); } $r = new Request(); $r->setView($this->_view); $r->setAction('sign_in_required'); $r->setKey('returnURL', urlencode($return_url)); $_tags = array('Local_Link' => $r->getURL()); $this->_Template_Contents = $_tags; $application->registerAttributes($this->_Template_Contents); return $this->mTmplFiller->fill($this->_templates['forbidden']); }