/** ************************************************************************
     * Optional. You can handle your bulk actions anywhere or anyhow you prefer.
     * For this example package, we will handle it in the class to keep things
     * clean and organized.
     *
     * @see $this->prepare_items()
     **************************************************************************/
    function process_bulk_action()
    {
        if ('delete' === $this->current_action()) {
            if (!empty($_GET['wdcheckbox'])) {
                $avgid = $_GET['wdcheckbox'];
                global $wpdb;
                $table_name1 = CBRatingSystemData::get_user_ratings_summury_table_name();
                $table_name = CBRatingSystemData::get_user_ratings_table_name();
                foreach ($avgid as $id) {
                    $sql = $wpdb->prepare("SELECT post_id ,form_id FROM {$table_name1} WHERE id=%d ", $id);
                    $results = $wpdb->get_results($sql, ARRAY_A);
                    //echo '<pre>'; print_r($results[0]['form_id']); echo '</pre>';
                    $sql = $wpdb->prepare("DELETE FROM {$table_name} WHERE post_id=%d AND form_id=%d", $results[0]['post_id'], $results[0]['form_id']);
                    $wpdb->query($sql);
                }
                $table_name = CBRatingSystemData::get_user_ratings_summury_table_name();
                $sql = "DELETE FROM {$table_name} WHERE id IN (" . implode(',', $avgid) . ")";
                $wpdb->query($sql);
                // global $wpdb;
            }
            ?>
            <script type="text/javascript">
                jQuery(document).ready(function ($) {
                    $('#message').show();
                    $('#message').html('Successfully deleted');
                    var ids = '<?php 
            echo json_encode($avgid);
            ?>
';
                    var trainindIdArray = ids.split(',');
                    $.each(trainindIdArray, function(index, value) {
                        //alert(index + ': ' + value);   // alerts 0:[1 ,  and  1:2]
                        value = value.replace('"','');
                        value = value.replace('[','');
                        value = value.replace(']','');
                        value = value.replace('"','');
                        //console.log(value);
                        $('.cbwdchkbox-'+value).parent().parent().hide();

                    });
                    setTimeout(function() {   //calls click event after a certain time
                        $('#message').hide();
                    }, 2000);

                });

            </script>
<?php 
        }
    }
 /**
  * Ajax function for the review submission
  */
 public static function cbRatingAjaxFunction()
 {
     global $wpdb;
     $user_id = get_current_user_id();
     //returns 0 if guest
     $user_info = '';
     if (isset($_POST['cbRatingData']) && !empty($_POST['cbRatingData'])) {
         $returnedData = $_POST['cbRatingData'];
         //var_dump($returnedData);
         if (wp_verify_nonce($returnedData['cbrp_nonce'], 'cb_ratingForm_front_form_nonce_field')) {
             if (!empty($returnedData['values'])) {
                 list($insertArray['form_id'], $insertArray['post_id']) = explode('-', $returnedData['rp_id']);
                 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();
                     $user_info = get_userdata($user_id);
                 }
                 $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=" . $insertArray['form_id'];
                 //$sql_get_loggin = maybe_unserialize($sql_get_loggin[0]->logging_method);
                 $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", $insertArray['form_id'], $insertArray['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", $insertArray['form_id'], $insertArray['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", $insertArray['form_id'], $insertArray['post_id'], $user_id, $user_ip);
                         $count = $wpdb->get_var($sql);
                     }
                 }
                 if ($count < 1) {
                     // first time rating
                     $insertArray['post_type'] = get_post_type($insertArray['post_id']);
                     $insertArray['created'] = time();
                     $question = array();
                     if (!empty($returnedData['question'][$insertArray['form_id']]) && is_array($returnedData['question'][$insertArray['form_id']])) {
                         foreach ($returnedData['question'][$insertArray['form_id']] as $qID => $qValue) {
                             if (is_array($qValue) && !empty($qValue)) {
                                 foreach ($qValue as $key => $val) {
                                     $type = $qValue[$qID . '_type'];
                                     if (isset($qValue[$type . '-' . $qID]) && !empty($qValue[$type . '-' . $qID])) {
                                         $question[$qID] = $qValue[$type . '-' . $qID];
                                     } elseif ($key != $qID . '_type' && $key != $type . '-' . $qID && !empty($val)) {
                                         $key = str_replace($qID . '_', '', $key);
                                         if (is_numeric($key)) {
                                             $question[$qID][$key] = $val;
                                         }
                                     }
                                 }
                             } else {
                                 $question[$qID] = $qValue;
                             }
                         }
                     }
                     $insertArray['question'] = maybe_serialize($question);
                     $comment = esc_html(sanitize_text_field($returnedData['comment']));
                     if (strlen($comment) <= $returnedData['comment_limit']) {
                         $insertArray['comment'] = $comment;
                     } elseif (strlen($comment) > $returnedData['comment_limit']) {
                         $insertArray['comment'] = substr($comment, 0, intval($returnedData['comment_limit']));
                     }
                     if (!is_user_logged_in()) {
                         if (!empty($returnedData['user_name'])) {
                             $insertArray['user_name'] = sanitize_text_field(trim($returnedData['user_name']));
                         } else {
                             $encoded = json_encode(array('validation' => 1, 'errorMessage' => __('Name field can\'t be left blank.', 'cbratingsystem')));
                             echo $encoded;
                             die;
                         }
                         if (!empty($returnedData['user_email']) and is_email(trim($returnedData['user_email']))) {
                             $insertArray['user_email'] = sanitize_text_field(trim($returnedData['user_email']));
                         } else {
                             $encoded = json_encode(array('validation' => 1, 'errorMessage' => __('Please enter a valid email address.', 'cbratingsystem')));
                             echo $encoded;
                             die;
                         }
                     }
                     /*else {
                                                 //guest user
                     							$insertArray['user_name']  = '';
                     							$insertArray['user_email'] = $returnedData['user_email'];
                     							$insertArray['user_ip']      = $user_ip;
                     							$insertArray['user_session'] = $user_session;
                     
                     						}*/
                     $insertArray['user_name'] = $user_id > 0 ? $user_info->user_login : $returnedData['user_name'];
                     $insertArray['user_email'] = $user_id > 0 ? $user_info->user_email : $returnedData['user_email'];
                     $insertArray['user_ip'] = $user_ip;
                     $insertArray['user_session'] = $user_session;
                     /*
                      * @example:
                      * $returnedData['values'] = array(
                      *      0 => 100          // label_id/criteria_id => ( (Score For this label / Star count) * 100)
                      * )
                      */
                     $insertArray['rating'] = maybe_serialize($returnedData['values']);
                     foreach ($returnedData['values'] as $key => $val) {
                         if (is_numeric($key)) {
                             $average[$key] = $val;
                         }
                     }
                     $hash_comment = $insertArray['user_ip'] . $insertArray['user_session'] . $insertArray['user_email'] . time();
                     $hash_comment = md5($hash_comment);
                     $insertArray['average'] = array_sum($average) / count($average);
                     //$insertArray['user_ip']      = CBRatingSystem::get_ipaddress();
                     //$insertArray['user_session'] = ( $user_id != 0 ) ? 'user-' . $user_id : $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
                     $insertArray['user_id'] = $user_id;
                     $insertArray['form_id'] = (int) $insertArray['form_id'];
                     $insertArray['post_id'] = (int) $insertArray['post_id'];
                     $insertArray['comment_status'] = $returnedData['comment_status'];
                     $insertArray['comment_hash'] = $hash_comment;
                     $insertArray['allow_user_to_hide'] = isset($returnedData["hide_this_user_name"]) ? $returnedData["hide_this_user_name"] : 0;
                     $return = CBRatingSystemData::update_rating($insertArray);
                     if ($insertArray['comment_status'] == 'unverified' && $insertArray['comment_hash'] != '' && $insertArray['user_email'] != '') {
                         $cb_subject = __('Verify Your email', 'cbratingsystem');
                         $cb_message = get_site_url() . '?cbratingemailverify=' . $insertArray['comment_hash'];
                         $from = get_option('admin_email');
                         //var_dump($from);
                         wp_mail($insertArray['user_email'], $cb_subject, $cb_message);
                         // mail($insertArray['user_email'],$cb_subject,$cb_message,"From: $from\n");
                     }
                     // buddypress post added 29-10-14 codeboxr
                     if (isset($returnedData["buddypress_post"]) && $returnedData["buddypress_post"] == '1' || is_user_logged_in()) {
                         if (function_exists('bp_is_active')) {
                             // buddy press active
                             $buddy_post = array('id' => false, 'action' => bp_core_get_userlink(bp_loggedin_user_id()) . __(' has rated this post ', 'cbratingsystem') . get_permalink($insertArray['post_id']), 'content' => $insertArray['comment'], 'component' => 'ratingcomponent', 'type' => 'ratingcomponent_activity', 'primary_link' => '', 'user_id' => bp_loggedin_user_id(), 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false, 'is_spam' => false);
                             do_action('cbratingsystem_buddypress_activity_post', $buddy_post);
                         }
                         //end checking if buddypress is installed
                     }
                     $lastcommentrt = $return;
                     // storing the last commend id for safety
                     if ($return) {
                         //getting the criteria rating result
                         $ratingAverage = self::viewPerCriteriaRatingResult($insertArray['form_id'], $insertArray['post_id'], $user_id);
                         $ratingsCount = $ratingAverage['ratingsCount'][$insertArray['form_id'] . '-' . $insertArray['post_id']];
                         if (!empty($ratingsCount)) {
                             $rating = array('form_id' => $insertArray['form_id'], 'post_id' => $insertArray['post_id'], 'post_type' => $insertArray['post_type'], 'per_post_rating_count' => $ratingsCount, 'per_post_rating_summary' => number_format($ratingAverage['perPost'][$insertArray['post_id']], 2), 'custom_user_rating_summary' => maybe_serialize($ratingAverage['customUser']), 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                             foreach ($ratingAverage['avgPerCriteria'] as $cId => $criteria) {
                                 $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($criteria['stars']);
                                 $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                             }
                             if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                                 foreach ($ratingAverage['customUser']['perCriteria']['editor'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                                 }
                             } else {
                                 foreach ($ratingAverage['avgPerCriteria'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = 0;
                                 }
                             }
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $rating['per_post_rating_summary'];
                             if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $ratingAverage['customUser']['perPost']['editor'];
                             } else {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = 0;
                             }
                             $return = CBRatingSystemData::update_rating_summary($rating);
                             $editorCount = isset($ratingAverage['customUser']['perPostRateCount']['editor']) ? (int) $ratingAverage['customUser']['perPostRateCount']['editor'] : 0;
                             //review part here
                             if (empty($ratingFormArray)) {
                                 $defaultFormId = get_option('cbratingsystem_defaultratingForm');
                                 $ratingFormId = apply_filters('rating_form_array', $defaultFormId);
                                 //getting the rating form data from here.
                                 $ratingFormArray = CBRatingSystemData::get_ratingForm($insertArray['form_id']);
                             }
                             //get the theme for doing frontend UI works
                             $theme_key = get_option('cbratingsystem_theme_key');
                             $reviewOptions['theme'] = $theme_key;
                             $reviewOptions['comment_status'] = $insertArray['comment_status'];
                             $reviewOptions["hide_this_user_name"] = isset($returnedData["hide_this_user_name"]) ? $returnedData["hide_this_user_name"] : 0;
                             $lastcomment = is_numeric($lastcommentrt) ? self::build_user_rating_review_single($reviewOptions, $ratingFormArray, $lastcommentrt) : '';
                             //echo $lastcomment;
                             if ($return) {
                                 $encoded = json_encode(array('img_path' => CB_RATINGSYSTEM_PLUGIN_DIR_IMG, 'hints' => json_encode($cCriteria), 'is_rated' => 1, 'ratingsCount' => $ratingsCount, 'editorRatingsCount' => $editorCount, 'lastcomment' => $lastcomment, 'theme_key' => $reviewOptions['theme'], 'firstcomment' => true, 'comment_status' => $insertArray['comment_status']));
                                 echo $encoded;
                             }
                         }
                     }
                 } else {
                     //at least one rating done
                     $summary = CBRatingSystemData::get_ratings_summary(array('form_id' => array($insertArray['form_id']), 'post_id' => array($insertArray['post_id'])));
                     if (!empty($summary[0])) {
                         foreach ($summary[0]['per_criteria_rating_summary'] as $cId => $criteria) {
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($criteria['stars']);
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                         }
                         if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                             foreach ($ratingAverage['customUser']['perCriteria']['editor'] as $cId => $criteria) {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                             }
                         } else {
                             if (!empty($summary[0])) {
                                 foreach ($summary[0]['per_criteria_rating_summary'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = 0;
                                 }
                             }
                         }
                         $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $rating['per_post_rating_summary'];
                         if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                             $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $ratingAverage['customUser']['perPost']['editor'];
                         } else {
                             $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = 0;
                         }
                         $encoded = json_encode(array('img_path' => CB_RATINGSYSTEM_PLUGIN_DIR_IMG, 'hints' => json_encode($cCriteria), 'is_rated' => 1, 'ratingsCount' => $summary[0]['per_post_rating_count'], 'errorMessage' => __('You have already rated this.', 'cbratingsystem')));
                         echo $encoded;
                     } else {
                         $encoded = json_encode(array('is_rated' => 1, 'errorMessage' => __('An error occurred while storing data. Please ensure that all data are resonable. If problem persist please contact the administrator.', 'cbratingsystem')));
                         echo $encoded;
                     }
                 }
                 //end you already submitted your rating.
             }
         }
     }
     die;
 }
    /**
     * Tools Options Pabels
     *
     * admin tool settings
     */
    public static function rating_tool_settings()
    {
        $mooddisplay = "one";
        if (isset($_POST['savebutton']) && $_POST['savebutton'] == __('Save Option', 'cbratingsystem')) {
            if (isset($_POST['wdcheckboxalldelete'])) {
                update_option("cbratingsystem_deleteonuninstall", 1);
            } else {
                update_option("cbratingsystem_deleteonuninstall", 0);
            }
            self::$message = __('Uninstall setting saved!', 'cbratingsystem');
        }
        //end switch
        if (isset($_POST['resetbutton']) && $_POST['resetbutton'] == __('Reset All', 'cbratingsystem')) {
            self::delete_all();
            self::create_all();
            //self::build_admin_ratingForm_tool_settings();
            self::$message = __('Reset done!', 'cbratingsystem');
        }
        ?>

            <?php 
        if (self::$message != '') {
            ?>
                <div id="message" class="updated"><?php 
            echo self::$message;
            ?>
</div>
            <?php 
        }
        ?>
            <p style="color: red;">
                <strong><?php 
        _e("Options and Tables", 'cbratingsystem');
        //_e('The Following WordPress Options/Tables will be DELETED:', 'wp-downloadmanager');
        ?>
</strong><br />
            </p>

            <table>
                <thead>
                <tr>
                    <th class="alternate"><?php 
        _e("Rating Options", 'cbratingsystem');
        //_e('Rating  Options', 'wp-ratingsystem');
        ?>
</th>
                    <th class="alternate"><?php 
        _e("Rating Tables", 'cbratingsystem');
        //_e('Rating  Tables', 'wp-ratingsystem');
        ?>
</th>
                </tr>
                </thead>
                <tr>
                    <td class="alternate">
                        <ol>
                            <li>cbratingsystem_defaultratingForm</li>
                            <li>cbratingsystem_theme_key</li>
                            <li>cbratingsystem_theme_settings</li>
                            <li>cbratingsystem_deleteonuninstall</li>
                        </ol>
                    </td>
                    <td class="alternate">
                        <?php 
        $tables[__('Rating Summary Table', 'cbratingsystem')] = CBRatingSystemData::get_ratingForm_settings_table_name();
        //look how to create an array
        $tables[__('User Rating Table', 'cbratingsystem')] = CBRatingSystemData::get_user_ratings_table_name();
        $tables[__('Rating Form Table', 'cbratingsystem')] = CBRatingSystemData::get_user_ratings_summury_table_name();
        ?>
                        <ol>
                            <?php 
        foreach ($tables as $key => $val) {
            echo '<li>' . $key . '(' . $val . ')</li>';
        }
        ?>
                        </ol>
                    </td>
                </tr>
            </table>

            <form method=post id="dwm_options" action="" enctype="multipart/form-data">
                <p><?php 
        echo __('Delete All options and tables related with this plugin on uninstall/delete', 'cbratingsystem');
        ?>
</p>
                <input class="form-checkbox" type="checkbox" name="wdcheckboxalldelete" value="cbdeleteall" <?php 
        get_option('cbratingsystem_deleteonuninstall') == 1 ? print_r("checked='checked'") : '';
        ?>
> Yes

                <input class="button button-primary button-large"  type=submit name="savebutton" value="<?php 
        _e('Save Option', 'cbratingsystem');
        ?>
" tabindex="8"><br>

            </form>
            <br />
            <hr/>
            <h2><?php 
        _e("Reset Setting", 'cbratingsystem');
        ?>
</h2>
            <form method=post id="rat_options" action="" enctype="multipart/form-data">
                <input class="button button-primary button-large"  type=submit name="resetbutton" value="<?php 
        _e('Reset All', 'cbratingsystem');
        ?>
" tabindex="8" onclick="return confirm('<?php 
        _e('You are about to reset all previous settings of this plugin .\\nThis action is not reversible.\\n\\n Choose [Cancel] to stop, [OK] to reset.', 'cbratingsystem');
        ?>
')">

                <p>
                    <span><?php 
        echo __('This will delete all tables and options created by this plugin. You will get a fresh Rating system to use as first time install. This process can not be undone.', 'cbratingsystem');
        ?>
</span>
                </p>
            </form>
        <?php 
        ?>
    <?php 
    }
    /**
     * process_bulk_action
     */
    public function process_bulk_action()
    {
        $action = $this->current_action();
        switch ($action) {
            case 'delete':
                if (!empty($_GET['wdcheckbox'])) {
                    global $wpdb;
                    $avgid = (array) $_GET['wdcheckbox'];
                    $formIds = array();
                    $postIds = array();
                    $table_name1 = CBRatingSystemData::get_user_ratings_table_name();
                    foreach ($avgid as $id) {
                        $id = (int) $id;
                        $sql = $wpdb->prepare("SELECT post_id ,form_id FROM {$table_name1} WHERE id=%d ", $id);
                        $results = $wpdb->get_results($sql, ARRAY_A);
                        array_push($formIds, $results[0]['form_id']);
                        array_push($postIds, $results[0]['post_id']);
                    }
                    $table_name1 = CBRatingSystemData::get_user_ratings_table_name();
                    $table_name = CBRatingSystemData::get_user_ratings_summury_table_name();
                    $table_name = CBRatingSystemData::get_user_ratings_table_name();
                    //$sql = $wpdb->prepare( "DELETE FROM $table_name WHERE id IN (" . implode( ',', $avgid ) . ")", null );
                    $sql = "DELETE FROM {$table_name} WHERE id IN (" . implode(',', (array) $avgid) . ")";
                    $wpdb->query($sql);
                    foreach ($postIds as $index => $id) {
                        $formId = $formIds[$index];
                        $postId = $id;
                        $ratingAverage = CBRatingSystemFront::viewPerCriteriaRatingResult($formId, $postId);
                        //$perPostAverageRating = isset($ratingAverage['perPost'][$postId])? $ratingAverage['perPost'][$postId] : '';
                        $perPostAverageRating = $ratingAverage['perPost'][$postId];
                        $postType = get_post_type($postId);
                        $ratingsCount = $ratingAverage['ratingsCount'][$formId . '-' . $postId];
                        $rating = array('form_id' => $formId, 'post_id' => $postId, 'post_type' => $postType, 'per_post_rating_count' => $ratingsCount, 'per_post_rating_summary' => $perPostAverageRating, 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                        $success = CBRatingSystemData::update_rating_summary($rating);
                    }
                    ?>
                        <script type="text/javascript">

                            jQuery(document).ready(function ($) {

                                $('.messages').show();
                                $('.messages').html('Successfully done');
                                var ids             = '<?php 
                    echo json_encode($avgid);
                    ?>
';
                                var trainindIdArray = ids.split(',');

                                $.each(trainindIdArray, function(index, value) {

                                    value = value.replace('"','');
                                    value = value.replace('[','');
                                    value = value.replace(']','');
                                    value = value.replace('"','');
                                    $('.user-rating-log-'+value).parents('tr').hide();


                                });
                                setTimeout(function() {   //calls click event after a certain time
                                    $('.messages').hide();
                                }, 2000);

                            });

                    </script>
                <?php 
                }
                break;
            case 'approve':
                if (!empty($_GET['wdcheckbox'])) {
                    $avgid = $_GET['wdcheckbox'];
                    $cbsommentstatus = 'approved';
                    $this->change_comment_status($avgid, $cbsommentstatus);
                    //cbratingsystemaddonfunctions ::cbratingsystem_comment_statuschange($avgid,$cbsommentstatus);
                }
                // end of if get
                echo '<script>window.location.href="admin.php?page=rating_reports"</script>';
                break;
            case 'spam':
                if (!empty($_GET['wdcheckbox'])) {
                    $avgid = $_GET['wdcheckbox'];
                    $cbsommentstatus = 'spam';
                    $this->change_comment_status($avgid, $cbsommentstatus);
                    //cbratingsystemaddonfunctions ::cbratingsystem_comment_statuschange($avgid,$cbsommentstatus);
                }
                // end of if get
                break;
            case 'unapprove':
                if (!empty($_GET['wdcheckbox'])) {
                    $avgid = $_GET['wdcheckbox'];
                    $cbsommentstatus = 'unapproved';
                    $this->change_comment_status($avgid, $cbsommentstatus);
                    //cbratingsystemaddonfunctions ::cbratingsystem_comment_statuschange($avgid,$cbsommentstatus);
                }
                // end of if get
                echo '<script>window.location.href="admin.php?page=rating_reports"</script>';
                break;
            default:
                // do nothing or something else
                return;
                break;
        }
        return;
    }