<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Core_Form_Admin_Ads_Ad extends Engine_Form
{
  public function init()
  {
    // Set form attributes
    $this->setTitle('Create Advertisement');
    $this->setDescription('Follow this guide to design and create a new advertisement.');
    $this->setAttrib('id', 'form-upload');
    $this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()));

    // Title
    $this->addElement('Text', 'name', array(
      'label' => 'Advertisement Name',
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 64)),
      ),
      'filters' => array(
        'StripTags',
        new Engine_Filter_Censor(),
        new Engine_Filter_EnableLinks(),
      ),
    ));

    $this->addElement('Radio', 'media_type', array(
      'id'=>'mediatype',
      'label' => 'Advertisement Media',
      'onchange' => "updateTextFields(this)",
      'multiOptions' => array("0"=>"Upload Banner Image", "1"=>"Insert Banner HTML"),
      'description' => 'CORE_FORM_ADMIN_ADS_AD_MEDIATYPE_DESCRIPTION'
    ));
//    $this->media->getDecorator('Description')->setOption('placement', 'append');


    // Init file

    $this->addElement('HTMLUpload', 'file', [
      'form' => '#form-upload',
      'url' => $this->getView()->url([
        'controller' => 'ads',
        'action' => 'upload-photo'
      ]),
      'accept' => 'image/*',
    ]);

    $this->addElement('Hidden', 'photo_id');

    $this->addDisplayGroup(array('file'), 'upload_image');
    $upload_image_group = $this->getDisplayGroup('upload_image');

    $this->addElement('Textarea', 'html_code', array(
      'label' => 'HTML Code',
    ));
    // Buttons
    $this->addElement('Button', 'preview_html', array(
      'label' => 'Preview',
      'ignore' => true,
      'onclick'=>'javascript:preview();',
      'decorators' => array('ViewHelper')
    ));

    $this->addDisplayGroup(array('html_code', 'preview_html'), 'html_field');
    $html_code_group = $this->getDisplayGroup('html_code');

    // init submit
    $this->addElement('Button', 'submit', array(
      'label' => 'Save Changes',
      'type' => 'submit',
      'ignore' => true,
    ));
  }
}
