source: trunk/gsdl/src/recpt/browsetools.cpp@ 541

Last change on this file since 541 was 541, checked in by rjmcnab, 25 years ago

removed some compiler warnings.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 29.6 KB
RevLine 
[208]1/**********************************************************************
2 *
3 * browsetools.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
[533]6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
[208]9 *
[533]10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
[208]24 * $Id: browsetools.cpp 541 1999-09-07 23:06:58Z rjmcnab $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
[541]30 Revision 1.22 1999/09/07 23:06:58 rjmcnab
31 removed some compiler warnings.
32
[533]33 Revision 1.21 1999/09/07 04:56:52 sjboddie
34 added GPL notice
35
[469]36 Revision 1.20 1999/08/25 04:46:58 sjboddie
37 fixed bug
38
[458]39 Revision 1.19 1999/08/13 04:18:04 sjboddie
40 fixed some typos
41
[444]42 Revision 1.18 1999/08/10 22:42:21 sjboddie
43 added more format options to document tocs - there are now just two
44 types of toc - standard (Hierarchical) and document (as in books)
45
[436]46 Revision 1.17 1999/08/09 02:12:07 sjboddie
47 made it so dates may be only 4 digits (i.e. year only)
48
[419]49 Revision 1.16 1999/07/30 02:16:10 sjboddie
50 -added ability to display nested classifications (expanded versions
51 of nested classifications has yet to be done).
52 -changed set_arrow_macros slightly to fit in with new showtoppage
53 format option
54
[412]55 Revision 1.15 1999/07/21 05:01:56 sjboddie
56 wrote handler for DateList classification
57
[404]58 Revision 1.14 1999/07/20 02:58:15 sjboddie
59 got List and AZList classifications using format strings - tidied
60 up a bit
61
[344]62 Revision 1.13 1999/07/07 05:44:25 sjboddie
63 Made some changes to allow for new way classifiers work (i.e. you can
64 now have classifiers containing other classifiers). At present there's
65 only a special case for dealing with the hdl 'magazine' section. A bit
66 of a redesign is needed to get it completely flexible
67
[322]68 Revision 1.12 1999/07/01 03:47:49 rjmcnab
69 Fixed a small warning.
70
[297]71 Revision 1.11 1999/06/27 21:49:01 sjboddie
72 fixed a couple of version conflicts - tidied up some small things
73
[293]74 Revision 1.10 1999/06/26 01:07:21 rjmcnab
75 Fixed a small "bug" -- well I probably just covered another one...
76
[284]77 Revision 1.9 1999/06/24 05:12:15 sjboddie
78 lots of small changes
79
[282]80 Revision 1.8 1999/06/17 03:06:53 sjboddie
81 got detach button working properly - the close book icon is now disabled
82 when page is detached as the javascript close() function I was using is
83 too unreliable over different browsers
84 note that in my last comment I meant the "cl" arg (not the "c" arg).
85
[281]86 Revision 1.7 1999/06/16 23:53:14 sjboddie
87 tidied a few things up. documentaction::define_external_macros now
88 resets the "c" arg if it's set to something stupid by the .xx suffixes
89
[279]90 Revision 1.6 1999/06/16 04:03:47 sjboddie
91 Now sets "cl" arg to "search" when going to a document from a search
92 results page. This allows the close book icon (in hierarchy toc) to
93 take you back to the results page if that's where you came from.
94 If you got to the document page somehow other than from a
95 classification or a search (i.e. if "cl" isn't set) then the close
96 book icon is disabled
97
[278]98 Revision 1.5 1999/06/16 03:11:25 sjboddie
99 get_info() now takes a getParents argument
100
[257]101 Revision 1.4 1999/05/10 03:40:26 sjboddie
102 lots of changes - slowly getting document action sorted out
103
[248]104 Revision 1.3 1999/04/30 01:59:39 sjboddie
105 lots of stuff - getting documentaction working (documentaction replaces
106 old browseaction)
107
[213]108 Revision 1.2 1999/03/29 02:14:29 sjboddie
109
110 More changes to browseaction
111
[208]112 Revision 1.1 1999/03/25 03:10:15 sjboddie
113
114 new library for browse stuff
115
116 */
117
118
119#include "browsetools.h"
[213]120#include "OIDtools.h"
[208]121
[404]122// simply checks to see if formatstring begins with a <td> tag
123static bool is_table_content (const text_t &formatstring) {
124 text_t::const_iterator here = formatstring.begin();
125 text_t::const_iterator end = formatstring.end();
126
127 while (here != end) {
128 if (*here != ' ') {
129 if (*here == '<') {
130 if ((*(here+1) == 't' || *(here+1) == 'T') &&
131 (*(here+2) == 'd' || *(here+2) == 'D') &&
132 (*(here+3) == '>' || *(here+3) == ' '))
133 return true;
134 } else return false;
135 }
136 here ++;
137 }
138 return false;
139}
140
[419]141static bool is_table_content (const format_t *formatlistptr) {
[404]142
[419]143 if (formatlistptr == NULL) return false;
144
145 if (formatlistptr->command == comText)
146 return is_table_content (formatlistptr->text);
147
148 return false;
149}
150
151
[404]152// output_controls displays the detach, expand/contract contents,
153// expand/contract text and highlighting/no highlighting buttons
[444]154static void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
[541]155 recptproto * /*collectproto*/, displayclass &disp,
[444]156 outconvertclass &outconvert, ostream &textout,
157 ostream &/*logout*/) {
[404]158
159 if (args["u"] != "1") {
160
161 FilterResponse_t response;
162 text_tarray metadata;
163 text_tarray buttons;
164
[444]165 text_tarray::const_iterator here = ibuttons.begin();
166 text_tarray::const_iterator end = ibuttons.end();
[404]167
[444]168 while (here != end) {
169
170 if (*here == "Detach")
171 buttons.push_back ("_document:imagedetach_");
172 else if (*here == "Highlight") {
173 if (args["hl"] == "1")
174 buttons.push_back ("_document:imagenohighlight_");
175 else
176 buttons.push_back ("_document:imagehighlight_");
177 } else if (*here == "Expand Contents") {
[404]178 if (args["gc"] == "1")
179 buttons.push_back ("_document:imagecontracttoc_");
180 else
181 buttons.push_back ("_document:imageexpandtoc_");
[444]182 } else if (*here == "Expand Text") {
183 if (args.getintarg("gt"))
184 buttons.push_back ("_document:imagecontracttext_");
185 else
186 buttons.push_back ("_document:imageexpandtext_");
187 }
188 here ++;
[404]189 }
190
[444]191 here = buttons.begin();
192 end = buttons.end();
[404]193 int count = 0;
194 while (here != end) {
195 if ((count != 0) && ((count % 3) == 0)) textout << "<br>\n";
196 textout << outconvert << disp << *here;
197 count ++;
198 here ++;
199 }
200 }
201}
202
203
[419]204// at the moment this just writes out the html to display
205// the cover image (assuming it's called cover.jpg)
206// this whole thing should be done with a call to the collection
207// server which would send a link to the cover image if there
208// was one otherwise send title, author and stuff
[541]209static void output_cover_image (cgiargsclass &args, recptproto * /*collectproto*/,
[419]210 displayclass &disp, outconvertclass &outconvert,
211 ostream &textout, ostream &/*logout*/) {
212
213 if (args["d"].empty()) return;
214
215 textout << outconvert << disp <<
216 "<img src=\"_httpcollection_/archives/_thisOID_/cover.jpg\"><br>\n";
217}
[404]218
[419]219
220
[344]221/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[444]222Functions for generating a document type tables of contents. These aren't really tables of
223contents at all, just a title, some navigation buttons and arrows and maybe a page ? of ?
224type thing. These should only be called for document level tocs (i.e. when the "d" argument
225is set) as I don't think it makes sense to display top level classifications in this way.
[344]226-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
227
[444]228void output_document_toc (cgiargsclass &args, const formatinfo_t &formatinfo,
229 recptproto *collectproto, displayclass &disp,
230 outconvertclass &outconvert, ostream &textout,
231 ostream &logout) {
[344]232
[419]233 text_t &arg_d = args["d"];
234 if (arg_d.empty()) return;
[213]235
[248]236 text_tarray metadata;
237 FilterResponse_t response;
[444]238 bool getParents = false;
[248]239 ResultDocInfo_t docinfo;
[419]240 text_t &collection = args["c"];
[444]241 int gt = args.getintarg("gt");
[213]242
[444]243 bool istop = is_top (arg_d);
244
245 format_t *formatlistptr = new format_t();
246 parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
247
248 text_tarray OIDs;
249 OIDs.push_back (arg_d);
250 if (formatinfo.DocumentArrowsTop && !gt && !istop)
251 OIDs.push_back (arg_d + ".pr.lc");
252
[248]253 metadata.push_back ("Title");
[444]254 int metasize = metadata.size();
[419]255
[444]256 if (get_info (OIDs, collection, metadata, getParents, collectproto, response, logout)) {
257
258 text_t &thistitle = response.docInfo[0].metadata[metasize-1].values.back();
259 text_t last_sib_title;
[469]260 if (formatinfo.DocumentArrowsTop && !gt && !istop) {
261 if (response.docInfo.size() == 1)
262 last_sib_title = response.docInfo[0].metadata[metasize-1].values.back();
263 else
264 last_sib_title = response.docInfo[1].metadata[metasize-1].values.back();
265 }
[213]266
[248]267 textout
[458]268 << "\n<!-- Table of Contents produced by browsetools::output_document_toc -->\n\n";
[444]269
[248]270 textout << outconvert << disp
271 << "<p><center>\n"
272 << "<table cellpadding=0 cellspacing=0 width=_pagewidth_>\n"
[257]273 << "<tr valign=top><td>\n";
[248]274
[444]275 // top arrows and page ? of ? title
276 if (formatinfo.DocumentArrowsTop && !gt) {
277
[248]278 // previous arrow
[419]279 textout << outconvert << disp << "<table><tr valign=top>\n"
280 << "<td align=left>_document:prevarrow_</td>\n";
[444]281
[248]282 // page ? of ? text
[419]283 textout << "<td align=center>\n";
[248]284
[444]285 if (!istop && is_number (thistitle) && is_number (last_sib_title))
286 textout << outconvert << disp << "_document:page_" << thistitle
287 << "_document:of_" << last_sib_title;
288
289 else
290 textout << outconvert << thistitle;
[248]291
292 // next arrow
[257]293 textout << outconvert << disp << "</td>\n<td align=right>_document:nextarrow_</td>\n</table>\n";
[213]294 }
[257]295
296 // goto line
[444]297 if (formatinfo.DocumentGoTo)
298 textout << outconvert << disp << "_document:gotoform_";
[257]299
300 // control buttons
[444]301 output_controls (args, formatinfo.DocumentButtons, collectproto,
302 disp, outconvert, textout, logout);
[257]303 textout << "</td>\n";
304
[444]305 // heading
306 textout << outconvert << "\n<td valign=top>\n"
307 << get_formatted_string (response.docInfo[0], formatlistptr);
[213]308
[281]309 textout << "</td></tr></table></center>\n";
[257]310 textout << "\n<!-- end of Table of Contents -->\n";
[213]311 }
312}
313
[257]314
[344]315/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
316Functions for generating a "Hierarchy" type table of contents. These can be used either
317at top classification level or at document level (the difference being that a cover
[436]318image and control buttons may be displayed at document level).
[344]319-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
320
[404]321// prototypes
322
[419]323static void output_contracted_hierarchy_toc (const text_t &classifytype, text_t &formatstring,
324 cgiargsclass &args, recptproto *collectproto,
325 displayclass &disp, outconvertclass &outconvert,
326 ostream &textout, ostream &logout);
327
[404]328static void output_expanded_hierarchy_toc (cgiargsclass &args, recptproto *collectproto,
329 displayclass &disp, outconvertclass &outconvert,
330 ostream &textout, ostream &logout);
[419]331
332static void output_parents_toc (cgiargsclass &args, const FilterResponse_t &parents,
333 int &tabcount, displayclass &disp,
334 format_t *formatlistptr, outconvertclass &outconvert,
[404]335 ostream &textout, ostream &logout);
336
[419]337static void output_siblings_toc (const text_t &classifytype, cgiargsclass &args,
338 const FilterResponse_t &siblings, int &tabcount,
339 displayclass &disp, format_t *formatlistptr,
340 outconvertclass &outconvert, ostream &textout,
341 ostream &logout);
[404]342
[419]343static void output_stdlist (cgiargsclass &args, ResultDocInfo_tarray::const_iterator &here,
344 ResultDocInfo_tarray::const_iterator &end, bool intable,
345 displayclass &disp, format_t *formatlistptr,
346 outconvertclass &outconvert, ostream &textout);
[344]347
[419]348static void output_datelist (cgiargsclass &args, ResultDocInfo_tarray::const_iterator &here,
349 ResultDocInfo_tarray::const_iterator &end, bool intable,
350 displayclass &disp, format_t *formatlistptr,
351 outconvertclass &outconvert, ostream &textout);
[257]352
[419]353
[444]354void output_standard_toc (const text_t &classifytype, const formatinfo_t &formatinfo,
355 text_t &formatstring, cgiargsclass &args,
356 recptproto *collectproto, displayclass &disp,
357 outconvertclass &outconvert, ostream &textout,
358 ostream &logout) {
[419]359
360 bool havecontrols = false;
361
[458]362 textout << "\n<!-- Table of Contents produced by browsetools::output_standard_toc -->\n\n";
[419]363
[257]364 // get the cover image (if there is one) and the control buttons
[419]365 // if we're inside a book
[257]366 if (!args["d"].empty()) {
[419]367 textout << "<p><table cellpadding=0 cellspacing=0><tr>\n";
[257]368 textout << "<td valign=top width=200>\n";
[444]369 if (formatinfo.DocumentImages)
370 output_cover_image (args, collectproto, disp, outconvert, textout, logout);
371 output_controls (args, formatinfo.DocumentButtons, collectproto, disp,
372 outconvert, textout, logout);
[419]373 textout << "</td><td valign=top>\n";
374 havecontrols = true;
[257]375 }
[248]376
[213]377 // get table of contents
[419]378 textout << "<table>\n";
[344]379
[213]380 if (args.getintarg("gc"))
[257]381 output_expanded_hierarchy_toc(args, collectproto, disp, outconvert, textout, logout);
[213]382 else
[419]383 output_contracted_hierarchy_toc(classifytype, formatstring, args, collectproto,
384 disp, outconvert, textout, logout);
[208]385
[419]386 textout << "</table>\n";
[213]387
[419]388 if (havecontrols) textout << "</td></tr></table>\n";
[213]389
[419]390 textout << "\n<!-- end of Table of Contents -->\n";
[257]391}
392
393
[419]394void output_contracted_hierarchy_toc (const text_t &classifytype, text_t &formatstring,
395 cgiargsclass &args, recptproto *collectproto,
396 displayclass &disp, outconvertclass &outconvert,
397 ostream &textout, ostream &logout) {
[208]398
[419]399 int tabcount = 0;
[257]400 text_tarray parents, metadata;
[419]401 FilterResponse_t fsiblings, fparents;
[404]402 bool getParents = false;
[213]403
[257]404 text_t &arg_d = args["d"];
[419]405 text_t OID = arg_d;
406 if (OID.empty()) OID = args["cl"];
407 text_t &collection = args["c"];
[213]408
[419]409 // if format string is empty use the default
410 if (formatstring.empty())
411 formatstring = "<td valign=top nowrap>[link][icon][/link]</td><td>{Or}{[Title],Untitled}</td>";
412
413 format_t *formatlistptr = new format_t();
414 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
415
416 metadata.push_back ("Date");
[257]417 metadata.push_back ("hastxt");
418 metadata.push_back ("haschildren");
[419]419 metadata.push_back ("doctype");
420 metadata.push_back ("classifytype");
[257]421
[419]422 if (has_children (OID, collection, collectproto, logout)) {
423 get_parents_array (OID + ".fc", parents);
[404]424
[419]425 if (!get_children (OID, collection, metadata, getParents,
426 collectproto, fsiblings, logout))
[257]427 return;
[419]428 } else {
429 get_parents_array (OID, parents);
430 if (!get_children (OID + ".pr", collection, metadata,
431 getParents, collectproto, fsiblings, logout))
[257]432 return;
[419]433 }
434 if (!get_info (parents, collection, metadata, false, collectproto, fparents, logout)) return;
435
436 if (!fparents.docInfo.empty())
437 output_parents_toc(args, fparents, tabcount, disp,
438 formatlistptr, outconvert, textout, logout);
439
440 if (!fsiblings.docInfo.empty())
441 output_siblings_toc (classifytype, args, fsiblings, tabcount, disp,
442 formatlistptr, outconvert, textout, logout);
443}
[344]444
[419]445void output_parents_toc (cgiargsclass &args, const FilterResponse_t &parents,
446 int &tabcount, displayclass &disp,
447 format_t *formatlistptr, outconvertclass &outconvert,
448 ostream &textout, ostream &/*logout*/) {
[344]449
[419]450 text_t tab, icon;
451 text_t &arg_cl = args["cl"];
452 text_t &arg_d = args["d"];
453 int numcols = parents.docInfo.size() + 1;
454
455 bool intable = is_table_content (formatlistptr);
456
457 ResultDocInfo_tarray::const_iterator thisparent = parents.docInfo.begin();
458 ResultDocInfo_tarray::const_iterator end = parents.docInfo.end();
459
460 int len = (*thisparent).metadata.size();
461 const text_t &classifytype = (*thisparent).metadata[len-1].values[0];
462
463 // don't want top level of any classifications to be displayed
464 if (arg_d.empty() && thisparent != end) {thisparent ++; numcols --;}
465
466 // don't want second level of classifications using classification links
467 if ((classifytype == "AZList" || classifytype == "DateList") && (thisparent != end))
468 {thisparent ++; numcols --;}
469
470 // the tab line
471 if (thisparent != end) {
472 text_t coltabs;
473 for (int i = 0; i < numcols; i ++) coltabs += "_document:tab_";
474 textout << outconvert << disp << "<tr>" << coltabs << "<td></td></tr>\n";
[257]475 }
476
[419]477 while (thisparent != end) {
[213]478
[419]479 const text_t &doctype = (*thisparent).metadata[len-2].values.back();
480
481 // set up icon and pointer
482 icon = "_document:icon";
483 if ((doctype != "classify") && ((*thisparent).OID == arg_d))
484 icon += "arrow";
485 if (doctype == "classify") icon += "openbookshelf_";
486 else if (is_top((*thisparent).OID)) icon += "openbook_";
487 else icon += "openfolder_";
488
489 if (tabcount == 1) textout << "<td></td>\n";
490 else if (tabcount > 1) textout << "<td colspan=" << tabcount << "></td>";
491
492 // set up the link
493 text_t link = "<a href=\"_httpdocument_";
494 if (is_top((*thisparent).OID) && args.getintarg("x")) link = "<a name=top>";
495 else
496 if (doctype == "classify") link += "&cl=" + (*thisparent).OID + ".pr\">";
497 else
498 if (is_top ((*thisparent).OID))
499 if (arg_cl.empty())
500 link = "<a name=top>";
501 else if (arg_cl == "search")
502 link = "<a href=\"_httpquery_\">";
503 else
504 link += "&cl=" + arg_cl + "\">";
505 else link += "&cl=" + arg_cl + "&d=" + (*thisparent).OID + ".pr\">";
506
507 if ((numcols-tabcount) == 1) textout << "<td>";
508 else if ((numcols-tabcount) > 1) textout << "<td colspan="
509 << (numcols-tabcount) << ">";
510
511 if (intable) textout << "<table><tr>";
512
513 textout << outconvert << disp
514 << get_formatted_string (*thisparent, formatlistptr, link, icon);
515
516 if (intable) textout << "</tr></table>";
517 textout << "</td></tr>\n";
518
519 tabcount ++;
520 thisparent ++;
521 }
522}
523
524
525void output_siblings_toc (const text_t &classifytype, cgiargsclass &args,
526 const FilterResponse_t &siblings, int &tabcount,
527 displayclass &disp, format_t *formatlistptr,
528 outconvertclass &outconvert, ostream &textout,
529 ostream &/*logout*/) {
530
531 bool intable = is_table_content (formatlistptr);
532
533 ResultDocInfo_tarray::const_iterator thissibling = siblings.docInfo.begin();
534 ResultDocInfo_tarray::const_iterator sibend = siblings.docInfo.end();
535
536 if (thissibling == sibend) return;
537
538 // tabbing
539 if (tabcount) {
540 if (tabcount == 1) textout << "<tr><td></td>\n";
541 else if (tabcount > 1) textout << "<tr><td colspan=" << tabcount << "></td>";
542 textout << "<td><table>\n";
543 }
544
545 if (!intable) textout << "<tr><td>\n";
[213]546
[419]547 if (classifytype == "DateList")
548 output_datelist (args, thissibling, sibend, intable, disp,
549 formatlistptr, outconvert, textout);
550 else
551 output_stdlist (args, thissibling, sibend, intable, disp,
552 formatlistptr, outconvert, textout);
553
554 if (!intable) textout << "</td></tr></table>\n";
555 if (tabcount) textout << "</table></td></tr>\n";
[208]556}
[213]557
[419]558void output_stdlist (cgiargsclass &args, ResultDocInfo_tarray::const_iterator &here,
559 ResultDocInfo_tarray::const_iterator &end, bool intable,
560 displayclass &disp, format_t *formatlistptr,
561 outconvertclass &outconvert, ostream &textout) {
[213]562
[419]563 text_t icon;
564 int count = 1;
565 int gt = args.getintarg("gt");
566 text_t &arg_cl = args["cl"];
567 text_t &arg_d = args["d"];
568
569 while (here != end) {
570
571 int len = (*here).metadata.size();
572 const text_t &doctype = (*here).metadata[len-2].values.back();
573 const text_t &hastxt = (*here).metadata[len-4].values.back();
574 const text_t &haschildren = (*here).metadata[len-3].values.back();
575
576 // set up icon and pointer
577 icon = "_document:icon";
578 if (doctype == "classify") {
579 if (((*here).OID == arg_cl) && (hastxt == "1"))
580 icon += "arrow";
581 } else if ((*here).OID == arg_d) icon += "arrow";
582
583 if (haschildren == "0") icon += "smalltext_";
584 else if (doctype == "classify") icon += "closedbookshelf_";
585 else if (is_top((*here).OID)) icon += "closedbook_";
586 else icon += "closedfolder_";
587
588 // set up link
589 text_t link = "<a href=\"_httpdocument_";
590 if (doctype == "classify") link += "&cl=" + (*here).OID + "\">";
591 else link += "&cl=" + arg_cl + "&d=" + (*here).OID + "\">";
592 if (gt) {
593 link = "<a href=\"#" + text_t(count) + "\">";
594 count ++;
595 }
596
597 if (intable) textout << "<tr>";
598
599 textout << outconvert << disp
600 << get_formatted_string (*here, formatlistptr, link, icon) << "\n";
601
602 if (intable) textout << "</tr>";
603
604 here ++;
605 }
606}
607
608
609void output_datelist (cgiargsclass &args, ResultDocInfo_tarray::const_iterator &here,
610 ResultDocInfo_tarray::const_iterator &end, bool intable,
611 displayclass &disp, format_t *formatlistptr,
612 outconvertclass &outconvert, ostream &textout) {
613
614 text_t lastyear = "0000";
615 text_t lastmonth = "00";
616
617 while (here != end) {
618
619 int len = (*here).metadata.size();
620 const text_t &doctype = (*here).metadata[len-2].values.back();
621 const text_t &date = (*here).metadata[len-5].values.back();
622
623 // bail on this document if it has no date
624 if (date.empty()) continue;
625
626 text_t::const_iterator datebegin = date.begin();
[436]627 int datesize = date.size();
628
629 if (datesize < 4) continue;
630 text_t thisyear = substr (datebegin, datebegin+4);
631 text_t thismonth = "00";
632 if (datesize >= 6)
633 thismonth = substr (datebegin+4, datebegin+6);
[419]634
635 text_t link = "<a href=\"_httpdocument_&cl=";
636 text_t icon = "_document:iconclosedbook_";
637
638 if (doctype == "classify") {
639 icon = "_document:iconclosedbookshelf_";
640 link += (*here).OID + "\">";
641 } else link += args["cl"] + "&d=" + (*here).OID + "\">";
642
643 textout << "<tr>\n";
644
645 if (thisyear != lastyear) {
646 textout << outconvert << "<td><b>" << thisyear << "</b></td>";
647 lastyear = thisyear;
648 } else
649 textout << "<td></td>";
650
651 if (thismonth != lastmonth) {
652 textout << outconvert << disp << ("<td><b>_textmonth" + thismonth + "_</b></td>");
653 lastmonth = thismonth;
654 } else
655 textout << "<td></td>";
656
657 if (!intable) textout << "<td>\n";
658
659 textout << outconvert << disp
660 << get_formatted_string (*here, formatlistptr, link, icon) << "\n";
661
662 if (!intable) textout << "</td>";
663
664 textout << "</tr>\n";
665
666 here ++;
667 }
668}
669
[257]670void output_expanded_hierarchy_toc (cgiargsclass &args, recptproto *collectproto,
671 displayclass &disp, outconvertclass &outconvert,
672 ostream &textout, ostream &logout) {
[213]673
[257]674 text_t OID, topOID, classifytype, icon;
675 FilterResponse_t response;
[322]676 int tabcols=0, totalcols=0, lasttabcols=0;
[257]677
678 int gt = args.getintarg("gt");
679 text_t doclink = "<a href=\"_httpdocument_&cl=";
680
[279]681 text_t &arg_d = args["d"];
682 text_t &arg_cl = args["cl"];
683
684 if (arg_d.empty()) {
685 if (arg_cl.empty()) return;
686 OID = arg_cl;
[257]687 topOID = OID; // don't always want to expand from top if expanding classifications
688 classifytype = "classify";
689 } else {
[279]690 OID = arg_d;
691 get_top (arg_d, topOID);
[257]692 classifytype = "Document";
693 }
694
695 // Get OIDs and metadata of all topOIDs contents (and topOID itself)
[444]696 text_tarray metadata;
697 metadata.push_back ("Title");
698 metadata.push_back ("haschildren");
699 metadata.push_back ("doctype");
700 // metadata.push_back ("hastxt");
701
702 get_contents (topOID, classifytype, metadata, totalcols,
703 args["c"], collectproto, response, logout);
[257]704 int excess = countchar (topOID.begin(), topOID.end(), '.');
705 totalcols -= excess;
706
707 // allow for pointer
708 if (classifytype == "Document" && !gt) totalcols += 2;
709 else totalcols += 1;
710
711 ResultDocInfo_tarray::const_iterator thissection = response.docInfo.begin();
712 ResultDocInfo_tarray::const_iterator lastsection = response.docInfo.end();
[213]713
714 int count = 1;
[257]715 while (thissection != lastsection) {
716
717 const text_t &title = (*thissection).metadata[0].values[0];
718 const int haschildren = (*thissection).metadata[1].values[0].getint();
719 const text_t &doctype = (*thissection).metadata[2].values[0];
[213]720
[257]721 text_t icontabs, tab, pointer;
722
[213]723 // set up icon
[284]724 icon = "_document:iconsmalltext_";
[257]725 if (is_top((*thissection).OID))
[284]726 if (classifytype == "Document") icon = "_document:iconopenbook_";
[257]727 else
[284]728 if (doctype == "classify") icon = "_document:iconopenbookshelf_";
729 else icon = "_document:iconclosedbook_";
[257]730 else if (haschildren)
[284]731 if (classifytype == "Document") icon = "_document:iconopenfolder_";
732 else icon = "_document:iconopenbookshelf_";
[257]733
734 // set up tabbing
735 if ((classifytype == "classify") && (doctype != "classify"))
736 tabcols = lasttabcols + 1;
737 else {
738 tabcols = countchar ((*thissection).OID.begin(), (*thissection).OID.end(), '.');
739 lasttabcols = tabcols;
740 }
741 tabcols -= excess;
[213]742
[257]743 for (int i = 0; i < tabcols; i++)
[284]744 icontabs += "_document:icontab_";
[257]745
[213]746 // set up pointer
[257]747 if (classifytype == "Document" && !gt) {
[284]748 if ((*thissection).OID == OID) pointer = "_document:iconpointer_";
749 else pointer = "_document:icontab_";
[257]750 tabcols ++;
751 }
752
753 int colsremaining = totalcols - tabcols;
[213]754
[257]755 if (tabcols > 0) {
756 tab = "<td";
757 if (tabcols > 1) tab += " colspan=" + text_t(tabcols);
758 tab += ">" + icontabs + pointer + "</td>";
[213]759 }
[257]760
761 textout << outconvert << disp << "<tr>" << tab << "<td>";
[213]762
[257]763 if ((classifytype == "Document") && (is_top((*thissection).OID)) &&
764 (args.getintarg("x")))
[282]765 textout << outconvert << disp << icon << "</td><td";
766
[257]767 else {
768 if (!gt) {
769 const text_t &thisOID = (*thissection).OID;
770 text_t link;
771 if (is_top (thisOID))
772 if (classifytype == "classify")
[279]773 link = doclink + arg_cl + "&d=" + thisOID + "\">";
[257]774 else
[279]775 if (arg_cl.empty())
776 link.clear();
777 else if (arg_cl == "search")
778 link = "<a href=\"_httpquery_\">";
779 else
780 link = doclink + arg_cl + "\">";
[257]781 else
782 if (haschildren)
783 if (classifytype == "classify")
[279]784 link = doclink + thisOID + ".pr\">";
[257]785 else
[279]786 link = doclink + arg_cl + "&d=" + thisOID + ".pr\">";
[257]787 else
788 if (classifytype == "classify")
[279]789 link = doclink + thisOID + "\">";
[257]790 else
[279]791 link = doclink + arg_cl + "&d=" + thisOID + "\">";
[257]792
[279]793 textout << outconvert << disp << link;
[213]794 } else {
[279]795 textout << "<a href=\"#" << count << "\">";
[213]796 count ++;
797 }
[282]798
799 textout << outconvert << disp << icon << "</a></td><td";
[213]800 }
[257]801 if (colsremaining > 1) textout << " colspan=" << colsremaining;
802 textout << outconvert << disp << ">" << title << "</td></tr>\n";
803
804 thissection ++;
[213]805 }
806}
807
[344]808/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
809-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
810
[248]811// set_arrow_macros sets the _httpprevarrow_ and _httpnextarrow_ macros
812// it shouldn't be called if OID is the top level of a book
813// as the "hasprevious" and "hasnext" metadata won't be set
814// when the filter can't get OIDs parent info - one day I'll
815// fix this ;-)
816void set_arrow_macros (const text_t &OID, const text_t &classifytype,
[419]817 bool showtoppage, displayclass &disp,
818 recptproto *collectproto, const text_t &collection,
819 ostream &logout) {
[248]820
821 if (OID.empty()) return;
822
823 text_tarray metadata;
824 FilterResponse_t response;
825
826 metadata.push_back ("haschildren");
827 metadata.push_back ("hasnext");
828 metadata.push_back ("hasprevious");
829 // get "haschildren", "hasnext" and "hasprevious" metadata for OID
[278]830 if (get_info (OID, collection, metadata, false, collectproto, response, logout)) {
[248]831
[257]832 text_t haschildren = response.docInfo[0].metadata[0].values[0];
833 text_t hasnext = response.docInfo[0].metadata[1].values[0];
834 text_t hasprevious = response.docInfo[0].metadata[2].values[0];
[248]835
836 if ((classifytype == "Hierarchy") || (classifytype == "Book")) {
837 if (haschildren == "1")
838 disp.setmacro ("httpnextarrow", "document",
839 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.fc,_httpdocument_&cl=_cgiargcl_.fc)");
840 else if (hasnext == "1")
841 disp.setmacro ("httpnextarrow", "document",
842 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.ns,_httpdocument_&cl=_cgiargcl_.ns)");
[257]843 else {
844 // see if parent has younger siblings
[278]845 if (get_info (OID + ".pr", collection, metadata, false, collectproto, response, logout)) {
[293]846 if (!response.docInfo[0].metadata.empty() &&
847 response.docInfo[0].metadata[1].values[0] == "1")
[257]848 disp.setmacro ("httpnextarrow", "document",
849 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.pr.ns,_httpdocument_&cl=_cgiargcl_.pr.ns)");
850 }
851 }
[248]852
853 if (hasprevious == "1") {
854 // see if OIDs older sibling has children
[278]855 if (get_info (OID + ".ps", collection, metadata, false, collectproto, response, logout)) {
[419]856 if (response.docInfo[0].metadata[0].values[0] == "1")
[248]857 disp.setmacro ("httpprevarrow", "document",
[257]858 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.ps.lc,_httpdocument_&cl=_cgiargcl_.ps.lc)");
[248]859 else
860 disp.setmacro ("httpprevarrow", "document",
861 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.ps,_httpdocument_&cl=_cgiargcl_.ps)");
862 }
[419]863 } else if (showtoppage && !is_top (OID))
[248]864 disp.setmacro ("httpprevarrow", "document",
865 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.pr,_httpdocument_&cl=_cgiargcl_.pr)");
866 }
867
868 else {
869 if (hasnext == "1")
870 disp.setmacro ("httpnextarrow", "document",
871 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.ns,_httpdocument_&cl=_cgiargcl_.ns)");
872 if (hasprevious == "1")
873 disp.setmacro ("httpprevarrow", "document",
874 "_If_(_cgiargd_,_httpdocument_&cl=_cgiargcl_&d=_cgiargd_.ps,_httpdocument_&cl=_cgiargcl_.ps)");
875 }
876 }
877}
Note: See TracBrowser for help on using the repository browser.