function cw_review_add_new_review_manual($review_new, $product_id) { global $tables; if (!empty($review_new['message'])) { $review_new['product_id'] = $product_id; $review_new['testimonials'] = $review_new['addto'] == 'testimonials' ? 1 : 0; $review_new['stoplist'] = $review_new['addto'] == 'stoplist' ? 1 : 0; unset($review_new['addto']); $review_new['ctime'] = time(); $inserted_id = cw_array2insert("products_reviews", $review_new); if (!empty($review_new['vote'])) { $vote_new = array(); $vote_new['product_id'] = $product_id; $vote_new['vote_value'] = $review_new['vote']; $vote_new['customer_id'] = 0; $vote_new['remote_ip'] = ""; $vote_new['review_id'] = $inserted_id; cw_array2insert("products_votes", $vote_new); cw_review_recalculate_avg_rating($product_id); } if ($product_id) { $attribute_value_id = cw_query_first_cell("SELECT ad.attribute_value_id\n FROM {$tables['attributes_default']} ad\n LEFT JOIN {$tables['attributes']} a ON a.attribute_id = ad.attribute_id\n WHERE a.field = 'has_review' AND a.addon = 'estore_products_review'"); cw_func_call('cw_attributes_save_attribute', array('item_id' => $product_id, 'item_type' => 'P', 'attributes' => array('has_review' => $attribute_value_id))); } } return $inserted_id; }
$review_new['email'] = $user_account['email']; $review_id = cw_call('cw_review_add_new_review_manual', array($review_new, 0)); } if (!empty($review_id)) { $review_data = cw_query_first("SELECT * FROM {$tables['products_reviews']} WHERE review_id='{$review_id}'"); foreach ($rating as $attr_id => $vote) { // update vote value $exists = cw_query_first_cell("SELECT vote_id FROM {$tables['products_votes']} WHERE review_id = '{$review_id}' AND attribute_id ='{$attr_id}'"); if ($exists) { cw_array2update('products_votes', array('vote_value' => $vote), "review_id = '{$review_id}' AND attribute_id ='{$attr_id}'"); } else { cw_array2insert('products_votes', array('remote_ip' => $review_data['remote_ip'], 'vote_value' => $vote, 'product_id' => $review_data['product_id'], 'customer_id' => $review_data['customer_id'], 'review_id' => $review_id, 'attribute_id' => $attr_id)); } cw_review_recalculate_avg_rating($review_data['product_id'], $attr_id); } cw_review_recalculate_avg_rating($review_data['product_id']); cw_add_top_message(cw_get_langvar_by_name('txt_thank_you_for_review')); } else { cw_add_top_message(cw_get_langvar_by_name('err_filling_form'), 'E'); } cw_header_location("index.php?target=global_reviews"); } $items_per_page_targets[$target] = 10; $total_items = cw_call('cw_review_get_global_review', array()); $navigation = cw_core_get_navigation($target, $total_items, $page); $global_reviews = cw_call('cw_review_get_global_review', array('', '', " ORDER BY {$tables['products_reviews']}.ctime DESC ", "LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}", FALSE)); $items_per_page_targets[$target] = PHP_INT_MAX; $navigation['script'] = 'index.php?target=' . $target; $smarty->assign('navigation', $navigation); if (!empty($global_reviews)) { $rating_cond = "type='global_rating'";
$review_store_place['author'] = $review_author; $review_store_place['main_title'] = $review_main_title; $review_store_place['message'] = $review_message; $review_store_place['antibot_err'] = true; $review_store_place['error'] = true; cw_header_location($return_url); } // Create a new review $review_id = cw_array2insert('products_reviews', array('remote_ip' => $user_ip, 'email' => $review_author, 'main_title' => $review_main_title, 'message' => $review_message, 'product_id' => $product_id, 'customer_id' => $_customer_id, 'status' => $config['estore_products_review']['status_created_reviews'], 'ctime' => time())); // Create votes if ($config['estore_products_review']['customer_voting'] == 'Y' && !empty($rating)) { foreach ($rating as $attribute_id => $vote) { cw_array2insert('products_votes', array('remote_ip' => $user_ip, 'vote_value' => $vote, 'product_id' => $product_id, 'customer_id' => $_customer_id, 'attribute_id' => $attribute_id, 'review_id' => $review_id)); cw_review_recalculate_avg_rating($product_id, $attribute_id); } cw_review_recalculate_avg_rating($product_id, 0); } // Update attribute 'has_review' // has_review has dropdown type with single option "Yes" to avoid // useless option "No" in product filter when we use "yes_no" type $attribute_value_id = cw_query_first_cell("SELECT ad.attribute_value_id\n\t\tFROM {$tables['attributes_default']} ad\n\t\tINNER JOIN {$tables['attributes']} a ON a.attribute_id = ad.attribute_id\n\t\tWHERE a.field = 'has_review' AND a.addon = 'estore_products_review'"); cw_func_call('cw_attributes_save_attribute', array('item_id' => $product_id, 'item_type' => 'P', 'attributes' => array('has_review' => $attribute_value_id))); cw_add_top_message(cw_get_langvar_by_name('txt_thank_you_for_review')); cw_header_location($return_url); } $vote_result = cw_query_first("\n SELECT COUNT(v.remote_ip) AS total, AVG(v.vote_value) AS rating\n FROM {$tables['products_votes']} v\n LEFT JOIN {$tables['products_reviews']} r ON r.review_id = v.review_id\n WHERE v.product_id='{$product_id}' AND IF(v.review_id = 0, 1, r.status) = 1 \n"); if ($vote_result['total'] == 0) { $vote_result['rating'] = 0; } $vote_result['rating'] = price_format($vote_result['rating']); $smarty->assign('vote_result', $vote_result);