\n";
echo "
package | jobs | cpuhours | users | accounts |
\n";
ob_flush();
flush();
$first=1;
$sql = "SELECT * FROM ( ";
foreach ( $packages as $pkg )
{
if ( $first==1 )
{
$first=0;
}
else
{
$sql .= "UNION\n";
}
$sql .= "SELECT '".$pkg."', COUNT(jobid) AS jobs, SUM(nproc*TIME_TO_SEC(walltime))/3600.0 AS cpuhours, COUNT(DISTINCT(username)) AS users, COUNT(DISTINCT(account)) AS accounts FROM Jobs WHERE system LIKE '".$_POST['system']."' AND groupname LIKE '".$_POST['groupname']."' AND ( ";
if ( isset($pkgmatch[$pkg]) )
{
$sql .= $pkgmatch[$pkg];
}
else
{
$sql .= "script LIKE '%".$pkg."%' OR software LIKE '%".$package."%'";
}
$sql .= " ) AND ( ".dateselect("start",$_POST['start_date'],$_POST['end_date'])." )";
$sql .= "\n";
}
$sql .= " ) AS grpsofttmp WHERE jobs > 0 ORDER BY ".$_POST['order']." DESC";
#echo "\n".$sql."
\n";
$result = db_query($db,$sql);
while ($result->fetchInto($row))
{
$rkeys=array_keys($row);
echo "";
foreach ($rkeys as $rkey)
{
$data[$rkey]=array_shift($row);
echo "".$data[$rkey]." | ";
}
echo "
\n";
ob_flush();
flush();
}
echo "\n";
if ( isset($_POST['xls']) )
{
$xlsresult = db_query($db,$sql);
$columns = array("package","jobs","cpuhours","users","accounts");
result_as_xls($xlsresult,$columns,$_POST['system']."-".$_POST['groupname']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']);
}
if ( isset($_POST['ods']) )
{
$odsresult = db_query($db,$sql);
$columns = array("package","jobs","cpuhours","users","accounts");
result_as_ods($odsresult,$columns,$_POST['system']."-".$_POST['groupname']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']);
}
db_disconnect($db);
bookmarkable_url();
}
else
{
begin_form("group-software.php");
text_field("Group","groupname",16);
system_chooser();
date_fields();
$orders=array("jobs","cpuhours","users");
$defaultorder="cpuhours";
pulldown("order","Order results by",$orders,$defaultorder);
checkbox("Generate Excel file","xls");
checkbox("Generate ODF file","ods");
end_form();
}
page_footer();
?>