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

www www@source.lon-capa.org
Sat, 11 Dec 2010 00:09:52 -0000


www		Sat Dec 11 00:09:52 2010 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  Eliminate some (unneeded?) logic and copy/paste coding
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.445 loncom/interface/londocs.pm:1.446
--- loncom/interface/londocs.pm:1.445	Wed Dec  8 02:08:21 2010
+++ loncom/interface/londocs.pm	Sat Dec 11 00:09:52 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.445 2010/12/08 02:08:21 www Exp $
+# $Id: londocs.pm,v 1.446 2010/12/11 00:09:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1521,12 +1521,11 @@
         $LONCAPA::map::resources[$idx]='';
     }
 
-    my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
-    if ($allowed) {
-        ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
+    my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
 	    &breadcrumbs($allowed,$crstype);
         $r->print($breadcrumbtrail);
-    } else {
+
+    unless ($allowed) {
         $randompick = -1;
     }
 
@@ -2663,6 +2662,10 @@
    $r->print('</div></div></div>');
 }
 
+sub supplemental_base {
+    return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Documents'));
+}
+
 sub handler {
     my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');
@@ -2759,29 +2762,42 @@
         &Apache::loncommon::restore_course_settings($stored_folderpath,
                                               {'folderpath' => 'scalar'});
     }
+   
+# If we are not allowed to make changes, all we can see are supplemental docs
     if (!$allowed) {
-        unless($env{'form.folderpath'} =~ /^supplemental/) {
-            $env{'form.folderpath'} = '';
+        $env{'form.pagepath'}='';
+        unless ($env{'form.folderpath'} =~ /^supplemental/) {
+            $env{'form.folderpath'} = &supplemental_base();
         }
     }
+# If we still not have a folderpath, see if we can resurrect at pagepath
     if (!$env{'form.folderpath'} && $allowed) {
         &Apache::loncommon::restore_course_settings($stored_folderpath,
                                               {'pagepath' => 'scalar'});
     }
-    if ($env{'form.pagepath'}) {
-       $env{'form.folderpath'}='';
-    }
+# Make the zeroth entry in supplemental docs page paths, so we can get to top level
     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
-        $env{'form.folderpath'} = 'supplemental&'.
-                                  &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
+        $env{'form.folderpath'} = &supplemental_base()
+                                  .'&'.
                                   $env{'form.folderpath'};
     }
+# If after all of this, we still don't have any paths, make them
+    unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
+       if ($supplementalflag) {
+          $env{'form.folderpath'}=&supplemental_base();
+       } else {
+          $env{'form.folderpath'}='default';
+       }
+    } 
+
 # Store this
     if ($allowed) {
        &Apache::loncommon::store_course_settings($stored_folderpath,
                                                 {'pagepath' => 'scalar',
                                                  'folderpath' => 'scalar'});
     }
+
+
     if ($env{'form.folderpath'}) {
 	my (@folderpath)=split('&',$env{'form.folderpath'});
 	$env{'form.foldername'}=&unescape(pop(@folderpath));
@@ -2846,29 +2862,20 @@
 
     # Breadcrumbs
     &Apache::lonhtmlcommon::clear_breadcrumbs();
-    if ($allowed) {
+    unless ($showdoc) {
         &Apache::lonhtmlcommon::add_breadcrumb({
-            href=>"/adm/coursedocs",text=>"$crstype Editor"});
+            href=>"/adm/coursedocs",text=>"$crstype Contents"});
 
-        $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
+        $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
                                                  {'force_register' => $showdoc,})
                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                  .&Apache::lonhtmlcommon::breadcrumbs(
                      'Editing the Table of Contents for your '.$crstype,
                      'Docs_Adding_Course_Doc')
         );
-    } elsif ($showdoc) {
+    } else {
         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
                                                 {'force_register' => $showdoc,}));
-    } else {
-        my $folder=$env{'form.folder'};
-        if ($folder eq '' || $folder eq 'supplemental') {
-            $env{'form.folderpath'} = 'supplemental&'.
-                                      &escape(&mt('Supplemental '.$crstype.' Documents'));
-        }
-        my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
-        $r->print(&Apache::loncommon::start_page("Supplemental documents").
-                  $breadcrumbtrail);
     }
 
   my %allfiles = ();
@@ -3310,8 +3317,7 @@
        }
        if ($folder =~ /^supplemental$/ &&
 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
-          $env{'form.folderpath'} = 'supplemental&'.
-                                    &escape(&mt('Supplemental '.$crstype.' Documents'));
+          $env{'form.folderpath'} = &supplemental_base();
        } elsif ($allowed) {
 	  $env{'form.folderpath'} = $savefolderpath;
        }
@@ -3594,7 +3600,7 @@
         }
     }
     my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
-    my $toplevelsupp = 'supplemental&Supplemental%20'.$crstype.'%20Documents';
+    my $toplevelsupp = &supplemental_base();
 
     return <<ENDNEWSCRIPT;
 function makenewfolder(targetform,folderseq) {