/**
     * Front end content builder function
     *
     * @param $ratingFormArray
     * @param $theme_key
     *
     * @return string
     */
    public static function add_ratingForm_to_content($ratingFormArray)
    {
        global $post, $wpdb, $wp_roles;
        //var_dump(CBRatingSystem::current_user_can_use_ratingsystem( $ratingFormArray['allowed_users'] ));
        $user_type = CBRatingSystem::current_user_can_use_ratingsystem($ratingFormArray['allowed_users']) ? 'registered' : 'guest';
        $post_id = isset($ratingFormArray['post_id']) && $ratingFormArray['post_id'] != '' ? $ratingFormArray['post_id'] : get_the_ID();
        $post_id = (int) $post_id;
        $post_type = get_post_type($post_id);
        $user_id = get_current_user_id();
        $user_session = $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
        //$userObject   = get_current_user();
        $user = get_current_user_id();
        $theme_key = $ratingFormArray['theme_key'];
        //var_dump($theme_key);
        $whrOpt['form_id'][] = $ratingFormArray['id'];
        $whrOpt['post_id'][] = $post_id;
        $comment_status_list = array('unverified', 'unapproved', 'approved', 'spam');
        if ($user_id == 0) {
            $userRoles = array('guest');
        } else {
            global $current_user;
            $userRoles = $current_user->roles;
        }
        $ratingFormArray['comment_moderation_users'] = is_array($ratingFormArray['comment_moderation_users']) ? $ratingFormArray['comment_moderation_users'] : array();
        $comment_status_of_user = in_array($userRoles[0], $ratingFormArray['comment_moderation_users']);
        $cb_comment_status = '';
        $cb_comment_filtered_status = apply_filters('cbratingsystem_comment_status', array('email_verify_guest' => isset($ratingFormArray['email_verify_guest']) ? $ratingFormArray['email_verify_guest'] : 0, 'comment_status_of_user' => $comment_status_of_user, 'cb_comment_status' => 'unapproved'));
        $cb_comment_status = $cb_comment_filtered_status['cb_comment_status'];
        //registered user or guest user
        if ($user_id == 0) {
            $user_session = $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
            //this is string
            $user_ip = CBRatingSystem::get_ipaddress();
        } elseif ($user_id > 0) {
            $user_session = 'user-' . $user_id;
            //this is string
            $user_ip = CBRatingSystem::get_ipaddress();
        }
        $commonElements = array_intersect($ratingFormArray['allowed_users'], $ratingFormArray['view_allowed_users']);
        $excludeElements = array_diff($ratingFormArray['view_allowed_users'], $commonElements);
        if (!empty($excludeElements)) {
            $viewrating = true;
        } else {
            $viewrating = false;
        }
        $table_name1 = CBRatingSystemData::get_user_ratings_table_name();
        $table_name2 = CBRatingSystemData::get_ratingForm_settings_table_name();
        $sql_get_loggin = "SELECT logging_method FROM {$table_name2} where id=" . $ratingFormArray['id'];
        $query_result = $wpdb->get_results($sql_get_loggin);
        $query_result2 = maybe_unserialize($query_result[0]->logging_method);
        //getting the data according to the administrative settings using IP/Cookie for the last comment
        if (in_array("cookie", $query_result2) && !in_array("ip", $query_result2)) {
            $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_session = %s", $ratingFormArray['id'], $post_id, $user_id, $user_session);
            $count = $wpdb->get_var($sql);
        } else {
            if (!in_array("cookie", $query_result2) && in_array("ip", $query_result2)) {
                $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_ip = %s", $ratingFormArray['id'], $post_id, $user_id, $user_ip);
                $count = $wpdb->get_var($sql);
            } else {
                $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_ip = %s", $ratingFormArray['id'], $post_id, $user_id, $user_ip);
                $count = $wpdb->get_var($sql);
            }
        }
        //var_dump($whrOpt);
        //get rating summary
        $avgRatingData = CBRatingSystemData::get_ratings_summary($whrOpt);
        if ($user_id == 0) {
            $isUserSubmittedRating = CBRatingSystemData::get_user_ratings_with_ratingForm(array($ratingFormArray['id']), array($post_id), array($user_id), $user_session);
        } elseif ($user_id > 0) {
            $isUserSubmittedRating = CBRatingSystemData::get_user_ratings_with_ratingForm(array($ratingFormArray['id']), array($post_id), array($user_id));
        }
        if (is_archive() and $ratingFormArray['show_on_arcv'] == 0 or is_home() && $ratingFormArray['show_on_home'] == 0 or is_single() && $ratingFormArray['show_on_single'] == 0) {
            $content = get_post_field('post_content', $post_id);
            return $content;
        }
        // var_dump(CBRatingSystem::current_user_can_use_ratingsystem( $ratingFormArray['allowed_users'] ));
        if (CBRatingSystem::current_user_can_use_ratingsystem($ratingFormArray['allowed_users']) && $ratingFormArray['show_on_single'] == 1 && in_array($post->post_type, $ratingFormArray['post_types'])) {
            if ($ratingFormArray['is_active'] == 1 && $count < 1) {
                //if(sizeof($avgRatingData) > 0) :
                if (sizeof($avgRatingData) > 0 && $avgRatingData[0]['per_post_rating_summary'] > 100) {
                    //echo "hello 1"; why 100
                    $ratingAverage = self::viewPerCriteriaRatingResult($ratingFormArray['id'], $post_id, $user_id);
                    $perPostAverageRating = $ratingAverage['perPost'][$post_id];
                    $perCriteriaAverageRating = $ratingAverage['avgPerCriteria'];
                    $customPerPostAverageRating = $ratingAverage['customUser']['perPost'];
                    $customPerCriteriaAverageRating = $ratingAverage['customUser']['perCriteria'];
                    $customPerPostRateCount = $ratingAverage['customUser']['perPostRateCount'];
                    $rating = array('form_id' => $ratingFormArray['id'], 'post_id' => $post_id, 'post_type' => $post_type, 'per_post_rating_count' => `per_post_rating_count`, 'per_post_rating_summary' => number_format($perPostAverageRating, 2), 'custom_user_rating_summary' => maybe_serialize($ratingAverage['customUser']), 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                    $return = CBRatingSystemData::update_rating_summary($rating);
                } else {
                    if (sizeof($avgRatingData) > 0) {
                        $perPostAverageRating = $avgRatingData[0]['per_post_rating_summary'];
                        $perCriteriaAverageRating = $avgRatingData[0]['per_criteria_rating_summary'];
                        $customPerPostAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perPost'];
                        $customPerCriteriaAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perCriteria'];
                        $customPerPostRateCount = $avgRatingData[0]['custom_user_rating_summary']['perPostRateCount'];
                    } else {
                        /*
                        $perPostAverageRating           = $avgRatingData[0]['per_post_rating_summary'];
                        $perCriteriaAverageRating       = $avgRatingData[0]['per_criteria_rating_summary'];
                        $customPerPostAverageRating     = $avgRatingData[0]['custom_user_rating_summary']['perPost'];
                        
                        $customPerPostRateCount         = $avgRatingData[0]['custom_user_rating_summary']['perPostRateCount'];
                        $customPerCriteriaAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perCriteria'];
                        */
                        $perPostAverageRating = 0;
                        $perCriteriaAverageRating = array();
                        $customPerPostAverageRating = array('registered' => 0, 'editor' => 0);
                        $customPerPostRateCount = array('registered' => 0, 'editor' => 0);
                        $customPerCriteriaAverageRating = array();
                    }
                }
                //end of else
                //endif;
                $nothome = 0;
                if (is_home() || is_front_page()) {
                    $nothome = 0;
                } else {
                    $nothome = 1;
                }
                $display = '<div class="cbrp_front_content y">';
                $display .= '<!--RatingForm Content-->
                        <h3 id="cbratingfrom_title" class="cbratingfrom_title" data-home="' . $nothome . '">' . __('Ratings', 'cbratingsystem') . ' </h3>
                        <div id="cbrp_container_' . $post_id . '" class="cbrp_container_' . $theme_key . '_theme cbrp-content-container cbrp-content-container-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '" data-post-id="' . $post_id . '">
                            <div class="cbrp_wrapper_' . $theme_key . '_theme cbrp-content-wprapper cbrp-content-wprapper-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '">
                                <div class="cbrp_switch_report_' . $theme_key . '_theme cbrp-switch-report cbrp-switch-report-form-' . $ratingFormArray['id'] . ' cbrp-switch-report-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" style="' . (!empty($isUserSubmittedRating) ? 'display:block;' : '') . '" data-form-id="' . $ratingFormArray['id'] . '" data-post-id="' . $post_id . '">
                                    <div class="allUser_criteria user_criteria">
                                        <div class="report-title" id="cbrp-report-title">
                                            <span style="line-height: 30px;">' . __('Current Average Ratings', 'cbratingsystem') . '</span>
                                        </div>
                                        <div class="clear" style="clear:both"></div>
                                            <div class="criteria-container">';
                if (!empty($perCriteriaAverageRating)) {
                    foreach ($perCriteriaAverageRating as $cId => $criteria) {
                        $labels = array();
                        foreach ($criteria['stars'] as $star) {
                            if ($star['title'] == '' || $star['enabled'] != 1) {
                                continue;
                            }
                            $labels[] = $star['title'];
                        }
                        $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($labels);
                        $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                        $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                        $display .= '
                                                            <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                                                <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
                                                                    <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
                                                                </div>
                                                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

                                                                </div>
                                                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
                                                                <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . ' ">
                                                                    <span>' . __('Avg', 'cbratingsystem') . ':  </span>
                                                                    <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
                                                                </div>
                                                            </div>
                                                            ';
                    }
                } else {
                    foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                        if ($firstLabelArray['label'] == '' || $firstLabelArray['enabled'] != 1) {
                            continue;
                        }
                        $labels = array();
                        foreach ($firstLabelArray['stars'] as $star) {
                            if ($star['title'] == '' || $star['enabled'] != 1) {
                                continue;
                            }
                            $labels[] = $star['title'];
                        }
                        $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($labels);
                        $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($labels));
                        $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($labels);
                        $display .= '
                                                        <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                                            <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
                                                                <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
                                                            </div>
                                                            <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
                                                            </div>
                                                            <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
                                                                <span>' . __('Avg', 'cbratingsystem') . ':</span>
                                                                <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
                                                            </div>
                                                        </div>
                                                            ';
                    }
                }
                $display .= '</div>';
                //end of <div class="criteria-container">
                $display .= '<div class="clear" style="clear:both"></div>
                                                                <div  class="rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form rating-average-label-form-' . $ratingFormArray['id'] . '" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
                                                                    <span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
                                                                    <span class="rating" itemprop="ratingValue">' . number_format($perPostAverageRating / 100 * 5, 2) . '</span> out of
																    <span itemprop="bestRating">5</span> ' . __('with', 'cbratingsystem') . '
                                                                    <span  class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count" itemprop="ratingCount">' . (!empty($avgRatingData[0]['per_post_rating_count']) ? (int) $avgRatingData[0]['per_post_rating_count'] : '0') . '</span> rating(s) </span>
                                                                </div>';
                $display .= '</div>';
                //end of  <div class="allUser_criteria user_criteria">
                if ($ratingFormArray['show_editor_rating'] == '1') {
                    if (!empty($customPerCriteriaAverageRating['editor'])) {
                        $display .= '<div class="editor_criteria user_criteria">
                                                    <div class="report-title" id="cbrp-report-title">
                                                        <span style="line-height: 30px;">' . __('Editor Avg. Rating ', 'cbratingsystem') . '</span>
                                                    </div>
                                                    <div class="clear" style="clear:both"></div>
                                                        <div class="criteria-container">';
                        foreach ($customPerCriteriaAverageRating['editor'] as $cId => $criteria) {
                            $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                            $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                            $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                            $display .= '
                                                                        <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                                                            <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
                                                                                <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
                                                                            </div>
                                                                            <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="editor-criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

                                                                            </div>
                                                                            <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
                                                                            <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '">
                                                                                <span>' . __('Avg ', 'cbratingsystem') . ': </span>
                                                                                <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
                                                                            </div>
                                                                        </div>
                                                                        ';
                        }
                        //end foreach
                    } else {
                        $display .= '<div class="editor_criteria user_criteria">
                                                     <div class="report-title" id="cbrp-report-title">
                                                         <span style="line-height: 30px;">' . __('Editors Average Rating', 'cbratingsystem') . '</span>
                                                    </div>
                                                     <div class="clear" style="clear:both"></div>

                                                     <div class="criteria-container">';
                        foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                            $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                            $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                            $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                            $display .= '
                                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                                        <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
                                                            <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
                                                        </div>
                                                        <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="editor-criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
                                                        </div>
                                                        <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
                                                            <span>' . __('Avg ', 'cbratingsystem') . ': </span>
                                                            <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
                                                        </div>
                                                    </div>
                                                        ';
                        }
                    }
                    //end of else for editor
                    $display .= '</div>';
                    //end of editor editor_criteria
                    $display .= ' <div class="clear" style="clear:both"></div>
                                                <div class="editor-rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form editor-rating-average-label-form-' . $ratingFormArray['id'] . '">
                                                     <span>' . __('Total Avg. Rating ', 'cbratingsystem') . ': </span>
                                                    <span class="rating">' . number_format($customPerPostAverageRating['editor'] / 100 * 5, 2) . '/5' . '</span>
                                                    <span class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count">' . (!empty($customPerPostRateCount['editor']) ? (int) $customPerPostRateCount['editor'] : '0') . '</span> rating(s) </span>
                                                </div>';
                    $display .= '</div>';
                    //end of editor editor_criteria_container
                }
                // end of if show editor rating
                $display .= '</div>';
                //end of <div cbrp_switch_report_
                if (empty($isUserSubmittedRating)) {
                    $display .= '
                                            <div class="cbrp-rating-buffer-form-' . $ratingFormArray['id'] . '-post-' . $post_id . ' cbrp_rating_buffer_' . $theme_key . '_theme cbrp-rating-buffer cbrp-rating-buffer-form-' . $ratingFormArray['id'] . ' cb-rating-buffer-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '">
                                                <div style="clear:both;"></div>
                                                <!--Criteria Area-->
                                                <div class="criteria_listings_' . $theme_key . '_theme criteria-listings criteria-listings-form-' . $ratingFormArray['id'] . '">';
                    if (!empty($ratingFormArray['custom_criteria'])) {
                        foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                            if ($firstLabelArray['label'] == '' || $firstLabelArray['enabled'] != 1) {
                                continue;
                            }
                            $star_labels = array();
                            foreach ($firstLabelArray['stars'] as $star) {
                                if (!$star['enabled']) {
                                    continue;
                                }
                                $star_labels[] = $star['title'];
                            }
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($star_labels);
                            $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($star_labels));
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($star_labels);
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($star_labels);
                            $display .= '
			                                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
			                                                        <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
			                                                            <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
			                                                        </div>
			                                                        <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

			                                                        </div>
			                                                        <div class="criteria_star_hint_' . $theme_key . '_theme criteria-star-hint criteria-star-hint-id-' . $firstLabel . ' criteria-star-hint-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '"></div>
			                                                    </div>';
                        }
                    }
                    //end if any enabled criteria
                    //show custom question
                    if (isset($ratingFormArray['custom_question']) && sizeof($ratingFormArray['custom_question']) > 0 && empty($isUserSubmittedRating) && $ratingFormArray['enable_question'] == 1) {
                        $display .= '<div style="clear:both;"></div>
							                                    <div class="question_box">';
                        foreach ($ratingFormArray['custom_question'] as $q_id => $q_arr) {
                            //skip question that are not enabled
                            if (!isset($q_arr['enabled']) || $q_arr['enabled'] != 1) {
                                continue;
                            }
                            if (isset($q_arr['required']) && $q_arr['required'] == 1) {
                                $requiredClass = 'required';
                                $requiredIcon = '<span class="form-required" title="' . __('Required Field', 'cbratingsystem') . '">*</span>';
                            } else {
                                $requiredClass = '';
                                $requiredIcon = '';
                            }
                            $method = 'display_' . $q_arr['field']['type'] . '_field';
                            // var_dump($method);
                            if (method_exists('CBRatingSystemFront', $method)) {
                                $fieldDisplay = self::$method($q_id, $q_arr, array('required_class' => $requiredClass, 'required_text' => $requiredIcon), $ratingFormArray);
                            } else {
                                $fieldDisplay = '';
                            }
                            //print single question
                            $display .= '<div class="item-question">';
                            $display .= $fieldDisplay;
                            $display .= '</div>';
                        }
                        //end foreach question
                        $display .= '</div>';
                    }
                    //end custom question
                    // hook here to hide name aaded 17-12 -14-@codeboxr hQ
                    $ratingreview_hide_name_html = '';
                    $display .= apply_filters('cbratingsystem_hide_current_user_name', $ratingreview_hide_name_html, $ratingFormArray, $post_id, $theme_key);
                    if ($ratingFormArray['enable_comment'] == 1 and empty($isUserSubmittedRating)) {
                        if ($ratingFormArray['comment_required'] == '1') {
                            $comment_class = '<span class="form-required" title="This field is required.">*</span>';
                            $comment_div_class = '1';
                        } else {
                            $comment_class = '';
                            $comment_div_class = '0';
                        }
                        $display .= '
                                    <div style="clear:both;"></div>
                                    <div class="cbratingsystem_comment_box">';
                        $display .= '<label class = "">' . __('Comment/Note:', 'cbratingsystem') . '</label>' . $comment_class;
                        $display .= '<textarea class="cbrating_commentarea cbrs_comment_textarea"  data-required = "' . $comment_div_class . '" name="comment[' . $ratingFormArray['id'] . ']" data-formid="' . $ratingFormArray['id'] . '" style="width:97.5%; height:50px;"></textarea>';
                        $display .= '<span class="cbrating_comment_limit_label cbrating_comment_limit_label_' . $theme_key . '_theme  cbrating_comment_limit_label_form_' . $ratingFormArray['id'] . '_post_' . $post_id . '"></span>';
                        $display .= '
                                    </div>
                                    <div style="clear:both;"></div>

                            ';
                    }
                    if ($user_id == 0) {
                        $display .= '<div class="user_info">
                                            <div class="user_name">
                                                <input id="user_name_field-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '" class="user_name_field required" type="text" name="userinfo[' . $ratingFormArray['id'] . '][name]" value="" placeholder="Your Name" required />
                                            </div>
                                            <div class="user_email">
                                                <input id="user_email_field-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '" class="user_email_field required" type="text" name="userinfo[' . $ratingFormArray['id'] . '][email]" value="" placeholder="Your Email" required />
                                            </div>
                                         </div>

                            ';
                    } else {
                        $display .= '<div class="user_info"></div>';
                        /*
                        $display .= '<div class="user_info">
                                        <!--input type="hidden" name="userinfo[' . $ratingFormArray['id'] . '][name]" value="' . $userObject->display_name . '" /-->
                                        <!--input type="hidden" name="userinfo[' . $ratingFormArray['id'] . '][email]" value="' . $userObject->email . '" /-->
                                    </div>
                        ';
                        */
                    }
                    $buddypress_post = isset($ratingFormArray['buddypress_post']) ? $ratingFormArray['buddypress_post'] : 0;
                    $user_hash = '';
                    $display .= '
                                    <div style="clear:both;"></div>
                                    </div>
                                    <div style="clear:both;"></div>
                                    <div class="submit_button_wrapper">
                                        <button class="button cbrp-button cbrp-button-form-' . $ratingFormArray['id'] . '" data-hash = "' . $user_hash . '"  data-buddypress-post = "' . $buddypress_post . '" data-comment-status ="' . $cb_comment_status . '" id="submit-rating" type="submit" name="op" value=""><span id="cbrp-button-label">' . __('Submit', 'cbratingsystem') . '</span></button>
                                        <div style="display:none;" class="cbrp_load_more_waiting_icon cbrp_load_more_waiting_icon_form-' . $ratingFormArray['id'] . '_post-' . $post_id . '"><img alt="' . __('Loading', 'cbratingsystem') . '" src="' . CB_RATINGSYSTEM_PLUGIN_DIR_URL . 'images/ajax-loader.gif" /></div>
                                    </div>
                                    <div style="clear:both;"></div>
                                    </div>
                                    <div id="cbrp-report" data-show-div="cbrp-switch-report-form-' . $ratingFormArray['id'] . '" class="cbratingsystem-tabswitch cbrp-rating-buffer cbrp-rating-buffer-form-' . $ratingFormArray['id'] . ' cbrp-rating-buffer-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-post-id ="' . $post_id . '">' . __('View Average', 'cbratingsystem') . '</div>
                                    <div id="cbrp-form" data-show-div="cbrp-rating-buffer-form-' . $ratingFormArray['id'] . '" class="cbratingsystem-tabswitch cbrp-switch-report cbrp-switch-report-form-' . $ratingFormArray['id'] . ' cbrp-switch-report-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-post-id ="' . $post_id . '">' . __('Rate this', 'cbratingsystem') . '</div>
                                    <div id="status" class="ratingFormStatus ratingFormStatus-form-' . $ratingFormArray['id'] . '"></div>

                                 ';
                }
                $display .= '</div>';
                //end of <div cbrp_wrapper_
                $display .= '

                            <input type="hidden" name="rp_id" value="' . $ratingFormArray['id'] . '-' . $post_id . '" />
                            <input type="hidden" id="cb_ratingForm_front_form_nonce_field" value="' . wp_create_nonce('cb_ratingForm_front_form_nonce_field') . '" />
                            <input type="hidden" name="formId" value="ratingForm" />
                        ';
                $jsSettings = self::front_end_js_settings($ratingFormArray, $cCriteria, $post_id);
                $display .= '<script type="text/javascript">' . $jsSettings . '</script>';
                //show credit to codeboxr
                if ($ratingFormArray['show_credit_to_codeboxr'] == '1') {
                    $cbrating_credit_msg = __('Rating System by codeboxr', 'cbratingsystem');
                    $credit = '<span class ="codeboxr_rating_credit"><a rel="external" href="http://codeboxr.com" target="_blank">' . $cbrating_credit_msg . '</a></span>';
                    $display .= apply_filters('cbratingsystem_codeboxr_credit', $credit);
                }
                $display .= '</div>';
                //end of <div cbrp_container_
                $display .= '</div>';
                //end of <div class="cbrp_front_content">
                $content = $display;
                self::viewPerCriteriaRatingResult($ratingFormArray, $post_id, $user_id);
                return $content;
            } else {
                // already given a rating
                if (CBRatingSystem::current_user_can_use_ratingsystem($ratingFormArray['allowed_users']) && $ratingFormArray['show_on_single'] == 1 && in_array($post->post_type, $ratingFormArray['post_types'])) {
                    if ($avgRatingData[0]['per_post_rating_summary'] > 100) {
                        $ratingAverage = self::viewPerCriteriaRatingResult($ratingFormArray['id'], $post_id, $user_id);
                        $perPostAverageRating = $ratingAverage['perPost'][$post_id];
                        $perCriteriaAverageRating = $ratingAverage['avgPerCriteria'];
                        $customPerPostAverageRating = $ratingAverage['customUser']['perPost'];
                        $customPerCriteriaAverageRating = $ratingAverage['customUser']['perCriteria'];
                        $customPerPostRateCount = $ratingAverage['customUser']['perPostRateCount'];
                        $rating = array('form_id' => $ratingFormArray['id'], 'post_id' => $post_id, 'post_type' => $post_type, 'per_post_rating_count' => `per_post_rating_count`, 'per_post_rating_summary' => number_format($perPostAverageRating, 2), 'custom_user_rating_summary' => maybe_serialize($ratingAverage['customUser']), 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                        $return = CBRatingSystemData::update_rating_summary($rating);
                    } else {
                        //var_dump('hi there');
                        $perPostAverageRating = $avgRatingData[0]['per_post_rating_summary'];
                        $perCriteriaAverageRating = $avgRatingData[0]['per_criteria_rating_summary'];
                        $customPerPostAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perPost'];
                        $customPerCriteriaAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perCriteria'];
                        $customPerPostRateCount = $avgRatingData[0]['custom_user_rating_summary']['perPostRateCount'];
                        $perCriteriaAverageRating = maybe_unserialize($perCriteriaAverageRating);
                    }
                    $display = '<div class="cbrp_front_content a">';
                    $display .= '<!--RatingForm Content-->
                    <h3 id="cbratingfrom_title" class="cbratingfrom_title"> ' . __('Ratings', 'cbratingsystem') . '</h3>
                    <div id="cbrp_container_' . $post_id . '" class="cbrp_container_' . $theme_key . '_theme cbrp-content-container cbrp-content-container-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '" data-post-id="' . $post_id . '"  data-count= "' . $count . '" style="display:bock;">
                        <div class="cbrp_wrapper_' . $theme_key . '_theme cbrp-content-wprapper cbrp-content-wprapper-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '">
                            <div class="cbrp_switch_report_' . $theme_key . '_theme cbrp-switch-report cbrp-switch-report-form-' . $ratingFormArray['id'] . '" style="' . (!empty($isUserSubmittedRating) ? 'display:block;' : '') . '" data-form-id="' . $ratingFormArray['id'] . '">
                                <div class="allUser_criteria user_criteria">
                                    <div class="report-title" id="cbrp-report-title">
                                        <span style="line-height: 30px;">' . __('Current Average Ratings', 'cbratingsystem') . '</span>
                                    </div>
                                    <div class="clear" style="clear:both"></div>

                                        <div class="criteria-container">';
                    if (!empty($perCriteriaAverageRating)) {
                        //	                                        if(is_serialized($perCriteriaAverageRating)  === FALSE && !is_array($perCriteriaAverageRating)){
                        //		                                        $perCriteriaAverageRating = json_decode($perCriteriaAverageRating);
                        //	                                        }
                        //	                                        else{
                        //		                                        $perCriteriaAverageRating = maybe_unserialize($perCriteriaAverageRating);
                        //	                                        }
                        foreach ($perCriteriaAverageRating as $cId => $criteria) {
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                            $display .= '
					                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
					                                    <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
					                                        <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
					                                    </div>
					                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper"></div>
					                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
					                                    <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '">
					                                        <span>' . __('Avg', 'cbratingsystem') . ': </span>
					                                        <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
					                                    </div>
					                                </div>
					                                ';
                        }
                    } else {
                        foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                            $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                            $display .= '
				                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
				                                    <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
				                                        <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], cbratingsystem) . '</span>
				                                    </div>
				                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
				                                        <!--input data-label-id="' . $firstLabel . '" class="criteria-star criteria-star-label-id-' . $firstLabel . '-currentScore" type="hidden" id="criteria-star" name="criteria[' . $firstLabel . '][value]" value="" /-->
				                                    </div>
				                                    <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
				                                        <span>' . __('Avg', 'cbratingsystem') . ': </span>
				                                        <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
				                                    </div>
				                                </div>
				                                    ';
                        }
                    }
                    $display .= '</div>';
                    // end of criteria-container
                    $display .= '<div class="clear" style="clear:both"></div>
			                                <div class="rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form rating-average-label-form-' . $ratingFormArray['id'] . '" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
			                                    <span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
                                                <span class="rating" itemprop="ratingValue">' . number_format($perPostAverageRating / 100 * 5, 2) . '</span> out of
											    <span itemprop="bestRating">5</span> ' . __('with', 'cbratingsystem') . '
                                                <span  class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count" itemprop="ratingCount">' . (!empty($avgRatingData[0]['per_post_rating_count']) ? (int) $avgRatingData[0]['per_post_rating_count'] : '0') . '</span> rating(s) </span>
			                                    <!--span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
			                                    <span class="rating">' . number_format($perPostAverageRating / 100 * 5, 2) . '/5' . '</span>
			                                    <span class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count">' . (!empty($avgRatingData[0]['per_post_rating_count']) ? (int) $avgRatingData[0]['per_post_rating_count'] : '0') . '</span> rating(s) </span-->
			                                </div>';
                    $display .= '</div>';
                    //end of allUser_criteria user_criteria
                    if ($ratingFormArray['show_editor_rating'] == '1') {
                        if (!empty($customPerCriteriaAverageRating['editor'])) {
                            $display .= '<div class="editor_criteria user_criteria">
				                                <div class="report-title" id="cbrp-report-title">
				                                    <span style="line-height: 30px;">' . __('Editors Average Rating', 'cbratingsystem') . '</span>
				                                </div>
				                                <div class="clear" style="clear:both"></div>

				                                  <div class="criteria-container">';
                            foreach ($customPerCriteriaAverageRating['editor'] as $cId => $criteria) {
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                                $display .= '
							                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
							                                    <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
							                                        <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
							                                    </div>
							                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="editor-criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

							                                    </div>
							                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
							                                    <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '"-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '">
							                                        <span>' . __('Avg', 'cbratingsystem') . ': </span>
							                                        <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
							                                    </div>
							                                </div>
							                                ';
                            }
                        } else {
                            $display .= '<div class="editor_criteria user_criteria">
				                               <div class="report-title" id="cbrp-report-title">
				                                    <span style="line-height: 30px;">' . __('Editors Average Rating', 'cbratingsystem') . '</span>
				                                </div>
				                                <div class="clear" style="clear:both"></div>

				                                    <div class="criteria-container">';
                            foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                                $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                                $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                                $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                                $display .= '
							                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
							                                    <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
							                                        <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
							                                    </div>
							                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="editor-criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

							                                    </div>
							                                    <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '"-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
							                                        <span>' . __('Avg', 'cbratingsystem') . ': </span>
							                                        <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
							                                    </div>
							                                </div>
							                                    ';
                            }
                        }
                        $display .= ' </div>';
                        //end of editor critaria_container
                        //editor rating
                        $display .= '

				                                <div class="clear" style="clear:both"></div>
				                                <div class="editor-rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form editor-rating-average-label-form-' . $ratingFormArray['id'] . '"  >
				                                    <span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
				                                    <span class="rating">' . number_format($customPerPostAverageRating['editor'] / 100 * 5, 2) . '/5' . '</span>
				                                    <span class="total_rates"> ' . __('based on', 'cbratingsystem') . '<span class="total_rates_count">' . (!empty($customPerPostRateCount['editor']) ? (int) $customPerPostRateCount['editor'] : '0') . '</span> rating(s) </span>
				                                </div>';
                        $display .= ' </div>';
                        //end of editor critaria_
                    }
                    // end of if show editor rating part
                    $display .= '</div>';
                    // end of cbrp_switch_report
                    if (empty($isUserSubmittedRating)) {
                        $display .= '
		                            <div class="cbrp_rating_buffer_' . $theme_key . '_theme cbrp-rating-buffer cbrp-rating-buffer-form-' . $ratingFormArray['id'] . '">
		                                <div style="clear:both;"></div>
		                                <!--Criteria Area-->
		                                <div class="criteria_listings_' . $theme_key . '_theme criteria-listings criteria-listings-form-' . $ratingFormArray['id'] . '">';
                        if (!empty($ratingFormArray['custom_criteria'])) {
                            foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                                $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                                $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                                $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                                $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                                $display .= '
		                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
		                                        <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
		                                            <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
		                                        </div>
		                                        <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">

		                                        </div>
		                                        <div class="criteria_star_hint_' . $theme_key . '_theme criteria-star-hint criteria-star-hint-id-' . $firstLabel . ' criteria-star-hint-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '"></div>
		                                    </div>
		                                    ';
                            }
                        }
                        if (!empty($ratingFormArray['custom_question']['enabled']) and empty($isUserSubmittedRating) and $ratingFormArray['enable_question'] == 1) {
                            $display .= '
		                                <div style="clear:both;"></div>
		                                <div class="question_box">
		                                    ';
                            foreach ($ratingFormArray['custom_question']['enabled'] as $q_id => $q_arr) {
                                if (!empty($ratingFormArray['custom_question']['required'])) {
                                    if (in_array($q_id, $ratingFormArray['custom_question']['required'])) {
                                        $requiredClass = 'required';
                                        $requiredIcon = '<span class="form-required" title="This field is required.">*</span>';
                                    } else {
                                        $requiredClass = '';
                                        $requiredIcon = '';
                                    }
                                }
                                $method = 'display_' . $q_arr['field']['type'] . '_field';
                                if (method_exists('CBRatingSystemFront', $method)) {
                                    $fieldDisplay = self::$method($q_id, $q_arr, array('required_class' => $requiredClass, 'required_text' => $requiredIcon), $ratingFormArray);
                                } else {
                                    $fieldDisplay = '';
                                }
                                $display .= '<div class="item-question">';
                                $display .= $fieldDisplay;
                                $display .= '</div>';
                            }
                            $display .= '
		                                </div>
		                        ';
                        }
                        $display .= ' <div style="clear:both;"></div></div>';
                        //end of rating_buffer
                        $display .= '<div style="clear:both;"></div></div>
								<div id="status" class="ratingFormStatus ratingFormStatus-form-' . $ratingFormArray['id'] . '"></div>';
                        //end of criteria_listing
                    }
                    //end if user submitted rating
                    $display .= '</div>';
                    //end of cbrp_wrapper
                    $display .= '
                        <input type="hidden" name="rp_id" value="' . $ratingFormArray['id'] . '-' . $post_id . '" />
                        <input type="hidden" id="cb_ratingForm_front_form_nonce_field" value="' . wp_create_nonce('cb_ratingForm_front_form_nonce_field') . '" />
                        <input type="hidden" name="formId" value="ratingForm" />
                   ';
                    if ($ratingFormArray['show_credit_to_codeboxr'] == '1') {
                        //$cbrating_credit_msg  = __('Rating System by codeboxr','cbratingsystem');
                        //$display        .= '<span class ="codeboxr_rating_credit">'.apply_filters('cbratingsystem_codeboxr_credit',$cbrating_credit_msg).'</span>';
                        $cbrating_credit_msg = __('Rating System by Codeboxr', 'cbratingsystem');
                        $credit = '<span class ="codeboxr_rating_credit"><a rel="external follow" href="http://codeboxr.com" target="_blank">' . $cbrating_credit_msg . '</a></span>';
                        $display .= apply_filters('cbratingsystem_codeboxr_credit', $credit);
                    }
                    $display .= '</div>';
                    //end of cbrp_container
                    if (!isset($cCriteria)) {
                        $cCriteria = array();
                    }
                    $jsSettings = self::front_end_js_settings($ratingFormArray, $cCriteria, $post_id);
                    $display .= '<script type="text/javascript">' . $jsSettings . '</script>';
                    $display .= '</div><!--test-->';
                    //end of cbrp_front_content
                    $content = $display;
                    self::viewPerCriteriaRatingResult($ratingFormArray, $post_id, $user_id);
                    return $content;
                }
                //end of if allowed user
            }
            //end of already given a rating
        } else {
            if ($viewrating) {
                $current_user = get_userdata(get_current_user_id());
                //var_dump($current_user);
                if ($current_user === FALSE) {
                    $current_user = new stdClass();
                }
                //var_dump($excludeElements);
                $current_user_roles = isset($current_user->roles) ? $current_user->roles : NULL;
                if ($current_user_roles == NULL || !is_array($current_user_roles)) {
                    //means guest
                    $current_user_roles = array();
                    $current_user->ID = 0;
                }
                $has_cap = array_intersect($current_user_roles, $excludeElements);
                if ($current_user->ID == 0 && in_array('guest', $excludeElements)) {
                    $testfinalview = true;
                } elseif (is_array($has_cap) && !empty($has_cap)) {
                    //var_dump($excludeElements);
                    $testfinalview = true;
                } else {
                    $testfinalview = false;
                }
                //var_dump($testfinalview);
                if ($ratingFormArray['is_active'] == 1 && $testfinalview == true && in_array($post->post_type, $ratingFormArray['post_types'])) {
                    if (isset($avgRatingData[0]['per_post_rating_summary']) && $avgRatingData[0]['per_post_rating_summary'] > 100) {
                        $ratingAverage = self::viewPerCriteriaRatingResult($ratingFormArray['id'], $post_id, $user_id);
                        $perPostAverageRating = $ratingAverage['perPost'][$post_id];
                        $perCriteriaAverageRating = $ratingAverage['avgPerCriteria'];
                        $customPerPostAverageRating = $ratingAverage['customUser']['perPost'];
                        $customPerCriteriaAverageRating = $ratingAverage['customUser']['perCriteria'];
                        $customPerPostRateCount = $ratingAverage['customUser']['perPostRateCount'];
                        $rating = array('form_id' => $ratingFormArray['id'], 'post_id' => $post_id, 'post_type' => $post_type, 'per_post_rating_count' => `per_post_rating_count`, 'per_post_rating_summary' => number_format($perPostAverageRating, 2), 'custom_user_rating_summary' => maybe_serialize($ratingAverage['customUser']), 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                        $return = CBRatingSystemData::update_rating_summary($rating);
                    } else {
                        $perPostAverageRating = $avgRatingData[0]['per_post_rating_summary'];
                        $perCriteriaAverageRating = $avgRatingData[0]['per_criteria_rating_summary'];
                        $customPerPostAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perPost'];
                        $customPerCriteriaAverageRating = $avgRatingData[0]['custom_user_rating_summary']['perCriteria'];
                        $customPerPostRateCount = $avgRatingData[0]['custom_user_rating_summary']['perPostRateCount'];
                    }
                    if (!is_home()) {
                        $nothome = 1;
                    }
                    $display = '<div class="cbrp_front_content x">';
                    $display .= '<!--RatingForm Content-->
                    <h3 id="cbratingfrom_title" class="cbratingfrom_title" data-home="' . $nothome . '">' . __('Rating', 'cbratingsystem') . ' </h3>
                    <div id="cbrp_container_' . $post_id . '" class="cbrp_container_' . $theme_key . '_theme cbrp-content-container cbrp-content-container-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '" data-post-id="' . $post_id . '">
                        <div class="cbrp_wrapper_' . $theme_key . '_theme cbrp-content-wprapper cbrp-content-wprapper-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" data-form-id="' . $ratingFormArray['id'] . '">
                            <div class="show_cbrp_switch_report_' . $theme_key . '_theme all_cbrp-switch-report cbrp-switch-report-form-' . $ratingFormArray['id'] . ' all_cbrp-switch-report-form-' . $ratingFormArray['id'] . '-post-' . $post_id . '" style="' . (!empty($isUserSubmittedRating) ? 'display:block;' : '') . '" data-form-id="' . $ratingFormArray['id'] . '" data-post-id="' . $post_id . '">
                                <div class="User_criteria user_criteria">
                                    <div class="report-title" id="cbrp-report-title">
                                        <span style="line-height: 30px;">' . __('Current Average Ratings', 'cbratingsystem') . '</span>
                                    </div>
                                    <div class="clear" style="clear:both"></div>

                                        <div class="criteria-container">
                ';
                    if (!empty($perCriteriaAverageRating)) {
                        foreach ($perCriteriaAverageRating as $cId => $criteria) {
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                            $cCriteria['readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                            $display .= '
                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                    <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
                                        <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
                                    </div>
                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
                                        <!--input data-label-id="' . $cId . '" class="criteria-star criteria-star-label-id-' . $cId . '-currentScore" type="hidden" id="criteria-star" name="criteria[' . $cId . '][value]" value="" /-->
                                    </div>
                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
                                     
                                    <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . ' ">
                                        <span>' . __('Avg', 'cbratingsystem') . ':  </span>
                                        <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
                                    </div>
                                </div>
                                ';
                        }
                    } else {
                        foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                            $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                            $cCriteria['criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                            $display .= '
                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
                                    <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
                                        <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
                                    </div>
                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
                                        <!--input data-label-id="' . $firstLabel . '" class="criteria-star criteria-star-label-id-' . $firstLabel . '-currentScore" type="hidden" id="criteria-star" name="criteria[' . $firstLabel . '][value]" value="" /-->
                                   		
                                    </div>
                                    <div class="criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
                                        <span>' . __('Avg', 'cbratingsystem') . ': </span>
                                        <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
                                    </div>
                                </div>
                                    ';
                        }
                    }
                    $display .= '</div><div class="clear" style="clear:both"></div>
                                <div class="rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form rating-average-label-form-' . $ratingFormArray['id'] . '"  itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
                                    <!--span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
                                    <span class="rating">' . number_format($perPostAverageRating / 100 * 5, 2) . '/5' . '</span>
                                    <span class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count">' . (!empty($avgRatingData[0]['per_post_rating_count']) ? (int) $avgRatingData[0]['per_post_rating_count'] : '0') . '</span> rating(s) </span-->
                                    <span>' . __('Total Avg Rating', 'cbratingsystem') . ': </span>
                                    <span class="rating" itemprop="ratingValue">' . number_format($perPostAverageRating / 100 * 5, 2) . '</span> out of
								    <span itemprop="bestRating">5</span> ' . __('with', 'cbratingsystem') . '
                                    <span  class="total_rates">  ' . __('based on', 'cbratingsystem') . ' <span class="total_rates_count" itemprop="ratingCount">' . (!empty($avgRatingData[0]['per_post_rating_count']) ? (int) $avgRatingData[0]['per_post_rating_count'] : '0') . '</span> rating(s) </span>
                                </div></div>';
                    //for editor
                    if ($ratingFormArray['show_editor_rating'] == '1') {
                        if (!empty($customPerCriteriaAverageRating['editor'])) {
                            $display .= '<div class="editor_criteria user_criteria">
                        		<div class="report-title" id="cbrp-report-title">
                                    <span style="line-height: 30px;">' . __('Editor Ave Rating ', 'cbratingsystem') . '</span>
                                </div>
                                <div class="clear" style="clear:both"></div>
                                
                                    <div class="criteria-container">';
                            foreach ($customPerCriteriaAverageRating['editor'] as $cId => $criteria) {
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                                $cCriteria['editor-readonly-criteria-label-' . $ratingFormArray['id'] . '-post-' . $post_id . '-avgvalue'] = $perPostAverageRating;
                                $display .= '
				                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="readonly_criteria_wrapper_' . $theme_key . '_theme readonly-criteria-wrapper readonly-criteria-id-wrapper-' . $cId . ' readonly-criteria-wrapper-form-' . $ratingFormArray['id'] . '">
				                                    <div class="readonly_criteria_label_wrapper_' . $theme_key . '_theme readonly-criteria-label-wrapper readonly-criteria-label-wrapper-form-' . $ratingFormArray['id'] . '" data-form-id="' . $ratingFormArray['id'] . '">
				                                        <span class="readonly-criteria-label criteria-label-form-' . $ratingFormArray['id'] . ' readonly-criteria-label-id-' . $cId . '" >' . __($ratingFormArray['custom_criteria'][$cId]['label'], 'cbratingsystem') . '</span>
				                                    </div>
				                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="editor-criteria-star-wrapper readonly-criteria-star-wrapper-id-' . $cId . '-form-' . $ratingFormArray['id'] . ' readonly-criteria-star-wrapper-id-' . $cId . ' criteria-star-wrapper-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
				                                        <!--input data-label-id="' . $cId . '" class="criteria-star criteria-star-label-id-' . $cId . '-currentScore" type="hidden" id="criteria-star" name="criteria[' . $cId . '][value]" value="" /-->
				                                    </div>
				                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $cId . '" class="criteria-star-hint readonly-criteria-star-hint-form-' . $ratingFormArray['id'] . '-id-' . $cId . ' criteria-star-hint-id-' . $cId . '"></div>
				                                    <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $cId . '">
				                                        <span>' . __('Avg ', 'cbratingsystem') . ': </span>
				                                        <span class="rating">' . number_format($criteria['value'] / 100 * count($ratingFormArray['custom_criteria'][$cId]['stars']), 2) . '/' . count($ratingFormArray['custom_criteria'][$cId]['stars']) . '</span>
				                                    </div>
				                                </div>
				                                ';
                            }
                        } else {
                            $display .= '<div class="editor_criteria user_criteria">
                                 <div class="report-title" id="cbrp-report-title">
                                    <span style="line-height: 30px;">' . __('Editors Average Rating', 'cbratingsystem') . '</span>
                                </div>
                                <div class="clear" style="clear:both"></div>
                                
                                    <div class="criteria-container">';
                            foreach ($ratingFormArray['custom_criteria'] as $firstLabel => $firstLabelArray) {
                                $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel] = array_values($firstLabelArray['stars']);
                                $cCriteria['criteria-stars-' . $firstLabel] = json_encode(array_values($firstLabelArray['stars']));
                                $cCriteria['editor-criteria-label-' . $ratingFormArray['id'] . '-stars-' . $firstLabel . '-count'] = count($firstLabelArray['stars']);
                                $display .= '
				                                <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="criteria_wrapper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $firstLabel . ' criteria-id-wrapper-' . $firstLabel . '-form-' . $ratingFormArray['id'] . ' criteria-wrapper-form-' . $ratingFormArray['id'] . '">
				                                    <div class="criteria_label_wrapper_' . $theme_key . '_theme criteria-label-wrapper">
				                                        <span class="criteria-label criteria-label-id-' . $firstLabel . '" >' . __($firstLabelArray['label'], 'cbratingsystem') . '</span>
				                                    </div>
				                                    <div data-form-id="' . $ratingFormArray['id'] . '" data-label-id="' . $firstLabel . '" class="editor-criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $firstLabel . '-form-' . $ratingFormArray['id'] . '" id="criteria-star-wrapper">
				                                        <!--input data-label-id="' . $firstLabel . '" class="criteria-star criteria-star-label-id-' . $firstLabel . '-currentScore" type="hidden" id="criteria-star" name="criteria[' . $firstLabel . '][value]" value="" /-->
				                                    </div>
				                                    <div class="editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '-postid-' . $post_id . ' readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label editor-criteria-average-label-form-' . $ratingFormArray['id'] . '-label-' . $firstLabel . '">
				                                        
				                                        <span>' . __('Avg ', 'cbratingsystem') . ': </span>
				                                        <span class="rating">0/' . count($firstLabelArray['stars']) . '</span>
				                                    </div>
				                                </div>
				                                    ';
                            }
                        }
                        //editor rating
                        $display .= '
                           
                                <div class="clear" style="clear:both"></div>
                                <div class="editor-rating-average-label-form-' . $ratingFormArray['id'] . '-postid-' . $post_id . ' readonly_criteria_average_label_form_' . $theme_key . '_theme readonly-criteria-average-label-form editor-rating-average-label-form-' . $ratingFormArray['id'] . '"  itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
                                    <span>' . __('Total Avg Rating ', 'cbratingsystem') . ': </span>
                                    <span class="rating">' . number_format($customPerPostAverageRating['editor'] / 100 * 5, 2) . '/5' . '</span>
                                    <span class="total_rates">  ' . __('basedon', 'cbratingsystem') . ' <span class="total_rates_count">' . (!empty($customPerPostRateCount['editor']) ? (int) $customPerPostRateCount['editor'] : '0') . '</span> rating(s) </span>

                                </div>
                                </div>                                
                            </div>
                        ';
                        $display .= '                      
                    </div>';
                    }
                    $jsSettings = self::front_end_js_settings($ratingFormArray, $cCriteria, $post_id);
                    $display .= '<script type="text/javascript">' . $jsSettings . '</script>';
                    if ($ratingFormArray['show_credit_to_codeboxr'] == '1') {
                        //$cbrating_credit_msg  = __('Rating System by codeboxr','cbratingsystem');
                        //$display        .= '<span class ="codeboxr_rating_credit" style = "font-size:xx-small!important;float: right;">'.apply_filters('cbratingsystem_codeboxr_credit',$cbrating_credit_msg).'</span>';
                        $cbrating_credit_msg = __('Rating System by codeboxr', 'cbratingsystem');
                        $credit = '<span class ="codeboxr_rating_credit"><a rel="external" href="http://codeboxr.com" target="_blank">' . $cbrating_credit_msg . '</a></span>';
                        $display .= apply_filters('cbratingsystem_codeboxr_credit', $credit);
                    }
                    $display .= '</div>';
                    $display .= '</div>';
                    $display .= '</div>';
                    $display .= '</div>';
                    $content = $display;
                    //var_dump('i am here agaon man');
                    self::viewPerCriteriaRatingResult($ratingFormArray, $post_id, $user_id);
                    if ($current_user->ID == 0) {
                        $cb_log_in_link = '<a href=" ' . wp_login_url(get_permalink()) . '" title="' . __('Login', 'cbratingsystem') . '">' . __('login', 'cbratingsystem') . '</a>';
                        $content .= '<p>' . sprintf(__('Please %s to rate', 'cbratingsystem'), $cb_log_in_link) . '</p>';
                    } else {
                        $content .= '<p>' . __('You are not allowed to rate.', 'cbratingsystem') . '</p>';
                    }
                    return $content;
                }
                //end of if viewrating true
            }
        }
    }
 function getRatingAverageWithCustomCondition()
 {
     CBRatingSystemData::get_user_ratings_with_ratingForm();
 }