示例#1
0
function get_item_input_field($fieldname, $item_attribute_type_r, $item_r, $value = NULL, $dowrap = TRUE, $prompt_mask = NULL, $onchange_event = NULL, $disabled = FALSE)
{
    if (is_array($item_attribute_type_r)) {
        $s_attribute_type = $item_attribute_type_r['s_attribute_type'];
        $order_no = $item_attribute_type_r['order_no'];
        $prompt = $item_attribute_type_r['prompt'];
        $input_type = $item_attribute_type_r['input_type'];
        $compulsory_ind = $item_attribute_type_r['compulsory_ind'];
        $widget['type'] = $item_attribute_type_r['input_type'];
        $widget['args'][0] = $item_attribute_type_r['input_type_arg1'];
        $widget['args'][1] = $item_attribute_type_r['input_type_arg2'];
        $widget['args'][2] = $item_attribute_type_r['input_type_arg3'];
        $widget['args'][3] = $item_attribute_type_r['input_type_arg4'];
        $widget['args'][4] = $item_attribute_type_r['input_type_arg5'];
    }
    if ($item_attribute_type_r['multi_attribute_ind'] == 'Y') {
        $multi_value = TRUE;
        if (!is_array($value)) {
            $old_value = ifempty($value, "");
            unset($value);
            $value[] = $old_value;
        }
    } else {
        $multi_value = FALSE;
        // an array will be a lookup value
        if (!is_array($value)) {
            // Escape all html entities so they are displayed correctly!
            if (strlen($value) > 0) {
                $value = htmlspecialchars($value);
            }
        }
    }
    $field = NULL;
    $field_mask = NULL;
    // Now we have to work out how to parse the input_type
    if ($item_attribute_type_r['input_type'] == 'hidden') {
        return hidden_field($fieldname, $value);
    } else {
        if ($item_attribute_type_r['input_type'] == 'readonly') {
            $field = readonly_field($fieldname, $value);
        } else {
            if ($item_attribute_type_r['input_type'] == 'textarea' || $item_attribute_type_r['input_type'] == 'htmlarea') {
                // arg[0] = rows, arg[1] = cols, arg[2] = length
                $field = textarea_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $widget['widget']['2'], $compulsory_ind, $value, $onchange_event, $disabled);
            } else {
                if ($item_attribute_type_r['input_type'] == 'text') {
                    // arg[0] = length of field, arg[1] = maxlength of field
                    $field = text_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                } else {
                    if ($item_attribute_type_r['input_type'] == 'password') {
                        // arg[0] = length of field, arg[1] = maxlength of field
                        $field = password_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                    } else {
                        if ($item_attribute_type_r['input_type'] == 'email') {
                            // arg[0] = length of field, arg[1] = maxlength of field
                            $field = email_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                        } else {
                            if ($item_attribute_type_r['input_type'] == 'filtered') {
                                // arg[0] = length of field, arg[1] = maxlength of field, arg[2] = legalChars
                                $field = filtered_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $widget['args']['2'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                            } else {
                                if ($item_attribute_type_r['input_type'] == 'datetime') {
                                    // arg[0] = datetime mask, arg[1] = auto_datetime
                                    $field = datetime_field($fieldname, $prompt, ifempty($widget['args']['0'], 'DD/MM/YYYY'), $widget['args']['1'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                                } else {
                                    if ($item_attribute_type_r['input_type'] == 'number') {
                                        // arg[0] = length of field, arg[0] = maxlength of field
                                        $field = number_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['0'], $compulsory_ind, $value, $onchange_event, $disabled, $multi_value);
                                    } else {
                                        if ($item_attribute_type_r['input_type'] == 'simple_checkbox') {
                                            // arg[0] = checked
                                            $field = checkbox_field($fieldname, $prompt, strcasecmp(trim($widget['args']['0']), 'CHECKED') === 0, $value, $onchange_event, $disabled);
                                        } else {
                                            if ($item_attribute_type_r['input_type'] == 'checkbox') {
                                                // arg[0] = checked, arg[1] = unchecked
                                                $field = enhanced_checkbox_field($fieldname, $prompt, $widget['args']['0'], $widget['args']['1'], $value, $onchange_event, $disabled);
                                            } else {
                                                if ($item_attribute_type_r['input_type'] == 'checkbox_grid') {
                                                    $lookup_results = fetch_attribute_type_lookup_rs($s_attribute_type, 'order_no, ' . get_lookup_order_by($widget['args']['0']) . ' ASC');
                                                    if ($lookup_results) {
                                                        //arg[0] = display_mask, arg[1] = orientation
                                                        $field = checkbox_grid($fieldname, $lookup_results, $widget['args']['0'], $widget['args']['1'], $value, $disabled);
                                                    }
                                                } else {
                                                    if ($item_attribute_type_r['input_type'] == 'radio_grid') {
                                                        $lookup_results = fetch_attribute_type_lookup_rs($s_attribute_type, 'order_no, ' . get_lookup_order_by($widget['args']['0']) . ' ASC');
                                                        if ($lookup_results) {
                                                            //arg[0] = display_mask, arg[1] = orientation
                                                            $field = radio_grid($fieldname, $lookup_results, $widget['args']['0'], $widget['args']['1'], $value, $disabled);
                                                        }
                                                    } else {
                                                        if ($item_attribute_type_r['input_type'] == 'value_radio_grid') {
                                                            //arg[0] = "comma delimited list of values"
                                                            $field = value_radio_grid($fieldname, explode(',', $widget['args']['0']), $value, $disabled);
                                                        } else {
                                                            if ($item_attribute_type_r['input_type'] == 'single_select') {
                                                                $lookup_results = fetch_attribute_type_lookup_rs($s_attribute_type, 'order_no, ' . get_lookup_order_by($widget['args']['0']) . ' ASC');
                                                                if ($lookup_results) {
                                                                    //arg[0] = display mask, arg[1] = max value length
                                                                    $field = single_select($fieldname, $lookup_results, $widget['args']['0'], $widget['args']['1'], $value, $onchange_event, $disabled);
                                                                }
                                                            } else {
                                                                if ($item_attribute_type_r['input_type'] == 'multi_select') {
                                                                    $lookup_results = fetch_attribute_type_lookup_rs($s_attribute_type, 'order_no, ' . get_lookup_order_by($widget['args']['0']) . ' ASC');
                                                                    if ($lookup_results) {
                                                                        //arg[0] = display mask, arg[1] = max value length, arg[2] = select box number of visible rows
                                                                        $field = multi_select($fieldname, $lookup_results, $widget['args']['0'], $widget['args']['1'], $widget['args']['2'], $value, $onchange_event, $disabled);
                                                                    }
                                                                } else {
                                                                    if ($item_attribute_type_r['input_type'] == 'value_select') {
                                                                        //arg[0] = "comma delimited list of values"; arg[1] = number of visible rows (Defaults to single select
                                                                        $field = value_select($fieldname, explode(',', $widget['args']['0']), $widget['args']['1'], $value, $onchange_event, $disabled);
                                                                    } else {
                                                                        if ($item_attribute_type_r['input_type'] == 'review_options') {
                                                                            //arg[1] = display_mask, arg[1] = orientation
                                                                            $lookup_results = fetch_attribute_type_lookup_rs($s_attribute_type, 'value DESC');
                                                                            //We want the rows highest value first.
                                                                            if ($lookup_results) {
                                                                                $field = review_options($fieldname, $lookup_results, $widget['args']['0'], $widget['args']['1'], $value, $disabled);
                                                                            }
                                                                        } else {
                                                                            if ($item_attribute_type_r['input_type'] == 'url') {
                                                                                //arg[0] = length of field, arg[1] = maxlength of field, arg[2] = extensions
                                                                                $field = url($fieldname, $item_r, $item_attribute_type_r, $prompt, $widget['args']['0'], $widget['args']['1'], $widget['args']['2'], $value, $onchange_event, $disabled, $multi_value);
                                                                            } else {
                                                                                $field = ">>> ERROR (input_type = {$input_type}) <<<";
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($dowrap) {
        return format_item_data_field($item_attribute_type_r, $field, $prompt_mask);
    } else {
        return $field;
    }
}
示例#2
0
文件: index.php 项目: horrabin/opendb
/**
    boolean - TRUE or FALSE only
    text - arbritrary text
    textarea - arbritrary text
    email - email address
    number - enforce a numeric value
    datemask - enforce a date mask.
    usertype - Restrict to a single user type only.
    usertype_array - Restrict to set of user types only.
    value_select(option1,option2)
    array - keys will be numeric and in sequence only.
*/
function get_group_block_input_field($config_group_item_r, $value)
{
    // replace period with '$', so we can avoid PHP auto-replacing '.' with '_' and the
    // confusion that will bring.
    $config_group_item_r['group_id'] = str_replace('.', '$', $config_group_item_r['group_id']);
    $fieldname = $config_group_item_r['group_id'] . '[' . $config_group_item_r['id'] . ']';
    if ($config_group_item_r['keyid'] != '0') {
        $fieldname .= '[' . $config_group_item_r['keyid'] . ']';
    }
    switch ($config_group_item_r['type']) {
        case 'boolean':
            return checkbox_field($fieldname, $config_group_item_r['prompt'], $value !== NULL && $value === TRUE, 'TRUE');
            break;
        case 'readonly':
            return readonly_field($fieldname, htmlspecialchars($value));
            break;
        case 'text':
            return text_field($fieldname, $config_group_item_r['prompt'], 50, 255, 'N', htmlspecialchars($value));
            break;
        case 'password':
            return password_field($fieldname, $config_group_item_r['prompt'], 50, 255, 'N', htmlspecialchars($value));
            break;
        case 'textarea':
            return textarea_field($fieldname, $config_group_item_r['prompt'], 50, 5, 255, 'N', htmlspecialchars($value));
            break;
        case 'email':
            return email_field($fieldname, $config_group_item_r['prompt'], 50, 255, 'N', htmlspecialchars($value));
            break;
        case 'number':
            return number_field($fieldname, $config_group_item_r['prompt'], 10, 50, 'N', htmlspecialchars($value));
            break;
        case 'datemask':
            return text_field($fieldname, $config_group_item_r['prompt'], 50, 255, 'N', htmlspecialchars($value));
            break;
        case 'instance_attribute_type':
            return custom_select($fieldname, fetch_instance_attribute_type_rs(), '%s_attribute_type% - %description%', 1, $value, 's_attribute_type');
            break;
        case 'language':
            return custom_select($fieldname, fetch_language_rs(), '%language%', 1, $value, 'language', NULL, 'default_ind');
            break;
        case 'theme':
            return custom_select($fieldname, get_user_theme_r(), '%value%', 1, $value);
            break;
        case 'export':
            return custom_select($fieldname, array_merge(array(''), get_export_r()), '%value%', 1, $value);
            break;
        case 'value_select':
            $value_options_r = explode(',', $config_group_item_r['subtype']);
            return value_select($fieldname, $value_options_r, 1, $value);
            break;
        case 'array':
            $buffer = '';
            switch ($config_group_item_r['subtype']) {
                case 'text':
                case 'number':
                    $element_name = $config_group_item_r['group_id'] . "[" . $config_group_item_r['id'] . "][]";
                    $buffer .= "<select name=\"" . $element_name . "\" size=\"5\" MULTIPLE>\n";
                    if (is_array($value)) {
                        reset($value);
                        while (list($key, $val) = each($value)) {
                            $buffer .= "<option value=\"" . $val . "\" SELECTED>" . $val . "\n";
                        }
                    }
                    $buffer .= "</select>";
                    $buffer .= "<ul class=\"actionButtons\">";
                    $buffer .= "<li><input type=\"button\" class=\"button\" value=\"Edit\" onClick=\"updateSelectedOption(this.form['" . $element_name . "'], '" . $config_group_item_r['prompt'] . "', '" . $config_group_item_r['subtype'] . "');\"></li>";
                    $buffer .= "<li><input type=\"button\" class=\"button\" value=\"Add\" onClick=\"addSelectOption(this.form['" . $element_name . "'], '" . $config_group_item_r['prompt'] . "', '" . $config_group_item_r['subtype'] . "');\"></li>";
                    $buffer .= "<li><input type=\"button\" class=\"button\" value=\"Delete\" onClick=\"removeSelectedOption(this.form['" . $element_name . "']);\"></li>";
                    $buffer .= "</ul>";
                    break;
            }
            return $buffer;
    }
    //else
    return '>>> ERROR <<<';
}