diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 5803d3223..16c2bf2b3 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -148,9 +148,6 @@ class PreferenceController extends Zend_Controller_Action session_start(); //Open session for writing. - // get current settings - $setting = Application_Model_StreamSetting::getStreamSetting(); - $name_map = array( 'ogg' => 'Ogg Vorbis', 'fdkaac' => 'AAC+', @@ -159,55 +156,14 @@ class PreferenceController extends Zend_Controller_Action 'mp3' => 'MP3', ); - // get predefined type and bitrate from pref table - $temp_types = Application_Model_Preference::GetStreamType(); - $stream_types = array(); - foreach ($temp_types as $type) { - $type = strtolower(trim($type)); - if (isset($name_map[$type])) { - $name = $name_map[$type]; - } else { - $name = $type; - } - $stream_types[$type] = $name; - } - - $temp_bitrate = Application_Model_Preference::GetStreamBitrate(); - $max_bitrate = intval(Application_Model_Preference::GetMaxBitrate()); - $stream_bitrates = array(); - foreach ($temp_bitrate as $type) { - if (intval($type) <= $max_bitrate) { - $stream_bitrates[trim($type)] = strtoupper(trim($type))." kbit/s"; - } - } - $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams()); $form = new Application_Form_StreamSetting(); - // $form->addElement('hash', 'csrf', array( - // 'salt' => 'unique' - // )); - $csrf_namespace = new Zend_Session_Namespace('csrf_namespace'); $csrf_element = new Zend_Form_Element_Hidden('csrf'); $csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElement($csrf_element); - $form->setSetting($setting); - $form->startFrom(); - - $live_stream_subform = new Application_Form_LiveStreamingPreferences(); - $form->addSubForm($live_stream_subform, "live_stream_subform"); - - for ($i=1; $i<=$num_of_stream; $i++) { - $subform = new Application_Form_StreamSettingSubForm(); - $subform->setPrefix($i); - $subform->setSetting($setting); - $subform->setStreamTypes($stream_types); - $subform->setStreamBitrates($stream_bitrates); - $subform->startForm(); - $form->addSubForm($subform, "s".$i."_subform"); - } if ($request->isPost()) { $params = $request->getPost(); /* Parse through post data and put in format @@ -245,7 +201,6 @@ class PreferenceController extends Zend_Controller_Action $values["s3_data"] = $s3_data; $values["s4_data"] = $s4_data; - $error = false; if ($form->isValid($values)) { $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata'); @@ -262,6 +217,7 @@ class PreferenceController extends Zend_Controller_Action $s4_set_admin_pass = !empty($values["s4_data"]["admin_pass"]); // this goes into cc_pref table + Application_Model_Preference::setUsingCustomStreamSettings($values['customStreamSettings']); Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']); Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]); Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]); @@ -292,35 +248,73 @@ class PreferenceController extends Zend_Controller_Action Application_Model_StreamSetting::setLiquidsoapError($i, "waiting"); } - Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data); - - $live_stream_subform->updateVariables(); - $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf(); - $this->view->form = $form; - $this->view->num_stream = $num_of_stream; + if (Application_Model_Preference::getUsingCustomStreamSettings()) { + Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data); + } $this->view->statusMsg = "
"._("Stream Setting Updated.")."
"; - $this->_helper->json->sendJson(array( - "valid"=>"true", - "html"=>$this->view->render('preference/stream-setting.phtml'), - "s1_set_admin_pass"=>$s1_set_admin_pass, - "s2_set_admin_pass"=>$s2_set_admin_pass, - "s3_set_admin_pass"=>$s3_set_admin_pass, - "s4_set_admin_pass"=>$s4_set_admin_pass, - )); - } else { - $live_stream_subform->updateVariables(); - $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf(); - $this->view->form = $form; - $this->view->num_stream = $num_of_stream; - $this->_helper->json->sendJson(array("valid"=>"false", "html"=>$this->view->render('preference/stream-setting.phtml'))); } } + // get predefined type and bitrate from pref table + $temp_types = Application_Model_Preference::GetStreamType(); + $stream_types = array(); + foreach ($temp_types as $type) { + $type = strtolower(trim($type)); + if (isset($name_map[$type])) { + $name = $name_map[$type]; + } else { + $name = $type; + } + $stream_types[$type] = $name; + } + + $temp_bitrate = Application_Model_Preference::GetStreamBitrate(); + $max_bitrate = intval(Application_Model_Preference::GetMaxBitrate()); + $stream_bitrates = array(); + foreach ($temp_bitrate as $type) { + if (intval($type) <= $max_bitrate) { + $stream_bitrates[trim($type)] = strtoupper(trim($type))." kbit/s"; + } + } + + // get current settings + $setting = Application_Model_StreamSetting::getStreamSetting(); + + $form->setSetting($setting); + $form->startFrom(); + + $live_stream_subform = new Application_Form_LiveStreamingPreferences(); + $form->addSubForm($live_stream_subform, "live_stream_subform"); + + for ($i=1; $i<=$num_of_stream; $i++) { + $subform = new Application_Form_StreamSettingSubForm(); + $subform->setPrefix($i); + $subform->setSetting($setting); + $subform->setStreamTypes($stream_types); + $subform->setStreamBitrates($stream_bitrates); + $subform->startForm(); + $form->addSubForm($subform, "s".$i."_subform"); + } + $live_stream_subform->updateVariables(); $this->view->num_stream = $num_of_stream; $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf(); $this->view->form = $form; + if ($request->isPost()) { + if ($form->isValid($values)) { + $this->_helper->json->sendJson(array( + "valid" => "true", + "html" => $this->view->render('preference/stream-setting.phtml'), + "s1_set_admin_pass" => $s1_set_admin_pass, + "s2_set_admin_pass" => $s2_set_admin_pass, + "s3_set_admin_pass" => $s3_set_admin_pass, + "s4_set_admin_pass" => $s4_set_admin_pass, + )); + } else { + $this->_helper->json->sendJson(array("valid" => "false", "html" => $this->view->render('preference/stream-setting.phtml'))); + } + } } public function serverBrowseAction() diff --git a/airtime_mvc/application/forms/LiveStreamingPreferences.php b/airtime_mvc/application/forms/LiveStreamingPreferences.php index f22ed0054..e0b9e1ec1 100644 --- a/airtime_mvc/application/forms/LiveStreamingPreferences.php +++ b/airtime_mvc/application/forms/LiveStreamingPreferences.php @@ -7,7 +7,6 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm { $CC_CONFIG = Config::getConfig(); $isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1; - $isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true"; $defaultFade = Application_Model_Preference::GetDefaultTransitionFade(); @@ -103,7 +102,7 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm $this->addElement($showSourceMount); // demo only code - if (!$isStreamConfigable) { + if ($isDemo) { $elements = $this->getElements(); foreach ($elements as $element) { if ($element->getType() != 'Zend_Form_Element_Hidden') { diff --git a/airtime_mvc/application/forms/StreamSetting.php b/airtime_mvc/application/forms/StreamSetting.php index 262432686..1f149eae4 100644 --- a/airtime_mvc/application/forms/StreamSetting.php +++ b/airtime_mvc/application/forms/StreamSetting.php @@ -16,6 +16,10 @@ class Application_Form_StreamSetting extends Zend_Form public function startFrom() { + $this->setDecorators(array( + array('ViewScript', array('viewScript' => 'preference/stream-setting.phtml')) + )); + $setting = $this->setting; $icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata'); @@ -55,6 +59,13 @@ class Application_Form_StreamSetting extends Zend_Form ->setAttribs(array('style' => "border: 0; color: #f6931f; font-weight: bold;")) ->setDecorators(array('ViewHelper')); $this->addElement($replay_gain); + + $custom = Application_Model_Preference::getUsingCustomStreamSettings(); + $customSettings = new Zend_Form_Element_Radio('customStreamSettings'); + $customSettings->setLabel(_('Stream Settings:')); + $customSettings->setMultiOptions(array(_("Default"), _("Use Custom"))); + $customSettings->setValue(!empty($custom) ? $custom : 0); + $this->addElement($customSettings); } public function isValid($data) diff --git a/airtime_mvc/application/forms/StreamSettingSubForm.php b/airtime_mvc/application/forms/StreamSettingSubForm.php index 8d1f96f43..435d465da 100644 --- a/airtime_mvc/application/forms/StreamSettingSubForm.php +++ b/airtime_mvc/application/forms/StreamSettingSubForm.php @@ -42,7 +42,7 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm $this->setIsArray(true); $this->setElementsBelongTo($prefix."_data"); - $disable_all = Application_Model_Preference::GetEnableStreamConf() == "false"; + $disable_all = !Application_Model_Preference::getUsingCustomStreamSettings(); $enable = new Zend_Form_Element_Checkbox('enable'); $enable->setLabel(_('Enabled:')) @@ -221,10 +221,10 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm $adminPass->setAttrib('alt', 'regular_text'); $this->addElement($adminPass); - $liquidsopa_error_msg = '

