Rename airtime_mvc/ to legacy/
This commit is contained in:
parent
f0879322c2
commit
3e18d42c8b
1316 changed files with 0 additions and 0 deletions
102
legacy/application/forms/AddShowAbsoluteRebroadcastDates.php
Normal file
102
legacy/application/forms/AddShowAbsoluteRebroadcastDates.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast-absolute.phtml'))
|
||||
));
|
||||
|
||||
for ($i=1; $i<=10; $i++) {
|
||||
|
||||
$text = new Zend_Form_Element_Text("add_show_rebroadcast_date_absolute_$i");
|
||||
$text->setAttrib('class', 'input_text');
|
||||
$text->addFilter('StringTrim');
|
||||
$text->addValidator('date', false, array('YYYY-MM-DD'));
|
||||
$text->setRequired(false);
|
||||
$text->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($text);
|
||||
|
||||
$text = new Zend_Form_Element_Text("add_show_rebroadcast_time_absolute_$i");
|
||||
$text->setAttrib('class', 'input_text');
|
||||
$text->addFilter('StringTrim');
|
||||
$text->addValidator('date', false, array('HH:mm'));
|
||||
$text->addValidator('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')));
|
||||
$text->setRequired(false);
|
||||
$text->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($text);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isValid($formData) {
|
||||
if (parent::isValid($formData)) {
|
||||
return $this->checkReliantFields($formData);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkReliantFields($formData)
|
||||
{
|
||||
$noError = true;
|
||||
|
||||
for ($i=1; $i<=10; $i++) {
|
||||
|
||||
$valid = true;
|
||||
$day = $formData['add_show_rebroadcast_date_absolute_'.$i];
|
||||
$time = $formData['add_show_rebroadcast_time_absolute_'.$i];
|
||||
|
||||
if (trim($day) == "" && trim($time) == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trim($day) == "") {
|
||||
$this->getElement('add_show_rebroadcast_date_absolute_'.$i)->setErrors(array(_("Day must be specified")));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if (trim($time) == "") {
|
||||
$this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array(_("Time must be specified")));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ($valid === false) {
|
||||
$noError = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
$show_start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
||||
$show_end = new DateTime($show_start_time);
|
||||
|
||||
$duration = $formData['add_show_duration'];
|
||||
$duration = explode(":", $duration);
|
||||
|
||||
$show_end->add(new DateInterval("PT$duration[0]H"));
|
||||
$show_end->add(new DateInterval("PT$duration[1]M"));
|
||||
$show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast
|
||||
|
||||
$rebroad_start = $day." ".$formData['add_show_rebroadcast_time_absolute_'.$i];
|
||||
$rebroad_start = new DateTime($rebroad_start);
|
||||
|
||||
if ($rebroad_start < $show_end) {
|
||||
$this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array(_("Must wait at least 1 hour to rebroadcast")));
|
||||
$valid = false;
|
||||
$noError = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $noError;
|
||||
}
|
||||
}
|
58
legacy/application/forms/AddShowAutoPlaylist.php
Normal file
58
legacy/application/forms/AddShowAutoPlaylist.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowAutoPlaylist extends Zend_Form_SubForm
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/add-show-autoplaylist.phtml'))
|
||||
));
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
// retrieves the length limit for each char field
|
||||
// and store to assoc array
|
||||
$maxLens = Application_Model_Show::getMaxLengths();
|
||||
|
||||
// Add autoplaylist checkbox element
|
||||
$this->addElement('checkbox', 'add_show_has_autoplaylist', array(
|
||||
'label' => _('Add Autoloading Playlist ?'),
|
||||
'required' => false,
|
||||
'class' => 'input_text',
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
|
||||
$autoPlaylistSelect = new Zend_Form_Element_Select("add_show_autoplaylist_id");
|
||||
$autoPlaylistSelect->setLabel(_("Select Playlist"));
|
||||
$autoPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
|
||||
$autoPlaylistSelect->setValue(null);
|
||||
$autoPlaylistSelect->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($autoPlaylistSelect);
|
||||
// Add autoplaylist checkbox element
|
||||
$this->addElement('checkbox', 'add_show_autoplaylist_repeat', array(
|
||||
'label' => _('Repeat Playlist Until Show is Full ?'),
|
||||
'required' => false,
|
||||
'class' => 'input_text',
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function makeReadonly()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('readonly','readonly');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
legacy/application/forms/AddShowLiveStream.php
Normal file
100
legacy/application/forms/AddShowLiveStream.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
require_once 'customvalidators/ConditionalNotEmpty.php';
|
||||
|
||||
class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$cb_airtime_auth = new Zend_Form_Element_Checkbox("cb_airtime_auth");
|
||||
$cb_airtime_auth->setLabel(sprintf(_("Use %s Authentication:"), PRODUCT_NAME))
|
||||
->setChecked(true)
|
||||
->setRequired(false);
|
||||
$this->addElement($cb_airtime_auth);
|
||||
|
||||
$cb_custom_auth = new Zend_Form_Element_Checkbox("cb_custom_auth");
|
||||
$cb_custom_auth ->setLabel(_("Use Custom Authentication:"))
|
||||
->setRequired(false);
|
||||
$this->addElement($cb_custom_auth);
|
||||
|
||||
//custom username
|
||||
$custom_username = new Zend_Form_Element_Text('custom_username');
|
||||
$custom_username->setAttrib('class', 'input_text')
|
||||
->setAttrib('autocomplete', 'off')
|
||||
->setAllowEmpty(true)
|
||||
->setLabel(_('Custom Username'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))));
|
||||
$this->addElement($custom_username);
|
||||
|
||||
//custom password
|
||||
$custom_password = new Zend_Form_Element_Password('custom_password');
|
||||
$custom_password->setAttrib('class', 'input_text')
|
||||
->setAttrib('autocomplete', 'off')
|
||||
->setAttrib('renderPassword','true')
|
||||
->setAllowEmpty(true)
|
||||
->setLabel(_('Custom Password'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))));
|
||||
$this->addElement($custom_password);
|
||||
|
||||
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||
|
||||
// Show source connection url parameters
|
||||
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
|
||||
$showSourceHost->setAttrib('readonly', true)
|
||||
->setLabel(_('Host:'))
|
||||
->setValue(isset($showSourceParams["host"])?$showSourceParams["host"]:"");
|
||||
$this->addElement($showSourceHost);
|
||||
|
||||
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
|
||||
$showSourcePort->setAttrib('readonly', true)
|
||||
->setLabel(_('Port:'))
|
||||
->setValue(isset($showSourceParams["port"])?$showSourceParams["port"]:"");
|
||||
$this->addElement($showSourcePort);
|
||||
|
||||
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
|
||||
$showSourceMount->setAttrib('readonly', true)
|
||||
->setLabel(_('Mount:'))
|
||||
->setValue(isset($showSourceParams["path"])?$showSourceParams["path"]:"");
|
||||
$this->addElement($showSourceMount);
|
||||
|
||||
$this->setDecorators(
|
||||
array(
|
||||
array('ViewScript', array('viewScript' => 'form/add-show-live-stream.phtml'))
|
||||
));
|
||||
}
|
||||
|
||||
public function isValid($data)
|
||||
{
|
||||
$isValid = parent::isValid($data);
|
||||
|
||||
if ($data['cb_custom_auth'] == 1) {
|
||||
if (trim($data['custom_username']) == '') {
|
||||
$element = $this->getElement("custom_username");
|
||||
$element->addError(_("Username field cannot be empty."));
|
||||
$isValid = false;
|
||||
}
|
||||
if (trim($data['custom_password']) == '') {
|
||||
$element = $this->getElement("custom_password");
|
||||
$element->addError(_("Password field cannot be empty."));
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
legacy/application/forms/AddShowRR.php
Normal file
31
legacy/application/forms/AddShowRR.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowRR extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
// Add record element
|
||||
$this->addElement('checkbox', 'add_show_record', array(
|
||||
'label' => _('Record from Line In?'),
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
// Add record element
|
||||
$this->addElement('checkbox', 'add_show_rebroadcast', array(
|
||||
'label' => _('Rebroadcast?'),
|
||||
'required' => false,
|
||||
));
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
111
legacy/application/forms/AddShowRebroadcastDates.php
Normal file
111
legacy/application/forms/AddShowRebroadcastDates.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast.phtml'))
|
||||
));
|
||||
|
||||
$relativeDates = array();
|
||||
$relativeDates[""] = "";
|
||||
for ($i=0; $i<=30; $i++) {
|
||||
$relativeDates["$i days"] = "+$i "._("days");
|
||||
}
|
||||
|
||||
for ($i=1; $i<=10; $i++) {
|
||||
|
||||
$select = new Zend_Form_Element_Select("add_show_rebroadcast_date_$i");
|
||||
$select->setAttrib('class', 'input_select');
|
||||
$select->setMultiOptions($relativeDates);
|
||||
$select->setRequired(false);
|
||||
$select->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($select);
|
||||
|
||||
$text = new Zend_Form_Element_Text("add_show_rebroadcast_time_$i");
|
||||
$text->setAttrib('class', 'input_text');
|
||||
$text->addFilter('StringTrim');
|
||||
$text->addValidator('date', false, array('HH:mm'));
|
||||
$text->addValidator('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')));
|
||||
$text->setRequired(false);
|
||||
$text->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($text);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isValid($formData) {
|
||||
if (parent::isValid($formData)) {
|
||||
return $this->checkReliantFields($formData);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkReliantFields($formData)
|
||||
{
|
||||
$noError = true;
|
||||
|
||||
for ($i=1; $i<=10; $i++) {
|
||||
|
||||
$valid = true;
|
||||
$days = $formData['add_show_rebroadcast_date_'.$i];
|
||||
$time = $formData['add_show_rebroadcast_time_'.$i];
|
||||
|
||||
if (trim($days) == "" && trim($time) == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trim($days) == "") {
|
||||
$this->getElement('add_show_rebroadcast_date_'.$i)->setErrors(array(_("Day must be specified")));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if (trim($time) == "") {
|
||||
$this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array(_("Time must be specified")));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if ($valid === false) {
|
||||
$noError = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
$days = explode(" ", $days);
|
||||
$day = $days[0];
|
||||
|
||||
$show_start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
||||
$show_end = new DateTime($show_start_time);
|
||||
|
||||
$duration = $formData['add_show_duration'];
|
||||
$duration = explode(":", $duration);
|
||||
|
||||
$show_end->add(new DateInterval("PT$duration[0]H"));
|
||||
$show_end->add(new DateInterval("PT$duration[1]M"));
|
||||
$show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast
|
||||
|
||||
$rebroad_start = $formData['add_show_start_date']." ".$formData['add_show_rebroadcast_time_'.$i];
|
||||
$rebroad_start = new DateTime($rebroad_start);
|
||||
$rebroad_start->add(new DateInterval("P".$day."D"));
|
||||
|
||||
if ($rebroad_start < $show_end) {
|
||||
$this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array(_("Must wait at least 1 hour to rebroadcast")));
|
||||
$valid = false;
|
||||
$noError = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $noError;
|
||||
}
|
||||
}
|
119
legacy/application/forms/AddShowRepeats.php
Normal file
119
legacy/application/forms/AddShowRepeats.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowRepeats extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
$linked = new Zend_Form_Element_Checkbox("add_show_linked");
|
||||
$linked->setLabel(_("Link:"));
|
||||
$this->addElement($linked);
|
||||
|
||||
//Add type select
|
||||
$this->addElement('select', 'add_show_repeat_type', array(
|
||||
'required' => true,
|
||||
'label' => _('Repeat Type:'),
|
||||
'class' => ' input_select',
|
||||
'multiOptions' => array(
|
||||
"0" => _("weekly"),
|
||||
"1" => _("every 2 weeks"),
|
||||
"4" => _("every 3 weeks"),
|
||||
"5" => _("every 4 weeks"),
|
||||
"2" => _("monthly")
|
||||
),
|
||||
));
|
||||
|
||||
// Add days checkboxes
|
||||
$this->addElement(
|
||||
'multiCheckbox',
|
||||
'add_show_day_check',
|
||||
array(
|
||||
'label' => _('Select Days:'),
|
||||
'required' => false,
|
||||
'multiOptions' => array(
|
||||
"0" => _("Sun"),
|
||||
"1" => _("Mon"),
|
||||
"2" => _("Tue"),
|
||||
"3" => _("Wed"),
|
||||
"4" => _("Thu"),
|
||||
"5" => _("Fri"),
|
||||
"6" => _("Sat"),
|
||||
),
|
||||
));
|
||||
|
||||
$repeatMonthlyType = new Zend_Form_Element_Radio("add_show_monthly_repeat_type");
|
||||
$repeatMonthlyType
|
||||
->setLabel(_("Repeat By:"))
|
||||
->setRequired(true)
|
||||
->setMultiOptions(
|
||||
array(2 => _("day of the month"), 3 => _("day of the week")))
|
||||
->setValue(2);
|
||||
$this->addElement($repeatMonthlyType);
|
||||
|
||||
// Add end date element
|
||||
$this->addElement('text', 'add_show_end_date', array(
|
||||
'label' => _('Date End:'),
|
||||
'class' => 'input_text',
|
||||
'value' => date("Y-m-d"),
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))
|
||||
)
|
||||
));
|
||||
|
||||
// Add no end element
|
||||
$this->addElement('checkbox', 'add_show_no_end', array(
|
||||
'label' => _('No End?'),
|
||||
'required' => false,
|
||||
'checked' => true,
|
||||
));
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isValid($formData) {
|
||||
if (parent::isValid($formData)) {
|
||||
return $this->checkReliantFields($formData);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkReliantFields($formData)
|
||||
{
|
||||
if (!$formData['add_show_no_end']) {
|
||||
$start_timestamp = $formData['add_show_start_date'];
|
||||
$end_timestamp = $formData['add_show_end_date'];
|
||||
$showTimeZone = new DateTimeZone($formData['add_show_timezone']);
|
||||
|
||||
//We're assuming all data is valid at this point (timezone, etc.).
|
||||
|
||||
$startDate = new DateTime($start_timestamp, $showTimeZone);
|
||||
$endDate = new DateTime($end_timestamp, $showTimeZone);
|
||||
|
||||
if ($endDate < $startDate) {
|
||||
$this->getElement('add_show_end_date')->setErrors(array(_('End date must be after start date')));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isset($formData['add_show_day_check'])) {
|
||||
$this->getElement('add_show_day_check')->setErrors(array(_('Please select a repeat day')));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
123
legacy/application/forms/AddShowStyle.php
Normal file
123
legacy/application/forms/AddShowStyle.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
require_once 'customfilters/ImageSize.php';
|
||||
|
||||
class Application_Form_AddShowStyle extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
// Add show background-color input
|
||||
$this->addElement('text', 'add_show_background_color', array(
|
||||
'label' => _('Background Colour:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
|
||||
$bg = $this->getElement('add_show_background_color');
|
||||
|
||||
$bg->setDecorators(array(array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-style.phtml',
|
||||
'class' => 'big'
|
||||
))));
|
||||
|
||||
$stringLengthValidator = Application_Form_Helper_ValidationTypes::overrideStringLengthValidator(6, 6);
|
||||
$bg->setValidators(array(
|
||||
'Hex', $stringLengthValidator
|
||||
));
|
||||
|
||||
// Add show color input
|
||||
$this->addElement('text', 'add_show_color', array(
|
||||
'label' => _('Text Colour:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
|
||||
$c = $this->getElement('add_show_color');
|
||||
|
||||
$c->setDecorators(array(array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-style.phtml',
|
||||
'class' => 'big'
|
||||
))));
|
||||
|
||||
$c->setValidators(array(
|
||||
'Hex', $stringLengthValidator
|
||||
));
|
||||
|
||||
// Show the current logo
|
||||
$this->addElement('image', 'add_show_logo_current', array(
|
||||
'label' => _('Current Logo:'),
|
||||
));
|
||||
|
||||
$logo = $this->getElement('add_show_logo_current');
|
||||
$logo->setDecorators(array(
|
||||
array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-style.phtml',
|
||||
'class' => 'big'
|
||||
))
|
||||
));
|
||||
// Since we need to use a Zend_Form_Element_Image proto, disable it
|
||||
$logo->setAttrib('disabled','disabled');
|
||||
|
||||
// Button to remove the current logo
|
||||
$this->addElement('button', 'add_show_logo_current_remove', array(
|
||||
'label' => '<span class="ui-button-text">' . _('Remove') . '</span>',
|
||||
'class' => 'ui-button ui-state-default ui-button-text-only',
|
||||
'escape' => false
|
||||
));
|
||||
|
||||
// Add show image input
|
||||
$upload = new Zend_Form_Element_File('add_show_logo');
|
||||
|
||||
$upload->setLabel(_('Show Logo:'))
|
||||
->setRequired(false)
|
||||
->setDecorators(array('File', array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-style.phtml',
|
||||
'class' => 'big',
|
||||
'placement' => false
|
||||
))))
|
||||
->addValidator('Count', false, 1)
|
||||
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
|
||||
->addFilter('ImageSize');
|
||||
|
||||
$this->addElement($upload);
|
||||
|
||||
// Add image preview
|
||||
$this->addElement('image', 'add_show_logo_preview', array(
|
||||
'label' => _('Logo Preview:'),
|
||||
));
|
||||
|
||||
$preview = $this->getElement('add_show_logo_preview');
|
||||
$preview->setDecorators(array(array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-style.phtml',
|
||||
'class' => 'big'
|
||||
))));
|
||||
$preview->setAttrib('disabled','disabled');
|
||||
|
||||
$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');
|
||||
$this->addElement($csrf_element);
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden'
|
||||
// We should still be able to remove the show logo
|
||||
&& $element->getName() != 'add_show_logo_current_remove') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hideShowLogo() {
|
||||
$this->removeElement('add_show_logo');
|
||||
$this->removeElement('add_show_logo_preview');
|
||||
}
|
||||
|
||||
}
|
114
legacy/application/forms/AddShowWhat.php
Normal file
114
legacy/application/forms/AddShowWhat.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowWhat extends Zend_Form_SubForm
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
// retrieves the length limit for each char field
|
||||
// and store to assoc array
|
||||
$maxLens = Application_Model_Show::getMaxLengths();
|
||||
|
||||
// Hidden element to indicate whether the show is new or
|
||||
// whether we are updating an existing show.
|
||||
$this->addElement('hidden', 'add_show_id', array(
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
|
||||
// Hidden element to indicate the instance id of the show
|
||||
// being edited.
|
||||
$this->addElement('hidden', 'add_show_instance_id', array(
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
|
||||
// Add name element
|
||||
$this->addElement('text', 'add_show_name', array(
|
||||
'label' => _('Name:'),
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'value' => _('Untitled Show'),
|
||||
'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['name'])))
|
||||
));
|
||||
|
||||
// Add URL element
|
||||
$this->addElement('text', 'add_show_url', array(
|
||||
'label' => _('URL:'),
|
||||
'class' => 'input_text',
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['url'])))
|
||||
));
|
||||
|
||||
// Add genre element
|
||||
$this->addElement('text', 'add_show_genre', array(
|
||||
'label' => _('Genre:'),
|
||||
'class' => 'input_text',
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(array('StringLength', false, array(0, $maxLens['genre'])))
|
||||
));
|
||||
|
||||
// Add the description element
|
||||
$this->addElement('textarea', 'add_show_description', array(
|
||||
'label' => _('Description:'),
|
||||
'required' => false,
|
||||
'class' => 'input_text_area',
|
||||
'validators' => array(array('StringLength', false, array(0, $maxLens['description'])))
|
||||
));
|
||||
|
||||
$descText = $this->getElement('add_show_description');
|
||||
|
||||
$descText->setDecorators(array(array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-block.phtml',
|
||||
'class' => 'block-display'
|
||||
))));
|
||||
|
||||
// Add the instance description
|
||||
$this->addElement('textarea', 'add_show_instance_description', array(
|
||||
'label' => _('Instance Description:'),
|
||||
'required' => false,
|
||||
'class' => 'input_text_area',
|
||||
'validators' => array(array('StringLength', false, array(0, $maxLens['description'])))
|
||||
));
|
||||
|
||||
$instanceDesc = $this->getElement('add_show_instance_description');
|
||||
|
||||
$instanceDesc->setDecorators(array(array('ViewScript', array(
|
||||
'viewScript' => 'form/add-show-block.phtml',
|
||||
'class' => 'block-display'
|
||||
))));
|
||||
$instanceDesc->setAttrib('disabled','disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the instance description when editing a show instance
|
||||
*/
|
||||
public function enableInstanceDesc()
|
||||
{
|
||||
$el = $this->getElement('add_show_instance_description');
|
||||
Logging::info($el);
|
||||
$el->setAttrib('disabled', null);
|
||||
$el->setAttrib('readonly', null);
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function makeReadonly()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('readonly','readonly');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
396
legacy/application/forms/AddShowWhen.php
Normal file
396
legacy/application/forms/AddShowWhen.php
Normal file
|
@ -0,0 +1,396 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/add-show-when.phtml'))
|
||||
));
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$dateValidator = Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM-DD");
|
||||
$regexValidator = Application_Form_Helper_ValidationTypes::overrideRegexValidator(
|
||||
"/^[0-2]?[0-9]:[0-5][0-9]$/",
|
||||
_("'%value%' does not fit the time format 'HH:mm'"));
|
||||
|
||||
|
||||
// Add start date element
|
||||
$startNow = new Zend_Form_Element_Radio('add_show_start_now');
|
||||
$startNow->setRequired(false)
|
||||
->setLabel(_('Start Time:'))
|
||||
->addMultiOptions(array(
|
||||
'now' => _('Now'),
|
||||
'future' => _('In the Future:')
|
||||
))
|
||||
->setValue('future')
|
||||
->setDecorators(array('ViewHelper'));
|
||||
//$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startNow);
|
||||
|
||||
|
||||
// Add start date element
|
||||
$startDate = new Zend_Form_Element_Text('add_show_start_date');
|
||||
$startDate->class = 'input_text';
|
||||
$startDate->setRequired(true)
|
||||
->setLabel(_('In the Future:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
$notEmptyValidator,
|
||||
$dateValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startDate);
|
||||
|
||||
// Add start time element
|
||||
$startTime = new Zend_Form_Element_Text('add_show_start_time');
|
||||
$startTime->class = 'input_text';
|
||||
$startTime->setRequired(true)
|
||||
->setValue('00:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
$notEmptyValidator,
|
||||
$regexValidator
|
||||
))->setDecorators(array('ViewHelper'));
|
||||
$startTime->setAttrib('alt', 'time');
|
||||
$this->addElement($startTime);
|
||||
|
||||
// Add end date element
|
||||
$endDate = new Zend_Form_Element_Text('add_show_end_date_no_repeat');
|
||||
$endDate->class = 'input_text';
|
||||
$endDate->setRequired(true)
|
||||
->setLabel(_('End Time:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
$notEmptyValidator,
|
||||
$dateValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endDate->setAttrib('alt', 'date');
|
||||
$this->addElement($endDate);
|
||||
|
||||
// Add end time element
|
||||
$endTime = new Zend_Form_Element_Text('add_show_end_time');
|
||||
$endTime->class = 'input_text';
|
||||
$endTime->setRequired(true)
|
||||
->setValue('01:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
$notEmptyValidator,
|
||||
$regexValidator))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endTime->setAttrib('alt', 'time');
|
||||
$this->addElement($endTime);
|
||||
|
||||
// Add duration element
|
||||
$this->addElement('text', 'add_show_duration', array(
|
||||
'label' => _('Duration:'),
|
||||
'class' => 'input_text',
|
||||
'value' => '01h 00m',
|
||||
'readonly' => true,
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
|
||||
$timezone = new Zend_Form_Element_Select('add_show_timezone');
|
||||
$timezone->setRequired(true)
|
||||
->setLabel(_("Timezone:"))
|
||||
->setMultiOptions(Application_Common_Timezone::getTimezones())
|
||||
->setValue(Application_Model_Preference::GetUserTimezone())
|
||||
->setAttrib('class', 'input_select add_show_input_select')
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($timezone);
|
||||
|
||||
// Add repeats element
|
||||
$this->addElement('checkbox', 'add_show_repeats', array(
|
||||
'label' => _('Repeats?'),
|
||||
'required' => false,
|
||||
'decorators' => array('ViewHelper')
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function isWhenFormValid($formData, $validateStartDate, $originalStartDate,
|
||||
$update, $instanceId) {
|
||||
if (parent::isValid($formData)) {
|
||||
return self::checkReliantFields($formData, $validateStartDate,
|
||||
$originalStartDate, $update, $instanceId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkReliantFields($formData, $validateStartDate, $originalStartDate=null, $update=false, $instanceId=null)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
||||
$end_time = $formData['add_show_end_date_no_repeat']." ".$formData['add_show_end_time'];
|
||||
|
||||
//have to use the timezone the user has entered in the form to check past/present
|
||||
$showTimezone = new DateTimeZone($formData["add_show_timezone"]);
|
||||
$nowDateTime = new DateTime("now", $showTimezone);
|
||||
$showStartDateTime = new DateTime($start_time, $showTimezone);
|
||||
$showEndDateTime = new DateTime($end_time, $showTimezone);
|
||||
|
||||
if ($validateStartDate && ($formData['add_show_start_now'] != "now")) {
|
||||
if ($showStartDateTime < $nowDateTime) {
|
||||
$this->getElement('add_show_start_time')->setErrors(array(_('Cannot create show in the past')));
|
||||
$valid = false;
|
||||
}
|
||||
// if edit action, check if original show start time is in the past. CC-3864
|
||||
if ($originalStartDate) {
|
||||
if ($originalStartDate < $nowDateTime) {
|
||||
$this->getElement('add_show_start_time')->setValue($originalStartDate->format("H:i"));
|
||||
$this->getElement('add_show_start_date')->setValue($originalStartDate->format("Y-m-d"));
|
||||
$this->getElement('add_show_start_time')->setErrors(array(_('Cannot modify start date/time of the show that is already started')));
|
||||
$this->disableStartDateAndTime();
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if end time is in the past, return error
|
||||
if ($showEndDateTime < $nowDateTime) {
|
||||
$this->getElement('add_show_end_time')->setErrors(array(_('End date/time cannot be in the past')));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
//validate duration.
|
||||
$duration = $showStartDateTime->diff($showEndDateTime);
|
||||
|
||||
if ($showStartDateTime > $showEndDateTime) {
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot have duration < 0m')));
|
||||
$valid = false;
|
||||
}
|
||||
else if ($showStartDateTime == $showEndDateTime) {
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot have duration 00h 00m')));
|
||||
$valid = false;
|
||||
}
|
||||
else if (intval($duration->format('%d')) > 0 &&
|
||||
(intval($duration->format('%h')) > 0
|
||||
|| intval($duration->format('%i')) > 0
|
||||
|| intval($duration->format('%s')) > 0)) {
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot have duration greater than 24h')));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
|
||||
/* We need to know the show duration broken down into hours and minutes
|
||||
* They are used for checking overlapping shows and for validating
|
||||
* rebroadcast instances
|
||||
*/
|
||||
$hours = $duration->format("%h");
|
||||
$minutes = $duration->format("%i");
|
||||
|
||||
/* Check if show is overlapping
|
||||
* We will only do this check if the show is valid
|
||||
* upto this point
|
||||
*/
|
||||
if ($valid) {
|
||||
//we need to know the start day of the week in show's local timezome
|
||||
$startDow = $showStartDateTime->format("w");
|
||||
|
||||
$utc = new DateTimeZone('UTC');
|
||||
$showStartDateTime->setTimezone($utc);
|
||||
$showEndDateTime->setTimezone($utc);
|
||||
|
||||
if ($formData["add_show_repeats"]) {
|
||||
|
||||
//get repeating show end date
|
||||
if ($formData["add_show_no_end"]) {
|
||||
$date = Application_Model_Preference::GetShowsPopulatedUntil();
|
||||
|
||||
if (is_null($date)) {
|
||||
$populateUntilDateTime = new DateTime("now", $utc);
|
||||
Application_Model_Preference::SetShowsPopulatedUntil($populateUntilDateTime);
|
||||
} else {
|
||||
$populateUntilDateTime = clone $date;
|
||||
}
|
||||
|
||||
} elseif (!$formData["add_show_no_end"]) {
|
||||
$popUntil = $formData["add_show_end_date"]." ".$formData["add_show_end_time"];
|
||||
$populateUntilDateTime = new DateTime($popUntil, $showTimezone);
|
||||
$populateUntilDateTime->setTimezone($utc);
|
||||
}
|
||||
|
||||
//get repeat interval
|
||||
if ($formData["add_show_repeat_type"] == 0) {
|
||||
$interval = 'P7D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 1) {
|
||||
$interval = 'P14D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 4) {
|
||||
$interval = 'P21D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 5) {
|
||||
$interval = 'P28D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 2) {
|
||||
$interval = 'P1M';
|
||||
} elseif ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 3) {
|
||||
list($weekNumberOfMonth, $dayOfWeek) =
|
||||
Application_Service_ShowService::getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime($start_time, $showTimezone));
|
||||
}
|
||||
|
||||
/* Check first show
|
||||
* Continue if the first show does not overlap
|
||||
*/
|
||||
if ($update) {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$showStartDateTime, $showEndDateTime, $update, null, $formData["add_show_id"]);
|
||||
} else {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$showStartDateTime, $showEndDateTime);
|
||||
}
|
||||
|
||||
/* Check if repeats overlap with previously scheduled shows
|
||||
* Do this for each show day
|
||||
*/
|
||||
if (!$overlapping) {
|
||||
|
||||
if (!isset($formData['add_show_day_check'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($formData["add_show_day_check"] as $day) {
|
||||
$repeatShowStart = clone $showStartDateTime;
|
||||
$repeatShowEnd = clone $showEndDateTime;
|
||||
$daysAdd=0;
|
||||
if ($startDow !== $day) {
|
||||
if ($startDow > $day)
|
||||
$daysAdd = 6 - $startDow + 1 + $day;
|
||||
else
|
||||
$daysAdd = $day - $startDow;
|
||||
|
||||
/* In case we are crossing daylights saving time we need
|
||||
* to convert show start and show end to local time before
|
||||
* adding the interval for the next repeating show
|
||||
*/
|
||||
$repeatShowStart->setTimezone($showTimezone);
|
||||
$repeatShowEnd->setTimezone($showTimezone);
|
||||
$repeatShowStart->add(new DateInterval("P".$daysAdd."D"));
|
||||
$repeatShowEnd->add(new DateInterval("P".$daysAdd."D"));
|
||||
//set back to UTC
|
||||
$repeatShowStart->setTimezone($utc);
|
||||
$repeatShowEnd->setTimezone($utc);
|
||||
}
|
||||
/* Here we are checking each repeating show by
|
||||
* the show day.
|
||||
* (i.e: every wednesday, then every thursday, etc.)
|
||||
*/
|
||||
while ($repeatShowStart->getTimestamp() < $populateUntilDateTime->getTimestamp()) {
|
||||
if ($formData['add_show_id'] == -1) {
|
||||
//this is a new show
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$repeatShowStart, $repeatShowEnd);
|
||||
} else {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$repeatShowStart, $repeatShowEnd, $update, null, $formData["add_show_id"]);
|
||||
}
|
||||
|
||||
if ($overlapping) {
|
||||
$valid = false;
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows')));
|
||||
break 1;
|
||||
} else {
|
||||
if ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 3) {
|
||||
$monthlyWeeklyStart = new DateTime($repeatShowStart->format("Y-m"),
|
||||
new DateTimeZone("UTC"));
|
||||
$monthlyWeeklyStart->add(new DateInterval("P1M"));
|
||||
$repeatShowStart = clone Application_Service_ShowService::getNextMonthlyWeeklyRepeatDate(
|
||||
$monthlyWeeklyStart,
|
||||
$formData["add_show_timezone"],
|
||||
$formData['add_show_start_time'],
|
||||
$weekNumberOfMonth,
|
||||
$dayOfWeek);
|
||||
$repeatShowEnd = clone $repeatShowStart;
|
||||
$repeatShowEnd->add(new DateInterval("PT".$hours."H".$minutes."M"));
|
||||
} else {
|
||||
$repeatShowStart->setTimezone($showTimezone);
|
||||
$repeatShowEnd->setTimezone($showTimezone);
|
||||
$repeatShowStart->add(new DateInterval($interval));
|
||||
$repeatShowEnd->add(new DateInterval($interval));
|
||||
$repeatShowStart->setTimezone($utc);
|
||||
$repeatShowEnd->setTimezone($utc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$valid = false;
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows')));
|
||||
}
|
||||
|
||||
} else {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows($showStartDateTime, $showEndDateTime, $update, $instanceId);
|
||||
if ($overlapping) {
|
||||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows')));
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
public function checkRebroadcastDates($repeatShowStart, $formData, $hours, $minutes, $showEdit=false) {
|
||||
$overlapping = false;
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
if (empty($formData["add_show_rebroadcast_date_".$i])) break;
|
||||
$rebroadcastShowStart = clone $repeatShowStart;
|
||||
/* formData is in local time so we need to set the
|
||||
* show start back to local time
|
||||
*/
|
||||
$rebroadcastShowStart->setTimezone(new DateTimeZone(
|
||||
$formData["add_show_timezone"]));
|
||||
$rebroadcastWhenDays = explode(" ", $formData["add_show_rebroadcast_date_".$i]);
|
||||
$rebroadcastWhenTime = explode(":", $formData["add_show_rebroadcast_time_".$i]);
|
||||
$rebroadcastShowStart->add(new DateInterval("P".$rebroadcastWhenDays[0]."D"));
|
||||
$rebroadcastShowStart->setTime($rebroadcastWhenTime[0], $rebroadcastWhenTime[1]);
|
||||
$rebroadcastShowStart->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
$rebroadcastShowEnd = clone $rebroadcastShowStart;
|
||||
$rebroadcastShowEnd->add(new DateInterval("PT".$hours."H".$minutes."M"));
|
||||
|
||||
if ($showEdit) {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$rebroadcastShowStart, $rebroadcastShowEnd, true, null, $formData['add_show_id']);
|
||||
} else {
|
||||
$overlapping = Application_Model_Schedule::checkOverlappingShows(
|
||||
$rebroadcastShowStart, $rebroadcastShowEnd);
|
||||
}
|
||||
|
||||
if ($overlapping) break;
|
||||
}
|
||||
|
||||
return $overlapping;
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function disableRepeatCheckbox()
|
||||
{
|
||||
$element = $this->getElement('add_show_repeats');
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
|
||||
public function disableStartDateAndTime()
|
||||
{
|
||||
$elements = array($this->getElement('add_show_start_date'), $this->getElement('add_show_start_time'));
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
legacy/application/forms/AddShowWho.php
Normal file
39
legacy/application/forms/AddShowWho.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddShowWho extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
// Add hosts autocomplete
|
||||
$this->addElement('text', 'add_show_hosts_autocomplete', array(
|
||||
'label' => _('Search Users:'),
|
||||
'class' => 'input_text ui-autocomplete-input',
|
||||
'required' => false
|
||||
));
|
||||
|
||||
$options = array();
|
||||
$hosts = Application_Model_User::getHosts();
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$options[$host['index']] = $host['label'];
|
||||
}
|
||||
|
||||
//Add hosts selection
|
||||
$hosts = new Zend_Form_Element_MultiCheckbox('add_show_hosts');
|
||||
$hosts->setLabel(_('DJs:'))
|
||||
->setMultiOptions($options);
|
||||
|
||||
$this->addElement($hosts);
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element->getType() != 'Zend_Form_Element_Hidden') {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
legacy/application/forms/AddTracktype.php
Normal file
79
legacy/application/forms/AddTracktype.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddTracktype extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
|
||||
$this->setAttrib('id', 'tracktype_form');
|
||||
|
||||
$hidden = new Zend_Form_Element_Hidden('tracktype_id');
|
||||
$hidden->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($hidden);
|
||||
|
||||
$this->addElement('hash', 'csrf', array(
|
||||
'salt' => 'unique'
|
||||
));
|
||||
|
||||
$typeName = new Zend_Form_Element_Text('type_name');
|
||||
$typeName->setLabel(_('Type Name:'));
|
||||
$typeName->setAttrib('class', 'input_text');
|
||||
$typeName->addFilter('StringTrim');
|
||||
$this->addElement($typeName);
|
||||
|
||||
$code = new Zend_Form_Element_Text('code');
|
||||
$code->setLabel(_('Code:'));
|
||||
$code->setAttrib('class', 'input_text');
|
||||
$code->setAttrib('style', 'width: 40%');
|
||||
$code->setRequired(true);
|
||||
$code->addValidator($notEmptyValidator);
|
||||
$code->addFilter('StringTrim');
|
||||
$this->addElement($code);
|
||||
|
||||
$description = new Zend_Form_Element_Textarea('description');
|
||||
$description->setLabel(_('Description:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 200))
|
||||
));
|
||||
$description->setAttrib('class', 'input_text');
|
||||
$description->addFilter('StringTrim');
|
||||
$this->addElement($description);
|
||||
|
||||
$visibility = new Zend_Form_Element_Select('visibility');
|
||||
$visibility->setLabel(_('Visibility:'));
|
||||
$visibility->setAttrib('class', 'input_select');
|
||||
$visibility->setAttrib('style', 'width: 40%');
|
||||
$visibility->setMultiOptions(array(
|
||||
"0" => _("Disabled"),
|
||||
"1" => _("Enabled")
|
||||
));
|
||||
//$visibility->getValue();
|
||||
$visibility->setRequired(true);
|
||||
$this->addElement($visibility);
|
||||
|
||||
$saveBtn = new Zend_Form_Element_Button('save_tracktype');
|
||||
$saveBtn->setAttrib('class', 'btn right-floated');
|
||||
$saveBtn->setIgnore(true);
|
||||
$saveBtn->setLabel(_('Save'));
|
||||
$this->addElement($saveBtn);
|
||||
}
|
||||
|
||||
public function validateCode($data)
|
||||
{
|
||||
if (strlen($data['tracktype_id']) == 0) {
|
||||
$count = CcTracktypesQuery::create()->filterByDbCode($data['code'])->count();
|
||||
|
||||
if ($count != 0) {
|
||||
$this->getElement('code')->setErrors(array(_("Code is not unique.")));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
136
legacy/application/forms/AddUser.php
Normal file
136
legacy/application/forms/AddUser.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_AddUser extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
/*
|
||||
$this->addElementPrefixPath('Application_Validate',
|
||||
'../application/validate',
|
||||
'validate');
|
||||
* */
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
|
||||
$notDemoValidator = new Application_Validate_NotDemoValidate();
|
||||
|
||||
$this->setAttrib('id', 'user_form');
|
||||
|
||||
$hidden = new Zend_Form_Element_Hidden('user_id');
|
||||
$hidden->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($hidden);
|
||||
|
||||
$this->addElement('hash', 'csrf', array(
|
||||
'salt' => 'unique'
|
||||
));
|
||||
|
||||
$login = new Zend_Form_Element_Text('login');
|
||||
$login->setLabel(_('Username:'));
|
||||
$login->setAttrib('class', 'input_text');
|
||||
$login->setRequired(true);
|
||||
$login->addValidator($notEmptyValidator);
|
||||
$login->addFilter('StringTrim');
|
||||
//$login->addValidator('UserNameValidate');
|
||||
$this->addElement($login);
|
||||
|
||||
$password = new Zend_Form_Element_Password('password');
|
||||
$password->setLabel(_('Password:'));
|
||||
$password->setAttrib('class', 'input_text');
|
||||
$password->setRequired(true);
|
||||
$password->addFilter('StringTrim');
|
||||
$password->addValidator($notEmptyValidator);
|
||||
$this->addElement($password);
|
||||
|
||||
$passwordVerify = new Zend_Form_Element_Password('passwordVerify');
|
||||
$passwordVerify->setLabel(_('Verify Password:'));
|
||||
$passwordVerify->setAttrib('class', 'input_text');
|
||||
$passwordVerify->setRequired(true);
|
||||
$passwordVerify->addFilter('StringTrim');
|
||||
$passwordVerify->addValidator($notEmptyValidator);
|
||||
$passwordVerify->addValidator($notDemoValidator);
|
||||
$this->addElement($passwordVerify);
|
||||
|
||||
$firstName = new Zend_Form_Element_Text('first_name');
|
||||
$firstName->setLabel(_('Firstname:'));
|
||||
$firstName->setAttrib('class', 'input_text');
|
||||
$firstName->addFilter('StringTrim');
|
||||
$this->addElement($firstName);
|
||||
|
||||
$lastName = new Zend_Form_Element_Text('last_name');
|
||||
$lastName->setLabel(_('Lastname:'));
|
||||
$lastName->setAttrib('class', 'input_text');
|
||||
$lastName->addFilter('StringTrim');
|
||||
$this->addElement($lastName);
|
||||
|
||||
$email = new Zend_Form_Element_Text('email');
|
||||
$email->setLabel(_('Email:'));
|
||||
$email->setAttrib('class', 'input_text');
|
||||
$email->addFilter('StringTrim');
|
||||
$email->setRequired(true);
|
||||
$email->addValidator($notEmptyValidator);
|
||||
$email->addValidator($emailValidator);
|
||||
$this->addElement($email);
|
||||
|
||||
$cellPhone = new Zend_Form_Element_Text('cell_phone');
|
||||
$cellPhone->setLabel(_('Mobile Phone:'));
|
||||
$cellPhone->setAttrib('class', 'input_text');
|
||||
$cellPhone->addFilter('StringTrim');
|
||||
$this->addElement($cellPhone);
|
||||
|
||||
$skype = new Zend_Form_Element_Text('skype');
|
||||
$skype->setLabel(_('Skype:'));
|
||||
$skype->setAttrib('class', 'input_text');
|
||||
$skype->addFilter('StringTrim');
|
||||
$this->addElement($skype);
|
||||
|
||||
$jabber = new Zend_Form_Element_Text('jabber');
|
||||
$jabber->setLabel(_('Jabber:'));
|
||||
$jabber->setAttrib('class', 'input_text');
|
||||
$jabber->addFilter('StringTrim');
|
||||
$jabber->addValidator($emailValidator);
|
||||
$this->addElement($jabber);
|
||||
|
||||
$select = new Zend_Form_Element_Select('type');
|
||||
$select->setLabel(_('User Type:'));
|
||||
$select->setAttrib('class', 'input_select');
|
||||
$select->setAttrib('style', 'width: 40%');
|
||||
$select->setMultiOptions(array(
|
||||
"G" => _("Guest"),
|
||||
"H" => _("DJ"),
|
||||
"P" => _("Program Manager"),
|
||||
"A" => _("Admin"),
|
||||
));
|
||||
$select->setRequired(false);
|
||||
$this->addElement($select);
|
||||
|
||||
$saveBtn = new Zend_Form_Element_Button('save_user');
|
||||
$saveBtn->setAttrib('class', 'btn right-floated');
|
||||
$saveBtn->setIgnore(true);
|
||||
$saveBtn->setLabel(_('Save'));
|
||||
$this->addElement($saveBtn);
|
||||
}
|
||||
|
||||
public function validateLogin($data)
|
||||
{
|
||||
if (strlen($data['user_id']) == 0) {
|
||||
$count = CcSubjsQuery::create()->filterByDbLogin($data['login'])->count();
|
||||
|
||||
if ($count != 0) {
|
||||
$this->getElement('login')->setErrors(array(_("Login name is not unique.")));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// We need to add the password identical validator here in case
|
||||
// Zend version is less than 1.10.5
|
||||
public function isValid($data) {
|
||||
$passwordIdenticalValidator = Application_Form_Helper_ValidationTypes::overridePasswordIdenticalValidator(
|
||||
$data['password']);
|
||||
$this->getElement('passwordVerify')->addValidator($passwordIdenticalValidator);
|
||||
return parent::isValid($data);
|
||||
}
|
||||
}
|
21
legacy/application/forms/DangerousPreferences.php
Normal file
21
legacy/application/forms/DangerousPreferences.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_DangerousPreferences extends Zend_Form_SubForm {
|
||||
|
||||
public function init() {
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences_danger.phtml'))
|
||||
));
|
||||
|
||||
$clearLibrary = new Zend_Form_Element_Button('clear_library');
|
||||
$clearLibrary->setLabel(_('Delete All Tracks in Library'));
|
||||
//$submit->removeDecorator('Label');
|
||||
$clearLibrary->setAttribs(array('class'=>'btn centered'));
|
||||
$clearLibrary->setAttrib('onclick', 'deleteAllFiles();');
|
||||
$clearLibrary->removeDecorator('DtDdWrapper');
|
||||
|
||||
$this->addElement($clearLibrary);
|
||||
}
|
||||
|
||||
}
|
68
legacy/application/forms/DateRange.php
Normal file
68
legacy/application/forms/DateRange.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_DateRange extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/daterange.phtml'))
|
||||
));
|
||||
|
||||
// Add start date element
|
||||
$startDate = new Zend_Form_Element_Text('his_date_start');
|
||||
$startDate->class = 'input_text';
|
||||
$startDate->setRequired(true)
|
||||
->setLabel(_('Date Start:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startDate);
|
||||
|
||||
// Add start time element
|
||||
$startTime = new Zend_Form_Element_Text('his_time_start');
|
||||
$startTime->class = 'input_text';
|
||||
$startTime->setRequired(true)
|
||||
->setValue('00:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startTime->setAttrib('alt', 'time');
|
||||
$this->addElement($startTime);
|
||||
|
||||
// Add end date element
|
||||
$endDate = new Zend_Form_Element_Text('his_date_end');
|
||||
$endDate->class = 'input_text';
|
||||
$endDate->setRequired(true)
|
||||
->setLabel(_('Date End:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endDate->setAttrib('alt', 'date');
|
||||
$this->addElement($endDate);
|
||||
|
||||
// Add end time element
|
||||
$endTime = new Zend_Form_Element_Text('his_time_end');
|
||||
$endTime->class = 'input_text';
|
||||
$endTime->setRequired(true)
|
||||
->setValue('01:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endTime->setAttrib('alt', 'time');
|
||||
$this->addElement($endTime);
|
||||
}
|
||||
}
|
318
legacy/application/forms/EditAudioMD.php
Normal file
318
legacy/application/forms/EditAudioMD.php
Normal file
|
@ -0,0 +1,318 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_EditAudioMD extends Zend_Form
|
||||
{
|
||||
|
||||
public function init() {}
|
||||
|
||||
public function startForm($p_id)
|
||||
{
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
// Set the method for the display form to POST
|
||||
$this->setMethod('post');
|
||||
|
||||
$file_id = new Zend_Form_Element_Hidden('file_id');
|
||||
$file_id->setValue($p_id);
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'obj_id');
|
||||
$this->addElement($file_id);
|
||||
|
||||
// Add artwork hidden field
|
||||
$artwork = new Zend_Form_Element_Hidden('artwork');
|
||||
$artwork->class = 'input_text artwork_'. $p_id;
|
||||
$artwork->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 2048))
|
||||
));
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'artwork');
|
||||
$this->addElement($artwork);
|
||||
|
||||
// Set artwork hidden field
|
||||
$set_artwork = new Zend_Form_Element_Hidden('set_artwork');
|
||||
$set_artwork->class = 'input_text set_artwork_'. $p_id;
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'set_artwork');
|
||||
$this->addElement($set_artwork);
|
||||
|
||||
// Remove artwork hidden field
|
||||
$remove_artwork = new Zend_Form_Element_Hidden('remove_artwork');
|
||||
$remove_artwork->class = 'input_text remove_artwork_'. $p_id;
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'remove_artwork');
|
||||
$this->addElement($remove_artwork);
|
||||
|
||||
// Add title field
|
||||
$track_title = new Zend_Form_Element_Text('track_title');
|
||||
$track_title->class = 'input_text';
|
||||
$track_title->setLabel(_('Title:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($track_title);
|
||||
|
||||
// Add artist field
|
||||
$artist_name = new Zend_Form_Element_Text('artist_name');
|
||||
$artist_name->class = 'input_text';
|
||||
$artist_name->setLabel(_('Creator:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($artist_name);
|
||||
|
||||
// Add album field
|
||||
$album_title = new Zend_Form_Element_Text('album_title');
|
||||
$album_title->class = 'input_text';
|
||||
$album_title->setLabel(_('Album:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($album_title);
|
||||
|
||||
|
||||
// Add album field
|
||||
$user_options = array();
|
||||
$users = Application_Model_User::getNonGuestUsers();
|
||||
|
||||
foreach ($users as $host) {
|
||||
$user_options[$host['index']] = $host['label'];
|
||||
}
|
||||
|
||||
$owner_id = new Zend_Form_Element_Select('owner_id');
|
||||
$owner_id->class = 'input_text';
|
||||
$owner_id->setLabel(_('Owner:'));
|
||||
$owner_id->setMultiOptions($user_options);
|
||||
$this->addelement($owner_id);
|
||||
|
||||
// Add track type dropdown
|
||||
$track_type_options = array();
|
||||
$track_types = Application_Model_Tracktype::getTracktypes();
|
||||
|
||||
array_multisort(array_map(function($element) {
|
||||
return $element['type_name'];
|
||||
}, $track_types), SORT_ASC, $track_types);
|
||||
|
||||
$track_type_options[""] = _('Select a Type');
|
||||
foreach ($track_types as $key => $tt) {
|
||||
$track_type_options[$tt['code']] = $tt['type_name'];
|
||||
}
|
||||
|
||||
$track_type = new Zend_Form_Element_Select('track_type');
|
||||
$track_type->class = 'input_text';
|
||||
$track_type->setLabel(_('Track Type:'));
|
||||
$track_type->setMultiOptions($track_type_options);
|
||||
$this->addelement($track_type);
|
||||
|
||||
// Description field
|
||||
$description = new Zend_Form_Element_Textarea('description');
|
||||
$description->class = 'input_text';
|
||||
$description->setLabel(_('Description:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($description);
|
||||
|
||||
// Add track number field
|
||||
$track_number = new Zend_Form_Element('track_number');
|
||||
$track_number->class = 'input_text';
|
||||
$track_number->setLabel('Track Number:')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(new Zend_Validate_Int()));
|
||||
$this->addElement($track_number);
|
||||
|
||||
// Add genre field
|
||||
$genre = new Zend_Form_Element('genre');
|
||||
$genre->class = 'input_text';
|
||||
$genre->setLabel(_('Genre:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 64))
|
||||
));
|
||||
$this->addElement($genre);
|
||||
|
||||
// Add year field
|
||||
$year = new Zend_Form_Element_Text('year');
|
||||
$year->class = 'input_text';
|
||||
$year->setLabel(_('Year:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 10)),
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM-DD"),
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM"),
|
||||
Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY")
|
||||
));
|
||||
$this->addElement($year);
|
||||
|
||||
// Add label field
|
||||
$label = new Zend_Form_Element('label');
|
||||
$label->class = 'input_text';
|
||||
$label->setLabel(_('Label:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($label);
|
||||
|
||||
// Add composer field
|
||||
$composer = new Zend_Form_Element('composer');
|
||||
$composer->class = 'input_text';
|
||||
$composer->setLabel(_('Composer:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($composer);
|
||||
|
||||
// Add conductor field
|
||||
$conductor = new Zend_Form_Element('conductor');
|
||||
$conductor->class = 'input_text';
|
||||
$conductor->setLabel(_('Conductor:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($conductor);
|
||||
|
||||
// Add mood field
|
||||
$mood = new Zend_Form_Element('mood');
|
||||
$mood->class = 'input_text';
|
||||
$mood->setLabel(_('Mood:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 64))
|
||||
));
|
||||
$this->addElement($mood);
|
||||
|
||||
// Add bmp field
|
||||
$bpm = new Zend_Form_Element_Text('bpm');
|
||||
$bpm->class = 'input_text';
|
||||
$bpm->setLabel(_('BPM:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('min'=>0,'max' => 8)),
|
||||
new Zend_Validate_Digits()));
|
||||
$this->addElement($bpm);
|
||||
|
||||
// Add copyright field
|
||||
$copyright = new Zend_Form_Element('copyright');
|
||||
$copyright->class = 'input_text';
|
||||
$copyright->setLabel(_('Copyright:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($copyright);
|
||||
|
||||
// Add isrc number field
|
||||
$isrc_number = new Zend_Form_Element('isrc_number');
|
||||
$isrc_number->class = 'input_text';
|
||||
$isrc_number->setLabel(_('ISRC Number:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($isrc_number);
|
||||
|
||||
// Add website field
|
||||
$info_url = new Zend_Form_Element('info_url');
|
||||
$info_url->class = 'input_text';
|
||||
$info_url->setLabel(_('Website:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($info_url);
|
||||
|
||||
// Add language field
|
||||
$language = new Zend_Form_Element('language');
|
||||
$language->class = 'input_text';
|
||||
$language->setLabel(_('Language:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($language);
|
||||
|
||||
$validCuePattern = '/^(?:[0-9]{1,2}:)?(?:[0-9]{1,2}:)?[0-9]{1,6}(\.\d{1,6})?$/';
|
||||
|
||||
$cueIn = new Zend_Form_Element_Text('cuein');
|
||||
$cueIn->class = 'input_text';
|
||||
$cueIn->setLabel("Cue In:");
|
||||
$cueInValidator = Application_Form_Helper_ValidationTypes::overrideRegexValidator(
|
||||
$validCuePattern, _(sprintf("Specify cue in time in the format %s", "(hh:mm:)ss(.dddddd)"))
|
||||
);
|
||||
$cueIn->setValidators(array($cueInValidator));
|
||||
$this->addElement($cueIn);
|
||||
|
||||
$cueOut = new Zend_Form_Element_Text('cueout');
|
||||
$cueOut->class = 'input_text';
|
||||
$cueOut->setLabel('Cue Out:');
|
||||
$cueOutValidator = Application_Form_Helper_ValidationTypes::overrideRegexValidator(
|
||||
$validCuePattern, _(sprintf("Specify cue out time in the format %s", "(hh:mm:)ss(.dddddd)"))
|
||||
);
|
||||
$cueOut->setValidators(array($cueOutValidator));
|
||||
$this->addElement($cueOut);
|
||||
|
||||
// Add the cancel button
|
||||
$this->addElement('button', 'editmdcancel', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn md-cancel',
|
||||
'label' => _('Cancel'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('button', 'editmdsave', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn md-save',
|
||||
'label' => _('Save'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
// Button to open the publish dialog
|
||||
$this->addElement('button', 'publishdialog', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn md-publish',
|
||||
'label' => _('Publish...'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addDisplayGroup(array('publishdialog', 'editmdsave', 'editmdcancel'), 'submitButtons', array(
|
||||
'decorators' => array(
|
||||
'FormElements',
|
||||
'DtDdWrapper'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function makeReadOnly()
|
||||
{
|
||||
foreach ($this as $element) {
|
||||
$element->setAttrib('readonly', 'readonly');
|
||||
}
|
||||
}
|
||||
|
||||
public function removeOwnerEdit() {
|
||||
$this->removeElement('owner_id');
|
||||
}
|
||||
public function removeActionButtons()
|
||||
{
|
||||
$this->removeElement('editmdsave');
|
||||
$this->removeElement('editmdcancel');
|
||||
}
|
||||
|
||||
}
|
211
legacy/application/forms/EditHistory.php
Normal file
211
legacy/application/forms/EditHistory.php
Normal file
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_EditHistory extends Zend_Form
|
||||
{
|
||||
const VALIDATE_DATETIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
||||
//this is used by the javascript widget, unfortunately h/H is opposite from Zend.
|
||||
const TIMEPICKER_DATETIME_FORMAT = 'yyyy-MM-dd hh:mm:ss';
|
||||
|
||||
const VALIDATE_DATE_FORMAT = 'yyyy-MM-dd';
|
||||
const VALIDATE_TIME_FORMAT = 'HH:mm:ss';
|
||||
|
||||
const ITEM_TYPE = "type";
|
||||
const ITEM_CLASS = "class";
|
||||
const ITEM_OPTIONS = "options";
|
||||
const ITEM_ID_SUFFIX = "name";
|
||||
|
||||
const TEXT_INPUT_CLASS = "input_text";
|
||||
|
||||
private $formElTypes = array(
|
||||
TEMPLATE_DATE => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_Date",
|
||||
"params" => array(
|
||||
"format" => self::VALIDATE_DATE_FORMAT
|
||||
)
|
||||
)
|
||||
),
|
||||
"filters" => array(
|
||||
"StringTrim"
|
||||
)
|
||||
),
|
||||
TEMPLATE_TIME => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_Date",
|
||||
"params" => array(
|
||||
"format" => self::VALIDATE_TIME_FORMAT
|
||||
)
|
||||
)
|
||||
),
|
||||
"filters" => array(
|
||||
"StringTrim"
|
||||
)
|
||||
),
|
||||
TEMPLATE_DATETIME => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_Date",
|
||||
"params" => array(
|
||||
"format" => self::VALIDATE_DATETIME_FORMAT
|
||||
)
|
||||
)
|
||||
),
|
||||
"filters" => array(
|
||||
"StringTrim"
|
||||
)
|
||||
),
|
||||
TEMPLATE_STRING => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"filters" => array(
|
||||
"StringTrim"
|
||||
)
|
||||
),
|
||||
TEMPLATE_BOOLEAN => array(
|
||||
"class" => "Zend_Form_Element_Checkbox",
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_InArray",
|
||||
"options" => array(
|
||||
"haystack" => array(0,1)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
TEMPLATE_INT => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_Int",
|
||||
)
|
||||
),
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
)
|
||||
),
|
||||
TEMPLATE_FLOAT => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
"class" => "Zend_Validate_Float",
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
public function init() {
|
||||
|
||||
$history_id = new Zend_Form_Element_Hidden($this::ID_PREFIX.'id');
|
||||
$history_id->setValidators(array(
|
||||
new Zend_Validate_Int()
|
||||
));
|
||||
$history_id->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($history_id);
|
||||
|
||||
$dynamic_attrs = new Zend_Form_SubForm();
|
||||
$this->addSubForm($dynamic_attrs, $this::ID_PREFIX.'template');
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('button', $this::ID_PREFIX.'save', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn '.$this::ID_PREFIX.'save',
|
||||
'label' => _('Save'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
// Add the cancel button
|
||||
$this->addElement('button', $this::ID_PREFIX.'cancel', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn '.$this::ID_PREFIX.'cancel',
|
||||
'label' => _('Cancel'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function createFromTemplate($template, $required) {
|
||||
|
||||
$templateSubForm = $this->getSubForm($this::ID_PREFIX.'template');
|
||||
|
||||
for ($i = 0, $len = count($template); $i < $len; $i++) {
|
||||
|
||||
$item = $template[$i];
|
||||
//don't dynamically add this as it should be included in the
|
||||
//init() function already if it should show up in the UI..
|
||||
if (in_array($item["name"], $required)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$formElType = $this->formElTypes[$item[self::ITEM_TYPE]];
|
||||
|
||||
$label = $item[self::ITEM_ID_SUFFIX];
|
||||
$id = $this::ID_PREFIX.$label;
|
||||
$el = new $formElType[self::ITEM_CLASS]($id);
|
||||
$el->setLabel($item["label"]);
|
||||
|
||||
if (isset($formElType["attrs"])) {
|
||||
|
||||
$attrs = $formElType["attrs"];
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
$el->setAttrib($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formElType["filters"])) {
|
||||
|
||||
$filters = $formElType["filters"];
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
$el->addFilter($filter);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($formElType["validators"])) {
|
||||
|
||||
$validators = $formElType["validators"];
|
||||
|
||||
foreach ($validators as $index => $arr) {
|
||||
$options = isset($arr[self::ITEM_OPTIONS]) ? $arr[self::ITEM_OPTIONS] : null;
|
||||
$validator = new $arr[self::ITEM_CLASS]($options);
|
||||
|
||||
//extra validator info
|
||||
if (isset($arr["params"])) {
|
||||
|
||||
foreach ($arr["params"] as $key => $value) {
|
||||
$method = "set".ucfirst($key);
|
||||
$validator->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
$el->addValidator($validator);
|
||||
}
|
||||
}
|
||||
|
||||
$el->setDecorators(array('ViewHelper'));
|
||||
$templateSubForm->addElement($el);
|
||||
}
|
||||
}
|
||||
}
|
22
legacy/application/forms/EditHistoryFile.php
Normal file
22
legacy/application/forms/EditHistoryFile.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_EditHistoryFile extends Application_Form_EditHistory
|
||||
{
|
||||
const ID_PREFIX = "his_file_";
|
||||
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
$this->setDecorators(
|
||||
array(
|
||||
array('ViewScript', array('viewScript' => 'form/edit-history-file.phtml'))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function createFromTemplate($template, $required) {
|
||||
|
||||
parent::createFromTemplate($template, $required);
|
||||
}
|
||||
}
|
66
legacy/application/forms/EditHistoryItem.php
Normal file
66
legacy/application/forms/EditHistoryItem.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_EditHistoryItem extends Application_Form_EditHistory
|
||||
{
|
||||
const ID_PREFIX = "his_item_";
|
||||
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
$this->setDecorators(array(
|
||||
'PrepareElements',
|
||||
array('ViewScript', array('viewScript' => 'form/edit-history-item.phtml'))
|
||||
));
|
||||
|
||||
/*
|
||||
$instance = new Zend_Form_Element_Select("instance_id");
|
||||
$instance->setLabel(_("Choose Show Instance"));
|
||||
$instance->setMultiOptions(array("0" => "-----------"));
|
||||
$instance->setValue(0);
|
||||
$instance->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($instance);
|
||||
*/
|
||||
|
||||
$starts = new Zend_Form_Element_Text(self::ID_PREFIX.'starts');
|
||||
$starts->setValidators(array(
|
||||
new Zend_Validate_Date(self::VALIDATE_DATETIME_FORMAT)
|
||||
));
|
||||
$starts->setAttrib('class', self::TEXT_INPUT_CLASS." datepicker");
|
||||
$starts->setAttrib('data-format', self::TIMEPICKER_DATETIME_FORMAT);
|
||||
$starts->addFilter('StringTrim');
|
||||
$starts->setLabel(_('Start Time'));
|
||||
$starts->setDecorators(array('ViewHelper'));
|
||||
$starts->setRequired(true);
|
||||
$this->addElement($starts);
|
||||
|
||||
$ends = new Zend_Form_Element_Text(self::ID_PREFIX.'ends');
|
||||
$ends->setValidators(array(
|
||||
new Zend_Validate_Date(self::VALIDATE_DATETIME_FORMAT)
|
||||
));
|
||||
$ends->setAttrib('class', self::TEXT_INPUT_CLASS." datepicker");
|
||||
$ends->setAttrib('data-format', self::TIMEPICKER_DATETIME_FORMAT);
|
||||
$ends->addFilter('StringTrim');
|
||||
$ends->setLabel(_('End Time'));
|
||||
$ends->setDecorators(array('ViewHelper'));
|
||||
//$ends->setRequired(true);
|
||||
$this->addElement($ends);
|
||||
}
|
||||
|
||||
public function createFromTemplate($template, $required) {
|
||||
|
||||
parent::createFromTemplate($template, $required);
|
||||
}
|
||||
|
||||
public function populateShowInstances($possibleInstances, $default) {
|
||||
|
||||
$possibleInstances["0"] = _("No Show");
|
||||
|
||||
$instance = new Zend_Form_Element_Select("his_instance_select");
|
||||
//$instance->setLabel(_("Choose Show Instance"));
|
||||
$instance->setMultiOptions($possibleInstances);
|
||||
$instance->setValue($default);
|
||||
$instance->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($instance);
|
||||
}
|
||||
}
|
160
legacy/application/forms/EditUser.php
Normal file
160
legacy/application/forms/EditUser.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_EditUser extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
/*
|
||||
$this->addElementPrefixPath('Application_Validate',
|
||||
'../application/validate',
|
||||
'validate');
|
||||
* */
|
||||
|
||||
$currentUser = Application_Model_User::getCurrentUser();
|
||||
$currentUserId = $currentUser->getId();
|
||||
$userData = Application_Model_User::GetUserData($currentUserId);
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
|
||||
$notDemoValidator = new Application_Validate_NotDemoValidate();
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/edit-user.phtml', "currentUser" => $currentUser->getLogin()))));
|
||||
$this->setAttrib('id', 'current-user-form');
|
||||
|
||||
$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');
|
||||
$this->addElement($csrf_element);
|
||||
|
||||
$hidden = new Zend_Form_Element_Hidden('cu_user_id');
|
||||
$hidden->setDecorators(array('ViewHelper'));
|
||||
$hidden->setValue($userData["id"]);
|
||||
$this->addElement($hidden);
|
||||
|
||||
$login = new Zend_Form_Element_Text('cu_login');
|
||||
$login->setLabel(_('Username:'));
|
||||
$login->setValue($userData["login"]);
|
||||
$login->setAttrib('class', 'input_text');
|
||||
$login->setAttrib('readonly', 'readonly');
|
||||
$login->setRequired(true);
|
||||
$login->addValidator($notEmptyValidator);
|
||||
$login->addFilter('StringTrim');
|
||||
$login->setDecorators(array('viewHelper'));
|
||||
$this->addElement($login);
|
||||
|
||||
$password = new Zend_Form_Element_Password('cu_password');
|
||||
$password->setLabel(_('Password:'));
|
||||
$password->setAttrib('class', 'input_text');
|
||||
$password->setRequired(true);
|
||||
$password->addFilter('StringTrim');
|
||||
$password->addValidator($notEmptyValidator);
|
||||
$password->setDecorators(array('viewHelper'));
|
||||
$this->addElement($password);
|
||||
|
||||
$passwordVerify = new Zend_Form_Element_Password('cu_passwordVerify');
|
||||
$passwordVerify->setLabel(_('Verify Password:'));
|
||||
$passwordVerify->setAttrib('class', 'input_text');
|
||||
$passwordVerify->setRequired(true);
|
||||
$passwordVerify->addFilter('StringTrim');
|
||||
$passwordVerify->addValidator($notEmptyValidator);
|
||||
$passwordVerify->addValidator($notDemoValidator);
|
||||
$passwordVerify->setDecorators(array('viewHelper'));
|
||||
$this->addElement($passwordVerify);
|
||||
|
||||
$firstName = new Zend_Form_Element_Text('cu_first_name');
|
||||
$firstName->setLabel(_('Firstname:'));
|
||||
$firstName->setValue($userData["first_name"]);
|
||||
$firstName->setAttrib('class', 'input_text');
|
||||
$firstName->addFilter('StringTrim');
|
||||
$firstName->setDecorators(array('viewHelper'));
|
||||
$this->addElement($firstName);
|
||||
|
||||
$lastName = new Zend_Form_Element_Text('cu_last_name');
|
||||
$lastName->setLabel(_('Lastname:'));
|
||||
$lastName->setValue($userData["last_name"]);
|
||||
$lastName->setAttrib('class', 'input_text');
|
||||
$lastName->addFilter('StringTrim');
|
||||
$lastName->setDecorators(array('viewHelper'));
|
||||
$this->addElement($lastName);
|
||||
|
||||
$email = new Zend_Form_Element_Text('cu_email');
|
||||
$email->setLabel(_('Email:'));
|
||||
$email->setValue($userData["email"]);
|
||||
$email->setAttrib('class', 'input_text');
|
||||
$email->addFilter('StringTrim');
|
||||
$email->setRequired(true);
|
||||
$email->addValidator($notEmptyValidator);
|
||||
$email->addValidator($emailValidator);
|
||||
$email->setDecorators(array('viewHelper'));
|
||||
$this->addElement($email);
|
||||
|
||||
$cellPhone = new Zend_Form_Element_Text('cu_cell_phone');
|
||||
$cellPhone->setLabel(_('Mobile Phone:'));
|
||||
$cellPhone->setValue($userData["cell_phone"]);
|
||||
$cellPhone->setAttrib('class', 'input_text');
|
||||
$cellPhone->addFilter('StringTrim');
|
||||
$cellPhone->setDecorators(array('viewHelper'));
|
||||
$this->addElement($cellPhone);
|
||||
|
||||
$skype = new Zend_Form_Element_Text('cu_skype');
|
||||
$skype->setLabel(_('Skype:'));
|
||||
$skype->setValue($userData["skype_contact"]);
|
||||
$skype->setAttrib('class', 'input_text');
|
||||
$skype->addFilter('StringTrim');
|
||||
$skype->setDecorators(array('viewHelper'));
|
||||
$this->addElement($skype);
|
||||
|
||||
$jabber = new Zend_Form_Element_Text('cu_jabber');
|
||||
$jabber->setLabel(_('Jabber:'));
|
||||
$jabber->setValue($userData["jabber_contact"]);
|
||||
$jabber->setAttrib('class', 'input_text');
|
||||
$jabber->addFilter('StringTrim');
|
||||
$jabber->addValidator($emailValidator);
|
||||
$jabber->setDecorators(array('viewHelper'));
|
||||
$this->addElement($jabber);
|
||||
|
||||
$locale = new Zend_Form_Element_Select("cu_locale");
|
||||
$locale->setLabel(_("Language:"));
|
||||
$locale->setMultiOptions(Application_Model_Locale::getLocales());
|
||||
$locale->setValue(Application_Model_Preference::GetUserLocale());
|
||||
$locale->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($locale);
|
||||
|
||||
$stationTz = Application_Model_Preference::GetDefaultTimezone();
|
||||
$userTz = Application_Model_Preference::GetUserTimezone();
|
||||
|
||||
$timezone = new Zend_Form_Element_Select("cu_timezone");
|
||||
$timezone->setLabel(_("Interface Timezone:"));
|
||||
$timezone->setMultiOptions(Application_Common_Timezone::getTimezones());
|
||||
$timezone->setValue($userTz == $stationTz ? null : $userTz);
|
||||
$timezone->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($timezone);
|
||||
}
|
||||
|
||||
public function validateLogin($p_login, $p_userId) {
|
||||
$count = CcSubjsQuery::create()
|
||||
->filterByDbLogin($p_login)
|
||||
->filterByDbId($p_userId, Criteria::NOT_EQUAL)
|
||||
->count();
|
||||
|
||||
if ($count != 0) {
|
||||
$this->getElement('cu_login')->setErrors(array(_("Login name is not unique.")));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We need to add the password identical validator here in case
|
||||
// Zend version is less than 1.10.5
|
||||
public function isValid($data)
|
||||
{
|
||||
if (isset($data['cu_password'])) {
|
||||
$passwordIdenticalValidator = Application_Form_Helper_ValidationTypes::overridePasswordIdenticalValidator(
|
||||
$data['cu_password']);
|
||||
$this->getElement('cu_passwordVerify')->addValidator($passwordIdenticalValidator);
|
||||
}
|
||||
return parent::isValid($data);
|
||||
}
|
||||
}
|
244
legacy/application/forms/GeneralPreferences.php
Normal file
244
legacy/application/forms/GeneralPreferences.php
Normal file
|
@ -0,0 +1,244 @@
|
|||
<?php
|
||||
|
||||
// this is not getting loaded by autloading since it has a classname
|
||||
// that makes it clash with how zf1 expects to load plugins.
|
||||
require_once 'customfilters/ImageSize.php';
|
||||
|
||||
class Application_Form_GeneralPreferences extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$maxLens = Application_Model_Show::getMaxLengths();
|
||||
$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
|
||||
|
||||
$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(),
|
||||
));
|
||||
|
||||
// Station description
|
||||
$stationDescription = new Zend_Form_Element_Textarea("stationDescription");
|
||||
$stationDescription->setLabel(_('Station Description'));
|
||||
$stationDescription->setValue(Application_Model_Preference::GetStationDescription());
|
||||
$stationDescription->setRequired(false);
|
||||
$stationDescription->setValidators(array(array('StringLength', false, array(0, $maxLens['description']))));
|
||||
$stationDescription->setAttrib('rows', 4);
|
||||
$this->addElement($stationDescription);
|
||||
|
||||
// Station Logo
|
||||
$stationLogoUpload = new Zend_Form_Element_File('stationLogo');
|
||||
$stationLogoUpload->setLabel(_('Station Logo:'))
|
||||
->setDescription(_("Note: Anything larger than 600x600 will be resized."))
|
||||
->setRequired(false)
|
||||
->addValidator('Count', false, 1)
|
||||
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
|
||||
->setMaxFileSize(1000000)
|
||||
->addFilter('ImageSize');
|
||||
$stationLogoUpload->setAttrib('accept', 'image/*');
|
||||
$this->addElement($stationLogoUpload);
|
||||
|
||||
$stationLogoRemove = new Zend_Form_Element_Button('stationLogoRemove');
|
||||
$stationLogoRemove->setLabel(_('Remove'));
|
||||
$stationLogoRemove->setAttrib('class', 'btn');
|
||||
$stationLogoRemove->setAttrib('id', 'logo-remove-btn');
|
||||
$stationLogoRemove->setAttrib('onclick', 'removeLogo();');
|
||||
$this->addElement($stationLogoRemove);
|
||||
|
||||
//Default station crossfade duration
|
||||
$this->addElement('text', 'stationDefaultCrossfadeDuration', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Default Crossfade Duration (s):'),
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
$rangeValidator,
|
||||
$notEmptyValidator,
|
||||
array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')))
|
||||
),
|
||||
'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(),
|
||||
));
|
||||
|
||||
//Default station fade in
|
||||
$this->addElement('text', 'stationDefaultFadeIn', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Default Fade In (s):'),
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
$rangeValidator,
|
||||
$notEmptyValidator,
|
||||
array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')))
|
||||
),
|
||||
'value' => $defaultFadeIn,
|
||||
));
|
||||
|
||||
//Default station fade out
|
||||
$this->addElement('text', 'stationDefaultFadeOut', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Default Fade Out (s):'),
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
$rangeValidator,
|
||||
$notEmptyValidator,
|
||||
array('regex', false, array('/^[0-9]+(\.\d+)?$/', 'messages' => _('Please enter a time in seconds (eg. 0.5)')))
|
||||
),
|
||||
'value' => $defaultFadeOut,
|
||||
));
|
||||
|
||||
$tracktypeDefault = new Zend_Form_Element_Select("tracktypeDefault");
|
||||
$tracktypeDefault->setLabel(_("Track Type Upload Default"));
|
||||
$tracktypeDefault->setMultiOptions(Application_Model_Library::getTracktypes());
|
||||
$tracktypeDefault->setValue(Application_Model_Preference::GetTrackTypeDefault());
|
||||
$this->addElement($tracktypeDefault);
|
||||
|
||||
// add intro playlist select here
|
||||
$introPlaylistSelect = new Zend_Form_Element_Select("introPlaylistSelect");
|
||||
$introPlaylistSelect->setLabel(_("Intro Autoloading Playlist"));
|
||||
$introPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
|
||||
$introPlaylistSelect->setValue(Application_Model_Preference::GetIntroPlaylist());
|
||||
$this->addElement($introPlaylistSelect);
|
||||
|
||||
$outroPlaylistSelect = new Zend_Form_Element_Select("outroPlaylistSelect");
|
||||
$outroPlaylistSelect->setLabel(_("Outro Autoloading Playlist"));
|
||||
$outroPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
|
||||
$outroPlaylistSelect->setValue(Application_Model_Preference::GetOutroPlaylist());
|
||||
$this->addElement($outroPlaylistSelect);
|
||||
|
||||
$podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride');
|
||||
$podcast_album_override->setLabel(_('Overwrite Podcast Episode Metatags'));
|
||||
$podcast_album_override->setMultiOptions(array(
|
||||
_("Disabled"),
|
||||
_("Enabled"),
|
||||
));
|
||||
$podcast_album_override->setValue(Application_Model_Preference::GetPodcastAlbumOverride());
|
||||
$podcast_album_override->setDescription(_('Enabling this feature will cause podcast episode tracks to have their Artist, Title, and Album metatags set from podcast feed values. Note that enabling this feature is recommended in order to ensure reliable scheduling of episodes via smartblocks.'));
|
||||
$podcast_album_override->setSeparator(' '); //No <br> between radio buttons
|
||||
$podcast_album_override->addDecorator('HtmlTag', array('tag' => 'dd',
|
||||
'id'=>"podcastAlbumOverride-element",
|
||||
'class' => 'radio-inline-list',
|
||||
));
|
||||
$this->addElement($podcast_album_override);
|
||||
|
||||
$podcast_auto_smartblock = new Zend_Form_Element_Radio('podcastAutoSmartblock');
|
||||
$podcast_auto_smartblock->setLabel(_('Generate a smartblock and a playlist upon creation of a new podcast'));
|
||||
$podcast_auto_smartblock->setMultiOptions(array(
|
||||
_("Disabled"),
|
||||
_("Enabled"),
|
||||
));
|
||||
$podcast_auto_smartblock->setValue(Application_Model_Preference::GetPodcastAutoSmartblock());
|
||||
$podcast_auto_smartblock->setDescription(_('If this option is enabled, a new smartblock and playlist matching the newest track of a podcast will be generated immediately upon creation of a new podcast. Note that the "Overwrite Podcast Episode Metatags" feature must also be enabled in order for smartblocks to reliably find episodes.'));
|
||||
$podcast_auto_smartblock->setSeparator(' '); //No <br> between radio buttons
|
||||
$podcast_auto_smartblock->addDecorator('HtmlTag', array('tag' => 'dd',
|
||||
'id'=>"podcastAutoSmartblock-element",
|
||||
'class' => 'radio-inline-list',
|
||||
));
|
||||
$this->addElement($podcast_auto_smartblock);
|
||||
|
||||
//TODO add and insert Podcast Smartblock and Playlist autogenerate options
|
||||
|
||||
$third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
|
||||
$third_party_api->setLabel(_('Public LibreTime API'));
|
||||
$third_party_api->setDescription(_('Required for embeddable schedule widget.'));
|
||||
$third_party_api->setMultiOptions(array(
|
||||
_("Disabled"),
|
||||
_("Enabled"),
|
||||
));
|
||||
$third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi());
|
||||
$third_party_api->setDescription(_('Enabling this feature will allow LibreTime to provide schedule data
|
||||
to external widgets that can be embedded in your website.'));
|
||||
$third_party_api->setSeparator(' '); //No <br> between radio buttons
|
||||
//$third_party_api->addDecorator(new Zend_Form_Decorator_Label(array('tag' => 'dd', 'class' => 'radio-inline-list')));
|
||||
$third_party_api->addDecorator('HtmlTag', array('tag' => 'dd',
|
||||
'id'=>"thirdPartyApi-element",
|
||||
'class' => 'radio-inline-list',
|
||||
));
|
||||
$this->addElement($third_party_api);
|
||||
|
||||
$allowedCorsUrlsValue = Application_Model_Preference::GetAllowedCorsUrls();
|
||||
$allowedCorsUrls = new Zend_Form_Element_Textarea('allowedCorsUrls');
|
||||
$allowedCorsUrls->setLabel(_('Allowed CORS URLs'));
|
||||
$allowedCorsUrls->setDescription(_('Remote URLs that are allowed to access this LibreTime instance in a browser. One URL per line.'));
|
||||
$allowedCorsUrls->setValue($allowedCorsUrlsValue);
|
||||
$this->addElement($allowedCorsUrls);
|
||||
|
||||
$locale = new Zend_Form_Element_Select("locale");
|
||||
$locale->setLabel(_("Default Language"));
|
||||
$locale->setMultiOptions(Application_Model_Locale::getLocales());
|
||||
$locale->setValue(Application_Model_Preference::GetDefaultLocale());
|
||||
$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());
|
||||
$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());
|
||||
$this->addElement($week_start_day);
|
||||
|
||||
$radioPageLoginButton = new Zend_Form_Element_Checkbox("radioPageLoginButton");
|
||||
$radioPageLoginButton->setDecorators(array(
|
||||
'ViewHelper',
|
||||
'Errors',
|
||||
'Label'
|
||||
));
|
||||
$displayRadioPageLoginButtonValue = Application_Model_Preference::getRadioPageDisplayLoginButton();
|
||||
if ($displayRadioPageLoginButtonValue == "") {
|
||||
$displayRadioPageLoginButtonValue = true;
|
||||
}
|
||||
$radioPageLoginButton->addDecorator('Label', array("class" => "enable-tunein"));
|
||||
$radioPageLoginButton->setLabel(_("Display login button on your Radio Page?"));
|
||||
$radioPageLoginButton->setValue($displayRadioPageLoginButtonValue);
|
||||
$this->addElement($radioPageLoginButton);
|
||||
|
||||
$feature_preview_mode = new Zend_Form_Element_Radio('featurePreviewMode');
|
||||
$feature_preview_mode->setLabel(_('Feature Previews'));
|
||||
$feature_preview_mode->setMultiOptions(array(
|
||||
_("Disabled"),
|
||||
_("Enabled"),
|
||||
));
|
||||
$feature_preview_mode->setValue(Application_Model_Preference::GetFeaturePreviewMode());
|
||||
$feature_preview_mode->setDescription(_('Enable this to opt-in to test new features.'));
|
||||
$feature_preview_mode->setSeparator(' '); //No <br> between radio buttons
|
||||
$feature_preview_mode->addDecorator('HtmlTag', array('tag' => 'dd',
|
||||
'id'=>"featurePreviewMode-element",
|
||||
'class' => 'radio-inline-list',
|
||||
));
|
||||
$this->addElement($feature_preview_mode);
|
||||
}
|
||||
|
||||
private function getWeekStartDays()
|
||||
{
|
||||
$days = array(
|
||||
_('Sunday'),
|
||||
_('Monday'),
|
||||
_('Tuesday'),
|
||||
_('Wednesday'),
|
||||
_('Thursday'),
|
||||
_('Friday'),
|
||||
_('Saturday')
|
||||
);
|
||||
|
||||
return $days;
|
||||
}
|
||||
}
|
148
legacy/application/forms/LiveStreamingPreferences.php
Normal file
148
legacy/application/forms/LiveStreamingPreferences.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
||||
|
||||
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml')),
|
||||
));
|
||||
|
||||
// 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());
|
||||
$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());
|
||||
$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('/^\d*(\.\d+)?$/',
|
||||
'messages' => _('Please enter a time in seconds (eg. 0.5)')))
|
||||
->setValue($defaultFade);
|
||||
$this->addElement($transition_fade);
|
||||
|
||||
//Master username
|
||||
$master_username = new Zend_Form_Element_Text('master_username');
|
||||
$master_username->setAttrib('autocomplete', 'off')
|
||||
->setAllowEmpty(true)
|
||||
->setLabel(_('Username:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValue(Application_Model_Preference::GetLiveStreamMasterUsername());
|
||||
$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(_('Password:'))
|
||||
->setFilters(array('StringTrim'));
|
||||
$this->addElement($master_password);
|
||||
|
||||
$masterSourceParams = parse_url(Application_Model_Preference::GetMasterDJSourceConnectionURL());
|
||||
|
||||
// Master source connection url parameters
|
||||
$masterSourceHost = new Zend_Form_Element_Text('master_source_host');
|
||||
$masterSourceHost->setLabel(_('Master Source Host:'))
|
||||
->setAttrib('readonly', true)
|
||||
->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL());
|
||||
$this->addElement($masterSourceHost);
|
||||
|
||||
|
||||
//liquidsoap harbor.input port
|
||||
$betweenValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(1024, 49151);
|
||||
|
||||
$m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
|
||||
|
||||
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
|
||||
$masterSourcePort->setLabel(_('Master Source Port:'))
|
||||
->setValue($m_port)
|
||||
->setValidators(array($betweenValidator))
|
||||
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))));
|
||||
|
||||
$this->addElement($masterSourcePort);
|
||||
|
||||
|
||||
|
||||
$m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
|
||||
$masterSourceMount = new Zend_Form_Element_Text('master_source_mount');
|
||||
$masterSourceMount->setLabel(_('Master Source Mount:'))
|
||||
->setValue($m_mount)
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
|
||||
$this->addElement($masterSourceMount);
|
||||
|
||||
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||
|
||||
// Show source connection url parameters
|
||||
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
|
||||
$showSourceHost->setLabel(_('Show Source Host:'))
|
||||
->setAttrib('readonly', true)
|
||||
->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||
$this->addElement($showSourceHost);
|
||||
|
||||
//liquidsoap harbor.input port
|
||||
$l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
|
||||
|
||||
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
|
||||
$showSourcePort->setLabel(_('Show Source Port:'))
|
||||
->setValue($l_port)
|
||||
->setValidators(array($betweenValidator))
|
||||
->addValidator('regex', false, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => _('Only numbers are allowed.'))));
|
||||
$this->addElement($showSourcePort);
|
||||
|
||||
$l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
|
||||
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
|
||||
$showSourceMount->setLabel(_('Show Source Mount:'))
|
||||
->setValue($l_mount)
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
|
||||
$this->addElement($showSourceMount);
|
||||
}
|
||||
|
||||
public function updateVariables()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
|
||||
$masterSourceParams = parse_url(Application_Model_Preference::GetMasterDJSourceConnectionURL());
|
||||
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
|
||||
|
||||
$this->setDecorators(
|
||||
array(
|
||||
array('ViewScript',
|
||||
array(
|
||||
'viewScript' => 'form/preferences_livestream.phtml',
|
||||
'master_source_host' => isset($masterSourceHost) ? Application_Model_Preference::GetMasterDJSourceConnectionURL() : "",
|
||||
'master_source_port' => isset($masterSourcePort) ? Application_Model_StreamSetting::getMasterLiveStreamPort() : "",
|
||||
'master_source_mount' => isset($masterSourceMount) ? Application_Model_StreamSetting::getMasterLiveStreamMountPoint() : "",
|
||||
'show_source_host' => isset($showSourceHost) ? Application_Model_Preference::GetLiveDJSourceConnectionURL() : "",
|
||||
'show_source_port' => isset($showSourcePort) ? Application_Model_StreamSetting::getDjLiveStreamPort() : "",
|
||||
'show_source_mount' => isset($showSourceMount) ? Application_Model_StreamSetting::getDjLiveStreamMountPoint() : "",
|
||||
'isDemo' => $isDemo,
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
111
legacy/application/forms/Login.php
Normal file
111
legacy/application/forms/Login.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_Login extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
// Set the method for the display form to POST
|
||||
$this->setMethod('post');
|
||||
|
||||
//If the request comes from an origin we consider safe, we disable the CSRF
|
||||
//token checking ONLY for the login page.
|
||||
$request = Zend_Controller_Front::getInstance()->getRequest();
|
||||
if ($request) {
|
||||
$refererUrl = $request->getHeader('referer');
|
||||
$originIsSafe = false;
|
||||
foreach (CORSHelper::getAllowedOrigins($request) as $safeOrigin) {
|
||||
if ($this->startsWith($safeOrigin, $refererUrl)) {
|
||||
$originIsSafe = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$originIsSafe) {
|
||||
$this->addElement('hash', 'csrf', array(
|
||||
'salt' => 'unique'
|
||||
));
|
||||
}
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/login.phtml'))
|
||||
));
|
||||
|
||||
// Add username element
|
||||
$username = new Zend_Form_Element_Text("username");
|
||||
$username->setLabel(_('Username:'))
|
||||
->setAttribs(array(
|
||||
'autofocus' => 'true',
|
||||
'class' => 'input_text',
|
||||
'required' => 'true'))
|
||||
->setValue((isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1)?'admin':'')
|
||||
->addFilter('StringTrim')
|
||||
->setDecorators(array('ViewHelper'))
|
||||
->setValidators(array('NotEmpty'));
|
||||
$this->addElement($username);
|
||||
|
||||
// Add password element
|
||||
$this->addElement('password', 'password', array(
|
||||
'label' => _('Password:'),
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'value' => (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1)?'admin':'',
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$locale = new Zend_Form_Element_Select("locale");
|
||||
$locale->setLabel(_("Language:"));
|
||||
$locale->setMultiOptions(Application_Model_Locale::getLocales());
|
||||
$locale->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($locale);
|
||||
$this->setDefaults(array(
|
||||
"locale" => Application_Model_Locale::getUserLocale()
|
||||
));
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('submit', 'submit', array(
|
||||
'ignore' => true,
|
||||
'label' => _('Login'),
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* tests if a string starts with a given string
|
||||
*
|
||||
* This method was pinched as is from phing since it was the only line of code
|
||||
* actually used from phing. I'm not 100% convinced why it was deemed necessary
|
||||
* in the first place as it is a rather simple method in the first place.
|
||||
*
|
||||
* For now it's here as a copy and we can refactor it away completely later.
|
||||
*
|
||||
* @see <https://github.com/phingofficial/phing/blob/41b2f54108018cf69aaa73904fade23e5adfd0cc/classes/phing/util/StringHelper.php>
|
||||
*
|
||||
* @param $check
|
||||
* @param $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function startsWith($check, $string)
|
||||
{
|
||||
if ($check === "" || $check === $string) {
|
||||
return true;
|
||||
} else {
|
||||
return (strpos($string, $check) === 0) ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
51
legacy/application/forms/PasswordChange.php
Normal file
51
legacy/application/forms/PasswordChange.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*/
|
||||
class Application_Form_PasswordChange extends Zend_Form
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/password-change.phtml'))
|
||||
));
|
||||
|
||||
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
|
||||
$stringLengthValidator = Application_Form_Helper_ValidationTypes::overrideStringLengthValidator(6, 80);
|
||||
|
||||
$this->addElement('password', 'password', array(
|
||||
'label' => _('Password'),
|
||||
'required' => true,
|
||||
'filters' => array('stringTrim'),
|
||||
'validators' => array($notEmptyValidator,
|
||||
$stringLengthValidator),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('password', 'password_confirm', array(
|
||||
'label' => _('Confirm new password'),
|
||||
'required' => true,
|
||||
'filters' => array('stringTrim'),
|
||||
'validators' => array(
|
||||
new Zend_Validate_Callback(function ($value, $context) {
|
||||
return $value == $context['password'];
|
||||
}),
|
||||
),
|
||||
'errorMessages' => array(_("Password confirmation does not match your password.")),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('submit', 'submit', array(
|
||||
'label' => _('Save'),
|
||||
'ignore' => true,
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
52
legacy/application/forms/PasswordRestore.php
Normal file
52
legacy/application/forms/PasswordRestore.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*/
|
||||
class Application_Form_PasswordRestore extends Zend_Form
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/password-restore.phtml'))
|
||||
));
|
||||
|
||||
$this->addElement('text', 'email', array(
|
||||
'label' => _('Email'),
|
||||
'required' => true,
|
||||
'filters' => array(
|
||||
'stringTrim',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('text', 'username', array(
|
||||
'label' => _('Username'),
|
||||
'required' => false,
|
||||
'filters' => array(
|
||||
'stringTrim',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('submit', 'submit', array(
|
||||
'label' => _('Reset password'),
|
||||
'ignore' => true,
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$cancel = new Zend_Form_Element_Button("cancel");
|
||||
$cancel->class = 'ui-button ui-widget ui-state-default ui-button-text-only center';
|
||||
$cancel->setLabel(_("Back"))
|
||||
->setIgnore(True)
|
||||
->setAttrib('onclick', 'window.location = ' . Zend_Controller_Front::getInstance()->getBaseUrl('login'))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($cancel);
|
||||
}
|
||||
}
|
87
legacy/application/forms/Player.php
Normal file
87
legacy/application/forms/Player.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
define("OPUS", "opus");
|
||||
|
||||
class Application_Form_Player extends Zend_Form_SubForm
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/player.phtml'))
|
||||
));
|
||||
|
||||
$title = new Zend_Form_Element_Text('player_title');
|
||||
$title->setValue(_('Now Playing'));
|
||||
$title->setLabel(_('Title:'));
|
||||
$title->setDecorators(array(
|
||||
'ViewHelper',
|
||||
'Errors',
|
||||
'Label'
|
||||
));
|
||||
$title->addDecorator('Label', array('class' => 'player-title'));
|
||||
$this->addElement($title);
|
||||
|
||||
$streamMode = new Zend_Form_Element_Radio('player_stream_mode');
|
||||
$streamMode->setLabel(_('Select Stream:'));
|
||||
$streamMode->setMultiOptions(
|
||||
array(
|
||||
"auto" => _("Auto detect the most appropriate stream to use."),
|
||||
"manual" => _("Select a stream:")
|
||||
)
|
||||
);
|
||||
$streamMode->setValue("auto");
|
||||
$this->addElement($streamMode);
|
||||
|
||||
$streamURL = new Zend_Form_Element_Radio('player_stream_url');
|
||||
$opusStreamCount = 0;
|
||||
$urlOptions = Array();
|
||||
foreach(Application_Model_StreamSetting::getEnabledStreamData() as $stream => $data) {
|
||||
$urlOptions[$stream] = strtoupper($data["codec"])." - ".$data["bitrate"]."kbps";
|
||||
if ($data["mobile"]) {
|
||||
$urlOptions[$stream] .= _(" - Mobile friendly");
|
||||
}
|
||||
if ($data["codec"] == OPUS) {
|
||||
$opusStreamCount += 1;
|
||||
$urlOptions[$stream] .= _(" - The player does not support Opus streams.");
|
||||
}
|
||||
}
|
||||
$streamURL->setMultiOptions(
|
||||
$urlOptions
|
||||
);
|
||||
|
||||
// Set default value to the first non-opus stream we find
|
||||
foreach ($urlOptions as $o => $v) {
|
||||
if (strpos(strtolower($v), OPUS) !== false) {
|
||||
continue;
|
||||
} else {
|
||||
$streamURL->setValue($o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$streamURL->setAttrib('numberOfEnabledStreams', sizeof($urlOptions)-$opusStreamCount);
|
||||
$streamURL->removeDecorator('label');
|
||||
$this->addElement($streamURL);
|
||||
|
||||
$embedSrc = new Zend_Form_Element_Textarea('player_embed_src');
|
||||
$embedSrc->setAttrib("readonly", "readonly");
|
||||
$embedSrc->setAttrib("class", "embed-player-text-box");
|
||||
$embedSrc->setAttrib('cols', '40')
|
||||
->setAttrib('rows', '4');
|
||||
$embedSrc->setLabel(_("Embeddable code:"));
|
||||
$embedSrc->setDescription(_("Copy this code and paste it into your website's HTML to embed the player in your site."));
|
||||
$embedSrc->setValue('<iframe frameborder="0" width="280" height="216" src="'.Application_Common_HTTPHelper::getStationUrl().'embed/player?stream=auto&title=Now Playing"></iframe>');
|
||||
$this->addElement($embedSrc);
|
||||
|
||||
$previewLabel = new Zend_Form_Element_Text('player_preview_label');
|
||||
$previewLabel->setLabel(_("Preview:"));
|
||||
$previewLabel->setDecorators(array(
|
||||
'ViewHelper',
|
||||
'Errors',
|
||||
'Label'
|
||||
));
|
||||
$previewLabel->addDecorator('Label', array('class' => 'preview-label'));
|
||||
$this->addElement($previewLabel);
|
||||
|
||||
}
|
||||
}
|
22
legacy/application/forms/PodcastPreferences.php
Normal file
22
legacy/application/forms/PodcastPreferences.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_PodcastPreferences extends Zend_Form_SubForm {
|
||||
|
||||
public function init() {
|
||||
$isPrivate = Application_Model_Preference::getStationPodcastPrivacy();
|
||||
$stationPodcastPrivacy = new Zend_Form_Element_Radio("stationPodcastPrivacy");
|
||||
$stationPodcastPrivacy->setLabel(_('Feed Privacy'));
|
||||
$stationPodcastPrivacy->setMultiOptions(array(
|
||||
_("Public"),
|
||||
_("Private"),
|
||||
));
|
||||
$stationPodcastPrivacy->setSeparator(' ');
|
||||
$stationPodcastPrivacy->addDecorator('HtmlTag', array('tag' => 'dd',
|
||||
'id'=>"stationPodcastPrivacy-element",
|
||||
'class' => 'radio-inline-list',
|
||||
));
|
||||
$stationPodcastPrivacy->setValue($isPrivate);
|
||||
$this->addElement($stationPodcastPrivacy);
|
||||
}
|
||||
|
||||
}
|
44
legacy/application/forms/Preferences.php
Normal file
44
legacy/application/forms/Preferences.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_Preferences extends Zend_Form
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences.phtml'))
|
||||
));
|
||||
|
||||
$general_pref = new Application_Form_GeneralPreferences();
|
||||
|
||||
// $this->addElement('hash', 'csrf', array(
|
||||
// 'salt' => 'unique',
|
||||
// 'decorators' => array(
|
||||
// 'ViewHelper'
|
||||
// )
|
||||
// ));
|
||||
|
||||
$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');
|
||||
$this->addElement($csrf_element);
|
||||
|
||||
$this->addSubForm($general_pref, 'preferences_general');
|
||||
|
||||
//tunein form
|
||||
$tuneinPreferences = new Application_Form_TuneInPreferences();
|
||||
$this->addSubForm($tuneinPreferences, 'preferences_tunein');
|
||||
|
||||
$danger_pref = new Application_Form_DangerousPreferences();
|
||||
$this->addSubForm($danger_pref, 'preferences_danger');
|
||||
|
||||
$submit = new Zend_Form_Element_Submit('submit');
|
||||
$submit->setLabel(_('Save'));
|
||||
//$submit->removeDecorator('Label');
|
||||
$submit->setAttribs(array('class'=>'btn right-floated'));
|
||||
$submit->removeDecorator('DtDdWrapper');
|
||||
|
||||
$this->addElement($submit);
|
||||
}
|
||||
}
|
11
legacy/application/forms/ScheduleShow.php
Normal file
11
legacy/application/forms/ScheduleShow.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_ScheduleShow extends Zend_Form
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
/* Form Elements & Other Definitions Here ... */
|
||||
}
|
||||
|
||||
}
|
28
legacy/application/forms/SetupLanguageTimezone.php
Normal file
28
legacy/application/forms/SetupLanguageTimezone.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_SetupLanguageTimezone extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/setup-lang-timezone.phtml'))));
|
||||
|
||||
$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');
|
||||
$this->addElement($csrf_element);
|
||||
|
||||
$language = new Zend_Form_Element_Select('setup_language');
|
||||
$language->setLabel(_("Station Language"));
|
||||
$language->setMultiOptions(Application_Model_Locale::getLocales());
|
||||
$this->addElement($language);
|
||||
|
||||
$timezone = new Zend_Form_Element_Select('setup_timezone');
|
||||
$timezone->setLabel(_("Station Timezone"));
|
||||
$timezone->setMultiOptions(Application_Common_Timezone::getTimezones());
|
||||
$this->addElement($timezone);
|
||||
}
|
||||
}
|
||||
|
107
legacy/application/forms/ShowBuilder.php
Normal file
107
legacy/application/forms/ShowBuilder.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_ShowBuilder extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/showbuilder.phtml'))
|
||||
));
|
||||
|
||||
// Add start date element
|
||||
$startDate = new Zend_Form_Element_Text('sb_date_start');
|
||||
$startDate->class = 'input_text';
|
||||
$startDate->setRequired(true)
|
||||
->setLabel(_('Date Start:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startDate);
|
||||
|
||||
// Add start time element
|
||||
$startTime = new Zend_Form_Element_Text('sb_time_start');
|
||||
$startTime->class = 'input_text';
|
||||
$startTime->setRequired(true)
|
||||
->setValue('00:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startTime->setAttrib('alt', 'time');
|
||||
$this->addElement($startTime);
|
||||
|
||||
// Add end date element
|
||||
$endDate = new Zend_Form_Element_Text('sb_date_end');
|
||||
$endDate->class = 'input_text';
|
||||
$endDate->setRequired(true)
|
||||
->setLabel(_('Date End:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endDate->setAttrib('alt', 'date');
|
||||
$this->addElement($endDate);
|
||||
|
||||
// Add end time element
|
||||
$endTime = new Zend_Form_Element_Text('sb_time_end');
|
||||
$endTime->class = 'input_text';
|
||||
$endTime->setRequired(true)
|
||||
->setValue('01:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endTime->setAttrib('alt', 'time');
|
||||
$this->addElement($endTime);
|
||||
|
||||
// add a select to choose a show.
|
||||
$showSelect = new Zend_Form_Element_Select("sb_show_filter");
|
||||
$showSelect->setLabel(_("Filter by Show"));
|
||||
$showSelect->setMultiOptions($this->getShowNames());
|
||||
$showSelect->setValue(null);
|
||||
$showSelect->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($showSelect);
|
||||
|
||||
if ($user->getType() === 'H') {
|
||||
$myShows = new Zend_Form_Element_Checkbox('sb_my_shows');
|
||||
$myShows->setLabel(_('All My Shows:'))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($myShows);
|
||||
}
|
||||
}
|
||||
|
||||
private function getShowNames()
|
||||
{
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
$showNames = array("0" => _("Filter by Show"));
|
||||
if ($user->getType() === 'H') {
|
||||
$showNames["-1"] = _("My Shows");
|
||||
}
|
||||
|
||||
$shows = CcShowQuery::create()
|
||||
->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)
|
||||
->orderByDbName()
|
||||
->find();
|
||||
|
||||
foreach ($shows as $show) {
|
||||
|
||||
$showNames[$show->getDbId()] = $show->getDbName();
|
||||
}
|
||||
|
||||
return $showNames;
|
||||
}
|
||||
|
||||
}
|
68
legacy/application/forms/ShowListenerStat.php
Normal file
68
legacy/application/forms/ShowListenerStat.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_ShowListenerStat extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/daterange.phtml'))
|
||||
));
|
||||
|
||||
// Add start date element
|
||||
$startDate = new Zend_Form_Element_Text('his_date_start');
|
||||
$startDate->class = 'input_text';
|
||||
$startDate->setRequired(true)
|
||||
->setLabel(_('Date Start:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startDate->setAttrib('alt', 'date');
|
||||
$this->addElement($startDate);
|
||||
|
||||
// Add start time element
|
||||
$startTime = new Zend_Form_Element_Text('his_time_start');
|
||||
$startTime->class = 'input_text';
|
||||
$startTime->setRequired(true)
|
||||
->setValue('00:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$startTime->setAttrib('alt', 'time');
|
||||
$this->addElement($startTime);
|
||||
|
||||
// Add end date element
|
||||
$endDate = new Zend_Form_Element_Text('his_date_end');
|
||||
$endDate->class = 'input_text';
|
||||
$endDate->setRequired(true)
|
||||
->setLabel(_('Date End:'))
|
||||
->setValue(date("Y-m-d"))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endDate->setAttrib('alt', 'date');
|
||||
$this->addElement($endDate);
|
||||
|
||||
// Add end time element
|
||||
$endTime = new Zend_Form_Element_Text('his_time_end');
|
||||
$endTime->class = 'input_text';
|
||||
$endTime->setRequired(true)
|
||||
->setValue('01:00')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$endTime->setAttrib('alt', 'time');
|
||||
$this->addElement($endTime);
|
||||
}
|
||||
}
|
935
legacy/application/forms/SmartBlockCriteria.php
Normal file
935
legacy/application/forms/SmartBlockCriteria.php
Normal file
|
@ -0,0 +1,935 @@
|
|||
<?php
|
||||
class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
||||
{
|
||||
private $criteriaOptions;
|
||||
private $stringCriteriaOptions;
|
||||
private $numericCriteriaOptions;
|
||||
private $dateTimeCriteriaOptions;
|
||||
private $timePeriodCriteriaOptions;
|
||||
private $sortOptions;
|
||||
private $limitOptions;
|
||||
private $isOrNotCriteriaOptions;
|
||||
private $trackTypeOptions;
|
||||
|
||||
/* We need to know if the criteria value will be a string
|
||||
* or numeric value in order to populate the modifier
|
||||
* select list
|
||||
*/
|
||||
private $criteriaTypes = array(
|
||||
0 => "",
|
||||
"album_title" => "s",
|
||||
"bit_rate" => "n",
|
||||
"bpm" => "n",
|
||||
"composer" => "s",
|
||||
"conductor" => "s",
|
||||
"copyright" => "s",
|
||||
"cuein" => "n",
|
||||
"cueout" => "n",
|
||||
"description" => "s",
|
||||
"artist_name" => "s",
|
||||
"encoded_by" => "s",
|
||||
"utime" => "d",
|
||||
"mtime" => "d",
|
||||
"lptime" => "d",
|
||||
"genre" => "s",
|
||||
"isrc_number" => "s",
|
||||
"label" => "s",
|
||||
"language" => "s",
|
||||
"length" => "n",
|
||||
"mime" => "s",
|
||||
"mood" => "s",
|
||||
"owner_id" => "s",
|
||||
"replay_gain" => "n",
|
||||
"sample_rate" => "n",
|
||||
"track_title" => "s",
|
||||
"track_number" => "n",
|
||||
"info_url" => "s",
|
||||
"year" => "n",
|
||||
"track_type" => "tt"
|
||||
);
|
||||
|
||||
private function getCriteriaOptions($option = null)
|
||||
{
|
||||
if (!isset($this->criteriaOptions)) {
|
||||
$this->criteriaOptions = array(
|
||||
0 => _("Select criteria"),
|
||||
"album_title" => _("Album"),
|
||||
"bit_rate" => _("Bit Rate (Kbps)"),
|
||||
"bpm" => _("BPM"),
|
||||
"composer" => _("Composer"),
|
||||
"conductor" => _("Conductor"),
|
||||
"copyright" => _("Copyright"),
|
||||
"cuein" => _("Cue In"),
|
||||
"cueout" => _("Cue Out"),
|
||||
"description" => _("Description"),
|
||||
"artist_name" => _("Creator"),
|
||||
"encoded_by" => _("Encoded By"),
|
||||
"genre" => _("Genre"),
|
||||
"isrc_number" => _("ISRC"),
|
||||
"label" => _("Label"),
|
||||
"language" => _("Language"),
|
||||
"mtime" => _("Last Modified"),
|
||||
"lptime" => _("Last Played"),
|
||||
"length" => _("Length"),
|
||||
"track_type" => _("Track Type"),
|
||||
"mime" => _("Mime"),
|
||||
"mood" => _("Mood"),
|
||||
"owner_id" => _("Owner"),
|
||||
"replay_gain" => _("Replay Gain"),
|
||||
"sample_rate" => _("Sample Rate (kHz)"),
|
||||
"track_title" => _("Title"),
|
||||
"track_number" => _("Track Number"),
|
||||
"utime" => _("Uploaded"),
|
||||
"info_url" => _("Website"),
|
||||
"year" => _("Year")
|
||||
);
|
||||
}
|
||||
|
||||
if (is_null($option)) return $this->criteriaOptions;
|
||||
else return $this->criteriaOptions[$option];
|
||||
}
|
||||
|
||||
private function getStringCriteriaOptions()
|
||||
{
|
||||
if (!isset($this->stringCriteriaOptions)) {
|
||||
$this->stringCriteriaOptions = array(
|
||||
"0" => _("Select modifier"),
|
||||
"contains" => _("contains"),
|
||||
"does not contain" => _("does not contain"),
|
||||
"is" => _("is"),
|
||||
"is not" => _("is not"),
|
||||
"starts with" => _("starts with"),
|
||||
"ends with" => _("ends with")
|
||||
);
|
||||
}
|
||||
return $this->stringCriteriaOptions;
|
||||
}
|
||||
|
||||
private function getNumericCriteriaOptions()
|
||||
{
|
||||
if (!isset($this->numericCriteriaOptions)) {
|
||||
$this->numericCriteriaOptions = array(
|
||||
"0" => _("Select modifier"),
|
||||
"is" => _("is"),
|
||||
"is not" => _("is not"),
|
||||
"is greater than" => _("is greater than"),
|
||||
"is less than" => _("is less than"),
|
||||
"is in the range" => _("is in the range")
|
||||
);
|
||||
}
|
||||
return $this->numericCriteriaOptions;
|
||||
}
|
||||
|
||||
|
||||
private function getDateTimeCriteriaOptions()
|
||||
{
|
||||
if (!isset($this->dateTimeCriteriaOptions)) {
|
||||
$this->dateTimeCriteriaOptions = array(
|
||||
"0" => _("Select modifier"),
|
||||
"before" => _("before"),
|
||||
"after" => _("after"),
|
||||
"between" => _("between"),
|
||||
"is" => _("is"),
|
||||
"is not" => _("is not"),
|
||||
"is greater than" => _("is greater than"),
|
||||
"is less than" => _("is less than"),
|
||||
"is in the range" => _("is in the range")
|
||||
);
|
||||
}
|
||||
return $this->dateTimeCriteriaOptions;
|
||||
}
|
||||
|
||||
|
||||
private function getTimePeriodCriteriaOptions()
|
||||
{
|
||||
if (!isset($this->timePeriodCriteriaOptions)) {
|
||||
$this->timePeriodCriteriaOptions = array(
|
||||
"0" => _("Select unit of time"),
|
||||
"minute" => _("minute(s)"),
|
||||
"hour" => _("hour(s)"),
|
||||
"day" => _("day(s)"),
|
||||
"week" => _("week(s)"),
|
||||
"month" => _("month(s)"),
|
||||
"year" => _("year(s)")
|
||||
);
|
||||
}
|
||||
return $this->timePeriodCriteriaOptions;
|
||||
}
|
||||
|
||||
|
||||
private function getLimitOptions()
|
||||
{
|
||||
if (!isset($this->limitOptions)) {
|
||||
$this->limitOptions = array(
|
||||
"hours" => _("hours"),
|
||||
"minutes" => _("minutes"),
|
||||
"items" => _("items"),
|
||||
"remaining" => _("time remaining in show")
|
||||
);
|
||||
}
|
||||
return $this->limitOptions;
|
||||
}
|
||||
private function getSortOptions()
|
||||
{
|
||||
if (!isset($this->sortOptions)) {
|
||||
$this->sortOptions = array(
|
||||
"random" => _("Randomly"),
|
||||
"newest" => _("Newest"),
|
||||
"oldest" => _("Oldest"),
|
||||
"mostrecentplay" => _("Most recently played"),
|
||||
"leastrecentplay" => _("Least recently played")
|
||||
);
|
||||
}
|
||||
return $this->sortOptions;
|
||||
}
|
||||
|
||||
private function getIsNotOptions()
|
||||
{
|
||||
if (!isset($this->isOrNotCriteriaOptions)) {
|
||||
$this->isOrNotCriteriaOptions = array(
|
||||
"0" => _("Select modifier"),
|
||||
"is" => _("is"),
|
||||
"is not" => _("is not")
|
||||
);
|
||||
}
|
||||
return $this->isOrNotCriteriaOptions;
|
||||
}
|
||||
|
||||
private function getTracktypeOptions()
|
||||
{
|
||||
if (!isset($this->trackTypeOptions)) {
|
||||
$tracktypes = Application_Model_Tracktype::getTracktypes();
|
||||
$names[] = _("Select Track Type");
|
||||
foreach($tracktypes as $arr => $a){
|
||||
$names[$a["code"]] = $tracktypes[$arr]["type_name"];
|
||||
}
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* converts UTC timestamp citeria into user timezone strings.
|
||||
*/
|
||||
private function convertTimestamps(&$criteria)
|
||||
{
|
||||
$columns = array("utime", "mtime", "lptime");
|
||||
|
||||
foreach ($columns as $column) {
|
||||
|
||||
if (isset($criteria[$column])) {
|
||||
|
||||
foreach ($criteria[$column] as &$constraint) {
|
||||
// convert to appropriate timezone timestamps only if the modifier is not a relative time
|
||||
if (!in_array($constraint['modifier'], array('before','after','between'))) {
|
||||
$constraint['value'] =
|
||||
Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']);
|
||||
if (isset($constraint['extra'])) {
|
||||
$constraint['extra'] =
|
||||
Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function takes a blockID as param and creates the data structure for the form displayed with the view
|
||||
* smart-block-criteria.phtml
|
||||
*
|
||||
* A description of the dataflow. First it loads the block and determines if it is a static or dynamic smartblock.
|
||||
* Next it adds a radio selector for static or dynamic type.
|
||||
* Then it loads the criteria via the getCriteria() function, which returns an array for each criteria.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public function startForm($p_blockId, $p_isValid = false)
|
||||
{
|
||||
// load type
|
||||
$out = CcBlockQuery::create()->findPk($p_blockId);
|
||||
if ($out->getDbType() == "dynamic") {
|
||||
$blockType = 0;
|
||||
} else {
|
||||
$blockType = 1;
|
||||
}
|
||||
|
||||
$spType = new Zend_Form_Element_Radio('sp_type');
|
||||
$spType->setLabel(_('Type:'))
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions(array(
|
||||
'dynamic' => _('Dynamic'),
|
||||
'static' => _('Static')
|
||||
|
||||
))
|
||||
->setValue($blockType);
|
||||
$this->addElement($spType);
|
||||
|
||||
$bl = new Application_Model_Block($p_blockId);
|
||||
$storedCrit = $bl->getCriteriaGrouped();
|
||||
Logging::info($storedCrit);
|
||||
|
||||
//need to convert criteria to be displayed in the user's timezone if there's some timestamp type.
|
||||
self::convertTimestamps($storedCrit["crit"]);
|
||||
|
||||
/* $modRoadMap stores the number of same criteria
|
||||
* Ex: 3 Album titles, and 2 Track titles
|
||||
* We need to know this so we display the form elements properly
|
||||
*/
|
||||
$modRowMap = array();
|
||||
|
||||
$openSmartBlockOption = false;
|
||||
if (!empty($storedCrit)) {
|
||||
$openSmartBlockOption = true;
|
||||
}
|
||||
|
||||
// this returns a number indexed array for each criteria found in the database
|
||||
$criteriaKeys = array();
|
||||
if (isset($storedCrit["crit"])) {
|
||||
$criteriaKeys = array_keys($storedCrit["crit"]);
|
||||
}
|
||||
//the way the everything is currently built it setups 25 smartblock criteria forms and then disables them
|
||||
//but this creates 29 elements
|
||||
$numElements = count($this->getCriteriaOptions());
|
||||
// loop through once for each potential criteria option ie album, composer, track
|
||||
// criteria from different groups are separated already by the getCriteriaGrouped call
|
||||
|
||||
for ($i = 0; $i < $numElements; $i++) {
|
||||
$criteriaType = "";
|
||||
|
||||
// if there is a criteria found then count the number of rows for this specific criteria ie > 1 track title
|
||||
// need to refactor this to maintain separation based upon criteria grouping
|
||||
if (isset($criteriaKeys[$i])) {
|
||||
//Logging::info($criteriaKeys[$i]);
|
||||
Logging::info($storedCrit["crit"][$criteriaKeys[$i]]);
|
||||
$critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
|
||||
} else {
|
||||
$critCount = 1;
|
||||
}
|
||||
// the challenge is that we need to increment the element for a new group
|
||||
// within the same criteria but not the reference point i in the array
|
||||
// and for these secondary groups they will have a differe$storedCrit["crit"][$criteriaKeys[$i]]nt j reference point
|
||||
// store the number of items with the same key in the ModRowMap
|
||||
$modRowMap[$i] = $critCount;
|
||||
|
||||
/* Loop through all criteria with the same field
|
||||
* Ex: all criteria for 'Album'
|
||||
*/
|
||||
for ($j = 0; $j < $critCount; $j++) {
|
||||
/****************** CRITERIA ***********/
|
||||
// hide the criteria drop down select on any rows after the first
|
||||
if ($j > 0) {
|
||||
$invisible = ' sp-invisible';
|
||||
} else {
|
||||
$invisible = '';
|
||||
}
|
||||
|
||||
$criteria = new Zend_Form_Element_Select("sp_criteria_field_" . $i . "_" . $j);
|
||||
$criteria->setAttrib('class', 'input_select sp_input_select' . $invisible)
|
||||
->setValue('Select criteria')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($this->getCriteriaOptions());
|
||||
// if this isn't the first criteria and there isn't an entry for it already disable it
|
||||
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||
$criteria->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
// add the numbering to the form ie the i loop for each specific criteria and
|
||||
// the j loop starts at 0 and grows for each item matching the same criteria
|
||||
// look up the criteria type using the criteriaTypes function from above based upon the criteria value
|
||||
if (isset($criteriaKeys[$i])) {
|
||||
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
|
||||
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
|
||||
}
|
||||
$this->addElement($criteria);
|
||||
|
||||
|
||||
/****************** MODIFIER ***********/
|
||||
// every element has an optional modifier dropdown select
|
||||
|
||||
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_" . $i . "_" . $j);
|
||||
$criteriaModifers->setValue('Select modifier')
|
||||
->setAttrib('class', 'input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||
$criteriaModifers->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
// determine the modifier based upon criteria type which is looked up based upon an array
|
||||
if (isset($criteriaKeys[$i])) {
|
||||
if ($criteriaType == "s") {
|
||||
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
||||
} elseif ($criteriaType == "d") {
|
||||
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||
} elseif ($criteriaType == "tt") {
|
||||
$criteriaModifers->setMultiOptions($this->getIsNotOptions());
|
||||
} else {
|
||||
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
||||
}
|
||||
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
|
||||
} else {
|
||||
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
||||
}
|
||||
$this->addElement($criteriaModifers);
|
||||
|
||||
/****************** VALUE ***********/
|
||||
/* The challenge here is that datetime */
|
||||
if (isset($criteriaKeys[$i])) {
|
||||
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
|
||||
if (isset($criteriaType) && $criteriaType == "tt" &&
|
||||
preg_match('/is|is not/', $modifierTest) == 1) {
|
||||
|
||||
$criteriaValue = new Zend_Form_Element_Select("sp_criteria_value_" . $i . "_" . $j);
|
||||
$criteriaValue->setAttrib('class', 'input_select sp_input_select')->setDecorators(array('viewHelper'));
|
||||
|
||||
if (isset($criteriaKeys[$i]) ) { //do if $relativeTT above
|
||||
$criteriaValue->setAttrib('enabled', 'enabled');
|
||||
} else {
|
||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
} else {
|
||||
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
|
||||
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_input_text')->setDecorators(array('viewHelper'));
|
||||
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
||||
$criteriaValue->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
if (isset($criteriaKeys[$i])) {
|
||||
/*
|
||||
* Need to parse relative dates in a special way to populate select box down below
|
||||
*/
|
||||
// this is used below to test whether the datetime select should be shown or hidden
|
||||
$relativeDateTime = false;
|
||||
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
|
||||
if (isset($criteriaType) && $criteriaType == "d" &&
|
||||
preg_match('/before|after|between/', $modifierTest) == 1) {
|
||||
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
||||
$relativeDateTime = true;
|
||||
$criteriaValue->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"], FILTER_SANITIZE_NUMBER_INT));
|
||||
} elseif (isset($criteriaType) && $criteriaType == "tt" &&
|
||||
preg_match('/is|is not/', $modifierTest) == 1) {
|
||||
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
||||
$relativeDateTime = false;
|
||||
|
||||
$tracktypeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||
$tracktypeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $tracktypeSelectValue));
|
||||
$criteriaValue->setMultiOptions($this->getTracktypeOptions());
|
||||
|
||||
if ($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]){
|
||||
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||
} else {
|
||||
$criteriaValue->setMultiOptions(array('0' => _('Select track type')));
|
||||
$criteriaValue->setMultiOptions($this->getTracktypeOptions());
|
||||
$criteriaValue->setValue($tracktypeSelectValue);
|
||||
}
|
||||
$criteriaValue->setAttrib('enabled', 'enabled');
|
||||
} else {
|
||||
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||
}
|
||||
}
|
||||
$this->addElement($criteriaValue);
|
||||
|
||||
|
||||
/****************** DATETIME SELECT *************/
|
||||
$criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_" . $i . "_" . $j);
|
||||
$criteriaDatetimeSelect->setAttrib('class', 'input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if (isset($criteriaKeys[$i]) && $relativeDateTime) {
|
||||
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
||||
} else {
|
||||
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
// check if the value is stored and it is a relative datetime field
|
||||
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"])
|
||||
&& isset($criteriaType) && $criteriaType == "d" &&
|
||||
preg_match('/before|after|between/', $modifierTest) == 1) {
|
||||
// need to remove any leading numbers stored in the database
|
||||
$dateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
||||
// need to strip white from front and ago from the end to match with the value of the time unit select dropdown
|
||||
$dateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $dateTimeSelectValue));
|
||||
$criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
||||
$criteriaDatetimeSelect->setValue($dateTimeSelectValue);
|
||||
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
||||
} else {
|
||||
$criteriaDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
|
||||
$criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
||||
|
||||
}
|
||||
|
||||
$this->addElement($criteriaDatetimeSelect);
|
||||
|
||||
/****************** EXTRA ***********/
|
||||
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_" . $i . "_" . $j);
|
||||
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) {
|
||||
// need to check if this is a relative date time value
|
||||
if (isset($criteriaType) && $criteriaType == "d" && $modifierTest == 'between') {
|
||||
// the criteria value will be a number followed by time unit and ago so set input to number part
|
||||
$criteriaExtra->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"], FILTER_SANITIZE_NUMBER_INT));
|
||||
} else {
|
||||
$criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
|
||||
}
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
|
||||
} else {
|
||||
$criteriaExtra->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
$this->addElement($criteriaExtra);
|
||||
/****************** DATETIME SELECT EXTRA **********/
|
||||
|
||||
$criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_" . $i . "_" . $j);
|
||||
$criteriaExtraDatetimeSelect->setAttrib('class', 'input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
|
||||
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])
|
||||
&& $modifierTest == 'between') {
|
||||
// need to remove the leading numbers stored in the database
|
||||
$extraDateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
|
||||
// need to strip white from front and ago from the end to match with the value of the time unit select dropdown
|
||||
$extraDateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $extraDateTimeSelectValue));
|
||||
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
||||
// Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT');
|
||||
$criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue);
|
||||
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
|
||||
|
||||
} else {
|
||||
$criteriaExtraDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
|
||||
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
||||
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
$this->addElement($criteriaExtraDatetimeSelect);
|
||||
}//for
|
||||
}//for
|
||||
|
||||
$repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks');
|
||||
$repeatTracks->setDecorators(array('viewHelper'))
|
||||
->setLabel(_('Allow Repeated Tracks:'));
|
||||
if (isset($storedCrit["repeat_tracks"])) {
|
||||
$repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1?true:false);
|
||||
}
|
||||
$this->addElement($repeatTracks);
|
||||
|
||||
$overflowTracks = new Zend_Form_Element_Checkbox('sp_overflow_tracks');
|
||||
$overflowTracks->setDecorators(array('viewHelper'))
|
||||
->setLabel(_('Allow last track to exceed time limit:'));
|
||||
if (isset($storedCrit["overflow_tracks"])) {
|
||||
$overflowTracks->setChecked($storedCrit["overflow_tracks"]["value"] == 1);
|
||||
}
|
||||
$this->addElement($overflowTracks);
|
||||
|
||||
$sort = new Zend_Form_Element_Select('sp_sort_options');
|
||||
$sort->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setLabel(_("Sort Tracks:"))
|
||||
->setMultiOptions($this->getSortOptions());
|
||||
if (isset($storedCrit["sort"])) {
|
||||
$sort->setValue($storedCrit["sort"]["value"]);
|
||||
}
|
||||
$this->addElement($sort);
|
||||
|
||||
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
||||
$limit->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($this->getLimitOptions());
|
||||
if (isset($storedCrit["limit"])) {
|
||||
$limit->setValue($storedCrit["limit"]["modifier"]);
|
||||
}
|
||||
$this->addElement($limit);
|
||||
|
||||
$limitValue = new Zend_Form_Element_Text('sp_limit_value');
|
||||
$limitValue->setAttrib('class', 'sp_input_text_limit')
|
||||
->setLabel(_('Limit to:'))
|
||||
->setDecorators(array('viewHelper'));
|
||||
$this->addElement($limitValue);
|
||||
if (isset($storedCrit["limit"])) {
|
||||
$limitValue->setValue($storedCrit["limit"]["value"]);
|
||||
} else {
|
||||
// setting default to 1 hour
|
||||
$limitValue->setValue(1);
|
||||
}
|
||||
|
||||
|
||||
$generate = new Zend_Form_Element_Button('generate_button');
|
||||
$generate->setAttrib('class', 'sp-button btn');
|
||||
$generate->setAttrib('title', _('Generate playlist content and save criteria'));
|
||||
$generate->setIgnore(true);
|
||||
if ($blockType == 0) {
|
||||
$generate->setLabel(_('Preview'));
|
||||
}
|
||||
else {
|
||||
$generate->setLabel(_('Generate'));
|
||||
}
|
||||
$generate->setDecorators(array('viewHelper'));
|
||||
$this->addElement($generate);
|
||||
|
||||
$shuffle = new Zend_Form_Element_Button('shuffle_button');
|
||||
$shuffle->setAttrib('class', 'sp-button btn');
|
||||
$shuffle->setAttrib('title', _('Shuffle playlist content'));
|
||||
$shuffle->setIgnore(true);
|
||||
$shuffle->setLabel(_('Shuffle'));
|
||||
$shuffle->setDecorators(array('viewHelper'));
|
||||
$this->addElement($shuffle);
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption,
|
||||
'criteriasLength' => $numElements, 'modRowMap' => $modRowMap))
|
||||
));
|
||||
}
|
||||
/*
|
||||
* This is a simple function that determines if a modValue should enable a datetime
|
||||
*/
|
||||
public function enableDateTimeUnit($modValue) {
|
||||
return (preg_match('/before|after|between/', $modValue) == 1);
|
||||
}
|
||||
|
||||
public function preValidation($params)
|
||||
{
|
||||
$data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']);
|
||||
// add elements that needs to be added
|
||||
// set multioption for modifier according to criteria_field
|
||||
$modRowMap = array();
|
||||
if (!isset($data['criteria'])) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($data['criteria'] as $critKey=>$d) {
|
||||
$count = 1;
|
||||
foreach ($d as $modKey=>$modInfo) {
|
||||
if ($modKey == 0) {
|
||||
$eleCrit = $this->getElement("sp_criteria_field_".$critKey."_".$modKey);
|
||||
$eleCrit->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field']));
|
||||
$eleCrit->setAttrib("disabled", null);
|
||||
|
||||
$eleMod = $this->getElement("sp_criteria_modifier_".$critKey."_".$modKey);
|
||||
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
|
||||
if ($criteriaType == "s") {
|
||||
$eleMod->setMultiOptions($this->getStringCriteriaOptions());
|
||||
} elseif ($criteriaType == "n") {
|
||||
$eleMod->setMultiOptions($this->getNumericCriteriaOptions());
|
||||
} elseif ($criteriaType == "d") {
|
||||
$eleMod->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||
} elseif ($criteriaType == "tt") {
|
||||
$eleMod->setMultiOptions($this->getIsNotOptions());
|
||||
} else {
|
||||
$eleMod->setMultiOptions(array('0' => _('Select modifier')));
|
||||
}
|
||||
$eleMod->setValue($modInfo['sp_criteria_modifier']);
|
||||
$eleMod->setAttrib("disabled", null);
|
||||
|
||||
$eleDatetime = $this->getElement("sp_criteria_datetime_select_".$critKey."_".$modKey);
|
||||
if ($this->enableDateTimeUnit($eleMod->getValue())) {
|
||||
$eleDatetime->setAttrib("enabled", "enabled");
|
||||
$eleDatetime->setValue($modInfo['sp_criteria_datetime_select']);
|
||||
$eleDatetime->setAttrib("disabled", null);
|
||||
}
|
||||
else {
|
||||
$eleDatetime->setAttrib("disabled","disabled");
|
||||
}
|
||||
$eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey);
|
||||
$eleValue->setValue($modInfo['sp_criteria_value']);
|
||||
$eleValue->setAttrib("disabled", null);
|
||||
|
||||
if (isset($modInfo['sp_criteria_extra'])) {
|
||||
$eleExtra = $this->getElement("sp_criteria_extra_".$critKey."_".$modKey);
|
||||
$eleExtra->setValue($modInfo['sp_criteria_extra']);
|
||||
$eleValue->setAttrib('class', 'input_text sp_extra_input_text');
|
||||
$eleExtra->setAttrib("disabled", null);
|
||||
}
|
||||
$eleExtraDatetime = $this->getElement("sp_criteria_extra_datetime_select_".$critKey."_".$modKey);
|
||||
if ($eleMod->getValue() == 'between') {
|
||||
$eleExtraDatetime->setAttrib("enabled", "enabled");
|
||||
$eleExtraDatetime->setValue($modInfo['sp_criteria_extra_datetime_select']);
|
||||
$eleExtraDatetime->setAttrib("disabled", null);
|
||||
}
|
||||
else {
|
||||
$eleExtraDatetime->setAttrib("disabled","disabled");
|
||||
}
|
||||
|
||||
} else {
|
||||
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$critKey."_".$modKey);
|
||||
$criteria->setAttrib('class', 'input_select sp_input_select sp-invisible')
|
||||
->setValue('Select criteria')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($this->getCriteriaOptions());
|
||||
|
||||
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
|
||||
$criteria->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field']));
|
||||
$this->addElement($criteria);
|
||||
|
||||
/****************** MODIFIER ***********/
|
||||
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$critKey."_".$modKey);
|
||||
$criteriaModifers->setValue('Select modifier')
|
||||
->setAttrib('class', 'input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
|
||||
if ($criteriaType == "s") {
|
||||
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
||||
} elseif ($criteriaType == "n") {
|
||||
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
||||
}
|
||||
elseif ($criteriaType == "d") {
|
||||
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
||||
} elseif ($criteriaType == "tt") {
|
||||
$criteriaModifers->setMultiOptions($this->getIsNotOptions());
|
||||
} else {
|
||||
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
||||
}
|
||||
$criteriaModifers->setValue($modInfo['sp_criteria_modifier']);
|
||||
$this->addElement($criteriaModifers);
|
||||
|
||||
/****************** VALUE ***********/
|
||||
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$critKey."_".$modKey);
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
||||
->setDecorators(array('viewHelper'));
|
||||
$criteriaValue->setValue($modInfo['sp_criteria_value']);
|
||||
$this->addElement($criteriaValue);
|
||||
/****************** DATETIME UNIT SELECT ***********/
|
||||
|
||||
$criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$critKey."_".$modKey);
|
||||
$criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if ($this->enableDateTimeUnit($criteriaValue->getValue())) {
|
||||
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
||||
$criteriaDatetimeSelect->setAttrib('disabled', null);
|
||||
$criteriaDatetimeSelect->setValue($modInfo['sp_criteria_datetime_select']);
|
||||
$this->addElement($criteriaDatetimeSelect);
|
||||
}
|
||||
else {
|
||||
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
/****************** EXTRA ***********/
|
||||
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey);
|
||||
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if (isset($modInfo['sp_criteria_extra'])) {
|
||||
$criteriaExtra->setValue($modInfo['sp_criteria_extra']);
|
||||
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
|
||||
} else {
|
||||
$criteriaExtra->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
$this->addElement($criteriaExtra);
|
||||
|
||||
/****************** EXTRA DATETIME UNIT SELECT ***********/
|
||||
|
||||
$criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_".$critKey."_".$modKey);
|
||||
$criteriaExtraDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
||||
->setDecorators(array('viewHelper'));
|
||||
if ($criteriaValue->getValue() == 'between') {
|
||||
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
|
||||
$criteriaExtraDatetimeSelect->setAttrib('disabled', null);
|
||||
$criteriaExtraDatetimeSelect->setValue($modInfo['sp_criteria_extra_datetime_select']);
|
||||
$this->addElement($criteriaExtraDatetimeSelect);
|
||||
}
|
||||
else {
|
||||
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$modRowMap[$critKey] = $count;
|
||||
}
|
||||
|
||||
$decorator = $this->getDecorator("ViewScript");
|
||||
$existingModRow = $decorator->getOption("modRowMap");
|
||||
foreach ($modRowMap as $key=>$v) {
|
||||
$existingModRow[$key] = $v;
|
||||
}
|
||||
$decorator->setOption("modRowMap", $existingModRow);
|
||||
|
||||
// reconstruct the params['criteria'] so we can populate the form
|
||||
$formData = array();
|
||||
foreach ($params['data'] as $ele) {
|
||||
$formData[$ele['name']] = $ele['value'];
|
||||
}
|
||||
|
||||
$this->populate($formData);
|
||||
|
||||
// Logging::info($formData);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function isValid($params)
|
||||
{
|
||||
$isValid = true;
|
||||
$data = $this->preValidation($params);
|
||||
$criteria2PeerMap = array(
|
||||
0 => "Select criteria",
|
||||
"album_title" => "DbAlbumTitle",
|
||||
"artist_name" => "DbArtistName",
|
||||
"bit_rate" => "DbBitRate",
|
||||
"bpm" => "DbBpm",
|
||||
"composer" => "DbComposer",
|
||||
"conductor" => "DbConductor",
|
||||
"copyright" => "DbCopyright",
|
||||
"cuein" => "DbCuein",
|
||||
"cueout" => "DbCueout",
|
||||
"description" => "DbDescription",
|
||||
"encoded_by" => "DbEncodedBy",
|
||||
"utime" => "DbUtime",
|
||||
"mtime" => "DbMtime",
|
||||
"lptime" => "DbLPtime",
|
||||
"genre" => "DbGenre",
|
||||
"info_url" => "DbInfoUrl",
|
||||
"isrc_number" => "DbIsrcNumber",
|
||||
"label" => "DbLabel",
|
||||
"language" => "DbLanguage",
|
||||
"length" => "DbLength",
|
||||
"mime" => "DbMime",
|
||||
"mood" => "DbMood",
|
||||
"owner_id" => "DbOwnerId",
|
||||
"replay_gain" => "DbReplayGain",
|
||||
"sample_rate" => "DbSampleRate",
|
||||
"track_title" => "DbTrackTitle",
|
||||
"track_number" => "DbTrackNumber",
|
||||
"year" => "DbYear",
|
||||
"track_type" => "DbTrackType"
|
||||
);
|
||||
|
||||
// things we need to check
|
||||
// 1. limit value shouldn't be empty and has upperbound of 24 hrs
|
||||
// 2. sp_criteria or sp_criteria_modifier shouldn't be 0
|
||||
// 3. validate formate according to DB column type
|
||||
$multiplier = 1;
|
||||
$result = 0;
|
||||
|
||||
// validation start
|
||||
if ($data['etc']['sp_limit_options'] == 'hours') {
|
||||
$multiplier = 60;
|
||||
}
|
||||
if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
|
||||
$element = $this->getElement("sp_limit_value");
|
||||
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
||||
$element->addError(_("Limit cannot be empty or smaller than 0"));
|
||||
$isValid = false;
|
||||
} else {
|
||||
$mins = floatval($data['etc']['sp_limit_value']) * $multiplier;
|
||||
if ($mins > 1440) {
|
||||
$element->addError(_("Limit cannot be more than 24 hrs"));
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$element = $this->getElement("sp_limit_value");
|
||||
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
||||
$element->addError(_("Limit cannot be empty or smaller than 0"));
|
||||
$isValid = false;
|
||||
} elseif (!ctype_digit($data['etc']['sp_limit_value'])) {
|
||||
$element->addError(_("The value should be an integer"));
|
||||
$isValid = false;
|
||||
} elseif (intval($data['etc']['sp_limit_value']) > 500) {
|
||||
$element->addError(_("500 is the max item limit value you can set"));
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['criteria'])) {
|
||||
foreach ($data['criteria'] as $rowKey=>$row) {
|
||||
foreach ($row as $key=>$d) {
|
||||
$element = $this->getElement("sp_criteria_field_".$rowKey."_".$key);
|
||||
// check for not selected select box
|
||||
if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0") {
|
||||
$element->addError(_("You must select Criteria and Modifier"));
|
||||
$isValid = false;
|
||||
} else {
|
||||
$column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]);
|
||||
// validation on type of column
|
||||
if (in_array($d['sp_criteria_field'], array('length', 'cuein', 'cueout'))) {
|
||||
if (!preg_match("/^(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
|
||||
$element->addError(_("'Length' should be in '00:00:00' format"));
|
||||
$isValid = false;
|
||||
}
|
||||
// this looks up the column type for the criteria the modified time, upload time etc.
|
||||
} elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) {
|
||||
// need to check for relative modifiers first - bypassing currently
|
||||
if (in_array($d['sp_criteria_modifier'], array('before','after','between'))) {
|
||||
if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_value'])) {
|
||||
$element->addError(_("Only non-negative integer numbers are allowed (e.g 1 or 5) for the text value"));
|
||||
$isValid = false;
|
||||
// TODO validate this on numeric input with whatever parsing also do for extra
|
||||
//if the modifier is before ago or between we skip validation until we confirm format
|
||||
}
|
||||
elseif (isSet($d['sp_criteria_datetime_select']) && $d['sp_criteria_datetime_select'] == "0") {
|
||||
$element->addError(_("You must select a time unit for a relative datetime."));
|
||||
$isValid = false;
|
||||
}
|
||||
} else {
|
||||
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
|
||||
$element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)"));
|
||||
$isValid = false;
|
||||
} else {
|
||||
$result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']);
|
||||
if (!$result["success"]) {
|
||||
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
||||
$element->addError($result["errMsg"]);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($d['sp_criteria_extra'])) {
|
||||
if ($d['sp_criteria_modifier'] == 'between') {
|
||||
// validate that the input value only contains a number if using relative date times
|
||||
if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_extra'])) {
|
||||
$element->addError(_("Only non-negative integer numbers are allowed for a relative date time"));
|
||||
$isValid = false;
|
||||
}
|
||||
// also need to check to make sure they chose a time unit from the dropdown
|
||||
elseif ($d['sp_criteria_extra_datetime_select'] == "0") {
|
||||
$element->addError(_("You must select a time unit for a relative datetime."));
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
|
||||
$element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)"));
|
||||
$isValid = false;
|
||||
} else {
|
||||
$result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']);
|
||||
if (!$result["success"]) {
|
||||
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
||||
$element->addError($result["errMsg"]);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($column->getType() == PropelColumnTypes::INTEGER &&
|
||||
$d['sp_criteria_field'] != 'owner_id') {
|
||||
if (!is_numeric($d['sp_criteria_value'])) {
|
||||
$element->addError(_("The value has to be numeric"));
|
||||
$isValid = false;
|
||||
}
|
||||
// length check
|
||||
if ($d['sp_criteria_value'] >= pow(2,31)) {
|
||||
$element->addError(_("The value should be less then 2147483648"));
|
||||
$isValid = false;
|
||||
}
|
||||
} elseif ($column->getType() == PropelColumnTypes::VARCHAR) {
|
||||
if (strlen($d['sp_criteria_value']) > $column->getSize()) {
|
||||
$element->addError(sprintf(_("The value should be less than %s characters"), $column->getSize()));
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($d['sp_criteria_value'] == "") {
|
||||
$element->addError(_("Value cannot be empty"));
|
||||
$isValid = false;
|
||||
}
|
||||
}//end foreach
|
||||
}//for loop
|
||||
}//if
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
}
|
19
legacy/application/forms/StationPodcast.php
Normal file
19
legacy/application/forms/StationPodcast.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_StationPodcast extends Zend_Form {
|
||||
|
||||
public function init() {
|
||||
// Station Podcast form
|
||||
$podcastPreferences = new Application_Form_PodcastPreferences();
|
||||
$this->addSubForm($podcastPreferences, 'preferences_podcast');
|
||||
|
||||
$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');
|
||||
$this->addElement($csrf_element);
|
||||
}
|
||||
|
||||
}
|
107
legacy/application/forms/StreamSetting.php
Normal file
107
legacy/application/forms/StreamSetting.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_StreamSetting extends Zend_Form
|
||||
{
|
||||
private $setting;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setSetting($setting)
|
||||
{
|
||||
$this->setting = $setting;
|
||||
}
|
||||
|
||||
public function startFrom()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'preference/stream-setting.phtml'))
|
||||
));
|
||||
|
||||
$setting = $this->setting;
|
||||
|
||||
$output_sound_device = new Zend_Form_Element_Checkbox('output_sound_device');
|
||||
$output_sound_device->setLabel(_('Hardware Audio Output:'))
|
||||
->setRequired(false)
|
||||
->setValue(($setting['output_sound_device'] == "true")?1:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output_sound_device);
|
||||
|
||||
$output_sound_device_type = new Zend_Form_Element_Select('output_sound_device_type');
|
||||
$output_sound_device_type->setLabel(_('Output Type'))
|
||||
->setMultiOptions(array(
|
||||
"ALSA"=>_("ALSA"),
|
||||
"AO"=>_("AO"),
|
||||
"OSS"=>_("OSS"),
|
||||
"Portaudio"=>_("Portaudio"),
|
||||
"Pulseaudio"=>_("Pulseaudio"),
|
||||
"Jack"=>_("Jack")))
|
||||
->setValue(isset($setting['output_sound_device_type'])?$setting['output_sound_device_type']:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output_sound_device_type);
|
||||
|
||||
$icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata');
|
||||
$icecast_vorbis_metadata->setLabel(_('Icecast Vorbis Metadata'))
|
||||
->setRequired(false)
|
||||
->setValue(($setting['icecast_vorbis_metadata'] == "true")?1:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
if (Application_Model_Preference::GetEnableStreamConf() == "false") {
|
||||
$icecast_vorbis_metadata->setAttrib("readonly", true);
|
||||
}
|
||||
$this->addElement($icecast_vorbis_metadata);
|
||||
|
||||
$stream_format = new Zend_Form_Element_Radio('streamFormat');
|
||||
$stream_format->setLabel(_('Stream Label:'));
|
||||
$stream_format->setMultiOptions(array(_("Artist - Title"),
|
||||
_("Show - Artist - Title"),
|
||||
_("Station name - Show name")));
|
||||
$stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat());
|
||||
$stream_format->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($stream_format);
|
||||
|
||||
$offAirMeta = new Zend_Form_Element_Text('offAirMeta');
|
||||
$offAirMeta->setLabel(_('Off Air Metadata'))
|
||||
->setValue(Application_Model_StreamSetting::getOffAirMeta())
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($offAirMeta);
|
||||
|
||||
$enable_replay_gain = new Zend_Form_Element_Checkbox("enableReplayGain");
|
||||
$enable_replay_gain->setLabel(_("Enable Replay Gain"))
|
||||
->setValue(Application_Model_Preference::GetEnableReplayGain())
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($enable_replay_gain);
|
||||
|
||||
$replay_gain = new Zend_Form_Element_Hidden("replayGainModifier");
|
||||
$replay_gain->setLabel(_("Replay Gain Modifier"))
|
||||
->setValue(Application_Model_Preference::getReplayGainModifier())
|
||||
->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(_('Streaming Server:'));
|
||||
$customSettings->setMultiOptions(array(_("Default Streaming"), _("Custom / 3rd Party Streaming")));
|
||||
$customSettings->setValue(!empty($custom) ? $custom : 0);
|
||||
$this->addElement($customSettings);
|
||||
}
|
||||
|
||||
public function isValid($data)
|
||||
{
|
||||
if (isset($data['output_sound_device'])) {
|
||||
$d = array();
|
||||
$d["output_sound_device"] = $data['output_sound_device'];
|
||||
$d["icecast_vorbis_metadata"] = $data['icecast_vorbis_metadata'];
|
||||
if (isset($data['output_sound_device_type'])) {
|
||||
$d["output_sound_device_type"] = $data['output_sound_device_type'];
|
||||
}
|
||||
$d["streamFormat"] = $data['streamFormat'];
|
||||
$this->populate($d);
|
||||
}
|
||||
$isValid = parent::isValid($data);
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
}
|
243
legacy/application/forms/StreamSettingSubForm.php
Normal file
243
legacy/application/forms/StreamSettingSubForm.php
Normal file
|
@ -0,0 +1,243 @@
|
|||
<?php
|
||||
class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
|
||||
{
|
||||
private $prefix;
|
||||
private $setting;
|
||||
private $stream_types;
|
||||
private $stream_bitrates;
|
||||
|
||||
static $customizable;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function setSetting($setting)
|
||||
{
|
||||
$this->setting = $setting;
|
||||
}
|
||||
|
||||
public function setStreamTypes($stream_types)
|
||||
{
|
||||
$this->stream_types = $stream_types;
|
||||
}
|
||||
|
||||
public function setStreamBitrates($stream_bitrates)
|
||||
{
|
||||
$this->stream_bitrates = $stream_bitrates;
|
||||
}
|
||||
|
||||
public function startForm()
|
||||
{
|
||||
$prefix = "s".$this->prefix;
|
||||
$stream_number = $this->prefix;
|
||||
$setting = $this->setting;
|
||||
$stream_types = $this->stream_types;
|
||||
$stream_bitrates = $this->stream_bitrates;
|
||||
|
||||
$streamDefaults = Application_Model_StreamSetting::getDefaults($prefix);
|
||||
// If we're not using custom stream settings, use the defaults
|
||||
$useDefaults = !Application_Model_Preference::getUsingCustomStreamSettings();
|
||||
|
||||
$this->setIsArray(true);
|
||||
$this->setElementsBelongTo($prefix."_data");
|
||||
|
||||
$enable = new Zend_Form_Element_Checkbox('enable');
|
||||
$enable->setLabel(_('Enabled:'))
|
||||
->setValue($setting[$prefix.'_enable'] == 'true' ? 1 : 0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($enable);
|
||||
static::$customizable[] = $enable->getName();
|
||||
|
||||
$mobile = new Zend_Form_Element_Checkbox('mobile');
|
||||
$mobile->setLabel(_('Mobile:'));
|
||||
$mobile->setValue($setting[$prefix.'_mobile']);
|
||||
$mobile->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($mobile);
|
||||
static::$customizable[] = $mobile->getName();
|
||||
|
||||
$type = new Zend_Form_Element_Select('type');
|
||||
$type->setLabel(_("Stream Type:"))
|
||||
->setMultiOptions($stream_types)
|
||||
->setValue(isset($setting[$prefix.'_type'])?$setting[$prefix.'_type']:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($type);
|
||||
static::$customizable[] = $type->getName();
|
||||
|
||||
$bitrate = new Zend_Form_Element_Select('bitrate');
|
||||
$bitrate->setLabel(_("Bit Rate:"))
|
||||
->setMultiOptions($stream_bitrates)
|
||||
->setValue(isset($setting[$prefix.'_bitrate'])?$setting[$prefix.'_bitrate']:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($bitrate);
|
||||
static::$customizable[] = $bitrate->getName();
|
||||
|
||||
$output = new Zend_Form_Element_Select('output');
|
||||
$output->setLabel(_("Service Type:"))
|
||||
->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"SHOUTcast"))
|
||||
->setValue($useDefaults ? $streamDefaults['output'] :
|
||||
(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast"))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output);
|
||||
|
||||
$channels = new Zend_Form_Element_Select('channels');
|
||||
$channels->setLabel(_("Channels:"))
|
||||
->setMultiOptions(array("mono"=>_("1 - Mono"), "stereo"=>_("2 - Stereo")))
|
||||
->setValue(isset($setting[$prefix.'_channels']) ? $setting[$prefix.'_channels'] : "stereo")
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($channels);
|
||||
static::$customizable[] = $channels->getName();
|
||||
|
||||
$host = new Zend_Form_Element_Text('host');
|
||||
$host->setLabel(_("Server"))
|
||||
->setValue($useDefaults ? $streamDefaults['host'] :
|
||||
(isset($setting[$prefix.'_host'])?$setting[$prefix.'_host']:""))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$host->setAttrib('alt', 'domain');
|
||||
$this->addElement($host);
|
||||
|
||||
$port = new Zend_Form_Element_Text('port');
|
||||
$port->setLabel(_("Port"))
|
||||
->setValue($useDefaults ? $streamDefaults['port'] :
|
||||
(isset($setting[$prefix.'_port'])?$setting[$prefix.'_port']:""))
|
||||
->setValidators(array(new Zend_Validate_Between(array('min'=>0, 'max'=>99999))))
|
||||
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($port);
|
||||
|
||||
$pass = new Zend_Form_Element_Text('pass');
|
||||
$pass->setLabel(_("Password"))
|
||||
->setValue($useDefaults ? $streamDefaults['pass'] :
|
||||
(isset($setting[$prefix.'_pass'])?$setting[$prefix.'_pass']:""))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$pass->setAttrib('alt', 'regular_text');
|
||||
$this->addElement($pass);
|
||||
|
||||
$genre = new Zend_Form_Element_Text('genre');
|
||||
$genre->setLabel(_("Genre"))
|
||||
->setValue(isset($setting[$prefix.'_genre'])?$setting[$prefix.'_genre']:"")
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($genre);
|
||||
|
||||
$url = new Zend_Form_Element_Text('url');
|
||||
$url->setLabel(_("URL"))
|
||||
->setValue(isset($setting[$prefix.'_url'])?$setting[$prefix.'_url']:"")
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$url->setAttrib('alt', 'url');
|
||||
$this->addElement($url);
|
||||
|
||||
$name = new Zend_Form_Element_Text('name');
|
||||
$name->setLabel(_("Name"))
|
||||
->setValue(isset($setting[$prefix.'_name'])?$setting[$prefix.'_name']:"")
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($name);
|
||||
|
||||
$description = new Zend_Form_Element_Text('description');
|
||||
$description->setLabel(_("Description"))
|
||||
->setValue(isset($setting[$prefix.'_description'])?$setting[$prefix.'_description']:"")
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($description);
|
||||
|
||||
$mount = new Zend_Form_Element_Text('mount');
|
||||
$mount->setLabel(_("Mount Point"))
|
||||
->setValue($useDefaults ? $streamDefaults['mount'] :
|
||||
(isset($setting[$prefix.'_mount'])?$setting[$prefix.'_mount']:""))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$mount->setAttrib('alt', 'regular_text');
|
||||
$this->addElement($mount);
|
||||
|
||||
$user = new Zend_Form_Element_Text('user');
|
||||
$user->setLabel(_("Username"))
|
||||
->setValue($useDefaults ? $streamDefaults['user'] :
|
||||
(isset($setting[$prefix.'_user'])?$setting[$prefix.'_user']:""))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$user->setAttrib('alt', 'regular_text');
|
||||
$this->addElement($user);
|
||||
|
||||
$adminUser = new Zend_Form_Element_Text('admin_user');
|
||||
$adminUser->setLabel(_("Admin User"))
|
||||
->setValue(Application_Model_StreamSetting::getAdminUser($prefix))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$adminUser->setAttrib('alt', 'regular_text');
|
||||
$this->addElement($adminUser);
|
||||
|
||||
$adminPass = new Zend_Form_Element_Password('admin_pass');
|
||||
$adminPass->setLabel(_("Admin Password"))
|
||||
->setValue(Application_Model_StreamSetting::getAdminPass($prefix))
|
||||
->setValidators(array(
|
||||
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$adminPass->setAttrib('alt', 'regular_text');
|
||||
$this->addElement($adminPass);
|
||||
|
||||
$liquidsoap_error_msg = '<div class="stream-status status-info"><p>'._('Getting information from the server...').'</p></div>';
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml',
|
||||
"stream_number"=>$stream_number,
|
||||
"enabled"=>$enable->getValue(),
|
||||
"liquidsoap_error_msg"=>$liquidsoap_error_msg))
|
||||
));
|
||||
}
|
||||
|
||||
public function isValid ($data)
|
||||
{
|
||||
$f_data = $data['s'.$this->prefix."_data"];
|
||||
$isValid = parent::isValid($f_data);
|
||||
// XXX: A couple of ugly workarounds here, but I guess that's what you get when you
|
||||
// combine an already-complex POST and GET into a single action...
|
||||
if (Application_Model_Preference::getUsingCustomStreamSettings() && $f_data) {
|
||||
if ($f_data['enable'] == 1 && isset($f_data["host"])) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
public function toggleState() {
|
||||
$elements = $this->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if (Application_Model_Preference::getUsingCustomStreamSettings()) {
|
||||
$element->setAttrib('disabled', null);
|
||||
} else if (!(in_array($element->getName(), static::$customizable)
|
||||
|| $element->getType() == 'Zend_Form_Element_Hidden')) {
|
||||
$element->setAttrib('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
legacy/application/forms/TuneInPreferences.php
Normal file
109
legacy/application/forms/TuneInPreferences.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
require_once 'customvalidators/ConditionalNotEmpty.php';
|
||||
|
||||
class Application_Form_TuneInPreferences extends Zend_Form_SubForm
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences_tunein.phtml'))
|
||||
));
|
||||
|
||||
$enableTunein = new Zend_Form_Element_Checkbox("enable_tunein");
|
||||
$enableTunein->setDecorators(array(
|
||||
'ViewHelper',
|
||||
'Errors',
|
||||
'Label'
|
||||
));
|
||||
$enableTunein->addDecorator('Label', array('class' => 'enable-tunein'));
|
||||
$enableTunein->setLabel(_("Push metadata to your station on TuneIn?"));
|
||||
$enableTunein->setValue(Application_Model_Preference::getTuneinEnabled());
|
||||
$this->addElement($enableTunein);
|
||||
|
||||
$tuneinStationId = new Zend_Form_Element_Text("tunein_station_id");
|
||||
$tuneinStationId->setLabel(_("Station ID:"));
|
||||
$tuneinStationId->setValue(Application_Model_Preference::getTuneinStationId());
|
||||
$tuneinStationId->setAttrib("class", "input_text");
|
||||
$this->addElement($tuneinStationId);
|
||||
|
||||
$tuneinPartnerKey = new Zend_Form_Element_Text("tunein_partner_key");
|
||||
$tuneinPartnerKey->setLabel(_("Partner Key:"));
|
||||
$tuneinPartnerKey->setValue(Application_Model_Preference::getTuneinPartnerKey());
|
||||
$tuneinPartnerKey->setAttrib("class", "input_text");
|
||||
$this->addElement($tuneinPartnerKey);
|
||||
|
||||
$tuneinPartnerId = new Zend_Form_Element_Text("tunein_partner_id");
|
||||
$tuneinPartnerId->setLabel(_("Partner Id:"));
|
||||
$tuneinPartnerId->setValue(Application_Model_Preference::getTuneinPartnerId());
|
||||
$tuneinPartnerId->setAttrib("class", "input_text");
|
||||
$this->addElement($tuneinPartnerId);
|
||||
}
|
||||
|
||||
public function isValid($data)
|
||||
{
|
||||
$valid = true;
|
||||
// Make request to TuneIn API to test the settings are valid.
|
||||
// TuneIn does not have an API to make test requests to check if
|
||||
// the credentials are correct. Therefore we will make a request
|
||||
// with the commercial flag set to true, which removes the metadata
|
||||
// from the station on TuneIn. After that, and if the test request
|
||||
// succeeds, we will make another request with the real metadata.
|
||||
if ($data["enable_tunein"]) {
|
||||
$credentialsQryStr = "?partnerId=".$data["tunein_partner_id"]."&partnerKey=".$data["tunein_partner_key"]."&id=".$data["tunein_station_id"];
|
||||
$commercialFlagQryStr = "&commercial=true";
|
||||
|
||||
$metadata = Application_Model_Schedule::getCurrentPlayingTrack();
|
||||
|
||||
if (is_null($metadata)) {
|
||||
$qryStr = $credentialsQryStr . $commercialFlagQryStr;
|
||||
} else {
|
||||
$metadata["artist"] = empty($metadata["artist"]) ? "n/a" : $metadata["artist"];
|
||||
$metadata["title"] = empty($metadata["title"]) ? "n/a" : $metadata["title"];
|
||||
$metadataQryStr = "&artist=" . $metadata["artist"] . "&title=" . $metadata["title"];
|
||||
|
||||
$qryStr = $credentialsQryStr . $metadataQryStr;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $qryStr);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$xmlData = curl_exec($ch);
|
||||
if (curl_error($ch)) {
|
||||
Logging::error("Failed to reach TuneIn: ". curl_errno($ch)." - ". curl_error($ch) . " - " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||
if (curl_error($ch) == "The requested URL returned error: 403 Forbidden") {
|
||||
$this->getElement("enable_tunein")->setErrors(array(_("Invalid TuneIn Settings. Please ensure your TuneIn settings are correct and try again.")));
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
if ($valid) {
|
||||
$xmlObj = new SimpleXMLElement($xmlData);
|
||||
if (!$xmlObj || $xmlObj->head->status != "200") {
|
||||
$this->getElement("enable_tunein")->setErrors(array(_("Invalid TuneIn Settings. Please ensure your TuneIn settings are correct and try again.")));
|
||||
$valid = false;
|
||||
} else if ($xmlObj->head->status == "200") {
|
||||
Application_Model_Preference::setLastTuneinMetadataUpdate(time());
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
// Set values to what the user entered since the form is invalid so they
|
||||
// don't have to enter in the values again and can see what they entered.
|
||||
$this->getElement("enable_tunein")->setValue($data["enable_tunein"]);
|
||||
$this->getElement("tunein_partner_key")->setValue($data["tunein_partner_key"]);
|
||||
$this->getElement("tunein_partner_id")->setValue($data["tunein_partner_id"]);
|
||||
$this->getElement("tunein_station_id")->setValue($data["tunein_station_id"]);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
}
|
51
legacy/application/forms/WatchedDirPreferences.php
Normal file
51
legacy/application/forms/WatchedDirPreferences.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_WatchedDirPreferences extends Zend_Form_SubForm
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/preferences_watched_dirs.phtml'))
|
||||
));
|
||||
|
||||
$this->addElement('text', 'storageFolder', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Import Folder:'),
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'value' => '',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('text', 'watchedFolder', array(
|
||||
'class' => 'input_text',
|
||||
'label' => _('Watched Folders:'),
|
||||
'required' => false,
|
||||
'filters' => array('StringTrim'),
|
||||
'value' => '',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function verifyChosenFolder($p_form_element_id)
|
||||
{
|
||||
$element = $this->getElement($p_form_element_id);
|
||||
|
||||
if (!is_dir($element->getValue())) {
|
||||
$element->setErrors(array(_('Not a valid Directory')));
|
||||
|
||||
return false;
|
||||
} else {
|
||||
$element->setValue("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
52
legacy/application/forms/customfilters/ImageSize.php
Normal file
52
legacy/application/forms/customfilters/ImageSize.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* custom filter for image uploads
|
||||
*
|
||||
* WARNING: you need to include this file directly when using it, it clashes with the
|
||||
* way zf1 Zend_Loader_PluginLoader expects it to be found. Another way around this
|
||||
* might be to rename the class and have the new name get loaded proper.
|
||||
*
|
||||
* Since this is only getting used in a few places I am re-adding the
|
||||
* require_once there to get this fixed for now.
|
||||
*/
|
||||
|
||||
class Zend_Filter_ImageSize implements Zend_Filter_Interface
|
||||
{
|
||||
public function filter($value)
|
||||
{
|
||||
if (!file_exists($value)) {
|
||||
throw new Zend_Filter_Exception('Image does not exist: ' . $value);
|
||||
}
|
||||
|
||||
$image = imagecreatefromstring(file_get_contents($value));
|
||||
if (false === $image) {
|
||||
throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
|
||||
}
|
||||
|
||||
// find ratio to scale down to
|
||||
// TODO: pass 600 as parameter in the future
|
||||
$origWidth = imagesx($image);
|
||||
$origHeight = imagesy($image);
|
||||
$ratio = max($origWidth, $origHeight) / 600;
|
||||
|
||||
if ($ratio > 1) {
|
||||
// img too big! create a scaled down image
|
||||
$newWidth = round($origWidth / $ratio);
|
||||
$newHeight = round($origHeight / $ratio);
|
||||
$resized = imagecreatetruecolor($newWidth, $newHeight);
|
||||
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
|
||||
|
||||
// determine type and store to disk
|
||||
$explodeResult = explode(".", $value);
|
||||
$type = strtolower($explodeResult[count($explodeResult) - 1]);
|
||||
$writeFunc = 'image' . $type;
|
||||
if ($type == 'jpeg' || $type == 'jpg') {
|
||||
imagejpeg($resized, $value, 100);
|
||||
} else {
|
||||
$writeFunc($resized, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Check if a field is empty but only when specific fields have specific values
|
||||
*
|
||||
* WARNING: you need to include this file directly when using it, it clashes with the
|
||||
* way zf1 Zend_Loader_PluginLoader expects it to be found. Another way around this
|
||||
* might be to rename the class and have the new name get loaded proper.
|
||||
*
|
||||
* Since this is only getting used in a few places I am re-adding the
|
||||
* require_once there to get this fixed for now.
|
||||
*/
|
||||
class ConditionalNotEmpty extends Zend_Validate_Abstract
|
||||
{
|
||||
const KEY_IS_EMPTY = 'keyIsEmpty';
|
||||
|
||||
protected $_messageTemplates;
|
||||
|
||||
protected $_fieldValues;
|
||||
|
||||
/**
|
||||
* Constructs a new ConditionalNotEmpty validator.
|
||||
*
|
||||
* @param array $fieldValues - the names and expected values of the fields we're depending on;
|
||||
* E.g., if we have a field that should only be validated when two other
|
||||
* fields PARENT_1 and PARENT_2 have values of '1' and '0' respectively, then
|
||||
* $fieldValues should contain ('PARENT_1'=>'1', 'PARENT_2'=>'0')
|
||||
*/
|
||||
public function __construct($fieldValues)
|
||||
{
|
||||
$this->_fieldValues = $fieldValues;
|
||||
$this->_messageTemplates = array(
|
||||
self::KEY_IS_EMPTY => _("Value is required and can't be empty")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Zend_Validate_Abstract.
|
||||
* Given names and expected values of the fields we're depending on ($_fieldValues),
|
||||
* this function returns true if the expected values doesn't match the actual user input,
|
||||
* or if $value is not empty. Returns false otherwise.
|
||||
*
|
||||
* @param String $value - this field's value
|
||||
* @param array $context - names and values of the rest of the fields in this form
|
||||
* @return boolean - true if valid; false otherwise
|
||||
*/
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
if ($value != "") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_array($context)) {
|
||||
foreach ($this->_fieldValues as $fieldName=>$fieldValue) {
|
||||
if (!isset($context[$fieldName]) || $context[$fieldName] != $fieldValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} elseif (is_string($context)) {
|
||||
if (!isset($context) || $context != $fieldValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_error(self::KEY_IS_EMPTY);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
29
legacy/application/forms/helpers/CustomDecorators.php
Normal file
29
legacy/application/forms/helpers/CustomDecorators.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/** Hide a Zend_Form_Element unless you're logged in as a SuperAdmin. */
|
||||
class Airtime_Decorator_SuperAdmin_Only extends Zend_Form_Decorator_Abstract
|
||||
{
|
||||
public function render($content)
|
||||
{
|
||||
$currentUser = Application_Model_User::getCurrentUser();
|
||||
if ($currentUser->isSuperAdmin()) {
|
||||
return $content;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Hide a Zend_Form_Element unless you're logged in as an Admin or SuperAdmin. */
|
||||
class Airtime_Decorator_Admin_Only extends Zend_Form_Decorator_Abstract
|
||||
{
|
||||
public function render($content)
|
||||
{
|
||||
$currentUser = Application_Model_User::getCurrentUser();
|
||||
if ($currentUser->isSuperAdmin() || $currentUser->isAdmin()) {
|
||||
return $content;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
96
legacy/application/forms/helpers/ValidationTypes.php
Normal file
96
legacy/application/forms/helpers/ValidationTypes.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
Class Application_Form_Helper_ValidationTypes {
|
||||
|
||||
public static function overrideNotEmptyValidator()
|
||||
{
|
||||
$validator = new Zend_Validate_NotEmpty();
|
||||
$validator->setMessage(
|
||||
_("Value is required and can't be empty"),
|
||||
Zend_Validate_NotEmpty::IS_EMPTY
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideEmailAddressValidator()
|
||||
{
|
||||
$validator = new Zend_Validate_EmailAddress();
|
||||
$validator->setMessage(
|
||||
_("'%value%' is no valid email address in the basic format local-part@hostname"),
|
||||
Zend_Validate_EmailAddress::INVALID_FORMAT
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrrideDateValidator($p_format)
|
||||
{
|
||||
$validator = new Zend_Validate_Date();
|
||||
|
||||
$validator->setFormat($p_format);
|
||||
|
||||
$validator->setMessage(
|
||||
_("'%value%' does not fit the date format '%format%'"),
|
||||
Zend_Validate_Date::FALSEFORMAT
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideRegexValidator($p_pattern, $p_msg)
|
||||
{
|
||||
$validator = new Zend_Validate_Regex($p_pattern);
|
||||
|
||||
$validator->setMessage(
|
||||
$p_msg,
|
||||
Zend_Validate_Regex::NOT_MATCH
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideStringLengthValidator($p_min, $p_max)
|
||||
{
|
||||
$validator = new Zend_Validate_StringLength();
|
||||
$validator->setMin($p_min);
|
||||
$validator->setMax($p_max);
|
||||
|
||||
$validator->setMessage(
|
||||
_("'%value%' is less than %min% characters long"),
|
||||
Zend_Validate_StringLength::TOO_SHORT
|
||||
);
|
||||
|
||||
$validator->setMessage(
|
||||
_("'%value%' is more than %max% characters long"),
|
||||
Zend_Validate_StringLength::TOO_LONG
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overrideBetweenValidator($p_min, $p_max)
|
||||
{
|
||||
$validator = new Zend_Validate_Between($p_min, $p_max, true);
|
||||
|
||||
$validator->setMessage(
|
||||
_("'%value%' is not between '%min%' and '%max%', inclusively"),
|
||||
Zend_Validate_Between::NOT_BETWEEN
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public static function overridePasswordIdenticalValidator($p_matchAgainst)
|
||||
{
|
||||
$validator = new Zend_Validate_Identical();
|
||||
$validator->setToken($p_matchAgainst);
|
||||
|
||||
$validator->setMessage(
|
||||
_("Passwords do not match"),
|
||||
Zend_Validate_Identical::NOT_SAME
|
||||
);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue