コード例 #1
0
function mysql_generate_edit_form($connection_parameters, $table_name, $display_fields = array(), $fields_to_display_properties = array(), $form_properties = array())
{
    global $show_output_code;
    # in order to bring in html to be printed, change '"' to '\"', '$' to '\$', and then regexp '\r\n([^\r\n]+)' to '\r\n         $php_code .= "$1\\r\\n";'
    $php_code = "<?php\r\n";
    if (!$form_properties['single_page']) {
        $php_code .= "   include( \"../../php_lib3/misc.php\" );\r\n";
        $php_code .= "   include( \"../../php_lib3/misc_categories.php\" );\r\n";
        $php_code .= "   include( \"../../php_lib3/mysql.php\" );\r\n\r\n";
    }
    if (is_array($connection_parameters)) {
        $connect_id = mysql_start($connection_parameters['mysql_server'], $connection_parameters['database_name'], $connection_parameters['mysql_username'], $connection_parameters['mysql_password']);
        if (!$form_properties['single_page']) {
            $php_code .= "   \$mysql_server = \"{$connection_parameters['mysql_server']}\";\r\n";
            $php_code .= "   \$mysql_username = \"{$connection_parameters['mysql_username']}\";\r\n";
            $php_code .= "   \$mysql_password = \"{$connection_parameters['mysql_password']}\";\r\n\r\n";
            $php_code .= "   \$database_name = \"{$connection_parameters['database_name']}\";\r\n";
        }
        $php_code .= "   \$table_name = \"{$table_name}\";\r\n";
        $php_code .= "   \$mysql_connect_id = mysql_start( \$mysql_server, \$database_name, \$mysql_username, \$mysql_password );\r\n\r\n";
        $current_database = $connection_parameters['database_name'];
    } else {
        $connect_id = $connection_parameters;
        $current_database = mysql_current_databse($connect_id);
        $connection_parameters['database_name'] = $current_database;
        $php_code .= "   \$database_name = \"{$current_database}\";\r\n";
        $php_code .= "   \$table_name = \"{$table_name}\";\r\n\r\n";
    }
    $form_field_group_name = $form_properties['form_field_group_name'] ? $form_properties['form_field_group_name'] : "fieldz";
    $table_structure = mysql_table_structure($connect_id, $table_name);
    $fields_to_display = array_keys($table_structure);
    $primary_key_field = mysql_primary_key_field($table_structure);
    if ($display_fields['on']) {
        foreach ($display_fields['on'] 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;
    } else {
        if ($display_fields['off']) {
            foreach ($display_fields['off'] as $value) {
                $find_key = array_search($value, $fields_to_display);
                if ($find_key !== False) {
                    unset($fields_to_display[$find_key]);
                }
            }
        } else {
            $all_fields = 1;
        }
    }
    if ($display_fields['hide']) {
        foreach ($display_fields['hide'] as $value) {
            if ($table_structure[$value]) {
                # verifies that the field is actually in the table
                $fields_to_hide[] = $value;
            }
        }
        $fields_to_hide1 = ",`" . join("`,`", $fields_to_hide) . "`";
    }
    if ($all_fields) {
        $fields = "*";
    } else {
        $fields = "`" . join("`,`", $fields_to_display) . "`";
        if (!is_array($fields_to_hide)) {
            $fields_to_hide = array();
        }
        if (!in_array($primary_key_field, $fields_to_display) and !in_array($primary_key_field, $fields_to_hide)) {
            # primary key wasnt found in the lists
            $fields_to_hide1 .= ",`{$primary_key_field}`";
        }
    }
    if (!$form_properties['single_page']) {
        $php_code .= "   \$table_structure = mysql_table_structure( \$mysql_connect_id, \$table_name );\r\n";
        //$php_code .= "   \$primary_key_field = mysql_primary_key_field( \$table_structure );\r\n\r\n";
        $php_code .= "   \$filter_field_names = array_keys( \$table_structure );\r\n";
        $php_code .= "   \$sql_field_names = \"{$fields}{$fields_to_hide1}\";\r\n";
        $php_code .= "   #\$sql_field_names = array_keys( \$table_structure );\r\n";
        $php_code .= "   \$primary_key_field = \"{$primary_key_field}\";\r\n\r\n";
    }
    $php_code .= "   if ( \$FORM['submit'] ) {\r\n";
    $php_code .= "      if ( \$FORM['f'] == \"add\" ) {\r\n";
    $php_code .= "         foreach ( \$FORM['{$form_field_group_name}'] as \$field_name => \$value ) {\r\n";
    $php_code .= "            if ( is_array(\$value) ) {\r\n";
    $php_code .= "               \$add_fields[\$field_name] = join( \",\", \$value );\r\n";
    $php_code .= "            } else {\r\n";
    $php_code .= "               #if ( trim(\$value) ) {\r\n";
    $php_code .= "                  \$add_fields[\$field_name] = trim(\$value);\r\n";
    $php_code .= "               #}\r\n";
    $php_code .= "            }\r\n";
    $php_code .= "         }\r\n\r\n";
    $php_code .= "         \$query_result = mysql_add_record( \"\", \$table_name, \$add_fields );\r\n\r\n";
    $php_code .= "         if ( !\$query_result ) {\r\n";
    $php_code .= "            print \"Error Adding Record\";\r\n";
    $php_code .= "            print mysql_info();\r\n";
    $php_code .= "            print mysql_error();\r\n";
    $php_code .= "            exit;\r\n";
    $php_code .= "         }\r\n";
    $php_code .= "      } else if ( \$FORM['f'] == \"edit\" ) {\r\n";
    $php_code .= "         foreach ( \$FORM['{$form_field_group_name}'] as \$field_name => \$value ) {\r\n";
    $php_code .= "            if ( is_array(\$value) ) {\r\n";
    $php_code .= "               \$update_fields[\$field_name] = join( \",\", \$value );\r\n";
    $php_code .= "            } else {\r\n";
    $php_code .= "               #if ( trim(\$value) ) {\r\n";
    $php_code .= "                  \$update_fields[\$field_name] = trim(\$value);\r\n";
    $php_code .= "               #}\r\n";
    $php_code .= "            }\r\n";
    $php_code .= "         }\r\n";
    if (!$form_properties['single_page']) {
        $php_code .= "         if ( \$FORM['submit'] == \"Save\" ) {\r\n";
        $php_code .= "            mysql_upd_record( \"\", \$table_name, \$update_fields, array( \$primary_key_field => \$FORM['pri_key'] ) );\r\n";
        #$php_code .= "            mysql_upd_record( \"\", \$table_name, \$update_fields, array( \"$primary_key_field\" => \$FORM['pri_key'] ) );\r\n";
        $php_code .= "         } else if ( \$FORM['submit'] == \"Delete\" ) {\r\n";
        $php_code .= "            mysql_del_record( \"\", \$table_name, array( \$primary_key_field => \$FORM['pri_key'] ) );\r\n";
        $php_code .= "         }\r\n";
    } else {
        $php_code .= "         mysql_upd_record( \"\", \$table_name, \$update_fields, array( 'id' => \$FORM['id'] ) );\r\n";
    }
    $php_code .= "      }\r\n";
    if (!$form_properties['single_page']) {
        if ($form_properties['popup_save']) {
            $php_code .= "      close_page();\r\n";
        } else {
            $php_code .= "      header( \"location: \$FORM[ref_url]\" );\r\n";
        }
        $php_code .= "      exit;\r\n";
        $php_code .= "      \$FORM['submit'] = \"\";\r\n";
    } else {
        $php_code .= "      header( \"location: index.php\" );\r\n";
        $php_code .= "      exit;\r\n";
    }
    $php_code .= "   }\r\n\r\n";
    //      $php_code .= "   \$FORM['start'] = ( \$FORM['start'] == \"\" OR \$FORM['start'] < 0 ) ? \"0\" : \$FORM['start'];\r\n";
    //      $php_code .= "   \$edit_record = mysql_extract_records_where( \"\", \$table_name, \"\", \"*\", \"\", \"\$FORM[start],1\" );\r\n";
    //      $php_code .= "   \$FORM['$form_field_group_name'] = \$edit_record[1];\r\n\r\n";
    if (!$form_properties['single_page']) {
        $php_code .= "   \$filter_operators = array( '=' => '', '!=' => '', '<' => '', '>' => '', 'regexp' => '~' );\r\n";
        $php_code .= "   \$total_records = mysql_count_query_records( \"\", \$table_name, \"\" );\r\n";
        $php_code .= "   if ( \$FORM['f'] == \"add\" OR \$total_records == 0 ) {\r\n";
    } else {
        $php_code .= "   if ( \$FORM['f'] == \"add\" ) {\r\n";
    }
    # loads the default entries from db into form
    foreach ($table_structure as $key => $array) {
        if ($array['default']) {
            #$FORM['fieldz'][$key] = $array['default'];
            $php_code .= "      \$FORM['{$form_field_group_name}']['{$key}'] = \"{$array['default']}\";\r\n";
        }
    }
    if (!$form_properties['single_page']) {
        $php_code .= "\r\n";
        $php_code .= "      if ( \$total_records ) {\r\n";
        $php_code .= "         \$FORM['start'] = \$total_records;\r\n";
        $php_code .= "         \$total_records = \$FORM['start'] + 1;\r\n";
        $php_code .= "      }\r\n";
        $php_code .= "      \$save_type = \"add\";\r\n";
        $php_code .= "   } else {\r\n";
        $php_code .= "      if ( \$FORM['where_data'] ) {\r\n";
        $php_code .= "         \$where_clause = \$FORM['where_data'];\r\n";
        $php_code .= "\t\t\t\$recount_total_records = 1;\r\n";
        $php_code .= "      } else if ( \$FORM['filter_field'] ) {\r\n";
        $php_code .= "         \$FORM['filter_data'] = mysql_real_escape_string( \$FORM['filter_data'] );\r\n";
        $php_code .= "         \$where_clause[\"`\$FORM[filter_field]` \$FORM[filter_operator] '\$FORM[filter_data]'\"] = '';\r\n";
        $php_code .= "\t\t\t\$recount_total_records = 1;\r\n";
        $php_code .= "      } else if ( \$FORM['filter_operator'] AND \$FORM['filter_data'] ) {\r\n";
        $php_code .= "         foreach ( \$table_structure as \$key => \$record ) {\r\n";
        $php_code .= "            if ( \$FORM['filter_operator'] == \"=\" ) {\r\n";
        $php_code .= "               # change single slash to double in order for like to handle it properly\r\n";
        $php_code .= "               \$new_value = str_replace( chr(92), chr(92).chr(92), \$FORM['filter_data'] );\r\n";
        $php_code .= "               \$where_clause_filter[] = \"`\$key` LIKE \\\"%\" . mysql_real_escape_string( \$new_value ) . \"%\\\"\";\r\n";
        $php_code .= "            } else {\r\n";
        $php_code .= "               \$where_clause_filter[] = \"`\$key` \$FORM[filter_operator] '\" . mysql_real_escape_string( \$FORM['filter_data'] ) . \"'\";\r\n";
        $php_code .= "            }\r\n";
        $php_code .= "         }\r\n";
        $php_code .= "         \$where_clause[\"( \" . join( \" OR \", \$where_clause_filter ) . \" )\"] = '';\r\n";
        $php_code .= "\t\t\t\$recount_total_records = 1;\r\n";
        $php_code .= "      }\r\n";
        $php_code .= "      if ( \$recount_total_records ) {\r\n";
        $php_code .= "         \$total_records = mysql_count_query_records( \"\", \$table_name, \$where_clause );\r\n";
        $php_code .= "      }\r\n\r\n";
        $php_code .= "      if ( \$FORM['starts'] ) \$FORM['start'] = \$FORM['starts'] - 1;\r\n";
        $php_code .= "      \$FORM['start'] = ( \$FORM['start'] == \"\" OR \$FORM['start'] < 0 ) ? \"0\" : \$FORM['start'];\r\n";
        $php_code .= "      \$edit_record = mysql_extract_records_where( \"\", \$table_name, \$where_clause, \$sql_field_names, \"\", \"\$FORM[start],1\" );\r\n";
        $php_code .= "      if ( \$where_clause AND \$edit_record == 1 ) {\r\n";
        $php_code .= "         print \"No Records Found\";\r\n";
        $php_code .= "         exit;\r\n";
        $php_code .= "      }\r\n";
        $php_code .= "      if ( \$FORM['start'] >= \$total_records ) {\r\n";
        $php_code .= "         header( \"Location: \" . \$_SERVER['PHP_SELF'] . \"?start=\" . (\$total_records - 1) );\r\n";
        $php_code .= "         exit;\r\n";
        $php_code .= "      }\r\n";
        $php_code .= "      \$FORM['fieldz'] = \$edit_record[1];\r\n";
        $php_code .= "      \$primary_key_id = \$edit_record[1][\$primary_key_field];\r\n";
        $php_code .= "      \$save_type = \"edit\";\r\n";
        $php_code .= "   }\r\n";
    } else {
        $php_code .= "   } else {\r\n";
        $php_code .= "      \$FORM['{$form_field_group_name}'] = mysql_extract_record_id( \"\", \$table_name, array( 'id' => \$FORM['id'] ) );\r\n";
        $php_code .= "   }\r\n";
    }
    $php_code .= "\r\n";
    //      print "<pre>";
    //      print_r( $table_structure );
    //      print "</pre>";
    //      print "<pre>";
    //      print_r( $fields_to_display_properties );
    //      print "</pre>";
    foreach ($fields_to_display as $field_name) {
        $field_structure = $table_structure[$field_name];
        $field_properties = $fields_to_display_properties[$field_name];
        #$field_properties = array_merge( $field_structure, $field_properties );
        if ($field_properties['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($connect_id, '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]);
            }
            $fkey_data = $field_properties['fkey'];
            if (!preg_match("/field[\\[<]|fk(?:ey)?[\\[<]/", $fkey_data['FIELD_DISPLAY']) and strtolower($fkey_data['DB']) == strtolower($current_database)) {
                $php_code .= "   \${$field_name}" . "_list = mysql_create_associate_array( \"\", \"{$fkey_data['TB']}\", \"{$fkey_data['FIELD_KEY']},{$fkey_data['FIELD_DISPLAY']}\" );\r\n";
            } else {
                $php_code .= "   \${$field_name}" . "_list = mysql_get_foreign_key_list( \"\", \"{$fkey_data['DB']}\", \"{$fkey_data['TB']}\", \"{$fkey_data['FIELD_KEY']}\", \"{$fkey_data['FIELD_DISPLAY']}\", \"{$fkey_data['WHERE_CLAUSE']}\", \"{$fkey_data['ORDER_BY']}\" );\r\n";
            }
            $field_properties['type'] = "enum";
            $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['build_cat'])) {
                        $fkey_fields = explode(",", $field_properties['fkey']);
                        if (!$fkey_fields[3]) {
                            $fkey_fields[3] = $fkey_fields[2];
                        }
                        $field_properties['fkey'] = array($connect_id, '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);
                }
                $category_data = $field_properties['build_cat'];
                if (strtolower($category_data['DB']) != strtolower($current_database) and $category_data['DB'] != "") {
                    $php_code .= "   mysql_change_db( \"\", \"{$category_data['DB']}\" );\r\n";
                }
                $php_code .= "   \${$field_name}_category_records = mysql_make_assoc_array( \"\", \"{$category_data['TB']}\", \"{$category_data['FIELDS']}\", \"{$category_data['WHERE_CLAUSE']}\", \"{$category_data['ORDER_BY']}\" );\r\n";
                $php_code .= "   \${$field_name}_list = build_category_paths( \${$field_name}_category_records, \"" . addcslashes($category_data['SEPARATOR'], "\"\\") . "\", \"{$category_data['INDENT']}\", " . preg_replace("/;\$/", "", array_to_php($category_data['OPTIONS'])) . " );\r\n";
                if (strtolower($category_data['DB']) != strtolower($current_database) and $category_data['DB'] != "") {
                    $php_code .= "   mysql_change_db( \"\", \"{$current_database}\" );\r\n";
                }
                $field_properties['type'] = "enum";
                $field_properties['size'] = "";
            } else {
                if ($field_properties['enum']) {
                    #$php_code .= "   \$$field_name" . "_list = array( '" . join( "' => \"\", '", $field_properties['enum'] ) . "' => \"\" );\r\n";
                    $php_code .= "   \${$field_name}" . "_list = " . array_to_php($field_properties['enum']) . "\r\n";
                } else {
                    if ($field_structure['type'] == "set" or $field_structure['type'] == "enum") {
                        $php_code .= "   \${$field_name}" . "_list = array( '" . join("' => \"\", '", $field_structure['size']) . "' => \"\" );\r\n";
                    }
                }
            }
        }
        if ($field_properties['multi_select'] or $field_structure['type'] == "set") {
            $php_code .= "   \$FORM['{$form_field_group_name}']['{$field_name}'] = explode( ',', \$FORM['fieldz']['{$field_name}'] );\r\n";
        }
        $field_properties['form_field_group_name'] = $form_field_group_name;
        if (!$field_properties['title']) {
            $field_display_name = convert_field_name($field_name);
        } else {
            $field_display_name = $field_properties['title'];
        }
        $field_properties['name'] = $field_name;
        if (!$form_properties['print_version']) {
            $form_field_html = mysql_generate_form_field($connect_id, $table_name, $field_name, $field_properties, "", $table_structure, 2);
        } else {
            /* $form_field_html = "<?php print \$FORM['$form_field_group_name']['$field_name'] ?>"; */
            if ($field_properties['fkey'] or $field_properties['build_cat']) {
                $form_field_html = "<?php print \${$field_name}_list[\$db_record['{$field_name}']] ?>";
            } else {
                if ($field_structure['type'] == "set") {
                    /* $form_field_html = "<?php print join( \", \", \$db_record['$field_name'] ) ?>"; */
                    $form_field_html = "<?php print str_replace( \",\", \", \", \$db_record['{$field_name}'] ) ?>";
                } else {
                    $form_field_html = "<?php print \$db_record['{$field_name}'] ?>";
                }
            }
        }
        # adds necessary code to textarea are shown correctly in both opera and firefix/ie
        /* preg_match_all( "/(<textarea name=\"[^\"]+\" cols=\"[^\"]+\" rows=\")([^\"]+)(\"[^>]*>)/", $form_field_html, $preg_results, PREG_SET_ORDER );
           foreach ( $preg_results as $array ) {
              $form_field_html = str_replace( $array[0], $array[1]."<?php if ( preg_match( \"/Opera[\\/ ]\\d+\\.\\d+/\", \$_SERVER['HTTP_USER_AGENT'] ) ) { print '$array[2]'; } else { print '" . ($array[2]-1) . "'; } ?>".$array[3], $form_field_html );
           } */
        if (isset($field_properties['print_value'])) {
            $form_field_html = "<?php if ( \$save_type == \"add\" ) { ?>{$form_field_html}<?php } else { print \$FORM['{$form_field_group_name}']['{$field_name}']; } ?>";
        }
        $html_code .= "<tr><td valign=\"top\" class=\"tb_title\"><b>{$field_display_name}</b></td><td class=\"tb_field\">{$form_field_html}</td></tr>\r\n";
        #$html_code .= "<tr><td valign=\"top\" style=\"padding: 7 0 5 5\"><b>$field_display_name</b></td><td style=\"padding: 5 5 5 0\">$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";
    }
    $php_code .= "?>\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"><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";
    //      }
    if (!$form_properties['single_page']) {
        $html_code .= "<tr><td colspan=\"2\" align=\"center\"><table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">\r\n";
        $html_code .= "   <tr>\r\n";
        $html_code .= "      <td style=\"padding-top: 5px\"><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Save\">\r\n";
        $html_code .= "      <input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Delete\">\r\n";
        $html_code .= "         <input name=\"pri_key\" type=\"hidden\" id=\"pri_key\" value=\"<?php print \$primary_key_id ?>\">\r\n";
        $html_code .= "         <input name=\"f\" type=\"hidden\" id=\"f\" value=\"<?php print \$save_type ?>\"> \r\n";
        $html_code .= "         <input type=\"reset\" name=\"Reset\" value=\"Revert\"></td>\r\n";
        $html_code .= "         </tr>\r\n";
        $html_code .= "      </table></td>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "   <input name=\"ref_url\" type=\"hidden\" value=\"<?php print \$_SERVER['REQUEST_URI'] ?>\">\r\n";
    } else {
        $html_code .= "<tr style=\"padding-top: 10px\"><td colspan=\"2\" align=\"center\"><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"Save\">\r\n";
        $html_code .= "   <input name=\"id\" type=\"hidden\" value=\"<?php print \$FORM['id'] ?>\">\r\n";
        $html_code .= "   <input name=\"f\" type=\"hidden\" value=\"<?php print \$FORM['f'] ?>\"></td>\r\n";
        $html_code .= "</tr>\r\n";
    }
    if ($fields_to_hide) {
        //         if ( !$form_properties['single_page'] ) {
        $fields_to_hide = "\"" . join("\", \"", $fields_to_hide) . "\"";
        $html_code .= "<?php\r\n";
        $html_code .= "      \$hidden_fields = array( {$fields_to_hide} );\r\n";
        $html_code .= "      if ( \$hidden_fields ) {\r\n";
        $html_code .= "         foreach ( \$hidden_fields as \$name ) {\r\n";
        $html_code .= "            print \"<input name=\\\"{$form_field_group_name}[\$name]\\\" type=\\\"hidden\\\" value=\\\"\" . \$FORM['fieldz'][\$name] . \"\\\">\";\r\n";
        $html_code .= "         }\r\n";
        $html_code .= "      }\r\n";
        $html_code .= "?>\r\n";
        //         } else {
        //         }
    }
    $html_code .= "</form>\r\n";
    $html_code .= "</table>\r\n";
    if (!$form_properties['single_page']) {
        $html_code .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\r\n";
        $html_code .= "<?php\r\n";
        $html_code .= "      \$url_parse = parse_url( \$_SERVER['REQUEST_URI'] );\r\n";
        $html_code .= "      parse_str( \$url_parse['query'], \$post_fields );\r\n";
        $html_code .= "      unset( \$post_fields['f'], \$post_fields['start'], \$post_fields['starts'] );\r\n";
        $html_code .= "      \$fields = array( \"filter_field\", \"filter_operator\", \"filter_data\", \"filter_null\" );\r\n";
        $html_code .= "      if ( \$post_fields ) {\r\n";
        $html_code .= "         foreach ( \$post_fields as \$name => \$value ) {\r\n";
        $html_code .= "            \$post_fields_html .= \"<input name=\\\"\$name\\\" type=\\\"hidden\\\" value=\\\"\$value\\\">\";\r\n";
        $html_code .= "         }\r\n";
        $html_code .= "      }\r\n";
        $html_code .= "?>\r\n";
        $html_code .= "   <tr>\r\n";
        $html_code .= "      <td align=\"center\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"arial_10pt\">\r\n";
        $html_code .= "            <tr>\r\n";
        $html_code .= "               <td>Record:</td>\r\n";
        $html_code .= "               <?php if ( \$FORM['start'] != 0 ) { ?>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "               <?php } ?>\r\n";
        $html_code .= "                  <td><input type=\"submit\" value=\"|<\"><input name=\"start\" type=\"hidden\" id=\"start\" value=\"0\"></td>\r\n";
        $html_code .= "                  <?php print \$post_fields_html ?>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <?php if ( \$FORM['start'] != 0 ) { ?>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "               <?php } ?>\r\n";
        $html_code .= "                  <td><input type=\"submit\" value=\"<\"><input name=\"start\" type=\"hidden\" id=\"start\" value=\"<?php print \$FORM['start'] - 1 ?>\"></td>\r\n";
        $html_code .= "                  <?php print \$post_fields_html ?>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <?php if ( \$total_records != 0 ) { ?>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "               <?php } else { \$FORM['start'] = -1; } ?>\r\n";
        $html_code .= "                  <td><input name=\"starts\" type=\"text\" id=\"starts\" value=\"<?php print \$FORM['start'] + 1 ?>\" size=\"6\"></td>\r\n";
        $html_code .= "                  <?php print \$post_fields_html ?>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <?php if ( \$FORM['start'] < (\$total_records-1) ) { ?>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "               <?php } ?>\r\n";
        $html_code .= "                  <td><input type=\"submit\" value=\">\"><input name=\"start\" type=\"hidden\" id=\"start\" value=\"<?php print \$FORM['start'] + 1 ?>\"></td>\r\n";
        $html_code .= "                  <?php print \$post_fields_html ?>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <?php if ( \$total_records != 0 AND \$FORM['start'] < (\$total_records-1) ) { ?>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "               <?php } ?>\r\n";
        $html_code .= "                  <td><input type=\"submit\" value=\">|\"><input name=\"start\" type=\"hidden\" id=\"start\" value=\"<?php print \$total_records - 1 ?>\"></td>\r\n";
        $html_code .= "                  <?php print \$post_fields_html ?>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <form>\r\n";
        $html_code .= "                  <td><input type=\"submit\" value=\">*\"><input name=\"f\" type=\"hidden\" id=\"f\" value=\"add\"></td>\r\n";
        $html_code .= "               </form>\r\n";
        $html_code .= "               <td>of <?php print \$total_records ?></td>\r\n";
        $html_code .= "            </tr>\r\n";
        $html_code .= "         </table></td>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "   <tr>\r\n";
        $html_code .= "      <td><img src=\"/images/non.gif\" width=\"1\" height=\"10\"></td>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "</table>\r\n";
        $html_code .= "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"arial_10pt\">\r\n";
        $html_code .= "   <tr> \r\n";
        $html_code .= "      <td colspan=\"2\" bgcolor=\"#808080\"><img src=\"../images/non.gif\" width=\"1\" height=\"1\"></td>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "   <tr> \r\n";
        $html_code .= "      <td colspan=\"2\"><img src=\"../images/non.gif\" width=\"1\" height=\"10\"></td>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "   <tr> \r\n";
        $html_code .= "      <form>\r\n";
        $html_code .= "         <td style=\"padding-left: 10px\">Quick Filter \r\n";
        $html_code .= "            <?php if ( \$FORM['filter_operator'] ) { ?>\r\n";
        $html_code .= "            <span class=\"arial_11px\">[<a href=\"<?php print \$_SERVER['PHP_SELF']; ?>?filter_data=<?php print \$FORM['filter_data'] ?>\">Clear Filter</a>]</span>\r\n";
        $html_code .= "            <?php } ?>\r\n";
        $html_code .= "            <br> <select name=\"filter_field\">\r\n";
        $html_code .= "               <option value=\"\">Field Name</option>\r\n";
        $html_code .= "               <?php print array_to_html_options( \$filter_field_names, \$FORM['filter_field'], \"values\" ) ?> </select> <select name=\"filter_operator\" id=\"filter_operator\">\r\n";
        $html_code .= "               <?php print array_to_html_options( \$filter_operators, \$FORM['filter_operator'] ) ?> </select> <input name=\"filter_data\" type=\"text\" id=\"filter_data\" size=\"15\" value=\"<?php print \$FORM['filter_data'] ?>\"> \r\n";
        $html_code .= "            <input type=\"submit\" value=\"Go\"></td>\r\n";
        $html_code .= "      </form>\r\n";
        $html_code .= "      <form>\r\n";
        $html_code .= "         <td align=\"right\" style=\"padding-right: 10px\">Where Statement<br> <input name=\"where_data\" type=\"text\" id=\"where_data\" value=\"<?php print htmlspecialchars( \$FORM['where_data'] ) ?>\"> <input type=\"submit\" value=\"Go\"></td>\r\n";
        $html_code .= "      </form>\r\n";
        $html_code .= "   </tr>\r\n";
        $html_code .= "</table>\r\n";
    }
    $table_width = $form_properties['table_width'] ? $form_properties['table_width'] : "98%";
    $table_class = $form_properties['table_class'] ? "class='" . $form_properties['table_class'] . "'" : "";
    $css_code .= "<style type=\"text/css\">\r\n";
    $css_code .= "<!--\r\n";
    if (!$form_properties['single_page']) {
        $css_code .= "   .arial_11px { font-family: Arial; font-size: 11px; line-height: normal; }\r\n";
        $css_code .= "   .arial_10pt { font-family: Arial; font-size: 10pt; line-height: normal; }\r\n";
        $css_code .= "   .verdana_10px { font-family: Verdana; font-size: 10px; }\r\n";
        $css_code .= "   .verdana_09px { font-family: Verdana; font-size: 9px; }\r\n";
    }
    $css_code .= "   .tb_title { padding: 7px 0 5px 5px }\r\n";
    $css_code .= "   .tb_field { padding: 5px 5px 5px 0 }\r\n";
    $css_code .= "-->\r\n";
    $css_code .= "</style>\r\n";
    $result = '<table width="' . $table_width . '" border="0" cellspacing="0" cellpadding="0" align="center" style="font-family: Arial; font-size: 10pt;" ' . $table_class . '>' . "\r\n";
    if ($form_properties['popup_save']) {
        $result .= '<form method="post" target="_blank" action="<?php print $_SERVER[\'PHP_SELF\'] ?>">' . "\r\n";
    } else {
        $result .= '<form method="post" action="<?php print $_SERVER[\'PHP_SELF\'] ?>">' . "\r\n";
    }
    $result .= '<tr><td colspan="2"><img src="/images/non.gif" width="1" height="5"></td></tr><tr></tr>' . "\r\n";
    $result .= $html_code;
    #$result .= '<tr><td colspan="2"><img src="/images/non.gif" width="1" height="5"></td></tr><tr></tr>' . "\r\n";
    #$result .= '</table>';
    #$result = '<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">' . $html_code . '</table>';
    $html_start = '<html>' . "\r\n";
    $html_start .= '<head>' . "\r\n";
    $html_start .= "<title>Add/Edit {$table_name} : {$connection_parameters['database_name']}</title>\r\n";
    $html_start .= '</head>' . "\r\n";
    $html_start .= '<body>' . "\r\n";
    $html_end = '</body>' . "\r\n";
    $html_end .= '</html>' . "\r\n";
    $output_code = $php_code . $html_start . $css_code . $result . $html_end;
    if ($show_output_code) {
        header("Content-type: text/html");
        $output_code = str_replace(" include( \"", " #include( \"", $output_code);
        $temp_file = tempnam("/tmp", gmdate("Y-m-d_H:i:s") . "_" . rand(0, 100000));
        $handle = fopen($temp_file, "w");
        fwrite($handle, $output_code);
        fclose($handle);
        if (!function_exists(array_to_html_options)) {
            function array_to_html_options($associate_array, $selected_item = array())
            {
                return associate_array_to_html_options($associate_array, $selected_item);
            }
        }
        include $temp_file;
        exit;
    }
    return $output_code;
}
コード例 #2
0
ファイル: db_view.php プロジェクト: madhavpanda/iou-centerms
								<tr> 
									<form action="<?php 
            print $return_to_menu_url;
            ?>
