]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/mkindextheory.pl
* minor correction to make the new mathml widget work better
[helm.git] / helm / cgi / mkindextheory.pl
1 #!/usr/bin/perl
2
3 # First of all, let's load HELM configuration
4 use Env;
5 my $HELM_LIB_DIR = $ENV{"HELM_LIB_DIR"};
6 # this should be the only fixed constant
7 my $DEFAULT_HELM_LIB_DIR = "/projects/helm/on-line/local/lib/helm";
8 if (defined ($HELM_LIB_DIR)) {
9    $HELM_LIB_PATH = $HELM_LIB_DIR."/configuration.pl";
10 } else {
11    $HELM_LIB_PATH = $DEFAULT_HELM_LIB_DIR."/configuration.pl";
12 }
13
14 # next require defines: $helm_dir, $html_link, $dtd_dir, $uris_dbm
15 require $HELM_LIB_PATH;
16
17 use URI::Escape;
18 use LWP::UserAgent;
19 use CGI;
20
21 my $cgi = new CGI($ENV{"REQUEST_URL"});
22 $uri = $cgi->param('theoryuri');
23 $getterURL = $cgi->param('getterURL');
24 $uri =~ s/(.*)\/$/$1/; # Remove a final slash if present
25 $uri .= "/"; # Put a final slash
26 $myurl = $cgi->url();
27
28 $cont = ""; # modified by side-effect by &callback
29 my $ua = LWP::UserAgent->new;
30 my $request = HTTP::Request->new(GET => $getterURL."ls?format=txt&baseuri=".$uri);
31 my $response = $ua->request($request, \&callback);
32  
33 @filenames = split(/\n/, $cont);
34
35 my $uridotdot = $uri;
36 $uridotdot =~ s/(.*)\/.+/$1/;
37 if ($uri ne "theory:/") {
38  # Let's print the link to the parent directory
39  $output = <<EOT;
40 <tr>
41 <td><img border="0" src="/icons/back.gif" alt="[BACK]"></td>
42 <td><a href="$myurl" onClick="top.theoryuri='$uridotdot'; refreshReload(); refreshTheoryHeader(); this.search='?theoryuri=$uridotdot&getterURL=$getterURL';" onMouseOver="window.status='$uridotdot'; return true">Parent Directory</a></td>
43 </tr>
44 EOT
45 }
46
47 foreach $i (@filenames) {
48    my ($type,$name,$flags) = split(/, /, $i);
49    my ($flagscic, $flagstypes) = split(/,/, $flags);
50    $flagscic =~ s/^<(.*)/$1/;
51    $flagstypes =~ s/(.*)>$/$1/;
52    if ($type eq "dir") {
53       $output .= <<EOT;
54 <tr>
55 <td><img border="0" src="/icons/folder.gif" alt="[DIR]"></td>
56 <td><a href="$myurl" onClick="top.theoryuri='$uri$name'; refreshReload(); refreshTheoryHeader(); this.search='?theoryuri=$uri$name&getterURL=$getterURL';" onMouseOver="window.status='$uri$name'; return true">$name</a></td>
57 </tr>
58 EOT
59    } elsif ($type eq "object") {
60          if ($name =~ /\.theory$/) {
61             # theory file
62             $output .= <<EOT;
63 <tr>
64 <td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
65 <td><a href="" target="theory" onClick="this.href=makeURL('theory','$uri$name','$flagscic','$flagstypes')" onMouseOver="window.status='$uri$name'; return true">$name</a>
66 </tr>
67 EOT
68          } else {
69             $output .= <<EOT;
70 <tr>
71 <td><img border="0" src="/icons/unknown.gif" alt="[DIR]"></td>
72 <td>$name</td>
73 </tr>
74 EOT
75          }
76    } else {
77       $output .= <<EOT;
78 <tr>
79 <td><img border="0" src="/icons/burst.gif" alt="[DIR]"></td>
80 <td>$name</td>
81 </tr>
82 EOT
83    }
84 }
85
86 print <<EOT;
87 Content-type: text/html
88
89 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
90 "http://www.w3.org/TR/REC-html40/loose.dtd">
91 <html>
92 <head>
93 <title>Index of $uri</title>
94 <script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/control.js">
95 </script>
96 </head>
97 <body bgcolor="#ffffff" text="#000000">
98 <table>
99 $output
100 </table>
101 <hr noshade align="left" width="80%">
102 </body>
103 </html>
104 EOT
105
106 #================================
107
108 sub callback
109 {
110  my ($data) = @_;
111  $cont .= $data;
112 }