Ejemplo n.º 1
0
    /**
     * Show avg rating for multiple posts for same form id,
     * calls from shortcode or direct function call or from widget
     *
     * @param     $option
     * @param int $show_title
     * @param int $show_form_id
     * @param int $show_text
     * @param int $show_star
     * @param int $show_single
     * @param int $text_label
     *
     * @return string
     */
    public static function standalone_singlePost_rating_summary($option, $show_title = 0, $show_form_id = 0, $show_text = 0, $show_star = 1, $show_single = 0, $text_label = '')
    {
        CBRatingSystem::load_scripts_and_styles();
        if ($option == NULL) {
            return '';
        }
        $text_label = $text_label == '' ? __('Rating: ', 'cbratingsystem') : $text_label;
        $post_ids = !isset($option['post_id']) || !is_array($option['post_id']) || sizeof($option['post_id']) == 0 ? array(get_the_ID()) : $option['post_id'];
        $form_ids = !isset($option['form_id']) || !is_array($option['form_id']) || sizeof($option['form_id']) == 0 ? array(self::get_default_ratingFormId()) : $option['form_id'];
        //$post_ids        = is_array($post_ids)
        $rating_smmary = array('post' => array());
        $show = '';
        /*echo '<pre>';
        		print_r($option);
        		echo '</pre>';*/
        //var_dump($form_ids);
        //var_dump($show_single);
        if ($show_single == 1 || sizeof($post_ids) == 1) {
            //if ( $show_single == 1 ) {
            //show only for first item
            $option['post_id'] = array($post_ids[0]);
            $option['form_id'] = array($form_ids[0]);
            $average_rating = CBRatingSystemData::get_ratings_summary($option);
            if (!sizeof($average_rating)) {
                $average_rating['form_id'] = $form_ids[0];
                $average_rating['post_id'] = $post_ids[0];
                $average_rating['post_title'] = get_the_title($post_ids[0]);
                $average_rating['per_post_rating_summary'] = 0;
                $average_rating['found'] = 0;
            } else {
                $average_rating = $average_rating[0];
                //no rating found for this post and form id
                $average_rating['found'] = 1;
            }
            $show .= '<div class="cbratingavgratelist">';
            if ($show_title == 1) {
                $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
            }
            if ($show_form_id == 1) {
                $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '</p>';
            }
            if ($show_text == 1) {
                $show .= '<p>' . $text_label . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5</p>';
            }
            $clip_back = 120;
            $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
            if ($show_star == 1) {
                ?>
				<script>
					jQuery(document).ready(function ($) {
						$('.cbrp-alone-rated<?php 
                echo $average_rating['post_id'];
                ?>
').raty({
							half    : true,
							path    : '<?php 
                echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                ?>
',
							score   : <?php 
                echo $average_rating['per_post_rating_summary'] / 100 * 5;
                ?>
,
							readOnly: true,
							hintList: ['', '', '', '', '']
						});
					});
				</script>
				<?php 
                $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $average_rating['post_id'] . '" style="margin: 0;"></div>';
            }
            $show .= '</div>';
            // echo   $show;
        } else {
            //var_dump('I am here');
            //$show = '';
            if (!empty($post_ids) && !empty($form_ids)) {
                //$position = 30;
                foreach ($post_ids as $post_id) {
                    //$average_ratings = CBRatingSystemData::get_ratings($form_id,$post_id);
                    //$option=array('post_id'=>$post_id,'form_id'=>$form_id);
                    //unset( $whrOpt );
                    $option = array();
                    $option['form_id'] = $form_ids;
                    $option['post_id'] = array($post_id);
                    $average_rating = CBRatingSystemData::get_ratings_summary($option);
                    if (!sizeof($average_rating)) {
                        $average_rating['form_id'] = $form_ids[0];
                        $average_rating['post_id'] = $post_ids[0];
                        $average_rating['post_title'] = get_the_title($post_ids[0]);
                        $average_rating['per_post_rating_summary'] = 0;
                        $average_rating['found'] = 0;
                    } else {
                        $average_rating = $average_rating[0];
                        $average_rating['found'] = 1;
                    }
                    $show .= '<div class="cbratingavgratelist" style="position:relative;">';
                    if ($show_title == 1) {
                        $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
                    }
                    if ($show_form_id == 1) {
                        $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '<p>';
                    }
                    if ($show_text == 1) {
                        $show .= '<p>' . $text_label . '' . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5<p>';
                    }
                    $clip_back = 120;
                    $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
                    if ($show_star == 1) {
                        ?>
						<script>
							jQuery(document).ready(function ($) {
								$('.cbrp-alone-rated<?php 
                        echo $post_id;
                        ?>
').raty({
									half    : true,
									path    : '<?php 
                        echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                        ?>
',
									score   : <?php 
                        echo $average_rating['per_post_rating_summary'] / 100 * 5;
                        ?>
,
									readOnly: true,
									hintList: ['', '', '', '', '']
								});
							});
						</script>
						<?php 
                        $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $post_id . '" style="margin: 0;"></div>';
                    }
                    $show .= '</div>';
                    //$position += 30;
                }
                //echo $show;
            }
        }
        return $show;
    }
