#!/usr/bin/php
<?php
# This tool is used to extract data from
# LDAP/AD via the aip command. For non-AIP
# environment, make sure aiptools is installed
# and cbtool has been run to configure the LDAP
# server information and credential.
$bindir = getenv("LSF_BINDIR");
$rawdata = shell_exec($bindir."/aip lu ig");
if ($rawdata == "")
   die("aip command failer\n");
$data = json_decode($rawdata, true);
if ($data === FALSE)
   die("cannot decode AIP output\n");
echo "jobs users-time\n";
echo "dept\n";
$existing = [];
foreach ($data as $g) {
    if (sizeof($g['Member']) == 0)
        continue;
    foreach ($g['Member'] as $u)
        if (!in_array($u, $existing)) {
            echo $u." ".$g['Name']."\n";
            $existing[] = $u;
        }
}
?>
