]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/mkindexcic.pl
* minor correction to make the new mathml widget work better
[helm.git] / helm / cgi / mkindexcic.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('cicuri');
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 "cic:/") {
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.cicuri='$uridotdot'; refreshReload(); refreshCICHeader(); this.search='?cicuri=$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.cicuri='$uri$name'; refreshReload(); refreshCICHeader(); this.search='?cicuri=$uri$name&getterURL=$getterURL';" onMouseOver="window.status='$uri$name'; return true">$name</a></td>
57 </tr>
58 </tr>
59 EOT
60    } elsif ($type eq "object") {
61          if ($name =~ /\.(con|var|ind)$/) {
62             # cic file
63             $output .= <<EOT;
64 <tr>
65 <td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
66 <td><a href="" target="cic" onClick="this.href=makeURL('cic','$uri$name','$flagscic','$flagstypes')" onMouseOver="window.status='$uri$name'; return true">$name</a>
67 </tr>
68 EOT
69          } else {
70             $output .= <<EOT;
71 <tr>
72 <td><img border="0" src="/icons/unknown.gif" alt="[DIR]"></td>
73 <td>$name</td>
74 </tr>
75 EOT
76          }
77    } else {
78       $output .= <<EOT;
79 <tr>
80 <td><img border="0" src="/icons/burst.gif" alt="[DIR]"></td>
81 <td>$name</td>
82 </tr>
83 EOT
84    }
85 }
86
87 print <<EOT;
88 Content-type: text/html
89
90 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
91 "http://www.w3.org/TR/REC-html40/loose.dtd">
92 <html>
93 <head>
94 <title>Index of $uri</title>
95 <script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/control.js">
96 </script>
97 </head>
98 <body bgcolor="#ffffff" text="#000000">
99 <table>
100 $output
101 </table>
102 <hr noshade align="left" width="80%">
103 </body>
104 </html>
105 EOT
106
107 #================================
108
109 sub callback
110 {
111  my ($data) = @_;
112  $cont .= $data;
113 }