00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Googleoptimizer_Block_Adminhtml_Cms_Page_Edit_Tab_Googleoptimizer extends Mage_Adminhtml_Block_Widget_Form
00035 {
00036 protected function _prepareForm()
00037 {
00038 $form = new Varien_Data_Form();
00039
00040 $fieldset = $form->addFieldset('googleoptimizer_fields',
00041 array('legend'=>Mage::helper('googleoptimizer')->__('Google Optimizer Scripts'))
00042 );
00043
00044 Mage::helper('googleoptimizer')->setStoreId(Mage::app()->getDefaultStoreView());
00045
00046 $fieldset->addField('conversion_page', 'select',
00047 array(
00048 'name' => 'conversion_page',
00049 'label' => Mage::helper('googleoptimizer')->__('Conversion Page'),
00050 'values'=> Mage::getModel('googleoptimizer/adminhtml_system_config_source_googleoptimizer_conversionpages')->toOptionArray(),
00051 'class' => 'select googleoptimizer validate-googleoptimizer',
00052 'required' => false,
00053 'onchange' => 'googleOptimizerConversionPageAction(this)'
00054 )
00055 );
00056
00057 if (!Mage::app()->isSingleStoreMode()) {
00058 $form->getElement('conversion_page')->setOnchange('googleOptimizerConversionCmsPageAction(this)');
00059 $fieldset->addField('conversion_page_url', 'note',
00060 array(
00061 'name' => 'conversion_page_url',
00062 'label' => Mage::helper('googleoptimizer')->__('Conversion Page URL'),
00063 )
00064 )->setRenderer($this->getLayout()->createBlock('googleoptimizer/adminhtml_cms_page_edit_renderer_conversion'));
00065 } else {
00066 $fieldset->addField('conversion_page_url', 'text',
00067 array(
00068 'name' => 'conversion_page_url',
00069 'label' => Mage::helper('googleoptimizer')->__('Conversion Page URL'),
00070 'class' => 'input-text',
00071 'readonly' => 'readonly',
00072 'required' => false,
00073 'note' => Mage::helper('googleoptimizer')->__('Please copy and paste this value to experiment edit form')
00074 )
00075 );
00076 }
00077
00078 $fieldset->addField('export_controls', 'text',
00079 array(
00080 'name' => 'export_controls',
00081 )
00082 );
00083
00084 $pageTypes = array(
00085 '' => Mage::helper('googleoptimizer')->__('-- Please Select --'),
00086 'original' => Mage::helper('googleoptimizer')->__('Original Page'),
00087 'variant' => Mage::helper('googleoptimizer')->__('Variant Page')
00088 );
00089
00090 $fieldset->addField('page_type', 'select',
00091 array(
00092 'name' => 'page_type',
00093 'label' => Mage::helper('googleoptimizer')->__('Page Type'),
00094 'values'=> $pageTypes,
00095 'class' => 'select googleoptimizer validate-googleoptimizer',
00096 'required' => false,
00097 'onchange' => 'googleOptimizerVariantPageAction(this)'
00098 )
00099 );
00100
00101 $fieldset->addField('control_script', 'textarea',
00102 array(
00103 'name' => 'control_script',
00104 'label' => Mage::helper('googleoptimizer')->__('Control Script'),
00105 'class' => 'textarea validate-googleoptimizer',
00106 'required' => false,
00107 'note' => '',
00108 )
00109 );
00110 $fieldset->addField('tracking_script', 'textarea',
00111 array(
00112 'name' => 'tracking_script',
00113 'label' => Mage::helper('googleoptimizer')->__('Tracking Script'),
00114 'class' => 'textarea validate-googleoptimizer',
00115 'required' => false,
00116 'note' => '',
00117 )
00118 );
00119 $fieldset->addField('conversion_script', 'textarea',
00120 array(
00121 'name' => 'conversion_script',
00122 'label' => Mage::helper('googleoptimizer')->__('Conversion Script'),
00123 'class' => 'textarea validate-googleoptimizer',
00124 'required' => false,
00125 'note' => '',
00126 )
00127 );
00128
00129 if (Mage::helper('googleoptimizer')->getConversionPagesUrl()
00130 && $this->getGoogleOptimizer()
00131 && $this->getGoogleOptimizer()->getConversionPage())
00132 {
00133 $form->getElement('conversion_page_url')
00134 ->setValue(Mage::helper('googleoptimizer')
00135 ->getConversionPagesUrl()->getData($this->getGoogleOptimizer()->getConversionPage())
00136 );
00137 }
00138
00139 $renderer = $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_googleoptimizer_import');
00140 $form->getElement('export_controls')->setRenderer($renderer);
00141
00142 $values = array();
00143 if ($this->getGoogleOptimizer() && $this->getGoogleOptimizer()->getData()) {
00144 $values = $this->getGoogleOptimizer()->getData();
00145 $fieldset->addField('code_id', 'hidden', array('name' => 'code_id'));
00146 if ($this->getGoogleOptimizer()->getData('page_type') == Mage_Googleoptimizer_Model_Code_Page::PAGE_TYPE_VARIANT) {
00147 foreach ($fieldset->getElements() as $element) {
00148 if (($element->getId() != 'tracking_script' && $element->getId() != 'page_type')
00149 && ($element->getType() == 'textarea' || $element->getType() == 'select'))
00150 {
00151 $element->setDisabled(true);
00152 }
00153 }
00154 }
00155 }
00156
00157 $form->addValues($values);
00158 $form->setFieldNameSuffix('googleoptimizer');
00159 $this->setForm($form);
00160
00161 return parent::_prepareForm();
00162 }
00163
00164 public function getCmsPage()
00165 {
00166 return Mage::registry('cms_page');
00167 }
00168
00169 public function getGoogleOptimizer()
00170 {
00171 if ($this->getCmsPage()->getGoogleoptimizer()) {
00172 $googleOptimizer = new Varien_Object($this->getCmsPage()->getGoogleoptimizer());
00173 } else {
00174 $googleOptimizer = $this->getCmsPage()->getGoogleOptimizerScripts();
00175 }
00176 return $googleOptimizer;
00177 }
00178 }