source: gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/generate-collection-space.pl.in@ 26747

Last change on this file since 26747 was 26747, checked in by davidb, 11 years ago

Added in more code to the go button function.

File size: 6.5 KB
Line 
1#!/cygdrive/c/strawberry/perl/bin/perl -w
2
3# Need to specify the full path of Perl above, e.g. for Windows something like
4#!C:\\Perl32\\bin\\perl -w
5
6use strict;
7
8# Set this to 1 to work around IIS 6 craziness
9my $iis6_mode = 0;
10
11
12# IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone
13# directory rather than the cgi-bin directory, causing lots of stuff to fail
14if ($iis6_mode)
15{
16 # Change into cgi-bin directory
17 chdir("cgi-bin");
18}
19
20
21# We use require and an eval here (instead of "use") to catch any errors loading the module (for IIS)
22eval("require \"gsdlCGI.pm\"");
23if ($@)
24{
25 print STDOUT "Content-type:text/plain\n\n";
26 print STDOUT "ERROR: $@\n";
27 exit 0;
28}
29
30sub generate_html_form
31{
32 # First create an overlay frame containing CL links.
33
34 # Then create frames with document links and images.
35
36 my ($isGSDL2,$site,$collect,$cl) = @_;
37
38 my $html_form = <<EOT;
39<html>
40 <head>
41 <title>Generate Collection Space for $collect</title>
42 <base href=".."/>
43
44 <link type="text/css" href="ext/html-to-expeditee/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
45 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-1.6.2.min.js"></script>
46 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
47 <script type="text/javascript" src="ext/html-to-expeditee/js/gsajax-min.js"></script>
48 <script type="text/javascript" src="ext/html-to-expeditee/js/html-to-expeditee.js"></script>
49
50 </head>
51 <body>
52 <form class="ui-widget">
53
54 <p style="font-size: 16px; width: 550px; text-align: justify;">Generate a Collection Space to make it easier to view documents in GlamED/Expeditee. Before running this script you must have already converted the Greenstone collection to an Expeditee frameset. If you have <b>NOT</b> done this, click <a href="html-to-expeditee.pl?site=$site&collect=$collect&cl=CL1" target="_blank">here</a></p>
55
56 Generate a Collection Space for <input type="text" class="ui-corner-all" style="padding: 4px;" name="collect" value="$collect" id="collect"/> using the classifier <input type="text" class="ui-corner-all" style="padding: 4px;" name="cl" value="$cl" id="cl"/>
57
58 <input value="$site" name="site" id="site" type="hidden"> <input value="Go" id="go" class="ui-button ui-widget ui-state-default ui-corner-all" type="submit">
59 </form>
60
61 <script type="text/javascript">
62 var clLinks = [];
63 var numClLinks;
64
65 \$(function(){
66 \$('#progress').progressbar();
67
68 \$('#go').button().click(function(){
69 var collect = document.getElementById("collect").value;
70
71 if(collect.match(/^\\s*\$/)){
72 alert("No collection specified");
73 return false;
74 }
75
76 var cl = document.getElementById("cl").value;
77 if(cl.match(/^\\s*\$/)){
78 alert("No classifier specified");
79 return false;
80 }
81
82 if(cl.match(/^\\d+\$/)){
83 cl = "CL" + cl;
84 }
85
86
87
88
89 return false;
90 });
91
92 function pageLoaded(){
93
94 var iframe = document.getElementById("iframe");
95
96 if(iframe.src){
97 if(iframe.style.display != "block"){
98 iframe.height = "90%";
99 iframe.style.display = "block";
100 }
101
102 var iframeDoc;
103
104 if(iframe.contentDocument){
105 /* FF */
106 iframeDoc = iframe.contentDocument;
107 }else if(iframe.contentWindow){
108 /* IE */
109 iframeDoc = iframe.contentWindow.document;
110 }
111
112 var frameNum = (numClPages - clPages.length);
113 var progressPercent = frameNum/numClPages * 100;
114
115 \$(function(){
116 \$('#progressbar').progressbar({ value: 0 });
117 });
118
119 var gsContent = iframeDoc.getElementById("gs_content");
120
121 //Need to change htmlToExpeditee code to account for links
122 var expFrameTre = htmlToExpeditee(gsContent);
123
124 var collect = document.getElementById("collect").value;
125 var site = document.getElementById("site").value;
126
127 var url = "cgi-bin/generate-collection-space.pl";
128 var params = "c=" + collect;
129
130 if(site.match(/\\w/)){
131 params += "&site=" + site;
132 }
133
134 params += "&a=generate-frame&fn=" + frameNum;
135 params += "&json=" + escape(expFrame);
136
137 var clHtml = urlPostSync(url,params);
138
139 if(!clHtml.match(/html-to-expeditee saved frame/)){
140 alert("Error processing url: " + url);s
141 }
142
143 if(clPages.length > 0){
144 var clPage = clPages.shift();
145
146 var cl = document.getElementById("cl").value;
147
148 var gs2 = $isGSDL2;
149
150 var url;
151
152 var url;
153
154 if(gs2){
155 url = "library.cgi";
156 url += "?c=" + collect + "&a=d&d=" + docOID;
157 }else{
158 url = "library";
159 url += "?c=" + collect + "&a=d&d=" + docOID;
160 }
161
162 iframe.src = url;
163 }else{
164
165 var progressbar = document.getElementById("progressbar");
166 progressbar.style.display = "none";
167
168 iframe.style.display = "none";
169 delete iframe.src;
170 }
171
172
173 }
174
175
176 }
177 </script>
178
179 <div id="progressbar" width="100%" style="display: none; margin: 10px; height: 10px;"></div>
180
181 <div id="workingTraverse" style="display: none"></div>
182
183 <hr style="margin: 10px;">
184
185 <iframe width="100%" id="iframe" style="display: none;" onload="pageLoaded()"></iframe>
186</body>
187</html>
188EOT
189
190 print "Content-type:text/html\n\n";
191 print $html_form;
192}
193
194sub main
195{
196 my $gsdl_cgi = new gsdlCGI();
197
198 # Load the Greenstone modules that we need to use
199 $gsdl_cgi->setup_gsdl();
200
201 my $gsdlhome = $ENV{'GSDLHOME'};
202 $gsdl_cgi->checked_chdir($gsdlhome);
203
204 require cgiactions::CollectionSpaceAction;
205
206 $gsdl_cgi->parse_cgi_args();
207
208 # We don't want the gsdlCGI module to return errors and warnings in XML
209 $gsdl_cgi->{'xml'} = 0;
210
211 my $fn = $gsdl_cgi->clean_param("fn");
212
213 if(defined $fn){
214 #Generate a frame.
215 my $action = new CollectionSpaceAction($gsdl_cgi,$iis6_mode);
216 $action->do_action();
217 }else{
218 my $collect = $gsdl_cgi->clean_param("collect");
219 my $cl = $gsdl_cgi->clean_param("cl");
220
221 #Establish collect_dir using defining 'site' along the way if GS3
222 my $site = undef;
223 my $isGSDL2 = undef;
224
225 if($gsdl_cgi->greenstone_version() == 2){
226 $isGSDL2 = 1;
227 }else{
228 $isGSDL2 = 0;
229
230 #GS3 makes use of 'site'
231 $site = $gsdl_cgi->clean_param("site");
232
233 if(!defined $site){
234 $gsdl_cgi->generate_error("No site specified.");
235 }
236 }
237
238 generate_html_form($isGSDL2,$site,$collect,$cl);
239 }
240}
241
242&main();
Note: See TracBrowser for help on using the repository browser.