'._('Getting information from the server...').'

'; + $liquidsoap_error_msg = '

'._('Getting information from the server...').'

'; $this->setDecorators(array( - array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "enabled"=>$enable->getValue(), "liquidsoap_error_msg"=>$liquidsopa_error_msg)) + array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "enabled"=>$enable->getValue(), "liquidsoap_error_msg"=>$liquidsoap_error_msg)) )); } @@ -232,23 +232,25 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm { $f_data = $data['s'.$this->prefix."_data"]; $isValid = parent::isValid($f_data); - if ($f_data['enable'] == 1) { - if ($f_data['host'] == '') { - $element = $this->getElement("host"); - $element->addError(_("Server cannot be empty.")); - $isValid = false; - } - if ($f_data['port'] == '') { - $element = $this->getElement("port"); - $element->addError(_("Port cannot be empty.")); - $isValid = false; - } - if ($f_data['output'] == 'icecast') { - if ($f_data['mount'] == '') { - $element = $this->getElement("mount"); - $element->addError(_("Mount cannot be empty with Icecast server.")); + if ($f_data) { + if ($f_data['enable'] == 1) { + if ($f_data['host'] == '') { + $element = $this->getElement("host"); + $element->addError(_("Server cannot be empty.")); $isValid = false; } + if ($f_data['port'] == '') { + $element = $this->getElement("port"); + $element->addError(_("Port cannot be empty.")); + $isValid = false; + } + if ($f_data['output'] == 'icecast') { + if ($f_data['mount'] == '') { + $element = $this->getElement("mount"); + $element->addError(_("Mount cannot be empty with Icecast server.")); + $isValid = false; + } + } } } diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index e8d116246..e597ecd27 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -1489,4 +1489,14 @@ class Application_Model_Preference self::setValue("task_manager_lock", $value); } + // SAAS-876 - Toggle indicating whether user is using custom stream settings + + public static function getUsingCustomStreamSettings() { + return self::getValue("using_custom_stream_settings"); + } + + public static function setUsingCustomStreamSettings($value) { + self::setValue("using_custom_stream_settings", $value); + } + } diff --git a/airtime_mvc/application/views/scripts/form/stream-setting-form.phtml b/airtime_mvc/application/views/scripts/form/stream-setting-form.phtml index a8d61d247..ca98ed789 100644 --- a/airtime_mvc/application/views/scripts/form/stream-setting-form.phtml +++ b/airtime_mvc/application/views/scripts/form/stream-setting-form.phtml @@ -1,7 +1,7 @@ stream_number; ?> -

