1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * tipaction.cpp -- define random tip macros
|
---|
4 | * Copyright (C) 1999 DigiLib Systems Limited, New Zealand
|
---|
5 | *
|
---|
6 | * PUT COPYRIGHT NOTICE HERE
|
---|
7 | *
|
---|
8 | * $Id: tipaction.cpp 515 1999-09-02 00:29:27Z rjmcnab $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 | /*
|
---|
13 | $Log$
|
---|
14 | Revision 1.3 1999/09/02 00:29:27 rjmcnab
|
---|
15 | added cgi argument "st" - show tips
|
---|
16 |
|
---|
17 | Revision 1.2 1999/07/30 02:24:45 sjboddie
|
---|
18 | added collectinfo argument to some functions
|
---|
19 |
|
---|
20 | Revision 1.1 1999/07/09 02:18:27 rjmcnab
|
---|
21 | Initial revision.
|
---|
22 |
|
---|
23 |
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | #include "tipaction.h"
|
---|
28 | #include <stdlib.h>
|
---|
29 |
|
---|
30 |
|
---|
31 | tipaction::tipaction () {
|
---|
32 | // "st" show tips - "0"=no, "1"=yes
|
---|
33 | cgiarginfo arg_ainfo;
|
---|
34 | arg_ainfo.shortname = "st";
|
---|
35 | arg_ainfo.longname = "show tips";
|
---|
36 | arg_ainfo.multiplechar = true;
|
---|
37 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
38 | arg_ainfo.argdefault = "1";
|
---|
39 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
40 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
41 | }
|
---|
42 |
|
---|
43 | void tipaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &disp,
|
---|
44 | cgiargsclass &args, recptproto */*collectproto*/,
|
---|
45 | ostream &logout) {
|
---|
46 | // define_external_macros sets the following macros:
|
---|
47 |
|
---|
48 | // _tip:thistip_ - a random tip (defined if st == "1")
|
---|
49 |
|
---|
50 | if (args["st"].getint()) {
|
---|
51 | // get the maximum tip number (_tip:tipmax_)
|
---|
52 | text_t tipmax_str;
|
---|
53 | disp.expandstring ("tip", "_tipmax_", tipmax_str);
|
---|
54 | if (tipmax_str.empty()) {
|
---|
55 | logout << "Warning: _tip:tipmax_ not set. This macro is needed for displaying tips.\n";
|
---|
56 | return;
|
---|
57 | }
|
---|
58 |
|
---|
59 | int tipmax = tipmax_str.getint();
|
---|
60 | if (tipmax < 1) {
|
---|
61 | logout << "Warning: _tip:tipmax_ was less than 1. No tips were set.\n";
|
---|
62 | return;
|
---|
63 | }
|
---|
64 |
|
---|
65 | disp.setmacro("thistip", "tip", "_tip" + text_t((rand()%tipmax) + 1) + "_");
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|