//  if (isset($_REQUEST['priority']))
//    $priority = $_REQUEST['priority'];
//
//  if ( !isset($_REQUEST['numberofruns'] )){
//    $numberOfRuns = 1;
//  } else {
//    $numberOfRuns = $_REQUEST['numberofruns'];
//  }
//
//  $userId = getCurrentUserId();
//
//if (isset($_REQUEST['runLabel']))
//    $runLabel=$_REQUEST['runLabel'];
//
//  if ( isset($resultId) && isset($userId) ){
//   processResultsForAll($resultId);
//  } else {
$twoWeeksAgo = current_seconds() - 1209600;
//    // Try to reprocess all reslults with missing data
$q = Doctrine_Query::create()->select('r.WPTResultId')->from('WPTResult r')->where('AvgFirstViewFirstByte = ?', 0)->andWhere('Date > ?', $twoWeeksAgo);
$resultIds = $q->fetchArray();
$q->free(true);
foreach ($resultIds as $resultId) {
    echo 'Processing: ' . $resultId['WPTResultId'] . '\\n';
    processResultsForAll($resultId['WPTResultId']);
}
echo 'Completed';
//  }
//  header("Location: ".$forwardTo);
/* Make sure that code below does not get executed when we redirect. */
exit;
        $l = $j['Label'];
        $jobArray[$i] = $l;
    }
    $smarty->assign('jobs', $jobArray);
    $smarty->display('report/downloadData.tpl');
    exit;
}
if ($_REQUEST['fromMonth']) {
    $fromDate = strtotime($_REQUEST['fromYear'] . "/" . $_REQUEST['fromMonth'] . "/" . $_REQUEST['fromDay'] . " " . $_REQUEST['fromHour'] . ":" . $_REQUEST['fromMinute']);
} else {
    $fromDate = current_seconds() - 86400;
}
if ($_REQUEST['toMonth']) {
    $toDate = strtotime($_REQUEST['toYear'] . "/" . $_REQUEST['toMonth'] . "/" . $_REQUEST['toDay'] . " " . $_REQUEST['toHour'] . ":" . $_REQUEST['toMinute']);
} else {
    $toDate = current_seconds();
}
try {
    header("Content-Type: text/csv");
    header("Content-Disposition: attachment; filename=\"data-" . $_REQUEST['fromYear'] . "-" . $_REQUEST['fromMonth'] . "-" . $_REQUEST['fromDay'] . "_" . $_REQUEST['toYear'] . "-" . $_REQUEST['toMonth'] . "-" . $_REQUEST['toDay'] . ".csv\"");
    print "label,id,status,valid,runlabel,date,wptjobid,wpthost,ttfb,dom,doc,fully,repeat ttfb,repeat dom,repeat doc,repeat fully\n";
    foreach ($labels as $label) {
        $data = getReportDataForLabel($label, $fromDate, $toDate, null, $runLabel);
        printResultData($data, $label);
    }
} catch (Exception $e) {
    print $e;
}
exit;
function printResultData($data, $label)
{