<?php

include "../common.inc.php"; 
$profile = new SiteProfile($conf);

$thediv = @$_GET["thediv"];
$keyword= stripslashes(urldecode(@$_GET["keyword"]));
# it's no use to send someone to the trends screen for 1 day, so we'll override that here
if (($to-$from) <= 86400) {
    $trendfrom=($to - (14*86400));
} else {
    $trendfrom=$from;   
}

$referrer= urldecode(@$_GET["referrer"]);
$statuscode = @$_GET["statuscode"];
$forminput = urldecode(@$_GET["forminput"]);
$ipnumber= @$_GET["ipnumber"];
$visitorid= @$_GET["visitorid"];
$useragent= @$_GET["useragent"];  
$country= @$_GET["country"];
$error= @$_GET["error"];
$kpi= @$_GET["kpi"];
$crawler= @$_GET["crawler"];
$contextDate= @$_GET["contextDate"];
$utm_content= @$_GET["utm_content"];
$utm_source= @$_GET["utm_source"];
$utm_medium= @$_GET["utm_medium"];
$utm_campaign= @$_GET["utm_campaign"];
$utm_term= @$_GET["utm_term"];

if (empty($contextDate)) {
    $ctdate="from=$from&to=$to";
} else {
    $ctdate="minimumDate=$contextDate&maximumDate=$contextDate";
}

$url = @$_GET["url"];
if(!empty($_GET['clicktrailurl'])) {
	$fromclicktrail = true;
	$url = @$_GET["clicktrailurl"];
}
if(!empty($_GET['clicktrailreferrer'])) {
	$fromclicktrail = true;
	$referrer = @$_GET["clicktrailreferrer"];
}
if(!empty($_GET['clicktrailipnumber'])) {
	$fromclicktrail = true;
	$ipnumber = $_GET['clicktrailipnumber'];
}

$purl = urldecode($url);

