[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 20 Feb 2004 16:21:49 -0000


matthew		Fri Feb 20 11:21:49 2004 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  Added &breadcrumbs, &clear_breadcrumbs, and &add_breadcrumb.
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.52 loncom/interface/lonhtmlcommon.pm:1.53
--- loncom/interface/lonhtmlcommon.pm:1.52	Wed Feb 18 03:07:16 2004
+++ loncom/interface/lonhtmlcommon.pm	Fri Feb 20 11:21:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.52 2004/02/18 08:07:16 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.53 2004/02/20 16:21:49 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -834,6 +834,115 @@
 sub htmlareabrowser {
     return 1;
 }
+
+############################################################
+############################################################
+
+=pod
+
+=item breadcrumbs
+
+Compiles the previously registered breadcrumbs into an series of links.
+FAQ and BUG links will be placed on the left side of the table if they
+are defined for the last registered breadcrumb.  
+Additionally supports a 'component', which will be displayed on the
+right side of the table (without a link).
+A link to help for the component will be included if one is specified.
+
+All inputs can be undef without problems.
+
+Inputs: $color (the background color of the table returned),
+        $component (the large text on the right side of the table),
+        $component_help
+
+Returns a string containing breadcrumbs for the current page.
+
+=item clear_breadcrumbs
+
+Clears the previously stored breadcrumbs.
+
+=item add_breadcrumb
+
+Pushes a breadcrumb on the stack of crumbs.
+
+input: $breadcrumb, a hash reference.  The keys 'href','title', and 'text'
+are required.  If present the keys 'faq' and 'bug' will be used to provide
+links to the FAQ and bug sites.
+
+returns: nothing    
+
+=cut
+
+############################################################
+############################################################
+{
+    my @Crumbs;
+
+    sub breadcrumbs {
+        my ($color,$component,$component_help) = @_;
+        $color = '#CCCCFF' if (! defined($color));
+        #
+        my $Str = "\n".
+            '<table width="100%" border="0" cellpadding="0" cellspacing="0">'.
+            '<tr><td bgcolor="'.$color.'">'.
+            '<font size="-1">';
+        # The last breadcrumb does not have a link, so handle it seperately.
+        my $last = pop(@Crumbs);
+        # The first one should be the course, I guess.
+        if (exists($ENV{'request.course.id'})) {
+            my $cid = $ENV{'request.course.id'};
+            unshift(@Crumbs,{href=>'/adm/menu',
+                             title=>'Go to main menu',
+                             text=>$ENV{'course.'.$cid.'.description'},
+                         });
+        }
+        my $links .= 
+            join('-&gt;',
+                 map {
+                     '<a href="'.$_->{'href'}.'" title="'.$_->{'title'}.'">'.
+                         $_->{'text'}.'</a>' 
+                     } @Crumbs
+                 );
+        $links .= '-&gt;' if ($links ne '');
+        $links .= '<b>'.$last->{'text'}.'</b>';
+        if (exists($last->{'bug'})) {
+            $links = &Apache::loncommon::help_open_bug($last->{'bug'}).$links;
+        }
+        if (exists($last->{'faq'})) {
+            $links = &Apache::loncommon::help_open_faq($last->{'faq'}).$links;
+        }
+        $Str .= $links.'</font></td>';
+        if (defined($component)) {
+            $Str .= '<td align="right" bgcolor="'.$color.'">'.
+                '<font size="+1">'.$component.'</font>';
+            if (defined($component_help)) {
+                $Str .= 
+                    &Apache::loncommon::help_open_topic($component_help);
+            }
+            $Str.= '</td>';
+        }
+        $Str .= '</tr></table>'."\n";
+        #
+        # Return the @Crumbs stack to what we started with
+        push(@Crumbs,$last);
+        shift(@Crumbs);
+        #
+        return $Str;
+    }
+
+    sub clear_breadcrumbs {
+        undef(@Crumbs);
+    }
+
+    sub add_breadcrumb {
+        push (@Crumbs,@_);
+    }
+
+}
+
+############################################################
+############################################################
+
 
 1;