<?php

/**
* @desc This report displays a overview of referrrer conversion.
*/

define("_AGGREGATOR", "Aggregator test");

$ag_skip_cat = array("_KEY_METRIC", "_PERFORMANCE", "_TWITTER", "_FACEBOOK", "_OPENCART", "_ZENCART", "_INTERCOM", "_MAILCHIMP", "_LINKEDIN", "_BENCHMARK", "_TRANSALARM");

foreach ($reports as $k => $v) {
	if (isset($v['hidden']) && $v['hidden']==true) {
		continue;
	}
	if (in_array($v['Category'], $ag_skip_cat)) {
		continue;
	}
	if (isset($v['canAggregate']) && $v['canAggregate']==false) {
		continue;
	}
	
	$name = "_AG".$k; 
	define($name, constant($k)." ");
	$reports[$name] = $reports[$k];
	$reports[$name]["Options"] = str_replace(",trafficsource", "", $reports[$name]["Options"]);
	$reports[$name]["Options"] = str_replace(",profileselector", "", $reports[$name]["Options"]);
	$reports[$name]["Options"] .= ",profilelist";
	$reports[$name]["ClassName"] = "Aggregator".$reports[$k]["ClassName"];
	//$reports[$name]["Category"] = "_AGGREGATOR";
	$reports[$name]["aggregate"] = $k;
	
}


//dump($reports);
foreach ($reports as $k => $v) {
	if (isset($v['aggregate'])) {		
		$extension = $reports[ $v['aggregate'] ]["ClassName"];
		if (!isset($v['extrafunk'])) {
			$v['extrafunk'] = "";
		}
		if (strpos($extension, "Trend")!==false) {
			$dp = "";
		} else {
			$dp = ",perprofile";
		}
		eval('class '.$v['ClassName'].' extends '.$extension.' { '.$v['extrafunk'].' 
			
			function Settings() {
				parent::Settings();
				
				// add the per profile display option				
				@$this->DisplayModes .= "'.$dp.'";

				// if any cols are set to not display, override that until we`ve done GetReportData
				$this->resetColDef = [];
				foreach ($this->columnDefinitions as $k => $v) {
					if (isset($v["display"]) && $v["display"]==false) {						
						$this->columnDefinitions[$k]["display"] = true;
						$this->resetColDef[] = $k;
					}
				}				
			}
			function GetReportData() { 
				if ($this->displaymode =="perprofile") {
					$data = $this->GetReportDataPP("'.$v['aggregate'].'");	
				} else {
					$data = $this->AggregateReportData("'.$v['aggregate'].'");
					
				}

				// now reset the columnDefinitions
				foreach($this->resetColDef as $k) {
					$this->columnDefinitions[$k]["display"] = false;
				}
				return $data;
			}
			function DisplayReport() { 
				if (count($_REQUEST) > 4) {
					parent::DisplayReport();
				} else {
					$this->ReportHeader();
   					echoNotice($this->SettingsButton()." Please open settings and press submit");
				}
			}

		}');
		//echo "<hr>";
	} else {
		$reports[$k]['hidden'] = true;
	}
}

//die();
?>