/*
FILE:     ndb_htmllib.h
*/
/*
VERSION:  1.600
*/
/*
DATE:     2/3/2005
*/
/*
  Comments and Questions to: sw-help@rcsb.rutgers.edu
*/
/*
COPYRIGHT 1999-2005 Rutgers - The State University of New Jersey

This software is provided WITHOUT WARRANTY OF MERCHANTABILITY OR
FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTY, EXPRESS OR
IMPLIED.  RUTGERS MAKE NO REPRESENTATION OR WARRANTY THAT THE
SOFTWARE WILL NOT INFRINGE ANY PATENT, COPYRIGHT OR OTHER
PROPRIETARY RIGHT.

The user of this software shall indemnify, hold harmless and defend
Rutgers, its governors, trustees, officers, employees, students,
agents and the authors against any and all claims, suits,
losses, liabilities, damages, costs, fees, and expenses including
reasonable attorneys' fees resulting from or arising out of the
use of this software.  This indemnification shall include, but is
not limited to, any and all claims alleging products liability.
*/
/*
               PDB SOFTWARE LICENSE AGREEMENT

BY CLICKING THE ACCEPTANCE BUTTON OR INSTALLING OR USING 
THIS "SOFTWARE, THE INDIVIDUAL OR ENTITY LICENSING THE  
SOFTWARE ("LICENSEE") IS CONSENTING TO BE BOUND BY AND IS 
BECOMING A PARTY TO THIS AGREEMENT.  IF LICENSEE DOES NOT 
AGREE TO ALL OF THE TERMS OF THIS AGREEMENT
THE LICENSEE MUST NOT INSTALL OR USE THE SOFTWARE.

1. LICENSE AGREEMENT

This is a license between you ("Licensee") and the Protein Data Bank (PDB) 
at Rutgers, The State University of New Jersey (hereafter referred to 
as "RUTGERS").   The software is owned by RUTGERS and protected by 
copyright laws, and some elements are protected by laws governing 
trademarks, trade dress and trade secrets, and may be protected by 
patent laws. 

2. LICENSE GRANT

RUTGERS grants you, and you hereby accept, non-exclusive, royalty-free 
perpetual license to install, use, modify, prepare derivative works, 
incorporate into other computer software, and distribute in binary 
and source code format, or any derivative work thereof, together with 
any associated media, printed materials, and on-line or electronic 
documentation (if any) provided by RUTGERS (collectively, the "SOFTWARE"), 
subject to the following terms and conditions: (i) any distribution 
of the SOFTWARE shall bind the receiver to the terms and conditions 
of this Agreement; (ii) any distribution of the SOFTWARE in modified 
form shall clearly state that the SOFTWARE has been modified from 
the version originally obtained from RUTGERS.  

2. COPYRIGHT; RETENTION OF RIGHTS.  

The above license grant is conditioned on the following: (i) you must 
reproduce all copyright notices and other proprietary notices on any 
copies of the SOFTWARE and you must not remove such notices; (ii) in 
the event you compile the SOFTWARE, you will include the copyright 
notice with the binary in such a manner as to allow it to be easily 
viewable; (iii) if you incorporate the SOFTWARE into other code, you 
must provide notice that the code contains the SOFTWARE and include 
a copy of the copyright notices and other proprietary notices.  All 
copies of the SOFTWARE shall be subject to the terms of this Agreement.  

3. NO MAINTENANCE OR SUPPORT; TREATMENT OF ENHANCEMENTS 

RUTGERS is under no obligation whatsoever to: (i) provide maintenance 
or support for the SOFTWARE; or (ii) to notify you of bug fixes, patches, 
or upgrades to the features, functionality or performance of the 
SOFTWARE ("Enhancements") (if any), whether developed by RUTGERS 
or third parties.  If, in its sole discretion, RUTGERS makes an 
Enhancement available to you and RUTGERS does not separately enter 
into a written license agreement with you relating to such bug fix, 
patch or upgrade, then it shall be deemed incorporated into the SOFTWARE 
and subject to this Agreement. You are under no obligation whatsoever 
to provide any Enhancements to RUTGERS or the public that you may 
develop over time; however, if you choose to provide your Enhancements 
to RUTGERS, or if you choose to otherwise publish or distribute your 
Enhancements, in source code form without contemporaneously requiring 
end users or RUTGERS to enter into a separate written license agreement 
for such Enhancements, then you hereby grant RUTGERS a non-exclusive,
royalty-free perpetual license to install, use, modify, prepare
derivative works, incorporate into the SOFTWARE or other computer
software, distribute, and sublicense your Enhancements or derivative
works thereof, in binary and source code form.

4. FEES.  There is no license fee for the SOFTWARE.  If Licensee
wishes to receive the SOFTWARE on media, there may be a small charge
for the media and for shipping and handling.  Licensee is
responsible for any and all taxes.

5. TERMINATION.  Without prejudice to any other rights, Licensor
may terminate this Agreement if Licensee breaches any of its terms
and conditions.  Upon termination, Licensee shall destroy all
copies of the SOFTWARE.

6. PROPRIETARY RIGHTS.  Title, ownership rights, and intellectual
property rights in the Product shall remain with RUTGERS.  Licensee 
acknowledges such ownership and intellectual property rights and will 
not take any action to jeopardize, limit or interfere in any manner 
with RUTGERS' ownership of or rights with respect to the SOFTWARE.  
The SOFTWARE is protected by copyright and other intellectual 
property laws and by international treaties.  Title and related 
rights in the content accessed through the SOFTWARE is the property 
of the applicable content owner and is protected by applicable law.  
The license granted under this Agreement gives Licensee no rights to such
content.

7. DISCLAIMER OF WARRANTY.  THE SOFTWARE IS PROVIDED FREE OF 
CHARGE, AND, THEREFORE, ON AN "AS IS" BASIS, WITHOUT WARRANTY OF 
ANY KIND, INCLUDING WITHOUT LIMITATION THE WARRANTIES THAT IT 
IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 
OR NON-INFRINGING.  THE ENTIRE RISK AS TO THE QUALITY AND 
PERFORMANCE OF THE SOFTWARE IS BORNE BY LICENSEE.  SHOULD THE 
SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, THE LICENSEE AND NOT 
LICENSOR ASSUMES THE ENTIRE COST OF ANY SERVICE AND REPAIR.  
THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF 
THIS AGREEMENT.  NO USE OF THE PRODUCT IS AUTHORIZED HEREUNDER 
EXCEPT UNDER THIS DISCLAIMER.

8. LIMITATION OF LIABILITY.  TO THE MAXIMUM EXTENT PERMITTED BY
APPLICABLE LAW,  IN NO EVENT WILL LICENSOR BE LIABLE FOR ANY 
INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 
OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, INCLUDING, 
WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK 
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL 
OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF ADVISED OF THE
POSSIBILITY THEREOF. 
*/
/*
  PURPOSE:      Include files for htmllib.a
*/


