/**
 * @return array|int
 * @throws Exception
 */
function gd_report_admin_page_new() {
    $datasource = gd_datasource_find($_GET['ds']);
    if ( !$datasource ) {
        return MENU_NOT_FOUND;
    }

    gd_datasource_set_active($datasource->name);

    if ( !gd_account_user_is_admin() && !gd_account_user_is_datasource_admin(null,gd_datasource_get_active()) ) {
        return MENU_ACCESS_DENIED;
    }

    drupal_add_library('gd_report_admin', 'GD_Admin_ReportSection_Builder');

    if ( !empty($_GET['title']) ) {
        $report = new stdClass();
        $report->title = check_plain($_GET['title']);
    } else {
        $report = null;
    }

    if ( !empty($_GET['dataset']) ) {
        $reportDataset = gd_data_controller_ui_metadata_get_dataset_ui_metadata($_GET['dataset']);
    } else {
        $reportDataset = null;
    }

    return gd_report_admin_page($report,$reportDataset);
}
/**
 * @return array
 */
function gd_dashboard_admin_page_new() {
    $datasource = gd_datasource_find($_GET['ds']);
    if ( !$datasource ) {
        return MENU_NOT_FOUND;
    }

    gd_datasource_set_active($datasource->name);

    if ( !gd_account_user_is_admin() && !gd_account_user_is_datasource_admin(null,gd_datasource_get_active()) ) {
        return MENU_ACCESS_DENIED;
    }

    drupal_add_library('gd_dashboard_admin', 'GD_Admin_DashboardSection_Builder');

    drupal_add_library('gd','datatables');
    drupal_add_library('gd','highcharts');
    drupal_add_js('sites/all/libraries/sparkline/jquery.sparkline.min.js');

    return gd_dashboard_admin_page();
}
<div id="gd-page">
    <div id="gd-nav">

        <div id="gd-navmain" class="container">
            <div class="row">
                <div class="col-md-4">
                    <?php if ($logo): ?>
                    <a tabindex="2" href="<?php print check_url($front_page); ?>" title="<?php print $site_name; ?>"><img class="gd-logo" id="gd-logo" src="<?php print $logo; ?>" alt="<?php print $site_name; ?>" /></a>
                    <?php endif; ?>
                </div>
                <div class="col-md-8">
                    <?php if ($logged_in) : ?>
                    <ul class="secondary-menu menulist pull-right">
                        <li class="first"><?php print l($user->firstname . ' ' . $user->lastname,'user/profile', array('attributes' => array('tabindex' => '3'))); ?></li>
                        <?php
                        if ( gd_account_user_is_admin() || gd_account_user_is_any_datasource_admin() ) {
                            if ( arg(0) == 'cp' ) {
                                print '<li>'.l("Dashboard Viewer","dashboards", array('query'=>array('ds'=>gd_datasource_find_active()),'attributes' => array('tabindex' => '4'))).'</li>';
                            } else {
                                print '<li>'.l("Control Panel","cp", array('attributes' => array('tabindex' => '4'))).'</li>';
                            }
                        } else {
                            print '<li>'.l("Dashboard Viewer","dashboards", array('attributes' => array('tabindex' => '4'))).'</li>';
                        }
                        ?>
                        <li class="last"><?php print l("Logout","user/logout",array('attributes' => array('tabindex' => '5'))); ?></li>
                    </ul>
                    <?php else : ?>
                    <ul class="menu pull-right">
                        <li class="last">
                            <?php
     borderWidth: 0,
     borderColor: "#fff",
     className: 'hchart-stats'
 },
 title: {
     text: 'Account Usage by Topic'
 },
 subtitle: {
     text: '(as of <?php echo date("m-d-Y"); ?>)',
     align: 'center'
 },
 xAxis: {
     categories: <?php echo $datamarts_list_js; ?>,
     labels: {
         formatter: function() {
             <?php if( gd_account_user_is_admin($user) ){ ?>
                 for (var i=0,count=datamartLinks.length;i<count;i+=1) {
                     if ( this.value == datamartLinks[i].title ) {
                         return '<a href="<?php echo GOVDASH_HOST; ?>' + datamartLinks[i].url +'">'+this.value+'</a>';
                     }
                 }
             <?php } else { ?>
                 for (var i=0,count=datamartLinks.length;i<count;i+=1) {
                     if ( this.value == datamartLinks[i].title ) {
                         return this.value;
                     }
                 }
             <?php } ?>
             return this.value;
         },
         align: 'right',
 * 
 * GovDashboard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GovDashboard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GovDashboard.  If not, see <http://www.gnu.org/licenses/>.
 */

if ( !gd_account_user_is_admin() && !gd_account_user_is_any_datasource_admin() ) {
    echo "<h3>Access Denied</h3>";
    drupal_exit();
}
?>
<div class="highcharts-title"><a href='javascript:;' onclick='parent.UserListActions.showActiveUsers()' target='_parent'><?php echo $user_chart['active']; ?> Active users</a> (<?php echo $user_chart['max']; ?> Max)</div>
<div class="highcharts-dial" id="active-user-dial"></div>

<script type="text/javascript">
    //<![CDATA[
    $(function() {
        function drawDial (options) {

            var renderTo = options.renderTo,
                    value = options.value,
                    centerX = options.centerX,
/**
 * @param $dashboardNode
 * @return array
 */
function gd_dashboard_build_page ( $dashboardNode ) {
    $event = new DefaultEvent();
    gd_datasource_set_active(get_node_field_value($dashboardNode,'field_dashboard_datasource'));

    ob_start();

    /**
     * Build current dashboard config
     */
    $DashboardConfig = new GD_DashboardConfig($dashboardNode,$_GET);
    drupal_add_library('gd_dashboard', 'GD_Dashboard_View');

    print '<div id="dashboard-view" class="gd-container">';


    // dashboard view
    echo '<div class="row">';

    echo '  <div class="col-md-6">';
    echo '    <h2>'.$dashboardNode->title.'</h2>';
    if ( get_node_field_value($dashboardNode, 'field_dashboard_desc') ) {
        echo '<p>'.get_node_field_value($dashboardNode, 'field_dashboard_desc').'</p>';
    }
    echo '  </div>';
    echo '  <div class="col-md-6">';

    echo '<div class="pull-right">';
    // is not public
    if ( arg(0) != 'public' ) {
        $edit = false;
        if ( gd_account_user_is_admin() || gd_account_user_is_datasource_admin(null,$DashboardConfig->getDatasource()) ) {
            $edit = true;
        }

        if ($edit) {
            echo '<a role="button" type="button" id="editButton" tabindex="100" class="btn btn-default gd-dashboard-editbtn" href="/cp/dashboard/'.$dashboardNode->nid.'">Edit</a>';
        }
    }

    if ( gd_dashboard_get_setting('export') && $DashboardConfig->isExportable() ) {
        echo ' <button role="button" type="button" id="exportButton" tabindex="100" class="btn btn-default gd-dashboard-exportbtn" data-dashboard="'.$dashboardNode->nid.'">Export</button>';
    }
    echo '</div>';

    echo '  </div>';
    echo '</div>';

    $options = array();
    if ( $DashboardConfig->isPublic() && arg(0) == 'public' ) {
        $options['public'] = TRUE;
        drupal_add_http_header('Cache-Control','no-transform,public,max-age=3600,s-maxage=3600');
        drupal_add_http_header('Expires',gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
    }
    $configView = new GD_DashboardView($DashboardConfig);
    print $configView->getView($options);

    print '</div>';

    $DashboardConfig->attachRequiredLibs(); // must be called after building view, or libs won't be set yet

    $page = array(
        '#show_messages' => false,
        '#theme' => 'page',
        '#type' => 'page',
        'content' => array(
            'system_main' => array(
                '#markup' => ob_get_clean()
            )
        ),
        'post_header' => array(
            '#markup' => ''
        ),
        'pre_content' => array(
            '#markup' => ''
        )
    );

    if (isset($dashboardNode->nid)) {
        $event->type = 1; // see gd_health_monitoring_database_install() for more details
        $event->owner = $dashboardNode->nid;

        EventRecorderFactory::getInstance()->record($event);
    }

    return $page;
}
 * You should have received a copy of the GNU General Public License
 * along with GovDashboard.  If not, see <http://www.gnu.org/licenses/>.
 */


if ( isset($_GET['datasource']) ) {
    $datasourceName = $_REQUEST['datasource'];
}

if ( isset($_POST['datasourceName']) ) {
    $datasourceName = $_POST['datasourceName'];
}

gd_datasource_set_active($datasourceName);

if ( !gd_account_user_is_admin() && !gd_account_user_is_datasource_admin(null,gd_datasource_get_active()) ) {
    echo "<h3>Access Denied</h3>";
    drupal_exit();
}

$datasource = gd_datasource_get($datasourceName);


$deleteWarningMessage = "Are you sure you want to delete \'".($datasource->publicName)."\'? ".
                        "This will delete all the associated Dashboards, Reports and Datasets from that topic. ".
                        "This action cannot be undone.";

if ( isset($_POST['editdatamart']) && $_POST['editdatamart'] == "yes" ) {

    $errors = array();
 public function canEdit () {
     if ( gd_account_user_is_admin() || gd_account_user_is_datasource_admin(null,$this->getDatasource()) ) {
         return true;
     }
     return false;
 }
/**
 * @param $operation
 * @return bool
 */
function gd_sync_resource_access ( $operation ) {
    return gd_account_user_is_admin();
}
<html lang="en">
<head>
    <?php
    global $theme;
    $path = drupal_get_path('theme', 'govdash_core');
    ?>
    <link rel="stylesheet" href="/sites/all/libraries/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href=<?php print $path."/css/style-cp.css"?> />

    <script src="/sites/all/libraries/jquery/jquery.min.js"></script>
    <script src="/sites/all/libraries/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<?php

if ( !gd_account_user_is_admin() ) {
    echo "<h3>Access Denied</h3>";
    drupal_exit();
}

$errors = array();
if ( isset($_POST['createdatamart']) && ($_POST['createdatamart'] == "yes") ) {

    // validate
    if ( trim($_POST['publicName']) == '' ) {
        $errors[] = "Name can not be blank";
    }

    if ( !gd_datasource_name_is_unique(trim($_POST['publicName'])) ) {
        $errors[] = "Topic Name already exists. Please rename the topic";
    }