function session_edit_form($session_id, $athlete_id, $error_message) { # Put columns we never want to show in this array: $do_not_show = array("athlete_id", "session_id", "parent_session"); $columns = get_column_names(); # Get an array of fields user does want to display $display_details = array(); $query = "SELECT detail from athlete_log_preferences\n where athlete_id={$athlete_id} "; # ORDER BY display_sequence"; $result = do_sql($query) or die('Query failed: ' . pg_last_error()); // pg_fetch_array returns the next whole row as an array at each iteration while ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { foreach ($row as $prev_detail) { array_push($display_details, $prev_detail); } } echo "{$error_message} \n"; # Start Form and Table echo "<DIV id=mainlogentry > <a name=log_entry_form></a>"; echo "<FORM action=update_log_entry.php method=post >\n"; echo "<input type=hidden name='session_id' value={$session_id}>\n"; echo "\n\n<TABLE class=mainlogentry ><TR><TD>\n\n"; // Get Current row data $query = "SELECT * from log\n where session_id={$session_id} "; $result = do_sql($query) or die('Query failed: ' . pg_last_error()); // pg_fetch_array returns the next whole row as an array at each iteration // there really should only be 1 row returned here. // Check for date fields because we need to convert them $date_fields = array(); $num = pg_num_fields($result); for ($fieldnum = 0; $fieldnum < $num; $fieldnum++) { if (pg_field_type($result, $fieldnum) == 'date') { // put names of all date fields into $date_fields $fieldname = pg_field_name($result, $fieldnum); array_push($date_fields, $fieldname); } } // Now stick the info for the row the user wants to edit into an array $session_details = pg_fetch_array($result, null, PGSQL_ASSOC); // Check for date fields and convert them // Get the fields names foreach (array_keys($session_details) as $field_name) { // and see if they are in the date_fields array if (in_array($field_name, $date_fields)) { // If they are then convert the date from pg format to d/m/y $session_details[$field_name] = convert_date_from_pg($session_details[$field_name]); } } // Dates are converted // // Display Entry fields // Save text/notes fields (ie data_type text or var > 50 ) in a variable to // display last $notes_fields = ""; echo "<TR>\n"; $maxnumcols = 6; $colcount = $maxnumcols; foreach ($display_details as $colname) { if (!in_array($colname, $do_not_show) && in_array($colname, $display_details)) { if ($colcount-- == 0) { echo "\n</TR>\n"; $colcount = $maxnumcols - 1; } $colinfo = get_column_info($colname); $input_type = "text"; $value = $session_details[$colname]; if (preg_match("/^var/", $colinfo['data_type'])) { // Get the var length $typearray = explode(" ", $colinfo['data_type']); $varlen = $typearray[1]; } if (preg_match("/^select/", $colinfo['data_type'])) { // We have a select list type. There should be a corresponding table // which lists the select info echo " <td align=center ><font size=1 > \n"; echo $colinfo['log_col_long_name'] . " <BR>\n"; generate_select_form($colname, $colinfo['data_type'], $value); } elseif (preg_match("/^pref/", $colinfo['data_type'])) { // We have a prefer select list type. There should be a corresponding table // which lists the prefered select info echo " <td align=center ><font size=1 > \n"; echo $colinfo['log_col_long_name'] . " <BR>\n"; generate_prefer_select_form($colname, $colinfo['data_type'], $value, $athlete_id); } elseif ($colinfo['data_type'] == "text" || $varlen >= 30) { // Set maximum field size to 80 if ($varlen <= 80) { $size = $varlen; } else { $size = 80; } $notes_fields = "{$notes_fields} <TR><TD> " . $colinfo['log_col_long_name'] . "</TD> <TD colspan=20 ><INPUT type=text name ={$colname} value='{$value}' size={$size} > </TD></TR>\n"; } else { echo " <td align=center ><font size=1 > \n"; echo $colinfo['log_col_long_name'] . " <BR>\n"; echo "<INPUT type={$input_type} name={$colname} value='{$value}' size=10>\n"; } echo "</font> </td>\n"; } } echo "</TR>\n"; echo "{$notes_fields}\n"; echo "</TABLE>"; echo "<input type=submit value='Submit entries'>"; echo "</FORM>"; echo "</DIV>"; ## END of FUNCTION }
function ajax_column_info() { return_and_finish(get_column_info($_POST['table_name'], $_POST['column_name'])); }