--- loncom/interface/londocs.pm 2010/02/02 01:30:46 1.325.2.7 +++ loncom/interface/londocs.pm 2009/07/13 17:34:28 1.379 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.325.2.7 2010/02/02 01:30:46 raeburn Exp $ +# $Id: londocs.pm,v 1.379 2009/07/13 17:34:28 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,7 +59,6 @@ my $hadchanges; my %help=(); - sub mapread { my ($coursenum,$coursedom,$map)=@_; return @@ -73,7 +72,7 @@ sub storemap { &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. $map,1); if ($errtext) { return ($errtext,2); } - + $hadchanges=1; return ($errtext,0); } @@ -117,17 +116,15 @@ sub authorhosts { sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); - my $crstype = &Apache::loncommon::course_type(); + my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } if ($home) { - return '
'. - ''. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'). - '
'; + return ''. + &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'
'; } else { return '
'. - &mt('Dump '.$crstype. + &mt('Dump '.$type. ' DOCS to Construction Space: available on other servers'). '
'; } @@ -136,17 +133,17 @@ sub dumpbutton { sub clean { my ($title)=@_; $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs; - return $title; + return $title; } sub dumpcourse { my ($r) = @_; - my $crstype = &Apache::loncommon::course_type(); - $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' DOCS to Construction Space'). + my $type = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space'). '
'); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' DOCS to Construction Space')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space')); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { return ''; } my $origcrsid=$env{'request.course.id'}; @@ -178,8 +175,8 @@ sub dumpcourse { my $fail=0; for (my $i=0;$i<$#dirs;$i++) { $makepath.='/'.$dirs[$i]; - unless (-e $makepath) { - unless(mkdir($makepath,0777)) { $fail=1; } + unless (-e $makepath) { + unless(mkdir($makepath,0777)) { $fail=1; } } } $r->print('
'.$item.' => '.$newfilename.': '); @@ -257,17 +254,17 @@ sub dumpcourse { $r->print(&Apache::loncommon::end_data_table()); &untiehash(); $r->print( - '

'); + '

'); } } sub exportbutton { - my $crstype = &Apache::loncommon::course_type(); + my $type = &Apache::loncommon::course_type(); return ''. + .' title="'.&mt('Export '.$type.' to IMS Package').'" />'. &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; } @@ -275,28 +272,18 @@ sub exportbutton { sub exportcourse { my $r=shift; - my $crstype = &Apache::loncommon::course_type(); + my $type = &Apache::loncommon::course_type(); my %discussiontime = &Apache::lonnet::dump('discussiontimes', $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 '.$crstype.' to IMS Package'). + $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package'). '

'.&mt('IMS Export Failed').'

'. - '
'); - if ($crstype eq 'Community') { - $r->print(&mt('Unable to retrieve information about community contents')); - } else { - $r->print(&mt('Unable to retrieve information about course contents')); - } - $r->print('
'); - if ($crstype eq 'Community') { - $r->print(&mt('Return to Community Editor')); - } else { - $r->print(&mt('Return to Course Editor')); - } - $r->print(''); - &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'}); + '
'. + &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); @@ -345,16 +332,16 @@ sub exportcourse { open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; - $outcome .= '

' - .&mt('[_1]Your IMS package[_2] is ready for download.' - ,'','') - .'

'; if ($copyresult) { $outcome .= '

' .&mt('The following errors occurred during export - [_1]' ,$copyresult) .'

'; } + $outcome .= '

' + .&mt('[_1]Your IMS package[_2] is ready for download.' + ,'','') + .'

'; } else { $outcome = '

' .&mt('Unfortunately you will not be able to retrieve' @@ -367,31 +354,29 @@ sub exportcourse { .'

'; } } - $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); + $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); $r->print($outcome); $r->print(&Apache::loncommon::end_page()); } else { - my $display='
'."\n". - '

'. - &mt('Choose which items you wish to export from your '.$crstype.'.'). - '

'. - '
'. + my $display; + $display = ''."\n"; + $display .= '

' + .&mt('Choose which items you wish to export from your '.$type.'.') + .'

