}
// No data, no report to run, bail!
if (!isset($id)) {
    exit;
}
// No reports to run, bail!
if (!is_array($config['mailreports']['schedule'])) {
    exit;
}
// The Requested report doesn't exist, bail!
if (!$config['mailreports']['schedule'][$id]) {
    exit;
}
$thisreport = $config['mailreports']['schedule'][$id];
$graphs = $thisreport['row'];
// No graphs on the report, bail!
if (!is_array($graphs) || !(count($graphs) > 0)) {
    exit;
}
// Print report header
// For each graph, print a header and the graph
$attach = array();
$idx = 0;
foreach ($graphs as $thisgraph) {
    $dates = get_dates($thisgraph['period'], $thisgraph['timespan']);
    $start = $dates['start'];
    $end = $dates['end'];
    $attach[] = mail_report_generate_graph($thisgraph['graph'], $thisgraph['style'], $thisgraph['timespan'], $start, $end);
}
mail_report_send($thisreport['descr'], $attach);
// Print report header
// Print command output
$cmdtext = "";
foreach ($cmds as $cmd) {
    $output = "";
    $cmdtext .= "Command output: {$cmd['descr']} (" . htmlspecialchars($cmd['detail']) . ")<br />\n";
    exec($cmd['detail'], $output);
    $cmdtext .= "<pre>\n";
    $cmdtext .= implode("\n", $output);
    $cmdtext .= "\n</pre>";
}
// Print log output
$logtext = "";
foreach ($logs as $log) {
    $lines = empty($log['lines']) ? 50 : $log['lines'];
    $filter = empty($log['detail']) ? null : array($log['detail']);
    $logtext .= "Log output: " . get_friendly_log_name($log['logfile']) . " ({$log['logfile']})<br />\n";
    $logtext .= "<pre>\n";
    $logtext .= implode("\n", mail_report_get_log($log['logfile'], $lines, $filter));
    $logtext .= "\n</pre>";
}
// For each graph, print a header and the graph
$attach = array();
foreach ($graphs as $thisgraph) {
    $dates = get_dates($thisgraph['period'], $thisgraph['timespan']);
    $start = $dates['start'];
    $end = $dates['end'];
    $attach[] = mail_report_generate_graph($thisgraph['graph'], $thisgraph['style'], $thisgraph['timespan'], $start, $end);
}
mail_report_send($thisreport['descr'], $cmdtext, $logtext, $attach);