Index: trunk/gsdl/src/recpt/documentaction.cpp
===================================================================
--- trunk/gsdl/src/recpt/documentaction.cpp	(revision 248)
+++ trunk/gsdl/src/recpt/documentaction.cpp	(revision 257)
@@ -12,4 +12,7 @@
 /*
    $Log$
+   Revision 1.2  1999/05/10 03:40:35  sjboddie
+   lots of changes - slowly getting document action sorted out
+
    Revision 1.1  1999/04/30 01:59:40  sjboddie
    lots of stuff - getting documentaction working (documentaction replaces
@@ -34,5 +37,5 @@
 documentaction::documentaction () {
   // this action uses cgi variables "a", "d", "cl",
-  // "x", "gc", and "gt"
+  // "x", "gc", "gt", "gp", and "hl"
   cgiarginfo arg_ainfo;
   arg_ainfo.shortname = "a";
@@ -71,5 +74,7 @@
 
   // in this action "gt" controls the expand/contract
-  // text function
+  // text function 0 = not expanded, 1 = expand unless 
+  // there are more than 10 sections containing text,
+  // 2 = expand all
   arg_ainfo.shortname = "gt";
   arg_ainfo.longname = "expand text";
@@ -88,4 +93,14 @@
   arg_ainfo.argdefault = "";
   arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // in this action "hl" is the "highlighting on/
+  // highlighting off control
+  arg_ainfo.shortname = "hl";
+  arg_ainfo.longname = "highlighting on/off";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
   argsinfo.addarginfo (NULL, arg_ainfo);
 
@@ -199,4 +214,5 @@
       
       metadata.push_back ("Title");
+      metadata.push_back ("classifytype");
       get_children ("", args["c"], metadata, collectproto, response, logout);
 
@@ -236,15 +252,20 @@
 	dochere = response.docInfo.begin();
 	while (dochere != docend) {
+	  const text_t &title = (*dochere).metadata[0].values[0];
+	  const text_t &classifytype = (*dochere).metadata[1].values[0];
+
 	  // if we're inside a document all the classification buttons should be enabled
 	  if (args["d"].empty() && ((*dochere).OID == topparent))
-	    navigationbar += "_imagespacer__icontab" + (*dochere).metadata[0].values[0] + "green_";
+	    navigationbar += "_imagespacer__icontab" + title + "green_";
 	  else {
-	    navigationbar += "_imagespacer__image" + (*dochere).metadata[0].values[0] + "_";
+	    navigationbar += "_imagespacer__image" + title + "_";
 
 	    // set the _httpbrowseXXX_ macro for this classification
-	    disp.setmacro ("httpbrowse" + (*dochere).metadata[0].values[0],
-			   "Global", "_httpdocument_&cl=" + (*dochere).OID + ".fc");
+	    text_t link = (*dochere).OID;
+	    if (classifytype == "AZList" || classifytype == "Datelist") link += ".fc";
+	    disp.setmacro ("httpbrowse" + title, "Global", 
+			   "_httpdocument_&cl=" + link);
 	  }
-	  javaimagesnavbar += "_java" + (*dochere).metadata[0].values[0] + "_";
+	  javaimagesnavbar += "_java" + title + "_";
 	  dochere ++;
 	}
@@ -277,5 +298,5 @@
 
   // _httpprevarrow_        these are set if next or previous arrows
-  // _httpnextarrow_        are to be used - (i.e. if it's a List or a Datelist 
+  // _httpnextarrow_        are to be used - (i.e. if it's an AZList or a Datelist 
   //                        classifytype at a top level or if it's a Book or a
   //                        Hierarchy classifytype at document level 
@@ -283,4 +304,8 @@
   // _header_               the header macro is overridden if we're not at a top level 
   //                        classification to remove the title block
+
+  // _javaimagescontent_     this is the javascript code to shove in to make the 
+  //                         flashy buttons work
+
   
   text_tarray metadata;
@@ -292,15 +317,33 @@
   if (!args["d"].empty()) {
     // we're at document level
+    text_t javaimagescontent;
 
     // get metadata for top level of document
-    text_t doctop = args["d"]; 
-    text_t classifytype;
+    text_t doctop;
     get_top (args["d"], doctop);
     if (get_info (doctop, args["c"], metadata, collectproto, response, logout)) {
       disp.setmacro ("header", "document", "_textheader_");
-      classifytype = response.docInfo[0].metadata[1].values[0];
+      text_t &classifytype = response.docInfo[0].metadata[1].values[0];
       if (classifytype.empty()) classifytype = "Book"; // defaults to Book
       if ((classifytype == "Book") || (classifytype == "Hierarchy"))
 	set_arrow_macros (args["d"], classifytype, disp, collectproto, args["c"], logout);
+
+      if (args["u"] != "1") {
+	javaimagescontent += "_javadetach_";
+	if (args["gt"] == "1") 
+	  javaimagescontent += "_javacontracttext__javacontinue_";
+	else 
+	  javaimagescontent += "_javaexpandtext_";
+	if (classifytype == "Hierarchy")
+	  if (args["gc"] == "1")
+	    javaimagescontent += "_javacontractcontents_";
+	  else 
+	    javaimagescontent += "_javaexpandcontents_";
+	if (args["hl"] != "1")
+	  javaimagescontent += "_javahighlighting_";
+	else 
+	  javaimagescontent += "_javanohighlighting_";
+	disp.setmacro ("javaimagescontent", "document", javaimagescontent);
+      }
     }
   } else {
@@ -308,10 +351,13 @@
 	
       // get metadata for top level classification
-      text_t classtop = args["cl"];
+      text_t classtop;
       get_top (args["cl"], classtop);
       if (get_info (classtop, args["c"], metadata, collectproto, response, logout)) {
 	  
+	text_t &title = response.docInfo[0].metadata[0].values[0];
+	text_t &classifytype = response.docInfo[0].metadata[1].values[0];
+
 	disp.setmacro ("imagethispage", "document", 
-		       "_icon" + response.docInfo[0].metadata[0].values[0] + "page_");
+		       "_icon" + title + "page_");
 
 	// now get the metadata for each child of top level
@@ -319,6 +365,5 @@
 	// (if they're required by the current classification type)
 	
-	if ((response.docInfo[0].metadata[1].values[0] == "List") || 
-	    (response.docInfo[0].metadata[1].values[0] == "Datelist")) {
+	if ((classifytype == "AZList") || (classifytype == "Datelist")) {
 	  
 	  text_t classificationlinks, navarrows;
@@ -378,49 +423,123 @@
   text_tarray metadata;
   FilterResponse_t response;
+  DocumentRequest_t docrequest;
+  DocumentResponse_t docresponse;
   text_t topparent, classifytype, classifytitle;
+  comerror_t err;
+
+  text_t &arg_d = args["d"];
+  text_t &arg_cl = args["cl"];
+  text_t &collection = args["c"];
+
+  text_t OID = arg_d;
+  if (arg_d.empty()) OID = arg_cl;
 
   textout << outconvert << disp << "_document:header_\n"
 	  << "_document:content_\n";
   
-  if (args["d"].empty() && args["cl"].empty())
-    textout << outconvert << "Document contains no data\n";
-  else {
-
-    if (!args["d"].empty()) get_top (args["d"], topparent);
-    else get_top (args["cl"], topparent);
-
-    // get the classifytitle and classifytype
-    metadata.push_back ("Title");
-    metadata.push_back ("classifytype");
-    if (get_info (topparent, args["c"], metadata, collectproto, response, logout)) {
-      classifytitle = response.docInfo[0].metadata[0].values[0];
-      classifytype = response.docInfo[0].metadata[1].values[0];
+  if (arg_d.empty() && arg_cl.empty()) {
+    textout << outconvert << "Document contains no data_document:footer_\n";
+    return true;
+  }
+
+  // get the classifytitle and classifytype
+  get_top (OID, topparent);
+  metadata.push_back ("Title");
+  metadata.push_back ("classifytype");
+  if (get_info (topparent, collection, metadata, collectproto, response, logout)) {
+    classifytitle = response.docInfo[0].metadata[0].values[0];
+    classifytype = response.docInfo[0].metadata[1].values[0];
+  }
+
+  if (!arg_d.empty()) {
+    
+    if (classifytype == "Hierarchy")
+      output_hierarchy_toc (classifytitle, args, collectproto, disp, 
+			    outconvert, textout, logout);
+    else
+      // Book is the default for a document level toc - AZList and Datelist don't
+      // make sense for document level
+      output_book_toc (classifytitle, args, collectproto, disp,
+		       outconvert, textout, logout);
+  } else {
+    
+    if (classifytype == "Hierarchy")
+      output_hierarchy_toc (classifytitle, args, collectproto, disp, 
+			    outconvert, textout, logout);
+    else if (classifytype == "Datelist")
+      output_datelist_toc (classifytitle, args, collectproto, disp, 
+			   outconvert, textout, logout);
+    else 
+      // AZList is the default for a classification level toc - Book doesn't make 
+      // sense for classification level
+      output_azlist_toc (classifytitle, args, collectproto, disp, 
+			 outconvert, textout, logout);
+  }
+
+  // get info on this document
+  metadata.erase (metadata.begin(), metadata.end());
+  metadata.push_back("Title");
+  metadata.push_back("hastxt");
+  metadata.push_back("haschildren");
+
+  if (get_info (OID, collection, metadata, collectproto, response, logout)) {
+    text_t &title = response.docInfo[0].metadata[0].values[0];
+    int hastxt = response.docInfo[0].metadata[1].values[0].getint();
+    int haschildren = response.docInfo[0].metadata[2].values[0].getint();
+
+    int gt = args.getintarg("gt");
+    if (gt == 0) {
+      if (hastxt == 1) {
+	// get the text
+	docrequest.OID = OID;
+	collectproto->get_document (collection, docrequest, docresponse, err, logout);
+	
+	textout << outconvert << disp 
+		<< "<p>\n<h3>" << title << "</h3>" << docresponse.doc;
+      }
+    } else {
+
+      // text is to be expanded
+      int tmp; // this doesn't get used here
+      if (!haschildren)
+	OID = get_parent (OID);
+
+      get_contents (OID, classifytype, tmp, collection, collectproto, response, logout);
+	      
+      ResultDocInfo_tarray::const_iterator sechere = response.docInfo.begin();
+      ResultDocInfo_tarray::const_iterator secend = response.docInfo.end();
+	      
+      if (gt == 1) {
+	// check if there are more than 10 sections containing text to be expanded - 
+	// if there are output warning message - this isn't a great way to do this
+	// since the sections may be very large or very small - one day I'll fix it 
+	// -- Stefan.
+	int seccount = 0;
+	while (sechere != secend) {
+	  if ((*sechere).metadata[3].values[0] == "1") seccount ++;
+	  if (seccount > 10) break;
+	  sechere ++;
+	}
+	if (seccount > 10) textout << outconvert << disp << "_document:textltwarning_";
+	else gt = 2;
+      }
+
+      if (gt == 2) {
+	// get the text for each section
+	sechere = response.docInfo.begin();
+	int count = 0;
+	while (sechere != secend) {
+	  textout << outconvert << disp << "\n<p><a name=" << count << "><h3>" 
+		  << (*sechere).metadata[0].values[0] << "</h3></a>\n";
+	  if ((*sechere).metadata[3].values[0] == "1") {
+	    docrequest.OID = (*sechere).OID;
+	    collectproto->get_document (collection, docrequest, docresponse, err, logout);
+	    textout << outconvert << disp << docresponse.doc;
+	  }
+	  count ++;
+	  sechere ++;
+	}
+      }
     }
-
-    if (!args["d"].empty()) {
-
-      if (classifytype == "Hierarchy")
-	output_hierarchy_toc (classifytitle, args, collectproto, disp, 
-			      outconvert, textout, logout);
-      else
-	// Book is the default for a document level toc - List and Datelist don't
-	// make sense for document level
-	output_book_toc (classifytitle, args, collectproto, disp,
-			 outconvert, textout, logout);
-    } else {
-
-      if (classifytype == "Hierarchy")
-	output_hierarchy_toc (classifytitle, args, collectproto, disp, 
-			      outconvert, textout, logout);
-      else if (classifytype == "Datelist")
-	output_datelist_toc (classifytitle, args, collectproto, disp, 
-			     outconvert, textout, logout);
-      else 
-	// List is the default for a classification level toc - Book doesn't make 
-	// sense for classification level
-	output_list_toc (classifytitle, args, collectproto, disp, 
-			 outconvert, textout, logout);
-    }
-
   }
   textout << outconvert << disp << "_document:footer_\n";
