### #Make incoming sql fragment escape friendly to pass it to postgres ### $_POST["sql"] = pg_escape_string( $_POST["sql"]); #make initial db connection $dbconnect = pg_connect(" port=5432 dbname=b-and-t-g user=clustcomp password=none"); if($dbconnect != 0){ //echo "Successfully connected to: " . pg_host($dbconnect) . "
\n"; } else { echo pg_last_error($dbconnect); exit(1); } ### #Creates a table that loads the preset query selected with the radio button to the form. ### function table_create_load($result) { $numrows = pg_num_rows($result); $fnum = pg_num_fields($result); echo "\n"; echo "\n"; echo "\n"; for ($x = 1; $x < $fnum; $x++) { echo "\n"; } echo "\n"; for ($i = 0; $i < $numrows; $i++) { $color = ( $i % 2 == 0 ) ? "ECFFFF" : "FFFFFF"; $row = pg_fetch_object($result, $i); echo "\n"; $fieldname = pg_field_name($result, 0); echo "\n"; for ($x = 1; $x < $fnum; $x++) { $fieldname = pg_field_name($result, $x); echo "\n"; } echo"\n"; } echo "\n
"; echo strtolower(pg_field_name($result, $x)); echo "
$fieldname . "\" />"; echo $row->$fieldname; echo "
\n"; return 0; } echo "All Preset Queries - Selecting a query and pressing 'Load' places the query in the update/add and Delete forms.
\n"; table_create_load(pg_query($dbconnect, "SELECT id, sql, long_desc, short_desc FROM preset_queries")); echo "
\n"; #### #create update/add and delete forms # form is empty if there is no posted query # form is filled out if a query was posted # # note: After this page is returned to from a delete, the sql post variable will be set but empty. Count this as unset (isset() is inqdequate). #### echo "Add/Update Preset Query - Adds a new query or updates an existing one. If the sql statement exists, the preset query corresponding to that statement is updates. If the sql doesn't exist, a new query is added.
\n"; if(isset($_POST["id"]) && "" != $_POST["id"] ){ echo "SELECT * FROM preset_queries where id = " . $_POST["id"] . "
\n"; $result = pg_query($dbconnect, "SELECT * FROM preset_queries where id = " . $_POST["id"]); $row = pg_fetch_object($result, 0); print "
\n"; echo "SQL
\n"; echo "
\n"; echo "Long Description
\n"; echo "
\n"; echo "Short Description
\n"; echo "
\n"; $fieldname = pg_field_name($result, 4); echo "$fieldname, "parallel")){ echo " checked "; } echo ">Parallel Architecture\n"; echo "$fieldname, "2d graph")){ echo " checked "; } echo ">2d Graph\n"; echo "
\n"; $fieldname = pg_field_name($result, 0); echo "\n"; echo "\n"; echo "
\n"; }else{ print "
\n"; echo "SQL
\n"; echo "
\n"; echo "Long Description
\n"; echo "
\n"; echo "Short Description
\n"; echo "
\n"; echo "Parallel Architecture\n"; echo "2d Graph\n"; echo "
\n"; echo "\n"; echo "
\n"; } echo "
\n"; ### #Creates a table that will delete a preset query from the database when selected via radio button and submitted. ### function table_create_delete($result) { $numrows = pg_num_rows($result); $fnum = pg_num_fields($result); echo "\n"; echo "\n"; echo "\n"; for ($x = 1; $x < $fnum; $x++) { echo "\n"; } echo "\n"; for ($i = 0; $i < $numrows; $i++) { $color = ( $i % 2 == 0 ) ? "ECFFFF" : "FFFFFF"; $row = pg_fetch_object($result, $i); echo "\n"; $fieldname = pg_field_name($result, 0); echo "\n"; for ($x = 1; $x < $fnum; $x++) { $fieldname = pg_field_name($result, $x); echo "\n"; } echo"\n"; } echo "\n
"; echo strtolower(pg_field_name($result, $x)); echo "
$fieldname . "\" />"; echo $row->$fieldname; echo "
\n"; return 0; } echo "Select a Preset Query to Delete - Selecting a query and pressing 'Delete' will delete that query.
\n"; table_create_delete(pg_query($dbconnect, "SELECT id, sql, long_desc, short_desc FROM preset_queries")); echo "
\n"; pg_close($dbconnect); ?>