forked from smillie/gas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemberreport.php
More file actions
76 lines (59 loc) · 2.21 KB
/
memberreport.php
File metadata and controls
76 lines (59 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php require 'ldapconnect.php'; ?>
<?php
if (!isUserInGroup($con, $user, "gsag")) {
header( 'Location: index.php' );
}
$mysqli = new mysqli($conf['db_host'], $conf['db_user'], $conf['db_pass'], $conf['db_name']);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=gs_members.csv");
header("Pragma: no-cache");
header("Expires: 0");
$users[] = array("Name","Student Number","Email Address", "Has Paid?");
$searchPattern = "(hasPaid=TRUE)";
$search = ldap_search($con, $dn, $searchPattern);
ldap_sort($con, $search, 'uid');
$results = ldap_get_entries($con, $search);
if (ldap_count_entries($con, $search) == 1){
$ruser = $results[0]['uid'][0];
} else if (ldap_count_entries($con, $search) == 0) {
$error = "No results for '$pattern'";
}
foreach (array_slice($results, 1) as $user) {
$u['name'] = $user['cn'][0];
$u['stuno'] = $user['studentnumber'][0];
$u['email'] = $user['mail'][0];
$u['paid'] = "Paid";
$users[] = $u;
}
/* Create the prepared statement */
if ($stmt = $mysqli->prepare("SELECT ID, firstname, lastname, username, studentnumber, email, IS_DELETED FROM newusers WHERE IS_DELETED = false")) {
/* Execute the prepared Statement */
$stmt->execute();
$stmt->bind_result($id, $first, $last, $uid, $stuno, $email, $created);
while ($stmt->fetch()) {
$u['name'] = $first." ".$last;
$u['stuno'] = $stuno;
$u['email'] = $email;
$u['paid'] = "Not Paid";
$users[] = $u;
}
/* Close the statement */
$stmt->close();
}
else {
/* Error */
}
outputCSV($users);
function outputCSV($data) {
$outstream = fopen("php://output", "w");
function __outputCSV(&$vals, $key, $filehandler) {
fputcsv($filehandler, $vals); // add parameters if you want
}
array_walk($data, "__outputCSV", $outstream);
fclose($outstream);
}
?>