--- loncom/interface/londocs.pm	2009/03/18 21:57:58	1.314.2.5
+++ loncom/interface/londocs.pm	2008/11/18 19:14:22	1.316
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.314.2.5 2009/03/18 21:57:58 raeburn Exp $
+# $Id: londocs.pm,v 1.316 2008/11/18 19:14:22 jms Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -26,6 +26,22 @@
 # http://www.lon-capa.org/
 #
 
+
+=head1 NAME
+
+Apache::londocs.pm
+
+=head1 SYNOPSIS
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=cut
+
 package Apache::londocs;
 
 use strict;
@@ -53,15 +69,27 @@ my %alreadyseen=();
 
 my $hadchanges;
 
-# Available help topics
+
+=pod
+
+=item %help=()
+
+ Available help topics
+
+=cut
 
 my %help=();
 
-# Mapread read maps into LONCAPA::map:: global arrays 
-# @order and @resources, determines status
-# sets @order - pointer to resources in right order
-# sets @resources - array with the resources with correct idx
-#
+=pod
+
+=item mapread()
+
+Mapread read maps into LONCAPA::map:: global arrays 
+@order and @resources, determines status
+sets @order - pointer to resources in right order
+sets @resources - array with the resources with correct idx
+
+=cut
 
 sub mapread {
     my ($coursenum,$coursedom,$map)=@_;
@@ -81,7 +109,14 @@ sub storemap {
     return ($errtext,0);
 }
 
-# ----------------------------------------- Return hash with valid author names
+
+=pod
+
+=item authorhosts()
+
+    Return hash with valid author names
+
+=cut
 
 sub authorhosts {
     my %outhash=();
@@ -116,7 +151,13 @@ sub authorhosts {
     }
     return ($home,$other,%outhash);
 }
-# ------------------------------------------------------ Generate "dump" button
+=pod
+
+=item dumpbutton()
+
+    Generate "dump" button
+
+=cut
 
 sub dumpbutton {
     my ($home,$other,%outhash)=&authorhosts();
@@ -141,7 +182,14 @@ sub clean {
     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
     return $title;	
 }
-# -------------------------------------------------------- Actually dump course
+
+=pod
+
+=item dumpcourse()
+
+    Actually dump course
+
+=cut
 
 sub dumpcourse {
     my ($r) = @_;
@@ -263,7 +311,13 @@ sub dumpcourse {
     }
 }
 
-# ------------------------------------------------------ Generate "export" button
+=pod
+
+=item exportbutton()
+
+    Generate "export" button
+
+=cut
 
 sub exportbutton {
     my $type = &Apache::loncommon::course_type();
@@ -273,6 +327,12 @@ sub exportbutton {
     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'</div>';
 }
 
+=pod
+
+=item exportcourse()
+
+=cut
+
 sub exportcourse {
     my $r=shift;
     my $type = &Apache::loncommon::course_type();
@@ -280,15 +340,6 @@ sub exportcourse {
                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
     my $numdisc = keys %discussiontime;
     my $navmap = Apache::lonnavmaps::navmap->new();
-    if (!defined($navmap)) {
-        $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package').
-                  '<h2>IMS Export Failed</h2>'.
-                  '<div class="LC_error">'.
-                  &mt('Unable to retrieve information about course contents').
-                  '</div><a href="/adm/coursedocs">'.&mt('Return to Course Editor').'</a>');
-        &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
-        return;
-    }
     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
     my $curRes;
     my $outcome;
@@ -480,7 +531,8 @@ function containerCheck(item) {
 	$r->print($display.'</table>'.
                   '<p><input type="hidden" name="finishexport" value="1">'.
                   '<input type="submit" name="exportcourse" value="'.
-                  &mt('Export '.$type.' DOCS').'" /></p></form>');
+                  &mt('Export '.$type.' DOCS').'" /></p></form>'.
+		  &Apache::loncommon::end_page());
     }
 }
 
@@ -919,8 +971,15 @@ sub store_template {
     }
 }
 
-# Imports the given (name, url) resources into the course
-# coursenum, coursedom, and folder must precede the list
+=pod
+
+=item group_import()
+
+    Imports the given (name, url) resources into the course
+    coursenum, coursedom, and folder must precede the list
+
+=cut
+
 sub group_import {
     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
 
@@ -1081,10 +1140,12 @@ sub log_docs {
     }
 }
 
+=pod
+
+=item docs_change_log()
+
+=cut
 
-#
-# Docs Change Log
-#
 sub docs_change_log {
     my ($r)=@_;
     my $folder=$env{'form.folder'};
@@ -1287,33 +1348,9 @@ sub do_paste_from_buffer {
 # Maps need to be copied first
     if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
 	$title=&mt('Copy of').' '.$title;
-        my $newid=$$.int(rand(100)).time;
-	my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
-        if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
-            my $path = $1;
-            my $prefix = $2;
-            my $ancestor = $3;
-            if (length($ancestor) > 10) {
-                $ancestor = substr($ancestor,-10,10);
-            }
-            $oldid = $path.$prefix.$ancestor;
-        }
-        my $counter = 0;
-        my $newurl=$oldid.$newid.'.'.$ext;
-        my $is_unique = &uniqueness_check($newurl);
-        while (!$is_unique && $counter < 100) {
-            $counter ++;
-            $newid ++;
-            $newurl = $oldid.$newid;
-            $is_unique = &uniqueness_check($newurl);
-        }
-        if (!$is_unique) {
-            if ($url=~/\.page$/) {
-                return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
-            } else {
-                return &mt('Paste failed: an error occurred creating a unique URL for the folder');
-            }
-        }
+	my $newid=$$.time;
+	$url=~/^(.+)\.(\w+)$/;
+	my $newurl=$1.$newid.'.'.$2;
 	my $storefn=$newurl;
 	$storefn=~s{^/\w+/$match_domain/$match_username/}{};
 	&Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
@@ -1362,20 +1399,6 @@ sub do_paste_from_buffer {
 # Store the result
 }
 
-sub uniqueness_check {
-    my ($newurl) = @_;
-    my $unique = 1;
-    foreach my $res (@LONCAPA::map::order) {
-        my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
-        $url=&LONCAPA::map::qtescape($url);
-        if ($newurl eq $url) {
-            $unique = 0;
-            last;    
-        }
-    }
-    return $unique;
-}
-
 my %parameter_type = ( 'randompick'     => 'int_pos',
 		       'hiddenresource' => 'string_yesno',
 		       'encrypturl'     => 'string_yesno',
@@ -1888,7 +1911,6 @@ END
     }
     
     my $orig_url = $url;
-    $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
     my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
 	my $symb=&Apache::lonnet::symbclean(
@@ -1951,7 +1973,7 @@ END
     	my $ro_set=
 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
 	$rand_order_text ='
-<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
+<nobr><label><input type="checkbox" name="randomorder_'.$orderidx.'" onClick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></nobr>';   
     }
     if ($ispage) {
         my $pagename=&escape($pagetitle);
@@ -2011,7 +2033,13 @@ ENDPARMS
     return $line;
 }
 
-# ---------------------------------------------------------------- tie the hash
+=pod
+
+=item tiehash()
+
+tie the hash
+
+=cut
 
 sub tiehash {
     my ($mode)=@_;
@@ -2037,7 +2065,15 @@ sub untiehash {
     return OK;
 }
 
-# --------------------------------------------------------------- check on this
+
+=pod
+
+=item checkonthis()
+
+check on this
+
+=cut
+
 
 sub checkonthis {
     my ($r,$url,$level,$title)=@_;
@@ -2111,36 +2147,38 @@ sub checkonthis {
 }
 
 
-#
-# ----------------------------------------------------------------- List Symbs
-# 
+
+=pod
+
+=item list_symbs()
+
+List Symbs
+
+=cut
+
 sub list_symbs {
     my ($r) = @_;
 
-    my $type = &Apache::loncommon::course_type();
     $r->print(&Apache::loncommon::start_page('Symb List'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
     my $navmap = Apache::lonnavmaps::navmap->new();
-    if (!defined($navmap)) {
-        $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
-                  '<div class="LC_error">'.
-                  &mt('Unable to retrieve information about course contents').
-                  '</div>');
-        &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
-    } else {
-        $r->print("<pre>\n");
-        foreach my $res ($navmap->retrieveResources()) {
-	    $r->print($res->compTitle()."\t".$res->symb()."\n");
-        }
-        $r->print("\n</pre>\n");
+    $r->print("<pre>\n");
+    foreach my $res ($navmap->retrieveResources()) {
+	$r->print($res->compTitle()."\t".$res->symb()."\n");
     }
+    $r->print("\n</pre>\n");
     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
 }
 
 
-#
-# -------------------------------------------------------------- Verify Content
-# 
+=pod
+
+=item verifycontent()
+
+Verify Content
+
+=cut
+
 sub verifycontent {
     my ($r) = @_;
     my $type = &Apache::loncommon::course_type();
@@ -2170,8 +2208,13 @@ sub verifycontent {
 	     &mt('Return to DOCS').'</a>');
 }
 
+=pod
+
+=item devalidateversioncache() & checkversions()
 
-# -------------------------------------------------------------- Check Versions
+Check Versions
+
+=cut
 
 sub devalidateversioncache {
     my $src=shift;
@@ -2475,7 +2518,13 @@ sub changewarning {
 $help{'Caching'}.'</span></h3></form>'."\n\n");
 }
 
-# =========================================== Breadcrumbs for special functions
+=pod
+
+=item init_breadcrumbs()
+
+Breadcrumbs for special functions
+
+=cut
 
 sub init_breadcrumbs {
     my ($form,$text)=@_;
@@ -2491,7 +2540,15 @@ sub init_breadcrumbs {
 					    bug=>'Instructor Interface'});
 }
 
-# ================================================================ Main Handler
+
+=pod
+
+=item handler()
+
+Main Handler
+
+=cut
+
 sub handler {
     my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');
@@ -3396,3 +3453,9 @@ ENDNEWSCRIPT
 }
 1;
 __END__
+
+=pod
+
+=back
+
+=cut