diff --git a/modules/productcomments/js/jquery.textareaCounter.plugin.js b/modules/productcomments/js/jquery.textareaCounter.plugin.js
new file mode 100644
index 000000000..03ca3eb44
--- /dev/null
+++ b/modules/productcomments/js/jquery.textareaCounter.plugin.js
@@ -0,0 +1,163 @@
+/*
+ * jQuery Textarea Characters Counter Plugin v 2.0
+ * Examples and documentation at: http://roy-jin.appspot.com/jsp/textareaCounter.jsp
+ * Copyright (c) 2010 Roy Jin
+ * Version: 2.0 (11-JUN-2010)
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ * Requires: jQuery v1.4.2 or later
+ */
+(function($){
+ $.fn.textareaCount = function(options, fn) {
+ var defaults = {
+ maxCharacterSize: -1,
+ originalStyle: 'originalTextareaInfo',
+ warningStyle: 'warningTextareaInfo',
+ warningNumber: 20,
+ displayFormat: '#input characters | #words words'
+ };
+ var options = $.extend(defaults, options);
+
+ var container = $(this);
+
+ $("
").insertAfter(container);
+
+ //create charleft css
+ var charLeftCss = {
+ 'width' : container.width()
+ };
+
+ var charLeftInfo = getNextCharLeftInformation(container);
+ charLeftInfo.addClass(options.originalStyle);
+ charLeftInfo.css(charLeftCss);
+
+ var numInput = 0;
+ var maxCharacters = options.maxCharacterSize;
+ var numLeft = 0;
+ var numWords = 0;
+
+ container.bind('keyup', function(event){limitTextAreaByCharacterCount();})
+ .bind('mouseover', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);})
+ .bind('paste', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);});
+
+
+ function limitTextAreaByCharacterCount(){
+ charLeftInfo.html(countByCharacters());
+ //function call back
+ if(typeof fn != 'undefined'){
+ fn.call(this, getInfo());
+ }
+ return true;
+ }
+
+ function countByCharacters(){
+ var content = container.val();
+ var contentLength = content.length;
+
+ //Start Cut
+ if(options.maxCharacterSize > 0){
+ //If copied content is already more than maxCharacterSize, chop it to maxCharacterSize.
+ if(contentLength >= options.maxCharacterSize) {
+ content = content.substring(0, options.maxCharacterSize);
+ }
+
+ var newlineCount = getNewlineCount(content);
+
+ // newlineCount new line character. For windows, it occupies 2 characters
+ var systemmaxCharacterSize = options.maxCharacterSize - newlineCount;
+ if (!isWin()){
+ systemmaxCharacterSize = options.maxCharacterSize
+ }
+ if(contentLength > systemmaxCharacterSize){
+ //avoid scroll bar moving
+ var originalScrollTopPosition = this.scrollTop;
+ container.val(content.substring(0, systemmaxCharacterSize));
+ this.scrollTop = originalScrollTopPosition;
+ }
+ charLeftInfo.removeClass(options.warningStyle);
+ if(systemmaxCharacterSize - contentLength <= options.warningNumber){
+ charLeftInfo.addClass(options.warningStyle);
+ }
+
+ numInput = container.val().length + newlineCount;
+ if(!isWin()){
+ numInput = container.val().length;
+ }
+
+ numWords = countWord(getCleanedWordString(container.val()));
+
+ numLeft = maxCharacters - numInput;
+ } else {
+ //normal count, no cut
+ var newlineCount = getNewlineCount(content);
+ numInput = container.val().length + newlineCount;
+ if(!isWin()){
+ numInput = container.val().length;
+ }
+ numWords = countWord(getCleanedWordString(container.val()));
+ }
+
+ return formatDisplayInfo();
+ }
+
+ function formatDisplayInfo(){
+ var format = options.displayFormat;
+ format = format.replace('#input', numInput);
+ format = format.replace('#words', numWords);
+ //When maxCharacters <= 0, #max, #left cannot be substituted.
+ if(maxCharacters > 0){
+ format = format.replace('#max', maxCharacters);
+ format = format.replace('#left', numLeft);
+ }
+ return format;
+ }
+
+ function getInfo(){
+ var info = {
+ input: numInput,
+ max: maxCharacters,
+ left: numLeft,
+ words: numWords
+ };
+ return info;
+ }
+
+ function getNextCharLeftInformation(container){
+ return container.next('.charleft');
+ }
+
+ function isWin(){
+ var strOS = navigator.appVersion;
+ if (strOS.toLowerCase().indexOf('win') != -1){
+ return true;
+ }
+ return false;
+ }
+
+ function getNewlineCount(content){
+ var newlineCount = 0;
+ for(var i=0; ivalue;
elseif ($entry->key == "content")
$content = $entry->value;
+ elseif ($entry->key == "customer_name")
+ $name = $entry->value;
elseif (preg_match("/grade/", $entry->key))
{
$id = array(preg_split("/_/", $entry->key));
@@ -72,7 +75,8 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
die('0');
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
- if (Context::getContext()->customer->id AND (!Context::getContext()->customer->is_guest OR $allow_guests))
+
+ if (Context::getContext()->customer->id OR (!Context::getContext()->customer->id AND $allow_guests))
{
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
@@ -83,6 +87,7 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
$customer_name = false;
if ($id_guest AND (!$customer_name = Context::getContext()->customer->firstname . " " . Context::getContext()->customer->lastname))
$errors[] = $productCom->l('Please fill your name');
+
if (!sizeof($errors) AND $content)
{
$comment = new ProductComment();
@@ -91,6 +96,8 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
$comment->id_customer = (int)Context::getContext()->cookie->id_customer;
$comment->id_guest = (int)$id_guest;
$comment->customer_name = pSQL($customer_name);
+ if (!$comment->id_customer)
+ $comment->customer_name = pSQL($name);
$comment->title = pSQL($title);
$comment->grade = 0;
$comment->validate = 0;
diff --git a/modules/productcomments/productcomments-extra.tpl b/modules/productcomments/productcomments-extra.tpl
index 04046aa8a..1ffee6cbb 100644
--- a/modules/productcomments/productcomments-extra.tpl
+++ b/modules/productcomments/productcomments-extra.tpl
@@ -24,6 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*}
+