Esempio n. 1
0
function generate_search_criteria(&$vars)
{
    global $booking_types, $select_options;
    global $private_somewhere, $approval_somewhere, $confirmation_somewhere;
    global $user_level, $tbl_entry, $tbl_area, $tbl_room;
    global $field_natures, $field_lengths;
    global $report_search_field_order;
    echo "<fieldset>\n";
    echo "<legend>" . get_vocab("search_criteria") . "</legend>\n";
    foreach ($report_search_field_order as $key) {
        switch ($key) {
            case 'report_start':
                echo "<div id=\"div_report_start\">\n";
                echo "<label>" . get_vocab("report_start") . ":</label>\n";
                genDateSelector("from_", $vars['from_day'], $vars['from_month'], $vars['from_year']);
                echo "</div>\n";
                break;
            case 'report_end':
                echo "<div id=\"div_report_end\">\n";
                echo "<label>" . get_vocab("report_end") . ":</label>\n";
                genDateSelector("to_", $vars['to_day'], $vars['to_month'], $vars['to_year']);
                echo "</div>\n";
                break;
            case 'areamatch':
                $options = sql_query_array("SELECT area_name FROM {$tbl_area} ORDER BY area_name");
                if ($options === FALSE) {
                    trigger_error(sql_error(), E_USER_WARNING);
                    fatal_error(FALSE, get_vocab("fatal_db_error"));
                }
                echo "<div id=\"div_areamatch\">\n";
                $params = array('label' => get_vocab("match_area") . ':', 'name' => 'areamatch', 'options' => $options, 'force_indexed' => TRUE, 'value' => $vars['areamatch']);
                generate_datalist($params);
                echo "</div>\n";
                break;
            case 'roommatch':
                // (We need DISTINCT because it's possible to have two rooms of the same name
                // in different areas)
                $options = sql_query_array("SELECT DISTINCT room_name FROM {$tbl_room} ORDER BY room_name");
                if ($options === FALSE) {
                    trigger_error(sql_error(), E_USER_WARNING);
                    fatal_error(FALSE, get_vocab("fatal_db_error"));
                }
                echo "<div id=\"div_roommatch\">\n";
                $params = array('label' => get_vocab("match_room") . ':', 'name' => 'roommatch', 'options' => $options, 'force_indexed' => TRUE, 'value' => $vars['roommatch']);
                generate_datalist($params);
                echo "</div>\n";
                break;
            case 'typematch':
                echo "<div id=\"div_typematch\">\n";
                $options = array();
                foreach ($booking_types as $type) {
                    $options[$type] = get_type_vocab($type);
                }
                $params = array('label' => get_vocab("match_type") . ':', 'name' => 'typematch[]', 'id' => 'typematch', 'options' => $options, 'force_assoc' => TRUE, 'value' => $vars['typematch'], 'multiple' => TRUE, 'attributes' => 'size="5"');
                generate_select($params);
                echo "<span>" . get_vocab("ctrl_click_type") . "</span>\n";
                echo "</div>\n";
                break;
            case 'namematch':
                echo "<div id=\"div_namematch\">\n";
                $params = array('label' => get_vocab("match_entry") . ':', 'name' => 'namematch', 'value' => $vars['namematch']);
                generate_input($params);
                echo "</div>\n";
                break;
            case 'descrmatch':
                echo "<div id=\"div_descrmatch\">\n";
                $params = array('label' => get_vocab("match_descr") . ':', 'name' => 'descrmatch', 'value' => $vars['descrmatch']);
                generate_input($params);
                echo "</div>\n";
                break;
            case 'creatormatch':
                echo "<div id=\"div_creatormatch\">\n";
                $params = array('label' => get_vocab("createdby") . ':', 'name' => 'creatormatch', 'value' => $vars['creatormatch']);
                generate_input($params);
                echo "</div>\n";
                break;
            case 'match_private':
                // Privacy status
                // Only show this part of the form if there are areas that allow private bookings
                if ($private_somewhere) {
                    // 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 (empty($user_level)) {
                        echo "<input type=\"hidden\" name=\"match_private\" value=\"" . PRIVATE_NO . "\">\n";
                    } else {
                        echo "<div id=\"div_privacystatus\">\n";
                        $options = array(PRIVATE_BOTH => get_vocab("both"), PRIVATE_NO => get_vocab("default_public"), PRIVATE_YES => get_vocab("default_private"));
                        $params = array('label' => get_vocab("privacy_status") . ':', 'name' => 'match_private', 'options' => $options, 'value' => $vars['match_private']);
                        generate_radio_group($params);
                        echo "</div>\n";
                    }
                }
                break;
            case 'match_confirmed':
                // Confirmation status
                // Only show this part of the form if there are areas that require approval
                if ($confirmation_somewhere) {
                    echo "<div id=\"div_confirmationstatus\">\n";
                    $options = array(CONFIRMED_BOTH => get_vocab("both"), CONFIRMED_YES => get_vocab("confirmed"), CONFIRMED_NO => get_vocab("tentative"));
                    $params = array('label' => get_vocab("confirmation_status") . ':', 'name' => 'match_confirmed', 'options' => $options, 'value' => $vars['match_confirmed']);
                    generate_radio_group($params);
                    echo "</div>\n";
                }
                break;
            case 'match_approved':
                // Approval status
                // Only show this part of the form if there are areas that require approval
                if ($approval_somewhere) {
                    echo "<div id=\"div_approvalstatus\">\n";
                    $options = array(APPROVED_BOTH => get_vocab("both"), APPROVED_YES => get_vocab("approved"), APPROVED_NO => get_vocab("awaiting_approval"));
                    $params = array('label' => get_vocab("approval_status") . ':', 'name' => 'match_approved', 'options' => $options, 'value' => $vars['match_approved']);
                    generate_radio_group($params);
                    echo "</div>\n";
                }
                break;
            default:
                // Must be a custom field
                $var = "match_{$key}";
                global ${$var};
                $params = array('label' => get_loc_field_name($tbl_entry, $key) . ':', 'name' => $var, 'value' => isset(${$var}) ? ${$var} : NULL);
                echo "<div>\n";
                // Output a checkbox 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) {
                    generate_checkbox($params);
                } else {
                    // If $select_options is defined we want to force a <datalist> and not a
                    // <select>.  That's because if we have options such as
                    // ('tea', 'white coffee', 'black coffee') we want the user to be able to type
                    // 'coffee' which will match both 'white coffee' and 'black coffee'.
                    if (isset($select_options["entry.{$key}"]) && !empty($select_options["entry.{$key}"])) {
                        $params['options'] = $select_options["entry.{$key}"];
                        // We force the values to be used and not the keys.   We will convert
                        // back to values when we construct the SQL query.
                        $params['force_indexed'] = TRUE;
                        generate_datalist($params);
                    } else {
                        $params['field'] = "entry.{$key}";
                        generate_input($params);
                    }
                }
                echo "</div>\n";
                break;
        }
        // switch
    }
    echo "</fieldset>\n";
}
Esempio n. 2
0
function create_field_entry_custom_field($field, $key, $disabled = FALSE)
{
    global $custom_fields, $tbl_entry;
    global $is_mandatory_field, $text_input_max, $maxlength;
    echo "<div>\n";
    $params = array('label' => get_loc_field_name($tbl_entry, $key) . ":", 'name' => VAR_PREFIX . $key, 'value' => isset($custom_fields[$key]) ? $custom_fields[$key] : NULL, 'disabled' => $disabled, 'attributes' => array(), 'maxlength' => isset($maxlength["entry.{$key}"]) ? $maxlength["entry.{$key}"] : NULL, 'mandatory' => isset($is_mandatory_field["entry.{$key}"]) && $is_mandatory_field["entry.{$key}"]);
    // Output a checkbox if it's a boolean or integer <= 2 bytes (which we will
    // assume are intended to be booleans)
    if ($field['nature'] == 'boolean' || $field['nature'] == 'integer' && isset($field['length']) && $field['length'] <= 2) {
        generate_checkbox($params);
    } elseif ($field['nature'] == 'character' && isset($field['length']) && $field['length'] > $text_input_max) {
        // HTML5 does not allow a pattern attribute for the textarea element
        $params['attributes'][] = 'rows="8"';
        $params['attributes'][] = 'cols="40"';
        generate_textarea($params);
    } else {
        $is_integer_field = $field['nature'] == 'integer' && $field['length'] > 2;
        if ($is_integer_field) {
            $params['type'] = 'number';
            $params['step'] = '1';
        } else {
            $params['type'] = 'text';
            if ($params['mandatory']) {
                // 'required' is not sufficient for strings, because we also want to make sure
                // that the string contains at least one non-whitespace character
                $params['pattern'] = REGEX_TEXT_POS;
            }
        }
        $params['field'] = "entry.{$key}";
        generate_input($params);
    }
    echo "</div>\n";
}
 echo "<div>\n";
 $params = array('label' => get_vocab("enable_reminders") . ":", 'name' => 'area_reminders_enabled', 'value' => $reminders_enabled);
 generate_checkbox($params);
 echo "</div>\n";
 echo "</fieldset>\n";
 echo "<fieldset>\n";
 echo "<legend>" . get_vocab("private_settings") . "</legend>\n";
 // Private enabled
 echo "<div>\n";
 $params = array('label' => get_vocab("allow_private") . ":", 'name' => 'area_private_enabled', 'value' => $private_enabled);
 generate_checkbox($params);
 echo "</div>\n";
 // Private mandatory
 echo "<div>\n";
 $params = array('label' => get_vocab("force_private") . ":", 'name' => 'area_private_mandatory', 'value' => $private_mandatory);
 generate_checkbox($params);
 echo "</div>\n";
 // Default privacy settings
 $options = array('1' => get_vocab("default_private"), '0' => get_vocab("default_public"));
 $params = array('label' => get_vocab("default_settings"), 'name' => 'area_private_default', 'options' => $options, 'force_assoc' => TRUE, 'value' => $private_default ? '1' : '0');
 generate_radio_group($params);
 echo "</fieldset>\n";
 echo "<fieldset>\n";
 echo "<legend>" . get_vocab("private_display") . "</legend>\n";
 echo "<label>" . get_vocab("private_display_label");
 echo "<span id=\"private_display_caution\">";
 echo get_vocab("private_display_caution");
 echo "</span>";
 echo "</label>\n";
 echo "<div class=\"group\" id=\"private_override\">\n";
 $options = array('none' => get_vocab("treat_respect"), 'private' => get_vocab("treat_private"), 'public' => get_vocab("treat_public"));
