Example #1
0
 public function get_enum_options($field)
 {
     return \k1lib\sql\get_db_table_enum_values($this->db, $this->db_table_name, $field);
 }
Example #2
0
function make_form_select_list(&$field_name, &$value, &$table_config_array, &$error_msg = "")
{
    global $db;
    /*
     * SELECT LIST
     */
    //ENUM drop list
    $select_data_array = array();
    if ($table_config_array[$field_name]['type'] == "enum") {
        $select_data_array = \k1lib\sql\get_db_table_enum_values($db, $table_config_array[$field_name]['table'], $field_name);
    } elseif ($table_config_array[$field_name]['sql'] != "") {
        $table_config_array[$field_name]['sql'];
        $sql_data = \k1lib\sql\sql_query($db, $table_config_array[$field_name]['sql'], TRUE);
        if (!empty($sql_data)) {
            foreach ($sql_data as $row) {
                $select_data_array[$row['value']] = $row['label'];
            }
        }
    } elseif (!empty($table_config_array[$field_name]['refereced_table_name'])) {
        $select_data_array = \k1lib\forms\get_labels_from_table($db, $table_config_array[$field_name]['refereced_table_name']);
    }
    $label_object = new html\label($table_config_array[$field_name]['label'], $field_name, "right inline");
    //    $select_object = new html\select($field_name);
    if (empty($value) && !$table_config_array[$field_name]['null']) {
        $value = $table_config_array[$field_name]['default'];
    }
    if (!empty($error_msg)) {
        $select_html = html\select_list_from_array($field_name, $select_data_array, $value, $table_config_array[$field_name]['null'], "error");
        $html_template = html\load_html_template("label_input_combo-error");
        $html_code = sprintf($html_template, $label_object->generate(), $select_html, $error_msg);
    } else {
        $select_html = html\select_list_from_array($field_name, $select_data_array, $value, $table_config_array[$field_name]['null']);
        $html_template = html\load_html_template("label_input_combo");
        $html_code = sprintf($html_template, $label_object->generate(), $select_html);
    }
    return $html_code;
}