public function beforePageHeader(OX_Admin_UI_Event_EventContext $oEventContext)
 {
     $pageId = $oEventContext->data['pageId'];
     $pageData = $oEventContext->data['pageData'];
     $oHeaderModel = $oEventContext->data['headerModel'];
     $agencyId = $pageData['agencyid'];
     $campaignId = $pageData['campaignid'];
     $advertiserId = $pageData['clientid'];
     $oEntityHelper = $this->oMarkedTextAdvertiserComponent->getEntityHelper();
     if (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
         switch ($pageId) {
             case 'campaign-banners':
                 $oDalZones = OA_Dal::factoryDAL('zones');
                 $linkedWebsites = $oDalZones->getWebsitesAndZonesListByCategory($agencyId, null, $campaignId, true);
                 $arraylinkedWebsitesKeys = array_keys($linkedWebsites);
                 $linkedWebsitesKey = $arraylinkedWebsitesKeys[0];
                 $arraylinkedZonesKeys = array_keys($linkedWebsites[$linkedWebsitesKey]['zones']);
                 $zoneId = $arraylinkedZonesKeys[0];
                 $aZone = Admin_DA::getZone($zoneId);
                 if ($aZone['type'] == 3) {
                     if (OA_Permission::hasAccessToObject('clients', $clientid) && OA_Permission::hasAccessToObject('campaigns', $campaignid)) {
                         OX_Admin_Redirect::redirect('plugins/' . $this->oMarkedTextAdvertiserComponent->group . "/oxMarkedTextAdvertiser-index.php?campaignid={$campaignId}&clientid={$advertiserId}");
                     }
                 }
                 break;
         }
     }
 }
 function setUp()
 {
     $this->dalData_intermediate_ad = OA_Dal::factoryDAL('data_intermediate_ad');
     $rsDal = $this->dalData_intermediate_ad->getDeliveredByCampaign(123);
     $aDelivered = $rsDal->toArray();
     foreach ($aDelivered as $delivered) {
         $this->assertNull($delivered);
     }
     $this->aIds = TestEnv::loadData('data_intermediate_ad_001');
 }
Esempio n. 3
0
 /**
  * Test that method returns correct object when DataObject exists and false otherwise.
  *
  * @TODO Add PEAR_Error expectations to simpletest in order to catch them
  */
 function testFactoryDAL()
 {
     // Test when object exists
     $dalBanners = OA_Dal::factoryDAL('banners');
     $this->assertIsA($dalBanners, 'MAX_Dal_Admin_Banners');
     // Test when object doesn't exist
     PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
     $dalBanners = OA_Dal::factoryDAL('foo' . rand());
     PEAR::staticPopErrorHandling();
     $this->assertFalse($dalBanners);
 }
Esempio n. 4
0
 function delete($useWhere = false, $cascade = true, $parentid = null)
 {
     // Find acls which use this channels
     $dalAcls = OA_Dal::factoryDAL('acls');
     $rsChannel = $dalAcls->getAclsByDataValueType($this->channelid, 'Site:Channel');
     $rsChannel->reset();
     while ($rsChannel->next()) {
         // Get the IDs of the banner that's using this channel
         $bannerId = $rsChannel->get('bannerid');
         // Get the remaining channels the banner will use, if any
         $aChannelIds = explode(',', $rsChannel->get('data'));
         $aChannelIds = array_diff($aChannelIds, array($this->channelid));
         // Prepare to update the banner's limitations in the "acls" table
         $doAcls = DB_DataObject::factory('acls');
         $doAcls->init();
         $doAcls->bannerid = $bannerId;
         $doAcls->executionorder = $rsChannel->get('executionorder');
         if (!empty($aChannelIds)) {
             $doAcls->data = implode(',', $aChannelIds);
             $doAcls->update();
         } else {
             $doAcls->delete();
         }
         // Re-compile the banner's limitations
         $aAcls = array();
         $doAcls = DB_DataObject::factory('acls');
         $doAcls->init();
         $doAcls->bannerid = $bannerId;
         $doAcls->orderBy('executionorder');
         $doAcls->find();
         while ($doAcls->fetch()) {
             $aData = $doAcls->toArray();
             $deliveryLimitationPlugin = OX_Component::factoryByComponentIdentifier('deliveryLimitations:' . $aData['type']);
             if ($deliveryLimitationPlugin) {
                 $deliveryLimitationPlugin->init($aData);
                 if ($deliveryLimitationPlugin->isAllowed($page)) {
                     $aAcls[$aData['executionorder']] = $aData;
                 }
             }
         }
         $sLimitation = MAX_AclGetCompiled($aAcls, $page);
         // TODO: it should be done inside plugins instead, there is no need to slash the data
         $sLimitation = !get_magic_quotes_runtime() ? stripslashes($sLimitation) : $sLimitation;
         $doBanners = OA_Dal::factoryDO('banners');
         $doBanners->bannerid = $bannerId;
         $doBanners->find();
         $doBanners->fetch();
         $doBanners->acl_plugins = MAX_AclGetPlugins($aAcls);
         $doBanners->acls_updated = OA::getNow();
         $doBanners->compiledlimitation = $sLimitation;
         $doBanners->update();
     }
     return parent::delete($useWhere, $cascade, $parentid);
 }
 public static function createTemplateWithModel($panel, $single = true)
 {
     $agencyId = OA_Permission::getAgencyId();
     $oDalZones = OA_Dal::factoryDAL('zones');
     $infix = $single ? '' : '-' . $panel;
     phpAds_registerGlobalUnslashed('action', 'campaignid', 'clientid', "text{$infix}", "page{$infix}");
     $campaignId = $GLOBALS['campaignid'];
     $text = $GLOBALS["text{$infix}"];
     $linked = $panel == 'linked';
     $showStats = empty($GLOBALS['_MAX']['CONF']['ui']['zoneLinkingStatistics']) ? false : true;
     $websites = $oDalZones->getWebsitesAndZonesList($agencyId, $campaignId, $linked, $text);
     $matchingZones = 0;
     foreach ($websites as $aWebsite) {
         $matchingZones += count($aWebsite['zones']);
     }
     $aZonesCounts = array('all' => $oDalZones->countZones($agencyId, null, $campaignId, $linked), 'matching' => $matchingZones);
     $pagerFileName = 'campaign-zone-zones.php';
     $pagerParams = array('clientid' => $GLOBALS['clientid'], 'campaignid' => $GLOBALS['campaignid'], 'status' => $panel, 'text' => $text);
     $currentPage = null;
     if (!$single) {
         $currentPage = $GLOBALS["page{$infix}"];
     }
     $oTpl = new OA_Admin_Template('campaign-zone-zones.html');
     $oPager = OX_buildPager($websites, self::WEBSITES_PER_PAGE, true, 'websites', 2, $currentPage, $pagerFileName, $pagerParams);
     $oTopPager = OX_buildPager($websites, self::WEBSITES_PER_PAGE, false, 'websites', 2, $currentPage, $pagerFileName, $pagerParams);
     list($itemsFrom, $itemsTo) = $oPager->getOffsetByPageId();
     $websites = array_slice($websites, $itemsFrom - 1, self::WEBSITES_PER_PAGE, true);
     // Add statistics for the displayed zones if required
     if ($showStats) {
         $oDalZones->mergeStatistics($websites, $campaignId);
     }
     // Count how many zone are displayed
     $showingCount = 0;
     foreach ($websites as $website) {
         $showingCount += count($website['zones']);
     }
     $aZonesCounts['showing'] = $showingCount;
     $oTpl->assign('pager', $oPager);
     $oTpl->assign('topPager', $oTopPager);
     $oTpl->assign('websites', $websites);
     $oTpl->assign('zonescounts', $aZonesCounts);
     $oTpl->assign('text', $text);
     $oTpl->assign('status', $panel);
     $oTpl->assign('page', $oTopPager->getCurrentPageID());
     $oTpl->assign('showStats', $showStats);
     $oTpl->assign('colspan', $showStats ? 6 : 3);
     return $oTpl;
 }
