$affiliate['password'] = md5($pw);
         }
     }
 }
 if (count($errormessage) == 0) {
     if ($affiliateid && $publiczones != 't' && $publiczones_old == 't') {
         // Reset append codes which called this affiliate's zones
         $res = phpAds_dbQuery("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tzoneid\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\taffiliateid = '{$affiliateid}'\n\t\t\t\t");
         $zones = array();
         while ($currentrow = phpAds_dbFetchArray($res)) {
             $zones[] = $currentrow['zoneid'];
         }
         if (count($zones)) {
             $res = phpAds_dbQuery("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tzoneid,\n\t\t\t\t\t\t\tappend\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tappendtype = " . phpAds_ZoneAppendZone . " AND\n\t\t\t\t\t\t\taffiliateid <> '{$affiliateid}'\n\t\t\t\t\t");
             while ($currentrow = phpAds_dbFetchArray($res)) {
                 $append = phpAds_ZoneParseAppendCode($currentrow['append']);
                 if (in_array($append[0]['zoneid'], $zones)) {
                     phpAds_dbQuery("\n\t\t\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\tappendtype = " . phpAds_ZoneAppendRaw . ",\n\t\t\t\t\t\t\t\t\tappend = ''\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tzoneid = '" . $currentrow['zoneid'] . "'\n\t\t\t\t\t\t\t");
                 }
             }
         }
     }
     if (!isset($affiliateid) || $affiliateid == '') {
         $keys = array();
         $values = array();
         while (list($key, $value) = each($affiliate)) {
             $keys[] = $key;
             $values[] = $value;
         }
         $query = "INSERT INTO " . $phpAds_config['tbl_affiliates'] . " (";
         $query .= implode(", ", $keys);
function phpAds_upgradeAppendZones()
{
    global $phpAds_config;
    // Check if md5 adding is needed
    if (!isset($phpAds_config['config_version']) || $phpAds_config['config_version'] < 200.112) {
        $res = phpAds_dbQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tzoneid,\n\t\t\t\t\tappend\n\t\t\t\tFROM\n\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\tWHERE\n\t\t\t\t\tappendtype = " . phpAds_ZoneAppendRaw . "\n\t\t\t");
        while ($row = phpAds_dbFetchArray($res)) {
            $append = phpAds_ZoneParseAppendCode($row['append']);
            if ($append[0]['zoneid']) {
                phpAds_dbQuery("\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tappendtype = " . phpAds_ZoneAppendZone . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tzoneid = '" . $row['zoneid'] . "'\n\t\t\t\t\t");
            }
        }
    }
}
Example #3
0
/**
 * Processes submit values of zone form
 *
 * @param OA_Admin_UI_Component_Form $form form to process
 * @return An array of Pear::Error objects if any
 */
function processForm($form)
{
    $aFields = $form->exportValues();
    switch ($aFields['delivery']) {
        case phpAds_ZoneText:
            $aFields['width'] = $aFields['height'] = 0;
            break;
        case OX_ZoneVideoOverlay:
            $aFields['width'] = $aFields['height'] = -2;
            break;
        case OX_ZoneVideoInstream:
            $aFields['width'] = $aFields['height'] = -3;
            break;
        default:
            if ($aFields['sizetype'] == 'custom') {
                if (isset($aFields['width']) && $aFields['width'] == '*') {
                    $aFields['width'] = -1;
                }
                if (isset($aFields['height']) && $aFields['height'] == '*') {
                    $aFields['height'] = -1;
                }
            } else {
                list($aFields['width'], $aFields['height']) = explode('x', $aFields['size']);
            }
            break;
    }
    if (!is_numeric($aFields['oac_category_id']) || $aFields['oac_category_id'] <= 0) {
        $aFields['oac_category_id'] = 'NULL';
    }
    if (empty($errors)) {
        // Edit
        if (!empty($aFields['zoneid'])) {
            // before we commit any changes to db, store whether the size has changed
            $aZone = Admin_DA::getZone($aFields['zoneid']);
            $size_changed = $aFields['width'] != $aZone['width'] || $aFields['height'] != $aZone['height'] ? true : false;
            $type_changed = $aFields['delivery'] != $aZone['delivery'] ? true : false;
            $doZones = OA_Dal::factoryDO('zones');
            $doZones->zonename = $aFields['zonename'];
            $doZones->description = $aFields['description'];
            $doZones->width = $aFields['width'];
            $doZones->height = $aFields['height'];
            $doZones->comments = $aFields['comments'];
            $doZones->delivery = $aFields['delivery'];
            if ($aFields['delivery'] != phpAds_ZoneText && $aFields['delivery'] != phpAds_ZoneBanner) {
                $doZones->append = '';
            }
            if ($aFields['delivery'] != phpAds_ZoneText) {
                $doZones->prepend = '';
            }
            $doZones->oac_category_id = $aFields['oac_category_id'];
            $doZones->zoneid = $aFields['zoneid'];
            $doZones->update();
            // Ad  Networks
            $doPublisher = OA_Dal::factoryDO('affiliates');
            $doPublisher->get($aFields['affiliateid']);
            $anWebsiteId = $doPublisher->as_website_id;
            if ($anWebsiteId) {
                $oAdNetworks = new OA_Central_AdNetworks();
                $doZones->get($aFields['zoneid']);
                $oAdNetworks->updateZone($doZones, $anWebsiteId);
            }
            // Reset append codes which called this zone
            $doZones = OA_Dal::factoryDO('zones');
            $doZones->appendtype = phpAds_ZoneAppendZone;
            if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                $doZones->addReferenceFilter('agency', OA_Permission::getEntityId());
            } elseif (OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER)) {
                $doZones->addReferenceFilter('affiliates', OA_Permission::getEntityId());
            }
            $doZones->find();
            while ($doZones->fetch() && ($row = $doZones->toArray())) {
                $append = phpAds_ZoneParseAppendCode($row['append']);
                if ($append[0]['zoneid'] == $aFields['zoneid']) {
                    $doZonesClone = clone $doZones;
                    $doZonesClone->appendtype = phpAds_ZoneAppendRaw;
                    $doZonesClone->append = '';
                    $doZonesClone->update();
                }
            }
            if ($type_changed && $aFields['delivery'] == MAX_ZoneEmail) {
                // Unlink all campaigns/banners linked to this zone
                $aPlacementZones = Admin_DA::getPlacementZones(array('zone_id' => $aFields['zoneid']), true, 'placement_id');
                if (!empty($aPlacementZones)) {
                    foreach ($aPlacementZones as $placementId => $aPlacementZone) {
                        Admin_DA::deletePlacementZones(array('zone_id' => $aFields['zoneid'], 'placement_id' => $placementId));
                    }
                }
                $aAdZones = Admin_DA::getAdZones(array('zone_id' => $aFields['zoneid']), false, 'ad_id');
                if (!empty($aAdZones)) {
                    foreach ($aAdZones as $adId => $aAdZone) {
                        Admin_DA::deleteAdZones(array('zone_id' => $aFields['zoneid'], 'ad_id' => $adId));
                    }
                }
            } else {
                if ($size_changed) {
                    $aZone = Admin_DA::getZone($aFields['zoneid']);
                    // Loop through all appended banners and make sure that they still fit...
                    $aAds = Admin_DA::getAdZones(array('zone_id' => $aFields['zoneid']), false, 'ad_id');
                    if (!empty($aAds)) {
                        foreach ($aAds as $adId => $aAd) {
                            $aAd = Admin_DA::getAd($adId);
                            if ($aZone['type'] == phpAds_ZoneText && $aAd['type'] != 'txt' || $aAd['width'] != $aZone['width'] && $aZone['width'] > -1 || $aAd['height'] != $aZone['height'] && $aZone['height'] > -1) {
                                Admin_DA::deleteAdZones(array('zone_id' => $aFields['zoneid'], 'ad_id' => $adId));
                            }
                        }
                    }
                    // Check if any campaigns linked to this zone have ads that now fit.
                    // If so, link them to the zone.
                    $aPlacementZones = Admin_DA::getPlacementZones(array('zone_id' => $aFields['zoneid']), true);
                    if (!empty($aPlacementZones)) {
                        foreach ($aPlacementZones as $aPlacementZone) {
                            // get ads in this campaign
                            $aAds = Admin_DA::getAds(array('placement_id' => $aPlacementZone['placement_id']), true);
                            foreach ($aAds as $adId => $aAd) {
                                Admin_DA::addAdZone(array('zone_id' => $aFields['zoneid'], 'ad_id' => $adId));
                            }
                        }
                    }
                }
            }
            // Queue confirmation message
            $translation = new OX_Translation();
            $translated_message = $translation->translate($GLOBALS['strZoneHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, "zone-edit.php?affiliateid=" . $aFields['affiliateid'] . "&zoneid=" . $aFields['zoneid']), htmlspecialchars($aFields['zonename'])));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            OX_Admin_Redirect::redirect("zone-edit.php?affiliateid=" . $aFields['affiliateid'] . "&zoneid=" . $aFields['zoneid']);
        } else {
            $doZones = OA_Dal::factoryDO('zones');
            $doZones->affiliateid = $aFields['affiliateid'];
            $doZones->zonename = $aFields['zonename'];
            $doZones->zonetype = phpAds_ZoneCampaign;
            $doZones->description = $aFields['description'];
            $doZones->comments = $aFields['comments'];
            $doZones->width = $aFields['width'];
            $doZones->height = $aFields['height'];
            $doZones->delivery = $aFields['delivery'];
            $doZones->oac_category_id = $aFields['oac_category_id'];
            // The following fields are NOT NULL but do not get values set in the form.
            // Should these fields be changed to NULL in the schema or should they have a default value?
            $doZones->category = '';
            $doZones->ad_selection = '';
            $doZones->chain = '';
            $doZones->prepend = '';
            $doZones->append = '';
            $aFields['zoneid'] = $doZones->insert();
            // Ad  Networks
            $doPublisher = OA_Dal::factoryDO('affiliates');
            $doPublisher->get($aFields['affiliateid']);
            $anWebsiteId = $doPublisher->as_website_id;
            if ($anWebsiteId) {
                $oAdNetworks = new OA_Central_AdNetworks();
                $oAdNetworks->updateZone($doZones, $anWebsiteId);
            }
            // Queue confirmation message
            $translation = new OX_Translation();
            $translated_message = $translation->translate($GLOBALS['strZoneHasBeenAdded'], array(MAX::constructURL(MAX_URL_ADMIN, 'zone-edit.php?affiliateid=' . $aFields['affiliateid'] . '&zoneid=' . $aFields['zoneid']), htmlspecialchars($aFields['zonename'])));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            OX_Admin_Redirect::redirect("affiliate-zones.php?affiliateid=" . $aFields['affiliateid']);
        }
    }
    return $errors;
}
        } else {
            list($zwidth, $zheight) = explode('x', $size);
        }
    }
    // Edit
    if (isset($zoneid) && $zoneid != '') {
        $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\tSET\n\t\t\t\tzonename='" . $zonename . "',\n\t\t\t\tdescription='" . $description . "',\n\t\t\t\twidth='" . $zwidth . "',\n\t\t\t\theight='" . $zheight . "',\n\t\t\t\tdelivery='" . $delivery . "'\n\t\t\t\t" . ($delivery != phpAds_ZoneText && $delivery != phpAds_ZoneBanner ? ", append = ''" : "") . "\n\t\t\t\t" . ($delivery != phpAds_ZoneText ? ", prepend = ''" : "") . "\n\t\t\tWHERE\n\t\t\t\tzoneid='" . $zoneid . "'\n\t\t\t") or phpAds_sqlDie();
        // Rebuild Cache
        if (!defined('LIBVIEWCACHE_INCLUDED')) {
            include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php';
        }
        phpAds_cacheDelete('what=zone:' . $zoneid);
        // Reset append codes which called this zone
        $res = phpAds_dbQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tzoneid,\n\t\t\t\t\tappend\n\t\t\t\tFROM\n\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\tWHERE\n\t\t\t\t\tappendtype = " . phpAds_ZoneAppendZone . "\n\t\t\t");
        while ($row = phpAds_dbFetchArray($res)) {
            $append = phpAds_ZoneParseAppendCode($row['append']);
            if ($append[0]['zoneid'] == $zoneid) {
                phpAds_dbQuery("\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tappendtype = " . phpAds_ZoneAppendRaw . ",\n\t\t\t\t\t\t\tappend = ''\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tzoneid = '" . $row['zoneid'] . "'\n\t\t\t\t\t");
            }
            phpAds_cacheDelete('what=zone:' . $row['zoneid']);
        }
        header("Location: zone-advanced.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid);
        exit;
    } else {
        $res = phpAds_dbQuery("\n\t\t\tINSERT INTO\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t(\n\t\t\t\taffiliateid,\n\t\t\t\tzonename,\n\t\t\t\tzonetype,\n\t\t\t\tdescription,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\tdelivery\n\t\t\t\t)\n\t\t\t VALUES (\n\t\t\t \t'" . $affiliateid . "',\n\t\t\t\t'" . $zonename . "',\n\t\t\t\t'" . phpAds_ZoneCampaign . "',\n\t\t\t\t'" . $description . "',\n\t\t\t\t'" . $zwidth . "',\n\t\t\t\t'" . $zheight . "',\n\t\t\t\t'" . $delivery . "'\n\t\t\t\t)\n\t\t\t") or phpAds_sqlDie();
        $zoneid = phpAds_dbInsertID();
        header("Location: zone-advanced.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid);
        exit;
    }
}
/*********************************************************/