Esempio n. 4
0
function create_field_entry_max_duration()
{
    global $max_duration_enabled, $max_duration_secs, $max_duration_periods;
    // The max duration policies
    echo "<fieldset>\n";
    echo "<legend>" . get_vocab("booking_durations") . "</legend>\n";
    echo "<div>\n";
    $params = array('label' => get_vocab("max_duration") . ":", 'name' => 'area_max_duration_enabled', 'value' => $max_duration_enabled, 'class' => 'enabler');
    generate_checkbox($params);
    echo "</div>\n";
    echo "<div>\n";
    $attributes = array('class="text"', 'type="number"', 'min="0"', 'step="1"');
    $params = array('name' => 'area_max_duration_periods', 'label' => get_vocab("mode_periods") . ':', 'value' => $max_duration_periods, 'attributes' => $attributes);
    generate_input($params);
    echo "</div>\n";
    echo "<div>\n";
    $max_duration_value = $max_duration_secs;
    toTimeString($max_duration_value, $max_duration_units);
    $attributes = array('class="text"', 'type="number"', 'min="0"', 'step="1"');
    $params = array('name' => 'area_max_duration_value', 'label' => get_vocab("mode_times") . ':', 'value' => $max_duration_value, 'attributes' => $attributes);
    generate_input($params);
    $units = array("seconds", "minutes", "hours", "days", "weeks");
    $options = array();
    foreach ($units as $unit) {
        $options[$unit] = get_vocab($unit);
    }
    $params = array('name' => 'area_max_duration_units', 'value' => array_search($max_duration_units, $options), 'options' => $options);
    generate_select($params);
    echo "</div>\n";
    echo "</fieldset>\n";
}