">stream_number?>

+

">stream_number?>

enabled == 0?'style="display: none;':''?> id="-config">
diff --git a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml index 29fbc6756..32d1b034d 100644 --- a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml +++ b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml @@ -1,12 +1,10 @@
-

enable_stream_conf == "true"){?>style="float:left">

+

- enable_stream_conf == "true"){?>
- + form->getElement('csrf') ?>
- statusMsg;?>
@@ -39,6 +37,12 @@
form->getElement('icecast_vorbis_metadata') ?>
+ + form->getElement('customStreamSettings')->render(); + ?> +
@@ -105,16 +109,18 @@
- num_stream;$i++){ - echo $this->form->getSubform("s".$i."_subform"); - } - ?> + num_stream;$i++){ + echo $this->form->getSubform("s".$i."_subform"); + } + } else { + // TODO: replace this with something that looks good + } + ?>
- enable_stream_conf == "true"){?>
- - +
diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 6ad9b941c..5d9bc4a67 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -2252,6 +2252,10 @@ span.errors.sp-errors{ width: 1100px; } +#stream_save_bottom { + bottom: 0; +} + .preferences .padded { margin-top: 5px; /* Firefox needs this */ } diff --git a/airtime_mvc/public/js/airtime/preferences/streamsetting.js b/airtime_mvc/public/js/airtime/preferences/streamsetting.js index 0fd0cd90a..54e397da6 100644 --- a/airtime_mvc/public/js/airtime/preferences/streamsetting.js +++ b/airtime_mvc/public/js/airtime/preferences/streamsetting.js @@ -469,7 +469,7 @@ $(document).ready(function() { setSliderForReplayGain(); getAdminPasswordStatus(); - $('#stream_save').live('click', function(){ + $("[id^='stream_save']").live('click', function(){ var confirm_pypo_restart_text = sprintf($.i18n._("If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If %s is recording, and if the change causes a playout engine restart, the recording will be interrupted."), PRODUCT_NAME); if (confirm(confirm_pypo_restart_text)) { var data = $('#stream_form').serialize();