From edb67fdd1995b43f593cf4e46f41c4c4eeee425b Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Wed, 11 Apr 2012 01:46:04 +0200 Subject: [PATCH 1/3] Inside stats --- stats/members.php | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 stats/members.php diff --git a/stats/members.php b/stats/members.php new file mode 100644 index 0000000..a6ae78a --- /dev/null +++ b/stats/members.php @@ -0,0 +1,88 @@ + 2, + 'portability' => DB_PORTABILITY_ALL, +); + +$conn = DB::connect(getDSN(), $options); + +if(DB :: isError($conn)) { + echo $conn->toString(); +} +$conn->setFetchMode(DB_FETCHMODE_ASSOC); + +if(isset($_GET['v']) && $_GET['v'] == 'num') { + echo num_members(); +} else if(isset($_GET['v']) && $_GET['v'] == 'reg') { + echo registrations(); +} else if(isset($_GET['v']) && $_GET['v'] == 'reg_grouped') { + echo members_by_month_and_year(); +} else { + echo json_encode(array('error' => 'Try ?v=num|reg|reg_grouped :-D')); +} + +/* current number of members */ +function num_members() { + global $conn; + $sql = "SELECT COUNT(*) FROM din_user WHERE expires > NOW();"; + $rows = $conn->getAll($sql); + if( DB::isError($rows) ) { + return json_encode( array('result' => 'db_error') ); + } + return format($rows); +} + +/* registrations by month and year */ +function registrations() { + global $conn; + $sql = "SELECT DATE_FORMAT(din_userupdate.date, '%Y-%m') AS month_and_year, count(*) as num + FROM `din_user` , din_userupdate + WHERE din_user.id = user_id_updated + AND din_userupdate.comment = 'User registered.' + GROUP BY DATE_FORMAT(din_userupdate.date, '%Y-%m') + ORDER BY din_userupdate.date"; + $rows = $conn->getAll($sql); + if( DB::isError($rows) ) { + return json_encode( array('result' => 'db_error') ); + } + return format($rows); +} + +/* Current members by first registered month and year */ +function members_by_month_and_year() { + global $conn; + $sql = "SELECT DATE_FORMAT(din_userupdate.date, '%Y-%m') AS month_and_year, count(*) as num + FROM `din_user`,din_userupdate + WHERE expires > NOW() + AND din_user.id = user_id_updated + AND din_userupdate.comment = 'User registered.' + GROUP BY DATE_FORMAT(din_userupdate.date, '%Y-%m') + ORDER BY din_userupdate.date;"; + $rows = $conn->getAll($sql); + if( DB::isError($rows) ) { + return json_encode( array('result' => 'db_error') ); + } + return format($rows); +} + +function format($rows) { + $result = array(); + foreach($rows as $row) { + $tmp = array(); + foreach($row as $k => $v) { + $tmp[] = $v; + } + $result[] = $tmp; + } + + /* json_encode */ + $result = json_encode( array( 'result' => $result) ); + + return $result; +} + +?> From 4004fae55fe61ceb90054092c3b1e4a4dc0ddca9 Mon Sep 17 00:00:00 2001 From: Just Thomas Misund Date: Wed, 11 Apr 2012 13:52:42 +0200 Subject: [PATCH 2/3] Including lifelong memberships in stats. --- stats/members.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stats/members.php b/stats/members.php index a6ae78a..909a089 100644 --- a/stats/members.php +++ b/stats/members.php @@ -1,6 +1,6 @@ NOW();"; + $sql = "SELECT COUNT(*) FROM din_user WHERE expires > NOW() OR expires IS NULL;"; $rows = $conn->getAll($sql); if( DB::isError($rows) ) { return json_encode( array('result' => 'db_error') ); From bede4f4fdae02e77e66fc5472a38543102590c9d Mon Sep 17 00:00:00 2001 From: Just Thomas Misund Date: Thu, 12 Apr 2012 15:37:59 +0200 Subject: [PATCH 3/3] Put usersync host in config --- inside/migration/config.example.php | 1 + inside/migration/ldap_api_functions.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/inside/migration/config.example.php b/inside/migration/config.example.php index e2ad0ee..ea023c3 100644 --- a/inside/migration/config.example.php +++ b/inside/migration/config.example.php @@ -2,3 +2,4 @@ define('ENC_KEY', "lol"); define('API_KEY', "lol"); +define('SYNC_HOST', "usersync.neuf.no"); diff --git a/inside/migration/ldap_api_functions.php b/inside/migration/ldap_api_functions.php index 04f303d..6dc3608 100644 --- a/inside/migration/ldap_api_functions.php +++ b/inside/migration/ldap_api_functions.php @@ -2,7 +2,7 @@ require_once('config.php'); /* This file is an example on how you might push users from inside to ldap/radius. * * Basically, fill an array with the required attributes, get the API_KEY and the encryption key - * * and send it to the file addNewUser.php under brukerinfo.neuf.no. + * * and send it to the script addNewUser.php on SYNC_HOST. * */ function enc_password($password, $key) { @@ -51,7 +51,7 @@ function ldap_add_user($username, $firstname, $lastname, $email, $password, $gro } /* Send the HTTP request. */ - $result = var_export(file_get_contents("http://brukerinfo.neuf.no/addNewUser.php?" . implode("&", $arr)), true); + $result = var_export(file_get_contents("http://".SYNC_HOST."/addNewUser.php?" . implode("&", $arr)), true); return $result; } function _log($str) {