#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "citation.h"
#include "web-util.h"
#include "web-conf.h"

extern char *emailAddress;
extern char *comments;


void PrintReferFormat (CitationPtr C);
void PrintRestOfForm (CitationPtr C);
void reportText();
void dateText();
void titleText();
void authorText();
void filenameText();
void keywordsText();
void reviewsText();
void abstractText();
void directionsText();
void emailText();
void commentsText();
void orgText();


/*--------------------------------------------------------*/
/* ListtoArray:                                           */
/*                                                        */
/* Puts the items (in list_ptr) in an array,              */
/* counts how many there are,                             */
/* returns the integer number                             */
/*--------------------------------------------------------*/
int ListtoArray (char array[N_STRINGS][STRING_SIZE], char *list_ptr)
{
   int x, y;
   char  *c, *s;

   for (s=list_ptr, x=0; *s != '\0';s++) {
      y = 0;
      while ((*s != ';') && (*s != '\n') && (*s != '\0')) {
         array[x][y] = *s;
         y++; s++;
      }
      array[x][y] = '\0';
      x++;
   }
   return (x);
}

/*--------------------------------------------------------*/
/* PrintFilledForm:                                       */
/*                                                        */
/* Puts its input parameters into an html form            */
/* (TR posting form)                                      */
/*--------------------------------------------------------*/

void 
PrintFilledForm (CitationPtr C)
{

   directionsText();

   /* form header stuff */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-query\">\n");
   printf ("<H2>Technical Report Bibliographic Information</H2>\n");

   printf ("<UL>");

   /* TR number */
   reportText();
   if (!getTrId(C)) {
      printf ("<INPUT SIZE=10 NAME=\"trnum\"><P>\n");
   }
   else {
      printf ("<INPUT SIZE=10 NAME=\"trnum\" VALUE = \"%s\"><P>\n",getTrId(C));
   }

   PrintRestOfForm (C);
}


/*--------------------------------------------------------*/
/* PrintUpdatedFilledForm:                                */
/*                                                        */
/* Puts its input parameters into an html form            */
/* (TR update posting form)                               */
/*--------------------------------------------------------*/

void 
PrintUpdatedFilledForm (CitationPtr C)
{

   directionsText();

   /* print form header stuff */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-update\">\n");
   printf ("<H2>Technical Report Bibliographic Information</H2>\n");

   printf ("<UL>");
  
   /* tr number */
   reportText();
   printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"%s\"<p>\n",getTrId(C));
   printf ("%s<p>\n",getTrId(C));

   C->url = NULL;   /* forestalls some potential update problems later on */
   PrintRestOfForm (C);
}/*end of PrintUpdatedFilledForm*/


/*--------------------------------------------------------*/
/* PreviewReferFormat:                                    */
/*                                                        */
/* Puts its input parameters into refer format for viewing*/
/* And saves state using "hidden" forms.                  */
/* For first time posting.                                */
/*--------------------------------------------------------*/