'; + $display .= '
'. ''.&mt('Content items').''. ''. '  
'; - if ($numdisc > 0) { - $display .= '
'. - ''.&mt('Discussion posts').''. - ''. - '  '. - '
'; - } - $display .= '
'; + ' onclick="javascript:uncheckAll(document.exportdoc.archive)" />
'. + '
'. + ''.&mt('Discussion posts').''. + ''. + '  '. + '
'; my $curRes; my $depth = 0; my $count = 0; @@ -402,11 +387,15 @@ sub exportcourse { my $lastcontainer = $startcount; $display .= &Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() - .''.&mt('Export content item?').''; + .''.&mt('Export content item?').'' + .''; if ($numdisc > 0) { - $display .= ''.&mt('Export discussion posts?').''; + $display .= &mt('Export discussion posts?'); + } else { + $display .= ' '; } - $display .= &Apache::loncommon::end_data_table_header_row(); + $display .= '' + .&Apache::loncommon::end_data_table_header_row(); while ($curRes = $it->next()) { if (ref($curRes)) { $count ++; @@ -427,30 +416,33 @@ sub exportcourse { $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard'; } } - my $currelem = $count+$boards+$startcount; $display .= &Apache::loncommon::start_data_table_row() .''."\n" .'is_sequence()) || ($curRes->is_page())) { - $lastcontainer = $currelem; - $display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"'; + my $checkitem = $count + $boards + $startcount; + $display .= 'onclick="javascript:propagateCheck('."'$checkitem'".')"'; } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { - $display .= ('' x2)."\n"; + $display .= '' + .''."\n"; } if ($curRes->is_sequence()) { $display .= ' '."\n"; + $lastcontainer = $count + $startcount + $boards; } elsif ($curRes->is_page()) { $display .= ' '."\n"; + $lastcontainer = $count + $startcount + $boards; } + my $currelem = $count+$boards+$startcount; $children{$parent{$depth}} .= $currelem.':'; $display .= ' '.$curRes->title().''."\n"; # Existing discussion posts? - if ($discussiontime{$ressymb} > 0) { $boards ++; + $currelem = $count+$boards+$startcount; $display .= '' .'' .''."\n"; @@ -464,7 +456,6 @@ sub exportcourse { my $scripttag = qq| |; - $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package', - $scripttag)); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($crstype).' to IMS content package')); + $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package', + $scripttag)); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); $r->print($display. '

'. ''."\n". '\n"; } } elsif ($caller eq 'noedit') { -# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. +# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. $repstatus = 'ok'; - $content = 'Not the owner of this resource'; + $content = 'Not the owner of this resource'; } if ($repstatus eq 'ok') { print $copiedfile $content; @@ -900,14 +890,14 @@ sub extract_media { } } if ($caller eq 'resource') { - my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; - my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); $embed_content = &Apache::lonnet::getfile($embed_path); unless ($embed_content eq -1) { $repstatus = 'ok'; } } elsif ($caller eq 'uploaded') { - + $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); } if ($repstatus eq 'ok') { @@ -969,10 +959,10 @@ sub group_import { while (@files) { my ($name, $url, $residx) = @{ shift(@files) }; - if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) + if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs') && (!&Apache::lonnet::stat_file($url))) { - + my $errtext = ''; my $fatal = 0; my $newmapstr = ''."\n". @@ -992,7 +982,7 @@ sub group_import { } } if ($url) { - if (!$residx + if (!$residx || defined($LONCAPA::map::zombies[$residx])) { $residx = &LONCAPA::map::getresidx($url,$residx); push(@LONCAPA::map::order, $residx); @@ -1001,7 +991,7 @@ sub group_import { if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } $url = &LONCAPA::map::qtunescape($url); $name = &LONCAPA::map::qtunescape($name); - $LONCAPA::map::resources[$residx] = + $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); } } @@ -1009,7 +999,7 @@ sub group_import { } sub breadcrumbs { - my ($allowed,$crstype)=@_; + my ($where,$allowed,$type)=@_; &Apache::lonhtmlcommon::clear_breadcrumbs(); my (@folders); if ($env{'form.pagepath'}) { @@ -1032,9 +1022,9 @@ sub breadcrumbs { my $url='/adm/coursedocs?folderpath='. &escape($folderpath); my $name=&unescape($foldername); -# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername +# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//; - if ($1 ne '') { + if ($1 ne '') { $randompick=$1; } else { $randompick=-1; @@ -1044,23 +1034,22 @@ sub breadcrumbs { if ($4 ne '') { $is_random_order = 1; } if ($folder eq 'supplemental') { if ($allowed) { - $name = &mt('Supplemental '.$crstype.' Documents'); + $name = &mt('Supplemental '.$type.' Documents'); } else { - $name = &mt($crstype.' Documents'); + $name = &mt($type.' Documents'); } } &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, 'title'=>$name, - 'text'=>''. - $name.'', + 'text'=>$name, 'no_mt'=>1, }); $plain.=$name.' > '; } $plain=~s/\>\;\s*$//; return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', - 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order); + undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order); } sub log_docs { @@ -1173,7 +1162,7 @@ sub docs_change_log { foreach my $key (@changes) { $wholeentry.=':'.$docslog{$id}{'logentry'}{$key}; } - if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } + if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } } my $count = 0; my $time = @@ -1224,7 +1213,7 @@ sub docs_change_log { if ($oldname ne '' && $oldname ne $newname) { $r->print(&LONCAPA::map::qtescape($newname)); } - } + } $r->print('

'); - } + } if ($randompick>=0) { $r->print('

'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'

'); } if ($is_random_order) { $r->print('

