AddShowLiveStream.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require_once 'customvalidators/ConditionalNotEmpty.php';
  3. class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
  4. {
  5. public function init()
  6. {
  7. $cb_airtime_auth = new Zend_Form_Element_Checkbox("cb_airtime_auth");
  8. $cb_airtime_auth->setLabel(sprintf(_("Use %s Authentication:"), PRODUCT_NAME))
  9. ->setRequired(false)
  10. ->setDecorators(array('ViewHelper'));
  11. $this->addElement($cb_airtime_auth);
  12. $cb_custom_auth = new Zend_Form_Element_Checkbox("cb_custom_auth");
  13. $cb_custom_auth ->setLabel(_("Use Custom Authentication:"))
  14. ->setRequired(false)
  15. ->setDecorators(array('ViewHelper'));
  16. $this->addElement($cb_custom_auth);
  17. //custom username
  18. $custom_username = new Zend_Form_Element_Text('custom_username');
  19. $custom_username->setAttrib('class', 'input_text')
  20. ->setAttrib('autocomplete', 'off')
  21. ->setAllowEmpty(true)
  22. ->setLabel(_('Custom Username'))
  23. ->setFilters(array('StringTrim'))
  24. ->setValidators(array(
  25. new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))))
  26. ->setDecorators(array('ViewHelper'));
  27. $this->addElement($custom_username);
  28. //custom password
  29. $custom_password = new Zend_Form_Element_Password('custom_password');
  30. $custom_password->setAttrib('class', 'input_text')
  31. ->setAttrib('autocomplete', 'off')
  32. ->setAttrib('renderPassword','true')
  33. ->setAllowEmpty(true)
  34. ->setLabel(_('Custom Password'))
  35. ->setFilters(array('StringTrim'))
  36. ->setValidators(array(
  37. new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))))
  38. ->setDecorators(array('ViewHelper'));
  39. $this->addElement($custom_password);
  40. $connection_url = Application_Model_Preference::GetLiveDJSourceConnectionURL();
  41. if (trim($connection_url) == "") {
  42. $connection_url = "N/A";
  43. }
  44. $this->setDecorators(array(
  45. array('ViewScript', array('viewScript' => 'form/add-show-live-stream.phtml', "connection_url"=>$connection_url))
  46. ));
  47. }
  48. public function isValid($data)
  49. {
  50. $isValid = parent::isValid($data);
  51. if ($data['cb_custom_auth'] == 1) {
  52. if (trim($data['custom_username']) == '') {
  53. $element = $this->getElement("custom_username");
  54. $element->addError(_("Username field cannot be empty."));
  55. $isValid = false;
  56. }
  57. if (trim($data['custom_password']) == '') {
  58. $element = $this->getElement("custom_password");
  59. $element->addError(_("Password field cannot be empty."));
  60. $isValid = false;
  61. }
  62. }
  63. return $isValid;
  64. }
  65. public function disable()
  66. {
  67. $elements = $this->getElements();
  68. foreach ($elements as $element) {
  69. if ($element->getType() != 'Zend_Form_Element_Hidden') {
  70. $element->setAttrib('disabled','disabled');
  71. }
  72. }
  73. }
  74. }