function addVastFileUploadGroup($form, $aBanner, $allowSwfFiles, $fileFieldName)
 {
     $imageName = null;
     $size = null;
     $filename = null;
     if ($fileFieldName == $aBanner['vast_overlay_format'] . '_upload') {
         $imageName = _getContentTypeIconImageName($aBanner['vast_creative_type']);
         $size = _getBannerSizeText($type, $aBanner['filename']);
         $filename = $aBanner['filename'];
     }
     if (!empty($aBanner['vast_overlay_width']) && !empty($aBanner['vast_overlay_height'])) {
         $form->addElement('hidden', 'vast_overlay_width', $aBanner['vast_overlay_width']);
         $form->addElement('hidden', 'vast_overlay_height', $aBanner['vast_overlay_height']);
     }
     addUploadGroup($form, $aBanner, array('uploadName' => $fileFieldName, 'radioName' => 'replaceimage', 'imageName' => $imageName, 'fileName' => $filename, 'fileSize' => $size, 'newLabel' => $GLOBALS['strNewBannerFile'], 'updateLabel' => $GLOBALS['strUploadOrKeep'], 'handleSWF' => $allowSwfFiles));
 }
예제 #2
0
function buildBannerForm($type, $aBanner, &$oComponent = null, $formDisabled = false)
{
    //-- Build forms
    $form = new OA_Admin_UI_Component_Form("bannerForm", "POST", $_SERVER['SCRIPT_NAME'], null, array("enctype" => "multipart/form-data"));
    $form->forceClientValidation(true);
    $form->addElement('hidden', 'clientid', $aBanner['clientid']);
    $form->addElement('hidden', 'campaignid', $aBanner['campaignid']);
    $form->addElement('hidden', 'bannerid', $aBanner['bannerid']);
    $form->addElement('hidden', 'type', $type);
    $form->addElement('hidden', 'status', $aBanner['status']);
    if ($type == 'sql' || $type == 'web') {
        $form->addElement('custom', 'banner-iab-note', null, null);
    }
    if ($aBanner['contenttype'] == 'swf' && empty($aBanner['alt_contenttype']) && empty($aBanner['alt_imageurl'])) {
        $form->addElement('custom', 'banner-backup-note', null, null);
    }
    $form->addElement('header', 'header_basic', $GLOBALS['strBasicInformation']);
    if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
        $form->addElement('text', 'description', $GLOBALS['strName']);
    } else {
        $form->addElement('static', 'description', $GLOBALS['strName'], $aBanner['description']);
    }
    //local banners
    if ($type == 'sql' || $type == 'web') {
        if ($type == 'sql') {
            $header = $form->createElement('header', 'header_sql', $GLOBALS['strMySQLBanner'] . " -  banner creative");
        } else {
            $header = $form->createElement('header', 'header_sql', $GLOBALS['strWebBanner'] . " -  banner creative");
        }
        $header->setAttribute('icon', 'icon-banner-stored.gif');
        $form->addElement($header);
        $imageName = _getContentTypeIconImageName($aBanner['contenttype']);
        $size = _getBannerSizeText($type, $aBanner['filename']);
        addUploadGroup($form, $aBanner, array('uploadName' => 'upload', 'radioName' => 'replaceimage', 'imageName' => $imageName, 'fileName' => $aBanner['filename'], 'fileSize' => $size, 'newLabel' => $GLOBALS['strNewBannerFile'], 'updateLabel' => $GLOBALS['strUploadOrKeep'], 'handleSWF' => true));
        $altImageName = null;
        $altSize = null;
        if ($aBanner['contenttype'] == 'swf') {
            $altImageName = _getContentTypeIconImageName($aBanner['alt_contenttype']);
            $altSize = _getBannerSizeText($type, $aBanner['alt_filename']);
        }
        $aUploadParams = array('uploadName' => 'uploadalt', 'radioName' => 'replacealtimage', 'imageName' => $altImageName, 'fileSize' => $altSize, 'fileName' => $aBanner['alt_filename'], 'newLabel' => $GLOBALS['strNewBannerFileAlt'], 'updateLabel' => $GLOBALS['strUploadOrKeep'], 'handleSWF' => false);
        if ($aBanner['contenttype'] != 'swf') {
            $aUploadParams = array_merge($aUploadParams, array('decorateId' => 'swfAlternative'));
        }
        addUploadGroup($form, $aBanner, $aUploadParams);
        $form->addElement('header', 'header_b_links', "Banner link");
        if (count($aBanner['hardcoded_links']) == 0) {
            $form->addElement('text', 'url', $GLOBALS['strURL']);
            $targetElem = $form->createElement('text', 'target', $GLOBALS['strTarget']);
            $targetElem->setAttribute('maxlength', '16');
            $form->addElement($targetElem);
        } else {
            foreach ($aBanner['hardcoded_links'] as $key => $val) {
                $link['text'] = $form->createElement('text', "alink[" . $key . "]", null);
                $link['text']->setAttribute("style", "width:330px");
                $link['radio'] = $form->createElement('radio', "alink_chosen", null, null, $key);
                $form->addGroup($link, 'url_group', $GLOBALS['strURL'], "", false);
                if (isset($aBanner['hardcoded_targets'][$key])) {
                    $targetElem = $form->createElement('text', "atar[" . $key . "]", $GLOBALS['strTarget']);
                    $targetElem->setAttribute('maxlength', '16');
                    $form->addElement($targetElem);
                }
                if (count($aBanner['hardcoded_links']) > 1) {
                    $form->addElement('text', "asource[" . $key . "]", $GLOBALS['strOverwriteSource']);
                }
            }
            $form->addElement('hidden', 'url', $aBanner['url']);
        }
        $form->addElement('header', 'header_b_display', 'Banner display');
        $form->addElement('text', 'alt', $GLOBALS['strAlt']);
        $form->addElement('text', 'statustext', $GLOBALS['strStatusText']);
        $form->addElement('text', 'bannertext', $GLOBALS['strTextBelow']);
        if (!empty($aBanner['bannerid'])) {
            $sizeG['width'] = $form->createElement('text', 'width', $GLOBALS['strWidth'] . ":");
            $sizeG['width']->setAttribute('onChange', 'oa_sizeChangeUpdateMessage("warning_change_banner_size");');
            $sizeG['width']->setSize(5);
            $sizeG['height'] = $form->createElement('text', 'height', $GLOBALS['strHeight'] . ":");
            $sizeG['height']->setAttribute('onChange', 'oa_sizeChangeUpdateMessage("warning_change_banner_size");');
            $sizeG['height']->setSize(5);
            $form->addGroup($sizeG, 'size', $GLOBALS['strSize'], " ", false);
            //validation rules
            $translation = new OX_Translation();
            $widthRequiredRule = array($translation->translate($GLOBALS['strXRequiredField'], array($GLOBALS['strWidth'])), 'required');
            $widthPositiveRule = array($translation->translate($GLOBALS['strXGreaterThanZeroField'], array($GLOBALS['strWidth'])), 'min', 1);
            $heightRequiredRule = array($translation->translate($GLOBALS['strXRequiredField'], array($GLOBALS['strHeight'])), 'required');
            $heightPositiveRule = array($translation->translate($GLOBALS['strXGreaterThanZeroField'], array($GLOBALS['strHeight'])), 'min', 1);
            $numericRule = array($GLOBALS['strNumericField'], 'numeric');
            $form->addGroupRule('size', array('width' => array($widthRequiredRule, $numericRule, $widthPositiveRule), 'height' => array($heightRequiredRule, $numericRule, $heightPositiveRule)));
        }
        if (!isset($aBanner['contenttype']) || $aBanner['contenttype'] == 'swf') {
            $form->addElement('checkbox', 'transparent', $GLOBALS['strSwfTransparency'], $GLOBALS['strSwfTransparency']);
        }
        //TODO $form->addRule("size", 'Please enter a number', 'numeric'); //this should make all fields in group size are numeric
    }
    //external banners
    if ($type == "url") {
        $header = $form->createElement('header', 'header_txt', $GLOBALS['strURLBanner']);
        $header->setAttribute('icon', 'icon-banner-url.gif');
        $form->addElement($header);
        $form->addElement('text', 'imageurl', $GLOBALS['strNewBannerURL']);
        if ($aBanner['contenttype'] == 'swf') {
            $altImageName = _getContentTypeIconImageName($aBanner['alt_contenttype']);
            $altSize = _getBannerSizeText($type, $aBanner['alt_filename']);
            $form->addElement('text', 'alt_imageurl', $GLOBALS['strNewBannerFileAlt']);
        }
        $form->addElement('header', 'header_b_links', "Banner link");
        $form->addElement('text', 'url', $GLOBALS['strURL']);
        $targetElem = $form->createElement('text', 'target', $GLOBALS['strTarget']);
        $targetElem->setAttribute('maxlength', '16');
        $form->addElement($targetElem);
        $form->addElement('header', 'header_b_display', 'Banner display');
        $form->addElement('text', 'alt', $GLOBALS['strAlt']);
        $form->addElement('text', 'statustext', $GLOBALS['strStatusText']);
        $form->addElement('text', 'bannertext', $GLOBALS['strTextBelow']);
        $sizeG['width'] = $form->createElement('text', 'width', $GLOBALS['strWidth'] . ":");
        $sizeG['width']->setAttribute('onChange', 'oa_sizeChangeUpdateMessage("warning_change_banner_size");');
        $sizeG['width']->setSize(5);
        $sizeG['height'] = $form->createElement('text', 'height', $GLOBALS['strHeight'] . ":");
        $sizeG['height']->setAttribute('onChange', 'oa_sizeChangeUpdateMessage("warning_change_banner_size");');
        $sizeG['height']->setSize(5);
        $form->addGroup($sizeG, 'size', $GLOBALS['strSize'], " ", false);
        if (!isset($aBanner['contenttype']) || $aBanner['contenttype'] == 'swf') {
            $form->addElement('checkbox', 'transparent', $GLOBALS['strSwfTransparency'], $GLOBALS['strSwfTransparency']);
        }
        //validation rules
        $translation = new OX_Translation();
        $widthRequiredRule = array($translation->translate($GLOBALS['strXRequiredField'], array($GLOBALS['strWidth'])), 'required');
        $widthPositiveRule = array($translation->translate($GLOBALS['strXGreaterThanZeroField'], array($GLOBALS['strWidth'])), 'min', 1);
        $heightRequiredRule = array($translation->translate($GLOBALS['strXRequiredField'], array($GLOBALS['strHeight'])), 'required');
        $heightPositiveRule = array($translation->translate($GLOBALS['strXGreaterThanZeroField'], array($GLOBALS['strHeight'])), 'min', 1);
        $numericRule = array($GLOBALS['strNumericField'], 'numeric');
        $form->addGroupRule('size', array('width' => array($widthRequiredRule, $numericRule, $widthPositiveRule), 'height' => array($heightRequiredRule, $numericRule, $heightPositiveRule)));
    }
    //html & text banners
    if ($oComponent) {
        $oComponent->buildForm($form, $aBanner);
    }
    $translation = new OX_Translation();
    //common for all banners
    if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
        $form->addElement('header', 'header_additional', "Additional data");
        $form->addElement('text', 'keyword', $GLOBALS['strKeyword']);
        $weightElem = $form->createElement('text', 'weight', $GLOBALS['strWeight']);
        $weightElem->setSize(6);
        $form->addElement($weightElem);
        $form->addElement('textarea', 'comments', $GLOBALS['strComments']);
        $weightPositiveRule = $translation->translate($GLOBALS['strXPositiveWholeNumberField'], array($GLOBALS['strWeight']));
        $form->addRule('weight', $weightPositiveRule, 'numeric');
    }
    //we want submit to be the last element in its own separate section
    $form->addElement('controls', 'form-controls');
    $form->addElement('submit', 'submit', 'Save changes');
    //validation rules
    if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
        $urlRequiredMsg = $translation->translate($GLOBALS['strXRequiredField'], array($GLOBALS['strName']));
        $form->addRule('description', $urlRequiredMsg, 'required');
    }
    //set banner values
    $form->setDefaults($aBanner);
    foreach ($aBanner['hardcoded_links'] as $key => $val) {
        $swfLinks["alink[" . $key . "]"] = phpAds_htmlQuotes($val);
        if ($val == $aBanner['url']) {
            $swfLinks['alink_chosen'] = $key;
        }
        if (isset($aBanner['hardcoded_targets'][$key])) {
            $swfLinks["atar[" . $key . "]"] = phpAds_htmlQuotes($aBanner['hardcoded_targets'][$key]);
        }
        if (count($aBanner['hardcoded_links']) > 1) {
            $swfLinks["asource[" . $key . "]"] = phpAds_htmlQuotes($aBanner['hardcoded_sources'][$key]);
        }
    }
    $form->setDefaults($swfLinks);
    if ($formDisabled) {
        $form->freeze();
    }
    return $form;
}