'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'

'); } - $r->print(''); + $r->print(&Apache::loncommon::start_data_table()); foreach my $res (@LONCAPA::map::order) { my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]); $name=&LONCAPA::map::qtescape($name); @@ -1619,14 +1608,16 @@ sub editor { unless ($name) { $name=(split(/\//,$url))[-1]; } unless ($name) { $idx++; next; } $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res, - $coursenum,$crstype)); + $coursenum)); $idx++; $shown++; } unless ($shown) { - $r->print(''); + $r->print(''); } - $r->print("\n
'.&mt('Currently no documents.').'

' + .&mt('Currently no documents.') + .'

\n"); + $r->print(&Apache::loncommon::end_data_table()); if ($allowed) { &print_paste_buffer($r,$container); } @@ -1697,7 +1688,7 @@ sub process_file_upload { return 'failed'; } else { if ($parseaction eq 'parse') { - my $total_embedded = scalar(keys(%{$allfiles})); + my $total_embedded = keys(%{$allfiles}); if ($total_embedded > 0) { my $num = 0; my $state = ' @@ -1708,7 +1699,7 @@ sub process_file_upload { '; $phase_status = 'phasetwo'; - $$upload_output .= + $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.
'. &Apache::loncommon::ask_for_embedded_content( '/adm/coursedocs',$state,$allfiles,$codebase); @@ -1758,20 +1749,19 @@ sub parse_supplemental_title { $foldertitle=&Apache::lontexconvert::msgtexconverted($4); my $name = &Apache::loncommon::plainname($uname,$udom); $name = &HTML::Entities::encode($name,'"<>&\''); - $renametitle = &HTML::Entities::encode($renametitle,'"<>&\''); $title=''.&Apache::lonlocal::locallocaltime($time).' '. $name.':
'.$foldertitle; } if (wantarray) { return ($title,$foldertitle,$renametitle); - } + } return $title; } # --------------------------------------------------------------- An entry line sub entryline { - my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_; + my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_; my ($foldertitle,$pagetitle,$renametitle); if (&is_supplemental_title($title)) { @@ -1785,12 +1775,12 @@ sub entryline { } my $orderidx=$LONCAPA::map::order[$index]; - + $renametitle=~s/\\/\\\\/g; $renametitle=~s/\"\;/\\\"/g; $renametitle=~s/ /%20/g; - my $line=''; + my $line=&Apache::loncommon::start_data_table_row(); my ($form_start,$form_end); # Edit commands my ($container, $type, $esc_path, $path, $symb); @@ -1812,16 +1802,16 @@ sub entryline { my $incindex=$index+1; my $selectbox=''; if (($folder!~/^supplemental/) && - ($#LONCAPA::map::order>0) && + ($#LONCAPA::map::order>0) && ((split(/\:/, - $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1] - ne '') && + $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1] + ne '') && ((split(/\:/, - $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1] + $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1] ne '')) { $selectbox= ''. - ''; for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) { if ($i==$incindex) { $selectbox.=''; @@ -1854,13 +1844,13 @@ sub entryline { } } } - if ($url=~/^\/res\/lib\/templates\//) { - $nocopy=1; + if ($url=~/^\/res\/lib\/templates\//) { + $nocopy=1; $nocut=1; } my $copylink=' '; my $cutlink=' '; - + my $skip_confirm = 0; if ( $folder =~ /^supplemental/ || ($url =~ m{( /smppg$ @@ -1893,18 +1883,16 @@ END $form_end = '
'; $line.=(< - - - - - - - -
- $lt{ -
- $lt{ -
+
+ + $lt{ + +
+
+ + $lt{ + +
$form_start @@ -1946,7 +1934,7 @@ END &Apache::lonnet::allowuploaded('/adm/coursedoc',$url); } } - + my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}); @@ -1970,7 +1958,7 @@ END } elsif ($url!~/\.(sequence|page)$/) { $url='/adm/coursedocs/showdoc'.$url; } - } elsif ($url=~m|^/ext/|) { + } elsif ($url=~m|^/ext/|) { $url='/adm/wrapper'.$url; $external = 1; } @@ -1981,7 +1969,7 @@ END } if ($container eq 'page') { my $symb=$env{'form.pagesymb'}; - + $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]); $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); } @@ -1991,7 +1979,7 @@ END my $foldername=&escape($foldertitle); my $folderpath=$env{'form.folderpath'}; if ($folderpath) { $folderpath.='&' }; -# Append randompick number, hidden, and encrypted with ":" to foldername, +# Append randompick number, hidden, and encrypted with ":" to foldername, # so it gets transferred between levels $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx, 'parameter_randompick'))[0] @@ -2003,7 +1991,7 @@ END 'parameter_randomorder'))[0]=~/^yes$/i); $url.='folderpath='.&escape($folderpath).$cpinfo; $parameterset='