setAttribute('id', 'div_report_start') ->setLabel($label) ->setControlAttributes(array( 'name' => 'from_date', 'value' => $data['from_date'], 'aria-label' => $label, 'required' => true) ); return $field; } function get_field_to_date(array $data) : FieldInputDate { $label = get_vocab('report_end'); $field = new FieldInputDate(); $field->setAttribute('id', 'div_report_end') ->setLabel($label) ->setControlAttributes(array( 'name' => 'to_date', 'value' => $data['to_date'], 'aria-label' => $label, 'required' => true) ); return $field; } function get_field_areamatch(array $data) : FieldInputDatalist { $label = get_vocab('match_area'); $field = new FieldInputDatalist(); $options = get_area_names(true); $field->setAttribute('id', 'div_areamatch') ->setLabel($label) ->setControlAttributes(array( 'name' => 'areamatch', 'value' => $data['areamatch'], 'aria-label' => $label)) ->addDatalistOptions($options, false); return $field; } function get_field_roommatch(array $data) : FieldInputDatalist { $label = get_vocab('match_room'); $field = new FieldInputDatalist(); // (We need DISTINCT because it's possible to have two rooms of the same name // in different areas) $sql = "SELECT DISTINCT room_name FROM " . _tbl('room'); // Don't show the invisible rooms $invisible_room_ids = get_invisible_room_ids(); if (count($invisible_room_ids) > 0) { $sql .= " WHERE id NOT IN (" . implode(',', $invisible_room_ids) . ")"; } $sql .= " ORDER BY room_name"; $options = db()->query_array($sql); $field->setAttribute('id', 'div_roommatch') ->setLabel($label) ->setControlAttributes(array( 'name' => 'roommatch', 'value' => $data['roommatch'], 'aria-label' => $label)) ->addDatalistOptions($options, false); return $field; } function get_field_typematch(array $data) : ?FieldSelect { $options = get_type_options(true); if (count($options) < 2) { return null; } $field = new FieldSelect(); $field->setAttributes(array('id' => 'div_typematch', 'class' => 'multiline')) ->setLabel(get_vocab('match_type')) ->setLabelAttribute('title', get_vocab('ctrl_click_type')) ->setControlAttributes(array('id' => 'typematch', 'name' => 'typematch[]', 'multiple' => true, 'size' => '5')) ->addSelectOptions($options, $data['typematch'], true); return $field; } function get_field_match_private(array $data) : ?Element { global $mrbs_user, $private_somewhere; // Only show this part of the form if there are areas that allow private bookings if (!$private_somewhere) { return null; } // If they're not logged in then there's no point in showing this part of the form because // they'll only be able to see public bookings anyway (and we don't want to alert them to // the existence of private bookings) if (!isset($mrbs_user) || ($mrbs_user->level == 0)) { $field = new ElementInputHidden(); $field->setAttributes(array('name' => 'match_private', 'value' => BOOLEAN_MATCH_FALSE)); } else { $options = array(BOOLEAN_MATCH_BOTH => get_vocab('both'), BOOLEAN_MATCH_FALSE => get_vocab('default_public'), BOOLEAN_MATCH_TRUE => get_vocab('default_private')); $field = new FieldInputRadioGroup(); $field->setAttribute('id', 'div_privacystatus') ->setLabel(get_vocab('privacy_status')) ->addRadioOptions($options, 'match_private', $data['match_private'], true); } return $field; } function get_field_match_confirmed(array $data) : ?FieldInputRadioGroup { global $confirmation_somewhere; // Only show this part of the form if there are areas that allow tentative bookings if (!$confirmation_somewhere) { return null; } $options = array(BOOLEAN_MATCH_BOTH => get_vocab('both'), BOOLEAN_MATCH_TRUE => get_vocab('confirmed'), BOOLEAN_MATCH_FALSE => get_vocab('tentative')); $field = new FieldInputRadioGroup(); $field->setAttribute('id', 'div_confirmationstatus') ->setLabel(get_vocab('confirmation_status')) ->addRadioOptions($options, 'match_confirmed', $data['match_confirmed'], true); return $field; } function get_field_match_approved(array $data) : ?FieldInputRadioGroup { global $approval_somewhere; // Only show this part of the form if there are areas that require approval if (!$approval_somewhere) { return null; } $options = array(BOOLEAN_MATCH_BOTH => get_vocab('both'), BOOLEAN_MATCH_TRUE => get_vocab('approved'), BOOLEAN_MATCH_FALSE => get_vocab('awaiting_approval')); $field = new FieldInputRadioGroup(); $field->setAttribute('id', 'div_approvalstatus') ->setLabel(get_vocab('approval_status')) ->addRadioOptions($options, 'match_approved', $data['match_approved'], true); return $field; } function get_field_custom(array $data, string $key) : Field { $var = "match_$key"; global $$var; global $field_natures, $field_lengths; $name = $var; $label = get_loc_field_name(_tbl('entry'), $key); // Output a radio group if it's a boolean or integer <= 2 bytes (which we will // assume are intended to be booleans) if (($field_natures[$key] == 'boolean') || (($field_natures[$key] == 'integer') && isset($field_lengths[$key]) && ($field_lengths[$key] <= 2)) ) { $options = array(BOOLEAN_MATCH_BOTH => get_vocab('both'), BOOLEAN_MATCH_TRUE => get_vocab('with'), BOOLEAN_MATCH_FALSE => get_vocab('without')); $value = (isset($$var)) ? $$var : BOOLEAN_MATCH_BOTH; $field = new FieldInputRadioGroup(); $field->setAttribute('id', "div_$name") ->setLabel($label) ->addRadioOptions($options, $name, $value, true); } else { $params = array('label' => $label, 'name' => $name, 'value' => (isset($$var)) ? $$var : null, 'field' => "entry.$key"); $field = get_field_report_input($params); } return $field; } // Generates a text input field of some kind. If $select_options or $datalist_options // is set then it will be a datalist, otherwise it will be a simple input field // $params an array indexed by 'label', 'name', 'value' and 'field' function get_field_report_input(array $params) : Field { global $select_options, $datalist_options; // If $select_options is defined we want to force a and not a //