public function init()
 {
     $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
     $rangeValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(0, 59.9);
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/preferences_general.phtml'))));
     $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
     $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
     //Station name
     $this->addElement('text', 'stationName', array('class' => 'input_text', 'label' => _('Station Name'), 'required' => false, 'filters' => array('StringTrim'), 'value' => Application_Model_Preference::GetStationName(), 'decorators' => array('ViewHelper')));
     //Default station fade in
     $this->addElement('text', 'stationDefaultCrossfadeDuration', array('class' => 'input_text', 'label' => _('Default Crossfade Duration (s):'), 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array($rangeValidator, $notEmptyValidator, 'regex', false, array('/^[0-9]{1,2}(\\.\\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')))), 'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(), 'decorators' => array('ViewHelper')));
     //Default station fade in
     $this->addElement('text', 'stationDefaultFadeIn', array('class' => 'input_text', 'label' => _('Default Fade In (s):'), 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array($rangeValidator, $notEmptyValidator, 'regex', false, array('/^[0-9]{1,2}(\\.\\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')))), 'value' => $defaultFadeIn, 'decorators' => array('ViewHelper')));
     //Default station fade out
     $this->addElement('text', 'stationDefaultFadeOut', array('class' => 'input_text', 'label' => _('Default Fade Out (s):'), 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array($rangeValidator, $notEmptyValidator, 'regex', false, array('/^[0-9]{1,2}(\\.\\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}')))), 'value' => $defaultFadeOut, 'decorators' => array('ViewHelper')));
     $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
     $third_party_api->setLabel(sprintf(_('Allow Remote Websites To Access "Schedule" Info?%s (Enable this to make front-end widgets work.)'), '<br>'));
     $third_party_api->setMultiOptions(array(_("Disabled"), _("Enabled")));
     $third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi());
     $third_party_api->setDecorators(array('ViewHelper'));
     $this->addElement($third_party_api);
     $locale = new Zend_Form_Element_Select("locale");
     $locale->setLabel(_("Default Interface Language"));
     $locale->setMultiOptions(Application_Model_Locale::getLocales());
     $locale->setValue(Application_Model_Preference::GetDefaultLocale());
     $locale->setDecorators(array('ViewHelper'));
     $this->addElement($locale);
     /* Form Element for setting the Timezone */
     $timezone = new Zend_Form_Element_Select("timezone");
     $timezone->setLabel(_("Station Timezone"));
     $timezone->setMultiOptions(Application_Common_Timezone::getTimezones());
     $timezone->setValue(Application_Model_Preference::GetDefaultTimezone());
     $timezone->setDecorators(array('ViewHelper'));
     $this->addElement($timezone);
     /* Form Element for setting which day is the start of the week */
     $week_start_day = new Zend_Form_Element_Select("weekStartDay");
     $week_start_day->setLabel(_("Week Starts On"));
     $week_start_day->setMultiOptions($this->getWeekStartDays());
     $week_start_day->setValue(Application_Model_Preference::GetWeekStartDay());
     $week_start_day->setDecorators(array('ViewHelper'));
     $this->addElement($week_start_day);
 }
 public function init()
 {
     $CC_CONFIG = Config::getConfig();
     $isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
     $isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true";
     $defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
     if ($defaultFade == "") {
         $defaultFade = '00.000000';
     }
     // automatic trasition on source disconnection
     $auto_transition = new Zend_Form_Element_Checkbox("auto_transition");
     $auto_transition->setLabel(_("Auto Switch Off"))->setValue(Application_Model_Preference::GetAutoTransition())->setDecorators(array('ViewHelper'));
     $this->addElement($auto_transition);
     // automatic switch on upon source connection
     $auto_switch = new Zend_Form_Element_Checkbox("auto_switch");
     $auto_switch->setLabel(_("Auto Switch On"))->setValue(Application_Model_Preference::GetAutoSwitch())->setDecorators(array('ViewHelper'));
     $this->addElement($auto_switch);
     // Default transition fade
     $transition_fade = new Zend_Form_Element_Text("transition_fade");
     $transition_fade->setLabel(_("Switch Transition Fade (s)"))->setFilters(array('StringTrim'))->addValidator('regex', false, array('/^[0-9]{1,2}(\\.\\d{1,6})?$/', 'messages' => _('enter a time in seconds 00{.000000}')))->setValue($defaultFade)->setDecorators(array('ViewHelper'));
     $this->addElement($transition_fade);
     //Master username
     $master_username = new Zend_Form_Element_Text('master_username');
     $master_username->setAttrib('autocomplete', 'off')->setAllowEmpty(true)->setLabel(_('Master Username'))->setFilters(array('StringTrim'))->setValue(Application_Model_Preference::GetLiveStreamMasterUsername())->setDecorators(array('ViewHelper'));
     $this->addElement($master_username);
     //Master password
     if ($isDemo) {
         $master_password = new Zend_Form_Element_Text('master_password');
     } else {
         $master_password = new Zend_Form_Element_Password('master_password');
         $master_password->setAttrib('renderPassword', 'true');
     }
     $master_password->setAttrib('autocomplete', 'off')->setAttrib('renderPassword', 'true')->setAllowEmpty(true)->setValue(Application_Model_Preference::GetLiveStreamMasterPassword())->setLabel(_('Master Password'))->setFilters(array('StringTrim'))->setDecorators(array('ViewHelper'));
     $this->addElement($master_password);
     //Master source connection url
     $master_dj_connection_url = new Zend_Form_Element_Text('master_dj_connection_url');
     $master_dj_connection_url->setAttrib('readonly', true)->setLabel(_('Master Source Connection URL'))->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL())->setDecorators(array('ViewHelper'));
     $this->addElement($master_dj_connection_url);
     //Show source connection url
     $live_dj_connection_url = new Zend_Form_Element_Text('live_dj_connection_url');
     $live_dj_connection_url->setAttrib('readonly', true)->setLabel(_('Show Source Connection URL'))->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL())->setDecorators(array('ViewHelper'));
     $this->addElement($live_dj_connection_url);
     //liquidsoap harbor.input port
     $betweenValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(1024, 49151);
     $m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
     $master_dj_port = new Zend_Form_Element_Text('master_harbor_input_port');
     $master_dj_port->setLabel(_("Master Source Port"))->setValue($m_port)->setValidators(array($betweenValidator))->addValidator('regex', false, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => _('Only numbers are allowed.'))))->setDecorators(array('ViewHelper'));
     $this->addElement($master_dj_port);
     $m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
     $master_dj_mount = new Zend_Form_Element_Text('master_harbor_input_mount_point');
     $master_dj_mount->setLabel(_("Master Source Mount Point"))->setValue($m_mount)->setValidators(array(array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))->setDecorators(array('ViewHelper'));
     $this->addElement($master_dj_mount);
     //liquidsoap harbor.input port
     $l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
     $live_dj_port = new Zend_Form_Element_Text('dj_harbor_input_port');
     $live_dj_port->setLabel(_("Show Source Port"))->setValue($l_port)->setValidators(array($betweenValidator))->addValidator('regex', false, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => _('Only numbers are allowed.'))))->setDecorators(array('ViewHelper'));
     $this->addElement($live_dj_port);
     $l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
     $live_dj_mount = new Zend_Form_Element_Text('dj_harbor_input_mount_point');
     $live_dj_mount->setLabel(_("Show Source Mount Point"))->setValue($l_mount)->setValidators(array(array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))->setDecorators(array('ViewHelper'));
     $this->addElement($live_dj_mount);
     // demo only code
     if (!$isStreamConfigable) {
         $elements = $this->getElements();
         foreach ($elements as $element) {
             if ($element->getType() != 'Zend_Form_Element_Hidden') {
                 $element->setAttrib("disabled", "disabled");
             }
         }
     }
 }