#ifndef __NDB_HTMLLIB_H__
#define __NDB_HTMLLIB_H__
#include <stdio.h>

#if 0
#ifdef __cplusplus
extern "C" {
#endif
#endif


#define    HT_TMP_DIR       "/tmp/"
#define    HT_ICON_PATH     "/NDB/icons/"

#define    HT_MAX_UPLOAD_BYTES               100000000
#define    HT_MAXCONDITIONS                  8000
#define    HT_MAXSELECTIONS                  8000
#define    HT_SCRIPT_TOP_QUERY_MENU          "mk-top-query-menu"
#define    HT_SCRIPT_TOP_SF_SCREEN           "mk-top-sf-screen"
#define    HT_SCRIPT_TABLE_MENU              "mk-table-menu"
#define    HT_SCRIPT_COLUMN_MENU             "mk-column-menu"
#define    HT_SCRIPT_CONDITION_FORM          "mk-condition-form"
#define    HT_SCRIPT_RESET_QUERY             "reset-query"
#define    HT_SCRIPT_EXECUTE_QUERY           "execute-query"
#define    HT_SCRIPT_EXECUTE_FORM_QUERY      "execute-form-query"
#define    HT_SCRIPT_ACCUM_REPORT_SELECT     "accum-report-select"
#define    HT_SCRIPT_ACCUM_STRUCT_SELECT     "accum-struct-select"
#define    HT_SCRIPT_DISPLAY_STRUCT          "display-structure"
#define    HT_SCRIPT_REPORT_MENU             "mk-report-menu-msd"

#define    HT_SCRIPT_DYNAMIC_REPORT          "launch-table-browser"
#define    HT_SCRIPT_DYNAMIC_SCATTER_PLOT    "launch-scatter-plot"
#define    HT_SCRIPT_DYNAMIC_HISTOGRAM_PLOT  "launch-histogram-plot"


#define    HT_ATTRIBUTE_QUERY_FILE          "qfile"
#define    HT_ATTRIBUTE_OPTION              "option"
#define    HT_ATTRIBUTE_DATABASE_NAME       "dbname"
#define    HT_ATTRIBUTE_DATABASE_VERSION    "dbvers"
#define    HT_ATTRIBUTE_BEGIN_LINE          "begline"
#define    HT_ATTRIBUTE_TABLE_NAME          "table"
#define    HT_ATTRIBUTE_TABLE_DESC          "table_description"
#define    HT_ATTRIBUTE_COLUMN_NAME         "column"
#define    HT_ATTRIBUTE_COLUMN_DESC         "column_description"
#define    HT_ATTRIBUTE_COLUMN_EXAM         "column_example"
#define    HT_ATTRIBUTE_DATA_TYPE           "type"
#define    HT_ATTRIBUTE_DISPLAY             "display"
#define    HT_ATTRIBUTE_ACTION              "action"
#define    HT_ATTRIBUTE_SNAME               "structure"
#define    HT_ATTRIBUTE_VALUE               "value"
#define    HT_ATTRIBUTE_OPERATOR            "op"
#define    HT_ATTRIBUTE_LOG_OPERATOR        "jop"
#define    HT_ATTRIBUTE_REPORT_NAME         "report_name"
#define    HT_ATTRIBUTE_MSD_PPID            "pid"
#define    HT_ATTRIBUTE_MSD_PAGE            "page"
#define    HT_ATTRIBUTE_MSD_PDBID           "pdbId"

#define    HT_ATTRIBUTE_REPORT_TABLE_NAME     "rtable"
#define    HT_ATTRIBUTE_REPORT_COLUMN_NAME    "rcolumn"
#define    HT_ATTRIBUTE_REPORT_DATA_TYPE      "rdatatype"

#define    HT_ATTRIBUTE_PDB_CODE            "pdbid"
#define    HT_ATTRIBUTE_NDB_CODE            "ndbid"


#define    HT_ATTRIBUTE_RETURN_URL          "return_url"
#define    HT_ATTRIBUTE_RETURN_URL_TEXT     "return_url_text"
#define    HT_ATTRIBUTE_ID_CODE             "idlist"


/*
 *  Colors, font sizes and icons are selected according to viewer type..
 */
#define    HT_COLOR_BG           "#ffffff"
/*
 *#define    HT_COLOR_LINK       "#ffffff"
 *#define    HT_COLOR_TEXT       "#ffffff"
 *#define    HT_COLOR_VLINK      "#ffffff"
 */

#define    HT_ICON_SF_NDB_LOGO   "small.ndbtitle.gif"
#define    HT_ICON_BG_FILE       "bg-ndb-cz1.gif"
#define    HT_ICON_BAR           "bar-bluepurple.gif"
#define    HT_ICON_SUBMIT_FORM   "calculate.gif"
#define    HT_ICON_RESET_FORM    "trash_barrel_fire.gif"



#define    HT_FONT_SIZE_BASE       3
#define    HT_FONT_SIZE_MENU_NAME  4
#define    HT_FONT_SIZE_MENU_ITEM  3
#define    HT_FONT_SIZE_ITEM_EXAMPLE 3
#define    HT_FONT_SIZE_NAVIGATOR  3
#define    HT_FONT_SIZE_TABLE_HEADER 2
#define    HT_FONT_SIZE_TABLE_DATA   2
#define    HT_FONT_SIZE_NAME       4


#define LF 10
#define CR 13

#define HT_MAX_NAME_LENGTH      1024
#define HT_MAX_ENTRIES          1000
#define HT_MAX_LINE_LENGTH      2048
#define HT_MAX_URL_LENGTH       2048


#ifndef __HTML_TYPEDEF_ENTRY_H__
#define __HTML_TYPEDEF_ENTRY_H__
  typedef struct {
    char *name;
    char *val;
    char *file;
    int  isFile;
  } entry;
#endif



typedef struct {
  char qfile[HT_MAX_NAME_LENGTH];
  char dbnm[HT_MAX_NAME_LENGTH];
  char dbvr[HT_MAX_NAME_LENGTH];
  char option[HT_MAX_NAME_LENGTH];
  char table[HT_MAX_NAME_LENGTH];
  char ppid[HT_MAX_NAME_LENGTH];
  char page[HT_MAX_NAME_LENGTH];
  char pdbid[HT_MAX_NAME_LENGTH];
  int iflag1, iflag2,  iflag3, iflag4, iflag5;
  int iflag6, iflag7, iflag8, iflag9, iflag10;
} HTSTATE;


/**PROTO*******************************************************************
 *       Prototypes for file:  ndb_htmllib.C
 */
void ht_dump_entries(entry *entries, int num);
void ht_put_open_frameset(FILE *fph, char *rows, char *cols);
void ht_put_open_frame(FILE *fph, char *src, char *name, int mwidth, int mheight, 
		   char *scroll, int resize_flag, int border);
void ht_put_close_frameset(FILE *fp);
void ht_put_content_type(FILE *fph); 
void ht_put_a_content_type(FILE *fph, const char *type); 
void ht_put_content_type_target(FILE *fph, char *target); 
void ht_put_location_type_script(FILE *fph, char *script); 
void ht_put_location_jscript(FILE *fph, char *jscript); 
void ht_put_location(FILE *fph, char *ref); 
void ht_put_location_on_server(FILE *fph, char *ref); 
void ht_put_title(FILE *fph, char *title);

void ht_put_title_w_local_jscripts(FILE *fph, char *title);
void ht_put_open_body(FILE *fph);
void ht_put_open_body_with_attributes(FILE *fph, const char *bgcolor,  const char *vlink, const char *link, const char *alink);
void ht_put_close_body(FILE *fph);
void ht_put_open_form(FILE *fph, char *script);
void ht_put_submit_reset_form_fancy(FILE *fph, char *label_submit, char *label_reset);
void ht_put_submit_reset_form(FILE *fph, char *label_submit, char *label_reset);
void ht_put_submit_form(FILE *fph, char *label_submit);
void ht_put_close_form(FILE *fph);
void ht_put_separator(FILE *fph);
void  ht_put_sf_logo_and_navigator(FILE *fph, const char *qfile, const char *dbnm, const char *dbvr, int iflag1);
void  ht_put_sf_navigator(FILE *fph, const char *qfile, const char *dbnm, const char *dbvr, int iflag1);
void ht_put_sf_address(FILE *fph);
void ht_put_anchor_with_label(FILE *fph, char *location, char *item);
void ht_put_sf_help_address(FILE *fph);
void ht_put_ndb_address(FILE *fph);
void ht_put_table_copyright_notice(FILE *fph, char *date);
void ht_put_table_copyright_notice_pf(FILE *fph, char *date);
void ht_put_header1_text(FILE *fph, char *text);
void ht_put_paragraph_break(FILE *fph);
void ht_put_line_break(FILE *fph);
void ht_put_text(FILE *fph, char *text);
void ht_put_centered_text(FILE *fph, char *text);
void ht_put_labeled_text(FILE *fph, char *label, char *text);
void ht_put_labeled_text_in_color(FILE *fph, char *label, char *text, char *color);
void ht_put_centered_menu_text(FILE *fph, char *name);
void ht_put_centered_menu_file_item(FILE *fph, char *file, char *item);
void ht_put_centered_menu_script_item(FILE *fph, char *script, char *item);
void ht_put_table_menu_item(FILE *fph, char *qfile, char *dbnm, char *dbvr, char *option, char *name, char *description);
void ht_put_column_menu_item(FILE *fph, 
			     char *qfile,
			     char *dbnm, 
			     char *dbvr, 
			     char *option,
			     char *table, 
			     char *column, 
			     char *description, 
			     char *examples, 
			     char *data_type);
void ht_put_open_preformat(FILE *fph);
void ht_put_close_preformat(FILE *fph);
void ht_put_open_definition_list(FILE *fph);
void ht_put_definition_item(FILE *fph, char *term, char *definition);
void ht_put_close_definition_list(FILE *fph);
void ht_put_open_unordered_list(FILE *fph);
void ht_put_list_item(FILE *fph, char *item);
void ht_put_close_unordered_list(FILE *fph);
void ht_put_pull_down_selection(FILE *fph, char *label, char *tag, char **items, int nitems);
void ht_put_pull_down_ordered_selection(FILE *fph, 
					char *label, 
					char *tag, 
					char **items, 
					int *iorder,
					int nitems);
void ht_put_scrolled_selection(FILE *fph, char *label, char *tag, char **items, 
			      int nitems, int ndisplay);
void ht_put_selection_navigator(FILE *fph, 
				char *qfile,
				char *dbnm, 
				char *dbvr,
				char *option,
				char *table,
				int iflag1, 
				int iflag2, 
				int iflag3,
				int iflag4,
				int iflag5);
void ht_put_sf_op_navigator(FILE *fph, 
			    const char *qfile,
			    const char *dbnm, 
			    const char *dbvr,
			    const char *option,
			    const char *table,
			    int iflag1, 
			    int iflag2, 
			    int iflag3,
			    int iflag4,
			    int iflag5,
			    int iflag6,
			    int iflag7, int iflag8, int iflag9, int iflag10);

void ht_init_htstate(HTSTATE *ht);
void ht_put_msd_op_navigator(FILE *fph, HTSTATE ht);
  

  
void ht_put_home_page_navigator(FILE *fph, char *home_page_path);
void ht_put_open_center(FILE *fph );
void ht_put_close_center(FILE *fph);
void ht_put_hidden_form_item(FILE *fph, char *name, char *value);
void ht_put_visible_form_item(FILE *fph, char *label, char *name, int size);
void ht_put_visible_form_item_default(FILE *fph, char *label, char *name, int size, char *value);
void ht_put_open_table(FILE *fph);
void ht_put_close_table(FILE *fph);
void ht_put_open_row(FILE *fph);
void ht_put_close_row(FILE *fph);
void ht_put_begin_font(FILE *fph, int font_size);
void ht_put_end_font(FILE *fph);
void ht_put_table_column_header_cj(FILE *fph, char *text);
void ht_put_table_column_header_lj(FILE *fph, char *text);
void ht_put_table_column_data_cj(FILE *fph, char *data);
void ht_put_table_column_data_lj(FILE *fph, char *data);

void getword(char *word, char *line, char stop); 
char *makeword(char *line, char stop); 
char *fmakeword(FILE *f, char stop, int *cl); 
char x2c(char *what); 
void unescape_url(char *url); 
void plustospace(char *str); 
void spacetoplus(char *str); 
int rind(char *s, char c); 
int getline(char *s, int n, FILE *f); 
void send_fd(FILE *f, FILE *fd);
int ind(char *s, char c); 
void escape_shell_cmd(char *cmd); 
void ht_strip_nl(char *string);
char *ht_get_unique_fid(void);
char *ht_get_unique_name_cluster(void);
char *ht_get_unique_name(void);
int ht_decode_multipart_form_data(entry *entries, const char *path);
char *ht_strip_leading_path(char *s);
void ht_check_get_request(void);
void ht_check_post_request(void);
int  ht_decode_cgi_query(entry entries[HT_MAX_ENTRIES]);
int  ht_decode_post_query(entry entries[HT_MAX_ENTRIES]);
int  ht_decode_post_query1(entry entries[HT_MAX_ENTRIES]);
int  ht_decode_get_query(entry *entries);
char *ht_add_script_path(char *script);
char *ht_get_keyword_value(const char *keyword, entry *entries, int nentries);
char *ht_get_keyword_file(const char *file, entry *entries, int nentries);
void ht_set_server_url(char *url);
char *ht_get_server_url(void);
void ht_set_server_cgi_path(char *path);
char *ht_get_server_cgi_path(void);
void ht_put_open_body_for_db(FILE *fph, const char *dbnm, const char *dbvr);

#if 0
#ifdef __cplusplus
}
#endif
#endif

#endif
