\n"); printf ("%s\n", htmlspecialchars ($label)); $value = htmlspecialchars ($row[$col_name]); if ($editable) # display as edit field { $str = sprintf ("\n", $value); } else # display as read-only text $str = $value; printf ("%s\n", $str); print ("\n"); } # DISPLAY_COLUMN function display_large_column ($label, $row, $col_name, $editable) { print ("\n"); printf ("%s\n", htmlspecialchars ($label)); $value = htmlspecialchars ($row[$col_name]); if ($editable) # display as edit field { $str = sprintf ("\n", $value); } else # display as read-only text $str = $value; printf ("%s\n", $str); print ("\n"); } # DISPLAY_LARGE_COLUMN function display_empty_column ($label, $col_name) { print ("\n"); printf ("%s\n", htmlspecialchars ($label)); $str = sprintf ("\n", $col_name); printf ("%s\n", $str); print ("\n"); } function display_big_empty_column ($label, $col_name, $cols, $rows) { print ("\n"); $str = sprintf ("\n", $cols, $rows); printf ("%s\n", htmlspecialchars ($label)); printf ("%s\n", $str); print ("\n"); } # Determine whether the client supplied the correct password for # a member entry. If so, display the entry for editing. # X_DISPLAY_ENTRY function display_entry () { global $PHP_SELF; global $what, $field; $db = cwslib_db_connect(); $result = mysql_query("SELECT * FROM cwslib WHERE $field LIKE \"%$what%\"", $db); #$result = mysql_query ($query) #or die ("Cannot execute query"); if (mysql_num_rows ($result) == 0) die ("No record with gene = $gene found"); if (mysql_num_rows ($result) > 1) die ("More than one user with member_id = $gene found"); printf ("
\n", $PHP_SELF, UPDATE_ENTRY); print ("\n"); # read results of query and format for editing $row = mysql_fetch_array ($result); hidden_field ("id", $row["id"]); display_column ("ID", $row, "id", 0); display_column ("Title", $row, "title", 1); display_column ("Authors", $row, "author", 1); display_column ("Journal: ", $row, "journal", 1); display_column ("date: ", $row, "date", 1); display_column ("issue: ", $row, "issue", 1); display_column ("PDF name", $row, "pdf_name", 1); display_column ("Key Words", $row, "keywords", 1); display_column ("MedLine UI", $row, "med_UI", 1); display_large_column ("Abstract", $row, "abstract", 1); display_column ("Notes", $row, "notes", 1); print ("
\n"); print ("\n"); print "
\n"; } # X_DISPLAY_ENTRY # NULLABLE # Determine whether or not the column with the given name in # the result set is nullable. function nullable ($result, $col_name) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { if (!($fld = mysql_fetch_field ($result, $i))) continue; if ($fld->name == $col_name) return (!$fld->not_null); } return (0); } # NULLABLE function display_editform () { global $PHP_SELF, $what, $med_UI; printf ("
\n", $PHP_SELF, DISPLAY_ENTRY); print ("Find \n"); print ("Search in field:\n"); print ("\n"); print ("\n"); print ("
\n"); } function entry_form () { global $PHP_SELF; printf ("
\n", $PHP_SELF, INSERT_ENTRY); display_empty_column ("Authors", "author"); display_empty_column ("Title", "title"); display_big_empty_column ("Journal", "journal", 80, 2); display_big_empty_column ("Abstract", "abstract", 80, 20); display_empty_column ("keywords", "keywords"); display_empty_column ("pdf name", "pdf_name"); display_empty_column ("Med UI", "med_UI"); display_empty_column ("notes", "notes"); print ("\n"); print ("
\n"); } # X_UPDATE_ENTRY function update_entry () { global $row, $id; $id = trim ($id); if (empty ($id)) die ("No Gene id available."); if (!ereg ("^[0-9]+$", $id)) # must be integer die ("Invalid member ID specified (must be number)"); # We'll need a result set to use for assessing nullability of # member table columns. This query gives us one without # selecting any rows. $result = mysql_query ("SELECT * FROM cwslib WHERE 1 = 0"); if (!$result) die ("Cannot query member table"); # iterate through each field in the form, using the values to # construct the UPDATE statement. $query = "UPDATE cwslib "; $delim = "SET "; while (list ($col_name, $val) = each ($row)) { $query .= "$delim $col_name ="; $delim = ","; # if a value is empty, update the value with NULL if the # column is nullable. This prevents trying to put an # empty string in the expiration when it should be NULL, # for example. $val = trim ($val); if (empty ($val)) { if (nullable ($result, $col_name)) $query .= "NULL"; # enter NULL else $query .= "\"\""; # enter empty string } else $query .= "\"" . addslashes ($val) . "\""; } $query .= " WHERE id = $id"; if (mysql_query ($query) && mysql_affected_rows () > 0){ print ("Entry updated successfully.\n"); printf ("Updated Record

\n", $id); # printf ("Updated Record

\n", $row["id"]); }else print ("Entry not updated.\n"); } # X_UPDATE_ENTRY if (empty ($action)) $action = INITIAL_PAGE; $title = "CWS Library -- Editing Form"; html_begin ($title, $title); $db = cwslib_db_connect (); # or die ("Cannot connect to server"); switch ($action) { case INITIAL_PAGE: display_editform (); break; case DISPLAY_ENTRY: display_entry (); break; case UPDATE_ENTRY: update_entry (); break; case ENTRY_FORM: entry_form (); break; case INSERT_ENTRY: insert_entry (); break; default: die ("Unknown action code ($action)"); } printf("Search"); html_end (); ?>