\n".$sql."\n";
$result = db_query($db,$sql);
if ( PEAR::isError($result) )
{
echo "
".$result->getMessage()."
\n";
}
while ($result->fetchInto($row))
{
while ($result->fetchInto($row))
{
$rkeys=array_keys($row);
foreach ($rkeys as $rkey)
{
$newelt = array_shift($row);
array_push($queues,$newelt);
}
}
}
# software usage
foreach ( $queues as $queue )
{
echo "System ".$_POST['system']." queue ".$queue."
\n";
echo "\n";
echo "package | jobs | cpuhours | accounts |
\n";
ob_flush();
flush();
$first=1;
$sql = "SELECT * FROM ( \n";
foreach ( $packages as $pkg )
{
if ( $first==1 )
{
$first=0;
}
else
{
$sql .= "UNION\n";
}
$sql .= "SELECT '".$pkg."', COUNT(jobid) AS jobs, SUM(".cpuhours($db,$_POST['system']).") AS cpuhours, COUNT(DISTINCT(account)) AS accounts FROM Jobs WHERE system LIKE '".$_POST['system']."' AND queue LIKE '".$queue."' 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 qsofttmp 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['csv']) )
{
$csvresult = db_query($db,$sql);
$columns = array("package","jobs","cpuhours","accounts");
result_as_csv($csvresult,$columns,$_POST['system']."-".$_POST['username']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']);
}
if ( isset($_POST['xls']) )
{
$xlsresult = db_query($db,$sql);
$columns = array("package","jobs","cpuhours","accounts");
result_as_xls($xlsresult,$columns,$_POST['system']."-".$_POST['username']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']);
}
if ( isset($_POST['ods']) )
{
$odsresult = db_query($db,$sql);
$columns = array("package","jobs","cpuhours","accounts");
result_as_ods($odsresult,$columns,$_POST['system']."-".$_POST['username']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']);
}
}
db_disconnect($db);
bookmarkable_url();
}
else
{
begin_form("queue-software.php");
system_chooser();
date_fields();
$orders=array("jobs","cpuhours","accounts");
$defaultorder="cpuhours";
pulldown("order","Order results by",$orders,$defaultorder);
checkbox("Generate CSV file","csv");
checkbox("Generate Excel file","xls");
checkbox("Generate ODF file","ods");
end_form();
}
page_footer();
?>