function test_MAX_commonSlashArray()
 {
     $this->sendMessage('test_MAX_commonSlashArray');
     $strIn0 = "Mr O\\'Reilly";
     $strIn1 = '"Mr Reilly"\\n';
     $strRe0 = addslashes($strIn0);
     $strRe1 = addslashes($strIn1);
     $aIn = array(0 => $strIn0, 1 => array(0 => $strIn1));
     $aRet = MAX_commonSlashArray($aIn);
     $this->assertEqual($aRet[0], $strRe0);
     $this->assertEqual($aRet[1][0], $strRe1);
 }
示例#2
0
function write_sim_ini_file($confAll)
{
    if (array_key_exists('realConfig', $_REQUEST)) {
        $conf['realConfig'] = $_REQUEST['realConfig'];
    } else {
        if (array_key_exists('realConfig', $confAll)) {
            $conf['realConfig'] = $confAll['realConfig'];
        }
    }
    if (array_key_exists('simdb', $_REQUEST)) {
        $conf['simdb'] = $_REQUEST['simdb'];
    } else {
        if (array_key_exists('simdb', $confAll)) {
            $conf['simdb'] = $confAll['simdb'];
        }
    }
    if (array_key_exists('scenario', $_REQUEST)) {
        $conf['scenario'] = $_REQUEST['scenario'];
    } else {
        if (array_key_exists('scenario', $confAll)) {
            $conf['scenario'] = $confAll['scenario'];
        }
    }
    if (array_key_exists('request', $_REQUEST)) {
        $conf['request'] = $_REQUEST['request'];
    } else {
        if (array_key_exists('request', $confAll)) {
            $conf['request'] = $confAll['request'];
        }
    }
    if (array_key_exists('delivery', $_REQUEST)) {
        $conf['delivery'] = $_REQUEST['delivery'];
    } else {
        if (array_key_exists('delivery', $confAll)) {
            $conf['delivery'] = $confAll['delivery'];
        }
    }
    if (array_key_exists('delivery', $_REQUEST)) {
        $conf['logging'] = $_REQUEST['logging'];
    } else {
        if (array_key_exists('logging', $confAll)) {
            $conf['logging'] = $confAll['logging'];
        }
    }
    $content = '';
    if (isset($conf['realConfig'])) {
        if ($conf['realConfig']) {
            $content .= "realConfig = \"{$conf['realConfig']}\"\n";
        }
        unset($conf['realConfig']);
    }
    require_once MAX_PATH . '/lib/max/other/common.php';
    $conf = MAX_commonSlashArray($conf);
    $content = parse_conf_for_ini_file($conf, $content, true);
    if ($handle = fopen(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php', 'w')) {
        fwrite($handle, $content);
        fclose($handle);
    }
    return get_conf();
}
示例#3
0
/**
* Recursively add slashes to the values in an array.
*
* @param array Input array.
* @return array Output array with values slashed.
*/
function MAX_commonSlashArray($a)
{
    if (is_array($a)) {
        reset($a);
        while (list($k, $v) = each($a)) {
            $a[$k] = MAX_commonSlashArray($v);
        }
        reset($a);
        return $a;
    } else {
        return is_null($a) ? null : addslashes($a);
    }
}
示例#4
0
 /**
  * Returns an array of constraints given an entity with params.
  *
  * @param string $entity
  * @param array $aParams
  * @return array
  */
 function _getLimitations($entity, $aParams)
 {
     if (!empty($aParams) && is_array($aParams)) {
         $aParams = MAX_commonSlashArray($aParams);
     }
     $aLimitations = array();
     // size limitation e.g. ((width = -1 AND height = -1) OR (width = 468 AND height = 60));
     $aSizeLimitations = array();
     $aZoneSize = array();
     if (isset($aParams['ad_width'])) {
         SqlBuilder::_addLimitation($aZoneSize, 'ad_width', 'd.width', $aParams['ad_width']);
     }
     if (isset($aParams['ad_height'])) {
         SqlBuilder::_addLimitation($aZoneSize, 'ad_height', 'd.height', $aParams['ad_height']);
     }
     $zoneSize = implode(' AND ', $aZoneSize);
     if (!empty($zoneSize)) {
         if (!empty($aParams['ad_nosize'])) {
             $aNoSize = array();
             SqlBuilder::_addLimitation($aNoSize, 'ad_width', 'd.width', -1);
             SqlBuilder::_addLimitation($aNoSize, 'ad_height', 'd.height', -1);
             $aSizeLimitations[] = '(' . implode(' AND ', $aNoSize) . ')';
         }
         $aSizeLimitations[] = '(' . $zoneSize . ')';
         $sizeLimitation = implode(' OR ', $aSizeLimitations);
         if (!empty($sizeLimitation)) {
             $aLimitations[] = '(' . $sizeLimitation . ')';
         }
     }
     if (!empty($aParams['ad_type'])) {
         if ($aParams['ad_type'] == "!txt") {
             SqlBuilder::_addLimitation($aLimitations, 'ad_type', 'd.storagetype', 'txt', MAX_LIMITATION_NOT_EQUAL);
         } else {
             SqlBuilder::_addLimitation($aLimitations, 'ad_type', 'd.storagetype', $aParams['ad_type']);
         }
     }
     if (!empty($aParams['ad_active'])) {
         SqlBuilder::_addLimitation($aLimitations, 'ad_active', 'd.status', OA_ENTITY_STATUS_RUNNING, $aParams['ad_active'] == 't' ? MAX_LIMITATION_EQUAL : MAX_LIMITATION_NOT_EQUAL);
     }
     if (!empty($aParams['placement_active'])) {
         SqlBuilder::_addLimitation($aLimitations, 'placement_active', 'm.status', OA_ENTITY_STATUS_RUNNING, $aParams['placement_active'] == 't' ? MAX_LIMITATION_EQUAL : MAX_LIMITATION_NOT_EQUAL);
     }
     if (!empty($aParams['placement_anonymous'])) {
         SqlBuilder::_addLimitation($aLimitations, 'placement_anonymous', 'm.anonymous', $aParams['placement_anonymous']);
     }
     if (!empty($aParams['zone_inventory_forecast_type'])) {
         SqlBuilder::_addLimitation($aLimitations, 'zone_inventory_forecast_type', 'z.inventory_forecast_type', $aParams['zone_inventory_forecast_type'], MAX_LIMITATION_BITWISE);
     }
     switch ($entity) {
         case 'ad':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             // never return the Market ad entity (in stats, UI)
             if (empty($aParams['market_ads_include'])) {
                 $aLimitations[] = "(d.ext_bannertype <> 'market-optin-banner' OR d.ext_bannertype IS NULL)";
             }
             break;
         case 'advertiser':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'a.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             // always filter by type
             if (!class_exists(DataObjects_Clients)) {
                 OA_Dal::factoryDO('Clients');
             }
             if (empty($aParams['advertiser_type'])) {
                 $aParams['advertiser_type'] = DataObjects_Clients::ADVERTISER_TYPE_DEFAULT;
                 //always add default type
             } else {
                 $aParams['advertiser_type'] .= "," . DataObjects_Clients::ADVERTISER_TYPE_DEFAULT;
                 //always add default type
             }
             SqlBuilder::_addLimitation($aLimitations, 'advertiser_type', 'a.type', $aParams['advertiser_type']);
             // filter by campaign types only if param given
             if (isset($aParams['campaign_type'])) {
                 if (!class_exists(DataObjects_Campaigns)) {
                     OA_Dal::factoryDO('Campaigns');
                 }
                 if (empty($aParams['campaign_type'])) {
                     $aParams['campaign_type'] = DataObjects_Campaigns::CAMPAIGN_TYPE_DEFAULT;
                     //always add default type
                 } else {
                     $aParams['campaign_type'] .= "," . DataObjects_Campaigns::CAMPAIGN_TYPE_DEFAULT;
                     //always add default type
                 }
                 SqlBuilder::_addLimitation($aLimitations, 'campaign_type', 'm.type', $aParams['campaign_type']);
             }
             break;
         case 'ad_category_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'ac.ad_id', $aParams['ad_id']);
             }
             if (!empty($aParams['ad_category_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_category_assoc_id', 'ac.ad_category_assoc_id', $aParams['ad_category_assoc_id']);
             }
             break;
         case 'ad_zone_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'az.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'az.ad_id', $aParams['ad_id']);
             }
             if (!empty($aParams['ad_zone_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_zone_assoc_id', 'az.ad_zone_assoc_id', $aParams['ad_zone_assoc_id']);
             }
             break;
         case 'agency':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'g.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'a.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'p.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             break;
         case 'campaign':
             if (!empty($aParams['client_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'client_id', 'cam.clientid', $aParams['client_id']);
             }
             break;
         case 'category':
             if (!empty($aParams['name'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'name', 'cat.name', $aParams['name']);
             }
             break;
         case 'channel':
             if (isset($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', $aParams['publisher_id']);
             } elseif (isset($aParams['channel_type']) && $aParams['channel_type'] == 'publisher') {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', 0, MAX_LIMITATION_NOT_EQUAL);
             }
             if (!empty($aParams['channel_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'channel_id', 'ch.channelid', $aParams['channel_id']);
             }
             if (isset($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', 0);
             }
             break;
         case 'channel_limitation':
             if (!empty($aParams['channel_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'channel_id', 'chl.channelid', $aParams['channel_id']);
             }
             break;
         case 'image':
             if (!empty($aParams['file_name'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'file_name', 'i.filename', $aParams['file_name']);
             }
             break;
         case 'limitation':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'l.bannerid', $aParams['ad_id']);
             }
             break;
         case 'placement':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             // always filter by type
             if (!class_exists(DataObjects_Campaigns)) {
                 OA_Dal::factoryDO('Campaigns');
             }
             if (empty($aParams['campaign_type'])) {
                 $aParams['campaign_type'] = DataObjects_Campaigns::CAMPAIGN_TYPE_DEFAULT;
                 //always add default type
             } else {
                 $aParams['campaign_type'] .= "," . DataObjects_Campaigns::CAMPAIGN_TYPE_DEFAULT;
                 //always add default type
             }
             SqlBuilder::_addLimitation($aLimitations, 'campaign_type', 'm.type', $aParams['campaign_type']);
             break;
         case 'placement_tracker':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 'mt.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'mt.campaignid', $aParams['placement_id']);
             }
             break;
         case 'placement_zone_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'pz.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'pz.placement_id', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             if (!empty($aParams['placement_zone_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_zone_assoc_id', 'pz.placement_zone_assoc_id', $aParams['placement_zone_assoc_id']);
             }
             break;
         case 'publisher':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'p.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             break;
         case 'history_span':
         case 'history_day_hour':
         case 'history_day':
         case 'history_month':
         case 'history_dow':
         case 'history_hour':
         case 'stats':
             if (!empty($aParams['agency_id'])) {
                 // join to affiliates if stats by zone
                 if (!empty($aParams['publisher_id']) || !empty($aParams['zone_id']) || isset($aParams['zone_type']) || isset($aParams['zone_width']) || isset($aParams['zone_height'])) {
                     SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
                 }
                 $adIds = SqlBuilder::_getBannerIdsForAgency($aParams['agency_id']);
                 if (!empty($adIds)) {
                     SqlBuilder::_addLimitation($aLimitations, 'ad_id', 's.ad_id', $adIds);
                 } else {
                     SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
                 }
             }
             if (!empty($aParams['publisher_id'])) {
                 if (!empty($aParams['market_stats'])) {
                     SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 's.website_id', $aParams['publisher_id']);
                 } else {
                     SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
                 }
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (isset($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 's.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 's.ad_id', $aParams['ad_id']);
             }
             if (empty($aParams['market_stats_get_start_date'])) {
                 $do = OA_Dal::factoryDO('Clients');
                 // Core stats exclude all Market advertiser activity
                 // Market stats only include the Market advertiser activity
                 if (!empty($aParams['market_stats'])) {
                     $aLimitations[] = 'a.type = ' . DataObjects_Clients::ADVERTISER_TYPE_MARKET;
                     // if we are not explicitely selecting zone_id = 0 stats, we exclude all zone_id stats
                     if (empty($aParams['market_stats_including_zone_zero'])) {
                         $aLimitations[] = 's.zone_id <> 0';
                     }
                 } else {
                     $aLimitations[] = 'a.type = ' . DataObjects_Clients::ADVERTISER_TYPE_DEFAULT;
                 }
                 if (!empty($aParams['custom_table']) && $aParams['custom_table'] == 'data_intermediate_ad_connection') {
                     $dateTimeCol = "s.tracker_date_time";
                 } else {
                     $dateTimeCol = "s.date_time";
                 }
                 if (!empty($aParams['day_begin'])) {
                     $aLimitations[] = "{$dateTimeCol}>='" . SqlBuilder::_dayToDateTime($aParams['day_begin'], true) . "'";
                 }
                 if (!empty($aParams['day_end'])) {
                     $aLimitations[] = "{$dateTimeCol}<='" . SqlBuilder::_dayToDateTime($aParams['day_end'], false) . "'";
                 }
             }
             break;
         case 'stats_by_entity':
             $aLimitations += SqlBuilder::_getLimitations('stats', $aParams);
             if (isset($aParams['zone_id']) && $aParams['zone_id'] == 0) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 's.zone_id', 0);
             }
             break;
         case 'tracker':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 't.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'mt.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             break;
         case 'variable':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 'v.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['variable_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'variable_id', 'v.variableid', $aParams['variable_id']);
             }
             break;
         case 'zone':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (isset($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             if (isset($aParams['zone_type'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_type', 'z.delivery', $aParams['zone_type']);
             }
             if (isset($aParams['zone_width'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_width', 'z.width', $aParams['zone_width']);
             }
             if (isset($aParams['zone_height'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_height', 'z.height', $aParams['zone_height']);
             }
             break;
     }
     return $aLimitations;
 }
 function _duplicatePlacement($aPlacement, $checkUniqueNames = false)
 {
     $placementId = $aPlacement['placement_id'];
     unset($aPlacement['placement_id']);
     if ($checkUniqueNames) {
         $aPlacements = Admin_DA::getPlacements(array('advertiser_id' => $aPlacement['advertiser_id']));
         Admin_DA::_getUniqueName($aPlacement, $aPlacements, @$GLOBALS['strCopy']);
     }
     // FIXME: get rid of this
     $aPlacement = MAX_commonSlashArray($aPlacement);
     // Massage to real field names
     Admin_DA::_switch($aPlacement, 'advertiser_id', 'clientid');
     Admin_DA::_switch($aPlacement, 'name', 'campaignname');
     $newPlacementId = Admin_DA::addPlacement($aPlacement);
     $aPlacementTrackers = Admin_DA::getPlacementTrackers(array('placement_id' => $placementId));
     foreach ($aPlacementTrackers as $aPlacementTracker) {
         $aPlacementTracker['placement_id'] = $newPlacementId;
         Admin_DA::duplicatePlacementTracker($aPlacementTracker);
     }
     $aPlacementZones = Admin_DA::_getEntities('placement_zone_assoc', array('placement_id' => $placementId));
     foreach ($aPlacementZones as $aPlacementZone) {
         $aPlacementZone['placement_id'] = $newPlacementId;
         Admin_DA::duplicatePlacementZone($aPlacementZone);
     }
     $aAds = Admin_DA::getAds(array('placement_id' => $placementId));
     foreach ($aAds as $aAd) {
         $aAd['placement_id'] = $newPlacementId;
         Admin_DA::duplicateAd($aAd, $aAds);
     }
     return $newPlacementId;
 }
示例#6
0
 /**
  * Returns an array of constraints given an entity with params.
  *
  * @param string $entity
  * @param array $aParams
  * @return array
  */
 function _getLimitations($entity, $aParams)
 {
     if (!empty($aParams) && is_array($aParams)) {
         $aParams = MAX_commonSlashArray($aParams);
     }
     $aLimitations = array();
     // size limitation e.g. ((width = -1 AND height = -1) OR (width = 468 AND height = 60));
     $aSizeLimitations = array();
     $aZoneSize = array();
     if (isset($aParams['ad_width'])) {
         SqlBuilder::_addLimitation($aZoneSize, 'ad_width', 'd.width', $aParams['ad_width']);
     }
     if (isset($aParams['ad_height'])) {
         SqlBuilder::_addLimitation($aZoneSize, 'ad_height', 'd.height', $aParams['ad_height']);
     }
     $zoneSize = implode(' AND ', $aZoneSize);
     if (!empty($zoneSize)) {
         if (!empty($aParams['ad_nosize'])) {
             $aNoSize = array();
             SqlBuilder::_addLimitation($aNoSize, 'ad_width', 'd.width', -1);
             SqlBuilder::_addLimitation($aNoSize, 'ad_height', 'd.height', -1);
             $aSizeLimitations[] = '(' . implode(' AND ', $aNoSize) . ')';
         }
         $aSizeLimitations[] = '(' . $zoneSize . ')';
         $sizeLimitation = implode(' OR ', $aSizeLimitations);
         if (!empty($sizeLimitation)) {
             $aLimitations[] = '(' . $sizeLimitation . ')';
         }
     }
     if (!empty($aParams['ad_type'])) {
         if ($aParams['ad_type'] == "!txt") {
             SqlBuilder::_addLimitation($aLimitations, 'ad_type', 'd.storagetype', 'txt', MAX_LIMITATION_NOT_EQUAL);
         } else {
             SqlBuilder::_addLimitation($aLimitations, 'ad_type', 'd.storagetype', $aParams['ad_type']);
         }
     }
     if (!empty($aParams['ad_active'])) {
         SqlBuilder::_addLimitation($aLimitations, 'ad_active', 'd.status', OA_ENTITY_STATUS_RUNNING, $aParams['ad_active'] == 't' ? MAX_LIMITATION_EQUAL : MAX_LIMITATION_NOT_EQUAL);
     }
     if (!empty($aParams['placement_active'])) {
         SqlBuilder::_addLimitation($aLimitations, 'placement_active', 'm.status', OA_ENTITY_STATUS_RUNNING, $aParams['placement_active'] == 't' ? MAX_LIMITATION_EQUAL : MAX_LIMITATION_NOT_EQUAL);
     }
     if (!empty($aParams['placement_anonymous'])) {
         SqlBuilder::_addLimitation($aLimitations, 'placement_anonymous', 'm.anonymous', $aParams['placement_anonymous']);
     }
     if (!empty($aParams['zone_inventory_forecast_type'])) {
         SqlBuilder::_addLimitation($aLimitations, 'zone_inventory_forecast_type', 'z.inventory_forecast_type', $aParams['zone_inventory_forecast_type'], MAX_LIMITATION_BITWISE);
     }
     switch ($entity) {
         case 'ad':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             break;
         case 'advertiser':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'a.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             break;
         case 'ad_category_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'ac.ad_id', $aParams['ad_id']);
             }
             if (!empty($aParams['ad_category_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_category_assoc_id', 'ac.ad_category_assoc_id', $aParams['ad_category_assoc_id']);
             }
             break;
         case 'ad_zone_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'az.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'az.ad_id', $aParams['ad_id']);
             }
             if (!empty($aParams['ad_zone_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_zone_assoc_id', 'az.ad_zone_assoc_id', $aParams['ad_zone_assoc_id']);
             }
             break;
         case 'agency':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'g.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'a.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'p.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             break;
         case 'campaign':
             if (!empty($aParams['client_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'client_id', 'cam.clientid', $aParams['client_id']);
             }
             break;
         case 'category':
             if (!empty($aParams['name'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'name', 'cat.name', $aParams['name']);
             }
             break;
         case 'channel':
             if (isset($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', $aParams['publisher_id']);
             } elseif (isset($aParams['channel_type']) && $aParams['channel_type'] == 'publisher') {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', 0, MAX_LIMITATION_NOT_EQUAL);
             }
             if (!empty($aParams['channel_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'channel_id', 'ch.channelid', $aParams['channel_id']);
             }
             if (isset($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'ch.affiliateid', 0);
             }
             break;
         case 'channel_limitation':
             if (!empty($aParams['channel_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'channel_id', 'chl.channelid', $aParams['channel_id']);
             }
             break;
         case 'image':
             if (!empty($aParams['file_name'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'file_name', 'i.filename', $aParams['file_name']);
             }
             break;
         case 'limitation':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'l.bannerid', $aParams['ad_id']);
             }
             break;
         case 'placement':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'm.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             break;
         case 'placement_tracker':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 'mt.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'mt.campaignid', $aParams['placement_id']);
             }
             break;
         case 'placement_zone_assoc':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'c.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'pz.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'pz.placement_id', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             if (!empty($aParams['placement_zone_assoc_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_zone_assoc_id', 'pz.placement_zone_assoc_id', $aParams['placement_zone_assoc_id']);
             }
             break;
         case 'publisher':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'p.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             break;
         case 'history_span':
         case 'history_day_hour':
         case 'history_day':
         case 'history_month':
         case 'history_dow':
         case 'history_hour':
         case 'stats':
             if (!empty($aParams['agency_id'])) {
                 $aLimitations[] = "(a.agencyid = {$aParams['agency_id']} OR p.agencyid = {$aParams['agency_id']})";
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
             }
             if (isset($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 's.zone_id', $aParams['zone_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
             }
             if (isset($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 's.ad_id', $aParams['ad_id']);
             }
             if (!empty($aParams['custom_table']) && $aParams['custom_table'] == 'data_intermediate_ad_connection') {
                 $dateTimeCol = "s.tracker_date_time";
             } else {
                 $dateTimeCol = "s.date_time";
             }
             if (!empty($aParams['day_begin'])) {
                 $aLimitations[] = "{$dateTimeCol}>='" . SqlBuilder::_dayToDateTime($aParams['day_begin'], true) . "'";
             }
             if (!empty($aParams['day_end'])) {
                 $aLimitations[] = "{$dateTimeCol}<='" . SqlBuilder::_dayToDateTime($aParams['day_end'], false) . "'";
             }
             break;
         case 'stats_by_entity':
             $aLimitations += SqlBuilder::_getLimitations('stats', $aParams);
             if (isset($aParams['zone_id']) && $aParams['zone_id'] == 0) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 's.zone_id', 0);
             }
             break;
         case 'tracker':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 't.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['placement_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'mt.campaignid', $aParams['placement_id']);
             }
             if (!empty($aParams['ad_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'ad_id', 'd.bannerid', $aParams['ad_id']);
             }
             break;
         case 'variable':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'a.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['advertiser_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 't.clientid', $aParams['advertiser_id']);
             }
             if (!empty($aParams['tracker_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'tracker_id', 'v.trackerid', $aParams['tracker_id']);
             }
             if (!empty($aParams['variable_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'variable_id', 'v.variableid', $aParams['variable_id']);
             }
             break;
         case 'zone':
             if (!empty($aParams['agency_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'agency_id', 'p.agencyid', $aParams['agency_id']);
             }
             if (!empty($aParams['publisher_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
             }
             if (isset($aParams['zone_id'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_id', 'z.zoneid', $aParams['zone_id']);
             }
             if (isset($aParams['zone_type'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_type', 'z.delivery', $aParams['zone_type']);
             }
             if (isset($aParams['zone_width'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_width', 'z.width', $aParams['zone_width']);
             }
             if (isset($aParams['zone_height'])) {
                 SqlBuilder::_addLimitation($aLimitations, 'zone_height', 'z.height', $aParams['zone_height']);
             }
             break;
     }
     return $aLimitations;
 }