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) { diff --git a/stats/members.php b/stats/members.php new file mode 100644 index 0000000..909a089 --- /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() OR expires IS NULL;"; + $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; +} + +?>