// art_saver - save the listing information that was entered via form; 
//
#cgivar formmode, id
//
//
#set TITLE = "Save a listing"
#include top

// now load CGI fields based on examp_art record format..
#sqlcgivars examp_art


// sanity checks..
#if @artist = "" || @title = ""
  <h2>An artist name and title are required.  Press your <b>Back</b> button and try again.</h2>
  #exit
#endif
#if $sqlwritable() != 0 
  <h2>Database not writable... check project setup and configuration.</h2>
  #exit
#endif


#if @formmode = new
  // allocate new serial number
  #sql #load select _sequence (as id) from examp_art
#endif

// in the size field, change inches symbol (") to tilde (~) to avoid quote hassles
#set size = $change( '"', "~", @size )

// save the <textarea> contents to a textchunk file..
//
// Note: in this case the examp_art subdirectory is provided, but
// normally the developer will need to create the necessary subdirectories
// manually in advance.
//
#savetext textdesc examp_art/@id
#set textdesc = $textsaved()


// build the SQL and insert or update the data row..
#sql
  #sqlbuild  @formmode  examp_art  quote  noquote=id
  #if @formmode != new
    where id = @id
  #endif
#endsql

// check error status...
#set STAT = $sqlerror()
#if @STAT != 0
  <h2>Save error.  Table = people.  Error code = @STAT</h2>
  #exit
#endif
<center> 
<br>
<br>
<h2>Saved.<br></h2>
<br>
<br>
<h3><a href="@CGIPROG?rtn=art_details&id=@id">Continue</a></h3>
</center>
