public function __viewIndex()
 {
     $panels = $_POST['panel'];
     if (!is_array($panels)) {
         die;
     }
     foreach ($panels as $panel) {
         Extension_Dashboard::updatePanelOrder($panel['id'], $panel['placement'], $panel['sort_order']);
     }
     die;
 }
    /**
     * Builds the content view
     */
    public function build()
    {
        //if (!Symphony::isLoggedIn()) {
        //	Administration::instance()->throwCustomError(
        //		__('You are not authorised to access this page.'),
        //		__('Access Denied'),
        //		Page::HTTP_STATUS_UNAUTHORIZED
        //	);
        //	return;
        //}
        // this loads our classes
        $ext = Symphony::ExtensionManager()->create('dashboard');
        $ext = Symphony::ExtensionManager()->create('google_analytics_dashboard');
        // html head
        $this->Html->setDTD('<!DOCTYPE html>');
        $this->Html->setAttribute('lang', Lang::get());
        $this->Head->appendChild(new XMLElement('title', extension_google_analytics_dashboard::EXT_NAME));
        // html body
        $html = '';
        $PANEL_ID = General::sanitize($_REQUEST['p']);
        $panel = Extension_Dashboard::getPanel($PANEL_ID);
        $config = unserialize($panel['config']);
        $client = extension_google_analytics_dashboard::createClient($config, $panel['id']);
        if (!isset($config['at'])) {
            $config['at'] = $client->getAccessToken();
        }
        if (!($at = @json_decode($config['at']))) {
            $html = <<<HTML
<h1>Server auth failed! Please check your configuration.</h1>
HTML;
        } else {
            $html = <<<HTML
<style type="text/css">
\thtml {
\t\toverflow-x: hidden;
\t}
\tbody {
\t\tmargin: 0;
\t}
\t.hidden {
\t\tdisplay: none;
\t}
</style>
<section id="chart"></section>
<a href="#" id="toggleOptions"><small>Options</small></a>
<section id="view-selector" class="hidden"></section>
<script>
(function (g) {
g.each = function (a, cb) {
\tArray.prototype.forEach.call(a, cb);
};
g.\$ = function (sel, cb) {
\tvar col = document.querySelectorAll(sel);
\tif (!!cb) {
\t\teach(col, cb);
\t}
\treturn col;
};
g.\$.remove = function (elem) {
\telem.parentNode.removeChild(elem);
};
})(window);
</script>
<script>
(function(w,d,s,g,js,fjs){
  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
  js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
  js.src='https://apis.google.com/js/platform.js';
  fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
}(window,document,'script'));
</script>
<script>
gapi.analytics.ready(function() {
  gapi.analytics.auth.authorize({
    serverAuth: {
      access_token: '{$at->access_token}'
    }
  });
  var viewSelector = new gapi.analytics.ViewSelector({
    container: 'view-selector'
  });
  var chart = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'dimensions': '{$config["dimensions"]}',
      'metrics': '{$config["metrics"]}',
      'start-date': '{$config["start-date"]}',
      'end-date': '{$config["end-date"]}',
    },
    chart: {
      type: '{$config["type"]}',
      container: 'chart',
      options: {
        width: '100%',
        height: '100%'
      }
    }
  });
  viewSelector.on('change', function(ids) {
    var newIds = {
      query: {
        ids: ids
      }
    }
    chart.set(newIds).execute();
  });
  chart.on('error', function (err) {
    alert(err.error.message);
  });
  viewSelector.execute();
  window.addEventListener('resize', function () {
    viewSelector.execute();
  });
});
</script>

<script>
var toggleOptions = function (e) {
\t\$('#view-selector', function (elem) {
\t\telem.classList.toggle('hidden');
\t});
\te.preventDefault();
};
\$('#toggleOptions', function (elem) {
\telem.addEventListener('click', toggleOptions);
});
</script>

