function getZones()
 {
     global $list_filters;
     if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN)) {
         $aParams = array();
         $aPublishers = Admin_DA::getPublishers($aParams);
         // set publisher id if list is to be filtered by publisher
         if (isset($list_filters['publisher'])) {
             $aParams = array('publisher_id' => $list_filters['publisher']);
         } else {
             // else use all publishers
             $aParams = array('publisher_id' => implode(',', array_keys($aPublishers)));
         }
         if (isset($this->_filter)) {
             $aParams['zone_inventory_forecast_type'] = $this->getForecastType();
         }
         $aZones = Admin_DA::getZones($aParams);
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
         $aParams = array('agency_id' => OA_Permission::getEntityId());
         $aPublishers = Admin_DA::getPublishers($aParams);
         // set publisher id if list is to be filtered by publisher
         if (isset($list_filters['publisher'])) {
             $aParams = array('publisher_id' => $list_filters['publisher']);
         } else {
             // else use all of this agency's publishers
             $aParams = array('publisher_id' => implode(',', array_keys($aPublishers)));
         }
         if (isset($this->_filter)) {
             $aParams['zone_inventory_forecast_type'] = $this->getForecastType();
         }
         $aZones = Admin_DA::getZones($aParams);
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER)) {
         $aParams = array('publisher_id' => OA_Permission::getEntityId());
         $aPublishers = Admin_DA::getPublishers($aParams);
         $aParams = array('publisher_id' => implode(',', array_keys($aPublishers)));
         if (isset($this->_filter)) {
             $aParams['zone_inventory_forecast_type'] = $this->getForecastType();
         }
         $aZones = Admin_DA::getZones($aParams);
     } else {
         $aPublishers = array();
         $aZones = array();
     }
     $aZoneArray = array();
     foreach ($aPublishers as $publisherId => $aPublisher) {
         foreach ($aZones as $zoneId => $aZone) {
             if ($aZone['publisher_id'] == $publisherId) {
                 $aZoneArray[$zoneId] = phpads_buildName($publisherId, MAX_getPublisherName($aPublisher['name'])) . " - " . phpAds_buildName($zoneId, MAX_getZoneName($aZone['name']));
             }
         }
     }
     return $aZoneArray;
 }
 /**
  * The final "child" implementation of the parental abstract method.
  *
  * @see OA_Admin_Statistics_Common::start()
  */
 function start()
 {
     // Get parameters
     $advertiserId = $this->_getId('advertiser');
     $placementId = $this->_getId('placement');
     $zoneId = $this->_getId('zone');
     // Security check
     OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER, OA_ACCOUNT_ADVERTISER);
     $this->_checkAccess(array('advertiser' => $advertiserId, 'placement' => $placementId));
     // Fetch campaigns
     $aZones = $this->getCampaignZones($placementId);
     // Cross-entity security check
     if (!isset($aZones[$zoneId])) {
         $this->noStatsAvailable = true;
     }
     // Add standard page parameters
     $this->aPageParams = array('clientid' => $advertiserId, 'campaignid' => $placementId, 'affiliateid' => $aZones[$zoneId]['publisher_id'], 'zoneid' => $zoneId);
     // Load the period preset and stats breakdown parameters
     $this->_loadPeriodPresetParam();
     $this->_loadStatsBreakdownParam();
     // Load $_GET parameters
     $this->_loadParams();
     // HTML Framework
     if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
         $this->pageId = '2.1.2.3.2';
         $this->aPageSections = array($this->pageId);
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
         $this->pageId = '1.2.3.2';
         $this->aPageSections = array($this->pageId);
     }
     // Add breadcrumbs
     $this->_addBreadcrumbs('campaign', $placementId);
     $this->addCrossBreadcrumbs('zone', $zoneId);
     // Add context
     $params = $this->aPageParams;
     foreach ($aZones as $k => $v) {
         $params['affiliateid'] = $aZones[$k]['publisher_id'];
         $params['zoneid'] = $k;
         phpAds_PageContext(MAX_buildName($k, MAX_getZoneName($v['name'], null, $v['anonymous'], $k)), $this->_addPageParamsToURI($this->pageName, $params, true), $zoneId == $k);
     }
     // Add shortcuts
     if (!OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
         $this->_addShortcut($GLOBALS['strClientProperties'], 'advertiser-edit.php?clientid=' . $advertiserId, 'images/icon-advertiser.gif');
     }
     $this->_addShortcut($GLOBALS['strCampaignProperties'], 'campaign-edit.php?clientid=' . $advertiserId . '&campaignid=' . $placementId, 'images/icon-campaign.gif');
     // Prepare the data for display by output() method
     $aParams = array('placement_id' => $placementId, 'zone_id' => $zoneId);
     $this->prepare($aParams, 'stats.php');
 }
 function addCrossBreadCrumbs($type, $entityId, $level = 0)
 {
     $cache = $this->crossEntitiesCache;
     switch ($type) {
         case 'campaign':
             if ($this->noStatsAvailable) {
                 $this->_addBreadcrumb('', MAX_getEntityIcon('placement'), $type);
             } else {
                 $this->_addBreadcrumb(MAX_buildName($entityId, MAX_getPlacementName($cache[$entityId])), MAX_getEntityIcon('placement'), $type);
             }
             break;
         case 'banner':
             if ($this->noStatsAvailable) {
                 $this->_addBreadcrumb('', MAX_getEntityIcon('ad'), $type);
             } else {
                 $this->_addBreadcrumb(MAX_buildName($entityId, MAX_getAdName($cache[$entityId]['name'], null, null, $cache[$entityId]['anonymous'], $entityId)), MAX_getEntityIcon('ad'), $type);
             }
             break;
         case 'publisher':
             if ($this->noStatsAvailable) {
                 $this->_addBreadcrumb('', MAX_getEntityIcon('publisher'), '');
             } else {
                 $this->_addBreadcrumb(MAX_buildName($entityId, MAX_getPublisherName($cache[$entityId]['name'], null, $cache[$entityId]['anonymous'], $entityId)), MAX_getEntityIcon('publisher'), 'website');
             }
             break;
         case 'zone':
             if ($this->noStatsAvailable) {
                 $this->_addBreadcrumb('', MAX_getEntityIcon('zone'), $type);
             } else {
                 $this->_addBreadcrumb(MAX_buildName($entityId, MAX_getZoneName($cache[$entityId]['name'], null, $cache[$entityId]['anonymous'], $entityId)), MAX_getEntityIcon('zone'), $type);
             }
             break;
     }
 }
 /**
  * Mask entities which have the hidden flag set
  *
  * @param array Entities array
  * @param string Name which should be used for hidden entitiies
  */
 function maskHiddenEntities(&$aEntitiesData, $entityType)
 {
     $this->fixLinkParams($aEntitiesData);
     foreach (array_keys($aEntitiesData) as $entityId) {
         if (isset($aEntitiesData[$entityId]['hidden']) && $aEntitiesData[$entityId]['hidden']) {
             switch ($entityType) {
                 case 'advertiser':
                     $aEntitiesData[$entityId]['name'] = MAX_getAdvertiserName($aEntitiesData[$entityId]['name'], null, true, $aEntitiesData[$entityId]['id']);
                     break;
                 case 'campaign':
                     $tmp = array('placement_id' => $aEntitiesData[$entityId]['id'], 'name' => $aEntitiesData[$entityId]['name'], 'anonymous' => true);
                     $aEntitiesData[$entityId]['name'] = MAX_getPlacementName($tmp);
                     break;
                 case 'banner':
                     $aEntitiesData[$entityId]['name'] = MAX_getAdName($aEntitiesData[$entityId]['name'], null, null, true, $aEntitiesData[$entityId]['id']);
                     break;
                 case 'publisher':
                     $aEntitiesData[$entityId]['name'] = MAX_getPublisherName($aEntitiesData[$entityId]['name'], null, true, $aEntitiesData[$entityId]['id']);
                     break;
                 case 'zone':
                     $aEntitiesData[$entityId]['name'] = MAX_getZoneName($aEntitiesData[$entityId]['name'], null, true, $aEntitiesData[$entityId]['id']);
                     break;
             }
             //$aEntitiesData[$entityId]['num_children'] = 0;
             //unset($aEntitiesData[$entityId]['subentities']);
         }
     }
     if ($this->listOrderField == 'name' || $this->listOrderField == 'id') {
         MAX_sortArray($aEntitiesData, $this->listOrderField, $this->listOrderDirection == 'up');
     }
 }
 /**
  * A private method to create and add the "connection detail" worksheet
  * of the report.
  *
  * @access private
  */
 function _addConnectionDetailWorksheet($aConnections, $aTrackerVariables)
 {
     // Create a worksheet
     $worksheetName = $this->translate("Connection Detail");
     $this->_oReportWriter->createReportWorksheet($worksheetName, $this->_name, $this->_getReportParametersForDisplay(), $this->_getReportWarningsForDisplay());
     $aStatus = $this->_getConnectionStatuses();
     // Create a subsection for each tracker
     foreach ($aTrackerVariables as $trackerId => $aTracker) {
         $trackerAnonymous = $this->_isTrackerLinkedToAnonymousCampaign($trackerId);
         $trackerName = MAX_getTrackerName($aTracker['tracker_name'], null, $trackerAnonymous, $trackerId);
         $aHeaders = array();
         $key = $this->translate("Connection ID");
         $aHeaders[$key] = 'id';
         $key = $this->translate("Connection Date / Time");
         $aHeaders[$key] = 'datetime';
         if (!empty($aTracker['variables'])) {
             foreach ($aTracker['variables'] as $trackerVariableId => $aTrackerVariable) {
                 $variableName = !empty($aTrackerVariable['tracker_variable_description']) ? $aTrackerVariable['tracker_variable_description'] : $aTrackerVariable['tracker_variable_name'];
                 // Don't display if the user is a publisher and the variable is hidden
                 if (!OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER) || $aTrackerVariable['tracker_variable_hidden'] != 't') {
                     switch ($aTrackerVariable['tracker_variable_data_type']) {
                         case 'int':
                         case 'numeric':
                             $aHeaders[$variableName] = 'numeric';
                             break;
                         case 'date':
                             $aHeaders[$variableName] = 'datetime';
                             break;
                         default:
                             $aHeaders[$variableName] = 'text';
                             break;
                     }
                 }
             }
         }
         $key = $this->translate("Approval Status");
         $aHeaders[$key] = 'text';
         $key = $this->translate("Comment");
         $aHeaders[$key] = 'text';
         if ($this->_shouldDisplaySourceField()) {
             $key = $GLOBALS['strSource'];
             $aHeaders[$key] = 'text';
         }
         $key = $this->translate("Advertiser Name");
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strTrackerName'];
         $aHeaders[$key] = 'text';
         $key = $this->translate("Ad Name");
         $aHeaders[$key] = 'text';
         $key = $this->translate("Website Name");
         $aHeaders[$key] = 'text';
         $key = $this->translate("Zone Name");
         $aHeaders[$key] = 'text';
         $key = $this->translate("Connection Type");
         $aHeaders[$key] = 'text';
         $key = $this->translate("Connecting Value Date / Time");
         $aHeaders[$key] = 'datetime';
         $key = $this->translate("IP Address");
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strCountry'];
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strDomain'];
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strLanguage'];
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strOS'];
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strBrowser'];
         $aHeaders[$key] = 'text';
         $key = $GLOBALS['strWindowDelay'];
         $aHeaders[$key] = 'text';
         $aData = array();
         if (!empty($aConnections[$trackerId]['connections'])) {
             $row = 0;
             foreach ($aConnections[$trackerId]['connections'] as $connectionId => $aConnection) {
                 // Skip connections with a hidden status
                 if (!isset($aStatus[$aConnection['connection_status']])) {
                     continue;
                 }
                 $aData[$row][] = $connectionId;
                 $aData[$row][] = $aConnection['tracker_date_time'];
                 if (!empty($aTracker['variables'])) {
                     foreach ($aTracker['variables'] as $trackerVariableId => $aTrackerVariable) {
                         // Don't display if the user is a publisher and the variable is hidden
                         if (!OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER) || $aTrackerVariable['tracker_variable_hidden'] != 't') {
                             $value = $aConnection['variables'][$trackerVariableId]['tracker_variable_value'];
                             if ($aTrackerVariable['tracker_variable_data_type'] == 'date') {
                                 // Change value to match Excel format
                                 $value = $this->_oReportWriter->convertToDate($value);
                             }
                             $aData[$row][] = $value;
                         }
                     }
                 }
                 $aData[$row][] = $this->_decodeConnectionStatus($aConnection['connection_status']);
                 $aData[$row][] = $aConnection['connection_comments'];
                 if ($this->_shouldDisplaySourceField()) {
                     $aData[$row][] = $aConnection['connection_channel'];
                 }
                 $aData[$row][] = MAX_getAdvertiserName($aConnection['advertiser_name'], null, $trackerAnonymous, $aConnection['advertiser_id']);
                 $aData[$row][] = $trackerName;
                 $aData[$row][] = MAX_getAdName($aConnection['ad_name'], $aConnection['ad_alt'], null, $trackerAnonymous, $aConnection['ad_id']);
                 $aData[$row][] = MAX_getPublisherName($aConnection['publisher_name'], null, $trackerAnonymous, $aConnection['publisher_id']);
                 $aData[$row][] = MAX_getZoneName($aConnection['zone_name'], null, $trackerAnonymous, $aConnection['zone_id']);
                 $aData[$row][] = $this->_decodeConnectionType($aConnection['connection_action']);
                 $aData[$row][] = $aConnection['connection_date_time'];
                 $aData[$row][] = $aConnection['connection_ip_address'];
                 $aData[$row][] = $aConnection['connection_country'];
                 $aData[$row][] = OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER) && $trackerAnonymous ? '' : $aConnection['connection_domain'];
                 $aData[$row][] = $aConnection['connection_language'];
                 $aData[$row][] = $aConnection['connection_os'];
                 $aData[$row][] = $aConnection['connection_browser'];
                 $aData[$row][] = $aConnection['window_delay'];
                 $row++;
             }
         }
         $this->_oReportWriter->createReportSection($worksheetName, $trackerName, $aHeaders, $aData, 30);
     }
 }