Esempio n. 6
0
 public static function createTemplateWithModel($panel, $single = true)
 {
     $agencyId = OA_Permission::getAgencyId();
     $oDalZones = OA_Dal::factoryDAL('zones');
     $infix = $single ? '' : '-' . $panel;
     phpAds_registerGlobalUnslashed('action', 'campaignid', 'clientid', "category{$infix}", "category{$infix}-text", "text{$infix}", "page{$infix}");
     $campaignId = $GLOBALS['campaignid'];
     $category = $GLOBALS["category{$infix}"];
     $categoryText = $GLOBALS["category{$infix}-text"];
     $text = $GLOBALS["text{$infix}"];
     $linked = $panel == 'linked';
     $websites = $oDalZones->getWebsitesAndZonesListByCategory($agencyId, $category, $campaignId, $linked, $text);
     $pagerFileName = 'campaign-zone-zones.php';
     $pagerParams = array('clientid' => $GLOBALS['clientid'], 'campaignid' => $GLOBALS['campaignid'], 'status' => $panel, 'category' => $category, 'category-text' => $categoryText, 'text' => $text);
     $currentPage = null;
     if (!$single) {
         $currentPage = $GLOBALS["page{$infix}"];
     }
     $oTpl = new OA_Admin_Template('campaign-zone-zones.html');
     $oPager = OX_buildPager($websites, self::WEBSITES_PER_PAGE, true, 'websites', 2, $currentPage, $pagerFileName, $pagerParams);
     $oTopPager = OX_buildPager($websites, self::WEBSITES_PER_PAGE, false, 'websites', 2, $currentPage, $pagerFileName, $pagerParams);
     list($itemsFrom, $itemsTo) = $oPager->getOffsetByPageId();
     $websites = array_slice($websites, $itemsFrom - 1, self::WEBSITES_PER_PAGE, true);
     $aZonesCounts = array('all' => $oDalZones->countZones($agencyId, null, $campaignId, $linked), 'matching' => $oDalZones->countZones($agencyId, $category, $campaignId, $linked, $text));
     $showingCount = 0;
     // TODO: currently we're calculating the number in PHP code. Once
     // MAX_Dal_Admin_Zones::countZones() supports the limit parameter, we can remove
     // the code below and use the dal.
     foreach ($websites as $website) {
         $showingCount += count($website['zones']);
     }
     $aZonesCounts['showing'] = $showingCount;
     $oTpl->assign('pager', $oPager);
     $oTpl->assign('topPager', $oTopPager);
     $oTpl->assign('websites', $websites);
     $oTpl->assign('zonescounts', $aZonesCounts);
     $oTpl->assign('category', $categoryText);
     $oTpl->assign('text', $text);
     $oTpl->assign('status', $panel);
     $oTpl->assign('page', $oTopPager->getCurrentPageID());
     return $oTpl;
 }
/**
 * Processes submit values of campaign form
 *
 * @param OA_Admin_UI_Component_Form $form form to process
 * @return An array of Pear::Error objects if any
 */
