function processNewUploadedFile(&$aFields, &$aVariables) { $incomingFieldName = null; // Deal with any files that are uploaded - // cant use the default banners handler for this upload field because this field // is on all versions of the of the overlay form (ie. for text and html) // so "empty filename supplied error" appear when creating a text/html overlay switch ($aFields['vast_overlay_format']) { case VAST_OVERLAY_FORMAT_IMAGE: $incomingFieldName = VAST_OVERLAY_FORMAT_IMAGE . '_upload'; break; case VAST_OVERLAY_FORMAT_SWF: $incomingFieldName = VAST_OVERLAY_FORMAT_SWF . '_upload'; break; } if (empty($_FILES[$incomingFieldName]['name'])) { return; } $oFile = OA_Creative_File::factoryUploadedFile($incomingFieldName); checkForErrorFileUploaded($oFile); $oFile->store('web'); // store file on webserver $aFile = $oFile->getFileDetails(); if (!empty($aFile)) { // using $aVariables here - as this is an attribute of the base class banner row $aVariables['filename'] = $aFile['filename']; $aFields['vast_creative_type'] = $aFile['contenttype']; $aFields['vast_overlay_width'] = $aFile['width']; $aFields['vast_overlay_height'] = $aFile['height']; } }
function processForm($bannerid, $form, &$oComponent, $formDisabled = false) { $aFields = $form->exportValues(); $doBanners = OA_Dal::factoryDO('banners'); // Get the existing banner details (if it is not a new banner) if (!empty($bannerid)) { if ($doBanners->get($bannerid)) { $aBanner = $doBanners->toArray(); } } $aVariables = array(); $aVariables['campaignid'] = $aFields['campaignid']; $aVariables['target'] = isset($aFields['target']) ? $aFields['target'] : ''; $aVariables['height'] = isset($aFields['height']) ? $aFields['height'] : 0; $aVariables['width'] = isset($aFields['width']) ? $aFields['width'] : 0; $aVariables['weight'] = !empty($aFields['weight']) ? $aFields['weight'] : 0; $aVariables['adserver'] = !empty($aFields['adserver']) ? $aFields['adserver'] : ''; $aVariables['alt'] = !empty($aFields['alt']) ? $aFields['alt'] : ''; $aVariables['bannertext'] = !empty($aFields['bannertext']) ? $aFields['bannertext'] : ''; $aVariables['htmltemplate'] = !empty($aFields['htmltemplate']) ? $aFields['htmltemplate'] : ''; $aVariables['description'] = !empty($aFields['description']) ? $aFields['description'] : ''; $aVariables['imageurl'] = !empty($aFields['imageurl']) && $aFields['imageurl'] != 'http://' ? $aFields['imageurl'] : ''; $aVariables['url'] = !empty($aFields['url']) && $aFields['url'] != 'http://' ? $aFields['url'] : ''; $aVariables['status'] = $aFields['status'] != '' ? $aFields['status'] : ''; $aVariables['statustext'] = !empty($aFields['statustext']) ? $aFields['statustext'] : ''; $aVariables['storagetype'] = $aFields['type']; $aVariables['ext_bannertype'] = $aFields['ext_bannertype']; $aVariables['comments'] = $aFields['comments']; $aVariables['filename'] = !empty($aBanner['filename']) ? $aBanner['filename'] : ''; $aVariables['contenttype'] = !empty($aBanner['contenttype']) ? $aBanner['contenttype'] : ''; if ($aFields['type'] == 'url') { $aVariables['contenttype'] = OA_Creative_File::staticGetContentTypeByExtension($aVariables['imageurl']); if (empty($aVariables['contenttype'])) { // Assume dynamic urls (i.e. http://www.example.com/foo?bar) are "gif" $aVariables['contenttype'] = 'gif'; } } elseif ($aFields['type'] == 'txt') { // Text banners should always have a "txt" content type $aVariables['contenttype'] = 'txt'; } $aVariables['alt_filename'] = !empty($aBanner['alt_filename']) ? $aBanner['alt_filename'] : ''; $aVariables['alt_contenttype'] = !empty($aBanner['alt_contenttype']) ? $aBanner['alt_contenttype'] : ''; $aVariables['alt_imageurl'] = !empty($aFields['alt_imageurl']) ? $aFields['alt_imageurl'] : ''; if (isset($aFields['keyword']) && $aFields['keyword'] != '') { $keywordArray = split('[ ,]+', $aFields['keyword']); $aVariables['keyword'] = implode(' ', $keywordArray); } else { $aVariables['keyword'] = ''; } $editSwf = false; // Deal with any files that are uploaded. if (!empty($_FILES['upload']) && $aFields['replaceimage'] == 't') { //TODO refactor upload to be a valid quickform elem $oFile = OA_Creative_File::factoryUploadedFile('upload'); checkForErrorFileUploaded($oFile); $oFile->store($aFields['type']); $aFile = $oFile->getFileDetails(); if (!empty($aFile)) { $aVariables['filename'] = $aFile['filename']; $aVariables['contenttype'] = $aFile['contenttype']; $aVariables['width'] = $aFile['width']; $aVariables['height'] = $aFile['height']; $aVariables['pluginversion'] = $aFile['pluginversion']; $editSwf = $aFile['editswf']; } // Delete the old file for this banner if (!empty($aBanner['filename']) && $aBanner['filename'] != $aFile['filename'] && ($aBanner['storagetype'] == 'web' || $aBanner['storagetype'] == 'sql')) { DataObjects_Banners::deleteBannerFile($aBanner['storagetype'], $aBanner['filename']); } } if (!empty($_FILES['uploadalt']) && $_FILES['uploadalt']['size'] > 0 && $aFields['replacealtimage'] == 't') { //TODO: Check image only? - Wasn't enforced before $oFile = OA_Creative_File::factoryUploadedFile('uploadalt'); checkForErrorFileUploaded($oFile); $oFile->store($aFields['type']); $aFile = $oFile->getFileDetails(); if (!empty($aFile)) { $aVariables['alt_filename'] = $aFile['filename']; $aVariables['alt_contenttype'] = $aFile['contenttype']; } } // Handle SWF transparency if ($aVariables['contenttype'] == 'swf') { $aVariables['transparent'] = isset($aFields['transparent']) && $aFields['transparent'] ? 1 : 0; } // Update existing hard-coded links if new file has not been uploaded if ($aVariables['contenttype'] == 'swf' && empty($_FILES['upload']['tmp_name']) && isset($aFields['alink']) && is_array($aFields['alink']) && count($aFields['alink'])) { // Prepare the parameters $parameters_complete = array(); // Prepare targets if (!isset($aFields['atar']) || !is_array($aFields['atar'])) { $aFields['atar'] = array(); } foreach ($aFields['alink'] as $key => $val) { if (substr($val, 0, 7) == 'http://' && strlen($val) > 7) { if (!isset($aFields['atar'][$key])) { $aFields['atar'][$key] = ''; } if (isset($aFields['alink_chosen']) && $aFields['alink_chosen'] == $key) { $aVariables['url'] = $val; $aVariables['target'] = $aFields['atar'][$key]; } /* if (isset($aFields['asource'][$key]) && $aFields['asource'][$key] != '') { $val .= '|source:'.$aFields['asource'][$key]; } */ $parameters_complete[$key] = array('link' => $val, 'tar' => $aFields['atar'][$key]); } } $parameters = array('swf' => $parameters_complete); } else { $parameters = null; } $aVariables['parameters'] = serialize($parameters); //TODO: deleting images is not viable because they could still be in use in the delivery cache // // Delete any old banners... // if (!empty($aBanner['filename']) && $aBanner['filename'] != $aVariables['filename']) { // phpAds_ImageDelete($aBanner['storagetype'], $aBanner['filename']); // } // if (!empty($aBanner['alt_filename']) && $aBanner['alt_filename'] != $aVariables['alt_filename']) { // phpAds_ImageDelete($aBanner['storagetype'], $aBanner['alt_filename']); // } // Clients are only allowed to modify certain fields, ensure that other fields are unchanged if (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) { $aVariables['weight'] = $aBanner['weight']; $aVariables['description'] = $aBanner['name']; $aVariables['comments'] = $aBanner['comments']; } $insert = empty($bannerid) ? true : false; if ($oComponent) { $result = $oComponent->preprocessForm($insert, $bannerid, $aFields, $aVariables); if ($result === false) { // handle error return false; } } // File the data $doBanners->setFrom($aVariables); if ($insert) { $bannerid = $doBanners->insert(); // Run the Maintenance Priority Engine process OA_Maintenance_Priority::scheduleRun(); } else { $doBanners->update(); // check if size has changed if ($aVariables['width'] != $aBanner['width'] || $aVariables['height'] != $aBanner['height']) { MAX_adjustAdZones($bannerid); MAX_addDefaultPlacementZones($bannerid, $aVariables['campaignid']); } } if ($oComponent) { $result = $oComponent->processForm($insert, $bannerid, $aFields, $aVariables); if ($result === false) { // handle error // remove rec from banners table? return false; } } $translation = new OX_Translation(); if ($insert) { // Queue confirmation message $translated_message = $translation->translate($GLOBALS['strBannerHasBeenAdded'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $bannerid), htmlspecialchars($aFields['description']))); OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0); // Determine what the next page is if ($editSwf) { $nextPage = "banner-swf.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}&insert=true"; } else { $nextPage = "campaign-banners.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid']; } } else { // Determine what the next page is if ($editSwf) { $nextPage = "banner-swf.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}"; } else { $translated_message = $translation->translate($GLOBALS['strBannerHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $aFields['bannerid']), htmlspecialchars($aFields['description']))); OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0); $nextPage = "banner-edit.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}"; } } // Go to the next page Header("Location: {$nextPage}"); exit; }