function exports_reports_view($group_id = false)
{
    global $wpdb;
    $has_full_access = exports_reports_current_user_can_any('exports_reports_full_access');
    if (is_super_admin() || !$has_full_access && exports_reports_has_role('administrator')) {
        $has_full_access = true;
    }
    if ('exports-reports' != $_GET['page']) {
        if (empty($group_id)) {
            $group_id = (int) str_replace('exports-reports-group-', '', $_GET['page']);
        }
        $group = $wpdb->get_results('SELECT `id`,`name` FROM `' . EXPORTS_REPORTS_TBL . 'groups` WHERE `disabled`=0 AND `id`=' . absint($group_id));
        if (empty($group)) {
            return false;
        }
    } else {
        $group_id = 0;
        $groups = $wpdb->get_results('SELECT `id`,`name` FROM `' . EXPORTS_REPORTS_TBL . 'groups` WHERE `disabled`=0 ORDER BY `weight`,`name`');
        if (!empty($groups)) {
            foreach ($groups as $group) {
                if (0 < $group_id) {
                    break;
                }
                $reports = $wpdb->get_results('SELECT `id`,`role_access` FROM `' . EXPORTS_REPORTS_TBL . 'reports` WHERE `disabled`=0 AND `group`=' . $group->id . ' ORDER BY `weight`,`name` LIMIT 1');
                if (@count($reports) > 0) {
                    foreach ($reports as $report) {
                        if ($has_full_access || exports_reports_current_user_can_any('exports_reports_view') || exports_reports_current_user_can_any('exports_reports_view_group_' . $group->id) || exports_reports_current_user_can_any('exports_reports_view_report_' . $report->id)) {
                            $group_id = $group->id;
                            break;
                        }
                        $roles = explode(',', $report->role_access);
                        if (empty($roles)) {
                            continue;
                        }
                        foreach ($roles as $role) {
                            if (exports_reports_has_role($role)) {
                                $group_id = $group->id;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if (empty($group_id)) {
        return false;
    }
    $reports = $wpdb->get_results('SELECT * FROM `' . EXPORTS_REPORTS_TBL . 'reports` WHERE `group`=' . $group_id . ' ORDER BY `weight`,`name`');
    if (empty($reports)) {
        return false;
    }
    $selectable_reports = array();
    $current_report = false;
    foreach ($reports as $report) {
        if ($has_full_access || exports_reports_current_user_can_any('exports_reports_view') || exports_reports_current_user_can_any('exports_reports_view_group_' . $group_id) || exports_reports_current_user_can_any('exports_reports_view_report_' . $report->id)) {
            if (false === $current_report) {
                $current_report = $report->id;
            }
            $selectable_reports[$report->id] = array();
            $selectable_reports[$report->id]['name'] = $report->name;
            $selectable_reports[$report->id]['sql_query'] = $report->sql_query;
            $selectable_reports[$report->id]['sql_query_count'] = $report->sql_query_count;
            $selectable_reports[$report->id]['default_none'] = $report->default_none;
            $selectable_reports[$report->id]['export'] = 0 == $report->disable_export ? true : false;
            $selectable_reports[$report->id]['field_data'] = $report->field_data;
            continue;
        }
        $roles = explode(',', $report->role_access);
        if (empty($roles)) {
            continue;
        }
        foreach ($roles as $role) {
            if (exports_reports_has_role($role)) {
                if (false === $current_report) {
                    $current_report = $report->id;
                }
                $selectable_reports[$report->id] = array();
                $selectable_reports[$report->id]['name'] = $report->name;
                $selectable_reports[$report->id]['sql_query'] = $report->sql_query;
                $selectable_reports[$report->id]['sql_query_count'] = $report->sql_query_count;
                $selectable_reports[$report->id]['default_none'] = $report->default_none;
                $selectable_reports[$report->id]['export'] = 0 == $report->disable_export ? true : false;
                $selectable_reports[$report->id]['field_data'] = $report->field_data;
            }
        }
    }
    if (empty($selectable_reports)) {
        return false;
    }
    if (isset($_GET['report']) && isset($selectable_reports[$_GET['report']])) {
        $current_report = $_GET['report'];
    }
    require_once EXPORTS_REPORTS_DIR . 'wp-admin-ui/Admin.class.php';
    $options = array();
    $options['css'] = EXPORTS_REPORTS_URL . 'assets/admin.css';
    $options['readonly'] = true;
    $options['identifier'] = true;
    $options['export'] = $selectable_reports[$current_report]['export'];
    $options['search'] = strlen($selectable_reports[$current_report]['field_data']) > 0 ? true : false;
    $options['default_none'] = 1 == $selectable_reports[$current_report]['default_none'] ? true : false;
    $options['sql'] = trim($selectable_reports[$current_report]['sql_query']);
    $options['sql_count'] = trim($selectable_reports[$current_report]['sql_query_count']);
    if (empty($options['sql_count'])) {
        unset($options['sql_count']);
    }
    $options['item'] = $options['items'] = $selectable_reports[$current_report]['name'];
    $options['icon'] = EXPORTS_REPORTS_URL . 'assets/icons/32.png';
    $options['heading'] = array('manage' => 'View Report:');
    $field_data = @json_decode($selectable_reports[$current_report]['field_data'], true);
    if (is_array($field_data) && !empty($field_data)) {
        $options['columns'] = array();
        foreach ($field_data as $field) {
            $field = exports_reports_field_defaults($field);
            $options['columns'][$field['name']] = array();
            if (0 < strlen($field['real_name'])) {
                $options['columns'][$field['name']]['real_name'] = $field['real_name'];
            }
            if (0 < strlen($field['label'])) {
                $options['columns'][$field['name']]['label'] = $field['label'];
            }
            if (0 < strlen($field['filter_label'])) {
                $options['columns'][$field['name']]['filter_label'] = $field['filter_label'];
            }
            if (0 < strlen($field['custom_display'])) {
                $options['columns'][$field['name']]['custom_display'] = $field['custom_display'];
            }
            if (0 < strlen($field['type'])) {
                $options['columns'][$field['name']]['type'] = $field['type'];
            }
            if (1 == $field['hide_report']) {
                $options['columns'][$field['name']]['display'] = false;
            }
            if (1 == $field['hide_export']) {
                $options['columns'][$field['name']]['export'] = false;
            }
            if (1 == $field['search'] || 1 == $field['hide_report']) {
                $options['columns'][$field['name']]['search'] = false;
            } else {
                $options['columns'][$field['name']]['search'] = true;
            }
            if (1 == $field['filter']) {
                $options['columns'][$field['name']]['filter'] = true;
            }
            if (1 == $field['filter']) {
                if (0 < strlen($field['filter_default'])) {
                    $options['columns'][$field['name']]['filter_default'] = $field['filter_default'];
                }
                if (0 < strlen($field['filter_ongoing'])) {
                    $options['columns'][$field['name']]['date_ongoing'] = $field['filter_ongoing'];
                    if (0 < strlen($field['filter_ongoing_default'])) {
                        $options['columns'][$field['name']]['filter_ongoing_default'] = $field['filter_ongoing_default'];
                    }
                }
            }
            if (1 == $field['total_field']) {
                $options['columns'][$field['name']]['total_field'] = true;
            }
            if (1 == $field['group_related']) {
                $options['columns'][$field['name']]['group_related'] = true;
            }
            if ('related' == $field['type']) {
                if (0 < strlen($field['related'])) {
                    $options['columns'][$field['name']]['related'] = $field['related'];
                }
                if (0 < strlen($field['related_field'])) {
                    $options['columns'][$field['name']]['related_field'] = $field['related_field'];
                }
                if (0 < strlen($field['related_sql'])) {
                    $options['columns'][$field['name']]['related_sql'] = $field['related_sql'];
                }
            }
        }
    }
    $options['report_id'] = $current_report;
    $options = apply_filters('exports_reports_report_options', $options, $current_report);
    $admin = new WP_Admin_UI($options);
    if (1 < count($selectable_reports)) {
        ?>
		<div style="background-color:#E7E7E7;border:1px solid #D7D7D7; padding:5px 15px;margin:15px 15px 0px 5px;">
			<strong style="padding-right:10px;">Exports and Reports:</strong>
			<label for="report" style="vertical-align:baseline;">Choose Report</label>
			<select id="report" onchange="document.location=this.value;">
				<?php 
        foreach ($selectable_reports as $report_id => $report) {
            ?>
					<option value="<?php 
            echo $admin->var_update(array('page' => $_GET['page'], 'report' => $report_id), false, false, true);
            ?>
"<?php 
            echo $current_report == $report_id ? ' SELECTED' : '';
            ?>
><?php 
            echo $report['name'];
            ?>
</option>
				<?php 
        }
        ?>
			</select>
		</div>
	<?php 
    }
    $admin->go();
}
示例#2
0
             if (0 < strlen($field['related_sql'])) {
                 $options['columns'][$field['name']]['related_sql'] = $field['related_sql'];
             }
         }
     }
 }
 $options['report_id'] = $report->id;
 if (!isset($_GET['action'])) {
     $_GET['action'] = 'export';
 } else {
     $_GET['action'] = 'manage';
 }
 $data = false;
 $download = false;
 ob_start();
 $admin = new WP_Admin_UI($options);
 $admin->action = 'export';
 if ('manage' == $_GET['action']) {
     if (isset($_GET['full']) && 1 == $_GET['full']) {
         $data = $admin->get_data(true);
     } else {
         $data = $admin->get_data();
     }
 } else {
     $admin->go();
     if ($admin->exported_file) {
         $data = array('export_file' => WP_ADMIN_UI_EXPORT_URL . '/' . $admin->exported_file, 'message' => 'Report exported');
         if (!empty($_GET['download'])) {
             $download = true;
         }
     } else {