Exemple #1
0
function errorHandler($errno, $errstr, $errfile = NULL, $errline = NULL, $errcontext = NULL)
{
    global $user;
    if (!ONLINEDEBUG || !checkUserHasPerm('View Debug Information')) {
        cleanSemaphore();
        dbDisconnect();
        printHTMLFooter();
        exit;
    }
    print "Error encountered<br>\n";
    switch ($errno) {
        case E_USER_ERROR:
            echo "<b>FATAL</b> [{$errno}] {$errstr}<br />\n";
            echo "  Fatal error in line {$errline} of file {$errfile}";
            echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
            echo "Aborting...<br />\n";
            cleanSemaphore();
            dbDisconnect();
            exit(1);
            break;
        case E_USER_WARNING:
            echo "<b>ERROR</b> [{$errno}] {$errstr}<br />\n";
            break;
        case E_USER_NOTICE:
            echo "<b>WARNING</b> [{$errno}] {$errstr}<br />\n";
            break;
        default:
            echo "Unkown error type: [{$errno}] {$errstr}<br />\n";
            break;
    }
    if (!empty($errfile) && !empty($errline)) {
        print "Error at {$errline} in {$errfile}<br>\n";
    }
    if (!empty($errcontext)) {
        print "<pre>\n";
        print_r($errcontext);
        print "</pre>\n";
    }
    print "<br><br><br>\n";
    print "<pre>\n";
    print getBacktraceString();
    print "</pre>\n";
    cleanSemaphore();
    dbDisconnect();
    printHTMLFooter();
    exit;
}
function AJgetBlockAllocatedMachineData()
{
    global $user;
    $start = processInputVar('start', ARG_STRING);
    if (!preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$/', $start)) {
        $start = unixFloor15(time() - 3600);
        $startdt = unixToDatetime($start);
    } else {
        $startdt = "{$start}:00";
        $start = datetimeToUnix($startdt);
    }
    $end = $start + 12 * 3600;
    $enddt = unixToDatetime($end);
    $alldata = array();
    # bare
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'blade'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['bare'] = $data;
    # virtual
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'virtualmachine'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['virtual'] = $data;
    $val = getContinuationVar('val') + 1;
    $cont = addContinuationsEntry('AJgetBlockAllocatedMachineData', array('val' => $val), SECINDAY, 1, 0);
    $alldata['cont'] = $cont;
    sendJSON($alldata);
}
Exemple #3
0
function AJshowReinstallRequest()
{
    global $user;
    $requestid = getContinuationVar('requestid');
    $reqdata = getRequestInfo($requestid, 1);
    if (is_null($reqdata) || $reqdata['stateid'] == 11 || $reqdata['stateid'] == 12 || $reqdata['stateid'] == 14 && ($reqdata['laststateid'] == 11 || $reqdata['laststateid'] == 12)) {
        sendJSON(array('status' => 'resgone'));
        return;
    }
    $imageid = $reqdata['reservations'][0]['imageid'];
    $imgdata = getImages(0, $imageid);
    $t = '';
    $cdata = getContinuationVar();
    $cont = addContinuationsEntry('AJreinstallRequest', $cdata, 300, 1, 0);
    if (count($reqdata['reservations']) == 1 && ($imgdata[$imageid]['ownerid'] == $user['id'] || checkUserHasPerm('View Debug Information')) && count($imgdata[$imageid]['imagerevision']) > 1) {
        # prompt for which revision to use for reinstall
        $m = i("This will cause the reserved machine to be reinstalled. You may select which version of the environment you would like to use for the reinstall. The currently installed version is initally selected.");
        $t .= preg_replace("/(.{1,85}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $t .= "<table summary=\"lists versions of the environment\">";
        $t .= "<TR>";
        $t .= "<TD></TD>";
        $t .= "<TH>" . i("Version") . "</TH>";
        $t .= "<TH>" . i("Creator") . "</TH>";
        $t .= "<TH>" . i("Created") . "</TH>";
        $t .= "<TH>" . i("Currently in Production") . "</TH>";
        $t .= "</TR>";
        foreach ($imgdata[$imageid]['imagerevision'] as $revision) {
            $t .= "<TR>";
            // if revision was selected or it wasn't selected but it is the production revision, show checked
            if ($reqdata['reservations'][0]['imagerevisionid'] == $revision['id']) {
                $t .= "<TD align=center><INPUT type=radio name=revisionid value={$revision['id']} checked></TD>";
            } else {
                $t .= "<TD align=center><INPUT type=radio name=revisionid value={$revision['id']}></TD>";
            }
            $t .= "<TD align=center>{$revision['revision']}</TD>";
            $t .= "<TD align=center>{$revision['user']}</TD>";
            $t .= "<TD align=center>{$revision['prettydate']}</TD>";
            if ($revision['production']) {
                $t .= "<TD align=center>" . i("Yes") . "</TD>";
            } else {
                $t .= "<TD align=center>" . i("No") . "</TD>";
            }
            $t .= "</TR>";
        }
        $t .= "</table><br>";
        $t .= "<strong>" . i("NOTE:") . "</strong> ";
    } else {
        $t .= i("This will cause the reserved machine to be reinstalled.") . "<br>";
    }
    $t .= i("Any data saved only to the reserved machine <strong>will be lost</strong>.") . "<br>";
    $t .= i("Are you sure you want to continue?") . "<br><br>";
    sendJSON(array('status' => 'success', 'txt' => $t, 'cont' => $cont));
}
Exemple #4
0
$modes = array_keys($actions['mode']);
$args = array_keys($actions['args']);
$hasArg = 0;
if (in_array($mode, $modes)) {
    $actionFunction = $actions['mode'][$mode];
    if (in_array($mode, $args)) {
        $hasArg = 1;
        $arg = $actions['args'][$mode];
    }
} else {
    $actionFunction = "main";
}
checkAccess();
sendHeaders();
printHTMLHeader();
if (checkUserHasPerm('View Debug Information')) {
    set_error_handler("errorHandler");
}
if ($hasArg) {
    if (function_exists($actionFunction)) {
        $actionFunction($arg);
    } else {
        $obj = getContinuationVar('obj');
        if (!is_null($obj) && method_exists($obj, $actionFunction)) {
            $obj->{$actionFunction}($arg);
        } else {
            main();
        }
    }
} else {
    if (function_exists($actionFunction)) {
Exemple #5
0
function viewStatistics()
{
    global $submitErr, $submitErrMsg, $user;
    define("30MIN", 1800);
    define("1HOUR", 3600);
    define("2HOURS", 7200);
    define("4HOURS", 14400);
    $month1 = processInputVar("month1", ARG_NUMERIC);
    $day1 = processInputVar("day1", ARG_NUMERIC);
    $year1 = processInputVar("year1", ARG_NUMERIC);
    $month2 = processInputVar("month2", ARG_NUMERIC);
    $day2 = processInputVar("day2", ARG_NUMERIC);
    $year2 = processInputVar("year2", ARG_NUMERIC);
    $affilid = processInputVar("affilid", ARG_NUMERIC, $user['affiliationid']);
    $mode2 = getContinuationVar('mode', 'default');
    $provid = processInputVar('provid', ARG_NUMERIC, 0);
    if ($mode2 == 'provisioning') {
        $affilid = 0;
        $provs = getContinuationVar('provs');
        if (!array_key_exists($provid, $provs)) {
            $ids = array_keys($provs);
            $provid = $ids[0];
        }
    } else {
        $provid = 0;
    }
    $affils = getAffiliations();
    if (!checkUserHasPerm('View Statistics by Affiliation') || $affilid != 0 && !array_key_exists($affilid, $affils)) {
        $affilid = $user['affiliationid'];
    }
    if ($affilid == 0) {
        $statsfor = i("All Affiliations");
    } else {
        $statsfor = $affils[$affilid];
    }
    $start = "{$year1}-{$month1}-{$day1} 00:00:00";
    $end = "{$year2}-{$month2}-{$day2} 23:59:59";
    if (!checkdate($month1, $day1, $year1)) {
        $submitErr |= STARTERR;
        $submitErrMsg[STARTERR] = i("The selected start date is not valid. Please select a valid date.") . "<br>\n";
    }
    if (!checkdate($month2, $day2, $year2)) {
        $submitErr |= ENDERR;
        $submitErrMsg[ENDERR] = i("The selected end date is not valid. Please select a valid date.") . "<br>\n";
    }
    if (datetimeToUnix($start) > datetimeToUnix($end)) {
        $submitErr |= ORDERERR;
        $submitErrMsg[ORDERERR] = i("The selected end date is before the selected start date. Please select an end date equal to or greater than the start date.") . "<br>\n";
    }
    if ($submitErr) {
        selectStatistics();
        return;
    }
    $timestart = microtime(1);
    if ($mode2 == 'default') {
        print "<H2>" . i("Statistic Information for") . " {$statsfor}</H2>\n";
    } elseif ($mode2 == 'provisioning') {
        print "<H2>" . i("Statistic Information for") . " {$provs[$provid]}</H2>\n";
    }
    print "<H3>";
    $tmp = mktime(0, 0, 0, $month1, $day1, $year1);
    $starttime = strftime('%x', $tmp);
    $tmp = mktime(0, 0, 0, $month2, $day2, $year2);
    $endtime = strftime('%x', $tmp);
    printf(i("Reservation information between %s and %s:"), $starttime, $endtime);
    print "</H3>\n";
    $reloadid = getUserlistID('vclreload@Local');
    if ($mode2 == 'default') {
        $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM log l, " . "image i, " . "user u, " . "OS o " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND ";
    } elseif ($mode2 == 'provisioning') {
        $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM image i, " . "user u, " . "OS o, " . "log l " . "JOIN (" . "SELECT s.logid, " . "MIN(s.computerid) AS computerid " . "FROM sublog s, " . "computer c " . "WHERE s.computerid = c.id AND " . "c.provisioningid = {$provid} " . "GROUP BY logid " . ") AS s ON (s.logid = l.id) " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND ";
    }
    if ($affilid != 0) {
        $query .= "u.affiliationid = {$affilid} AND ";
    }
    $query .= "l.userid = u.id " . "ORDER BY i.prettyname";
    $qh = doQuery($query, 275);
    $totalreservations = 0;
    $users = array();
    $nows = 0;
    $futures = 0;
    $notavailable = 0;
    $loadtimes = array("2less" => 0, "2to6" => 0, "6to8" => 0, "8more" => 0);
    $ending = array("deleted" => 0, "released" => 0, "failed" => 0, "noack" => 0, "nologin" => 0, "timeout" => 0, "EOR" => 0, "none" => 0);
    $imagecount = array();
    $imageusers = array();
    $imagehours = array();
    $imageload2less = array();
    $imageload2to6 = array();
    $imageload6to8 = array();
    $imageload8more = array();
    $imagefails = array();
    $lengths = array("30min" => 0, "1hour" => 0, "2hours" => 0, "4hours" => 0, "6hours" => 0, "8hours" => 0, "10hours" => 0, "10hrsplus" => 0);
    $totalhours = 0;
    $osusers = array();
    while ($row = mysql_fetch_assoc($qh)) {
        if (!array_key_exists($row["prettyname"], $imageload2less)) {
            $imageload2less[$row["prettyname"]] = 0;
        }
        if (!array_key_exists($row["prettyname"], $imageload2to6)) {
            $imageload2to6[$row["prettyname"]] = 0;
        }
        if (!array_key_exists($row["prettyname"], $imageload6to8)) {
            $imageload6to8[$row["prettyname"]] = 0;
        }
        if (!array_key_exists($row["prettyname"], $imageload8more)) {
            $imageload8more[$row["prettyname"]] = 0;
        }
        # notavailable
        if ($row["wasavailable"] == 0) {
            $notavailable++;
        } else {
            $totalreservations++;
            # load times
            if ($row['loadtime'] <= 120) {
                $loadtimes['2less']++;
                # imageload2less
                $imageload2less[$row['prettyname']]++;
            } elseif ($row['loadtime'] > 120 && $row['loadtime'] <= 360) {
                $loadtimes['2to6']++;
                $imageload2to6[$row['prettyname']]++;
            } elseif ($row['loadtime'] > 360 && $row['loadtime'] <= 480) {
                $loadtimes['6to8']++;
                $imageload6to8[$row['prettyname']]++;
            } else {
                $loadtimes['8more']++;
                $imageload8more[$row['prettyname']]++;
            }
        }
        # users
        $users[$row['userid']] = 1;
        # nowfuture
        if ($row["nowfuture"] == "now") {
            $nows++;
        } else {
            $futures++;
        }
        # ending
        $ending[$row["ending"]]++;
        # imagecount
        if (!array_key_exists($row["prettyname"], $imagecount)) {
            $imagecount[$row["prettyname"]] = 0;
        }
        $imagecount[$row["prettyname"]]++;
        # imageusers
        if (!array_key_exists($row["prettyname"], $imageusers)) {
            $imageusers[$row["prettyname"]] = array();
        }
        $imageusers[$row['prettyname']][$row['userid']] = 1;
        # lengths
        $length = $row["finalend"] - $row["start"];
        if ($length < 0) {
            $length = 0;
        }
        if ($length <= 1800) {
            $lengths["30min"]++;
        } elseif ($length <= 3600) {
            $lengths["1hour"]++;
        } elseif ($length <= 7200) {
            $lengths["2hours"]++;
        } elseif ($length <= 14400) {
            $lengths["4hours"]++;
        } elseif ($length <= 21600) {
            $lengths["6hours"]++;
        } elseif ($length <= 28800) {
            $lengths["8hours"]++;
        } elseif ($length <= 36000) {
            $lengths["10hours"]++;
        } else {
            $lengths["10hrsplus"]++;
        }
        # imagehours
        if (!array_key_exists($row["prettyname"], $imagehours)) {
            $imagehours[$row["prettyname"]] = 0;
        }
        $imagehours[$row["prettyname"]] += $length / 3600;
        # imagefails
        if (!array_key_exists($row["prettyname"], $imagefails)) {
            $imagefails[$row["prettyname"]] = 0;
        }
        if ($row['ending'] == 'failed') {
            $imagefails[$row["prettyname"]] += 1;
        }
        # total hours
        $totalhours += $length;
        # osusers
        if (!array_key_exists($row["OS"], $osusers)) {
            $osusers[$row["OS"]] = array();
        }
        $osusers[$row['OS']][$row['userid']] = 1;
    }
    print "<DIV align=center>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Total Reservations:") . "</TH>\n";
    print "    <TD>{$totalreservations}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Total Hours Used:") . "</TH>\n";
    print "    <TD>" . (int) ($totalhours / 3600) . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("\"Now\" Reservations:") . "</TH>\n";
    print "    <TD>{$nows}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("\"Later\" Reservations:") . "</TH>\n";
    print "    <TD>{$futures}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Unavailable:") . "</TH>\n";
    print "    <TD>{$notavailable}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Load times &lt; 2 minutes:") . "</TH>\n";
    print "    <TD>{$loadtimes['2less']}</TD>\n";
    print "  </TR>\n";
    print "    <TH align=right>" . i("Load times 2-6 minutes:") . "</TH>\n";
    print "    <TD>{$loadtimes['2to6']}</TD>\n";
    print "  </TR>\n";
    print "    <TH align=right>" . i("Load times 6-8 minutes:") . "</TH>\n";
    print "    <TD>{$loadtimes['6to8']}</TD>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Load times &gt;= 8 minutes:") . "</TH>\n";
    print "    <TD>{$loadtimes['8more']}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Total Unique Users:") . "</TH>\n";
    print "    <TD>" . count($users) . "</TD>\n";
    print "  </TR>\n";
    foreach (array_keys($osusers) as $key) {
        print "  <TR>\n";
        print "    <TH align=right>";
        printf(i("Unique Users of %s:"), $key);
        print "</TH>\n";
        print "    <TD>" . count($osusers[$key]) . "</TD>\n";
        print "  </TR>\n";
    }
    print "</TABLE>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TD></TD>\n";
    print "    <TH>" . i("Reservations") . "</TH>\n";
    print "    <TH>" . i("Unique Users") . "</TH>\n";
    print "    <TH>" . i("Hours Used") . "</TH>\n";
    print "    <TH>" . i("&lt; 2 min wait") . "</TH>\n";
    print "    <TH>" . i("2-6 min wait") . "</TH>\n";
    print "    <TH>" . i("6-8 min wait") . "</TH>\n";
    print "    <TH>" . i("&gt;= 8 min wait") . "</TH>\n";
    print "    <TH>" . i("Failures") . "</TH>\n";
    print "  </TR>\n";
    foreach ($imagecount as $key => $value) {
        print "  <TR>\n";
        print "    <TH align=right>{$key}:</TH>\n";
        print "    <TD align=center>{$value}</TD>\n";
        print "    <TD align=center>" . count($imageusers[$key]) . "</TD>\n";
        if ((int) $imagehours[$key] == 0) {
            print "    <TD align=center>1</TD>\n";
        } else {
            print "    <TD align=center>" . (int) $imagehours[$key] . "</TD>\n";
        }
        print "    <TD align=center>{$imageload2less[$key]}</TD>\n";
        print "    <TD align=center>{$imageload2to6[$key]}</TD>\n";
        print "    <TD align=center>{$imageload6to8[$key]}</TD>\n";
        print "    <TD align=center>{$imageload8more[$key]}</TD>\n";
        if ($imagefails[$key]) {
            $percent = $imagefails[$key] * 100 / $value;
            if ($percent < 1) {
                $percent = sprintf('%.1f%%', $percent);
            } else {
                $percent = sprintf('%d%%', $percent);
            }
            print "    <TD align=center><font color=red>{$imagefails[$key]} ";
            print "({$percent})</font></TD>\n";
        } else {
            print "    <TD align=center>{$imagefails[$key]}</TD>\n";
        }
        print "  </TR>\n";
    }
    print "</TABLE>\n";
    print "<H3>" . i("Durations:") . "</H3>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("0 - 30 Min:") . "</TH>\n";
    print "    <TD>" . $lengths["30min"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("30 Min - 1 Hour:") . "</TH>\n";
    print "    <TD>" . $lengths["1hour"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("1 Hour - 2 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["2hours"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("2 Hours - 4 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["4hours"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("4 Hours - 6 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["6hours"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("6 Hours - 8 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["8hours"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("8 Hours - 10 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["10hours"] . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("&gt; 10 Hours:") . "</TH>\n";
    print "    <TD>" . $lengths["10hrsplus"] . "</TD>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    print "<H3>" . i("Ending information:") . "</H3>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Deleted:") . "</TH>\n";
    print "    <TD>" . $ending["deleted"] . "</TD>\n";
    print "    <TD rowspan=7><img src=\"images/blank.gif\" width=5></TD>\n";
    print "    <TD>" . i("(Future reservation deleted before start time reached)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Released:") . "</TH>\n";
    print "    <TD>" . $ending["released"] . "</TD>\n";
    print "    <TD>" . i("(Reservation released before end time reached)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Not Acknowledged:") . "</TH>\n";
    print "    <TD>" . $ending["noack"] . "</TD>\n";
    print "    <TD>" . i("(\"Connect!\" button never clicked)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("No Login:"******"</TH>\n";
    print "    <TD>" . $ending["nologin"] . "</TD>\n";
    print "    <TD>" . i("(User never logged in)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("End of Reservation:") . "</TH>\n";
    print "    <TD>" . $ending["EOR"] . "</TD>\n";
    print "    <TD>" . i("(End of reservation reached)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Timed Out:") . "</TH>\n";
    print "    <TD>" . $ending["timeout"] . "</TD>\n";
    print "    <TD>" . i("(Disconnect and no reconnection within 15 minutes)") . "</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right>" . i("Failed:") . "</TH>\n";
    print "    <TD>" . $ending["failed"] . "</TD>\n";
    print "    <TD>" . i("(Reserved computer failed to get prepared for user)") . "</TD>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    print "<br>\n";
    print "</div>\n";
    $unixstart = datetimeToUnix($start);
    $unixend = datetimeToUnix($end);
    $start = date('Y-m-d', $unixstart);
    $end = date('Y-m-d', $unixend);
    $cdata = array('start' => $start, 'end' => $end, 'affilid' => $affilid, 'mode' => $mode2, 'provid' => $provid);
    print "<H2>" . i("Reservations by Day") . "</H2>\n";
    print "<small>" . i("(Reservations with start time on given day)") . "</small><br>\n";
    $cdata['divid'] = 'resbyday';
    $cont = addContinuationsEntry('AJgetStatData', $cdata);
    print "<input type=hidden id=statdaycont value=\"{$cont}\">\n";
    print "<div id=\"resbyday\" class=\"statgraph\">(Loading...)</div>\n";
    print "<H2>" . i("Max Concurrent Reservations By Day") . "</H2>\n";
    $cdata['divid'] = 'maxconcurresday';
    $cont = addContinuationsEntry('AJgetStatData', $cdata);
    print "<input type=hidden id=statconcurrescont value=\"{$cont}\">\n";
    print "<div id=\"maxconcurresday\" class=\"statgraph\">Loading graph data...</div>\n";
    print "<H2>" . i("Max Concurrent Blade Reservations By Day") . "</H2>\n";
    $cdata['divid'] = 'maxconcurbladeday';
    $cont = addContinuationsEntry('AJgetStatData', $cdata);
    print "<input type=hidden id=statconcurbladecont value=\"{$cont}\">\n";
    print "<div id=\"maxconcurbladeday\" class=\"statgraph\">Loading graph data...</div>\n";
    print "<H2>" . i("Max Concurrent Virtual Machine Reservations By Day") . "</H2>\n";
    $cdata['divid'] = 'maxconcurvmday';
    $cont = addContinuationsEntry('AJgetStatData', $cdata);
    print "<input type=hidden id=statconcurvmcont value=\"{$cont}\">\n";
    print "<div id=\"maxconcurvmday\" class=\"statgraph\">Loading graph data...</div>\n";
    print "<H2>" . i("Reservations by Hour") . "</H2>\n";
    print "<small>(" . i("Active reservations during given hour averaged over selected dates") . ")</small><br><br>\n";
    $cdata['divid'] = 'resbyhour';
    $cont = addContinuationsEntry('AJgetStatData', $cdata);
    print "<input type=hidden id=statreshourcont value=\"{$cont}\">\n";
    print "<div id=\"resbyhour\" class=\"statgraph\">Loading graph data...</div>\n";
    $endtime = microtime(1);
    $end = $endtime - $timestart;
    #print "running time: $endtime - $timestart = $end<br>\n";
}
Exemple #6
0
function getNavMenu($inclogout, $inchome, $homeurl = HOMEURL)
{
    global $user, $docreaders, $authed, $mode;
    if ($authed && $mode != 'expiredemouser') {
        $computermetadata = getUserComputerMetaData();
        $requests = getUserRequests("all", $user["id"]);
    } else {
        $computermetadata = array("platforms" => array(), "schedules" => array());
    }
    $rt = '';
    if ($inchome) {
        $rt .= menulistLI('home');
        $rt .= "<a href=\"{$homeurl}\">" . i("HOME") . "</a></li>\n";
    }
    $rt .= menulistLI('reservations');
    $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=viewRequests\">";
    $rt .= i("Reservations") . "</a></li>\n";
    #$rt .= menulistLI('config');
    #$rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=config\">";
    #$rt .= i("Manage Configs") . "</a></li>\n";
    $rt .= menulistLI('blockAllocations');
    $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=blockAllocations\">";
    $rt .= i("Block Allocations") . "</a></li>\n";
    $rt .= menulistLI('userPreferences');
    $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=userpreferences\">";
    $rt .= i("User Preferences") . "</a></li>\n";
    if (in_array("groupAdmin", $user["privileges"])) {
        $rt .= menulistLI('manageGroups');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=viewGroups\">";
        $rt .= i("Manage Groups") . "</a></li>\n";
    }
    if (in_array("imageAdmin", $user["privileges"])) {
        $rt .= menulistLI('image');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=image\">";
        $rt .= i("Manage Images") . "</a></li>\n";
    }
    if (in_array("scheduleAdmin", $user["privileges"])) {
        $rt .= menulistLI('schedule');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=schedule\">";
        $rt .= i("Manage Schedules") . "</a></li>\n";
    }
    if (in_array("computerAdmin", $user["privileges"])) {
        $rt .= menulistLI('computer');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=computer\">";
        $rt .= i("Manage Computers") . "</a></li>\n";
    }
    if (in_array("mgmtNodeAdmin", $user["privileges"])) {
        $rt .= menulistLI('managementnode');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=managementnode\">";
        $rt .= i("Management Nodes") . "</a></li>\n";
    }
    if (in_array("serverProfileAdmin", $user["privileges"]) || in_array("serverCheckOut", $user["privileges"])) {
        $rt .= menulistLI('serverProfiles');
        $rt .= "<a href=\"" . BASEURL . SCRIPT;
        $rt .= "?mode=serverProfiles\">" . i("Server Profiles") . "</a></li>\n";
    }
    if (count($computermetadata["platforms"]) && count($computermetadata["schedules"])) {
        $rt .= menulistLI('timeTable');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=pickTimeTable\">";
        $rt .= i("View Time Table") . "</a></li>\n";
    }
    if (in_array("userGrant", $user["privileges"]) || in_array("resourceGrant", $user["privileges"]) || in_array("nodeAdmin", $user["privileges"])) {
        $rt .= menulistLI('privileges');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=viewNodes\">";
        $rt .= i("Privileges") . "</a></li>\n";
    }
    if (checkUserHasPerm('User Lookup (global)') || checkUserHasPerm('User Lookup (affiliation only)')) {
        $rt .= menulistLI('userLookup');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=userLookup\">";
        $rt .= i("User Lookup") . "</a></li>\n";
    }
    if (in_array("computerAdmin", $user["privileges"])) {
        $rt .= menulistLI('vm');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=editVMInfo\">";
        $rt .= i("Virtual Hosts") . "</a></li>\n";
    }
    if (checkUserHasPerm('Schedule Site Maintenance')) {
        $rt .= menulistLI('sitemaintenance');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=siteMaintenance\">";
        $rt .= i("Site Maintenance") . "</a></li>\n";
    }
    $rt .= menulistLI('statistics');
    $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=selectstats\">";
    $rt .= i("Statistics") . "</a></li>\n";
    if (checkUserHasPerm('View Dashboard (global)') || checkUserHasPerm('View Dashboard (affiliation only)')) {
        $rt .= menulistLI('dashboard');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=dashboard\">";
        $rt .= i("Dashboard") . "</a></li>\n";
    }
    if (checkUserHasPerm('Site Configuration (global)') || checkUserHasPerm('Site Configuration (affiliation only)')) {
        $rt .= menulistLI('siteconfig');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=siteconfig\">";
        $rt .= i("Site Configuration") . "</a></li>\n";
    }
    $rt .= menulistLI('codeDocumentation');
    $rt .= "<a href=\"" . DOCUMENTATIONURL . "\">";
    $rt .= i("Documentation") . "</a></li>\n";
    if ($inclogout) {
        $rt .= menulistLI('authentication');
        $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=logout\">";
        $rt .= i("Logout") . "</a></li>\n";
    }
    return $rt;
}
Exemple #7
0
function confirmDeleteGroup()
{
    global $user;
    $groupid = getContinuationVar("groupid");
    $type = getContinuationVar("type");
    $usergroups = getUserGroups();
    $groupid = processInputVar('groupid', ARG_NUMERIC);
    if ($type == 'user') {
        if (!array_key_exists($groupid, $usergroups)) {
            print "<h2>Delete User Group</h2>\n";
            print "The selected user group does not exist.\n";
            return;
        }
        if ($usergroups[$groupid]['ownerid'] != $user['id']) {
            if ($usergroups[$groupid]['custom'] == 0 || $usergroups[$groupid]['courseroll'] == 1) {
                if (!checkUserHasPerm('Manage Federated User Groups (global)') && (!checkUserHasPerm('Manage Federated User Groups (affiliation only)') || $usergroups[$groupid]['groupaffiliationid'] != $user['affiliationid'])) {
                    print "<h2>Delete User Group</h2>\n";
                    print "You do not have access to delete the selected user group.\n";
                    return;
                }
            } else {
                print "<h2>Delete User Group</h2>\n";
                print "You do not have access to delete the selected user group.\n";
                return;
            }
        }
        $tmp = explode('@', $usergroups[$groupid]['name']);
        $checkname = $tmp[0];
        if ($usergroups[$groupid]['groupaffiliationid'] == 1 && ($checkname == 'Specify End Time' || $checkname == 'Allow No User Check' || $checkname == 'Default for Editable by')) {
            print "<h2>Delete User Group</h2>\n";
            print "{$usergroups[$groupid]['name']} is a system group that cannot be deleted";
            return;
        }
    } else {
        $userresources = getUserResources(array("groupAdmin"), array("manageGroup"), 1);
        $noaccess = 1;
        foreach (array_keys($userresources) as $rtype) {
            if (array_key_exists($groupid, $userresources[$rtype])) {
                $noaccess = 0;
                break;
            }
        }
        if ($noaccess) {
            print "<h2>Delete Resource Group</h2>\n";
            print "You do not have access to delete the selected resource group.\n";
            return;
        }
    }
    $resourcegroups = getResourceGroups();
    if ($type == "user") {
        $title = "Delete User Group";
        $usemsg = "This group is currently in use.  You cannot delete it until " . "it is no longer being used.";
        $question = "Delete the following user group?";
        $name = $usergroups[$groupid]["name"];
        $target = "";
    } else {
        $title = "Delete Resource Group";
        $usemsg = "This group is currently assigned to at least one node in the " . "privilege tree.  You cannot delete it until it is no longer " . "in use.";
        $question = "Delete the following resource group?";
        list($resourcetype, $name) = explode('/', $resourcegroups[$groupid]["name"]);
        $target = "#resources";
    }
    if (checkForGroupUsage($groupid, $type, $usemsg)) {
        print "<H2 align=center>{$title}</H2>\n";
        print $usemsg;
        return;
    }
    print "<DIV align=center>\n";
    print "<H2>{$title}</H2>\n";
    print "{$question}<br><br>\n";
    print "<TABLE>\n";
    if ($type == "resource") {
        print "  <TR>\n";
        print "    <TH align=right>Type:</TH>\n";
        print "    <TD>{$resourcetype}</TD>\n";
        print "  </TR>\n";
    }
    print "  <TR>\n";
    print "    <TH align=right>Name:</TH>\n";
    print "    <TD>{$name}</TD>\n";
    print "  </TR>\n";
    if ($type == "resource") {
        print "  <TR>\n";
        print "    <TH align=right>Owning User Group:</TH>\n";
        print "    <TD>" . $resourcegroups[$groupid]["owner"] . "</TD>\n";
        print "  </TR>\n";
    } elseif ($usergroups[$groupid]['courseroll'] == 1 || $usergroups[$groupid]['custom'] == 0) {
        print "<TR>\n";
        print "  <TH align=right>Type:</TH>\n";
        if ($usergroups[$groupid]['courseroll'] == 1) {
            print "  <TD>Course Roll</TD>\n";
        } elseif ($usergroups[$groupid]['custom'] == 0) {
            print "  <TD>Federated</TD>\n";
        }
        print "</TR>\n";
        print "<TR>\n";
        print "  <TD colspan=2><br><strong>Note</strong>: This type of group is ";
        print "created from external sources<br>and could be recreated from ";
        print "those sources at any time.<br><br></TD>\n";
        print "</TR>\n";
    }
    print "</TABLE>\n";
    print "<TABLE>\n";
    print "  <TR valign=top>\n";
    print "    <TD>\n";
    print "      <FORM action=\"" . BASEURL . SCRIPT . "{$target}\" method=post>\n";
    $cdata = array('groupid' => $groupid, 'type' => $type);
    $cont = addContinuationsEntry('submitDeleteGroup', $cdata);
    print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <INPUT type=submit value=Submit>\n";
    print "      </FORM>\n";
    print "    </TD>\n";
    print "    <TD>\n";
    print "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    print "      <INPUT type=hidden name=mode value=viewGroups>\n";
    print "      <INPUT type=submit value=Cancel>\n";
    print "      </FORM>\n";
    print "    </TD>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    print "</DIV>\n";
}
Exemple #8
0
function getDashboardAffilID()
{
    global $user;
    if (!checkUserHasPerm('View Dashboard (global)')) {
        return $user['affiliationid'];
    }
    $affilid = processInputVar('affilid', ARG_NUMERIC);
    $affils = getAffiliations();
    if ($affilid != 0 && !array_key_exists($affilid, $affils)) {
        return 0;
    }
    return $affilid;
}
Exemple #9
0
 function AJupdateAllSettings()
 {
     if (!checkUserHasPerm('Site Configuration (global)')) {
         $arr = array('status' => 'noaccess', 'msg' => i('You do not have access to modify the submitted settings.'));
         sendJSON($arr);
         return;
     }
     switch ($this->type) {
         case 'numeric':
             $newval = processInputVar('newval', ARG_NUMERIC);
             if ($newval < $this->minval || $newval > $this->maxval) {
                 $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted"));
                 sendJSON($arr);
                 return;
             }
             break;
         case 'boolean':
             $newval = processInputVar('newval', ARG_NUMERIC);
             if ($newval !== '0' && $newval !== '1') {
                 $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted"));
                 sendJSON($arr);
                 return;
             }
             break;
         case 'text':
             # TODO
             $newval = processInputVar('newval', ARG_STRING);
             $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("unsupported type"));
             sendJSON($arr);
             return;
         case 'textarea':
             $newval = processInputVar('newval', ARG_STRING);
             if (!$this->validateValue($newval)) {
                 $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted"));
                 if (isset($this->invalidvaluemsg)) {
                     $arr['errmsg'] = $this->invalidvaluemsg;
                 }
                 sendJSON($arr);
                 return;
             }
             break;
         default:
             $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted"));
             sendJSON($arr);
             return;
     }
     setVariable($this->key, $newval, 'none');
     $arr = array('status' => 'success', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'msg' => $this->updatemsg);
     sendJSON($arr);
 }
Exemple #10
0
function AJdelProfile()
{
    if (!checkUserHasPerm('Manage VM Profiles')) {
        sendJSON(array('failed' => 'noaccess'));
        return;
    }
    $profileid = processInputVar('profileid', ARG_NUMERIC);
    # check to see if profile is in use
    $query = "SELECT vh.computerid, " . "s.name " . "FROM vmhost vh, " . "computer c, " . "state s " . "WHERE vh.computerid = c.id AND " . "c.stateid = s.id AND " . "s.name IN ('vmhostinuse', 'tovmhostinuse') AND " . "vh.vmprofileid = {$profileid}";
    $qh = doQuery($query, 101);
    if ($row = mysql_fetch_assoc($qh)) {
        sendJSON(array('failed' => 'inuse'));
        return;
    }
    $query = "DELETE FROM vmprofile WHERE id = {$profileid}";
    doQuery($query, 101);
    sendJSON(array('SUCCESS'));
}
Exemple #11
0
function jsonGetUserGroupMembers()
{
    global $user;
    $usergrpid = processInputVar('groupid', ARG_NUMERIC);
    $domid = processInputVar('domid', ARG_STRING);
    $query = "SELECT g.ownerid, " . "g.affiliationid, " . "g.custom, " . "g.courseroll, " . "g2.name AS editgroup, " . "g2.editusergroupid AS editgroupid " . "FROM usergroup g " . "LEFT JOIN usergroup g2 ON (g.editusergroupid = g2.id) " . "WHERE g.id = {$usergrpid}";
    $qh = doQuery($query, 101);
    if (!($grpdata = mysql_fetch_assoc($qh))) {
        # problem getting group members
        $msg = 'failed to fetch group members';
        $arr = array('members' => $msg, 'domid' => $domid);
        sendJSON($arr);
        return;
    }
    if ($grpdata['custom'] == 1 && $user['id'] != $grpdata['ownerid'] && !array_key_exists($grpdata['editgroupid'], $user['groups']) || ($grpdata['custom'] == 0 || $grpdata['courseroll'] == 1) && !checkUserHasPerm('Manage Federated User Groups (global)') && (!checkUserHasPerm('Manage Federated User Groups (affiliation only)') || $grpdata['affiliationid'] != $user['affiliationid'])) {
        # user doesn't have access to view membership
        $msg = '(not authorized to view membership)';
        $arr = array('members' => $msg, 'domid' => $domid);
        sendJSON($arr);
        return;
    }
    $grpmembers = getUserGroupMembers($usergrpid);
    $members = '';
    foreach ($grpmembers as $group) {
        $members .= "{$group}<br>";
    }
    if ($members == '') {
        $members = '(empty group)';
    }
    $arr = array('members' => $members, 'domid' => $domid);
    sendJSON($arr);
}
Exemple #12
0
function XMLRPCgetUserGroupMembers($name, $affiliation)
{
    global $user;
    if (!in_array('groupAdmin', $user['privileges'])) {
        return array('status' => 'error', 'errorcode' => 16, 'errormsg' => 'access denied for managing groups');
    }
    $validate = array('name' => $name, 'affiliation' => $affiliation);
    $rc = validateAPIgroupInput($validate, 1);
    if ($rc['status'] == 'error') {
        return $rc;
    }
    $query = "SELECT ownerid, " . "editusergroupid AS editgroupid, " . "affiliationid, " . "custom, " . "courseroll " . "FROM usergroup " . "WHERE id = {$rc['id']}";
    $qh = doQuery($query, 101);
    if (!($row = mysql_fetch_assoc($qh))) {
        return array('status' => 'error', 'errorcode' => 18, 'errormsg' => 'user group with submitted name and affiliation does not exist');
    }
    // if custom and not owner and not member of managing group or
    //    custom/courseroll and no federated user group access, no access to delete group
    if ($row['custom'] == 1 && $user['id'] != $row['ownerid'] && !array_key_exists($row['editgroupid'], $user['groups']) || ($row['custom'] == 0 || $row['courseroll'] == 1) && !checkUserHasPerm('Manage Federated User Groups (global)') && (!checkUserHasPerm('Manage Federated User Groups (affiliation only)') || $row['affiliationid'] != $user['affiliationid'])) {
        return array('status' => 'error', 'errorcode' => 28, 'errormsg' => 'access denied to user group with submitted name and affiliation');
    }
    $query = "SELECT CONCAT(u.unityid, '@', a.name) AS member " . "FROM usergroupmembers ugm, " . "user u, " . "affiliation a " . "WHERE ugm.usergroupid = {$rc['id']} AND " . "ugm.userid = u.id AND " . "u.affiliationid = a.id";
    $qh = doQuery($query, 101);
    $members = array();
    while ($row = mysql_fetch_assoc($qh)) {
        $members[] = $row['member'];
    }
    return array('status' => 'success', 'members' => $members);
}