/**
  * A method to insert the default data into the database.
  *
  * The default data are:
  *
  *  - Test Advertiser 1
  *    - Placement 11
  *      - High Priority
  *      - Daily target of 120 impressions (5 per
  *        hour assuming even delivery each hour)
  *        - Advertisement 111
  *          - Banner Weight 1
  *    - Placement 12
  *      - High Priority
  *      - Runs from 2005-01-01 to 2005-12-31
  *      - Total target of 87,600 (10 per hour
  *        assuming even delivery each hour)
  *        - Advertisement 121
  *          - Banner Weight 2
  *        - Advertisement 122
  *          - Banner Weight 1
  *
  *  - Test Advertiser 2
  *    - Placement 21
  *    - Placement 22
  *
  *  - Test Publisher 1
  *    - Zone 11
  *    - Zone 12
  *
  *  - Test Publisher 2
  *    - Zone 21
  *    - Zone 22
  *
  * - Advertisement 111 is linked to Zone 11
  * - Advertisement 121 is linked to Zone 21
  * - Advertisement 122 is linked to Zone 21 AND Zone 22
  *
  * @static
  * @access public
  * @TODO Complete the specification of the default data and the implementation
  *       of the creation thereof.
  */
 function insertDefaultData()
 {
     $oDbh =& OA_DB::singleton();
     // Set now
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oldNow = $oServiceLocator->get('now');
     $oServiceLocator->register('now', new Date('2005-03-01'));
     // Add a default agency
     $agencyID = Admin_DA::addAgency(array('name' => 'Test Agency', 'contact' => 'Contact Name', 'username' => 'agency', 'email' => '*****@*****.**', 'active' => 1));
     // Add two advertisers for the agency
     $advertiserOneID = Admin_DA::addAdvertiser(array('agencyid' => $agencyID, 'clientname' => 'Test Advertiser 1', 'contact' => 'Contact Name 1', 'clientusername' => 'advertiser1', 'email' => '*****@*****.**'));
     $advertiserTwoID = Admin_DA::addAdvertiser(array('agencyid' => $agencyID, 'clientname' => 'Test Advertiser 2', 'contact' => 'Contact Name 2', 'clientusername' => 'advertiser2', 'email' => '*****@*****.**'));
     // Add the advertiser's placements (campaigns) & advertisements
     $campaignOneOneID = Admin_DA::addPlacement(array('campaignname' => 'Campaign 11 - Manual Daily Target of 120', 'clientid' => $advertiserOneID, 'views' => -1, 'clicks' => -1, 'conversions' => -1, 'status' => OA_ENTITY_STATUS_RUNNING, 'priority' => 2, 'target_impression' => 120, 'target_click' => -1, 'target_conversion' => -1));
     $adOneOneOneID = Admin_DA::addAd(array('campaignid' => $campaignOneOneID, 'description' => 'Advertisement 111', 'active' => 't', 'weight' => 1, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
     $campaignOneTwoID = Admin_DA::addPlacement(array('campaignname' => 'Campaign 22 - Auto Distribution of 87,600 Impressions', 'clientid' => $advertiserOneID, 'views' => 87600, 'clicks' => -1, 'conversions' => -1, 'status' => OA_ENTITY_STATUS_RUNNING, 'priority' => 2, 'target_impression' => -1, 'target_click' => -1, 'target_conversion' => -1, 'activate_time' => '2005-01-01 00:00:00', 'expire_time' => '2005-12-31 23:59:59'));
     $adOneTwoOneID = Admin_DA::addAd(array('campaignid' => $campaignOneTwoID, 'description' => 'Advertisement 121', 'active' => 't', 'weight' => 2, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
     $adOneTwoTwoID = Admin_DA::addAd(array('campaignid' => $campaignOneTwoID, 'description' => 'Advertisement 122', 'active' => 't', 'weight' => 1, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
     // Add two publishers for the agency
     $publisherOneID = Admin_DA::addPublisher(array('agencyid' => $agencyID, 'name' => 'Test Publisher 1', 'contact' => 'Contact Name 1', 'username' => 'publisher1', 'email' => '*****@*****.**'));
     $publisherTwoID = Admin_DA::addPublisher(array('agencyid' => $agencyID, 'name' => 'Test Publisher 1', 'contact' => 'Contact Name 1', 'username' => 'publisher1', 'email' => '*****@*****.**'));
     // Add the publisher's zones
     $zoneOneOneID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 11', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
     $zoneOneTwoID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 12', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
     $zoneTwoOneID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 21', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
     $zoneTwoTwoID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 22', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
     // Link the ads to the zones
     Admin_DA::addAdZone(array('ad_id' => $adOneOneOneID, 'zone_id' => $zoneOneOneID, 'link_type' => 1));
     Admin_DA::addAdZone(array('ad_id' => $adOneTwoOneID, 'zone_id' => $zoneTwoOneID, 'link_type' => 1));
     Admin_DA::addAdZone(array('ad_id' => $adOneTwoTwoID, 'zone_id' => $zoneTwoOneID, 'link_type' => 1));
     Admin_DA::addAdZone(array('ad_id' => $adOneTwoTwoID, 'zone_id' => $zoneTwoTwoID, 'link_type' => 1));
     // Restore "now"
     if ($oldNow) {
         $oServiceLocator->register('now', $oldNow);
     } else {
         $oServiceLocator->remove('now');
     }
 }
 function testGetAd()
 {
     $id = Admin_DA::addAd(array('campaignid' => rand(1, 999), 'active' => 't', 'contenttype' => 'gif', 'pluginversion' => rand(1, 999), 'htmltemplate' => '<html></html>', 'htmlcache' => '<html><body></body></html>', 'url' => 'http://www.openx.org', 'bannertext' => 'text', 'compiledlimitation' => '', 'append' => '', 'acls_updated' => '2007-04-11', 'status' => 1));
     $ret = Admin_DA::getAd($id);
     // should look like this
     /*
     Array
     (
         [ad_id] => 1
         [placement_id] => 234234
         [active] => t
         [name] => desc
         [type] => sql
         [contenttype] => gif
         [pluginversion] => 1
         [filename] => sdfasdf
         [imageurl] => http://img.com
         [htmltemplate] => foo
         [htmlcache] => bar
         [width] => 5
         [height] => 6
         [weight] => 3
         [seq] => 1
         [target] =>
         [url] => http://localhost/phpMyAdmin/
         [alt] =>
         [status] =>
         [bannertext] => asdasdfad
         [adserver] =>
         [block] => 0
         [capping] => 0
         [session_capping] => 0
         [compiledlimitation] => asdfasdf
         [append] => asdfasdf
         [bannertype] => 2
         [alt_filename] =>
         [alt_imageurl] =>
         [alt_contenttype] => gif
         [prepend] =>
     )
     */
     $this->assertTrue(is_array($ret));
     $this->assertTrue(count($ret));
     $this->assertTrue(array_key_exists('ad_id', $ret));
     $this->assertTrue(array_key_exists('placement_id', $ret));
     $this->assertTrue(array_key_exists('status', $ret));
     $this->assertEqual(1, $ret['status']);
     $this->assertTrue(array_key_exists('name', $ret));
     $this->assertTrue(array_key_exists('type', $ret));
     $this->assertTrue(array_key_exists('contenttype', $ret));
     $this->assertTrue(array_key_exists('pluginversion', $ret));
     $this->assertTrue(array_key_exists('filename', $ret));
     $this->assertTrue(array_key_exists('imageurl', $ret));
     $this->assertTrue(array_key_exists('htmltemplate', $ret));
     $this->assertTrue(array_key_exists('htmlcache', $ret));
     $this->assertTrue(array_key_exists('width', $ret));
     $this->assertTrue(array_key_exists('height', $ret));
     $this->assertTrue(array_key_exists('weight', $ret));
     $this->assertTrue(array_key_exists('seq', $ret));
     $this->assertTrue(array_key_exists('target', $ret));
     $this->assertTrue(array_key_exists('url', $ret));
     $this->assertTrue(array_key_exists('alt', $ret));
     $this->assertTrue(array_key_exists('status', $ret));
     $this->assertTrue(array_key_exists('bannertext', $ret));
     $this->assertTrue(array_key_exists('adserver', $ret));
     $this->assertTrue(array_key_exists('block', $ret));
     $this->assertTrue(array_key_exists('capping', $ret));
     $this->assertTrue(array_key_exists('session_capping', $ret));
     $this->assertTrue(array_key_exists('compiledlimitation', $ret));
     $this->assertTrue(array_key_exists('prepend', $ret));
     $this->assertTrue(array_key_exists('append', $ret));
     $this->assertTrue(array_key_exists('bannertype', $ret));
     $this->assertTrue(array_key_exists('alt_filename', $ret));
     $this->assertTrue(array_key_exists('alt_imageurl', $ret));
     $this->assertTrue(array_key_exists('alt_contenttype', $ret));
 }
 function _duplicateAd($aAd, $checkUniqueNames = false)
 {
     require_once MAX_PATH . '/www/admin/lib-storage.inc.php';
     // Copy the linked creative
     $newFile = phpAds_ImageDuplicate($aAd['type'], $aAd['filename']);
     if ($newFile !== false) {
         $aAd['filename'] = $newFile;
     }
     // Remove the existing advert id
     $adId = $aAd['ad_id'];
     unset($aAd['ad_id']);
     // Check for unique names
     if ($checkUniqueNames) {
         $aAds = Admin_DA::getAds(array('placement_id' => $aAd['placement_id']));
         Admin_DA::_getUniqueName($aAd, $aAds, $GLOBALS['strCopy']);
     }
     // Add the new ad
     $newAdId = Admin_DA::addAd($aAd);
     // Copy the limitations
     $aLimitations = Admin_DA::getDeliveryLimitations(array('ad_id' => $adId));
     foreach ($aLimitations as $aLimitation) {
         $aLimitation['ad_id'] = $newAdId;
         Admin_DA::addLimitation($aLimitation);
     }
     // Copy the zone ad associations
     $aAdZones = Admin_DA::getAdZones(array('ad_id' => $adId));
     foreach ($aAdZones as $aAdZone) {
         $aAdZone['ad_id'] = $newAdId;
         Admin_DA::duplicateAdZone($aAdZone);
     }
     return $newAdId;
 }