function processCampaignForm($form, &$oComponent = null)
{
    $aFields = $form->exportValues();
    if (!empty($aFields['start'])) {
        $oDate = new Date(date('Y-m-d 00:00:00', strtotime($aFields['start'])));
        $oDate->toUTC();
        $activate = $oDate->getDate();
    } else {
        $oDate = new Date(date('Y-m-d 00:00:00'));
        $oDate->toUTC();
        $activate = $oDate->getDate();
    }
    if (!empty($aFields['end'])) {
        $oDate = new Date(date('Y-m-d 23:59:59', strtotime($aFields['end'])));
        $oDate->toUTC();
        $expire = $oDate->getDate();
    } else {
        $expire = null;
    }
    if (empty($aFields['campaignid'])) {
        // The form is submitting a new campaign, so, the ID is not set;
        // set the ID to the string "null" so that the table auto_increment
        // or sequence will be used when the campaign is created
        $aFields['campaignid'] = "null";
    } else {
        // The form is submitting a campaign modification; need to test
        // if any of the banners in the campaign are linked to an email zone,
        // and if so, if the link(s) would still be valid if the change(s)
        // to the campaign were made...
        $dalCampaigns = OA_Dal::factoryDAL('campaigns');
        $aCurrentLinkedEmalZoneIds = $dalCampaigns->getLinkedEmailZoneIds($aFields['campaignid']);
        if (PEAR::isError($aCurrentLinkedEmalZoneIds)) {
            OX::disableErrorHandling();
            $errors[] = PEAR::raiseError($GLOBALS['strErrorDBPlain']);
            OX::enableErrorHandling();
        }
        $errors = array();
        foreach ($aCurrentLinkedEmalZoneIds as $zoneId) {
            $thisLink = Admin_DA::_checkEmailZoneAdAssoc($zoneId, $aFields['campaignid'], $activate, $expire);
            if (PEAR::isError($thisLink)) {
                $errors[] = $thisLink;
                break;
            }
        }
    }
    //correct and check revenue and ecpm
    correctAdnCheckNumericFormField($aFields, $errors, 'revenue', $GLOBALS['strErrorEditingCampaignRevenue']);
    correctAdnCheckNumericFormField($aFields, $errors, 'ecpm', $GLOBALS['strErrorEditingCampaignECPM']);
    if (empty($errors)) {
        //check booked limits values
        // If this is a remnant, ecpm or exclusive campaign with an expiry date, set the target's to unlimited
        if (!empty($expire) && ($aFields['campaign_type'] == OX_CAMPAIGN_TYPE_REMNANT || $aFields['campaign_type'] == OX_CAMPAIGN_TYPE_ECPM || $aFields['campaign_type'] == OX_CAMPAIGN_TYPE_CONTRACT_EXCLUSIVE)) {
            $aFields['impressions'] = $aFields['clicks'] = $aFields['conversions'] = -1;
        } else {
            if (!empty($aFields['impr_unlimited']) && $aFields['impr_unlimited'] == 't') {
                $aFields['impressions'] = -1;
            } else {
                if (empty($aFields['impressions']) || $aFields['impressions'] == '-') {
                    $aFields['impressions'] = 0;
                }
            }
            if (!empty($aFields['click_unlimited']) && $aFields['click_unlimited'] == 't') {
                $aFields['clicks'] = -1;
            } else {
                if (empty($aFields['clicks']) || $aFields['clicks'] == '-') {
                    $aFields['clicks'] = 0;
                }
            }
            if (!empty($aFields['conv_unlimited']) && $aFields['conv_unlimited'] == 't') {
                $aFields['conversions'] = -1;
            } else {
                if (empty($aFields['conversions']) || $aFields['conversions'] == '-') {
                    $aFields['conversions'] = 0;
                }
            }
        }
        //pricing model - reset fields not applicable to model to 0,
        //note that in new flow MAX_FINANCE_CPA allows all limits to be set
        if ($aFields['revenue_type'] == MAX_FINANCE_CPM) {
            $aFields['clicks'] = -1;
            $aFields['conversions'] = -1;
        } else {
            if ($aFields['revenue_type'] == MAX_FINANCE_CPC) {
                $aFields['conversions'] = -1;
            } else {
                if ($aFields['revenue_type'] == MAX_FINANCE_MT) {
                    $aFields['impressions'] = -1;
                    $aFields['clicks'] = -1;
                    $aFields['conversions'] = -1;
                }
            }
        }
        //check type and set priority
        if ($aFields['campaign_type'] == OX_CAMPAIGN_TYPE_REMNANT) {
            $aFields['priority'] = 0;
            //low
        } else {
            if ($aFields['campaign_type'] == OX_CAMPAIGN_TYPE_CONTRACT_NORMAL) {
                $aFields['priority'] = isset($aFields['high_priority_value']) ? $aFields['high_priority_value'] : 5;
                //high
            } else {
                if ($aFields['campaign_type'] == OX_CAMPAIGN_TYPE_CONTRACT_EXCLUSIVE) {
                    $aFields['priority'] = -1;
                    //exclusive
                } else {
                    if ($aFields['campaign_type'] == OX_CAMPAIGN_TYPE_ECPM) {
                        $aFields['priority'] = -2;
                        //ecpm
                    }
                }
            }
        }
        // Set target
        $target_impression = 0;
        $target_click = 0;
        $target_conversion = 0;
        if ($aFields['priority'] > 0) {
            // Daily targets need to be set only if the campaign doesn't have both expiration and lifetime targets
            $hasExpiration = !empty($expire);
            $hasLifetimeTargets = $aFields['impressions'] != -1 || $aFields['clicks'] != -1 || $aFields['conversions'] != -1;
            if (!($hasExpiration && $hasLifetimeTargets) && isset($aFields['target_value']) && $aFields['target_value'] != '-') {
                switch ($aFields['target_type']) {
                    case 'target_impression':
                        $target_impression = $aFields['target_value'];
                        break;
                    case 'target_click':
                        $target_click = $aFields['target_value'];
                        break;
                    case 'target_conversion':
                        $target_conversion = $aFields['target_value'];
                        break;
                }
            }
            $aFields['weight'] = 0;
        } else {
            // Set weight
            if (!isset($aFields['weight']) || $aFields['weight'] == '-' || $aFields['weight'] == '') {
                $aFields['weight'] = 0;
            }
        }
        if ($aFields['anonymous'] != 't') {
            $aFields['anonymous'] = 'f';
        }
        if ($aFields['companion'] != 1) {
            $aFields['companion'] = 0;
        }
        if ($aFields['show_capped_no_cookie'] != 1) {
            $aFields['show_capped_no_cookie'] = 0;
        }
        $new_campaign = $aFields['campaignid'] == 'null';
        if (empty($aFields['revenue']) || $aFields['revenue'] <= 0) {
            // No revenue information, set to null
            $aFields['revenue'] = OX_DATAOBJECT_NULL;
        }
        if (empty($aFields['ecpm']) || $aFields['ecpm'] <= 0) {
            // No ecpm information, set to null
            $aFields['ecpm'] = OX_DATAOBJECT_NULL;
        }
        // Get the capping variables
        $block = _initCappingVariables($aFields['time'], $aFields['capping'], $aFields['session_capping']);
        $doCampaigns = OA_Dal::factoryDO('campaigns');
        $doCampaigns->campaignname = $aFields['campaignname'];
        $doCampaigns->clientid = $aFields['clientid'];
        $doCampaigns->views = $aFields['impressions'];
        $doCampaigns->clicks = $aFields['clicks'];
        $doCampaigns->conversions = $aFields['conversions'];
        $doCampaigns->priority = $aFields['priority'];
        $doCampaigns->weight = $aFields['weight'];
        $doCampaigns->target_impression = $target_impression;
        $doCampaigns->target_click = $target_click;
        $doCampaigns->target_conversion = $target_conversion;
        $doCampaigns->min_impressions = $aFields['min_impressions'];
        $doCampaigns->ecpm = $aFields['ecpm'];
        $doCampaigns->anonymous = $aFields['anonymous'];
        $doCampaigns->companion = $aFields['companion'];
        $doCampaigns->show_capped_no_cookie = $aFields['show_capped_no_cookie'];
        $doCampaigns->comments = $aFields['comments'];
        $doCampaigns->revenue = $aFields['revenue'];
        $doCampaigns->revenue_type = $aFields['revenue_type'];
        $doCampaigns->block = $block;
        $doCampaigns->capping = $aFields['capping'];
        $doCampaigns->session_capping = $aFields['session_capping'];
        // Activation and expiration
        $doCampaigns->activate_time = isset($activate) ? $activate : OX_DATAOBJECT_NULL;
        $doCampaigns->expire_time = isset($expire) ? $expire : OX_DATAOBJECT_NULL;
        if (!empty($aFields['campaignid']) && $aFields['campaignid'] != "null") {
            $doCampaigns->campaignid = $aFields['campaignid'];
            $doCampaigns->setEcpmEnabled();
            $doCampaigns->update();
        } else {
            $doCampaigns->setEcpmEnabled();
            $aFields['campaignid'] = $doCampaigns->insert();
        }
        if ($oComponent) {
            $oComponent->processCampaignForm($aFields);
        }
        // Recalculate priority only when editing a campaign
        // or moving banners into a newly created, and when:
        //
        // - campaign changes status (activated or deactivated) or
        // - the campaign is active and target/weight are changed
        //
        if (!$new_campaign) {
            $doCampaigns = OA_Dal::staticGetDO('campaigns', $aFields['campaignid']);
            $status = $doCampaigns->status;
            switch (true) {
                case (bool) $status != (bool) $aFields['status_old']:
                    // Run the Maintenance Priority Engine process
                    OA_Maintenance_Priority::scheduleRun();
                    break;
                case $status == OA_ENTITY_STATUS_RUNNING:
                    if (!empty($aFields['target_type']) && ${$aFields['target_type']} != $aFields['target_old'] || !empty($aFields['target_type']) && $aFields['target_type_old'] != $aFields['target_type'] || $aFields['weight'] != $aFields['weight_old'] || $aFields['clicks'] != $aFields['previousclicks'] || $aFields['conversions'] != $aFields['previousconversions'] || $aFields['impressions'] != $aFields['previousimpressions']) {
                        // Run the Maintenance Priority Engine process
                        OA_Maintenance_Priority::scheduleRun();
                    }
                    break;
            }
        }
        // Rebuild cache
        // include_once MAX_PATH . '/lib/max/deliverycache/cache-'.$conf['delivery']['cache'].'.inc.php';
        // phpAds_cacheDelete();
        // Delete channel forecasting cache
        include_once 'Cache/Lite.php';
        $options = array('cacheDir' => MAX_CACHE);
        $cache = new Cache_Lite($options);
        $group = 'campaign_' . $aFields['campaignid'];
        $cache->clean($group);
        $translation = new OX_Translation();
        if ($new_campaign) {
            // Queue confirmation message
            $translated_message = $translation->translate($GLOBALS['strCampaignHasBeenAdded'], array(MAX::constructURL(MAX_URL_ADMIN, 'campaign-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid']), htmlspecialchars($aFields['campaignname']), MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'])));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            OX_Admin_Redirect::redirect("advertiser-campaigns.php?clientid=" . $aFields['clientid']);
        } else {
            $translated_message = $translation->translate($GLOBALS['strCampaignHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, 'campaign-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid']), htmlspecialchars($aFields['campaignname'])));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            OX_Admin_Redirect::redirect("campaign-edit.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid']);
        }
    }
    //return processing errors
    return $errors;
}
 /**
  * Method tests invalidateZonesLinkingCache method
  */
 function test_invalidateZonesLinkingCache()
 {
     $cachedData[0] = MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]);
     $cachedData[1] = MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][1]);
     $aZonesIds = array($this->_aIds['zones'][0], $this->_aIds['zones'][1]);
     // Unlink zones from campaign
     $dalZones = OA_Dal::factoryDAL('zones');
     $dalZones->unlinkZonesFromCampaign($aZonesIds, $this->_aIds['campaigns'][0]);
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]), $cachedData[0]);
     $this->assertEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][1]), $cachedData[1]);
     $this->oDeliveryCacheManager->invalidateZonesLinkingCache($aZonesIds);
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][0]), $cachedData[0]);
     $this->assertNotEqual(MAX_cacheGetZoneLinkedAds($this->_aIds['zones'][1]), $cachedData[1]);
 }