HTML;
        }
        $this->Body->setValue($html);
    }
 public function view()
 {
     if (isset($_POST['action']['submit'])) {
         $this->panelErrors = Extension_Dashboard::validatePanelOptions($this->panelType, $this->panelId);
         if (empty($this->panelErrors)) {
             $this->panelId = Extension_Dashboard::savePanel(array('id' => $this->panelId, 'label' => $this->panelLabel, 'placement' => $this->panelPlacement, 'type' => $this->panelType), $this->panelConfig);
         }
     } else {
         if (isset($_POST['action']['delete'])) {
             Extension_Dashboard::deletePanel($this->panelId);
             $this->_Result->setAttribute('id', $this->panelId);
             $this->_Result->setAttribute('placement', $this->panelPlacement);
             return;
         }
     }
     if (isset($this->panelId) && !empty($this->panelId)) {
         $this->panelConfig = Extension_Dashboard::getPanel($this->panelId);
         $this->panelLabel = $this->panelConfig['label'];
         $this->panelPlacement = $this->panelConfig['placement'];
     }
     if (isset($_POST['action']['submit']) && empty($this->panelErrors)) {
         $html = Extension_Dashboard::buildPanelHTML($this->panelConfig);
         $class = $html->getAttribute('class');
         $html->setAttribute('class', $class . ' new-panel');
         $this->_Result->setAttribute('id', $this->panelId);
         $this->_Result->setAttribute('placement', $this->panelPlacement);
         $this->_Result->setValue(sprintf('<![CDATA[%s]]>', $html->generate()));
     } else {
         $this->addHeaderToPage('Content-Type', 'text/html');
         $container = new XMLElement('form');
         $container->setAttribute('id', 'save-panel');
         $container->appendChild(new XMLElement('div', NULL, array('class' => 'top')));
         $heading = new XMLElement('h3', __('Configuration') . ' <span>' . (isset($this->panelLabel) ? $this->panelLabel : __('Untitled Panel')) . '<span>');
         $container->appendChild($heading);
         $config_options = Extension_Dashboard::buildPanelOptions($this->panelType, $this->panelId, $this->panelErrors);
         $primary = new XMLElement('div', NULL, array('class' => 'panel-config'));
         $fieldset = new XMLElement('fieldset', NULL, array('class' => 'settings'));
         $legend = new XMLElement('legend', __('General'));
         $fieldset->appendChild($legend);
         $group = new XMLElement('div', NULL, array('class' => 'group'));
         $group->appendChild(Widget::Label(__('Name'), Widget::Input('label', $this->panelLabel)));
         $group->appendChild(Widget::Label(__('Placement'), Widget::Select('placement', array(array('primary', $this->panelPlacement == 'primary', __('Main content')), array('secondary', $this->panelPlacement == 'secondary', __('Sidebar'))))));
         $fieldset->appendChild($group);
         $primary->appendChild($fieldset);
         if ($config_options) {
             $primary->appendChild($config_options);
         }
         $actions = new XMLElement('div', NULL, array('class' => 'actions'));
         $actions->appendChild(Widget::Input('action[submit]', __('Save Panel'), 'submit', array('class' => 'button create')));
         $actions->appendChild(Widget::Input('action[cancel]', __('Cancel'), 'submit'));
         if ($this->panelId) {
             $actions->appendChild(new XMLElement('button', __('Delete Panel'), array('class' => 'delete', 'name' => 'action[delete]')));
         }
         $primary->appendChild($actions);
         $primary->appendChild(Widget::Input('id', $this->panelId, 'hidden'));
         $primary->appendChild(Widget::Input('type', $this->panelType, 'hidden'));
         $container->appendChild($primary);
         if (Symphony::isXSRFEnabled()) {
             $container->prependChild(XSRF::formToken());
         }
         $this->_Result = $container;
     }
 }
Example #4
0
 public function __viewIndex()
 {
     $this->setPageType('form');
     $this->setTitle(__('Symphony') . ' &ndash; ' . __('Dashboard'));
     $this->addScriptToHead(URL . '/extensions/dashboard/assets/jquery-ui-1.11.4.custom.min.js', 29421);
     $this->addStylesheetToHead(URL . '/extensions/dashboard/assets/dashboard.index.css', 'screen', 29422);
     $this->addScriptToHead(URL . '/extensions/dashboard/assets/dashboard.index.js', 29423);
     // https://github.com/symphonycms/symphony-2/wiki/Migration-Guide-to-2.5-for-Developers#properties
     $author = null;
     if (is_callable(array('Symphony', 'Author'))) {
         $author = Symphony::Author();
     } else {
         $author = Administration::instance()->Author;
     }
     // Add welcome message
     $hour = date('H');
     $welcome = __('Nice to meet you');
     if ($author->get('last_see') != NULL) {
         if ($hour < 10) {
             $welcome = __('Good morning');
         } elseif ($hour < 17) {
             $welcome = __('Welcome back');
         } else {
             $welcome = __('Good evening');
         }
     }
     $panel_types = array();
     /**
      * Ask panel extensions to list their panel types.
      *
      * @delegate DashboardPanelTypes
      * @param string $context
      * '/backend/'
      * @param array $types
      */
     Symphony::ExtensionManager()->notifyMembers('DashboardPanelTypes', '/backend/', array('types' => &$panel_types));
     if ($author->isDeveloper()) {
         $panel_types_options = array(array('', FALSE, __('New Panel')));
         natsort($panel_types);
         foreach ($panel_types as $handle => $name) {
             $panel_types_options[] = array($handle, false, $name);
         }
         $actions = array();
         $actions[] = Widget::Select('panel-type', $panel_types_options);
         $actions[] = Widget::Anchor(__('Enable Editing'), '#', __('Disable Editing'), 'edit-mode button');
     }
     $this->Form->setAttribute('class', 'two columns');
     $this->appendSubheading($welcome . ', ' . $author->get('first_name'), $actions);
     $this->insertDrawer(Widget::Drawer('dashboard', 'Dashboard', new XMLElement('span', ''), 'closed', time()), 'horizontal', FALSE);
     $container = new XMLElement('div', NULL, array('id' => 'dashboard'));
     $primary = new XMLElement('div', NULL, array('class' => 'primary column sortable-container'));
     $secondary = new XMLElement('div', NULL, array('class' => 'secondary column sortable-container'));
     $panels = Extension_Dashboard::getPanels();
     foreach ($panels as $p) {
         $html = Extension_Dashboard::buildPanelHTML($p);
         switch ($p['placement']) {
             case 'primary':
                 $primary->appendChild($html);
                 break;
             case 'secondary':
                 $secondary->appendChild($html);
                 break;
         }
     }
     $container->appendChild($primary);
     $container->appendChild($secondary);
     $this->Form->appendChild($container);
 }