" method="post">
										<td align="center"><input type="submit" id="submit" value="Return to Menu"></td>
									</form>
								</tr>
						</table></td>
              </tr>
            </table></td>
        </tr>
<?php 
        } else {
            if ($FORM['f'] == "view") {
                $table_structure = mysql_table_structure($mysql_connect_id, $table_name);
                if (!$primary_key_field) {
                    $primary_key_field = mysql_primary_key_field($table_structure);
                }
                $record = mysql_extract_record_id($mysql_connect_id, $table_name, array($primary_key_field => $FORM['pri']));
                $return_to_menu_url = $_SERVER[PHP_SELF] . "?" . $FORM['return_query'];
                if ($field_features) {
                    foreach ($field_features as $field_name => $features) {
                        if ($field_features[$field_name]['fkey'] or $field_features[$field_name]['build_cat']) {
                            $fkey_used = 1;
                            break;
                        }
                    }
                }
                if ($FORM['fkey'] == "off") {
                    foreach ($field_features as $field_name => $features) {
コード例 #3
0
ファイル: mysql.php プロジェクト: madhavpanda/iou-centerms
function mysql_create_associate_array($connect_id, $table, $fields, $select_addons = array(), $format = "", $multi_dimension = 0, $text_separator = " - ")
{
    global $sql_debug;
    if (!$table or !$fields) {
        return false;
    }
    if (!is_array($fields)) {
        #preg_match_all( "/(\w+\([^\)]+\)(\s+as\s+`?\w+`?)?|(`?\w+`?)(\s+as\s+`?\w+`?)?)/", $fields, $preg_results, PREG_SET_ORDER );
        preg_match_all("/\\s*((\\w+\\([^\\)]+\\)(\\s+as\\s+`?\\w+`?)?|((?:`?\\w+`?\\.)?`?\\w+`?)(\\s+as\\s+`?\\w+`?)?)|\\*)\\s*,/", $fields . ",", $preg_results, PREG_SET_ORDER);
        #print_r2( $preg_results );
        $fields = array();
        foreach ($preg_results as $array) {
            $fields[] = $array[1];
        }
        #$fields = preg_split( "/,\s*/", $fields ); -- The Old
        if (end($fields) == "*") {
            # incase i want all the fields to be used and set the first initial field name to use as the keys in the array
            array_pop($fields);
            $table_structure = mysql_table_structure($connect_id, $table, 1, 1);
            foreach ($fields as $field) {
                unset($table_structure[array_search($field, $table_structure)]);
            }
            foreach ($table_structure as $field) {
                $fields[] = $field;
            }
        }
    }
    if (count($fields) < 2) {
        return false;
    }
    $sql_statement = mysql_create_select_statement($table, $fields, $select_addons);
    if ($connect_id) {
        $sql_result = mysql_query($sql_statement, $connect_id);
    } else {
        $sql_result = mysql_query($sql_statement);
    }
    if ($sql_debug) {
        mysql_show_sql_statement($sql_statement, $sql_result, mysql_error());
    }
    if ($sql_result) {
        if ($sql_result == 1) {
            #return 1;
            return array();
        } else {
            if (!mysql_num_rows($sql_result)) {
                # Confirms that the SQL was executed correctly
                #return 1;
                return array();
            }
        }
        while ($sql_record = mysql_fetch_assoc($sql_result)) {
            $original_record = $sql_record;
            $variable_name = array_shift($sql_record);
            if ($multi_dimension) {
                # the outputted associated array will be multi-dimensional
                # [1231] => array( [name] => Spiderman, [timing] => 1:24 )
                $return_array[$variable_name] = $sql_record;
            } else {
                if (!$format) {
                    $return_array[$variable_name] = join($text_separator, $sql_record);
                } else {
                    # format the string by replacing the [field_name] entries
                    $formatted_value = $format;
                    foreach ($original_record as $key => $value) {
                        $formatted_value = str_replace("[" . $key . "]", $value, $formatted_value);
                    }
                    $return_array[$variable_name] = $formatted_value;
                }
            }
        }
        return $return_array;
    }
    return 0;
}