Example #1
0
function wpbi_mce_tag($atts, $content = null)
{
    global $wpbi_url, $template_site, $wpdb, $wpbi_sql;
    //    remove_filter('the_content', 'wpautop');
    $template_site->set_filenames(array('iframe' => $wpbi_url['tpl']['root-path'] . $wpbi_url['tpl']['iframe']));
    extract(shortcode_atts(array('type' => 'table', 'id' => NULL, 'iframe' => 'n'), $atts));
    $code = '';
    if ($type == 'table') {
        if ($iframe == 'y') {
            //Get Key
            $vo_table = new vo_table($id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
            $dao_table = new dao_table($wpdb, $wpbi_sql['tname']['tables']);
            $vo_table = $dao_table->select($vo_table);
            $vo_table = $vo_table[0];
            $table_key = $vo_table->table_key;
            //Prepare output
            $template_site->assign_vars(array('IFRAME_JS_AUTOHEIGHT' => $wpbi_url['jquery']['iframe-auto-height'], 'IFRAME_SRC' => $wpbi_url['iframe']['src'] . '?t=' . $table_key, 'IFRAME_WIDTH' => '100%'));
            ob_start();
            $template_site->pparse('iframe');
            $iframe_output = ob_get_contents();
            ob_end_clean();
            $code = $iframe_output;
        } else {
            $code = get_html_4_table($id);
        }
    } else {
        if ($type == 'chart') {
            if ($iframe == 'y') {
                //Get Key
                $selected_charts = $id;
                $vo_chart = new vo_chart(NULL);
                $vo_chart->set_chart_id($selected_charts);
                $vo_chart->set_chart_key($selected_charts);
                $dao_chart = new dao_chart($wpdb, $wpbi_sql['tname']['charts']);
                $vo_chart = $dao_chart->select($vo_chart);
                $vo_chart = $vo_chart[0];
                $chart_key = $vo_chart->chart_key;
                //Prepare output
                $template_site->assign_vars(array('IFRAME_JS_AUTOHEIGHT' => $wpbi_url['jquery']['iframe-auto-height'], 'IFRAME_SRC' => $wpbi_url['iframe']['src'] . '?c=' . $chart_key, 'IFRAME_WIDTH' => is_numeric($vo_chart->width) ? $vo_chart->width . 'px' : '800px'));
                ob_start();
                $template_site->pparse('iframe');
                $iframe_output = ob_get_contents();
                ob_end_clean();
                $code = $iframe_output;
            } else {
                $code = get_html_4_chart($id);
            }
        }
    }
    return $code;
}
Example #2
0
        }
        $style_options = $style_options . '<option ' . $checked . ' value="' . $styles_lst[$stl] . '">' . basename($styles_lst[$stl], '.css') . '</option>';
    }
    $template_site->assign_vars(array('TPL_CSS' => $wpbi_url['styles']['url'] . "tables/" . (!isset($_POST[$wpbi_settings['parameter']['tb-style']]) ? $vo_table->css_style : $_POST[$wpbi_settings['parameter']['tb-style']]), 'PG_TITLE' => $wpbi_dialog['page']['tables']['title'], 'PG_DESCRIPTION' => sprintf($wpbi_dialog['table']['saved']['edit'], $vo_table->name, htmlentities($current_qy->statement)), 'VW_EDIT_STYLE_OPTIONS' => $style_options, 'VW_EDIT_SETTINGS' => $wpbi_dialog['form']['label']['settings'], 'VW_EDIT_VALUES' => $wpbi_dialog['form']['label']['values'], 'VW_EDIT_NAME' => $wpbi_dialog['form']['label']['table-name'], 'P_VW_NAME' => $wpbi_settings['parameter']['tb-name'], 'V_VW_NAME' => isset($_POST[$wpbi_settings['parameter']['tb-name']]) ? $_POST[$wpbi_settings['parameter']['tb-name']] : $vo_table->name, 'VW_EDIT_TITLE' => $wpbi_dialog['form']['label']['table-title'], 'P_VW_TITLE' => $wpbi_settings['parameter']['tb-title'], 'V_VW_TITLE' => isset($_POST[$wpbi_settings['parameter']['tb-title']]) ? $_POST[$wpbi_settings['parameter']['tb-title']] : $vo_table->title, 'VW_EDIT_STYLE' => $wpbi_dialog['form']['label']['table-style'], 'P_VW_STYLE' => $wpbi_settings['parameter']['tb-style'], 'VW_EDIT_HEADER' => $wpbi_dialog['form']['label']['table-header'], 'P_VW_HEADER' => $wpbi_settings['parameter']['tb-header'], 'V_VW_HEADER' => isset($_POST[$wpbi_settings['parameter']['tb-header']]), 'V_VW_HEADER_CHECKED' => isset($_POST[$wpbi_settings['parameter']['tb-header']]) || $_POST[$wpbi_settings['parameter']['action']] != $wpbi_settings['value']['edit-test'] && $vo_table->has_header ? 'checked' : '', 'VW_EDIT_FOOTER' => $wpbi_dialog['form']['label']['table-footer'], 'P_VW_FOOTER' => $wpbi_settings['parameter']['tb-footer'], 'V_VW_FOOTER' => $_POST[$wpbi_settings['parameter']['tb-footer']], 'V_VW_FOOTER_CHECKED' => isset($_POST[$wpbi_settings['parameter']['tb-footer']]) || $_POST[$wpbi_settings['parameter']['action']] != $wpbi_settings['value']['edit-test'] && $vo_table->has_footer ? 'checked' : '', 'VW_EDIT_DOWNLOAD' => $wpbi_dialog['form']['label']['table-download'], 'P_VW_DOWNLOAD' => $wpbi_settings['parameter']['tb-download'], 'V_VW_DOWNLOAD' => $_POST[$wpbi_settings['parameter']['tb-download']], 'V_VW_DOWNLOAD_CHECKED' => isset($_POST[$wpbi_settings['parameter']['tb-download']]) || $_POST[$wpbi_settings['parameter']['action']] != $wpbi_settings['value']['edit-test'] && $vo_table->can_download ? 'checked' : '', 'VW_EDIT_HTML_VALUES' => $wpbi_dialog['form']['label']['table-html-values'], 'P_VW_HTML_VALUES' => $wpbi_settings['parameter']['tb-html-values'], 'V_VW_HTML_VALUES' => $_POST[$wpbi_settings['parameter']['tb-html-values']], 'V_VW_HTML_VALUES_CHECKED' => isset($_POST[$wpbi_settings['parameter']['tb-html-values']]) || $_POST[$wpbi_settings['parameter']['action']] != $wpbi_settings['value']['edit-test'] && $vo_table->encode_html ? 'checked' : '', 'VW_EDIT_ROWS_PER_PG' => $wpbi_dialog['form']['label']['table-rows-pg'], 'P_VW_ROWS_PER_PG' => $wpbi_settings['parameter']['tb-row-pg'], 'V_VW_ROWS_PER_PG' => is_numeric($_POST[$wpbi_settings['parameter']['tb-row-pg']]) ? abs(intval($_POST[$wpbi_settings['parameter']['tb-row-pg']])) : $vo_table->rows_per_pg, 'P_VW_TX_COLUMN_TF' => $wpbi_settings['parameter']['tb-tx-column-tf'], 'VW_EDIT_COLUMNS' => $wpbi_dialog['form']['label']['table-col'], 'VW_EDIT_COL_VISIBLE' => $wpbi_dialog['form']['label']['table-col-visible'], 'VW_EDIT_COL_LABEL' => $wpbi_dialog['form']['label']['table-col-label'], 'VW_EDIT_COL_ISTIME' => $wpbi_dialog['form']['label']['table-col-istime'], 'LBL_BTN_ADD' => $wpbi_dialog['button']['label']['save'], 'LBL_BTN_TEST' => $wpbi_dialog['button']['label']['test'], 'P_VW_QY' => $wpbi_settings['parameter']['qy_id'], 'V_VW_QY' => $vo_table->query_id, 'P_VW_ID' => $wpbi_settings['parameter']['tb-id'], 'V_VW_ID' => $vo_table->id, 'P_VW_ACTION' => $wpbi_settings['parameter']['action'], 'V_EDIT_ACTION' => $wpbi_settings['value']['edit'], 'V_TEST_ACTION' => $wpbi_settings['value']['edit-test'], 'VW_TEST_RESULT' => $test_output, 'VW_EDIT_STYLE_DEFAULT_OPT' => $wpbi_dialog['form']['option']['table-style-default'], 'VW_EDIT_FORM_ACTION' => substr(substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1), 0, strpos(substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1), '&')), 'VW_EDIT_COLUMNS_OPTIONS' => $columns_html));
    wp_enqueue_script('datatables-jquery', $wpbi_url['datatables']['jquerymin']);
    //Parse tpl
    $template_site->pparse('css');
    $template_site->pparse('header');
    $template_site->pparse('tables-edit-2');
}
/**** Edit table: save modifications ***/
if ($_POST[$wpbi_settings['parameter']['action']] == $wpbi_settings['value']['edit'] && isset($_POST[$wpbi_settings['parameter']['tb-id']])) {
    //Insert table metadata
    $vo_new_table = new vo_table(NULL, $_POST[$wpbi_settings['parameter']['qy_id']], $_POST[$wpbi_settings['parameter']['tb-name']], $_POST[$wpbi_settings['parameter']['tb-title']], is_numeric($_POST[$wpbi_settings['parameter']['tb-row-pg']]) ? abs(intval($_POST[$wpbi_settings['parameter']['tb-row-pg']])) : $wpbi_settings['parameter']['page-interval'], $_POST[$wpbi_settings['parameter']['tb-style']], isset($_POST[$wpbi_settings['parameter']['tb-header']]) ? 1 : 0, isset($_POST[$wpbi_settings['parameter']['tb-footer']]) ? 1 : 0, isset($_POST[$wpbi_settings['parameter']['tb-download']]) ? 1 : 0, NULL, isset($_POST[$wpbi_settings['parameter']['tb-html-values']]) ? 1 : 0);
    $vo_old_table = new vo_table($_POST[$wpbi_settings['parameter']['tb-id']], NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    $dao_table = new dao_table($wpdb, $wpbi_sql['tname']['tables']);
    $dao_table->edit($vo_old_table, $vo_new_table);
    //Drop cols metadata
    $selected_tables = $_POST[$wpbi_settings['parameter']['tb-id']];
    $vo_tb_cols = new vo_tb_cols(NULL, $selected_tables, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    $dao_tb_cols = new dao_tb_cols($wpdb, $wpbi_sql['tname']['cols']);
    $dao_tb_cols->del($vo_tb_cols);
    //insert columns metadata
    for ($col_idx = 0; $col_idx < sizeof($_POST[$wpbi_settings['parameter']['tb-tx-column-tf']]); $col_idx++) {
        $vo_tb_cols = new vo_tb_cols(NULL, $selected_tables, $_POST[$wpbi_settings['parameter']['tb-tx-column-tf']][$col_idx], in_array($col_idx, $_POST[$wpbi_settings['parameter']['tb-cb-column-tf']]) ? 1 : 0);
        $dao_tb_cols = new dao_tb_cols($wpdb, $wpbi_sql['tname']['cols']);
        $dao_tb_cols->add($vo_tb_cols);
    }
}
?>
Example #3
0
function get_html_4_table($id)
{
    global $wpdb, $qy_table_databases, $qy_table_queries, $wpbi_sql, $wpbi_settings, $wpbi_url, $wpbi_dialog, $lng, $language, $template_site;
    $template_site->set_filenames(array('css' => $wpbi_url['tpl']['root-path'] . $wpbi_url['tpl']['css']));
    $table_id = $id;
    //id or key
    $search_by_key = false;
    if (!is_numeric($table_id)) {
        if (strlen($table_id) == 32 && strpos($table_id, ' ') === false) {
            $search_by_key = true;
        } else {
            return '<p>Could not create table. Wrong ID provided.</p>';
        }
    }
    $test_output = '';
    //Store the test output
    //Get table metadata
    $vo_table = new vo_table($table_id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, $table_id, NULL);
    $dao_table = new dao_table($wpdb, $wpbi_sql['tname']['tables']);
    $vo_table = $search_by_key ? $dao_table->select_by_key($vo_table) : $dao_table->select($vo_table);
    $vo_table = $vo_table[0];
    //Get cols metadata
    $selected_table = $vo_table->id;
    $vo_tb_cols = new vo_tb_cols(NULL, $selected_table, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    $dao_tb_cols = new dao_tb_cols($wpdb, $wpbi_sql['tname']['cols']);
    $vo_tb_cols = $dao_tb_cols->select($vo_tb_cols);
    //Get selected query
    $dao_query = new dao_query($wpdb, $wpbi_sql['tname']['queries']);
    $tgt_query = new vo_query($vo_table->query_id, NULL, NULL, NULL, NULL);
    $vo_query = $dao_query->select($tgt_query);
    $vo_query = $vo_query[0];
    //Select associated db
    $dao_database = new dao_database($wpdb, $wpbi_sql['tname']['databases']);
    $tgt_database = new vo_database($vo_query->db_id, NULL, NULL, NULL, NULL);
    $vo_database = $dao_database->select($tgt_database);
    $vo_database = $vo_database[0];
    //Create wpdb object and execute the query
    $my_test_db = new wpdb($vo_database->user, $vo_database->pass, $vo_database->name, $vo_database->host);
    $query = new query($vo_query->statement, $wpdb, $wpbi_sql['tname']['vars']);
    $total_rows = $my_test_db->get_results($query->count_qy_results(), 'ARRAY_N');
    $total_rows = intval($total_rows[0][0]);
    if ($total_rows == 0) {
        $test_output = $test_output . $wpbi_dialog['msg']['query']['no-records'];
    } else {
        //Add page navigation if requested
        if ($vo_table->rows_per_pg > 0) {
            //Page navigation
            $pagination = new pagination();
            $pagination->set_pagination_tpl_path($wpbi_url['tpl']);
            $pagination->set_pg_interval($vo_table->rows_per_pg);
            $pagination->set_pg_parameter($table_id . '_paged');
            $pagination->set_current_page(isset($_GET[$pagination->pg_parameter]) ? abs((int) $_GET[$pagination->pg_parameter]) : 1);
            $pagination->set_rows($total_rows);
            //$pagination->set_css_class(basename($vo_table->style_id,'.css'));
            $pagination->set_css_style(basename($vo_table->style_id, '.css'));
            $pagination->set_pagination_stats($wpbi_dialog['table']['pagination']['stats']);
            $pagination->set_paginate_links(paginate_links(array('base' => esc_url(add_query_arg($pagination->pg_parameter, '%#%')), 'format' => '', 'prev_text' => __($wpbi_dialog['table']['pagination']['prev_text']), 'next_text' => __($wpbi_dialog['table']['pagination']['next_text']), 'total' => ceil($pagination->rows / $pagination->pg_interval), 'current' => $pagination->current_page)));
            $pagination->initialize();
            $pagination_html = $pagination->get_html();
            //END page navigation
            //Execute query limitng the resultset
            $my_test_rows = $my_test_db->get_results($query->limit_qy_to($pagination->item_start - 1, $pagination->pg_interval), 'ARRAY_N');
        } else {
            $my_test_rows = $my_test_db->get_results($query->stmt, 'ARRAY_N');
        }
        //get columns
        $my_test_cols = array();
        $my_test_cols_visible = array();
        $col_idx = 0;
        foreach ($vo_tb_cols as $vo_tb_col) {
            array_push($my_test_cols, $vo_tb_col->col_label);
            if ($vo_tb_col->is_visible) {
                array_push($my_test_cols_visible, $col_idx);
            }
            $col_idx++;
        }
        //Output table
        $table = new table();
        $table->set_table_tpl_path($wpbi_url['tpl']);
        $table->set_table_pagination($pagination_html);
        $table->set_css_class(basename($vo_table->style_id, '.css'));
        $table->set_css_style(basename($vo_table->style_id, '.css'));
        $table->set_rows($my_test_rows);
        $table->set_cols($my_test_cols);
        $table->set_visible_cols($my_test_cols_visible);
        $table->set_title($vo_table->title);
        $table->has_header($vo_table->has_header);
        $table->has_footer($vo_table->has_footer);
        $table->set_can_download($vo_table->can_download);
        $table->encode_html(!$vo_table->encode_html);
        $test_output = $test_output . $table->get_html();
    }
    //Prepare output
    $template_site->assign_vars(array('TPL_CSS' => $wpbi_url['styles']['url'] . "tables/" . $table->css_style . '.css'));
    ob_start();
    $template_site->pparse('css');
    $css_output = ob_get_contents();
    ob_end_clean();
    return $css_output . $test_output;
}