/*-------------------------------------------------------*/
/* Store preferences									 */
/*-------------------------------------------------------*/
$session['prefs']['inventory_entities'][OA_Permission::getEntityId()]['clientid'] = $clientid;
phpAds_SessionDataStore();
/*-------------------------------------------------------*/
/* HTML framework                                        */
/*-------------------------------------------------------*/
if (!isset($variables)) {
    if (isset($session['prefs']['tracker-variables.php']['variables']) && $session['prefs']['tracker-variables.php']['trackerid'] == $trackerid) {
        $variables = $session['prefs']['tracker-variables.php']['variables'];
    }
}
if (!empty($trackerid)) {
    // Get publisher list
    $dalAffiliates = OA_Dal::factoryDAL('affiliates');
    $rsAffiliates = $dalAffiliates->getPublishersByTracker($trackerid);
    $rsAffiliates->find();
    $publishers = array();
    while ($rsAffiliates->fetch() && ($row = $rsAffiliates->toArray())) {
        $publishers[$row['affiliateid']] = strip_tags(phpAds_BuildAffiliateName($row['affiliateid'], $row['name']));
    }
    if (!isset($variablemethod)) {
        // get variable method
        $doTrackers = OA_Dal::factoryDO('trackers');
        if ($doTrackers->get($trackerid)) {
            $variablemethod = $doTrackers->variablemethod;
        }
    }
    if (!isset($variables)) {
        // get variables from db
Esempio n. 10
0
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |
+---------------------------------------------------------------------------+
$Id: campaign-zone-link.php 37157 2009-05-28 12:31:10Z andrew.hill $
*/
// Require the initialisation file
require_once '../../init.php';
// Required files
require_once MAX_PATH . '/www/admin/config.php';
/*-------------------------------------------------------*/
/* Main code                                             */
/*-------------------------------------------------------*/
require_once MAX_PATH . '/lib/OA/Admin/Template.php';
require_once MAX_PATH . '/lib/OA/Admin/UI/CampaignZoneLink.php';
phpAds_registerGlobalUnslashed('action', 'campaignid', 'allSelected', 'category-linked', 'category-available', 'text-linked', 'text-available');
$agencyId = OA_Permission::getAgencyId();
$oDalZones = OA_Dal::factoryDAL('zones');
$action = $GLOBALS["action"];
$campaignId = $GLOBALS['campaignid'];
OA_Permission::enforceAccount(OA_ACCOUNT_MANAGER);
OA_Permission::enforceAccessToObject('campaigns', $campaignid);
$aZonesIds = array();
$aZonesIdsHash = array();
foreach ($_REQUEST['ids'] as $zone) {
    if (substr($zone, 0, 1) == 'z') {
        $aZonesIds[] = substr($zone, 1);
        $aZonesIdsHash[substr($zone, 1)] = "x";
    }
}
// If we're requested to link all matching zones, we need to determine the ids to link
// Ideally, there should be a DAL method to that directly. Note that we're replacing
// only the $aZonesIds array here, and keeping $aZonesIdsHash populated based on the
 function setUp()
 {
     $this->dalBanners = OA_Dal::factoryDAL('banners');
 }
 /**
  * Cleans up the session and carry on any additional tasks required to logout the user
  *
  */
 function logout()
 {
     phpAds_SessionDataDestroy();
     $dalAgency = OA_Dal::factoryDAL('agency');
     header("Location: " . $dalAgency->getLogoutUrl(OA_Permission::getAgencyId()));
     exit;
 }
 function setUp()
 {
     $this->dalChannel = OA_Dal::factoryDAL('channel');
 }
$rsChannel->find();
$allChannelsValid = true;
while ($rsChannel->fetch() && ($row = $rsChannel->toArray())) {
    if (!MAX_AclValidate('channel-acl.php', array('channelid' => $row['channelid']))) {
        $allChannelsValid = false;
        $affiliateName = !empty($row['affiliatename']) ? $row['affiliatename'] : $strUntitled;
        echo "<a href='channel-acl.php?affiliateid={$row['affiliateid']}&channelid={$row['channelid']}'>{$row['name']}</a><br />";
    }
}
if ($allChannelsValid) {
    echo $strChannelCompiledLimitationsValid;
}
phpAds_showBreak();
echo "<strong>{$strBanners}:</strong>";
phpAds_ShowBreak();
$dalBanners = OA_Dal::factoryDAL('banners');
$rsBanners = $dalBanners->getBannersCampaignsClients();
$rsBanners->find();
$allBannersValid = true;
while ($rsBanners->fetch() && ($row = $rsBanners->toArray())) {
    if (!MAX_AclValidate('banner-acl.php', array('bannerid' => $row['bannerid']))) {
        $allBannersValid = false;
        $bannerName = !empty($row['description']) ? $row['description'] : $strUntitled;
        $campaignName = !empty($row['campaignname']) ? $row['campaignname'] : $strUntitled;
        $clientName = !empty($row['clientname']) ? $row['clientname'] : $strUntitled;
        echo "{$clientName} -> {$campaignName} -> <a href='banner-acl.php?clientid={$row['clientid']}&campaignid={$row['campaignid']}&bannerid={$row['bannerid']}'>{$bannerName}</a><br />";
    }
}
if ($allBannersValid) {
    echo $strBannerCompiledLimitationsValid;
}
Esempio n. 15
0
 /**
  * @param $oDate
  * @param $campaignId
  * @return int Number of emails sent
  */
 function sendCampaignImpendingExpiryEmail($oDate, $campaignId)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     global $date_format;
     $oPreference = new OA_Preferences();
     if (!isset($this->aAdminCache)) {
         // Get admin account ID
         $adminAccountId = OA_Dal_ApplicationVariables::get('admin_account_id');
         // Get admin prefs
         $adminPrefsNames = $this->_createPrefsListPerAccount(OA_ACCOUNT_ADMIN);
         $aAdminPrefs = $oPreference->loadAccountPreferences($adminAccountId, $adminPrefsNames, OA_ACCOUNT_ADMIN);
         // Get admin users
         $aAdminUsers = $this->getAdminUsersLinkedToAccount();
         // Store admin cache
         $this->aAdminCache = array($aAdminPrefs, $aAdminUsers);
     } else {
         // Retrieve admin cache
         list($aAdminPrefs, $aAdminUsers) = $this->aAdminCache;
     }
     $aPreviousOIDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aPreviousOIDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aPreviousOIDates['start']);
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $campaignId);
     if (!$doCampaigns) {
         return 0;
     }
     $aCampaign = $doCampaigns->toArray();
     if (!isset($this->aClientCache[$aCampaign['clientid']])) {
         $doClients = OA_Dal::staticGetDO('clients', $aCampaign['clientid']);
         // Add advertiser linked users
         $aLinkedUsers['advertiser'] = $this->getUsersLinkedToAccount('clients', $aCampaign['clientid']);
         // Add advertiser prefs
         $advertiserPrefsNames = $this->_createPrefsListPerAccount(OA_ACCOUNT_ADVERTISER);
         $aPrefs['advertiser'] = $oPreference->loadAccountPreferences($doClients->account_id, $advertiserPrefsNames, OA_ACCOUNT_ADVERTISER);
         if (!isset($aAgencyCache[$doClients->agencyid])) {
             // Add manager linked users
             $doAgency = OA_Dal::staticGetDO('agency', $doClients->agencyid);
             $aLinkedUsers['manager'] = $this->getUsersLinkedToAccount('agency', $doClients->agencyid);
             // Add manager preferences
             $managerPrefsNames = $this->_createPrefsListPerAccount(OA_ACCOUNT_MANAGER);
             $aPrefs['manager'] = $oPreference->loadAccountPreferences($doAgency->account_id, $managerPrefsNames, OA_ACCOUNT_MANAGER);
             // Get agency "From" details
             $aAgencyFromDetails = $this->_getAgencyFromDetails($doAgency->agencyid);
             // Store in the agency cache
             $this->aAgencyCache = array($doClients->agencyid => array($aLinkedUsers['manager'], $aPrefs['manager'], $aAgencyFromDetails));
         } else {
             // Retrieve agency cache
             list($aLinkedUsers['manager'], $aPrefs['manager'], $aAgencyFromDetails) = $this->aAgencyCache[$doClients->agencyid];
         }
         // Add admin linked users and preferences
         $aLinkedUsers['admin'] = $aAdminUsers;
         $aPrefs['admin'] = $aAdminPrefs;
         // Create a linked user 'special' for the advertiser that will take the admin preferences for advertiser
         $aLinkedUsers['special']['advertiser'] = $doClients->toArray();
         $aLinkedUsers['special']['advertiser']['contact_name'] = $aLinkedUsers['special']['advertiser']['contact'];
         $aLinkedUsers['special']['advertiser']['email_address'] = $aLinkedUsers['special']['advertiser']['email'];
         $aLinkedUsers['special']['advertiser']['language'] = '';
         $aLinkedUsers['special']['advertiser']['user_id'] = 0;
         // Check that every user is not going to receive more than one email if they
         // are linked to more than one account
         $aLinkedUsers = $this->_deleteDuplicatedUser($aLinkedUsers);
         // Create the linked special user preferences from the admin preferences
         // the special user is the client that doesn't have preferences in the database
         $aPrefs['special'] = $aPrefs['admin'];
         $aPrefs['special']['warn_email_special'] = $aPrefs['special']['warn_email_advertiser'];
         $aPrefs['special']['warn_email_special_day_limit'] = $aPrefs['special']['warn_email_advertiser_day_limit'];
         $aPrefs['special']['warn_email_special_impression_limit'] = $aPrefs['special']['warn_email_advertiser_impression_limit'];
         // Store in the client cache
         $this->aClientCache = array($aCampaign['clientid'] => array($aLinkedUsers, $aPrefs, $aAgencyFromDetails));
     } else {
         // Retrieve client cache
         list($aLinkedUsers, $aPrefs, $aAgencyFromDetails) = $this->aClientCache[$aCampaign['clientid']];
     }
     $copiesSent = 0;
     foreach ($aLinkedUsers as $accountType => $aUsers) {
         if ($accountType == 'special' || $accountType == 'advertiser') {
             // Get the agency details and use them for emailing advertisers
             $aFromDetails = $aAgencyFromDetails;
         } else {
             // Use the Admin details
             $aFromDetails = '';
         }
         if ($aPrefs[$accountType]['warn_email_' . $accountType]) {
             // Does the account type want warnings when the impressions are low?
             if ($aPrefs[$accountType]['warn_email_' . $accountType . '_impression_limit'] > 0 && $aCampaign['views'] > 0) {
                 // Test to see if the placements impressions remaining are less than the limit
                 $dalCampaigns = OA_Dal::factoryDAL('campaigns');
                 $remainingImpressions = $dalCampaigns->getAdImpressionsLeft($aCampaign['campaignid']);
                 if ($remainingImpressions < $aPrefs[$accountType]['warn_email_' . $accountType . '_impression_limit']) {
                     // Yes, the placement will expire soon! But did the placement just reach
                     // the point where it is about to expire, or did it happen a while ago?
                     $previousRemainingImpressions = $dalCampaigns->getAdImpressionsLeft($aCampaign['campaignid'], $aPreviousOIDates['end']);
                     if ($previousRemainingImpressions >= $aPrefs[$accountType]['warn_email_' . $accountType . '_impression_limit']) {
                         // Yes! This is the operation interval that the boundary
                         // was crossed to the point where it's about to expire,
                         // so send that email, baby!
                         foreach ($aUsers as $aUser) {
                             $aEmail = $this->prepareCampaignImpendingExpiryEmail($aUser, $aCampaign['clientid'], $aCampaign['campaignid'], 'impressions', $aPrefs[$accountType]['warn_email_' . $accountType . '_impression_limit'], $accountType);
                             if ($aEmail !== false) {
                                 if ($this->sendMail($aEmail['subject'], $aEmail['contents'], $aUser['email_address'], $aUser['contact_name'], $aFromDetails)) {
                                     $copiesSent++;
                                     if ($aConf['email']['logOutgoing']) {
                                         phpAds_userlogSetUser(phpAds_userMaintenance);
                                         phpAds_userlogAdd(phpAds_actionWarningMailed, $aPlacement['campaignid'], "{$aEmail['subject']}\n\n\n                                                 {$aUser['contact_name']}({$aUser['email_address']})\n\n\n                                                 {$aEmail['contents']}");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // Does the account type want warnings when the days are low?
             if ($aPrefs[$accountType]['warn_email_' . $accountType . '_day_limit'] > 0 && !empty($aCampaign['expire_time'])) {
                 // Calculate the date that should be used to see if the warning needs to be sent
                 $warnSeconds = (int) ($aPrefs[$accountType]['warn_email_' . $accountType . '_day_limit'] + 1) * SECONDS_PER_DAY;
                 $oEndDate = new Date($aCampaign['expire_time']);
                 $oEndDate->setTZbyID('UTC');
                 $oTestDate = new Date();
                 $oTestDate->copy($oDate);
                 $oTestDate->addSeconds($warnSeconds);
                 // Test to see if the test date is after the placement's expiration date
                 if ($oTestDate->after($oEndDate)) {
                     // Yes, the placement will expire soon! But did the placement just reach
                     // the point where it is about to expire, or did it happen a while ago?
                     $oiSeconds = (int) $aConf['maintenance']['operationInterval'] * 60;
                     $oTestDate->subtractSeconds($oiSeconds);
                     if (!$oTestDate->after($oEndDate)) {
                         // Yes! This is the operation interval that the boundary
                         // was crossed to the point where it's about to expire,
                         // so send those emails, baby!
                         foreach ($aUsers as $aUser) {
                             $aEmail = $this->prepareCampaignImpendingExpiryEmail($aUser, $aCampaign['clientid'], $aCampaign['campaignid'], 'date', $oEndDate->format($date_format), $accountType);
                             if ($aEmail !== false) {
                                 if ($this->sendMail($aEmail['subject'], $aEmail['contents'], $aUser['email_address'], $aUser['contact_name'], $aFromDetails)) {
                                     $copiesSent++;
                                     if ($aConf['email']['logOutgoing']) {
                                         phpAds_userlogSetUser(phpAds_userMaintenance);
                                         phpAds_userlogAdd(phpAds_actionWarningMailed, $aPlacement['campaignid'], "{$aEmail['subject']}\n\n\n                                                 {$aUser['contact_name']}({$aUser['email_address']})\n\n\n                                                 {$aEmail['contents']}");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Restore the default language strings
     Language_Loader::load('default');
     return $copiesSent;
 }
require_once '../../init.php';
require_once MAX_PATH . '/lib/OX/Util/Utils.php';
// Required files
require_once MAX_PATH . '/lib/OA/Dal.php';
require_once MAX_PATH . '/lib/OA/Dll.php';
require_once MAX_PATH . '/www/admin/config.php';
require_once MAX_PATH . '/lib/OA/Permission.php';
// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_MANAGER, OA_ACCOUNT_ADVERTISER);
$aEntityMap = array();
if (!empty($clientid)) {
    if (!OA_Permission::hasAccessToObject('clients', $clientid)) {
        echo "{ }";
        exit;
    }
    // Retrieve list of campaigns
    $dalCampaigns = OA_Dal::factoryDAL('campaigns');
    $aCampaigns = $dalCampaigns->getClientCampaigns($clientid);
    foreach ($aCampaigns as $campaignId => $aCampaign) {
        $campaignName = $aCampaign['name'];
        $aEntityMap[$campaignId] = $campaignName;
    }
}
if (count($aEntityMap)) {
    while (list($k, $v) = each($aEntityMap)) {
        $aEntityMap[$k] = $k . ': { "name": "' . addslashes($v) . '" }';
    }
    echo "{" . implode(', ', $aEntityMap) . "}";
    exit;
}
echo "{ }";
 /**
  * Tests unlinkZonesFromBanner method
  *
  */
 function testUnlinkZonesFromBanner()
 {
     $dalZones = OA_Dal::factoryDAL('zones');
     // Create agency
     $doAgency = OA_Dal::factoryDO('agency');
     $doAgency->name = 'Ad Network Manager';
     $agencyId = DataGenerator::generateOne($doAgency);
     // Generate websites and zones
     $aWebsitesAndZones = $this->_aWebsitesAndZones;
     foreach ($aWebsitesAndZones as $websiteKey => $aWebsite) {
         if (is_array($aWebsite['zones'])) {
             foreach ($aWebsite['zones'] as $zoneKey => $aZone) {
                 $aWebsitesAndZones[$websiteKey]['zones'][$zoneKey]['width'] = 468;
                 $aWebsitesAndZones[$websiteKey]['zones'][$zoneKey]['height'] = 60;
                 $aWebsitesAndZones[$websiteKey]['zones'][$zoneKey]['delivery'] = phpAds_ZoneBanner;
             }
         }
     }
     $aAffiliatesIds = array();
     $aZonesIds = array();
     $this->_createWebsitesAndZones($aWebsitesAndZones, $agencyId, $aAffiliatesIds, $aZonesIds);
     // Generate advertisers and campaigns
     $aClientsIds = array();
     $aCampaignsIds = array();
     $this->_createAdvertisersAndCampaigns($this->_aAdvertisersAndCampaigns, $agencyId, $aClientsIds, $aCampaignsIds);
     $aBannerIds = array();
     // Add banners to campaigns
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->width = 468;
     $doBanners->height = 60;
     $doBanners->name = 'Banner 1 campaign 1 adv 1';
     $doBanners->campaignid = $aCampaignsIds[1][1];
     $aBannerIds[1][1][1] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 2 campaign 1 adv 1';
     $doBanners->campaignid = $aCampaignsIds[1][1];
     $aBannerIds[1][1][2] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 1 campaign 1 adv 2';
     $doBanners->campaignid = $aCampaignsIds[2][1];
     $aBannerIds[2][1][1] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 1 campaign 2 adv 1';
     $doBanners->campaignid = $aCampaignsIds[1][2];
     $aBannerIds[1][2][1] = DataGenerator::generateOne($doBanners);
     // Link banners and zones to campaigns
     $aFlatZonesIds1 = array($aZonesIds[1][1], $aZonesIds[1][2], $aZonesIds[1][3], $aZonesIds[2][1], $aZonesIds[2][2]);
     $result = $dalZones->linkZonesToCampaign($aFlatZonesIds1, $aCampaignsIds[1][1]);
     $aFlatZonesIds2 = array($aZonesIds[1][1], $aZonesIds[2][1]);
     $result = $dalZones->linkZonesToCampaign($aFlatZonesIds2, $aCampaignsIds[1][2]);
     // Empty zones array
     $result = $dalZones->unlinkZonesFromBanner(array(), $aBannerIds[1][1][1]);
     $this->assertEqual($result, 0);
     // Check if there is still 7 placement_zone_assoc (5 zones linked to $aCampaignsIds[1][1] and 2 zones linked to $aCampaignsIds[1][2])
     $doPlacementZoneAssoc = OA_Dal::factoryDO('placement_zone_assoc');
     $this->assertEqual($doPlacementZoneAssoc->count(), 7);
     // Check if there is still 12 ad_zone_assoc (5*2=10 banners linked to $aCampaignsIds[1][1] and 2*1=2 banners linked to $aCampaignsIds[1][2])
     $doAdZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZoneAssoc->whereAdd('zone_id <> 0');
     $this->assertEqual($doAdZoneAssoc->count(), 12);
     // remove all zones from $aBannerIds[1][2][1]
     $result = $dalZones->unlinkZonesFromBanner($aFlatZonesIds2, $aBannerIds[1][2][1]);
     $this->assertEqual($result, 2);
     // still 7, as placement_zone_assoc should be untouched
     $doPlacementZoneAssoc = OA_Dal::factoryDO('placement_zone_assoc');
     $this->assertEqual($doPlacementZoneAssoc->count(), 7);
     $doAdZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZoneAssoc->whereAdd('zone_id <> 0');
     $this->assertEqual($doAdZoneAssoc->count(), 10);
     // Remove 4 zones from campaign 1
     $aFlatZonesIds3 = array($aZonesIds[1][2], $aZonesIds[1][3], $aZonesIds[2][1], $aZonesIds[2][2]);
     $result = $dalZones->unlinkZonesFromBanner($aFlatZonesIds3, $aBannerIds[1][1][1]);
     $this->assertEqual($result, 4);
     $result = $dalZones->unlinkZonesFromBanner($aFlatZonesIds3, $aBannerIds[1][1][2]);
     $this->assertEqual($result, 4);
     $doAdZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZoneAssoc->whereAdd('zone_id <> 0');
     $this->assertEqual($doAdZoneAssoc->count(), 2);
     // zone with 2 banners
     // expected result:
     //  $aBannerIds[1][1][1] linked to zone $aZonesIds[1][1]
     //  $aBannerIds[1][1][2] linked to zone $aZonesIds[1][1]
     $aExpectedAdZoneAssocs = array(array('zone_id' => $aZonesIds[1][1], 'ad_id' => $aBannerIds[1][1][1]), array('zone_id' => $aZonesIds[1][1], 'ad_id' => $aBannerIds[1][1][2]));
     foreach ($aExpectedAdZoneAssocs as $aExpectedAdZoneAssoc) {
         $doAdZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc');
         $doAdZoneAssoc->zone_id = $aExpectedAdZoneAssoc['zone_id'];
         $doAdZoneAssoc->ad_id = $aExpectedAdZoneAssoc['ad_id'];
         $this->assertEqual($doAdZoneAssoc->count(), 1, "ad_zone_assoc not found for zone_id={$aExpectedAdZoneAssoc['zone_id']} and ad_id={$aExpectedAdZoneAssoc['ad_id']}");
     }
     // Remove last linked zone
     $result = $dalZones->unlinkZonesFromBanner(array($aZonesIds[1][1]), $aBannerIds[1][1][1]);
     $this->assertEqual($result, 1);
     $result = $dalZones->unlinkZonesFromBanner(array($aZonesIds[1][1]), $aBannerIds[1][1][2]);
     $this->assertEqual($result, 1);
     $doAdZoneAssoc = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZoneAssoc->whereAdd('zone_id <> 0');
     $this->assertEqual($doAdZoneAssoc->count(), 0);
 }
Esempio n. 18
0
/**
 * Recompiles all acls definitions for one of the type: banners or channel.
 *
 * @param string $aclsTable 'acls' or 'acls_channel'.
 * @param string $idColumn 'bannerid' or 'channelid'.
 * @param string $page 'banner-acl.php' or 'channel-acl.php'.
 * @param string $objectTable 'banners' or 'channel'
 * @return boolean True on success, PEAR::Error on failure.
 */
function OA_aclRecompileAclsForTable($aclsTable, $idColumn, $page, $objectTable, $upgrade = false)
{
    $dbh =& OA_DB::singleton();
    $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
    $table = $dbh->quoteIdentifier($prefix . $objectTable, true);
    $result = $dbh->exec("UPDATE {$table} SET compiledlimitation = '', acl_plugins = ''");
    if (PEAR::isError($result)) {
        return $result;
    }
    $dalAcls =& OA_Dal::factoryDAL('acls');
    $rsAcls = $dalAcls->getRsAcls($aclsTable, $idColumn);
    if (PEAR::isError($rsAcls)) {
        return $rsAcls;
    }
    $result = $rsAcls->find();
    if (PEAR::isError($result)) {
        return $result;
    }
    // Init variable to store limitation types to be upgraded
    $aUpgradeByType = array();
    // Init array to store all banner ACLs
    $aAcls = array();
    // Fetch first row
    if (!$rsAcls->fetch()) {
        // No rows, exit
        return true;
    }
    do {
        $row = $rsAcls->toArray();
        if (!isset($aUpgradeByType[$row['type']])) {
            // Plugin not loaded yet
            $oPlugin = OA_aclGetComponentFromRow($row);
            if ($oPlugin) {
                // Upgrade requested or plugin allowed
                $aUpgradeByType[$row['type']] = $upgrade || $oPlugin->isAllowed($page);
                unset($oPlugin);
            } else {
                $aUpgradeByType[$row['type']] = false;
            }
        }
        if ($aUpgradeByType[$row['type']]) {
            $aAcls[$row['executionorder']] = $row;
        }
        // Fetch next record
        $result = $rsAcls->fetch();
        // Was this the last one? Is the next record linked to another entity?
        if (!$result || $row[$idColumn] != $rsAcls->get($idColumn)) {
            // Yes, we need to save!
            $aEntities = array($idColumn => $row[$idColumn]);
            MAX_AclSave($aAcls, $aEntities, $page);
            $aAcls = array();
        }
    } while ($result);
    return true;
}
 function setUp()
 {
     $this->dalAgency = OA_Dal::factoryDAL('agency');
 }
 /**
  * Function creates 2 zones on 1 website and 2 campaigns 2 banners each under 1 advertiser
  * website and advertiser are under the same agency 
  *
  * @return array Array of DB Ids in format:
  *               array = ( 'zones' => array ( 0=> zone_id_1, ...),
  *                         'agency => array ( 0=> agency_id ) ... )
  *               keys: 'zones', 'affiliates', 'agency', 'clients', 'campaigns', 'images', 'banners', 'trackers', 'channel'
  */
 function _createTestData()
 {
     $aIds = array();
     // Create zones and websites
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->zonename = 'Zone 1';
     $doZones->width = 468;
     $doZones->height = 60;
     $doZones->delivery = phpAds_ZoneBanner;
     $aIds['zones'][0] = DataGenerator::generateOne($doZones, true);
     $aIds['affiliates'][0] = DataGenerator::getReferenceId('affiliates');
     $aIds['agency'][0] = DataGenerator::getReferenceId('agency');
     $doZones->zonename = 'Zone 2';
     $doZones->affiliateid = $aIds['affiliates'][0];
     $aIds['zones'][1] = DataGenerator::generateOne($doZones, true);
     $doClients = OA_Dal::factoryDO('clients');
     $doClients->clientname = 'Advertiser 1';
     $doClients->agencyid = $aIds['agency'][0];
     $aIds['clients'][0] = DataGenerator::generateOne($doClients);
     // Create campaigns
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Campaign 1';
     $doCampaigns->clientid = $aIds['clients'][0];
     $aIds['campaigns'][0] = DataGenerator::generateOne($doCampaigns);
     $doCampaigns->campaignname = 'Campaign 2';
     $aIds['campaigns'][1] = DataGenerator::generateOne($doCampaigns);
     // Create images and banners
     $doImages = OA_Dal::factoryDO('images');
     for ($i = 0; $i < 4; $i++) {
         $aIds['images'][$i] = 'test' . $i . '.gif';
         $doImages->filename = $aIds['images'][$i];
         DataGenerator::generateOne($doImages);
     }
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->width = 468;
     $doBanners->height = 60;
     $doBanners->storagetype = 'sql';
     $doBanners->contenttype = 'gif';
     $doBanners->name = 'Banner 1-1';
     $doBanners->filename = $aIds['images'][0];
     $doBanners->campaignid = $aIds['campaigns'][0];
     $aIds['banners'][0] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 1-2';
     $doBanners->filename = $aIds['images'][1];
     $doBanners->campaignid = $aIds['campaigns'][0];
     $aIds['banners'][1] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 2-1';
     $doBanners->filename = $aIds['images'][2];
     $doBanners->campaignid = $aIds['campaigns'][1];
     $aIds['banners'][2] = DataGenerator::generateOne($doBanners);
     $doBanners->name = 'Banner 2-2';
     $doBanners->filename = $aIds['images'][3];
     $doBanners->campaignid = $aIds['campaigns'][1];
     $aIds['banners'][3] = DataGenerator::generateOne($doBanners);
     // Create tracker
     $doTrackers = OA_Dal::factoryDO('trackers');
     $doTrackers->trackername = "Tracker 1";
     $doTrackers->clientid = $aIds['clients'][0];
     $aIds['trackers'][0] = DataGenerator::generateOne($doTrackers);
     // Create Channel
     $doChannel = OA_Dal::factoryDO('channel');
     $doChannel->agencyid = $aIds['agency'][0];
     $doChannel->affiliateid = $aIds['affiliates'][0];
     $doChannel->name = 'Website channel';
     $aIds['channel'][0] = DataGenerator::generateOne($doChannel);
     // link zones (and banners) to campaigns
     $dalZones = OA_Dal::factoryDAL('zones');
     $dalZones->linkZonesToCampaign($aIds['zones'], $aIds['campaigns'][0]);
     $dalZones->linkZonesToCampaign($aIds['zones'], $aIds['campaigns'][1]);
     return $aIds;
 }
         if ($plugin->getHook() == MSE_PLUGIN_HOOK_AdServer_saveSummary) {
             $plugin->serviceLocatorRegister();
             // Make sure it is the arrival plugin
             if ($oServiceLocator->get('financeSummaryTable') == $data_summary_table) {
                 break;
             } else {
                 $plugin->serviceLocatorRemove();
             }
         }
     }
 } else {
     $plugin = null;
     $data_summary_table = 'data_summary_ad_hourly';
 }
 // Update "data_intermediate_ad" table
 $dalData_intermediate_ad = OA_Dal::factoryDAL('data_intermediate_ad');
 $dalData_intermediate_ad->addConversion($operation, $basketValue, $numItems, $ad_id, $creative_id, $zone_id, $opDay, $opHour);
 // Update "$data_summary_table" table
 $dalData_intermediate_ad->addConversion($operation, $basketValue, $numItems, $ad_id, $creative_id, $zone_id, $opDay, $opHour, $data_summary_table);
 // Update finance info
 $oServiceLocator =& OA_ServiceLocator::instance();
 $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
 if (!$oDal) {
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDal = $oFactory->factory();
 }
 $oStartDate = new Date($oConnectionDate->format('%Y-%m-%d %H:00:00'));
 $oEndDate = new Date($oConnectionDate->format('%Y-%m-%d %H:00:00'));
 $oDal->_saveSummaryUpdateWithFinanceInfo($oStartDate, $oEndDate, $data_summary_table);
 if (!is_null($plugin)) {
     $plugin->serviceLocatorRemove();
Esempio n. 22
0
 /**
  * A method to determine the lifetime ad conversions left before expiration.
  *
  * @param integer    $campaignId The campaign ID.
  * @param PEAR::Date $oDate      An optional date. If present, sets an upper
  *                               date boundary of the end of the operation
  *                               interval the date is in to limit the delivery
  *                               statistics used in determining how many
  *                               conversions have delivered. Can be used to
  *                               determine the the lifetime ad conversions left
  *                               before expiration at a previous time.
  * @return mixed The number of ad conversions remaining, or the
  *               string "unlimited".
  */
 function getAdConversionsLeft($campaignId, $oDate = null)
 {
     global $strUnlimited;
     $prefix = $this->getTablePrefix();
     // Get the campaign info
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->get($campaignId);
     $aData = $doCampaigns->toArray();
     if ($aData['clicks'] > 0) {
         // Get the campaign delivery info
         if (!is_null($oDate)) {
             // Get the end of operation interval the date represents
             $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
             $oDate = $aDates['end'];
         }
         $dalDataIntermediateAd = OA_Dal::factoryDAL('data_intermediate_ad');
         $record = $dalDataIntermediateAd->getDeliveredByCampaign($campaignId, $oDate);
         $aDeliveryData = $record->toArray();
         return $aData['conversions'] - $aDeliveryData['conversions_delivered'];
     } else {
         return $strUnlimited;
     }
 }
    if (isset($session['prefs']['agency-index.php']['orderdirection'])) {
        $orderdirection = $session['prefs']['agency-index.php']['orderdirection'];
    } else {
        $orderdirection = '';
    }
}
if (isset($session['prefs']['agency-index.php']['nodes'])) {
    $node_array = explode(",", $session['prefs']['agency-index.php']['nodes']);
} else {
    $node_array = array();
}
/*-------------------------------------------------------*/
/* Main code                                             */
/*-------------------------------------------------------*/
// Get agencies & campaign and build the tree
$dalAgency = OA_Dal::factoryDAL('agency');
$aManagers = $dalAgency->getAllManagers($listorder, $orderdirection);
foreach ($aManagers as $k => $v) {
    $aManagers[$k]['expand'] = 0;
    $aManagers[$k]['count'] = 0;
    $aManagers[$k]['hideinactive'] = 0;
}
echo "\t\t\t\t<table border='0' width='100%' cellpadding='0' cellspacing='0'>\n";
echo "\t\t\t\t<tr height='25'>\n";
echo "\t\t\t\t\t<td height='25' width='40%'>\n";
echo "\t\t\t\t\t\t<b>&nbsp;&nbsp;<a href='agency-index.php?listorder=name'>" . $GLOBALS['strName'] . "</a>";
if ($listorder == "name" || $listorder == "") {
    if ($orderdirection == "" || $orderdirection == "down") {
        echo " <a href='agency-index.php?orderdirection=up'>";
        echo "<img src='" . OX::assetPath() . "/images/caret-ds.gif' border='0' alt='' title=''>";
    } else {
 function setUp()
 {
     $this->dalClients = OA_Dal::factoryDAL('clients');
 }
/**
 * @todo Consider using PEAR Cache::Lite instead of globals for caching
 */
function phpAds_getClientDetails($clientid)
{
    global $clientCache;
    if (isset($clientCache[$clientid]) && is_array($clientCache[$clientid])) {
        $client_details = $clientCache[$clientid];
    } else {
        $dalClients = OA_Dal::factoryDAL('clients');
        $client_details = $dalClients->getAdvertiserDetails($clientid);
        $clientCache[$clientid] = $client_details;
    }
    return $client_details;
}
     $agencyId = OA_Permission::getAgencyId();
     $aCampaigns = $oDal->updateCampaignsPriorityByAgency($agencyId, $updateFrom, $updateTo);
     foreach ($aCampaigns as $campaignId => $aCampaign) {
         if ($aCampaign['status_changed'] && $aCampaign['status'] == OA_ENTITY_STATUS_INACTIVE) {
             // store without string indexes, to not to waste space in session
             $aInactivatedCampaignsIds[$campaignId] = array($campaignId, $aCampaign['clientid'], $aCampaign['campaignname']);
         }
     }
     $runMaintenance = true;
 }
 // We changed contract
 if ((bool) $_POST['contract_ecpm_enabled'] != (bool) $pref['contract_ecpm_enabled']) {
     // Reload the prefs we just changed into the global variable because
     // we use it when setting ecpm_enabled in the DO.
     OA_Preferences::loadPreferences();
     $oDal = OA_Dal::factoryDAL('campaigns');
     $agencyId = OA_Permission::getAgencyId();
     $aCampaigns = $oDal->updateEcpmEnabledByAgency($agencyId);
     foreach ($aCampaigns as $campaignId => $aCampaign) {
         if ($aCampaign['status_changed'] && $aCampaign['status'] == OA_ENTITY_STATUS_INACTIVE) {
             // store without string indexes, to not to waste space in session
             $aInactivatedCampaignsIds[$campaignId] = array($campaignId, $aCampaign['clientid'], $aCampaign['campaignname']);
         }
     }
     $runMaintenance = true;
 }
 // store the list of inactivated campaigns in the session
 if (!empty($aInactivatedCampaignsIds)) {
     $session['aInactivatedCampaignsIds'] = $aInactivatedCampaignsIds;
     phpAds_SessionDataStore();
 }
function getAdvertiserMap()
{
    $aAdvertisers = array();
    $dalClients = OA_Dal::factoryDAL('clients');
    if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
        $agency_id = OA_Permission::getEntityId();
        $aAdvertisers = $dalClients->getAllAdvertisersForAgency($agency_id);
    } else {
        if (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
            $advertiserId = OA_Permission::getEntityId();
            $aAdvertiser = $dalClients->getAdvertiserDetails($advertiserId);
            $aAdvertisers[$advertiserId] = $aAdvertiser;
        }
    }
    $aAdvertiserMap = array();
    foreach ($aAdvertisers as $clientid => $aClient) {
        $aAdvertiserMap[$clientid] = array('name' => $aClient['clientname'], 'url' => "advertiser-campaigns.php?clientid=" . $clientid);
    }
    return $aAdvertiserMap;
}
Esempio n. 28
0
 /**
  * Links a campaign to the given tracker ID
  *
  * @param int $trackerId the ID of the tracker to link the campaign to.
  * @param int $campaignId the ID of the campaign to link to the tracker.
  * @param int $status optional connection status type, eg MAX_CONNECTION_STATUS_APPROVED. See constants.php.
  *                    if no status given, uses the tracker's default status.
  * @return boolean true on successful link, false on error.
  */
 public function linkTrackerToCampaign($trackerId, $campaignId, $status = null)
 {
     if (!$this->checkIdExistence('trackers', $trackerId)) {
         $this->raiseError(self::ERROR_UNKNOWN_TRACKER_ID);
         return false;
     }
     if (!$this->checkIdExistence('campaigns', $campaignId)) {
         $this->raiseError(self::ERROR_UNKNOWN_CAMPAIGN_ID);
         return false;
     }
     if (!$this->checkPermissions(array(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER), 'trackers', $oTrackerInfo->trackerId)) {
         return false;
     }
     if (!$this->checkSameAdvertiser($trackerId, $campaignId)) {
         $this->raiseError(self::ERROR_CAMPAIGN_ADVERTISER_MISMATCH);
         return false;
     }
     $dalTrackers = OA_Dal::factoryDAL('trackers');
     $aLinkedCampaigns = $dalTrackers->getLinkedCampaigns($trackerId);
     if (!isset($aLinkedCampaigns[$campaignId])) {
         $result = $dalTrackers->linkCampaign($trackerId, $campaignId, $status);
         if (PEAR::isError($result)) {
             $this->raiseError($result->getMessage());
             return false;
         }
         return true;
     } else {
         // Already linked
         return true;
     }
 }
Esempio n. 29
0
 /**
  * A method to test the getLinkedEmailZoneIds() method.
  *
  * Note that the banner/zone association in this test is
  * performed via the Admin_DA class, as a result of the fact
  * that neither the "zone" or "banner" Entity Service
  * classes support this functionality at the time of writing.
  */
 function testGetLinkedEmailZoneIds()
 {
     $oDataGenerator = new DataGenerator();
     $dalZones = OA_Dal::factoryDAL('zones');
     // Test with invalid input
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds('foo');
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     // Test with invalid campaign IDs
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds(-1);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds(0);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds(2);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     // Generate an owning manager account
     $doAgency = OA_Dal::factoryDO('agency');
     $managerId = $oDataGenerator->generateOne($doAgency);
     // Generate an advertiser account within the manager account
     $doClients = OA_Dal::factoryDO('clients');
     $doClients->agencyid = $managerId;
     $advertiserId = $oDataGenerator->generateOne($doClients);
     // Generate a website account within the manager account
     $doAffiliates = OA_Dal::factoryDO('affiliates');
     $doAffiliates->agencyid = $managerId;
     $websiteId = $oDataGenerator->generateOne($doAffiliates);
     // Generate a campaign, with start and end dates
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->clientid = $advertiserId;
     $doCampaigns->activate_time = '2009-02-23 00:00:00';
     $doCampaigns->expire_time = '2009-02-24 23:59:59';
     $campaignId = $oDataGenerator->generateOne($doCampaigns);
     // Generate a banner in the campaign generated above
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $campaignId;
     $bannerId = $oDataGenerator->generateOne($doBanners);
     // Test with no linked zones
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds($campaignId);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     // Add two non-email zones, and link the campaign to the zones
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->affiliateid = $websiteId;
     $doZones->delivery = phpAds_ZoneBanner;
     $zoneId1 = $oDataGenerator->generateOne($doZones);
     $result = $dalZones->linkZonesToCampaign(array($zoneId1), $campaignId);
     $this->assertEqual($result, 1);
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->affiliateid = $websiteId;
     $doZones->delivery = phpAds_ZonePopup;
     $zoneId2 = $oDataGenerator->generateOne($doZones);
     $result = $dalZones->linkZonesToCampaign(array($zoneId2), $campaignId);
     $this->assertEqual($result, 1);
     // Test with linked zones that are not email zones
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds($campaignId);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(empty($aResult));
     // Add an email zone, and link the campaign's banner to the zone
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->affiliateid = $websiteId;
     $doZones->delivery = MAX_ZoneEmail;
     $zoneId3 = $oDataGenerator->generateOne($doZones);
     $aParameters = array('zone_id' => $zoneId3, 'ad_id' => $bannerId);
     $result = Admin_DA::addAdZone($aParameters);
     $this->assertTrue($result);
     // Test with linked zones, one of which is an email zone
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds($campaignId);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(!empty($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult[0], $zoneId3);
     // Add another email zone, and link the campaign's banner to the zone
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->affiliateid = $websiteId;
     $doZones->delivery = MAX_ZoneEmail;
     $zoneId4 = $oDataGenerator->generateOne($doZones);
     $aParameters = array('zone_id' => $zoneId4, 'ad_id' => $bannerId);
     $result = Admin_DA::addAdZone($aParameters);
     $this->assertTrue($result);
     // Test with linked zones, some of which are email zones
     $aResult = $this->oDalCampaigns->getLinkedEmailZoneIds($campaignId);
     $this->assertTrue(is_array($aResult));
     $this->assertTrue(!empty($aResult));
     $this->assertEqual(count($aResult), 2);
     $this->assertEqual($aResult[0], $zoneId3);
     $this->assertEqual($aResult[1], $zoneId4);
 }
Esempio n. 30
0
/**
 * Show a confirm message for zone delete
 *
 * @param int $zoneId Zone ID
 * @return string
 */
function MAX_zoneDelConfirm($zoneId)
{
    $dalZones = OA_Dal::factoryDAL('zones');
    return phpAds_DelConfirm($dalZones->checkZoneLinkedToActiveCampaign($zoneId) ? $GLOBALS['strConfirmDeleteZoneLinkActive'] . '\\n' . $GLOBALS['strConfirmDeleteZone'] : $GLOBALS['strConfirmDeleteZone']);
}