/** * 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 }
/** ************************************************************************ * 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 } }
/** * 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; }