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

Last change on this file since 26714 was 26714, checked in by davidb, 8 years ago

Changing alert message for when the script has finished running.

File size: 5.0 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;
7my $iis6_mode = 0;
8
9if($iis6_mode){
10 #Change into cgi-bin directory
11 chdir("cgi-bin");
12}
13
14eval("require \"gsdlCGI.pm\"");
15if ($@)
16{
17 print STDOUT "Content-type:text/plain\n\n";
18 print STDOUT "ERROR: $@\n";
19 exit 0;
20}
21
22sub display_output
23{
24 my($docID,$c,$assocfilepath,$site) = @_;
25
26 my $iframeURL = "library/collection/$c/document/$docID"."?p.showAssocFilePath=1";
27
28 #Render an html page to display and export item.
29 my $html = <<EOT;
30<html>
31<head>
32 <title>Export Document to Expeditee</title>
33 <base href=".."/>
34
35 <link type="text/css" href="ext/html-to-expeditee/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" rel="stylesheet"/>
36 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-1.6.2.min.js"></script>
37 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
38 <script type="text/javascript" src="ext/html-to-expeditee/js/html-to-expeditee.js"></script>
39 <script type="text/javascript" src="ext/html-to-expeditee/js/gsajax-min.js"></script>
40
41 <style type="text/css">
42 body{
43 font-family: Arial;
44 font-size: 16px;
45 color: #000;
46 }
47 </style>
48 <script type="text/javascript">
49 function load(){
50
51 var iframe = document.getElementById("iframe");
52
53 if(iframe.style.display != "block"){
54 iframe.height = "90%";
55 iframe.style.display = "block";
56 }
57
58 var iframeDoc;
59
60 if(iframe.contentDocument){
61 /* Firefox and Chrome */
62 iframeDoc = iframe.contentDocument;
63 }else if(iframe.contentWindow){
64 /* IE */
65 iframeDoc = iframe.contentWindow.document;
66 }
67
68 var gsContent = iframeDoc.getElementById("gs_content");
69 var xmlUrl = iframe.src + "&o=xml";
70
71 var frameNum = getMetadata(xmlUrl,'frameID');
72
73 if(frameNum === null){
74 //use -1 as default, to change later.
75 frameNum = -1;
76 }
77
78 //Check for assocfilepath
79 var assocElem = iframeDoc.getElementById('assocfilepath');
80 var assoc = null;
81
82 if(assocElem === undefined || assocElem === null){
83 assoc = getMetadata(xmlUrl,'assocfilepath');
84 }
85
86 var expFrameTree = htmlToExpeditee(gsContent);
87 var expFrame = JSON.stringify(expFrameTree);
88
89 var site = "$site";
90 var url = "cgi-bin/export-individual-expeditee.pl";
91 var params = "c=" + "$c";
92
93 if(site.match(/\\w/)){
94 params += "&site=" + site;
95 }
96
97 params += "&a=generate-frame&fn=" + frameNum;
98 params += "&json=" + escape(expFrame);
99
100 //Add an assocfilepath param
101 if(assoc !== null){
102 params += "&assoc=" + assoc;
103 }
104
105 var request = urlPostSync(url,params);
106 var msg = "Document has been successfully exported to Expeditee.";
107
108 //TODO: the value of frameNum is changed in ExpediteeExportAction, so need a way to retrieve this for the alert message.
109 if(frameNum != -1)
110 msg += " The corresponding Expeditee frame can be found in the collection's export directory at: " + frameNum + ".exp";
111
112 alert(msg);
113 }
114
115 function getMetadata(xmlUrl,nameValue){
116
117 var metadata = null;
118
119 \$.ajax({
120 type: "GET",
121 async: false,
122 url: xmlUrl,
123 dataType: "xml",
124 success: function(xml){
125
126 \$(xml).find('metadata').each(function(){
127
128 var name = \$(this).attr('name');
129
130 if(name === nameValue){
131
132 if(metadata === null){
133 metadata = \$(this).text();
134 //console.log(metadata);
135 }
136
137 }
138 });
139
140 }
141
142 });
143
144 return metadata;
145 }
146 </script>
147
148 <body>
149
150 <p id="msg">Exporting following document to Expeditee... </p>
151
152 <hr style="margin: 10px;"/>
153
154 <!-- Load up an iframe to display URL in-->
155 <div align="center"><iframe id="iframe" width="1000px" height="90%" src="$iframeURL" onload="load();"></iframe></div>
156 </body>
157 </html>
158EOT
159 print "Content-type:text/html\n\n";
160 print $html;
161}
162
163sub main
164{
165 my $gsdl_cgi = new gsdlCGI();
166
167 #Load needed GSDL modules
168 $gsdl_cgi->setup_gsdl();
169
170 my $gsdlhome = $ENV{'GSDLHOME'};
171 $gsdl_cgi->checked_chdir($gsdlhome);
172
173 require cgiactions::ExpediteeExportAction;
174 $gsdl_cgi->parse_cgi_args();
175
176 $gsdl_cgi->{'xml'} = 0;
177
178 my $fn = $gsdl_cgi->param("fn");
179
180 if(defined $fn){
181
182 my $site = $gsdl_cgi->clean_param("site");
183 my $c = $gsdl_cgi->clean_param("c");
184 my $a = $gsdl_cgi->clean_param("a"); #assocfilepath
185
186 my $json = $gsdl_cgi->clean_param("json");
187
188 my $action = new ExpediteeExportAction($gsdl_cgi,$iis6_mode);
189 $action->do_action();
190
191 }else{
192
193 my $docID = $gsdl_cgi->clean_param("docID");
194 my $c = $gsdl_cgi->clean_param("c");
195 my $assocfilepath = $gsdl_cgi->clean_param("assocfilepath");
196 my $site = $gsdl_cgi->clean_param("site");
197
198 if(!defined $site){
199 $gsdl_cgi->generate_error("No site specified.");
200 }
201
202 display_output($docID,$c,$assocfilepath,$site);
203 }
204}
205
206&main();
Note: See TracBrowser for help on using the repository browser.