Commit 57b46549 authored by Robert Lyon's avatar Robert Lyon

Bug 1691910: Consolidating the admin and institution statistics pages

Making the admin/statistics.php obsolete and getting admin/users/statistics.php
to do the work.

The institution 'all' shows the site statistics

Sponsored by University of Sussex and Dublin City University

behatnotneeded

Change-Id: Ic2fb9d4ef355fdc5e5527c1ce776463d821c0c08
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 75f4fd25
......@@ -17,7 +17,7 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php');
require(get_config('libroot') . 'statistics.php');
if (get_config('installed')) {
define('TITLE', get_string('administration', 'admin'));
validate_theme(get_config('theme'));
......@@ -26,7 +26,6 @@ else {
define('TITLE', get_string('installation', 'admin'));
}
require(get_config('libroot') . 'upgrade.php');
require_once(get_config('libroot') . 'registration.php');
$upgrades = check_upgrades();
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('STAFF', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'registration.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$extradata = json_decode(param_variable('extradata'));
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views', 'content', 'historical', 'institutions', 'logins');
if (!in_array($type, $subpages)) {
$type = 'users';
}
if ($type == 'historical') {
$field = (isset($extradata->field) ? $extradata->field : 'count_usr');
}
if ($type == 'institutions' || $type == 'logins') {
$sort = (isset($extradata->sort) ? $extradata->sort : 'displayname');
$sortdesc = (isset($extradata->sortdesc) ? $extradata->sortdesc : false);
$start = param_alphanumext('start', null);
$end = param_alphanumext('end', null);
}
switch ($type) {
case 'logins':
$data = institution_logins_statistics($limit, $offset, $sort, $sortdesc, $start, $end);
$data = $data['table'];
break;
case 'institutions':
$data = institution_comparison_stats_table($limit, $offset, $sort, $sortdesc);
break;
case 'historical':
$data = historical_stats_table($limit, $offset, $field);
break;
case 'content':
$data = content_stats_table($limit, $offset);
break;
case 'groups':
$data = group_stats_table($limit, $offset);
break;
case 'views':
$data = view_stats_table($limit, $offset);
break;
case 'users':
default:
$data = user_stats_table($limit, $offset);
}
json_reply(false, (object) array('message' => false, 'data' => $data));
<?php
/**
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('STAFF', 1);
define('MENUITEM', 'adminhome/statistics');
require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php');
define('TITLE', get_string('sitestatistics', 'admin'));
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views', 'content', 'historical', 'institutions', 'logins');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
}
if ($type == 'historical') {
$field = param_alphanumext('field', 'count_usr');
}
if ($type == 'institutions' || $type == 'logins') {
$sort = param_alphanumext('sort', 'displayname');
$sortdesc = param_boolean('sortdesc');
$start = param_alphanumext('start', null);
$end = param_alphanumext('end', null);
}
$sitedata = site_statistics(true);
switch ($type) {
case 'logins':
$data = institution_logins_statistics($limit, $offset, $sort, $sortdesc, $start, $end);
break;
case 'institutions':
$data = institution_comparison_statistics($limit, $offset, $sort, $sortdesc);
break;
case 'historical':
$data = historical_statistics($limit, $offset, $field);
break;
case 'content':
$data = content_statistics($limit, $offset);
break;
case 'groups':
$data = group_statistics($limit, $offset);
break;
case 'views':
$data = view_statistics($limit, $offset);
break;
case 'users':
default:
$data = user_statistics($limit, $offset, $sitedata);
}
$js = <<< EOF
jQuery(function() {
{$data['table']['pagination_js']}
});
EOF;
$smarty = smarty(array('paginator','js/chartjs/Chart.min.js'));
setpageicon($smarty, 'icon-area-chart');
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('sitedata', $sitedata);
$smarty->assign('type', $type);
$smarty->assign('subpages', $subpages);
$smarty->assign('subpagedata', $data);
$smarty->display('admin/statistics.tpl');
......@@ -14,38 +14,33 @@ define('INSTITUTIONALSTAFF', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require(get_config('libroot') . 'registration.php');
require(get_config('libroot') . 'statistics.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$extradata = json_decode(param_variable('extradata'));
$institution = (isset($extradata->institution) ? $extradata->institution : 'mahara');
$type = param_alpha('type', 'users');
$subpages = array('users', 'views', 'content', 'historical');
if (!in_array($type, $subpages)) {
$type = 'users';
}
if ($type == 'historical') {
$field = (isset($extradata->field) ? $extradata->field : 'count_members');
$institution = param_alphanum('institution', null);
if (empty($institution)) {
if (isset($extradata->institution)) {
$institution = $extradata->institution;
}
else if ($USER->get('admin') || $USER->get('staff')) {
$institution = 'all';
}
else {
$institution = 'mahara';
}
}
$institutiondata = institution_statistics($institution, true);
switch ($type) {
case 'historical':
$data = institution_historical_stats_table($limit, $offset, $field, $institutiondata);
break;
case 'content':
$data = institution_content_stats_table($limit, $offset, $institutiondata);
break;
case 'views':
$data = institution_view_stats_table($limit, $offset, $institutiondata);
break;
case 'users':
default:
$data = institution_user_stats_table($limit, $offset, $institutiondata);
}
json_reply(false, (object) array('message' => false, 'data' => $data));
$type = param_alpha('type', 'users');
$extraparams = new stdClass();
$extraparams->type = $type;
$extraparams->offset = param_integer('offset', 0);
$extraparams->limit = param_integer('limit', 10);
$extraparams->sort = isset($extradata->sort) ? $extradata->sort : 'displayname';
$extraparams->sortdesc = isset($extradata->sortdesc) ? true : false;
$extraparams->start = param_alphanumext('start', null);
$extraparams->end = param_alphanumext('end', null);
$extraparams->field = isset($extradata->field) ? $extradata->field : (($institution == 'all') ? 'count_usr' : 'count_members');
list($subpages, $institutiondata, $subpagedata) = display_statistics($institution, $type, $extraparams);
json_reply(false, (object) array('message' => false, 'data' => $subpagedata['table']));
......@@ -14,7 +14,7 @@ define('INSTITUTIONALSTAFF', 1);
define('MENUITEM', 'manageinstitutions/statistics');
require(dirname(dirname(dirname(__FILE__))).'/init.php');
require(get_config('libroot') . 'registration.php');
require(get_config('libroot') . 'statistics.php');
require_once('institution.php');
if (!is_logged_in()) {
......@@ -31,7 +31,7 @@ if (!empty($institution)) {
}
if (!$notallowed) {
$institutionelement = get_institution_selector(true, false, true, get_config('staffstats'));
$institutionelement = get_institution_selector(true, false, true, get_config('staffstats'), ($USER->get('admin') || $USER->get('staff')));
}
if (empty($institutionelement) || $notallowed) {
......@@ -47,6 +47,7 @@ if (!$institution || !$USER->can_edit_institution($institution, true)) {
else if (!empty($institution)) {
$institutionelement['defaultvalue'] = $institution;
}
$institutionselector = pieform(array(
'name' => 'usertypeselect',
'class' => 'form-inline',
......@@ -55,42 +56,32 @@ $institutionselector = pieform(array(
)
));
define('TITLE', get_string('institutionstatisticsfor', 'admin', get_field('institution', 'displayname', 'name', $institution)));
$type = param_alpha('type', 'users');
$subpages = array('users', 'views', 'content', 'historical');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
$showall = ($institution == 'all') ? true : false;
if ($showall) {
define('TITLE', get_string('statisticsforallinstitutions', 'admin'));
$icon = 'icon-area-chart';
}
if ($type == 'historical') {
$field = param_alphanumext('field', 'count_members');
else {
define('TITLE', get_string('institutionstatisticsfor', 'admin', get_field('institution', 'displayname', 'name', $institution)));
$icon = 'icon-university';
}
$institutiondata = institution_statistics($institution, true);
switch ($type) {
case 'historical':
$data = institution_historical_statistics($limit, $offset, $field, $institutiondata);
break;
case 'content':
$data = institution_content_statistics($limit, $offset, $institutiondata);
break;
case 'views':
$data = institution_view_statistics($limit, $offset, $institutiondata);
break;
case 'users':
default:
$data = institution_user_statistics($limit, $offset, $institutiondata);
}
$type = param_alpha('type', 'users');
$extraparams = new stdClass();
$extraparams->type = $type;
$extraparams->offset = param_integer('offset', 0);
$extraparams->limit = param_integer('limit', 10);
$extraparams->sort = param_alphanumext('sort', 'displayname');
$extraparams->sortdesc = param_boolean('sortdesc');
$extraparams->start = param_alphanumext('start', null);
$extraparams->end = param_alphanumext('end', null);
list($subpages, $institutiondata, $subpagedata) = display_statistics($institution, $type, $extraparams);
$wwwroot = get_config('wwwroot');
$js = <<< EOF
jQuery(function ($) {
{$data['table']['pagination_js']}
{$subpagedata['table']['pagination_js']}
function reloadStats() {
window.location.href = '{$wwwroot}admin/users/statistics.php?institution='+$('#usertypeselect_institution').val() +'&type={$type}';
......@@ -101,15 +92,14 @@ jQuery(function ($) {
EOF;
$smarty = smarty(array('paginator','js/chartjs/Chart.min.js'));
setpageicon($smarty, 'icon-university');
setpageicon($smarty, $icon);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('institutiondata', $institutiondata);
$smarty->assign('type', $type);
$smarty->assign('subpages', $subpages);
$smarty->assign('subpagedata', $data);
$smarty->assign('showall', ($showall ? '_all' : ''));
$smarty->assign('subpagedata', $subpagedata);
$smarty->assign('institutionselector', $institutionselector);
$smarty->display('admin/users/statistics.tpl');
......@@ -20,8 +20,9 @@ if (!defined('CRON')) {
json_headers();
$validtypes = array('Line', 'Bar', 'Radar', 'PolarArea', 'Pie', 'Doughnut');
$type = ucfirst(param_alphanum('type', false));
if (!in_array($type, $validtypes)) {
$search_array = array_combine(array_map('strtolower', $validtypes), $validtypes);
$type = strtolower(param_alphanum('type', false));
if (empty($search_array[$type])) {
json_reply('missingparameter', '\'' . $type . '\' is not a valid graph type');
}
$graph = param_alphanumext('graph', null);
......@@ -31,13 +32,13 @@ if (!defined('CRON')) {
$extradata = json_decode($extradata);
require_once(get_config('libroot') . 'graph.php');
require_once(get_config('libroot') . 'registration.php');
require_once(get_config('libroot') . 'statistics.php');
if (!function_exists($graph) || !in_array($graph, allowed_graph_functions())) {
json_reply('invalidparameter', 'Cannot call graph function \'' . $graph . '\'');
}
else {
$data = ($extradata) ? $graph($type, $extradata) : $graph($type);
$data = ($extradata) ? $graph($search_array[$type], $extradata) : $graph($search_array[$type]);
if (empty($data)) {
$data['empty'] = true;
json_reply(false, array('data' => $data));
......
......@@ -266,8 +266,7 @@ $string['reopensitedetail'] = 'Your site is closed. Site administrators may stay
// Statistics
$string['siteinformation'] = 'Site information';
$string['viewfullsitestatistics'] = 'View full site statistics';
$string['sitestatistics'] = 'Site statistics';
$string['siteinstalled'] = 'Site installed';
$string['institutioncreated_all'] = 'Site installed';
$string['databasesize'] = 'Database size';
$string['diskusage'] = 'Disk usage';
$string['maharaversion'] = 'Mahara version';
......@@ -1307,3 +1306,5 @@ $string['cli_lang_branch'] = 'Mahara series version to fetch langpacks for serie
$string['withselectedcontentexport'] = 'Re-queue items into the export queue';
$string['withselectedcontentdelete'] = 'Delete selected items from the export queue';
$string['statisticsforallinstitutions'] = 'Statistics for all institutions';
\ No newline at end of file
......@@ -3,5 +3,5 @@
<h3>Login statistics</h3>
<p>By default you see the logins for the previous calendar month. If you view this page in April, you will see the results for March.</p>
<p>To alter the results time period you can add a <strong>'start'</strong> and an <strong>'end'</strong> option to the URL, e.g.</p>
<p>'admin/statistics.php?type=logins&start=2015-01-01&end=2015-04-30'</p>
<p>'admin/users/statistics.php?type=logins&start=2015-01-01&end=2015-04-30'</p>
<p>This will return the results for the 4-month period of 1 January to 30 April 2015.</p>
......@@ -5000,5 +5000,10 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2017052900) {
log_debug('Clear menu cache for removal of menu items');
clear_menu_cache();
}
return $status;
}
......@@ -840,7 +840,18 @@ class Institution {
}
}
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false) {
/**
* Returns an institution dropdown selector
*
* @param bool $includedefault To include the 'mahara' institution in list
* @param bool $assumesiteadmin To call this function like you had site admin privileges
* @param bool $includesitestaff To allow site staff to see dropdown like the site admin would
* @param bool $includeinstitutionstaff To allow institution staff to see dropdown like institution admin would
* @param bool $allselector To add an 'all' option to the dropdown where it makes sense, eg in institution statistics page
*
* @return null or array suitable for pieform element
*/
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false, $allselector=false) {
global $USER;
if (($assumesiteadmin || $USER->get('admin')) || ($includesitestaff && $USER->get('staff'))) {
......@@ -883,6 +894,9 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false
}
$options = array();
if ($allselector) {
$options['all'] = get_string('Allinstitutions', 'mahara');
}
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
}
......
......@@ -4085,7 +4085,7 @@ function cron_institution_registration_data() {
* Cronjob to save weekly site data locally
*/
function cron_site_data_weekly() {
require_once(get_config('libroot') . 'registration.php');
require_once(get_config('libroot') . 'statistics.php');
$current = site_data_current();
$time = db_format_timestamp(time());
......@@ -4107,7 +4107,7 @@ function cron_site_data_weekly() {
}
function cron_site_data_daily() {
require_once(get_config('libroot') . 'registration.php');
require_once(get_config('libroot') . 'statistics.php');
$current = site_data_current();
$time = db_format_timestamp(time());
......@@ -4191,7 +4191,7 @@ function cron_site_data_daily() {
}
function cron_institution_data_weekly() {
require_once(get_config('libroot') . 'registration.php');
require_once(get_config('libroot') . 'statistics.php');
foreach (get_column('institution', 'name') as $institution) {
$current = institution_data_current($institution);
$time = db_format_timestamp(time());
......@@ -4214,7 +4214,7 @@ function cron_institution_data_weekly() {
}
function cron_institution_data_daily() {
require_once(get_config('libroot') . 'registration.php');
require_once(get_config('libroot') . 'statistics.php');
foreach (get_column('institution', 'name') as $institution) {
$current = institution_data_current($institution);
$time = db_format_timestamp(time());
......
This diff is collapsed.
This diff is collapsed.
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017052300;
$config->version = 2017052900;
$config->series = '17.10';
$config->release = '17.10dev';
$config->minupgradefrom = 2012080604;
......
......@@ -2301,12 +2301,6 @@ function admin_nav() {
'title' => get_string('register'),
'weight' => 20,
),
'adminhome/statistics' => array(
'path' => 'adminhome/statistics',
'url' => 'admin/statistics.php',
'title' => get_string('sitestatistics', 'admin'),
'weight' => 30,
),
'configsite' => array(
'path' => 'configsite',
'url' => 'admin/site/options.php',
......@@ -2747,21 +2741,6 @@ function institutional_admin_nav() {
'weight' => 110,
),
);
if ($USER->get('staff')) {
$ret['adminhome'] = array(
'path' => 'adminhome',
'url' => 'admin/statistics.php',
'title' => get_string('site', 'admin'),
'weight' => 40,
'accesskey' => 'a',
);
$ret['adminhome/statistics'] = array(
'path' => 'adminhome/statistics',
'url' => 'admin/statistics.php',
'title' => get_string('statistics', 'admin'),
'weight' => 10,
);
};
// enable plugins to augment the institution admin menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
......@@ -2795,13 +2774,6 @@ function staff_nav() {
'weight' => 10,
'accesskey' => 'u',
),
'statistics' => array(
'path' => 'statistics',
'url' => 'admin/statistics.php',
'title' => get_string('sitestatistics', 'admin'),
'weight' => 20,
'accesskey' => 's',
),
'institutionalstatistics' => array(
'path' => 'statistics',
'url' => 'admin/users/statistics.php',
......
......@@ -87,9 +87,9 @@
{if $sitedata}
<div class="panel panel-info site-stats">
<h3 class="panel-heading">{$sitedata.name}: {str tag=siteinformation section=admin} <span class="icon icon-area-chart pull-right" role="presentation" aria-hidden="true"></span></h3>
{include file='admin/stats.tpl' full=0}
<a class="panel-footer text-small" href="{$WWWROOT}admin/statistics.php">{str tag=viewfullsitestatistics section=admin} <span class="icon icon-arrow-circle-right pull-right" role="presentation" aria-hidden="true"></span></a>
<h3 class="panel-heading">{$sitedata.displayname}: {str tag=siteinformation section=admin} <span class="icon icon-area-chart pull-right" role="presentation" aria-hidden="true"></span></h3>
{include file='admin/users/stats.tpl' institutiondata=$sitedata showall='_all'}
<a class="panel-footer text-small" href="{$WWWROOT}admin/users/statistics.php">{str tag=viewfullsitestatistics section=admin} <span class="icon icon-arrow-circle-right pull-right" role="presentation" aria-hidden="true"></span></a>
</div>
{/if}
......
{include file='header.tpl'}
{if $sitedata}
<div id="site-stats-wrap" class="panel-items js-masonry" data-masonry-options='{ "itemSelector": ".panel" }'>
<div class="panel panel-info">
<h3 class="panel-heading">{$sitedata.name}: {str tag=siteinformation section=admin} <span class="icon icon-info pull-right" role="presentation" aria-hidden="true"></span></h3>
{include file='admin/stats.tpl' cron=1}
</div>
<div class="panel panel-default double">
<div class="panel-heading">
<ul class="nav nav-pills">
{foreach from=$subpages item=subpage}
<li{if $subpage == $type} class="active"{/if}>
<a {if $subpage == $type}class="current-tab" {/if}href="{$WWWROOT}admin/statistics.php?type={$subpage}">{str tag=$subpage}<span class="accessible-hidden sr-only">({str tag=tab}{if $subpage == $type} {str tag=selected}{/if})</span></a>
</li>
{/foreach}
</ul>
</div>
<div class="subpage panel-body row" id="site-stats-wrap2">
<div id="statistics_table_container" class="col-md-12">
<h3>{$subpagedata.tabletitle}{if $subpagedata.help}{$subpagedata.help|safe}{/if}</h3>
{if $subpagedata.tablesubtitle}<div class="small">{$subpagedata.tablesubtitle}</div>{/if}
{if $subpagedata.table.count == 0}{else}
<div class="table-responsive">
<table id="statistics_table" class="table table-striped fullwidth">
<thead>
<tr>
{foreach from=$subpagedata.tableheadings item=heading}
<th{if $heading.class} class="{$heading.class}"{/if}>{if $heading.link}<a href="{$heading.link}">{/if}{$heading.name}{if $heading.link}</a>{/if}</th>
{/foreach}
</tr>
</thead>
<tbody>
{$subpagedata.table.tablerows|safe}
</tbody>
</table>
</div>
{$subpagedata.table.pagination|safe}
{/if}
</div>
{if $subpagedata.summary}
<div class="col-md-12 image-right">
{$subpagedata.summary|safe}
</div>
{/if}
</div>
{if $subpagedata.table.csv}
<a href="{$WWWROOT}download.php" class="panel-footer"><span class="icon icon-table" role="presentation" aria-hidden="true"></span> {str tag=exportstatsascsv section=admin}</a>
{/if}
</div>
</div>
{/if}
{include file='footer.tpl'}
{if $sitedata.weekly}
<div id="site-stats-graph" class="panel-body site-stats-graph">
<canvas class="graphcanvas" id="sitestatsgraph"></canvas>
<script type="application/javascript">
{literal}
jQuery(function() {
fetch_graph_data({'id':'sitestatsgraph','type':'line','graph':'graph_site_data_weekly'});
});
{/literal}
</script>
</div>
{/if}
<table class="table">
<tr>
<th>{str tag=siteinstalled section=admin}</th>