Commit af6fa075 authored by Thomas Löffler's avatar Thomas Löffler

Add missed t3a-members file again

parent 2b5cc3a5
Pipeline #6446 passed with stages
in 4 minutes and 33 seconds
<?php
error_reporting(E_ALL & ~E_NOTICE);
require('api-keys.php');
define(
'PATH_THISSCRIPT',
str_replace(
'//',
'/',
str_replace(
'\\',
'/',
(PHP_SAPI === 'fpm-fcgi' || PHP_SAPI === 'cgi' || PHP_SAPI === 'isapi' || PHP_SAPI === 'cgi-fcgi') &&
(!empty($_SERVER['ORIG_PATH_TRANSLATED']) ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
(!empty($_SERVER['ORIG_PATH_TRANSLATED']) ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
(!empty($_SERVER['ORIG_SCRIPT_FILENAME']) ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME'])
)
)
);
define('PATH_SITE', dirname(PATH_THISSCRIPT) . '/');
// db connection
require(PATH_SITE . '../typo3conf/AdditionalConfiguration.php');
define('TYPO3_DB_NAME', $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']);
define('TYPO3_DB_HOST', $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host']);
define('TYPO3_DB_USERNAME', $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user']);
define('TYPO3_DB_PASSWORD', $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password']);
// no user serviceable parts below...
if (empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && empty($_SERVER['HTTPS'])) {
syslog(LOG_WARNING, 't3a-members.php: This service must be called through a SSL connection!');
header('HTTP/1.0 403 Forbidden');
die('Not using HTTPS');
}
if (isset($apiKeys[$_SERVER['HTTP_X_FORWARDED_FOR']]) && $apiKeys[$_SERVER['HTTP_X_FORWARDED_FOR']] === $_GET['apiKey']) {
echo printAssociationMembers();
} else {
syslog(
LOG_NOTICE,
't3a-members.php: API key for remote address ' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ' not found or invalid.'
);
header('HTTP/1.0 403 Forbidden');
die('Invalid token');
}
function printAssociationMembers()
{
$output = '';
$result = getAssociationMembers();
switch ($_GET['type']) {
case 'sympa':
foreach ($result as $row) {
$output .= $row['email'] . ' ' . $row['name'] . chr(10);
}
break;
case 'voting':
$output .= 'firstName;middleName;lastName;gender;email' . chr(10);
foreach ($result as $row) {
// leave the middle name empty, but hardcode gender to "male" because there needs to be some value
$output .= $row['firstname'] . ';;' . $row['lastname'] . ';male;' . $row['email'] . chr(10);
}
break;
case 'csv':
default:
foreach ($result as $row) {
$output .= arrayToCsv($row) . chr(10);
}
break;
}
return $output;
}
function getAssociationMembers()
{
$db = new mysqli(TYPO3_DB_HOST, TYPO3_DB_USERNAME, TYPO3_DB_PASSWORD, TYPO3_DB_NAME);
$db->query('SET NAMES utf8');
$where = 'email != "" AND hidden=0 AND deleted=0';
$where .= ' AND end_date > UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 1 DAY))';
$query = 'SELECT `uid`,`email`,`name`,`firstname`,`lastname`,`membership` FROM `tx_t3omembership_domain_model_member` WHERE ' . $where;
$query .= ' ORDER BY email';
$members = [];
$result = $db->query($query);
if ($result === false) {
echo mysqli_error($db);
die();
}
while ($row = mysqli_fetch_assoc($result)) {
$members[] = $row;
}
return $members;
}
/**
* Formats a line (passed as a fields array) as CSV and returns the CSV as a string.
* Adapted from http://us3.php.net/manual/en/function.fputcsv.php#87120
*/
function arrayToCsv(array &$fields, $delimiter = ';', $enclosure = '"', $encloseAll = false, $nullToMysqlNull = false)
{
$output = [];
foreach ($fields as $field) {
if ($field === null && $nullToMysqlNull) {
$output[] = 'NULL';
continue;
}
// Enclose fields containing $delimiter, $enclosure or whitespace
if ($encloseAll || preg_match("/(?:${delimiter}|${enclosure}|\s)/", $field)) {
$output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure;
} else {
$output[] = $field;
}
}
return implode($delimiter, $output);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment