--- loncom/interface/londocs.pm 2008/12/13 00:19:07 1.320 +++ loncom/interface/londocs.pm 2009/01/28 18:10:04 1.329 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.320 2008/12/13 00:19:07 raeburn Exp $ +# $Id: londocs.pm,v 1.329 2009/01/28 18:10:04 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,7 +59,6 @@ my $hadchanges; my %help=(); - sub mapread { my ($coursenum,$coursedom,$map)=@_; return @@ -120,11 +119,9 @@ sub dumpbutton { my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } if ($home) { - return '
'. - ''. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'). - '
'; + &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'); } else { return '
'. &mt('Dump '.$type. @@ -265,10 +262,9 @@ sub dumpcourse { sub exportbutton { my $type = &Apache::loncommon::course_type(); - return '
'. - ''. - &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; + &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); } @@ -280,6 +276,15 @@ 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; @@ -471,8 +476,7 @@ function containerCheck(item) { $r->print($display.''. '

'. '

'. - &Apache::loncommon::end_page()); + &mt('Export '.$type.' DOCS').'" />

'); } } @@ -1270,7 +1274,9 @@ ENDPASTE sub do_paste_from_buffer { my ($coursenum,$coursedom,$folder) = @_; - return 0 if (!$env{'form.pastemarked'}); + if (!$env{'form.pastemarked'}) { + return; + } # paste resource to end of list my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); @@ -1278,13 +1284,45 @@ sub do_paste_from_buffer { # Maps need to be copied first if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) { $title=&mt('Copy of').' '.$title; - my $newid=$$.time; - $url=~/^(.+)\.(\w+)$/; - my $newurl=$1.$newid.'.'.$2; + 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 $storefn=$newurl; $storefn=~s{^/\w+/$match_domain/$match_username/}{}; - &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, - &Apache::lonnet::getfile($url)); + my $paste_map_result = + &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, + &Apache::lonnet::getfile($url)); + if ($paste_map_result eq '/adm/notfound.html') { + if ($url=~/\.page$/) { + return &mt('Paste failed: an error occurred saving the composite page'); + } else { + return &mt('Paste failed: an error occurred saving the folder'); + } + } $url = $newurl; } # published maps can only exists once, so remove it from paste buffer when done @@ -1326,9 +1364,24 @@ sub do_paste_from_buffer { $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res'; push(@LONCAPA::map::order, $newidx); + return 'ok'; # 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', @@ -1444,9 +1497,14 @@ sub editor { } if ($env{'form.pastemarked'}) { - &do_paste_from_buffer($coursenum,$coursedom,$folder); - ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container); - return $errtext if ($fatal); + my $paste_res = + &do_paste_from_buffer($coursenum,$coursedom,$folder); + if ($paste_res eq 'ok') { + ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container); + return $errtext if ($fatal); + } elsif ($paste_res ne '') { + $r->print('

'.$paste_res.'

'); + } } $r->print($upload_output); @@ -2082,19 +2140,27 @@ List Symbs 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(); - $r->print("
\n");
-    foreach my $res ($navmap->retrieveResources()) {
-	$r->print($res->compTitle()."\t".$res->symb()."\n");
+    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
\n"); $r->print(''.&mt('Return to DOCS').''); } - sub verifycontent { my ($r) = @_; my $type = &Apache::loncommon::course_type(); @@ -2452,6 +2518,7 @@ sub handler { return OK if $r->header_only; my $type = &Apache::loncommon::course_type(); + # --------------------------------------------- Initialize help topics for this foreach my $topic ('Adding_Course_Doc','Main_Course_Documents', 'Adding_External_Resource','Navigate_Content', @@ -2505,6 +2572,8 @@ sub handler { my $showdoc=0; my $containertag; my $uploadtag; + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['folderpath','pagepath', 'pagesymb']); @@ -2578,9 +2647,10 @@ sub handler { } # -------------------------------------------------------------------- Body tag $script = ''; - my @brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}]; + my $brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}]; $r->print(&Apache::loncommon::start_page("$type Documents", $script, - {'force_register' => $showdoc, bread_crumbs => @brcrum}). + {'force_register' => $showdoc, + 'bread_crumbs' => $brcrum}). &Apache::loncommon::help_open_menu('','',273,'RAT')); my %allfiles = (); @@ -2676,9 +2746,8 @@ sub handler { 'uplm' => 'Upload a new main '.lc($type).' document', 'upls' => 'Upload a new supplemental '.lc($type).' document', 'impp' => 'Import a document', - 'pubd' => 'Published documents', + 'pubd' => 'Published Documents', 'copm' => 'All documents out of a published map into this folder', - 'spec' => 'Special documents', 'upld' => 'Upload Document', 'srch' => 'Search', 'impo' => 'Import', @@ -2704,13 +2773,86 @@ sub handler { 'file' => 'File', 'title' => 'Title', 'comment' => 'Comment', - 'parse' => 'If HTML file, upload embedded images/multimedia files' + 'parse' => 'Upload embedded images/multimedia files if HTML file!', + 'nd' => 'New Document', + 'pm' => 'Published Map', + 'sd' => 'Special Document', + 'mo' => 'More Options', + 'hao' => 'Hide all Options' ); # ----------------------------------------------------------------------------- + my $fileupload=(< + +FIUP + + my $checkbox=(<$lt{'parse'}? + + --> + +CHBO + + my $fileuploadform=(< + $fileupload +
+ $lt{'title'}:
+ + $uploadtag + +
+ + $checkbox + +
+
+ + + $help{'Uploading_From_Harddrive'} + + +FUFORM + + my $simpleeditdefaultform=(< + $lt{'pubd'}
+ $uploadtag + +
+ + + $help{'Importing_LON-CAPA_Resource'} + +
+ +
+

+ $lt{'copm'}
+
+ + $help{'Load_Map'} +

+ +SEDFFORM + + my $extresourcesform=(< + $uploadtag + + + $help{'Adding_External_Resource'} + + +ERFORM + if ($allowed) { &update_paste_buffer($coursenum,$coursedom); - my $dumpbut=&dumpbutton(); - my $exportbut=&exportbutton(); my %lt=&Apache::lonlocal::texthash( 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', @@ -2730,41 +2872,7 @@ sub handler { $containertag = ''; $uploadtag = ''; } - - $r->print(< - - - - - $containertag - -
- - $uploadtag -
-
-
- -
- $help{'Verify_Content'} -
-
- $help{'Check_Resource_Versions'} -
- $dumpbut - $exportbut -
- -
-
- - -
-
-
-
 
-ENDCOURSEVERIFY + $r->print(&generate_admin_options($containertag,$uploadtag,\%lt,\%help,\%env)); $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc', &mt('Editing the Table of Contents for your '.$type))); } @@ -2807,219 +2915,250 @@ ENDCOURSEVERIFY $container='page'; } my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container; + + + + my $recoverform=(< + + +RFORM + + my $imspform=(< + + + +IMSPFORM + + my $newnavform=(< + $uploadtag + + + + $help{'Navigate_Content'} + + +NNFORM + my $newsmppageform=(< + $uploadtag + + + $help{'Simple Page'} + + +NSPFORM + + my $newsmpproblemform=(< + $uploadtag + + + $help{'Simple Problem'} + + + +NSPROBFORM + + my $newdropboxform=(< + $uploadtag + + + + + +NDBFORM + + my $newexuploadform=(< + $uploadtag + + + + $help{'Score_Upload_Form'} + + +NEXUFORM + + my $newbulform=(< + $uploadtag + + + + $help{'Bulletin Board'} + + +NBFORM + + my $newaboutmeform=(< + $uploadtag + + + + $help{'My Personal Info'} + + +NAMFORM + + my $newaboutsomeoneform=(< + $uploadtag + + + + + +NASOFORM + + + my $newrosterform=(< + $uploadtag + + + + $help{'Course Roster'} + + +NROSTFORM + $r->print(< +
  • $lt{'nd'}
  • +
  • $lt{'pm'}
  • +
  • $lt{'pubd'}
  • +
  • $lt{'sd'}
  • +
  • $lt{'mo'}
  • +
  • $lt{'hao'}
  • + + - +'."\n". @@ -3050,71 +3189,96 @@ ENDBLOCK '.sequence'; my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + + my $supupdocform=(< + $fileupload +
    +
    + + $checkbox + +

    + $lt{'comment'}:
    + +
    + + + + + $help{'Uploading_From_Harddrive'} + + +SUPDOCFORM + + my $supnewfolderform=(< + + + + $help{'Adding_Folders'} + + +SNFFORM + + + my $supnewextform=(< + + + + $help{'Adding_External_Resource'} + + +SNEFORM + + my $supnewsylform=(< + + + + + $help{'Syllabus'} + + +SNSFORM + + my $supnewaboutmeform=(< + + + + + $help{'My Personal Info'} + + +SNAMFORM + $r->print(<
    - - - +
      +
    • $lt{'nd'}
    • +
    • $lt{'sd'}
    • +
    • $lt{'hao'}
    • +
    +
    -$lt{'file'}:
    -
    - -
    -$lt{'title'}:
    - -$uploadtag - -
    - - - -
    -
    - - - $help{'Uploading_From_Harddrive'} - -
    +$fileuploadform
    -
    -$lt{'pubd'}
    -$uploadtag - -
    - - -$help{'Importing_LON-CAPA_Resource'} - -
    - +$simpleeditdefaultform
    -

    -$lt{'copm'}
    -
    - -$help{'Load_Map'} -

    -
    -
    -
    - -
    +$recoverform ENDFORM unless ($env{'form.pagepath'}) { $r->print(< -
    -$uploadtag - - - $help{'Adding_External_Resource'} - -
    -
    - - -
    +$extresourcesform +
    +$imspform ENDFORM } $r->print('
    '); unless ($env{'form.pagepath'}) { my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"'); + + + + my $newpageform=(< + + + + $help{'Adding_Pages'} + + +NPFORM + + my $newfolderform=(< + + + + $help{'Adding_Folders'} + + +NFFORM + + my $newsylform=(< + $uploadtag + + + + $help{'Syllabus'} + + +NSYLFORM + + my $newgroupfileform=(< + $uploadtag + + + + $help{'Group Files'} + + +NGFFORM + + $r->print(<
    - - - -$help{'Adding_Folders'} - -
    -
    - - - -$help{'Adding_Pages'} - -
    -
    -$uploadtag - - - - $help{'Syllabus'} - -
    -
    -$uploadtag - - - -$help{'Navigate_Content'} - -
    -
    -$uploadtag - - - $help{'Simple Page'} - -
    -
    -$uploadtag - - -$help{'Simple Problem'} - -
    -
    -$uploadtag - - - - -
    -
    -$uploadtag - - - -$help{'Score_Upload_Form'} - -
    -
    -$uploadtag - - - -$help{'Bulletin Board'} - -
    -
    -$uploadtag - - - -$help{'My Personal Info'} - -
    -
    -$uploadtag - - - - -
    -
    -$uploadtag - - - -$help{'Group Files'} - -
    -
    -$uploadtag - - - -$help{'Course Roster'} - -
    +
    +$newfolderform +
    +$newpageform +
    +$newsylform +
    +$newnavform +
    +$newsmppageform +
    +$newsmpproblemform +
    +$newdropboxform +
    +$newexuploadform +
    +$newbulform +
    +$newaboutmeform +
    +$newaboutsomeoneform +
    +$newgroupfileform +
    +$newrosterform ENDFORM } if ($env{'form.pagepath'}) { $r->print(< -$uploadtag - - -$help{'Simple Problem'} - - -
    -$uploadtag - - - -$help{'Score_Upload_Form'} - -
    +$newsmpproblemform +
    +$newexuploadform ENDBLOCK } $r->print('
    $lt{'upls'}$lt{'spec'}
    + -
    -
    - +$supupdocform +
    +$supnewfolderform
    +$supnewextform
    - - - -

    -$lt{'comment'}:
    - +$supnewsylform
    - - - - - $help{'Uploading_From_Harddrive'} - - -
    -
    - - - - $help{'Adding_Folders'} - -
    -
    - - - - $help{'Adding_External_Resource'} - -
    -
    - - - - -$help{'Syllabus'} - -
    -
    - - - - -$help{'My Personal Info'} - -
    +$supnewaboutmeform
    ENDSUPFORM @@ -3144,6 +3308,73 @@ ENDSUPFORM return OK; } +sub generate_admin_options { + my ($containertag,$uploadtag,$lt_ref,$help_ref,$env_ref) = @_; + my %lt = %{$lt_ref}; + my %help = %{$help_ref}; + my %env = %{$env_ref}; + my $dumpbut=&dumpbutton(); + my $exportbut=&exportbutton(); + return (< + + + + + $containertag + +
    + + $uploadtag +
    +
    +
      +
    • + $help{'Verify_Content'} +
    • +
    • + $help{'Check_Resource_Versions'} +
    • +
    • + $dumpbut +
    • +
    • + $exportbut +
    • +
    • + +
    • +
    • + + +
    • +
    +
    +
     
    +ENDOPTIONFORM +} + +sub generate_edit_table { + my ($optionhash_ref,$namehash_ref,$orderhash_ref) = @_; + my %optionhash = %{$optionhash_ref}; #id verlinkt mit inhalt + my %namehash = %{$namehash_ref}; #name verlinkt mit id + my %orderhash = %{$orderhash_ref}; #name mit kürzel verlinkt mit name + my $form; + $form = '

    '.&mt('Upload Course Documents').'

    '; + $form .= '
      '; + foreach my $name (sort(keys(%orderhash))){ + if($name eq 'zz_hide'){ + $form .= '
    • '.&mt($orderhash{$name}).'
    • '; + }else{ + $form .= '
    • '.&mt($orderhash{$name}).'
    • '; + } + } + foreach my $field (keys(%optionhash)){ + $form .= '
      '.$optionhash{$field}.'
      '; + } + $form .= '

    '; + return $form; +} sub editing_js { my ($udom,$uname) = @_; @@ -3346,6 +3577,7 @@ function markcopy(folderpath,index,oldti this.document.forms.renameform.submit(); } + ENDNEWSCRIPT } 1;