--- loncom/interface/londocs.pm 2009/03/18 21:57:58 1.314.2.5 +++ loncom/interface/londocs.pm 2008/11/21 20:31:48 1.317 @@ -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.317 2008/11/21 20:31:48 jms Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,6 +26,8 @@ # http://www.lon-capa.org/ # + + package Apache::londocs; use strict; @@ -53,15 +55,10 @@ my %alreadyseen=(); my $hadchanges; -# Available help topics 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 -# + sub mapread { my ($coursenum,$coursedom,$map)=@_; @@ -81,7 +78,7 @@ sub storemap { return ($errtext,0); } -# ----------------------------------------- Return hash with valid author names + sub authorhosts { my %outhash=(); @@ -116,7 +113,7 @@ sub authorhosts { } return ($home,$other,%outhash); } -# ------------------------------------------------------ Generate "dump" button + sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); @@ -141,7 +138,8 @@ sub clean { $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs; return $title; } -# -------------------------------------------------------- Actually dump course + + sub dumpcourse { my ($r) = @_; @@ -263,7 +261,7 @@ sub dumpcourse { } } -# ------------------------------------------------------ Generate "export" button + sub exportbutton { my $type = &Apache::loncommon::course_type(); @@ -273,6 +271,8 @@ sub exportbutton { &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').''; } + + sub exportcourse { my $r=shift; my $type = &Apache::loncommon::course_type(); @@ -280,15 +280,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'). - '

IMS Export Failed

'. - '
'. - &mt('Unable to retrieve information about course contents'). - '
'.&mt('Return to Course Editor').''); - &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 +471,8 @@ function containerCheck(item) { $r->print($display.''. '

'. '

'); + &mt('Export '.$type.' DOCS').'" />

'. + &Apache::loncommon::end_page()); } } @@ -919,8 +911,7 @@ sub store_template { } } -# Imports the given (name, url) resources into the course -# coursenum, coursedom, and folder must precede the list + sub group_import { my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; @@ -1082,9 +1073,9 @@ sub log_docs { } -# -# Docs Change Log -# + + + sub docs_change_log { my ($r)=@_; my $folder=$env{'form.folder'}; @@ -1287,33 +1278,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 +1329,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 +1841,6 @@ END } my $orig_url = $url; - $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}); if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) { my $symb=&Apache::lonnet::symbclean( @@ -1951,7 +1903,7 @@ END my $ro_set= ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':''); $rand_order_text =' -'; +'; } if ($ispage) { my $pagename=&escape($pagetitle); @@ -2011,7 +1963,13 @@ ENDPARMS return $line; } -# ---------------------------------------------------------------- tie the hash +=pod + +=item tiehash() + +tie the hash + +=cut sub tiehash { my ($mode)=@_; @@ -2037,7 +1995,8 @@ sub untiehash { return OK; } -# --------------------------------------------------------------- check on this + + sub checkonthis { my ($r,$url,$level,$title)=@_; @@ -2111,36 +2070,31 @@ 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('

'.&mt('Retrieval of List Failed').'

'. - '
'. - &mt('Unable to retrieve information about course contents'). - '
'); - &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'}); - } else { - $r->print("
\n");
-        foreach my $res ($navmap->retrieveResources()) {
-	    $r->print($res->compTitle()."\t".$res->symb()."\n");
-        }
-        $r->print("\n
\n"); + $r->print("
\n");
+    foreach my $res ($navmap->retrieveResources()) {
+	$r->print($res->compTitle()."\t".$res->symb()."\n");
     }
+    $r->print("\n
\n"); $r->print(''.&mt('Return to DOCS').''); } -# -# -------------------------------------------------------------- Verify Content -# + sub verifycontent { my ($r) = @_; my $type = &Apache::loncommon::course_type(); @@ -2171,8 +2125,6 @@ sub verifycontent { } -# -------------------------------------------------------------- Check Versions - sub devalidateversioncache { my $src=shift; &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'. @@ -2475,7 +2427,6 @@ sub changewarning { $help{'Caching'}.''."\n\n"); } -# =========================================== Breadcrumbs for special functions sub init_breadcrumbs { my ($form,$text)=@_; @@ -2491,7 +2442,9 @@ sub init_breadcrumbs { bug=>'Instructor Interface'}); } -# ================================================================ Main Handler + + + sub handler { my $r = shift; &Apache::loncommon::content_type($r,'text/html'); @@ -3396,3 +3349,126 @@ ENDNEWSCRIPT } 1; __END__ + + +=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 + +=item %help=() + +Available help topics + +=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 + +=item authorhosts() + +Return hash with valid author names + +=item dumpbutton() + +Generate "dump" button + +=item clean() + +=item dumpcourse() + + Actually dump course + + +=item exportbutton() + + Generate "export" button + +=item exportcourse() + +=item create_ims_store() + +=item build_package() + +=item get_dependencies() + +=item process_content() + +=item replicate_content() + +=item extract_media() + +=item store_template() + +=item group_import() + + Imports the given (name, url) resources into the course + coursenum, coursedom, and folder must precede the list + +=item breadcrumbs() + +=item log_docs() + +=item docs_change_log() + +=item update_paste_buffer() + +=item print_paste_buffer() + +=item do_paste_from_buffer() + +=item update_parameter() + +=item handle_edit_cmd() + +=item editor() + +=item process_file_upload() + +=item process_secondary_uploads() + +=item is_supplemental_title() + +=item parse_supplemental_title() + +=item entryline() + +=item tiehash() + +=item untiehash() + +=item checkonthis() + +check on this + +=item verifycontent() + +Verify Content + +=item devalidateversioncache() & checkversions() + +Check Versions + +=item mark_hash_old() + +=item is_hash_old() + +=item changewarning() + +=item init_breadcrumbs() + +Breadcrumbs for special functions + +=back + +=cut