// $record[$field_name] = mysql_get_foreign_key_text( $mysql_connect_id, $fkey_fields[0], $fkey_fields[1], array( $fkey_fields[2] => $record[$field_name] ), $fkey_fields[3] ); // } else { // $record[$field_name] = mysql_get_foreign_key_text( $mysql_connect_id, $features['fkey']['DB'], $features['fkey']['TB'], array( $features['fkey']['FIELD_KEY'] => $record[$field_name] ), $features['fkey']['FIELD_DISPLAY'] ); // } if (!$reference_array[$field_name]) { if (is_string($features['fkey'])) { $fkey_fields = explode(",", $features['fkey']); if (!$fkey_fields[3]) { $fkey_fields[3] = $fkey_fields[2]; } $reference_array[$field_name] = mysql_get_foreign_key_list($mysql_connect_id, $fkey_fields[0], $fkey_fields[1], $fkey_fields[2], $fkey_fields[3], $fkey_fields[4], $fkey_fields[5]); } else { if (!$features['fkey']['FIELD_DISPLAY']) { $features['fkey']['FIELD_DISPLAY'] = $features['fkey']['FIELD_KEY']; } $reference_array[$field_name] = mysql_get_foreign_key_list($mysql_connect_id, $features['fkey']['DB'], $features['fkey']['TB'], $features['fkey']['FIELD_KEY'], $features['fkey']['FIELD_DISPLAY'], $features['fkey']['WHERE_CLAUSE'], $features['fkey']['ORDER_BY']); } } $multiple_values = explode(",", $record[$field_name]); $multiple_results = array(); foreach ($multiple_values as $value) { $multiple_results[] = $reference_array[$field_name][$value]; } $record[$field_name] = join(", ", $multiple_results); } else { if ($features['build_cat']) { if (!$reference_array[$field_name]) { $field_properties = $features; if ($field_properties['build_cat']['fkey']) { $field_properties['fkey'] = $field_properties['build_cat']['fkey']; if (is_string($field_properties['fkey'])) {
function mysql_generate_form($connect_id, $table, $fields_to_display = "", $fields_to_display_properties = array(), $edit_record_values = array(), $form_properties = array(), $edit_mode = 0) { global $form_field_input_format; $table_structure = mysql_table_structure($connect_id, $table); if (!$fields_to_display) { $fields_to_display = $table_structure; $structure_used = 1; } else { # if $fields_to_display is set then it should be an non-associated array of the field names # example - ( 'id', 'name', 'country_code' ) foreach ($fields_to_display as $value) { if ($table_structure[$value]) { # verifies that the field is actually in the table $fields_to_display1[$value] = ""; } } $fields_to_display = $fields_to_display1; } $form_field_group_name = $form_properties['form_field_group_name'] ? $form_properties['form_field_group_name'] : "fieldz"; $field_name_column_width = $form_properties['field_name_width'] ? " width=\"{$form_properties['field_name_width']}\"" : ""; $field_name_extra = $field_name_column_width; $field_input_align = $form_properties['field_input_align'] ? " align=\"{$form_properties['field_input_align']}\"" : ""; $field_input_extra = $field_input_align; foreach ($fields_to_display as $key => $field_properties) { if ($fields_to_display_properties) { $field_structure = $fields_to_display_properties[$key]; if ($field_structure) { # If field properties are set for this field in $fields_to_display_properties then # put them into $field_structure $field_properties = $field_structure; #foreach ( $field_structure as $keyz => $value ) { # if ( !$field_properties[$keyz] ) { # $field_properties[$keyz] = $value; # } #} } } if (!$structure_used) { # Add mysql structure fields returned from the mysql_table_structure function including # 'type', 'size', 'others', 'null', 'keys', 'default', 'extra', if they are not already sent # in the $fields_to_display_properties array $field_structure = $table_structure[$key]; foreach ($field_structure as $keyz => $value) { if (!$field_properties[$keyz]) { $field_properties[$keyz] = $value; } } } # -------------- FIELD FEATURES ----------------------- # value - if set, its contents will be added to the field # size - if set, it is used to set the maximum characters which can be entered in the field # html_addon - addition html code which will be added to the field # TEXTBOX attributes # set_password - if set, a text field will stars in it # width - if set, it will be used to set a fields width # multiline - FORMAT - width,height [field type change to 'tinytext'] # if set, it converts a text field to a textarea with the provided dimension # multibox - if set, it converts a text field to multiple text boxes which will be separated with \r\n # TEXTAREA attributes # text_wrap - if set, a textarea will have the text wrap feature # dimension - if set, it will be used to set a fields width and height # singleline - FORMAT width [field type change to 'varchar'] # LISTBOX attributes # multi_select - if set, drop down menus will appear as listbox with the mutliselect feature # sort_enum - if set, enum/set fields will be sorted # enum - FORMAT - value=field,value=field,...... [field type change 'enum'] # if set, it converts a field to a drop down menu # boolen_yn - if set, the listbox will have 'Yes' and 'No' entries # OTHERS # css_style - if set, the provided css style will be used for the field # html_style - if set, its contents will be added in ' style=""' and added to the fields html code # display_html - if set, the html code found in it will be displayed [field type change to 'html'] # -------------- Non-MySQL types ----------------------- # html - html code to replace the generated html code # fkey - contains an array with 'DB' as database_name, 'TB' as table name, 'FIELD_KEY' as the foreign # 'FIELD_KEY' as the foreign key field in the table and 'FIELD_DISPLAY' as the fields in the # table that should be displayed in place of the value in 'FIELD_DISPLAY' # build_cat - builds a tree like list if ($field_properties['fkey'] or $field_properties['fkey_view']) { if ($field_properties['fkey_view']) { $field_properties['fkey'] = $field_properties['fkey_view']; } $field_properties['type'] = "enum"; if (is_string($field_properties['fkey'])) { $fkey_fields = explode(",", $field_properties['fkey']); if (!$fkey_fields[3]) { $fkey_fields[3] = $fkey_fields[2]; } $field_properties['enum'] = mysql_get_foreign_key_list($connect_id, $fkey_fields[0], $fkey_fields[1], $fkey_fields[2], $fkey_fields[3], $fkey_fields[4], $fkey_fields[5]); } else { if (!$field_properties['fkey']['FIELD_DISPLAY']) { $field_properties['fkey']['FIELD_DISPLAY'] = $field_properties['fkey']['FIELD_KEY']; } $field_properties['enum'] = mysql_get_foreign_key_list($connect_id, $field_properties['fkey']['DB'], $field_properties['fkey']['TB'], $field_properties['fkey']['FIELD_KEY'], $field_properties['fkey']['FIELD_DISPLAY'], $field_properties['fkey']['WHERE_CLAUSE'], $field_properties['fkey']['ORDER_BY']); } if (!$field_properties['size']) { $field_properties['size'] = ""; } } else { if ($field_properties['build_cat']) { if ($field_properties['build_cat']['fkey']) { $field_properties['fkey'] = $field_properties['build_cat']['fkey']; if (is_string($field_properties['fkey'])) { $fkey_fields = explode(",", $field_properties['fkey']); if (!$fkey_fields[3]) { $fkey_fields[3] = $fkey_fields[2]; } $field_properties['fkey'] = array('DB' => $fkey_fields[0], 'TB' => $fkey_fields[1], 'FIELD_KEY' => $fkey_fields[2], 'FIELD_DISPLAY' => $fkey_fields[3], 'WHERE_CLAUSE' => $fkey_fields[4], 'ORDER_BY' => $fkey_fields[5]); } if ($field_properties['fkey']['FIELDS']) { $fields = $field_properties['fkey']['FIELDS']; } else { if (!$field_properties['fkey']['FIELD_DISPLAY']) { $field_properties['fkey']['FIELD_DISPLAY'] = $field_properties['fkey']['FIELD_KEY']; } $fields = $field_properties['fkey']['FIELD_KEY'] . "," . $field_properties['fkey']['FIELD_DISPLAY']; if ($fields == "id,name") { $fields = "id,parent_id,name"; } else { if ($fields == "code,name") { $fields = "code,parent_code,name"; } } } if ($field_properties['fkey']['OPTIONS']) { $options = $field_properties['fkey']['OPTIONS']; } else { if ($field_properties['fkey']['FIELD_KEY'] == "code" and $field_properties['fkey']['OPTIONS']) { $options = array('use_codes' => "Y"); } } $field_properties['build_cat'] = array('DB' => $field_properties['fkey']['DB'], 'TB' => $field_properties['fkey']['TB'], 'FIELDS' => $fields, 'WHERE_CLAUSE' => $field_properties['fkey']['WHERE_CLAUSE'], 'ORDER_BY' => $field_properties['fkey']['ORDER_BY'], 'SEPARATOR' => "||", 'INDENT' => 1, 'OPTIONS' => $options); #print_r2( $field_properties['build_cat'], 1 ); } $field_properties['type'] = "enum"; $database = $field_properties['build_cat']['DB']; if ($database) { $current_db = mysql_current_databse($connect_id); if ($current_db != $database) { mysql_change_db($connect_id, $database); } else { $database = ""; } } $category_records = mysql_make_assoc_array($connect_id, $field_properties['build_cat']['TB'], $field_properties['build_cat']['FIELDS'], $field_properties['build_cat']['WHERE_CLAUSE'], $field_properties['build_cat']['ORDER_BY']); $field_properties['enum'] = build_category_paths($category_records, $field_properties['build_cat']['SEPARATOR'], $field_properties['build_cat']['INDENT'], $field_properties['build_cat']['OPTIONS']); if ($database) { mysql_change_db($connect_id, $current_db); } if (!$field_properties['size']) { $field_properties['size'] = ""; } } } if ($field_properties['title']) { $field_display_name = $field_properties['title']; } else { if (($field_properties['fkey'] or $field_properties['fkey_view'] or $field_properties['build_cat']) and preg_match("/(.*)_id\$/i", $key, $preg_results)) { $field_display_name = convert_field_name($preg_results[1]); } else { #$field_display_name = ucwords( strtolower( str_replace( "_", " ", $key ) ) ); $field_display_name = convert_field_name($key); } } $field_properties['name'] = $key; $field_value = $edit_record_values[$key]; $field_properties['form_field_group_name'] = $form_field_group_name; if ($field_properties['print_value'] and $edit_mode == 1) { $form_field_html = $field_value; } else { if ($field_properties['use_field']) { $form_field_html = str_replace("({$form_field_group_name}}[{$field_properties[use_field]}]", "({$form_field_group_name}}[{$key}]", $form_fields_html[$field_properties['use_field']]); #$form_fields_html[$key] = $form_field_html; } else { $form_field_input_format = ""; $form_field_html = mysql_generate_form_field($connect_id, $table, $key, $field_properties, $field_value, $table_structure, $edit_mode); if (!$form_field_html) { $form_field_html = "Unknown Type [" . $field_properties['type'] . "][" . $field_properties['size'] . "]"; } $form_fields_html[$key] = $form_field_html; if ($form_field_input_format) { $field_display_name .= "</b><br><font size=\"1\" face=\"verdana\">{$form_field_input_format}</font><b>"; } } } if ($field_properties['field_input_under_name'] or $form_properties['field_input_under_name']) { $html_code .= "<tr><td colspan=\"2\" style=\"padding: 5\"><b>{$field_display_name}</b><br>{$form_field_html}</td></tr>\r\n"; } else { $html_code .= "<tr><td valign=\"top\" style=\"padding: 7 0 5 5\"{$field_name_extra}><b>{$field_display_name}</b></td><td style=\"padding: 5 5 5 0\"{$field_input_extra}>{$form_field_html}</td></tr>\r\n"; } $html_code .= '<tr><td colspan="2" bgcolor="#808080"><img src="/images/non.gif" width="1" height="1"></td></tr>' . "\r\n"; } $submit_record_title = "Submit Record"; if ($form_properties['submit_button_title']) { $submit_record_title = $form_properties['submit_button_title']; } $html_code .= '<tr><td colspan="2" align="center" style="padding: 5 0 0"><input type="submit" name="submit" value="' . $submit_record_title . '">'; if ($form_properties['other_submit_buttons']) { $other_submit_button_texts = explode(",", $form_properties['other_submit_buttons']); foreach ($other_submit_button_texts as $other_submit_button_text) { $html_code .= ' <input type="submit" name="submit" value="' . $other_submit_button_text . '">'; } } if (!$form_properties['no_reset']) { $html_code .= ' <input type="reset" name="reset" value="Reset Fields"></td></tr>' . "\r\n"; } $table_width = isset($form_properties['table_width']) ? $form_properties['table_width'] : "98%"; $table_class = $form_properties['table_class'] ? " class='" . $form_properties['table_class'] . "'" : ""; $table_class .= $form_properties['table_style'] ? " style='" . $form_properties['table_style'] . "'" : ""; $result = '<table width="' . $table_width . '" border="0" cellspacing="0" cellpadding="0" align="center"' . $table_class . '>'; $result .= $html_code; $result .= '</table>'; return $result; }