public static function destroy_all()
 {
     if (!current_user_can('frm_delete_entries')) {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     global $wpdb;
     $params = FrmForm::get_admin_params();
     $message = '';
     $errors = array();
     $form_id = (int) $params['form'];
     if ($form_id) {
         $entry_ids = FrmDb::get_col('frm_items', array('form_id' => $form_id));
         $action = FrmFormAction::get_action_for_form($form_id, 'wppost', 1);
         if ($action) {
             // this action takes a while, so only trigger it if there are posts to delete
             foreach ($entry_ids as $entry_id) {
                 do_action('frm_before_destroy_entry', $entry_id);
                 unset($entry_id);
             }
         }
         $wpdb->query($wpdb->prepare("DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id));
         $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
         if ($results) {
             $message = __('Entries were Successfully Destroyed', 'formidable');
         }
     } else {
         $errors = __('No entries were specified', 'formidable');
     }
     self::display_list($message, $errors);
 }
Ejemplo n.º 2
0
 public static function bulk_actions($action = 'list-form')
 {
     $params = FrmForm::get_admin_params();
     $errors = array();
     $bulkaction = '-1';
     if ($action == 'list-form') {
         if ($_REQUEST['bulkaction'] != '-1') {
             $bulkaction = sanitize_text_field($_REQUEST['bulkaction']);
         } else {
             if ($_POST['bulkaction2'] != '-1') {
                 $bulkaction = sanitize_text_field($_REQUEST['bulkaction2']);
             }
         }
     } else {
         $bulkaction = str_replace('bulk_', '', $action);
     }
     $items = FrmAppHelper::get_param('item-action', '');
     if (empty($items)) {
         $errors[] = __('No entries were specified', 'formidable');
     } else {
         $frm_settings = FrmAppHelper::get_settings();
         if (!is_array($items)) {
             $items = explode(',', $items);
         }
         if ($bulkaction == 'delete') {
             if (!current_user_can('frm_delete_entries')) {
                 $errors[] = $frm_settings->admin_permission;
             } else {
                 if (is_array($items)) {
                     foreach ($items as $item_id) {
                         FrmEntry::destroy($item_id);
                     }
                 }
             }
         } else {
             if ($bulkaction == 'csv') {
                 FrmAppHelper::permission_check('frm_view_entries');
                 $form_id = $params['form'];
                 if (!$form_id) {
                     $form = FrmForm::get_published_forms(array(), 1);
                     if (!empty($form)) {
                         $form_id = $form->id;
                     } else {
                         $errors[] = __('No form was found', 'formidable');
                     }
                 }
                 if ($form_id && is_array($items)) {
                     echo '<script type="text/javascript">window.onload=function(){location.href="' . esc_url_raw(admin_url('admin-ajax.php') . '?form=' . $form_id . '&action=frm_entries_csv&item_id=' . implode(',', $items)) . '";}</script>';
                 }
             }
         }
     }
     FrmEntriesController::display_list('', $errors);
 }