Example #1
0
/**
 * Renders the browser of existing tables
 */
function wpdatatables_browse()
{
    global $wpdb, $wdt_admin_translation_array;
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    if ($action == 'edit') {
        $id = $_GET['table_id'];
        $tpl = new PDTTpl();
        $tpl->setTemplate('edit_table.inc.php');
        // Admin JS
        wp_enqueue_script('wpdatatables-admin', WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js');
        // Google Charts
        wp_enqueue_script('wdt_google_charts', 'https://www.google.com/jsapi');
        // Selecter
        wp_enqueue_script('wpdatatables-selecter', WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js');
        wp_enqueue_style('wpdatatables-selecter', WDT_CSS_PATH . 'jquery.fs.selecter.css');
        // Picker
        wp_enqueue_script('wpdatatables-picker', WDT_JS_PATH . 'picker/jquery.fs.picker.min.js');
        wp_enqueue_style('wpdatatables-picker', WDT_CSS_PATH . 'jquery.fs.picker.css');
        // Popup
        wp_enqueue_script('wpdatatables-popup', WDT_JS_PATH . 'popup/jquery.remodal.min.js');
        wp_enqueue_style('wpdatatables-popup', WDT_CSS_PATH . 'jquery.remodal.css');
        // JsRender
        wp_enqueue_script('wpdatatables-jsrender', WDT_JS_PATH . 'jsrender/jsrender.min.js');
        // Table create/edit JS
        wp_enqueue_script('wpdatatables-edit', WDT_JS_PATH . 'wpdatatables/wpdatatables_edit_table.js');
        // Media upload
        wp_enqueue_script('media-upload');
        // Localization
        wp_localize_script('wpdatatables-edit', 'wpdatatables_edit_strings', $wdt_admin_translation_array);
        $tpl->addData('wpShowTitle', __('Edit wpDataTable', 'wpdatatables'));
        $tpl->addData('table_id', $id);
        $tpl->addData('table_data', wdt_get_table_by_id($id));
        $tpl->addData('column_data', wdt_get_columns_by_table_id($id));
        $tpl->addData('wdtUserRoles', get_editable_roles());
        $edit_page = $tpl->returnData();
        $edit_page = apply_filters('wpdatatables_filter_edit_page', $edit_page);
        echo $edit_page;
    } else {
        if ($action == 'delete') {
            $id = $_REQUEST['table_id'];
            if (!is_array($id)) {
                $wpdb->query("DELETE \n\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}wpdatatables\n\t\t\t\t\t\t\t\t\tWHERE id={$id}");
            } else {
                foreach ($id as $single_id) {
                    $wpdb->query("DELETE \n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}wpdatatables\n\t\t\t\t\t\t\t\t\t\tWHERE id={$single_id}");
                }
            }
        }
        $wdtBrowseTable = new WDTBrowseTable();
        $wdtBrowseTable->prepare_items();
        ob_start();
        $wdtBrowseTable->search_box('search', 'search_id');
        $wdtBrowseTable->display();
        $tableHTML = ob_get_contents();
        ob_end_clean();
        $tpl = new PDTTpl();
        // Popup
        $tpl->addJs(WDT_JS_PATH . 'popup/jquery.remodal.min.js');
        $tpl->addCss(WDT_CSS_PATH . 'jquery.remodal.css');
        // Admin JS
        $tpl->addJs(WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js');
        $tpl->setTemplate('browse.inc.php');
        $tpl->addData('tableHTML', $tableHTML);
        $browse_page = $tpl->returnData();
        $browse_page = apply_filters('wpdatatables_filter_browse_page', $browse_page);
        echo $browse_page;
    }
    do_action('wpdatatables_browse_page');
}
/**
 * Renders the browser of existing tables
 */
function wpdatatables_browse()
{
    global $wpdb, $wdt_admin_translation_array;
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    if ($action == 'edit') {
        $id = $_GET['table_id'];
        $tpl = new PDTTpl();
        $tpl->setTemplate('edit_table.inc.php');
        wpdatatables_enqueue_editing_scripts();
        $tpl->addData('wpShowTitle', __('Edit wpDataTable', 'wpdatatables'));
        $tpl->addData('table_id', $id);
        $tpl->addData('table_data', wdt_get_table_by_id($id));
        $tpl->addData('column_data', wdt_get_columns_by_table_id($id));
        $tpl->addData('wdtUserRoles', get_editable_roles());
        $edit_page = $tpl->returnData();
        $edit_page = apply_filters('wpdatatables_filter_edit_page', $edit_page);
        echo $edit_page;
    } else {
        if ($action == 'delete') {
            $id = $_REQUEST['table_id'];
            if (!is_array($id)) {
                $wpdb->query("DELETE \n                                                        FROM {$wpdb->prefix}wpdatatables\n                                                        WHERE id={$id}");
                $wpdb->query("DELETE \n                                                        FROM {$wpdb->prefix}wpdatatables_columns\n                                                        WHERE table_id={$id}");
                $wpdb->query("DELETE \n                                                        FROM {$wpdb->prefix}wpdatacharts\n                                                        WHERE wpdatatable_id={$id}");
            } else {
                foreach ($id as $single_id) {
                    $wpdb->query("DELETE \n                                                                FROM {$wpdb->prefix}wpdatatables\n                                                                WHERE id={$single_id}");
                    $wpdb->query("DELETE \n                                                                FROM {$wpdb->prefix}wpdatatables_columns\n                                                                WHERE table_id={$single_id}");
                    $wpdb->query("DELETE \n                                                                FROM {$wpdb->prefix}wpdatacharts\n                                                                WHERE wpdatatable_id={$single_id}");
                }
            }
        }
        $wdtBrowseTable = new WDTBrowseTable();
        $wdtBrowseTable->prepare_items();
        ob_start();
        $wdtBrowseTable->search_box('search', 'search_id');
        $wdtBrowseTable->display();
        $tableHTML = ob_get_contents();
        ob_end_clean();
        $tpl = new PDTTpl();
        // Popup
        $tpl->addJs(WDT_JS_PATH . 'popup/jquery.remodal.min.js');
        $tpl->addCss(WDT_CSS_PATH . 'jquery.remodal.css');
        // Admin JS
        $tpl->addJs(WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js');
        $tpl->setTemplate('browse.inc.php');
        $tpl->addData('tableHTML', $tableHTML);
        $browse_page = $tpl->returnData();
        $browse_page = apply_filters('wpdatatables_filter_browse_page', $browse_page);
        echo $browse_page;
    }
    do_action('wpdatatables_browse_page');
}