source: gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/export-individual-expeditee.pl.in@ 26632

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

Adding in scripts for running Export individual GSDL documents to GlamED feature.

File size: 6.2 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
6##
7# This is used for exporting individual Greenstone
8# documents to Expeditee. To export entire collections,
9# use html-to-expeditee.pl
10##
11use strict;
12my $iis6_mode = 0;
13
14if($iis6_mode){
15 #Change into cgi-bin directory
16 chdir("cgi-bin");
17}
18
19eval("require \"gsdlCGI.pm\"");
20if ($@)
21{
22 print STDOUT "Content-type:text/plain\n\n";
23 print STDOUT "ERROR: $@\n";
24 exit 0;
25}
26
27sub display_output
28{
29 my($docID,$c,$assocfilepath,$site,$fn,$found) = @_;
30
31 my $iframeURL = "library/collection/$c/document/$docID"."?p.showAssocFilePath=1";
32
33 #Render an html page to display & export item.
34 my $html = <<EOT;
35<html>
36 <head>
37 <title>Export Item to Expeditee</title>
38 <base href=".."/>
39
40 <link type="text/css" href="ext/html-to-expeditee/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" rel="stylesheet"/>
41 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-1.6.2.min.js"></script>
42 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
43 <script type="text/javascript" src="ext/html-to-expeditee/js/html-to-expeditee.js"></script>
44 <script type="text/javascript" src="ext/html-to-expeditee/js/gsajax-min.js"></script>
45
46 <style type="text/css">
47 body{
48 font-family: Arial;
49 font-size: 16px;
50 color: #000;
51 }
52 </style>
53 <script type="text/javascript">
54 function load(){
55
56 var iframe = document.getElementById("iframe");
57 if(iframe.style.display != "block"){
58 iframe.height = "90%";
59 iframe.style.display = "block";
60 }
61
62 var iframeDoc;
63 if( iframe.contentDocument){
64 /* Firefox & Chrome */
65 iframeDoc = iframe.contentDocument;
66 }else if(iframe.contentWindow){
67 /* IE */
68 iframeDoc = iframe.contentWindow.document;
69 }
70
71 var gsContent = iframeDoc.getElementById("gs_content");
72
73 //hide rightSidebar div
74 var rightSidebar = iframeDoc.getElementById("rightSidebar");
75 if(rightSidebar !== undefined){
76 rightSidebar.style.display = "none";
77 }
78
79 var expFrameTree = htmlToExpeditee(gsContent);
80 var expFrame = JSON.stringify(expFrameTree);
81
82 var site = "$site";
83 var url = "cgi-bin/export-individual-expeditee.pl";
84 var params = "c=" + "$c";
85
86 if(site.match(/\\w/)){
87 params += "&site=" + site;
88 }
89 params += "&a=generate-frame&fn=" + "$fn";
90 params += "&found=" + "$found";
91 params += "&json=" + escape(expFrame);
92
93 var request = urlPostSync(url,params);
94
95 alert("Document has been successfully exported to Expeditee. It can be found in the collection's export directory at: $fn.exp");
96 }
97 </script>
98 </head>
99 <body>
100
101 <p id="msg">Exporting following document to Expeditee... </p>
102
103 <hr style="margin: 10px;"/>
104
105 <!-- Load up an iframe to display URL in-->
106 <div align="center"><iframe id="iframe" width="1000px" height="90%" src="$iframeURL" onload="load();"></iframe</div>
107
108 </body>
109</html>
110EOT
111 print "Content-type:text/html\n\n";
112 print $html;
113}
114
115##For debugging.
116sub check{
117
118 my($check1,$check2,$check3,$check4,$check5) = @_;
119
120 print "Content-type:text/html\n\n";
121 print $check1;
122 print $check2;
123 print $check3;
124 print $check4;
125 print $check5;
126}
127
128sub main
129{
130 my $gsdl_cgi = new gsdlCGI();
131
132 #Load needed GSDL modules
133 $gsdl_cgi->setup_gsdl();
134
135 my $gsdlhome = $ENV{'GSDLHOME'};
136 $gsdl_cgi->checked_chdir($gsdlhome);
137
138 #require cgiactions::HtmlToExpediteeAction;
139 require cgiactions::ExpediteeExportAction;
140 $gsdl_cgi->parse_cgi_args();
141
142 $gsdl_cgi->{'xml'} = 0;
143
144 my $fn = $gsdl_cgi->param("fn");
145
146 if(defined $fn){
147
148 my $site = $gsdl_cgi->clean_param("site");
149 my $c = $gsdl_cgi->clean_param("c");
150 my $a = $gsdl_cgi-> clean_param("a");
151 my $json = $gsdl_cgi->clean_param("json");
152 my $found = $gsdl_cgi->clean_param("found");
153 #check($site,$c,$a,$json,$found);
154
155 my $action = new ExpediteeExportAction($gsdl_cgi,$iis6_mode);
156 $action->do_action();
157
158 #my $action = new HtmlToExpediteeAction($gsdl_cgi,$iis6_mode);
159 #$action->do_action();
160 }else{
161
162 printf("fn not defined\n");
163 my $docID = $gsdl_cgi->clean_param("docID");
164 my $c = $gsdl_cgi->clean_param("c");
165 my $assocfilepath = $gsdl_cgi->clean_param("assocfilepath");
166 my $site = $gsdl_cgi->clean_param("site");
167
168 if(!defined $site){
169 $gsdl_cgi->generate_error("No site specified.");
170 }
171
172 #Open export directory
173 my $collect_dir = $gsdl_cgi->get_collection_dir($site);
174 my $export_dir = &util::filename_cat($collect_dir,$c,"export");
175
176 my $frameInf = "$export_dir\\frame.inf";
177 my $fn = "";
178 my @files;
179
180 #check if export directory exists otherwise create it.
181 if(-d $export_dir){
182 opendir DIR, $export_dir or die "cannot open dir $export_dir: $!";
183 @files = readdir DIR;
184 closedir DIR;
185 }else{
186 print "Reached!\n";
187 &util::mk_dir($export_dir);
188
189 my $zeroFrame = "0.exp";
190 open(ZERO_FRAME,">>$export_dir\\$zeroFrame") || die "$!";
191 close ZERO_FRAME;
192
193 opendir DIR, $export_dir or die "can't open dir $export_dir: $!\n";
194 @files = readdir DIR;
195 closedir DIR;
196 }
197
198 my $found = 0;
199 for my $file(@files){
200 if($file =~ m/\d/){
201
202 my $fullFile = "$export_dir\\$file";
203 open FILE, $fullFile or die $!;
204 my @lines = <FILE>;
205
206 for my $line(@lines){
207 if($line eq "T \@assocfilepath $assocfilepath\n"){
208 $fn = $fullFile;
209 $found = 1;
210 }
211 }
212 close(FILE);
213 }
214 }
215
216 unless($found){
217 #use frame.inf file to get file number
218 if(-e $frameInf){
219
220 open FRAME_INF, $frameInf or die $!;
221 my @lines = <FRAME_INF>;
222
223 for my $line(@lines){
224 $fn = $line;
225 }
226 }else{
227
228 print "$frameInf not found\n";
229
230 $fn = 0;
231 }
232 }
233
234 #now get frame number out of file name
235 my @getFrameNumArray = split('\\\\',$fn);
236 @getFrameNumArray = reverse(@getFrameNumArray);
237 $fn = $getFrameNumArray[0];
238
239 $fn =~ s/[^0-9]//g;
240 unless($found){
241 $fn = $fn + 1;
242 }
243 #unless($found){
244 # $fn = $fn + 1;
245 #}
246
247 print "fn = ".$fn."\n";
248
249 display_output($docID,$c,$assocfilepath,$site,$fn,$found);
250 }
251
252}
253
254&main();
Note: See TracBrowser for help on using the repository browser.