} $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 ); } $database = $field_properties['build_cat']['DB']; if ($database) { $current_db = mysql_current_databse($mysql_connect_id); if ($current_db != $database) { mysql_change_db($mysql_connect_id, $database); } else { $database = ""; } } $category_records = mysql_make_assoc_array($mysql_connect_id, $field_properties['build_cat']['TB'], $field_properties['build_cat']['FIELDS'], $field_properties['build_cat']['WHERE_CLAUSE'], $field_properties['build_cat']['ORDER_BY']); if ($database) { mysql_change_db($mysql_connect_id, $current_db); } $name_field = $field_properties['build_cat']['OPTIONS']['alternative_field_names']['name'] ? $field_properties['build_cat']['OPTIONS']['alternative_field_names']['name'] : "name"; foreach ($category_records as $key => $array) { $category_records_new[$key] = $array[$name_field]; } #$category_records_new = build_category_paths( $category_records, "\\", 0, $field_properties['build_cat']['OPTIONS'] ); $reference_array[$field_name] = $category_records_new; } $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 {
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; }
function get_users_country($connect_id, $ip_address = "", $country_db = "", $country_table = "") { $country_db = $country_db ? $country_db : "theemira_count"; $country_table = $country_table ? $country_table : "ip_to_country"; $ip_address = $ip_address ? $ip_address : $_SERVER['REMOTE_ADDR']; $current_db = mysql_current_databse($connect_id); #preg_match( "/(\d*)\.(\d*)\.(\d*)\.(\d*)/", $_SERVER['REMOTE_ADDR'], $ip_parts ); #$ip_2_long = ($ip_parts[1] * 16777216) + ($ip_parts[2] * 65536) + ($ip_parts[3] * 256) + $ip_parts[4]; $ip_2_long = sprintf("%u", ip2long($ip_address)); if ($current_db != $country_db) { mysql_change_db($connect_id, $country_db); } #$country_record = mysql_extract_records_where( $connect_id, $country_table, array( "ip_from <= $ip_2_long" => '', "ip_to >= $ip_2_long" => '' ) ); $country_record = mysql_extract_records_where($connect_id, $country_table, "ip_from <= {$ip_2_long} AND ip_to >= {$ip_2_long}"); if (!$country_record[1]['country_code2']) { $user_country_code = "UN"; $user_country_name = "Unknown"; } else { $user_country_code = $country_record[1]['country_code2']; $user_country_name = $country_record[1]['country_name']; } if ($current_db != $country_db) { mysql_change_db($connect_id, $current_db); } return array($user_country_code, $user_country_name); }
function mysql_get_foreign_key_text($connect_id, $database, $table, $key_field, $display_fields) { if ($database) { $current_db = mysql_current_databse($connect_id); if ($current_db != $database) { mysql_change_db($connect_id, $database); } else { $database = ""; } } if (!is_array($key_field)) { print "#Error# {$key_field} should be an array [Example - array( 'id' => 'snoop' )]"; } else { if (current($key_field)) { if (preg_match("/field\\[([^\\]]+)\\]/i", $display_fields)) { $display_fields_new = $display_fields; while (preg_match("/field\\[([^\\]]+)\\]/i", $display_fields_new, $preg_results)) { $display_fields_new = str_replace($preg_results[0], "", $display_fields_new); $field_list[] = strtolower($preg_results[1]); } $fields_to_extract = join(",", $field_list); } else { $fields_to_extract = $display_fields; $text_separator = " - "; } $fkey_record = mysql_extract_record_id($connect_id, $table, $key_field, $fields_to_extract); if ($fkey_record) { #$fkey_text = join( $text_separator, $fkey_record ); if ($text_separator) { $fkey_text = join($text_separator, $fkey_record); } else { # Allows formatting of the $display_fields string $display_fields_new = $display_fields; while (preg_match("/field\\[([^\\]]+)\\]/i", $display_fields_new, $preg_results)) { $preg_value = strtolower($preg_results[1]); $display_fields_new = str_replace($preg_results[0], $fkey_record[$preg_value], $display_fields_new); } $bracket_types = array("[" => "]", "<" => ">"); foreach ($bracket_types as $open_bracket => $close_bracket) { $open_bracket = preg_quote($open_bracket); $close_bracket = preg_quote($close_bracket); $preg_query = "/(?:fk|fkey)" . $open_bracket . "([^\\.]+)\\.([^\\.]+)\\.([^=]+)=([^,]+), ([^" . $close_bracket . "]+)" . $close_bracket . "/i"; while (preg_match($preg_query, $display_fields_new, $preg_results)) { # Usage - fkey[database.table.field=value, fieldstodisplay] # Example - fkey[general.city.code=DXB, 'field<name>-field<country_code>'] $preg_results[5] = preg_replace("/^'/", "", $preg_results[5]); $preg_results[5] = preg_replace("/'\$/", "", $preg_results[5]); $text_replace = mysql_get_foreign_key_text($connect_id, $preg_results[1], $preg_results[2], array($preg_results[3] => $preg_results[4]), $preg_results[5]); $display_fields_new = str_replace($preg_results[0], $text_replace, $display_fields_new); } } $fkey_text = str_replace(",", ",", $display_fields_new); } } else { $fkey_text = "FKey [ERROR]"; } } else { $fkey_text = "[NULL]"; } } if ($database) { mysql_change_db($connect_id, $current_db); } return $fkey_text; }