Commit 37807c0e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Merge branch 'stats'

parents e650ca56 7fbc2280
......@@ -33,6 +33,7 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)).'/init.php');
require(get_config('libroot') . 'registration.php');
if (get_config('installed')) {
define('TITLE', get_string('administration', 'admin'));
}
......@@ -54,7 +55,7 @@ if (isset($upgrades['core']) && !empty($upgrades['core']->install)) {
}
if (!get_config('registration_lastsent')) {
$register = register_site();
$register = true;
}
$closed = get_config('siteclosedbyadmin');
......@@ -73,11 +74,18 @@ $closeform = pieform(array(
),
));
if (empty($upgrades)) {
$sitedata = site_statistics();
}
$smarty = smarty();
$smarty->assign('PAGEHEADING', hsc(get_string('administration', 'admin')));
// normal admin page starts here
$smarty->assign('upgrades', $upgrades);
if (isset($sitedata)) {
$smarty->assign('sitedata', $sitedata);
}
if (isset($register)) {
$smarty->assign('register', $register);
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'adminhome');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
require(dirname(dirname(__FILE__)).'/init.php');
require_once('pieforms/pieform.php');
require(get_config('libroot') . 'registration.php');
if (!get_config('registration_lastsent')) {
$register = register_site();
}
$smarty = smarty();
if (isset($register)) {
$smarty->assign('register', $register);
}
$smarty->display('admin/registersite.tpl');
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 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');
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views');
if (!in_array($type, $subpages)) {
$type = 'users';
}
switch ($type) {
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
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'adminhome');
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');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
}
$sitedata = site_statistics(true);
switch ($type) {
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
addLoadEvent(function () {
{$data['table']['pagination_js']}
});
EOF;
$smarty = smarty(array('paginator'));
$smarty->assign('PAGEHEADING', hsc(TITLE));
$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');
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)).'/init.php');
$type = param_alpha('type');
switch ($type) {
case 'weekly':
case 'institutions':
case 'viewtypes':
case 'grouptypes':
$maxage = 3600;
header('Content-type: ' . 'image/png');
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
readfile(get_config('dataroot') . 'images/' . $type . '.png');
exit;
}
?>
......@@ -337,49 +337,17 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
require_once(get_config('libroot') . 'institution.php');
if (!$USER->get('admin')) { // Filter the list for institutional admins
$where = '
WHERE ii.name IN (' . join(',', array_map('db_quote', $USER->get('admininstitutions'))) . ')';
$filter = $USER->get('admininstitutions');
$showdefault = false;
}
else {
$where = '';
$smarty->assign('siteadmin', true);
$defaultinstmembers = count_records_sql('
SELECT COUNT(u.id) FROM {usr} u LEFT OUTER JOIN {usr_institution} i ON u.id = i.usr
WHERE u.deleted = 0 AND i.usr IS NULL AND u.id != 0
');
}
$institutions = get_records_sql_assoc('
SELECT
ii.name,
ii.displayname,
ii.maxuseraccounts,
ii.suspended,
COALESCE(a.members, 0) AS members,
COALESCE(a.staff, 0) AS staff,
COALESCE(a.admins, 0) AS admins
FROM
{institution} ii
LEFT JOIN
(SELECT
i.name, i.displayname, i.maxuseraccounts,
COUNT(ui.usr) AS members, SUM(ui.staff) AS staff, SUM(ui.admin) AS admins
FROM
{institution} i
LEFT OUTER JOIN {usr_institution} ui ON (ui.institution = i.name)
LEFT OUTER JOIN {usr} u ON (u.id = ui.usr)
WHERE
(u.deleted = 0 OR u.id IS NULL)
GROUP BY
i.name, i.displayname, i.maxuseraccounts
) a ON (a.name = ii.name)' . $where . '
ORDER BY
ii.name = \'mahara\', ii.displayname', array());
if (isset($defaultinstmembers)) {
$institutions['mahara']->members = $defaultinstmembers;
$institutions['mahara']->staff = '';
$institutions['mahara']->admins = '';
$filter = false;
$showdefault = true;
}
$institutions = Institution::count_members($filter, $showdefault);
$smarty->assign('institutions', $institutions);
}
......
......@@ -300,6 +300,27 @@ class ArtefactTypeComment extends ArtefactType {
return $result;
}
public static function count_comments(&$viewids=null, &$artefactids=null) {
if (!empty($viewids)) {
return get_records_sql_assoc('
SELECT c.onview, COUNT(c.artefact) AS comments
FROM {artefact_comment_comment} c
WHERE c.onview IN (' . join(',', $viewids) . ') AND c.deletedby IS NULL
GROUP BY c.onview',
array()
);
}
if (!empty($artefactids)) {
return get_records_sql_assoc('
SELECT c.onartefact, COUNT(c.artefact) AS comments
FROM {artefact_comment_comment} c
WHERE c.onartefact IN (' . join(',', $artefactids) . ') AND c.deletedby IS NULL
GROUP BY c.onartefact',
array()
);
}
}
public static function last_public_comment($view=null, $artefact=null) {
if (!empty($artefact)) {
$where = 'c.onartefact = ?';
......
......@@ -91,6 +91,7 @@ class User {
'parentuser' => null,
'loginanyway' => false,
'sesskey' => '',
'ctime' => null,
);
$this->attributes = array();
......@@ -111,7 +112,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -148,7 +150,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -214,6 +217,7 @@ class User {
' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ',
' . db_format_tsfield('u.lastaccess', 'lastaccess') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . '
' . db_format_tsfield('u.ctime', 'ctime') . '
FROM {usr} u
LEFT JOIN {auth_remote_user} r ON u.id = r.localusr
WHERE
......@@ -234,7 +238,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -251,6 +256,14 @@ class User {
return $this;
}
/**
* Set stuff that needs to be initialised once before a user record is created.
*/
public function create() {
$this->set('ctime', time());
}
/**
* Take a row object from the usr table and populate this object with the
* values
......@@ -473,7 +486,7 @@ class User {
$this->stdclass = new StdClass;
reset($this->defaults);
foreach (array_keys($this->defaults) as $k) {
if ($k == 'expiry' || $k == 'lastlogin' || $k == 'lastlastlogin' || $k == 'lastaccess' || $k == 'suspendedctime') {
if ($k == 'expiry' || $k == 'lastlogin' || $k == 'lastlastlogin' || $k == 'lastaccess' || $k == 'suspendedctime' || $k == 'ctime') {
$this->stdclass->{$k} = db_format_timestamp($this->get($k));
} else {
$this->stdclass->{$k} = $this->get($k);//(is_null($this->get($k))? 'NULL' : $this->get($k));
......@@ -819,7 +832,8 @@ class LiveUser extends User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......
......@@ -127,11 +127,15 @@ $string['Register'] = 'Register';
$string['registrationfailedtrylater'] = 'Registation failed with error code %s. Please try again later.';
$string['registrationsuccessfulthanksforregistering'] = 'Registation successful - thanks for registering!';
$string['registeryourmaharasite'] = 'Register your Mahara Site';
$string['registeryourmaharasitesummary'] = '
<p>You can choose to register your Mahara Site with <a href="http://mahara.org/">mahara.org</a>, and help us to build up a picture of the Mahara installation base around the world. Registering will remove this notice.</p>
<p>You can register your site, and preview the information that will be sent on the <strong><a href="%sadmin/registersite.php">Site Registration page.</a></strong></p>';
$string['registeryourmaharasitedetail'] = '
<p>You can choose to register your Mahara Site with <a href="http://mahara.org/">mahara.org</a>. Registration is free, and helps us build up a picture of the Mahara installation base around the world.</p>
<p>You can see the information that will be sent to mahara.org - nothing that can personally identify any of your users will be sent.</p>
<p>If you tick &quot;send weekly updates&quot;, Mahara will automatically send an update to mahara.org once a week with your updated information.</p>
<p>Registering will remove this notice. You will be able to change whether you send weekly updates on the <a href="%sadmin/site/options.php">site options</a> page.</p>';
$string['siteregistered'] = 'Your site has been registered. You can turn weekly updates on and off on the <a href="%sadmin/site/options.php">site options</a> page.</p>';
// Close site
$string['Close'] = 'Close';
......@@ -141,6 +145,42 @@ $string['Open'] = 'Open';
$string['reopensite'] = 'Reopen Site';
$string['reopensitedetail'] = 'Your site is closed. Site administrators may stay logged in until an upgrade is detected.';
// Statistics
$string['siteinformation'] = 'Site Information';
$string['viewfullsitestatistics'] = 'View Full Site Statistics';
$string['sitestatistics'] = 'Site Statistics';
$string['siteinstalled'] = 'Site Installed';
$string['databasesize'] = 'Database Size';
$string['diskusage'] = 'Disk Usage';
$string['maharaversion'] = 'Mahara version';
$string['activeusers'] = 'Active users';
$string['loggedinsince'] = '%s today, %s since %s, %s all time';
$string['groupmemberaverage'] = 'On average, each user is in %s groups';
$string['viewsperuser'] = 'Users who make views have about %s views each';
$string['Cron'] = 'Cron';
$string['runningnormally'] = 'Running normally';
$string['cronnotrunning'] = 'Cron is not running.<br>See the <a href="http://wiki.mahara.org/System_Administrator\'s_Guide/Installing_Mahara">installation guide</a> for instructions on how to set it up.';
$string['Loggedin'] = 'Logged in';
$string['youraverageuser'] = 'Your Average User...';
$string['statsmaxfriends'] = 'Has %s friends (most is <a href="%s">%s</a> with %d)';
$string['statsnofriends'] = 'Has 0 friends :(';
$string['statsmaxviews'] = 'Has made %s views (most is <a href="%s">%s</a> with %d)';
$string['statsnoviews'] = 'Has made 0 views :(';
$string['statsmaxgroups'] = 'Is in %s groups (most is <a href="%s">%s</a> with %d)';
$string['statsnogroups'] = 'Is in 0 groups :(';
$string['statsmaxquotaused'] = 'Has used about %s of disk quota (most is <a href="%s">%s</a> with %s)';
$string['groupcountsbytype'] = 'Number of groups by Group Type';
$string['groupcountsbyjointype'] = 'Number of groups by Access Type';
$string['blockcountsbytype'] = 'Most frequently used blocks in Portfolio Views:';
$string['Rank'] = 'Rank';
$string['rankingsupdated'] = 'Rankings last updated: %s';
$string['uptodate'] = 'up to date';
$string['latestversionis'] = 'latest version is <a href="%s">%s</a>';
$string['viewsbytype'] = 'Views by Type';
$string['userstatstabletitle'] = 'Daily User Statistics';
$string['groupstatstabletitle'] = 'Biggest Groups';
$string['viewstatstabletitle'] = 'Most Popular Views';
// Site options
$string['adminsonly'] = 'Administrators only';
$string['adminsandstaffonly'] = 'Administrators and Staff only';
......
......@@ -52,6 +52,10 @@ $string['membershiptype.controlled'] = 'Controlled Membership';
$string['membershiptype.invite'] = 'Invite Only';
$string['membershiptype.request'] = 'Request Membership';
$string['membershiptype.open'] = 'Open Membership';
$string['membershiptype.abbrev.controlled'] = 'Controlled';
$string['membershiptype.abbrev.invite'] = 'Invite';
$string['membershiptype.abbrev.request'] = 'Request';
$string['membershiptype.abbrev.open'] = 'Open';
$string['pendingmembers'] = 'Pending Members';
$string['reason'] = 'Reason';
$string['approve'] = 'Approve';
......
......@@ -870,6 +870,9 @@ $string['back'] = 'Back';
$string['backto'] = 'Back to %s';
$string['alphabet'] = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
$string['formatpostbbcode'] = 'You can format your post using BBCode. %sLearn more%s';
$string['Created'] = 'Created';
$string['Total'] = 'Total';
$string['Visits'] = 'Visits';
// import related strings (maybe separated later)
$string['importedfrom'] = 'Imported from %s';
......
......@@ -120,6 +120,7 @@ $string['updatewatchlistfailed'] = 'Update of watchlist failed';
$string['watchlistupdated'] = 'Your watchlist has been updated';
$string['editmyview'] = 'Edit my View';
$string['backtocreatemyview'] = 'Back to create my View';
$string['viewvisitcount'] = '%d page visit(s) from %s to %s';
$string['friend'] = 'Friend';
$string['profileicon'] = 'Profile Icon';
......@@ -290,4 +291,8 @@ $string['viewcopywouldexceedquota'] = 'Copying this View would exceed your file
$string['blockcopypermission'] = 'Block copy permission';
$string['blockcopypermissiondesc'] = 'If you allow other users to copy this View, you may choose how this block will be copied';
// View types
$string['profile'] = 'Profile';
$string['portfolio'] = 'Portfolio';
?>
......@@ -104,6 +104,7 @@
<FIELD NAME="quota" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="quotaused" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="authinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......@@ -582,6 +583,7 @@
<FIELD NAME="template" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="copynewuser" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="type" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="visits" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="allowcomments" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
</FIELDS>
<KEYS>
......@@ -696,6 +698,18 @@
<KEY NAME="primary" TYPE="primary" FIELDS="token" />
</KEYS>
</TABLE>
<TABLE NAME="view_visit">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
<INDEXES>
<INDEX NAME="ctimeix" UNIQUE="false" FIELDS="ctime"/>
</INDEXES>
</TABLE>
<!-- site content stuff -->
<!--
<TABLE NAME="site_file">
......@@ -763,5 +777,15 @@
<KEY NAME="hostfk" TYPE="foreign" FIELDS="host" REFTABLE="host" REFFIELDS="wwwroot" />
</KEYS>
</TABLE>
<TABLE NAME="site_data">
<FIELDS>
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="value" TYPE="text" LENGTH="small"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="ctime,type" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -1531,5 +1531,72 @@ function xmldb_core_upgrade($oldversion=0) {
set_config('anonymouscomments', 1);
}
if ($oldversion < 2010041900 && !table_exists(new XMLDBTable('site_data'))) {
// Upgrades for admin stats pages
// Table for collection of historical stats
$table = new XMLDBTable('site_data');
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME, null, XMLDB_NOTNULL);
$table->addFieldInfo('type', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('ctime','type'));
create_table($table);
// Insert cron jobs to save site data
$cron = new StdClass;
$cron->callfunction = 'cron_site_data_weekly';
$cron->minute = 55;
$cron->hour = 23;
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = 6;
insert_record('cron', $cron);