rendered paste body$rr_form = new HTML_QuickForm('report_request');
$rr_form->addElement('header', 'header', 'Downloaders Report');
$rr_form->addElement('select', 'report_by', 'Report type:', $group_options, array('style' => 'width: 100%'));
$rr_form->addElement('select', 'advertiser', 'Report for Foo:', $foo, array('style' => 'width: 100%'));
$rr_form->addElement('select', 'source', 'Report for source:', $source_options , array('style' => 'width: 100%'));
$rr_form->addElement('text', 'date_from', 'Since date:');
$rr_form->addElement('text', 'date_to', 'Up to:');
$rr_form->addElement('submit', null, 'Generate report');
$rr_form->display();
if ($rr_form->validate()) display_report($rr_form);
function display_report($form)
{
$where1 = array(1);
$where2 = array(1);
switch($form->exportValue('report_by'))
{
case 'advertiser':
$fields1[] = $fields2[] = "advertisers.name AS advertiser_name, COUNT(*) AS count";
....