Merge branch 'master' into nikolark

This commit is contained in:
nikolark committed 2012-04-19 02:34:17 +02:00
commit c787ac9207
3 files changed
+91 -2

No files matched your search

+1
View File
@@ -2,3 +2,4 @@
define('ENC_KEY', "lol");
define('API_KEY', "lol");
define('SYNC_HOST', "usersync.neuf.no");
+2 -2
View File
@@ -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) {
+88
View File
@@ -0,0 +1,88 @@
<?php
set_include_path("../includes/");
require_once("../inside/credentials.php");
require_once("../includes/DB.php");
/* Connect db */
$options = array(
'debug' => 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;
}
?>