void 
PreviewReferFormat (CitationPtr C)
{
   printf ("<title>TR Bibliographic Preview Form</title>\n");
   printf("<H1>Preview TR Bibliographic Information</H1>\n");
   printf("<p>The bibliographic information you have entered \n");
   printf("will be appended to the database in refer format as follows:\n");
   printf("<P>\n");
   printf ("Note that you must include author (%%A), title (%%T), tr number (%%R), and date (%%D) ");
   printf ("before posting.<p>\n");
   printf ("<HR>");

   PrintReferFormat (C);
   /* now create "hidden" forms in order to save state: */

   /* the first hidden form is for going ahead with the posting */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-query\">\n");
   printf ("<INPUT TYPE=\"hidden\" NAME=\"choice\" VALUE=\"Submit for Posting\">\n");
   if (getTrId(C)) { 
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"%s\">\n",getTrId(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"\"> \n");
   }
   if (getDate(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"%s\">\n",getDate(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"\"> \n");
   }
   if (getOrg(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"%s\">\n",getOrg(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"\"> \n");
   }
   if (emailAddress) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"%s\">\n",emailAddress);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"\"> \n");
   }

   if (comments) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"%s\">\n",comments);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"\"> \n");
   }

   if (getTitle(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"%s\">\n",getTitle(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"\"> \n");
   }
   if (getAuthor(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"%s\">\n",getAuthor(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"\"> \n");
   }
   if (getUrl(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"%s\">\n",getUrl(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"\"> \n");
   }
   if (getAbstract(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"%s\">\n",getAbstract(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"\"> \n");
   }
   if (getKeywords(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"%s\">\n",getKeywords(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"\"> \n");
   }
   if (getCategories(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"%s\">\n",getCategories(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"\"> \n");
   }
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Submit for Posting\"><P>\n");
   printf ("</FORM>\n");

   /* the second hidden form is for returning to the posting form */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-repeat\">\n");
   printf ("<INPUT TYPE=\"hidden\" NAME=\"choice\" VALUE=\"Submit for Posting\">\n");
   if (getTrId(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"%s\">\n",getTrId(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"\"> \n");
   }
   if (getDate(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"%s\">\n",getDate(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"\"> \n");
   }
   if (getOrg(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"%s\">\n",getOrg(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"\"> \n");
   }
   if (emailAddress) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"%s\">\n",emailAddress);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"\"> \n");
   }

   if (comments) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"%s\">\n",comments);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"\"> \n");
   }

   if (getTitle(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"%s\">\n",getTitle(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"\"> \n");
   }
   if (getAuthor(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"%s\">\n",getAuthor(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"\"> \n");
   }
   if (getUrl(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"%s\">\n",getUrl(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"\"> \n");
   }
   if (getAbstract(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"%s\">\n",getAbstract(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"\"> \n");
   }
   if (getKeywords(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"%s\">\n",getKeywords(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"\"> \n");
   }
   if (getCategories(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"%s\">\n",getCategories(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"\"> \n");
   }
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Return to Posting Form\"><P>\n");
   printf ("</FORM>");

}/* end of PreviewReferFormat */


/*--------------------------------------------------------*/
/* PreviewUpdatedReferFormat:                             */
/*                                                        */
/* Puts its input parameters into refer format for viewing*/
/* And saves state using "hidden" forms.                  */
/* For update posting.                                    */
/*--------------------------------------------------------*/

void 
PreviewUpdatedReferFormat (CitationPtr C)
{
   printf ("<title>TR Bibliographic Preview Form</title>\n");
   printf("<H1>Preview TR Bibliographic Information</H1>\n");
   printf("<p>The bibliographic information you have entered \n");
   printf("will be updated in the database in refer format as follows:\n");
   printf("<P>\n");
   printf ("Note that you must include author, title, and date before reposting.<p>\n");
   printf ("<HR>");

   PrintReferFormat (C);

   /* now create "hidden" forms to save state */
   /* the first is for going straight from previewing to updating (posting) */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-update\">\n");
   printf ("<INPUT TYPE=\"hidden\" NAME=\"choice\" VALUE=\"Submit for RePosting\">\n");
   if (getTrId(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"%s\">\n",getTrId(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"\"> \n");
   }
   if (getDate(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"%s\">\n",getDate(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"\"> \n");
   }
   if (getTitle(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"%s\">\n",getTitle(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"\"> \n");
   }
   if (getOrg(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"%s\">\n",getOrg(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"\"> \n");
   }
   if (emailAddress) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"%s\">\n",emailAddress);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"\"> \n");
   }

   if (comments) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"%s\">\n",comments);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"\"> \n");
   }

   if (getAuthor(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"%s\">\n",getAuthor(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"\"> \n");
   }
   if (getUrl(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"%s\">\n",getUrl(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"\"> \n");
   }
   if (getAbstract(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"%s\">\n",getAbstract(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"\"> \n");
   }
   if (getKeywords(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"%s\">\n",getKeywords(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"\"> \n");
   }
   if (getCategories(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"%s\">\n",getCategories(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"\"> \n");
   }
/*  printf ("Everything is fine:\n");*/
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Submit for RePosting\"><P>\n");
   printf ("</FORM>");

   /* the second is for going from previewing back to the update form */
   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"trpost-update-repeat\">\n");
   printf ("<INPUT TYPE=\"hidden\" NAME=\"choice\" VALUE=\"Submit for Posting\">\n");
   if (getTrId(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"%s\">\n",getTrId(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"trnum\" VALUE=\"\"> \n");
   }
   if (getDate(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"%s\">\n",getDate(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"\"> \n");
   }
   if (getOrg(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"%s\">\n",getOrg(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"organization\" VALUE=\"\"> \n");
   }
   if (emailAddress) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"%s\">\n",emailAddress);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"\"> \n");
   }

   if (comments) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"%s\">\n",comments);
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"\"> \n");
   }

   if (getTitle(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"%s\">\n",getTitle(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"\"> \n");
   }
   if (getAuthor(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"%s\">\n",getAuthor(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"authors\" VALUE=\"\"> \n");
   }
   if (getUrl(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"%s\">\n",getUrl(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"url\" VALUE=\"\"> \n");
   }
   if (getAbstract(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"%s\">\n",getAbstract(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"abstract\" VALUE=\"\"> \n");
   }
   if (getKeywords(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"%s\">\n",getKeywords(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"keywords\" VALUE=\"\"> \n");
   }
   if (getCategories(C)) {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"%s\">\n",getCategories(C));
   }
   else {
      printf ("<INPUT TYPE=\"hidden\" NAME=\"categories\" VALUE=\"\"> \n");
   }
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Return to Posting Form\"><P>\n");
   printf ("</FORM>");

}/* end of PreviewUpdatedReferFormat */


/*--------------------------------------------------------*/
/* DisplayReferEntry:                                     */
/*                                                        */
/* Takes as input all the bibliographic data available.   */
/* Puts its input parameters into html format for viewing.*/
/* (called by Refer2View)                                 */
/*--------------------------------------------------------*/

void 
DisplayReferEntry (CitationPtr C)
{

   /*printf ("<H2>TR Bibliographic Information</H2>\n");*/
   printf ("<UL>");
  
   /***There HAS to be one, so we should not check for one!!??*****/
   if (getTrId(C)) {
      printf ("<LI>TR NUMBER: ");
      printf (" %s\n<p>", getTrId(C));
   }
  
   if (getDate(C)) {
      printf ("<LI>DATE: ");
      printf (" %s\n<p>",getDate(C));
   }
  
   if (getTitle(C)) {
      printf ("<LI>TITLE: ");
      printf (" %s\n<p>",getTitle(C));
   }
  
   if (getAuthor(C)) {
      printf ("<LI>AUTHOR(S): ");
      printf (" %s\n<p>",getAuthor(C));
   }
  
   if (getUrl(C)) {
      printf ("<LI>URL: ");
      printf (" <a href=\"%s\">%s</a>\n<p>",getUrl(C), getUrl(C));
   }

   if (getAbstract(C)) {
      printf ("<LI>ABSTRACT: ");
      printf ("%s\n<p>",getAbstract(C));
   }

   if (getKeywords(C)) {
      printf ("<LI>KEYWORDS:");
      printf ("%s<P>\n", getKeywords(C));
   }

   if (getCategories(C)) {
      printf ("<LI>CATEGORIES: ");
      printf ("%s <P>\n", getCategories(C));
   }

   if (getOrg(C)) {
      printf ("<LI>TR Series Name: ");
      printf ("%s <P>\n", getOrg(C));
   }

}/*end of DisplyReferEntry*/


/*--------------------------------------------------------*/
/* Refer2Form:                                            */
/*                                                        */
/* reads a refer bib entry (in passedfilename)            */
/* and passes the information to PrintUpdatedFilledForm.  */
/* (used for updating)                                    */
/*--------------------------------------------------------*/

void Refer2Form (char *passedfilename) {

   FILE *fp;
   CitationPtr C;

   /* The passed file should contain a single citation */
   fp = fopen (passedfilename, "r");
   if (!fp) {
      printf ("ERROR: Could not open file passed from techrep.\n");
      return;
   }

   C = read_one_citation (fp);
   if (!C) {
      printf ("ERROR: Could not read citation passed from techrep.\n");
      return;
   }

   fclose(fp);

   PrintUpdatedFilledForm (C);

}/* end of Refer2Form */


/*--------------------------------------------------------*/
/* Refer2View:                                            */
/*                                                        */
/* reads a refer bib entry (in passedfilename)            */
/* and displays the information in html format.           */
/* (by calling DisplayReferEntry)                         */
/* (used for previewing during posting)                   */
/*--------------------------------------------------------*/

void Refer2View (char *passedfilename) {

   FILE *fp;
   CitationPtr C;

   /* The passed file should contain a single citation */
   fp = fopen (passedfilename, "r");
   if (!fp) {
      printf ("ERROR: Could not open file passed from techrep.\n");
      return;
   }

   C = read_one_citation (fp);
   if (!C) {
      printf ("ERROR: Could not read citation passed from techrep.\n");
      return;
   }

   fclose(fp);

   DisplayReferEntry (C);
}/* end of Refer2View */


/* 
 * Prints html-ized refer for the given citation.
 */
void
PrintReferFormat (CitationPtr C)
{
   char temp_array[N_STRINGS][STRING_SIZE];
   int listCount;
   int x;

   if (getAuthor(C)) {
      listCount = ListtoArray(temp_array, getAuthor(C));
      for (x = 0; x < listCount; x++) {
         printf ("%%%c %s\n<br>", REF_AUTHOR, temp_array[x]);
      }
   }
   if (getTitle(C)) {
      printf ("%%%c %s\n<br>", REF_TITLE, getTitle(C));
   }
   if (getOrg(C)) {
      printf ("%%%c %s\n<br>", REF_INST, getOrg(C));
   }
   if (getTrId(C)) {
      printf ("%%%c %s\n<br>", REF_REPORT, getTrId(C));
   }
   if (getDate(C)) {
      printf ("%%%c %s\n<br>", REF_DATE, getDate(C));
   }
   if (getUrl(C)) {
      printf ("%%%c %s\n<br>", REF_URL, getUrl(C));
   }
   if (getKeywords(C)) {
      printf ("%%%c ", REF_KEYWORDS);
      listCount = ListtoArray(temp_array, getKeywords(C));
      for (x = 0; x < listCount; x++)  {
         printf ("%s, ",temp_array[x]);
      }
      printf ("\n<br>");
   }
   if (getCategories(C)) {
      printf ("%%%c ", REF_CATEGORY);
      listCount = ListtoArray(temp_array, getCategories(C));
      for (x = 0; x < listCount ; x++)  {
         printf ("%s, ",temp_array[x]);
      }
      printf ("\n<br>");
   }
   if (getAbstract(C)) {
      printf ("%%%c %s\n<br>", REF_ABSTRACT,getAbstract(C));
   }
}

void
PrintRestOfForm (CitationPtr C)
{
   int i;
   FILE *fp;
   char orgFile[STRING_SIZE];    
   char line[STRING_SIZE], *org;
   int first = TRUE;

   /* organization */
   sprintf (orgFile, "%s/lib/TrSeriesNames", TR_HOME);
   if ((fp = fopen(orgFile, "r")) == NULL) {
      fprintf (stderr, "Could not find file containing organization names.");
      exit(1);
   }
   orgText ();
   printf ("<SELECT NAME=\"organization\">\n");
   while (fgets (line, STRING_SIZE, fp) != NULL) {
      org = stripTrailingBlanks (line);
      if (strlen(org)) {
         if (first) {
            printf ("<OPTION SELECTED>%s\n", org);
            first = FALSE;
         } else {
            printf ("<OPTION>%s\n", org);
         }
      }
   }
   printf ("</SELECT> <P>\n");
   fclose (fp);

   /* date */
   dateText();
   if (!getDate(C)) {
      printf ("<INPUT SIZE=30 NAME=\"date\"> <P>\n");
   }
   else  {
      printf ("<INPUT SIZE=30 NAME=\"date\" VALUE = \"%s\"><P>\n",getDate(C));
   }
  
   /* title */
   titleText();
   if (!getTitle(C)) {
      printf ("<INPUT SIZE=65 NAME=\"title\"> <P>\n");
   }
   else  {
      printf ("<INPUT SIZE=65 NAME=\"title\" VALUE = \"%s\"><P>\n",getTitle(C));
   }
  
   /* authors */
   authorText();
   if (!getAuthor(C)) {
      printf ("<INPUT SIZE=65 NAME=\"authors\"><P>\n");
   }
   else  {
      printf ("<INPUT SIZE=65 NAME=\"authors\" VALUE = \"%s\"><P>\n",getAuthor(C));
   }
  
   emailText();
   printf ("<INPUT SIZE=65 NAME=\"email\"> <P>\n");

   /* url */
   filenameText();
   if (!getUrl(C)) {
      printf ("<INPUT SIZE=65 NAME=\"url\"> <P>\n");
   }
   else  {
      printf ("<INPUT SIZE=65 NAME=\"url\" VALUE =\"%s\"><P>\n",getUrl(C));
   }

   /* abstract */
   abstractText();
   if (!getAbstract(C)) {
      printf ("<TEXTAREA ROWS=5 COLS=65 NAME=\"abstract\"></TEXTAREA><P>\n");
   }
   else  {
      printf ("<TEXTAREA ROWS=5 COLS=65 NAME=\"abstract\">%s</TEXTAREA><P>\n",getAbstract(C));
   }

   /* keywords */
   keywordsText();
   if (!getKeywords(C)) {
      printf ("<INPUT SIZE=65 NAME=\"keywords\"> <P>\n");
   }
   else  {
      printf ("<INPUT SIZE=65 NAME=\"keywords\" VALUE = \"%s\"> <P>\n", getKeywords(C));
   }

   /* cr subject categories */
   reviewsText();
   if (!getCategories(C)) {
      printf ("<INPUT SIZE=65 NAME=\"categories\"> <P>\n");
   }
   else  {
      printf ("<INPUT SIZE=65 NAME=\"categories\" VALUE = \"%s\"> <P>\n", getCategories(C));
   }

   commentsText();
   printf ("<TEXTAREA ROWS=3 COLS=65 NAME=\"comments\"></TEXTAREA><P>\n");

   printf ("<LI><b>CHOOSE TO SUBMIT INFORMATION FOR POSTING OR TO PREVIEW IT FIRST</b><br>\n");
   printf ("<p><SELECT NAME=\"choice\">\n");
   printf ("<OPTION SELECTED>Submit for Posting\n");
   printf ("<OPTION>Preview First\n");
   printf ("</SELECT>\n");
   printf ("</UL><p><p>");
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Submit Information\"><P>\n");
/*  printf ("<INPUT TYPE=\"reset\" VALUE=\"Reset\"><p>\n");*/
   printf ("</FORM>");

   printf ("<FORM METHOD=POST ACTION=\"%s\">\n", MASTERFORM);
   printf ("<INPUT TYPE=\"hidden\" NAME=\"tr_task_data\" VALUE=\"techrep-menu-htmlform\">\n");
   printf ("<INPUT TYPE=\"submit\" VALUE=\"Cancel\"><P>\n");
   printf ("</FORM>\n");
}

void 
directionsText()
{
   printf ("<h2>Directions</h2>");
   printf ("Fill out the form below. Be sure to specify your email address in the\n");
   printf ("space provided. This information is collated and sent to <b>%s</b>,\n", TR_ADMIN);
   printf ("who is the report administrator at your site. The report administrator\n");
   printf ("verifies the information on the form with you before posting it in\n");
   printf ("the online archive.<p>\n");
   printf ("Be aware that when you request a change to the archive through POST, DELETE\n");
   printf ("or UPDATE, the change must be verified. Thus there will be some delay\n");
   printf ("in the appearance of your report in the online archive.<p>\n");
   printf ("\n");
}

void
reportText()
{
   printf ("<LI><b>TECHNICAL REPORT NUMBER:</b>This is a unique string that identifies\n");
   printf ("your TR. You have to obtain this from Sally Elder in 226 Bell.<br>\n");
}

void 
dateText()
{
   printf ("<LI><b>DATE WRITTEN:</b> The date format should be \"Month Day, Year\",\n");
   printf ("for example, \"July 4, 1994\" <br>\n");
}
void
titleText()
{
   printf ("<LI><b>TITLE OF TECHNICAL REPORT:</b><br>\n");
}
void
authorText()
{
   printf ("<LI><b>AUTHORS:</b> Separate authors' names with a semicolon, comma, or other delimiter<br>\n");
}
void
filenameText()
{
   printf ("<LI><b>PATH AND FILENAME OF TECHNICAL REPORT:</b>This file must be\n");
   printf ("readable by the Report Administrator so that it can be copied to the TR archive.<br>\n");
}
void
abstractText()
{
   printf ("<LI><b>ABSTRACT:</b> You can put the full text of the abstract here\n");
   printf ("or simply specify the full path to a filename containing this text.<br>\n");
}
void
keywordsText()
{
   printf ("<LI><b>KEYWORDS:</b><br>\n");
}

void
reviewsText()
{
   printf ("<LI><b>COMPUTING REVIEWS SUBJECT CATEGORIES (OPTIONAL):</b> <br>\n");
   printf ("<a href=\"%s/catlist.html\">Here</a> is a list of possible categories\n", HELP_URL);
   printf ("Separate category names with a semicolon \";\"<br>\n");
}

void
commentsText()
{
   printf ("<LI><b>COMMENTS:</b> Place any comments you need to make to the Report\n");
   printf ("Administrator here. These comments are <b>not</b> saved as part of\n");
   printf ("the bibliographic entry for your report.<br>\n");
   printf ("Please mention here which system (castor, hadar etc.) that the
   files mentioned above are on.<br>\n");
}

void
emailText()
{
   printf ("<LI><b>CONTACT PERSON:</b> The email address (probably your own) of the\n");
   printf ("person who will verify the information provided here.<br>\n");
}

void orgText()
{
    printf ("<LI><b>INSTITUTION/TR-SERIES:</b> Select one from the list.<br>\n");
}
       
