/* Author: Ram Samudrala (me@ram.org)
 * Version: O1.1
 * Detail: <http://www.ram.org/computing/sc/sc.html>
 * November 22, 1995.
 *
 * See the URL above for more information.
 */

#include "cgi_common.h"
#include "cgi_defines.h"
#include "sc_defines.h"
#include "cgi_cookies.h"
#include "cgi_error_handlers.h"

int content_type_displayed = FALSE;

/******************************************************************/

int main()
{
  char cookie_string[ORDER_COOKIE_STRING_LENGTH], order_string[ORDER_COOKIE_STRING_LENGTH], *cp;
  char tmp_string[ORDER_COOKIE_STRING_LENGTH];
  entry entries[MAX_ENTRIES];
  int number_of_entries, i;
  
  check_method("POST", "main");
  check_content_type("main");
  number_of_entries = read_entries(entries);

  if (get_cookie("order", order_string) == FALSE)
    strcpy(order_string, "|");
   
  for(i = 0; i <= number_of_entries; i++)
    if ((entries[i].name[0] != '\0') && (entries[i].val[0] != '\0'))
    {
      sprintf(tmp_string, "%s%c%s|", entries[i].name, SEPARATOR, entries[i].val);
      strcat(order_string, tmp_string);
    }
  
  set_cookie(ORDER_COOKIE_NAME, order_string, DEFAULT_PATH, DEFAULT_EXPIRES, SHOPPER_PROCESSING_SCRIPT);   
  return TRUE;
}

/******************************************************************/