Ejemplo n.º 2
0
    public static function post_meta_box_form($object, $box)
    {
        //echo '<pre>'; print_r($object); echo '</pre>';
        $postId = $object->ID;
        //var_dump($postId);
        $ratingFormEnabled = get_post_meta($postId, '_cbrating_enable_ratingForm', true);
        $defaultRatingFormEnabled = get_post_meta($postId, '_cbrating_is_default_ratingForm', true);
        $ratingFormToShow = get_post_meta($postId, '_cbrating_listing_ratingForm', true);
        $default = get_option('cbratingsystem_defaultratingForm');
        $default = CBRatingSystem::get_default_ratingFormId();
        $ratingFormToShow = (!empty($ratingFormToShow) and is_numeric($ratingFormToShow)) ? $ratingFormToShow : ((is_numeric($default) and !empty($default)) ? $default : '#NONE#');
        $action = array('is_active' => true, 'post_type' => $object->post_type);
        $ratingForms = CBRatingSystemData::get_ratingForms(true, $action);
        $adminUrl = admin_url('?page=rating');
        $option = '<select id="listing_ratingForm" name="listing_ratingForm" class="listing_ratingForm_select" style="width:50%">';
        if ($ratingFormToShow == '#NONE#') {
            $option .= '<option selected value="#NONE#">' . __('--Select rating form--', 'cbratingsystem') . '</option>';
        } else {
            $option .= '<option value="#NONE#">' . __('--Select rating form--', 'cbratingsystem') . '</option>';
        }
        if (!empty($ratingForms)) {
            foreach ($ratingForms as $ratingForm) {
                if ($default == $ratingForm->id) {
                    $txt = ' (' . __('Default Form', 'cbratingsystem') . ')';
                } else {
                    $txt = '';
                }
                if ($ratingFormToShow == $ratingForm->id) {
                    $option .= '<option selected value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                } else {
                    $option .= '<option value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                }
            }
        }
        $option .= '</select>';
        ?>
		<?php 
        wp_nonce_field(basename(__FILE__), 'rating_form_meta_box_nonce');
        ?>


		<p>
			<label for="enable_ratingForm"><?php 
        _e(sprintf("Display Form"), 'cbratingsystem');
        ?>
</label>
			<input type="checkbox" id="enable_ratingForm" name="enable_ratingForm" value="1" <?php 
        echo $ratingFormEnabled != '' ? $ratingFormEnabled == 1 ? 'checked' : '' : 'checked';
        ?>
/>
		</p>
		<p>
			<label for="is_default_ratingForm"><?php 
        _e(sprintf("Use Default"), 'cbratingsystem');
        ?>
</label>
			<input type="checkbox" id="is_default_ratingForm" name="is_default_ratingForm" value="1" <?php 
        echo $defaultRatingFormEnabled != '' ? $defaultRatingFormEnabled == 1 ? 'checked' : '' : 'checked';
        ?>
/>
		</p>
		<p class="cb_listing_ratingForm">
			<label for="listing_ratingForm"><?php 
        _e(sprintf("Select which form should work for this %s:", $object->post_type), 'cbratingsystem');
        ?>
</label>
			<br />
			<?php 
        echo $option;
        ?>
			<span class="description"><?php 
        _e(sprintf("Select which form should work for this %s. You can checkout rating forms at %s page.", $object->post_type, '<a target="_blank" href="' . $adminUrl . '">this</a>'), 'cbratingsystem');
        ?>
</span>
		</p>

		<script type="text/javascript">
			jQuery(document).ready(function ($) {
				$('input#is_default_ratingForm').change(function () {
					if ($(this).is(':checked')) {
						$('.cb_listing_ratingForm').hide();
					} else {
						$('.cb_listing_ratingForm').show();
					}
				});
				if ($('input#is_default_ratingForm').is(':checked')) {
					$('.cb_listing_ratingForm').hide();
				} else {
					$('.cb_listing_ratingForm').show();
				}
			});
		</script>
	<?php 
    }
Ejemplo n.º 3
0
    /**
     * @param array $instance
     *
     * @return string|void
     */
    function form($instance)
    {
        if ($instance) {
            $title = esc_attr($instance['title']);
        } else {
            $title = __('Top Rated Users', 'cbratingsystem');
        }
        if (array_key_exists('timelimit', $instance)) {
            $timelimit = $instance['timelimit'];
        } else {
            $timelimit = '0';
        }
        if (array_key_exists('user_id', $instance)) {
            $user_id = $instance['user_id'];
        } else {
            $user_id = '';
        }
        if (array_key_exists('post_id', $instance)) {
            $post_id = $instance['post_id'];
        } else {
            $post_id = '';
        }
        if (array_key_exists('resultlimit', $instance)) {
            $limit = $instance['resultlimit'];
        } else {
            $limit = '10';
        }
        if (array_key_exists('posttype', $instance)) {
            $posttype = $instance['posttype'];
        } else {
            $posttype = '0';
        }
        if (array_key_exists('post_filter', $instance)) {
            $post_filter = $instance['post_filter'];
        } else {
            $post_filter = 'post_type';
        }
        if (array_key_exists('form_id', $instance)) {
            $form_id = $instance['form_id'];
        } else {
            $form_id = 'form_id';
        }
        if (array_key_exists('order', $instance)) {
            $order = $instance['order'];
        } else {
            $order = 'DESC';
        }
        if (array_key_exists('firstorder', $instance)) {
            $firstorder = $instance['firstorder'];
        } else {
            $firstorder = 'post_count';
        }
        ?>
        <p>
            <label for = "<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e("Title", 'cbratingsystem');
        ?>
:</label>
            <input class = "widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" type="text" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo $title;
        ?>
" />
        </p>
        <!--user limit  -->
        <p>
            <label for = "<?php 
        echo $this->get_field_id('user_id');
        ?>
"><?php 
        _e("User Ids ('Blank or comma separate ids ) ", 'cbratingsystem');
        ?>
:</label>
            <input class = "widefat" id="<?php 
        echo $this->get_field_id('user_id');
        ?>
" type="text" name="<?php 
        echo $this->get_field_name('user_id');
        ?>
" value="<?php 
        echo $user_id;
        ?>
" />
        </p>
        <!--time limit  -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('timelimit');
        ?>
"><?php 
        _e("Display Last", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('timelimit');
        ?>
" name="<?php 
        echo $this->get_field_name('timelimit');
        ?>
" class="widefat" style="width:50%">
                <?php 
        //$no_of_days = array( 1 => '24 hours', 7 => 'Week', 15 => '15 Days', 30 => 'Month', 0 => 'All' );
        $no_of_days = array(1 => __('Last 24 hours', 'cbratingsystem'), 7 => __('Last 7 Days', 'cbratingsystem'), 15 => __('Last 15 Days', 'cbratingsystem'), 30 => __('Last 30 days', 'cbratingsystem'), 0 => __('All Time', 'cbratingsystem'));
        foreach ($no_of_days as $day => $day_label) {
            echo "<option value='{$day}'";
            if ($timelimit == $day) {
                echo "selected='selected'";
            }
            echo ">{$day_label}</option>";
        }
        ?>
            </select>
        </p>
        <p><?php 
        _e('Note: Based on Post creation date', 'cbratingsystem');
        ?>
</p>
        <!--result limit  -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('resultlimit');
        ?>
">No. To Display:</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('resultlimit');
        ?>
" type="text" name="<?php 
        echo $this->get_field_name('resultlimit');
        ?>
" value="<?php 
        echo $limit;
        ?>
" />
        </p>
        <!--post id -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('post_id');
        ?>
"><?php 
        _e("Post Ids ('Blank or comma separate ids ) ", 'cbratingsystem');
        ?>
:</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('post_id');
        ?>
" type="text" name="<?php 
        echo $this->get_field_name('post_id');
        ?>
" value="<?php 
        echo $post_id;
        ?>
" />
        </p>
        <!--post type id -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('posttype');
        ?>
"><?php 
        _e("Post Type", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('posttype');
        ?>
" name="<?php 
        echo $this->get_field_name('posttype');
        ?>
" class="widefat" style="width: 55%">
                <?php 
        echo "<option value='0'";
        if ($posttype == 0) {
            echo "selected='selected'";
        }
        echo ">" . ucfirst('All') . "</option>";
        //////////////
        foreach (CBRatingSystem::post_types() as $argType => $postTypes) {
            echo '<optgroup label="' . $postTypes['label'] . '">';
            foreach ($postTypes['types'] as $type => $typeLabel) {
                echo "<option value='{$type}'";
                if ($posttype == $type) {
                    echo "selected='selected'";
                }
                echo ">" . ucfirst($typeLabel) . "</option>";
            }
            echo '</optgroup>';
        }
        ?>
            </select>
        </p>
        <!-- post type filter -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('post_filter');
        ?>
"><?php 
        _e("Post Filter", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('post_filter');
        ?>
" name="<?php 
        echo $this->get_field_name('post_filter');
        ?>
" class="widefat" style="width:50%">
                <?php 
        $no_of_filter = array('post_type' => 'Post Type', 'post_id' => 'Post ID');
        foreach ($no_of_filter as $key => $label) {
            echo "<option value = '{$key}'";
            if ($post_filter == $key) {
                echo "selected='selected'";
            }
            echo "> {$label} </option>";
        }
        ?>
            </select>
        </p>
        <!-- order by  type filter -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('order');
        ?>
"><?php 
        _e("Order", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('order');
        ?>
" name="<?php 
        echo $this->get_field_name('order');
        ?>
" class="widefat" style="width:50%">
                <?php 
        $no_of_filter = array('ASC' => 'Ascending', 'DESC' => 'Descending');
        foreach ($no_of_filter as $key => $label) {
            echo "<option value = '{$key}'";
            if ($order == $key) {
                echo "selected='selected'";
            }
            echo "> {$label} </option>";
        }
        ?>
            </select>
        </p>
        <!-- order by  type filter -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('firstorder');
        ?>
"><?php 
        _e("First Sort By", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('firstorder');
        ?>
" name="<?php 
        echo $this->get_field_name('firstorder');
        ?>
" class="widefat" style="width:50%">
                <?php 
        $no_of_filter = array('rating' => 'Rating', 'post_count' => 'User post Number');
        foreach ($no_of_filter as $key => $label) {
            echo "<option value = '{$key}'";
            if ($firstorder == $key) {
                echo "selected='selected'";
            }
            echo "> {$label} </option>";
        }
        ?>
            </select>
        </p>


        <!--form id -->
        <p>
            <label for="<?php 
        echo $this->get_field_id('form_id');
        ?>
"><?php 
        _e("Form", 'cbratingsystem');
        ?>
:</label>
            <select id="<?php 
        echo $this->get_field_id('form_id');
        ?>
" name="<?php 
        echo $this->get_field_name('form_id');
        ?>
" class="widefat" style="width: 55%">
                <?php 
        $action = array('is_active' => true);
        $ratingForms = CBRatingSystemData::get_ratingForms(true, $action);
        $ratingFormToShow = intval($form_id);
        $default = CBRatingSystem::get_default_ratingFormId();
        if (!empty($ratingForms)) {
            echo "<option value='0'";
            if ($ratingFormToShow == 0) {
                echo "selected='selected'";
            }
            echo ">" . ucfirst('All') . "</option>";
            foreach ($ratingForms as $ratingForm) {
                if ($default == $ratingForm->id) {
                    $txt = ' (' . __('Default Form', 'cbratingsystem') . ')';
                } else {
                    $txt = '';
                }
                if ($ratingFormToShow == $ratingForm->id) {
                    echo '<option selected value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                } else {
                    echo '<option value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                }
            }
        }
        ?>
            </select>
        </p>
    <?php 
    }
Ejemplo n.º 4
0
 public static function build_admin_ratingForm_tool_settings()
 {
     //create tables again
     CBRatingSystemData::install_table();
     $settings = array();
     //adding options
     update_option("cbratingsystem_defaultratingForm", 0);
     update_option("cbratingsystem_theme_key", 'basic');
     update_option("cbratingsystem_theme_settings", $settings);
     update_option("cbratingsystem_deleteonuninstall", 0);
     //CBRatingSystemAdmin::admin_ratingForm_edit_page_custom_label( $RFSettings = array() );
 }
Ejemplo n.º 5
0
    /** ************************************************************************
     * 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 
        }
    }
Ejemplo n.º 6
0
 /**
  * @param $ratingFormArray
  * @param $post_id
  * @param int $user_id
  * @return mixed
  */
 public static function viewPerCriteriaRatingResult($ratingFormArray, $post_id, $user_id = 0)
 {
     //$time1 = microtime();
     if (!empty($post_id)) {
         if (!is_array($ratingFormArray) and is_numeric($ratingFormArray)) {
             $ratingFormArray = CBRatingSystemData::get_ratingForm($ratingFormArray);
         }
         if (is_array($ratingFormArray)) {
             $data['form_id'] = $ratingFormArray['id'];
             $data['ratings'] = CBRatingSystemData::get_ratings($ratingFormArray['id'], $post_id);
             $data['avgRatingArray']['ratingsCount'][$ratingFormArray['id'] . '-' . $post_id] = count($data['ratings']);
             foreach ($data['ratings'] as $k => $rating) {
                 foreach ($rating['rating'] as $cId => $value) {
                     if (is_numeric($cId)) {
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['value'] = $value;
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['count'] = count($ratingFormArray['custom_criteria'][$cId]['stars']);
                         $data['ratingsValueArray'][$k]['criterias'][$cId]['criteria_array'] = $ratingFormArray['custom_criteria'][$cId]['stars'];
                     }
                 }
                 $data['ratingsValueArray'][$k]['user_id'] = $data['ratings'][$k]['user_id'];
             }
             $data['criteria'] = $ratingFormArray['custom_criteria'];
             $userIdToMatch = array('guest' => array(0), 'registered' => -1);
             //var_dump($ratingFormArray['editor_group']);
             $userWithCustomRole = new WP_User_Query(array('role' => $ratingFormArray['editor_group'][0], 'fields' => 'ID'));
             if (!empty($userWithCustomRole->total_users)) {
                 $userIds = $userWithCustomRole->results;
                 $userIdToMatch['editor'] = $userIds;
             }
             $data['userIdToMatch'] = $userIdToMatch;
             CBRatingSystemCalculation::allUserPerCriteriaAverageCalculation($data, $post_id);
             return $data['avgRatingArray'];
         }
     }
 }
 function getRatingAverageWithCustomCondition()
 {
     CBRatingSystemData::get_user_ratings_with_ratingForm();
 }
Ejemplo n.º 8
0
<?php

/**
 * Fired when the plugin is uninstalled.
 *
 * @package   rating
 * @author    codeboxr <*****@*****.**>
 * @license   GPL-2.0+
 * @link      http://codeboxr.com
 * @copyright 2014 codeboxr
 */
// If uninstall not called from WordPress, then exit
require_once plugin_dir_path(__FILE__) . "data.php";
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}
if (!current_user_can('activate_plugins')) {
    return;
}
check_admin_referer('bulk-plugins');
//var_dump(current_user_can( 'activate_plugins' ));exit;
// Important: Check if the file is the one
// that was registered during the uninstall hook.
$checkuninstall = intval(get_option('cbratingsystem_deleteonuninstall'));
if ($checkuninstall == 1) {
    CBRatingSystemData::delete_tables();
    CBRatingSystemData::delete_options();
    CBRatingSystemData::delete_metakeys();
}
    /**
     * 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;
    }
    /**
     * [build_admin_dashboard description]
     * @return [type]
     */
    public static function build_admin_dashboard()
    {
        //$data = CBRatingSystemData::get_ratings_summary();
        $formPath = admin_url('admin.php?page=ratingformedit');
        $reviewPath = admin_url('admin.php?page=rating_reports');
        $ratingForms = CBRatingSystemData::get_ratings_summary_with_ratingForms(true);
        $totalRatingForm = count($ratingForms);
        $defaultFormId = get_option('cbratingsystem_defaultratingForm');
        ?>

		<div class="wrap">

			<div id="icon-options-general" class="icon32"></div>
			<h2><?php 
        _e("CBX Multi Criteria Rating System Dashboard", 'cbratingsystem');
        ?>
</h2>

			<div id="poststuff">

				<div id="post-body" class="metabox-holder columns-2">

					<!-- main content -->
					<div id="post-body-content">

						<div class="meta-box-sortables ui-sortable">

							<div class="postbox">

								<h3><span><?php 
        _e('Overview', 'cbratingsystem');
        ?>
</span></h3>
								<div class="inside">

									<?php 
        $url = get_option('siteurl');
        $url .= '/wp-admin/admin.php?page=ratingformedit';
        ?>
									<table class="widefat">
										<thead>
											<tr>
												<th class="row-title">
													<?php 
        _e('Default', 'cbratingsystem');
        ?>
												</th>
												<th >
													<?php 
        _e('Form', 'cbratingsystem');
        ?>
												</th>
												<th><?php 
        _e('Reviews', 'cbratingsystem');
        ?>
</th>
											</tr>
										</thead>
										<tbody>
										<?php 
        if (!empty($ratingForms)) {
            foreach ($ratingForms as $k => $ratingForm) {
                $oddEvenClass = $k % 2 ? 'odd' : 'even';
                $title = $ratingForm->name ? $ratingForm->name : "";
                $link = $formPath . '&id=' . $ratingForm->id;
                $reviewLink = $reviewPath . '&form=' . $ratingForm->id;
                $reviewsCount = $ratingForm->count ? $ratingForm->count : 0;
                $reviewsText = $reviewsCount > 1 ? __('Reviews', 'cbratingsystem') : __('Review', 'cbratingsystem');
                if ($defaultFormId != $ratingForm->id) {
                    ?>
													<tr class="<?php 
                    echo $oddEvenClass;
                    ?>
">
														<td class="first b b_pages">
															<span><img title="Not Default Form" alt="Not Default Form" src="<?php 
                    echo plugins_url('/images/star-off-big.png', __FILE__);
                    ?>
" /></span>
														</td>
														<td class="t pages">
															<a href="<?php 
                    echo $link;
                    ?>
"><?php 
                    echo $title;
                    ?>
 </a> - <?php 
                    _e('ID', 'cbratingsystem');
                    ?>
: <?php 
                    echo $ratingForm->id;
                    ?>
														</td>
														<td class="t pages">
															<?php 
                    if ($reviewsCount > 1) {
                        $class = 'approved';
                    } else {
                        $class = 'waiting';
                    }
                    ?>
															<a href="<?php 
                    echo $reviewLink;
                    ?>
"><span class="count"><?php 
                    echo $reviewsCount;
                    ?>
</span></a>
															<a href="<?php 
                    echo $reviewLink;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
"><?php 
                    echo $reviewsText;
                    ?>
</a>
														</td>
													</tr>
												<?php 
                } else {
                    ?>
													<tr class="default <?php 
                    echo $oddEvenClass;
                    ?>
">
														<td class="first b b_pages">
															<span><img title="Default Form" alt="Default Form" src="<?php 
                    echo plugins_url('/images/star-on-big.png', __FILE__);
                    ?>
" /></span>
														</td>
														<td class="t pages">
															<a href="<?php 
                    echo $link;
                    ?>
"><?php 
                    echo $title;
                    ?>
</a> - <?php 
                    _e('ID', 'cbratingsystem');
                    ?>
: <?php 
                    echo $ratingForm->id;
                    ?>
														</td>
														<td class="t pages">
															<?php 
                    if ($reviewsCount > 1) {
                        $class = 'approved';
                    } else {
                        $class = 'waiting';
                    }
                    ?>
															<a href="<?php 
                    echo $reviewLink;
                    ?>
"><span class="count"><?php 
                    echo $reviewsCount;
                    ?>
</span></a>
															<a href="<?php 
                    echo $reviewLink;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
"><?php 
                    echo $reviewsText;
                    ?>
</a>
														</td>
													</tr>
												<?php 
                }
            }
        }
        ?>
										</tbody>
									</table>
								</div> <!-- .inside -->

							</div> <!-- .postbox -->

						</div> <!-- .meta-box-sortables .ui-sortable -->

					</div> <!-- post-body-content -->

					<!-- sidebar -->
					<div id="postbox-container-1" class="postbox-container">

						<div class="meta-box-sortables">

							<div class="postbox">

								<h3><span><?php 
        _e('Plugin Information', 'cbratingsystem');
        ?>
</span></h3>
								<div class="inside">
									<?php 
        define('CB_RATINGSYSTEM_SUPPORT_VIDEO_DISPLAY', true);
        require CB_RATINGSYSTEM_PATH . '/cb-sidebar.php';
        ?>
								</div> <!-- .inside -->

							</div> <!-- .postbox -->

						</div> <!-- .meta-box-sortables -->

					</div> <!-- #postbox-container-1 .postbox-container -->

				</div> <!-- #post-body .metabox-holder .columns-2 -->

				<br class="clear">
			</div> <!-- #poststuff -->

		</div> <!-- .wrap -->



	<?php 
    }