if ($purl=="/") {
    $purl="/ (Home Page)";
}
if ($kpi!="") {
    $pkpi = urldecode($kpi);
    echo "<h5 class='actionmenu-header' title='$pkpi'><b>KPI: $pkpi</b></h5>";
    echo "<ul class='actionmenu-list'>";
    echo "<li><a class='open_in_new_dialog' type='_CONVERSION_TRENDS' href=\"reports.php?labels=_CONVERSION_TRENDS&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._CONVERSION_TRENDS."</a></li>";
    echo "<li><a class='open_in_new_dialog' type='_PERFORMANCE_TRENDS' href=\"reports.php?labels=_PERFORMANCE_TRENDS&conf=$conf&from=$from&to=$to\">"._PERFORMANCE_TRENDS."</a></li>";
    
    echo "<li class='divider'></li>";
    
    echo "<li><a class='open_in_new_dialog' type='_PAGE_CONVERSION' href=\"reports.php?labels=_PAGE_CONVERSION&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._PAGE_CONVERSION."</a></li>";
    echo "<li><a class='open_in_new_dialog' type='_REFERRER_CONVERSION' href=\"reports.php?labels=_REFERRER_CONVERSION&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._REFERRER_CONVERSION."</a></li>";
    echo "<li><a class='open_in_new_dialog' type='_KEYWORD_CONVERSION' href=\"reports.php?labels=_KEYWORD_CONVERSION&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._KEYWORD_CONVERSION."</a></li>";
    echo "<li><a class='open_in_new_dialog' type='_COUNTRY_CONVERSION' href=\"reports.php?labels=_COUNTRY_CONVERSION&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._COUNTRY_CONVERSION."</a></li>";
    echo "<li><a class='open_in_new_dialog' type='_TIME_TO_CONVERSION' href=\"reports.php?labels=_TIME_TO_CONVERSION&conf=$conf&from=$from&to=$to&roadto=".($kpi)."\">"._TIME_TO_CONVERSION."</a></li>";
   
    
    
    $url=$kpi;
}
if ($url!="") {

    if (strpos(urldecode($url),"?")!=FALSE) {
        $urlparts=explode("?",urldecode($url));
        $addcond="&cvalue2=".urlencode($urlparts[1])."&field2=params&condition2=contains&andor=AND";  
    } else {
        $urlparts[0]=$url;
        $addcond="";   
    }
	if (empty($kpi)) {
        echo "<h5 class='actionmenu-header' title='$purl'><b>$purl:</b></h5>";
        echo "<ul class='actionmenu-list'>";
        
    } else{
        echo "<li class='divider'></li>";
    }
    
    echo "<li><a class='open_in_new_dialog' type='_TREND_ANALYSIS' name='"._TREND_ANALYSIS."' rel='TrendAnalysis' href=\"reports.php?labels=_TREND_ANALYSIS&sourcetype=page&source=".$url."&conf=$conf&from=$from&to=$to\">"._SHOW_PAGE_TRENDS."</a></li>";
    
    echo "<li><a class='open_in_new_dialog' type='_PAGE_ANALYSIS' name='"._PAGE_ANALYSIS."' rel='PageAnalysis' href=\"reports.php?labels=_PAGE_ANALYSIS&page=".$url."&conf=$conf&$ctdate&crawlerselect= \">"._GO_TO_PAGE_ANALYSIS."</a></li>";
    
    if ($addcond=="") {
        echo "<li><a class='open_in_new_dialog' type='_TOP_PAGES_DETAILS' name='"._TOP_PAGES_DETAILS."' rel='TopPagesDetails' href=\"reports.php?labels=_TOP_PAGES_DETAILS&search=".$url."&searchmode=like&$ctdate&conf=$conf\">"._SHOW_ALL_PAGE_VARIATIONS."</a></li>";
    }
    echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&$ctdate&cvalue1=".$urlparts[0]."&conf=$conf&field1=url&condition1=is$addcond\">"._VIEW_CLICK_TRAIL_TO_PAGE."</a></li>";

    echo "<li><a class='open_in_new_dialog' type='_TOP_CLICK_PATHS' href=\"reports.php?labels=_TOP_CLICK_PATHS&$ctdate&searchmode=like&search=".$urlparts[0]."&conf=$conf\">"._TOP_CLICK_PATHS."</a></li>";
    
    echo "<li><a href=\\" .urldecode($url)."\" target=_blank>"._GO_TO_WEB_PAGE."</a></li>";
    
    if($session->canEditProfiles()) {	
        echo "<li class='divider'></li>";

        $filter = array("field0" => "url", "condition0" => "is", "cvalue0" => urldecode($url) );

		echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_FILTER_THIS_PAGE."</a></li>";		
		
		echo "<li><a class='open_delete_page' data-page='". urldecode($url) ."'>"._REMOVE_THIS_PAGE."</a></li>";
	}	

} else if ($keyword!="") {
    echo "<h5 class='actionmenu-header'><b>$keyword:</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_TREND_ANALYSIS' name='"._TREND_ANALYSIS."' rel='TrendAnalysis' href=\"reports.php?labels=_TREND_ANALYSIS&sourcetype=keyword&source=".urlencode($keyword)."&conf=$conf&from=$from&to=$to\">"._KEYWORD_OVER_TIME."</a></li>";
    
    
    echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&$ctdate&cvalue1=".urlencode($keyword)."&conf=$conf&field1=keywords&condition1=is\">"._VIEW_CLICK_TRAILS_KEYWORD."</a></li>";
    
	echo "<li><a class='open_in_new_dialog' type='_LANDING_PAGE' name='"._LANDING_PAGE."' rel='LandingPage' href=\"reports.php?labels=_LANDING_PAGE&sourcetype=keywords&$ctdate&source=".urlencode($keyword)."&conf=$conf\">"."Show Keyword landing page"."</a></li>";

    echo "<li><a class='open_in_new_dialog' type='_TOP_KEYWORDS_DETAILS' name='"._TOP_KEYWORDS_DETAILS."' rel='TopKeywordsDetails' href=\"reports.php?labels=_TOP_KEYWORDS_DETAILS&searchmode=like&$ctdate&conf=$conf&search=".urlencode($keyword)."\">"."Show Keyword sources"."</a></li>";
	
    if($session->canEditProfiles()) {	
        echo "<li class='divider'></li>";	

        $filter = array("field0" => "keywords", "condition0" => "contains", "cvalue0" => urldecode($keyword) );
		echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_FILTER_KEYWORD."</a></li>";
	}
    
} else if ($referrer!="") {
	$referrer = urldecode($referrer);
    if (strpos($referrer,"?")!=FALSE) {
        $refparts=explode("?",$referrer);
        $addcond="&cvalue2=".urlencode($refparts[1])."&field2=refparams&condition2=contains&andor=AND";  
    } else {
        $refparts[0]=$referrer;
        $addcond="";   
    }
    if (substr($referrer,0,3)=="[G]") {
        $showreferrer = substr($referrer,3);   
    } else {
        $showreferrer = $referrer;   
    }
    
    echo "<h5 class='actionmenu-header'><b>". urldecode($showreferrer) .":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_TREND_ANALYSIS' name='"._TREND_ANALYSIS."' rel='TrendAnalysis' href=\"reports.php?labels=_TREND_ANALYSIS&sourcetype=referrer&source=".urlencode($referrer)."&conf=$conf&from=$from&to=$to\">"._REFERRER_TREND_OVER_TIME."</a></li>";	
	
	echo "<li><a class='open_in_new_dialog' type='_LANDING_PAGE' name='"._LANDING_PAGE."' rel='LandingPage' href=\"reports.php?labels=_LANDING_PAGE&sourcetype=referrer&$ctdate&source=".urlencode($referrer)."&conf=$conf&sourcetype=referrer\">"."Show Referrer landing page"."</a></li>";
	
    
    echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&cvalue1=".urlencode($refparts[0])."&$ctdate&field1=referrer&condition1=contains$addcond&conf=$conf\">"._VIEW_CLICK_TRAILS_REFERRER."</a></li>";
    
    echo "<li><a href=\"".urldecode($showreferrer)."\" target=_blank>"._GO_TO_REFERRER_IN_NEW_WINDOW."</a></li>";   
    
	if($session->canEditProfiles()) {		
        echo "<li class='divider'></li>";

        $filter = array("field0" => "referrer", "condition0" => "contains", "cvalue0" => $referrer );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_FILTER_THIS_REFERRER."</a></li>";
	}
    
} else if ($statuscode!="") {
    
    $code = substr($statuscode,0,3);

    echo "<h5 class='actionmenu-header'><b>". $statuscode.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    
    
    
} else if ($forminput!="") {
    
    $input = explode("@",$forminput);
    $val = $input[0];
    $field = $input[1];
    $type = $input[2];
    
    if ($type=="funnelentry") {
        if ($val=="any") {$val="/";}
        if (substr($val,0,4)!="http") {  # It's a url
            $type="page";
        } else {
            $type="referrer";
        }
        $orival=$val;
        $val=explode(",",$val);
        # this gets only that last value to input into the script
        foreach($val as $valpart) {
            $realval=trim($valpart);
        }
        if ($realval == $orival) {
            $orival="";   
        } else if (count($val) > 1) {
            $orival = str_replace($realval,"",$orival);
        }
        
        $val=$realval;       
    }
    if (substr($type,-1)=="s") {
        $label=$type;   
    } else if ($type=="country") {
        $label="Countries";    
    } else {
        $label=$type."s";   
    }
    
    echo "<h5 class='actionmenu-header'>".ucwords($label)." matching: <b>\"". $val."\"</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    if ($type=="page" || $type=="url") 
    {
        if (substr($val,0,1)!="/") {
            $val="%".$val;   
        }
        if (strpos($val, "?")!==false) {
            echo "Autocomplete not available for urls with parameters";
            return;
        } else {
            $query = "select url as item from {$profile->tablename_urls} where url like ".$db->Quote($val.'%')." order by id asc limit 10";
        }
    } 
    else if ($type=="keyword" || $type=="keywords") 
    {
        $query = "select keywords as item from {$profile->tablename_keywords} where keywords like ".$db->Quote('%'.$val.'%')." order by id asc limit 10";
    } 
    else if ($type=="referrer") 
    {
        if (substr($val,0,4)!="http") {
            $val="%".$val;   
        }
        $query = "select referrer as item from {$profile->tablename_referrers} where referrer like ".$db->Quote($val.'%')." order by id asc limit 10";
    }
    else if ($type=="ipnumber") 
    {
        $query = "select ipnumber as item from {$profile->tablename_visitorids} where ipnumber like ".$db->Quote($val.'%')." order by id asc limit 10";
    }
    else if ($type=="visitorid") 
    {
        $query = "select visitorid as item from {$profile->tablename_visitorids} where visitorid like ".$db->Quote($val.'%')." order by id asc limit 10";
    }
    else if ($type=="params") 
    {
        if ($val=="") {$val="?";}
        if (substr($val,0,1)!="?") {
            $val="%".$val;   
        }
        $query = "select params as item from {$profile->tablename_urlparams} where params like ".$db->Quote($val.'%')." limit 10";
    }
    else if ($type=="status") 
    {        
        $query = "select code as realitem, concat(code,\" - \",descr) as item from ".TBL_LGSTATUS." where code like ".$db->Quote($val.'%');
    }
    else if ($type=="refparams") 
    {
        if ($val=="") {$val="?";}
        if (substr($val,0,1)!="?") {
            $val="%".$val;   
        }
        $query = "select params as item from {$profile->tablename_refparams} where params like ".$db->Quote($val.'%')." limit 10";
    }
    else if ($type=="useragent") 
    {        
        $query = "select DISTINCT(CONCAT(name, ' ', version)) as item from {$profile->tablename_useragents} where useragent like ".$db->Quote('%'.$val.'%')." order by id limit 10";
    }
    else if ($type=="country") 
    {        
        $query = "select distinct country as item from {$profile->tablename} where country like ".$db->Quote($val.'%')." limit 10";
    }
    else if ($type=="crawl") 
    {        
        $query = "select \"0 - Real People (Humans)\" as item, \"0\" as realitem union ";
        $query .= "select \"1 - Bots, Crawlers etc. (Computers)\" as item, \"1\" as realitem union ";
        $query .= "select \"2 - RSS Readers (Hits on Feed URLs)\" as item, \"2\" as realitem";
    }
    else if ($type=="is_mobile") 
    {        
        $query = "select \"0 = Not a Mobile Device\" as item, \"0\" as realitem union ";
        $query .= "select \"1 = A Mobile Device\" as item, \"1\" as realitem";
    }
    else if ($type=="kpi") 
    {        
        if ($profile->targetfiles) {         
            $targets=explode(",",$profile->targetfiles);   
            $query="";
            $i=0;
            foreach ($targets as $thistarget) {
                $thistarget=trim($thistarget);
                if ($thistarget) {
                    if ($val!="") {
                        if (strpos($thistarget,$val)===FALSE) {
                            continue;
                        }
                    } 
                    if ($i > 0) { $query .= " union "; }
                    $query .= "select ". $db->Quote($thistarget) ." as item";
                    $i++;
                }
            }
        }
    }
    
    $i=0;
    if (isset($query)) {    
        $q = $db->Execute($query);
        while ($data=$q->FetchRow()) {
            if (!isset($data['realitem'])) {
                if ($type=="country") {
                    $data['realitem'] = $data['item'];
                    if(!empty($cnames[$data["item"]])){
                        $data['item'] = $data["item"]." - ".$cnames[$data["item"]];
                    }
                } else {
                    $data['realitem']=$data['item'];
                }
            }
            if ($input[2]=="funnelentry") {
                $clickevent ="toFunnelForm('$field','".urldecode($data['realitem'])."','$orival');"; 
            } else {
                $clickevent ="toFormDynamic('$field','".urlencode($data['realitem'])."', this); return false;";
            }
            echo "<li><a href=# onclick=\"$clickevent\">".urldecode($data['item'])."</a></li>";
            $i++;
        }
        if ($i==0) {
            echo "<li>No $type found for \"$val\"</li>";
        }
    } else {
        echo "<li>Error: No valid type selected</li>";
    }
    
} else if ($ipnumber!="") {
    $vip = explode(";",$ipnumber);
    $ipnumber = $vip[0];
    if(isset($vip[1])){
		$visitorid = $vip[1]; # if we have a visitorid, we're coming from clicktrial.php
	}else{
		$visitorid = '';
	}

    echo "<h5 class='actionmenu-header'><b>". $ipnumber.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    if (!empty($visitorid)) {	
		echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&conf=$conf&field1=ipnumber&condition1=is&cvalue1=$ipnumber&visitorid=$visitorid&from=$from&to=$to\">"._VIEW_CLICKTRAILS_WITH_THIS_IPNUMBER."</a></li>";	
    } else {
		$visitorid_url = "reports.php?labels=_CLICK_TRAILS";
		$c = 0;
		foreach($_GET as $req_key => $req_val) {
			$visitorid_url .= "&{$req_key}={$req_val}";
			$c++;
		}
		$visitorid_url = urldecode($visitorid_url);
		
		echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"{$visitorid_url}&from=$from&to=$to\">"._VIEW_CLICKTRAILS_WITH_THIS_IPNUMBER."</a></li>";
		
    }    
    
    echo "<li><a href=\"https://apps.db.ripe.net/search/query.html?searchtext=$ipnumber\" target=_blank>"._RIPE_WHOIS_LOOKUP."</a></li>";
    
	if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";		

        $filter = array("field0" => "ipnumber", "condition0" => "is", "cvalue0" => $ipnumber );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_FILTER_THIS_IPNUMBER."</a></li>";
				
        echo "<li><a class='open_edit_visitor' data-vid='$visitorid' data-ipnumber='$ipnumber'>"._EDIT_VISITORS."</a></li>";

        echo "<li><a class='open_delete_ipnumber' data-ipnumber='$ipnumber'>"._REMOVE_THIS_IPNUMBER."</a></li>";
	}       
} else if ($country!="") {
    
    echo "<h5 class='actionmenu-header'><b>". urldecode($country).":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    $cc = array_flip($cnames);
    $cc = @$cc[urldecode($country)];

    if (empty($contextDate)) {
        $ctdate="from=$from&to=$to";
    } else {
        $ctdate="minimumDate=$contextDate&maximumDate=$contextDate";
    }

    echo "<li><a class='open_in_new_dialog' type='_COUNTRY_TRENDS' name='"._COUNTRY_TRENDS."' rel='CountryTrends' href=\"reports.php?labels=_COUNTRY_TRENDS&conf=$conf&country=$cc&displaymode=linechart&from=$from&to=$to\">"._COUNTRY_TRENDS."</a></li>";
    
    echo "<li><a class='open_in_new_dialog' type='_TOP_CITIES' name='"._TOP_CITIES."' rel='TopCities' href=\"reports.php?labels=_TOP_CITIES&conf=$conf&country=$cc&from=$from&to=$to\">"._TOP_CITIES."</a></li>";
    

    echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&conf=$conf&field1=country&condition1=is&cvalue1=$cc&visitorid=$visitorid&$ctdate\">"._CLICK_TRAILS."</a></li>";
    
    echo "<li><a class='open_in_new_dialog' type='_BROWSER_TRENDS' name='"._BROWSER_TRENDS."' rel='BrowserTrends' href=\"reports.php?labels=_BROWSER_TRENDS&conf=$conf&country=$cc&from=$from&to=$to\">"._BROWSER_TRENDS."</a></li>";
    
    echo "<li><a class='open_in_new_dialog' type='_OS_TRENDS' name='"._OS_TRENDS."' rel='OSTrends' href=\"reports.php?labels=_OS_TRENDS&conf=$conf&country=$cc&from=$from&to=$to\">"._OS_TRENDS."</a></li>";

    echo "<li><a class='open_in_new_dialog' type='_MOST_ACTIVE_USERS' name='"._MOST_ACTIVE_USERS."' rel='MostActiveVisitors' href=\"reports.php?labels=_MOST_ACTIVE_USERS&conf=$conf&country_list=$country&$ctdate\">"._MOST_ACTIVE_USERS."</a></li>";
    
     
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("field0" => "country", "condition0" => "is", "cvalue0" => $cc );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
         
    
} else if ($error!="") {
    
    $code = substr($error, 0,3);
    echo "<h5 class='actionmenu-header'><b>". urldecode($error).":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_DETAILED_ERROR_REPORT' href=\"reports.php?labels=_DETAILED_ERROR_REPORT&conf=$conf&$ctdate&status=$error\">"._VIEW_PAGES_WITH_THIS_STATUSCODE."</a></li>";    
    
    echo "<li><a class='open_in_new_dialog' type='_CLICK_TRAILS' name='"._CLICK_TRAILS."' rel='ClickTrail' href=\"reports.php?labels=_CLICK_TRAILS&$ctdate&conf=$conf&field1=status&condition1=is&cvalue1=$code\">"._VIEW_CLICKTRAILS_WITH_THIS_STATUSCODE."</a></li>";

    echo "<li class='divider'></li>";

    echo "<li><a class='open_in_new_dialog' type='_ERROR_REPORT' name='"._ERROR_REPORT."' rel='ErrorReport' href=\"reports.php?labels=_ERROR_REPORT&$ctdate&conf=$conf\">"._ERROR_REPORT."</a></li>";

    echo "<li><a class='open_in_new_dialog' type='_ERROR_TRENDS' href=\"reports.php?labels=_ERROR_TRENDS&conf=$conf&from=$from&to=$to\">"._ERROR_TRENDS."</a></li>";

    
} else if ($crawler!="") {
    
    
    echo "<h5 class='actionmenu-header'><b>". urldecode($crawler).":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_CRAWLER_TRENDS' href=\"reports.php?labels=_CRAWLER_TRENDS&conf=$conf&from=$from&to=$to\">"._CRAWLER_TRENDS."</a></li>";    
    
    echo "<li><a class='open_in_new_dialog' type='_MOST_ACTIVE_CRAWLERS' href=\"reports.php?labels=_MOST_ACTIVE_CRAWLERS&$ctdate&conf=$conf&searchmode=equals&search=$crawler\">"._MOST_ACTIVE_CRAWLERS."</a></li>";

    echo "<li><a class='open_in_new_dialog' type='_DETAILED_CRAWLER_REPORT' href=\"reports.php?labels=_DETAILED_CRAWLER_REPORT&$ctdate&conf=$conf&agent=".$crawler."\">"._DETAILED_CRAWLER_REPORT."</a></li>";

} else if ($utm_content!="") {    
    $utm_content = urldecode($utm_content);
    echo "<h5 class='actionmenu-header'><b>". $utm_content.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_UTM_TRENDS' href=\"reports.php?labels=_UTM_TRENDS&conf=$conf&from=$from&to=$to&viewData=_UTM_CONTENT&searchmode=equals&search=$utm_content\">"._UTM_TRENDS."</a></li>";    
    
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("name" => "UTM Content $utm_content", "category" => "Marketing Campaigns","field0" => "params", "condition0" => "contains", "cvalue0" => "utm_content=$utm_content" );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
} else if ($utm_source!="") {    
    $utm_source = urldecode($utm_source);
    echo "<h5 class='actionmenu-header'><b>". $utm_source.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_UTM_TRENDS' href=\"reports.php?labels=_UTM_TRENDS&conf=$conf&from=$from&to=$to&viewData=_UTM_SOURCES&searchmode=equals&search=$utm_source\">"._UTM_TRENDS."</a></li>";    
    
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("name" => "UTM Src $utm_source", "category" => "Marketing Campaigns","field0" => "params", "condition0" => "contains", "cvalue0" => "utm_source=$utm_source" );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
}else if ($utm_medium!="") {    
    $utm_medium = urldecode($utm_medium);
    echo "<h5 class='actionmenu-header'><b>". $utm_medium.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_UTM_TRENDS' href=\"reports.php?labels=_UTM_TRENDS&conf=$conf&from=$from&to=$to&viewData=_UTM_MEDIUM&searchmode=equals&search=$utm_medium\">"._UTM_TRENDS."</a></li>";    
    
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("name" => "UTM Medium $utm_medium", "category" => "Marketing Campaigns","field0" => "params", "condition0" => "contains", "cvalue0" => "utm_medium=$utm_medium" );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
} else if ($utm_campaign!="") {    
    $utm_campaign = urldecode($utm_campaign);
    echo "<h5 class='actionmenu-header'><b>". $utm_campaign.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_UTM_TRENDS' href=\"reports.php?labels=_UTM_TRENDS&conf=$conf&from=$from&to=$to&viewData=_UTM_CAMPAIGNS&searchmode=equals&search=$utm_campaign\">"._UTM_TRENDS."</a></li>";    
    
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("name" => "UTM Campaign $utm_campaign", "category" => "Marketing Campaigns","field0" => "params", "condition0" => "contains", "cvalue0" => "utm_campaign=$utm_campaign" );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
} else if ($utm_term!="") {    
    $utm_term = urldecode($utm_term);
    echo "<h5 class='actionmenu-header'><b>". $utm_term.":</b></h5>";
    echo "<ul class='actionmenu-list'>";
    
    echo "<li><a class='open_in_new_dialog' type='_UTM_TRENDS' href=\"reports.php?labels=_UTM_TRENDS&conf=$conf&from=$from&to=$to&viewData=_UTM_TERM&searchmode=equals&search=$utm_term\">"._UTM_TRENDS."</a></li>";    
    
    if($session->canEditProfiles()) {
        echo "<li class='divider'></li>";
        $filter = array("name" => "UTM Term $utm_term", "category" => "Marketing Campaigns","field0" => "params", "condition0" => "contains", "cvalue0" => "utm_term=$utm_term" );
        echo "<li><a class='actionmenu-filter' data-filter='". json_encode($filter) ."'>"._CREATE_NEW_SEGMENT."</a></li>";
    }
}



echo "<li class='divider'></li>";
echo "<li><a id=\"closeme\">"._CANCEL_CLOSE_MENU."</a></li>";
echo "</ul>";
?>
