}
}
if (isset($Session['prefs']['stats-global-advertiser.php']['nodes'])) {
    $node_array = explode(",", $Session['prefs']['stats-global-advertiser.php']['nodes']);
} else {
    $node_array = array();
}
/*********************************************************/
/* Main code                                             */
/*********************************************************/
// Get clients & campaign and build the tree
if (phpAds_isUser(phpAds_Admin)) {
    $res_clients = phpAds_dbQuery("SELECT clientid,clientname" . " FROM " . $phpAds_config['tbl_clients'] . phpAds_getClientListOrder($listorder, $orderdirection)) or phpAds_sqlDie();
    $res_campaigns = phpAds_dbQuery("SELECT campaignid,campaignname,clientid,views,clicks,conversions,active" . " FROM " . $phpAds_config['tbl_campaigns'] . phpAds_getCampaignListOrder($listorder, $orderdirection)) or phpAds_sqlDie();
} elseif (phpAds_isUser(phpAds_Agency)) {
    $res_clients = phpAds_dbQuery("SELECT clientid,clientname" . " FROM " . $phpAds_config['tbl_clients'] . " WHERE agencyid=" . phpAds_getUserID() . phpAds_getClientListOrder($listorder, $orderdirection)) or phpAds_sqlDie();
    $res_campaigns = phpAds_dbQuery("SELECT m.campaignid as campaignid" . ",m.campaignname as campaignname" . ",m.clientid as clientid" . ",m.views as views" . ",m.clicks as clicks" . ",m.conversions as conversions" . ",m.active as active" . " FROM " . $phpAds_config['tbl_campaigns'] . " AS m" . "," . $phpAds_config['tbl_clients'] . " AS c" . " WHERE m.clientid=c.clientid" . " AND c.agencyid=" . phpAds_getUserID() . phpAds_getCampaignListOrder($listorder, $orderdirection)) or phpAds_sqlDie();
}
while ($row_clients = phpAds_dbFetchArray($res_clients)) {
    $clients[$row_clients['clientid']] = $row_clients;
    $clients[$row_clients['clientid']]['expand'] = 0;
    $clients[$row_clients['clientid']]['count'] = 0;
    $clients[$row_clients['clientid']]['hideinactive'] = 0;
}
while ($row_campaigns = phpAds_dbFetchArray($res_campaigns)) {
    $campaigns[$row_campaigns['campaignid']] = $row_campaigns;
    $campaigns[$row_campaigns['campaignid']]['expand'] = 0;
    $campaigns[$row_campaigns['campaignid']]['count'] = 0;
}
switch ($period) {
    case 't':
        $query = "SELECT clientid" . " FROM " . $phpAds_config['tbl_clients'] . " WHERE clientid=" . $clientid . " AND agencyid=" . phpAds_getUserID();
        $res = phpAds_dbQuery($query) or phpAds_sqlDie();
        if (phpAds_dbNumRows($res) == 0) {
            phpAds_PageHeader("2");
            phpAds_Die($strAccessDenied, $strNotAdmin);
        }
    }
}
/*********************************************************/
/* HTML framework                                        */
/*********************************************************/
if (phpAds_isUser(phpAds_Admin) || phpAds_isUser(phpAds_Agency)) {
    if (phpAds_isUser(phpAds_Admin)) {
        $query = "SELECT clientid,clientname" . " FROM " . $phpAds_config['tbl_clients'] . phpAds_getClientListOrder($navorder, $navdirection);
    } elseif (phpAds_isUser(phpAds_Agency)) {
        $query = "SELECT clientid,clientname" . " FROM " . $phpAds_config['tbl_clients'] . " WHERE agencyid=" . phpAds_getUserID() . phpAds_getClientListOrder($navorder, $navdirection);
    }
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row = phpAds_dbFetchArray($res)) {
        phpAds_PageContext(phpAds_buildName($row['clientid'], $row['clientname']), "stats-advertiser-history.php?clientid=" . $row['clientid'], $clientid == $row['clientid']);
    }
    phpAds_PageShortcut($strClientProperties, 'advertiser-edit.php?clientid=' . $clientid, 'images/icon-advertiser.gif');
    if (phpAds_isUser(phpAds_Admin)) {
        $extra = "<br><br><br>";
        $extra .= "<b>{$strMaintenance}</b><br>";
        $extra .= "<img src='images/break.gif' height='1' width='160' vspace='4'><br>";
        $extra .= "<a href='stats-reset.php?clientid={$clientid}'" . phpAds_DelConfirm($strConfirmResetClientStats) . ">";
        $extra .= "<img src='images/" . $phpAds_TextDirection . "/icon-undo.gif' align='absmiddle' border='0'>&nbsp;{$strResetStats}</a>";
        $extra .= "<br><br>";
    }
    phpAds_PageHeader("2.1.1", $extra);
if (phpAds_isUser(phpAds_Admin) || phpAds_isUser(phpAds_Agency)) {
    if (isset($Session['prefs']['advertiser-index.php']['listorder'])) {
        $navorder = $Session['prefs']['advertiser-index.php']['listorder'];
    } else {
        $navorder = '';
    }
    if (isset($Session['prefs']['advertiser-index.php']['orderdirection'])) {
        $navdirection = $Session['prefs']['advertiser-index.php']['orderdirection'];
    } else {
        $navdirection = '';
    }
    // Get other advertisers
    if (phpAds_isUser(phpAds_Admin)) {
        $query = "SELECT * FROM " . $phpAds_config['tbl_clients'] . phpAds_getClientListOrder($navorder, $navdirection);
    } elseif (phpAds_isUser(phpAds_Agency)) {
        $query = "SELECT * FROM " . $phpAds_config['tbl_clients'] . " WHERE agencyid=" . $Session['userid'] . phpAds_getClientListOrder($navorder, $navdirection);
    }
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row = phpAds_dbFetchArray($res)) {
        phpAds_PageContext(phpAds_buildName($row['clientid'], $row['clientname']), "advertiser-trackers.php?clientid=" . $row['clientid'], $clientid == $row['clientid']);
    }
    phpAds_PageShortcut($strClientHistory, 'stats-advertiser-history.php?clientid=' . $clientid, 'images/icon-statistics.gif');
    phpAds_PageHeader("4.1.4");
    echo "\t\t\t\t<img src='images/icon-advertiser.gif' align='absmiddle'>&nbsp;\n";
    echo "\t\t\t\t<b>" . phpAds_getClientName($clientid) . "</b>\n";
    echo "\t\t\t\t<br><br><br>\n";
    phpAds_ShowSections(array("4.1.2", "4.1.3", "4.1.4"));
}
/*********************************************************/
/* Main code                                             */
/*********************************************************/