--- loncom/interface/londocs.pm 2006/05/30 12:46:09 1.228 +++ loncom/interface/londocs.pm 2006/11/22 03:56:36 1.255 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.228 2006/05/30 12:46:09 www Exp $ +# $Id: londocs.pm,v 1.255 2006/11/22 03:56:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,16 +33,15 @@ use Apache::Constants qw(:common :http); use Apache::imsexport; use Apache::lonnet; use Apache::loncommon; -use Apache::lonratedt; -use Apache::lonratsrv; +use LONCAPA::map(); +use Apache::lonratedt(); use Apache::lonxml; -use Apache::loncreatecourse; +use Apache::lonclonecourse; use Apache::lonnavmaps; use HTML::Entities; use GDBM_File; use Apache::lonlocal; use Cwd; -use lib '/home/httpd/lib/perl/'; use LONCAPA; my $iconpath; @@ -58,7 +57,7 @@ my $hadchanges; my %help=(); -# Mapread read maps into lonratedt::global arrays +# 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 @@ -67,15 +66,15 @@ my %help=(); sub mapread { my ($coursenum,$coursedom,$map)=@_; return - &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'. - $map); + &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'. + $map); } sub storemap { my ($coursenum,$coursedom,$map)=@_; my ($outtext,$errtext)= - &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. - $map,1); + &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. + $map,1); if ($errtext) { return ($errtext,2); } $hadchanges=1; @@ -121,16 +120,18 @@ sub authorhosts { sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); + my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } my $output=''; if ($home) { return ''. ''. + &mt('Dump '.$type.' DOCS to Construction Space').'" />'. &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'); } else { return''. - &mt('Dump Course DOCS to Construction Space: available on other servers'); + &mt('Dump '.$type. + ' DOCS to Construction Space: available on other servers'); } } @@ -143,8 +144,8 @@ sub clean { sub dumpcourse { my ($r) = @_; - - $r->print(&Apache::loncommon::start_page('Dump Course DOCS to Construction Space'). + my $type = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space'). '
'); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { return ''; } @@ -184,13 +185,13 @@ sub dumpcourse { $r->print('
'.$_.' => '.$newfilename.': '); if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) { if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) { - print $fh &Apache::loncreatecourse::rewritefile( - &Apache::loncreatecourse::readfile($env{'request.course.id'},$_), + print $fh &Apache::lonclonecourse::rewritefile( + &Apache::lonclonecourse::readfile($env{'request.course.id'},$_), (%replacehash,$crs => '') ); } else { print $fh - &Apache::loncreatecourse::readfile($env{'request.course.id'},$_); + &Apache::lonclonecourse::readfile($env{'request.course.id'},$_); } $fh->close(); } else { @@ -228,15 +229,17 @@ sub dumpcourse { $r->print('

'.&mt('Folder in Construction Space').'


'); &tiehash(); $r->print('

'.&mt('Filenames in Construction Space').'

'); - foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) { + foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { $r->print(''); my ($ext)=($_=~/\.(\w+)$/); my $title=$hash{'title_'.$hash{ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}}; $title=~s/:/:/g; $r->print(''); - unless ($title) { + if (!$title) { $title=$_; + } else { + $title=~s|/|_|g; } $title=~s/\.(\w+)$//; $title=&clean($title); @@ -246,21 +249,23 @@ sub dumpcourse { $r->print("
'.&mt('Internal Filename').''.&mt('Title').''.&mt('Save as ...').'
'.$_.''.($title?$title:' ').'
\n"); &untiehash(); $r->print( - '

'); + '

'); } } # ------------------------------------------------------ Generate "export" button sub exportbutton { + my $type = &Apache::loncommon::course_type(); return ''. ''. + &mt('Export '.$type.' to IMS').'" />'. &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); } sub exportcourse { my $r=shift; + 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; @@ -301,7 +306,7 @@ sub exportcourse { open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; - $outcome .= 'Download the zip file from IMS course archive
'; + $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive
',$imszipfile,); if ($copyresult) { $outcome .= 'The following errors occurred during export - '.$copyresult; } @@ -309,13 +314,13 @@ sub exportcourse { $outcome = '
Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.
'; } } - $r->print(&Apache::loncommon::start_page('Export course to IMS content package')); + $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package')); $r->print($outcome); $r->print(&Apache::loncommon::end_page()); } else { my $display; $display = '
'."\n"; - $display .= 'Choose which items you wish to export from your course.

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

'); $display .= ''. '
 Content items'. ' |; - $r->print(&Apache::loncommon::start_page('Export course to IMS content package', + $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package', $scripttag)); $r->print($display.'
'. '

'. '

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

'. &Apache::loncommon::end_page()); } } @@ -925,13 +930,13 @@ sub group_import { } } if ($url) { - my $idx = &Apache::lonratedt::getresidx($url); - $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx; + my $idx = &LONCAPA::map::getresidx($url); + $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx; my $ext = 'false'; if ($url=~/^http:\/\//) { $ext = 'true'; } $url =~ s/:/\:/g; $name =~ s/:/\:/g; - $Apache::lonratedt::resources[$idx] = + $LONCAPA::map::resources[$idx] = join ':', ($name, $url, $ext, 'normal', 'res'); } } @@ -949,13 +954,16 @@ sub breadcrumbs { } my $folderpath; my $cpinfo=''; + my $plain=''; if ($env{'form.markedcopy_url'}) { - &Apache::lonnet::logthis('Found '.$env{'form.markedcopy_url'}); $cpinfo='&markedcopy_url='. &escape($env{'form.markedcopy_url'}). '&markedcopy_title='. &escape($env{'form.markedcopy_title'}); } + my $randompick=-1; + my $isencrypted=0; + my $ishidden=0; while (@folders) { my $folder=shift(@folders); my $foldername=shift(@folders); @@ -963,16 +971,209 @@ sub breadcrumbs { $folderpath.=$folder.'&'.$foldername; my $url='/adm/coursedocs?folderpath='. &escape($folderpath); + my $name=&unescape($foldername); +# randompick number, hidden, encrypted is appended with ":"s to the foldername + $name=~s/\:(\d*)\:(\w*)\:(\w*)$//; + if ($1 ne '') { + $randompick=$1; + } else { + $randompick=-1; + } + if ($2) { $ishidden=1; } + if ($3) { $isencrypted=1; } &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, - 'title'=>&unescape($foldername), + 'title'=>$name, 'text'=>''. - &unescape($foldername).'' + $name.'' }); - - + $plain.=$name.' > '; + } + $plain=~s/\>\;\s*$//; + return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', + 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain); +} + +sub log_docs { + return &Apache::lonnet::instructor_log('docslog',@_); +} + +{ + my @oldresources=(); + my @oldorder=(); + my $parmidx; + my %parmaction=(); + my %parmvalue=(); + my $changedflag; + + sub snapshotbefore { + @oldresources=@LONCAPA::map::resources; + @oldorder=@LONCAPA::map::order; + $parmidx=undef; + %parmaction=(); + %parmvalue=(); + $changedflag=0; + } + + sub remember_parms { + my ($idx,$parameter,$action,$value)=@_; + $parmidx=$idx; + $parmaction{$parameter}=$action; + $parmvalue{$parameter}=$value; + $changedflag=1; + } + + sub log_differences { + my ($plain)=@_; + my %storehash=('folder' => $plain); + if ($parmidx) { + $storehash{'parameter_res'}=$oldresources[$parmidx]; + foreach my $parm (keys %parmaction) { + $storehash{'parameter_action_'.$parm}=$parmaction{$parm}; + $storehash{'parameter_value_'.$parm}=$parmvalue{$parm}; + } + } + my $maxidx=$#oldresources; + if ($#LONCAPA::map::resources>$#oldresources) { + $maxidx=$#LONCAPA::map::resources; + } + for (my $idx=0; $idx<=$maxidx; $idx++) { + if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) { + $storehash{'before_resources_'.$idx}=$oldresources[$idx]; + $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx]; + $changedflag=1; + } + if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) { + $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]]; + $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]; + $changedflag=1; + } + } + $storehash{'maxidx'}=$maxidx; + if ($changedflag) { &log_docs(\%storehash); } + } +} + + +# +# Docs Change Log +# +sub docs_change_log { + my ($r)=@_; + $r->print(&Apache::loncommon::start_page('Course Document Change Log')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log')); + + my %docslog=&Apache::lonnet::dump('nohist_docslog', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + + if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); } + + $r->print('
'. + ''); + + my %saveable_parameters = ('show' => 'scalar',); + &Apache::loncommon::store_course_settings('docs_log', + \%saveable_parameters); + &Apache::loncommon::restore_course_settings('docs_log', + \%saveable_parameters); + if (!$env{'form.show'}) { $env{'form.show'}=10; } + my %lt=('hiddenresource' => 'Resources hidden', + 'encrypturl' => 'URL hidden', + 'randompick' => 'Randomly pick', + 'set' => 'set to', + 'del' => 'deleted'); + + my $countselect = + &Apache::lonmeta::selectbox('show',$env{'form.show'},undef, + (&mt('all'),10,20,50,100,1000,10000)); + + $r->print(''.&mt('[_1] Records',$countselect).''. + '
'); + $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row(). + ''.&mt('Time').''.&mt('User').''.&mt('Folder').''.&mt('Before').''. + &mt('After').''. + &Apache::loncommon::end_data_table_header_row()); + my $shown=0; + foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) { + my @changes=keys(%{$docslog{$id}{'logentry'}}); + my $count = 0; + my $time = + &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'}); + my $plainname = + &Apache::loncommon::plainname($docslog{$id}{'exe_uname'}, + $docslog{$id}{'exe_udom'}); + my $about_me_link = + &Apache::loncommon::aboutmewrapper($plainname, + $docslog{$id}{'exe_uname'}, + $docslog{$id}{'exe_udom'}); + my $send_msg_link=''; + if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'}) + || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) { + $send_msg_link ='
'. + &Apache::loncommon::messagewrapper(&mt('Send message'), + $docslog{$id}{'exe_uname'}, + $docslog{$id}{'exe_udom'}); + } + $r->print(&Apache::loncommon::start_data_table_row()); + $r->print(''.$time.' + '.$about_me_link. + '
'.$docslog{$id}{'exe_uname'}. + ':'.$docslog{$id}{'exe_udom'}.''. + $send_msg_link.''. + $docslog{$id}{'logentry'}{'folder'}.''); +# Before + for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { + my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; + my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; + if ($oldname ne $newname) { + $r->print(&LONCAPA::map::qtescape($oldname)); + } + } + $r->print(''); +# After + $r->print(''); + + for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { + my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; + my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; + if ($oldname ne $newname) { + $r->print(&LONCAPA::map::qtescape($newname)); + } + } + $r->print(''); + if ($docslog{$id}{'logentry'}{'parameter_res'}) { + $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':'); + } +# End + $r->print(''.&Apache::loncommon::end_data_table_row()); + $shown++; + if (!($env{'form.show'} eq &mt('all') + || $shown<=$env{'form.show'})) { last; } } - return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp'); + $r->print(&Apache::loncommon::end_data_table()); + $r->print(&Apache::loncommon::end_page()); } sub editor { @@ -985,19 +1186,20 @@ sub editor { } ($errtext,$fatal)= &mapread($coursenum,$coursedom,$folder.'.'.$container); - if ($#Apache::lonratedt::order<1) { - my $idx=&Apache::lonratedt::getresidx(); + if ($#LONCAPA::map::order<1) { + my $idx=&LONCAPA::map::getresidx(); if ($idx<=0) { $idx=1; } - $Apache::lonratedt::order[0]=$idx; - $Apache::lonratedt::resources[$idx]=''; + $LONCAPA::map::order[0]=$idx; + $LONCAPA::map::resources[$idx]=''; } if (defined($env{'form.markcopy'})) { # Mark for copying - my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]); + my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]); $env{'form.markedcopy_title'}=$title; $env{'form.markedcopy_url'}=$url; } - $r->print(&breadcrumbs($folder)); + my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain)=&breadcrumbs($folder); + $r->print($breadcrumbtrail); if ($fatal) { $r->print('

'.$errtext.'

'); } else { @@ -1006,68 +1208,79 @@ sub editor { # ---------------- if they are for this folder and user allowed to make changes if (($allowed) && ($env{'form.folder'} eq $folder)) { # set parameters and change order - if (defined($env{'form.setparms'})) { + &snapshotbefore(); + if ($env{'form.changeparms'}) { my $idx=$env{'form.setparms'}; # set parameters if ($env{'form.randpick_'.$idx}) { - &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos'); + &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos'); + &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx}); } else { - &Apache::lonratedt::delparameter($idx,'parameter_randompick'); + &LONCAPA::map::delparameter($idx,'parameter_randompick'); + &remember_parms($idx,'randompick','del'); } if ($env{'form.hidprs_'.$idx}) { - &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno'); - } else { - &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource'); - } + &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno'); + &remember_parms($idx,'hiddenresource','set',$env{'form.hidprs_'.$idx}); + } else { + &LONCAPA::map::delparameter($idx,'parameter_hiddenresource'); + &remember_parms($idx,'hiddenresource','del'); + } if ($env{'form.encprs_'.$idx}) { - &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno'); - } else { - &Apache::lonratedt::delparameter($idx,'parameter_encrypturl'); + &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno'); + &remember_parms($idx,'encrypturl','set',$env{'form.encprs_'.$idx}); + } else { + &LONCAPA::map::delparameter($idx,'parameter_encrypturl'); + &remember_parms($idx,'encrypturl','del'); + } +# store the changed version + ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); + if ($fatal) { + $r->print('

'.$errtext.'

'); + return; } + } - if ($env{'form.newpos'}) { + if ($env{'form.newpos'}) { # change order - - my $newpos=$env{'form.newpos'}-1; - my $currentpos=$env{'form.currentpos'}-1; - my $i; - my @neworder=(); - if ($newpos>$currentpos) { + my $newpos=$env{'form.newpos'}-1; + my $currentpos=$env{'form.currentpos'}-1; + my $i; + my @neworder=(); + if ($newpos>$currentpos) { # moving stuff up - for ($i=0;$i<$currentpos;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i]; - } - for ($i=$currentpos;$i<$newpos;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i+1]; - } - $neworder[$newpos]=$Apache::lonratedt::order[$currentpos]; - for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i]; - } - } else { + for ($i=0;$i<$currentpos;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i]; + } + for ($i=$currentpos;$i<$newpos;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i+1]; + } + $neworder[$newpos]=$LONCAPA::map::order[$currentpos]; + for ($i=$newpos+1;$i<=$#LONCAPA::map::order;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i]; + } + } else { # moving stuff down - for ($i=0;$i<$newpos;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i]; - } - $neworder[$newpos]=$Apache::lonratedt::order[$currentpos]; - for ($i=$newpos+1;$i<$currentpos+1;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i-1]; - } - for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) { - $neworder[$i]=$Apache::lonratedt::order[$i]; - } + for ($i=0;$i<$newpos;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i]; + } + $neworder[$newpos]=$LONCAPA::map::order[$currentpos]; + for ($i=$newpos+1;$i<$currentpos+1;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i-1]; + } + for ($i=$currentpos+1;$i<=$#LONCAPA::map::order;$i++) { + $neworder[$i]=$LONCAPA::map::order[$i]; } - @Apache::lonratedt::order=@neworder; } + @LONCAPA::map::order=@neworder; # store the changed version - ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); if ($fatal) { $r->print('

'.$errtext.'

'); return; } - } + if ($env{'form.pastemarked'}) { # paste resource to end of list my $url=$env{'form.markedcopy_url'}; @@ -1080,7 +1293,7 @@ sub editor { my $newurl=$1.$newid.'.'.$2; my $storefn=$newurl; $storefn=~s/^\/\w+\/\w+\/\w+\///; - &Apache::loncreatecourse::writefile + &Apache::lonclonecourse::writefile ($env{'request.course.id'},$storefn, &Apache::lonnet::getfile($url)); $url=$newurl; @@ -1092,10 +1305,10 @@ sub editor { if ($url=~/^http\:\/\//) { $ext='true'; } $url=~s/\:/\:/g; # Now insert the URL at the bottom - my $newidx=&Apache::lonratedt::getresidx($url); - $Apache::lonratedt::resources[$newidx]= + my $newidx=&LONCAPA::map::getresidx($url); + $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res'; - $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx; + $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx; # Store the result ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); if ($fatal) { @@ -1108,55 +1321,54 @@ sub editor { if ($env{'form.cmd'}) { my ($cmd,$idx)=split(/\_/,$env{'form.cmd'}); if ($cmd eq 'del') { - my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]); + my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]); if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) { &Apache::lonnet::removeuploadedurl($url); } else { - &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); + &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); } - for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) { - $Apache::lonratedt::order[$i]= - $Apache::lonratedt::order[$i+1]; + for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) { + $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1]; } - $#Apache::lonratedt::order--; + $#LONCAPA::map::order--; } elsif ($cmd eq 'cut') { - my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]); - &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); - for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) { - $Apache::lonratedt::order[$i]= - $Apache::lonratedt::order[$i+1]; + my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]); + &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); + for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) { + $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1]; } - $#Apache::lonratedt::order--; + $#LONCAPA::map::order--; } elsif ($cmd eq 'up') { - if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) { - my $i=$Apache::lonratedt::order[$idx-1]; - $Apache::lonratedt::order[$idx-1]= - $Apache::lonratedt::order[$idx]; - $Apache::lonratedt::order[$idx]=$i; + if (($idx) && (defined($LONCAPA::map::order[$idx-1]))) { + my $i=$LONCAPA::map::order[$idx-1]; + $LONCAPA::map::order[$idx-1] = $LONCAPA::map::order[$idx]; + $LONCAPA::map::order[$idx] = $i; } } elsif ($cmd eq 'down') { - if (defined($Apache::lonratedt::order[$idx+1])) { - my $i=$Apache::lonratedt::order[$idx+1]; - $Apache::lonratedt::order[$idx+1]= - $Apache::lonratedt::order[$idx]; - $Apache::lonratedt::order[$idx]=$i; + if (defined($LONCAPA::map::order[$idx+1])) { + my $i=$LONCAPA::map::order[$idx+1]; + $LONCAPA::map::order[$idx+1] = $LONCAPA::map::order[$idx]; + $LONCAPA::map::order[$idx] = $i; } } elsif ($cmd eq 'rename') { - my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]; + my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]; my ($rtitle,@rrest)=split(/\:/, - $Apache::lonratedt::resources[ - $Apache::lonratedt::order[$idx]]); + $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]); my $comment= &HTML::Entities::decode($env{'form.title'}); $comment=~s/\/\>\;/g; $comment=~s/\:/\:/g; if ($comment=~/\S/) { - $Apache::lonratedt::resources[ - $Apache::lonratedt::order[$idx]]= - $comment.':'.join(':',@rrest); + $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]= + $comment.':'.join(':',@rrest); } +# Devalidate title cache + my $renamed_url=$rrest[0]; +# Has the :-escaping + $renamed_url=~s/\&colon\;/\:/g; + &Apache::lonnet::devalidate_title_cache($renamed_url); } # Store the changed version ($errtext,$fatal)=&storemap($coursenum,$coursedom, @@ -1169,6 +1381,7 @@ sub editor { # Group import/search if ($env{'form.importdetail'}) { my @imports; +# &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'}); foreach (split(/\&/,$env{'form.importdetail'})) { if (defined($_)) { my ($name,$url)=split(/\=/,$_); @@ -1178,7 +1391,7 @@ sub editor { } } # Store the changed version - ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder, + ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder, $container,'londocs',@imports); if ($fatal) { $r->print('

'.$errtext.'

'); @@ -1190,10 +1403,9 @@ sub editor { if ($env{'form.importmap'}=~/\w/) { foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) { my ($title,$url,$ext,$type)=split(/\:/,$_); - my $idx=&Apache::lonratedt::getresidx($url); - $Apache::lonratedt::resources[$idx]=$_; - $Apache::lonratedt::order - [$#Apache::lonratedt::order+1]=$idx; + my $idx=&LONCAPA::map::getresidx($url); + $LONCAPA::map::resources[$idx]=$_; + $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx; } # Store the changed version ($errtext,$fatal)=&storemap($coursenum,$coursedom, @@ -1206,16 +1418,27 @@ sub editor { $r->print('

'.&mt('No map selected.').'

'); } } + &log_differences($plain); } # ---------------------------------------------------------------- End commands # ---------------------------------------------------------------- Print screen my $idx=0; my $shown=0; + if (($ishidden) || ($isencrypted) || ($randompick>=0)) { + $r->print('

'.&mt('Parameters').':

'); + } + 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.').'

'); + } $r->print(''); - foreach (@Apache::lonratedt::order) { - my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]); - $name=&Apache::lonratsrv::qtescape($name); - $url=&Apache::lonratsrv::qtescape($url); + foreach (@LONCAPA::map::order) { + my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]); + $name=&LONCAPA::map::qtescape($name); + $url=&LONCAPA::map::qtescape($url); unless ($name) { $name=(split(/\//,$url))[-1]; } unless ($name) { $idx++; next; } $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum)); @@ -1273,9 +1496,9 @@ sub process_file_upload { } ($errtext,$fatal)= &mapread($coursenum,$coursedom,$folder.'.'.$container); - if ($#Apache::lonratedt::order<1) { - $Apache::lonratedt::order[0]=1; - $Apache::lonratedt::resources[1]=''; + if ($#LONCAPA::map::order<1) { + $LONCAPA::map::order[0]=1; + $LONCAPA::map::resources[1]=''; } if ($fatal) { return 'failed'; @@ -1291,7 +1514,7 @@ sub process_file_upload { } # this is for a course, not a user, so set coursedoc flag # probably the only place in the system where this should be "1" - my $newidx=&Apache::lonratedt::getresidx(); + my $newidx=&LONCAPA::map::getresidx(); $destination .= $newidx; my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination, $parseaction,$allfiles, @@ -1308,9 +1531,9 @@ sub process_file_upload { $env{'user.domain'}.'___&&&___'.$comment; } - $Apache::lonratedt::resources[$newidx]= - $comment.':'.$url.':'.$ext.':normal:res'; - $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx; + $LONCAPA::map::resources[$newidx]= + $comment.':'.$url.':'.$ext.':normal:res'; + $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx; ($errtext,$fatal)=&storemap($coursenum,$coursedom, $folder.'.'.$container); if ($fatal) { @@ -1391,7 +1614,7 @@ sub entryline { my $renametitle=$title; my $foldertitle=$title; my $pagetitle=$title; - my $orderidx=$Apache::lonratedt::order[$index]; + my $orderidx=$LONCAPA::map::order[$index]; if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) { $foldertitle=&Apache::lontexconvert::msgtexconverted($4); $renametitle=$4; @@ -1427,17 +1650,17 @@ sub entryline { my $incindex=$index+1; my $selectbox=''; if (($folder!~/^supplemental/) && - ($#Apache::lonratedt::order>0) && + ($#LONCAPA::map::order>0) && ((split(/\:/, - $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1] + $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1] ne '') && ((split(/\:/, - $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1] + $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1] ne '')) { $selectbox= ''. ' +
@@ -1509,6 +1733,7 @@ ENDCOPY + '. - ""; + ""; if (($allowed) && ($folder!~/^supplemental/)) { my %lt=&Apache::lonlocal::texthash( 'hd' => 'Hidden', 'ec' => 'URL hidden'); my $enctext= - ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':''); + ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':''); my $hidtext= - ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':''); + ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':''); $line.=(< - + + ENDPARMS } @@ -1764,9 +2001,10 @@ sub list_symbs { # sub verifycontent { my ($r) = @_; + my $type = &Apache::loncommon::course_type(); my $loaderror=&Apache::lonnet::overloaderror($r); if ($loaderror) { return $loaderror; } - $r->print(&Apache::loncommon::start_page('Verify Course Documents')); + $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents')); $hashtied=0; undef %alreadyseen; %alreadyseen=(); @@ -1775,7 +2013,7 @@ sub verifycontent { if ($hash{$_}=~/\.(page|sequence)$/) { if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) { $r->print('
'. - &mt('The following sequence or page is included more than once in your course: '). + &mt('The following sequence or page is included more than once in your '.$type.': '). &unescape($hash{$_}).'
'. &mt('Note that grading records for problems included in this sequence or folder will overlap.
')); } @@ -1800,7 +2038,8 @@ sub devalidateversioncache { sub checkversions { my ($r) = @_; - $r->print(&Apache::loncommon::start_page('Check Course Document Versions')); + my $type = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page("Check $type Document Versions")); my $header=''; my $startsel=''; my $monthsel=''; @@ -1861,7 +2100,7 @@ sub checkversions { &changewarning($r,''); if ($env{'form.timerange'} eq 'all') { # show all documents - $header=&mt('All Documents in Course'); + $header=&mt('All Documents in '.$type); $allsel=1; foreach (keys %hash) { if ($_=~/^ids\_(\/res\/.+)$/) { @@ -1906,7 +2145,7 @@ sub checkversions { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); my %lt=&Apache::lonlocal::texthash - ('st' => 'Version changes since start of Course', + ('st' => 'Version changes since start of '.$type, 'lm' => 'Version changes since last Month', 'lw' => 'Version changes since last Week', 'sy' => 'Version changes since Yesterday', @@ -1915,9 +2154,9 @@ sub checkversions { 'fi' => 'File', 'md' => 'Modification Date', 'mr' => 'Most recently published Version', - 've' => 'Version used in Course', - 'vu' => 'Set Version to be used in Course', -'sv' => 'Set Versions to be used in Course according to Selections below', + 've' => 'Version used in '.$type, + 'vu' => 'Set Version to be used in '.$type, +'sv' => 'Set Versions to be used in '.$type.' according to Selections below', 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)', 'sc' => 'Set all Resource Versions to current Version (Fix Versions)', 'di' => 'Differences'); @@ -1964,7 +2203,7 @@ ENDHEADERS '
'. - '
@@ -1579,7 +1804,11 @@ END } elsif ($url=~m|^/ext/|) { $url='/adm/wrapper'.$url; } - $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); + if (&Apache::lonnet::symbverify($symb,$url)) { + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); + } else { + $url=''; + } if ($container eq 'page') { my $symb=$env{'form.pagesymb'}; @@ -1592,11 +1821,18 @@ END my $foldername=&escape($foldertitle); my $folderpath=$env{'form.folderpath'}; if ($folderpath) { $folderpath.='&' }; - $folderpath.=$folderarg.'&'.$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] + .':'.((&LONCAPA::map::getparameter($orderidx, + 'parameter_hiddenresource'))[0]=~/^yes$/i) + .':'.((&LONCAPA::map::getparameter($orderidx, + 'parameter_encrypturl'))[0]=~/^yes$/i); $url.='folderpath='.&escape($folderpath).$cpinfo; $parameterset=''.&mt('Store').''; @@ -1622,20 +1858,21 @@ END } $line.='$title".($url?"":'').$title. + ($url?'':' '.&mt('(re-initialize course to access)').'')." -$parametersetMost Recent: '. ''.$currentversion.''. 'In Course: '. + 'In '.$type.': '. ''); # Used in course my $usedversion=$hash{'version_'.$linkurl}; @@ -2077,6 +2316,7 @@ sub changewarning { } $url='/adm/coursedocs?'.$pathvar.'='.$path; } + my $course_type = &Apache::loncommon::course_type(); if (!defined($message)) { $message='Changes will become active for your current session after [_1], or the next time you log in.'; } @@ -2087,7 +2327,7 @@ sub changewarning { '" />

'. &mt($message,' '). + &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />'). $help{'Caching'}.'

'."\n\n"); } @@ -2097,6 +2337,7 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; + my $type = &Apache::loncommon::course_type(); # --------------------------------------------- Initialize help topics for this foreach ('Adding_Course_Doc','Main_Course_Documents', @@ -2118,6 +2359,7 @@ sub handler { 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages'); $help{'My Personal Info'} = &Apache::loncommon::help_open_topic( 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages'); + $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files'); $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); # does this user have privileges to modify docs @@ -2127,6 +2369,8 @@ sub handler { &verifycontent($r); } elsif ($allowed && $env{'form.listsymbs'}) { &list_symbs($r); + } elsif ($allowed && $env{'form.docslog'}) { + &docs_change_log($r); } elsif ($allowed && $env{'form.versions'}) { &checkversions($r); } elsif ($allowed && $env{'form.dumpcourse'}) { @@ -2165,7 +2409,7 @@ sub handler { $showdoc='/'.$1; } unless ($showdoc) { # got called from remote - if (($env{'form.folder'}=~/^default_/) || + if (($env{'form.folder'}=~/^(?:group|default)_/) || ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) { $forcestandard = 1; } @@ -2186,8 +2430,7 @@ sub handler { # get personal data my $uname=$env{'user.name'}; my $udom=$env{'user.domain'}; - my $plainname=&escape( - &Apache::loncommon::plainname($uname,$udom)); + my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom)); # graphics settings @@ -2198,9 +2441,9 @@ sub handler { } # -------------------------------------------------------------------- Body tag $script = ''; - $r->print(&Apache::loncommon::start_page('Course Documents', $script, + $r->print(&Apache::loncommon::start_page("$type Documents", $script, {'force_register' => $showdoc,}). - &Apache::loncommon::help_open_menu('','','','',273,'RAT')); + &Apache::loncommon::help_open_menu('','',273,'RAT')); my %allfiles = (); my %codebase = (); @@ -2287,8 +2530,8 @@ sub handler { unless ($showdoc || $upload_result eq 'phasetwo') { # ----------------------------------------------------------------------------- my %lt=&Apache::lonlocal::texthash( - 'uplm' => 'Upload a new main course document', - 'upls' => 'Upload a new supplemental course document', + 'uplm' => 'Upload a new main '.lc($type).' document', + 'upls' => 'Upload a new supplemental '.lc($type).' document', 'impp' => 'Import a document', 'pubd' => 'Published documents', 'copm' => 'All documents out of a published map into this folder', @@ -2296,6 +2539,7 @@ sub handler { 'upld' => 'Upload Document', 'srch' => 'Search', 'impo' => 'Import', + 'book' => 'Import Bookmarks', 'selm' => 'Select Map', 'load' => 'Load Map', 'reco' => 'Recover Deleted Resources', @@ -2310,6 +2554,7 @@ sub handler { 'scuf' => 'Score Upload Form', 'bull' => 'Bulletin Board', 'mypi' => 'My Personal Info', + 'grpo' => 'Group Files', 'abou' => 'About User', 'imsf' => 'Import IMS package', 'file' => 'File', @@ -2325,6 +2570,7 @@ sub handler { 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', 'ls' => 'List Symbs', + 'sl' => 'Show Log' ); my $folderpath=$env{'form.folderpath'}; @@ -2332,7 +2578,7 @@ sub handler { if ($env{'form.folder'} eq '' || $env{'form.folder'} eq 'supplemental') { $folderpath='default&'. - &escape(&mt('Main Course Documents')); + &escape(&mt('Main '.$type.' Documents')); } } unless ($env{'form.pagepath'}) { @@ -2361,11 +2607,13 @@ $dumpbut $exportbut
+ +
ENDCOURSEVERIFY $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc', - &mt('Editing the Table of Contents for your Course'))); + &mt('Editing the Table of Contents for your '.$type))); } # --------------------------------------------------------- Standard documents $r->print(''); @@ -2376,7 +2624,7 @@ ENDCOURSEVERIFY my $folder=$env{'form.folder'}; if ($folder eq '' || $folder eq 'supplemental') { $folder='default'; - $env{'form.folderpath'}='default&'.&escape(&mt('Main Course Documents')); + $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents')); } my $postexec=''; if ($folder eq 'default') { @@ -2432,11 +2680,14 @@ $uploadtag $lt{'pubd'}
$uploadtag - + +
- + $help{'Importing_LON-CAPA_Resource'} +
+


$lt{'copm'}
@@ -2449,7 +2700,7 @@ $help{'Load_Map'}
- + ENDFORM unless ($env{'form.pagepath'}) { @@ -2568,6 +2819,15 @@ $uploadtag onClick="javascript:makeabout();" /> +
+$uploadtag + + + +$help{'Group Files'} + + ENDFORM } if ($env{'form.pagepath'}) { @@ -2607,7 +2867,7 @@ ENDBLOCK if ($folder =~ /^supplemental$/ && $env{'form.folderpath'} =~ /^default\&/) { $env{'form.folderpath'}='supplemental&'. - &escape(&mt('Supplemental Course Documents')); + &escape(&mt('Supplemental '.$type.' Documents')); } &editor($r,$coursenum,$coursedom,$folder,$allowed); if ($allowed) { @@ -2712,7 +2972,7 @@ sub editing_js { function makenewfolder(targetform,folderseq) { var foldername=prompt('Name of New Folder','New Folder'); if (foldername) { - targetform.importdetail.value=foldername+"="+folderseq; + targetform.importdetail.value=escape(foldername)+"="+folderseq; targetform.submit(); } } @@ -2720,7 +2980,7 @@ function makenewfolder(targetform,folder function makenewpage(targetform,folderseq) { var pagename=prompt('Name of New Page','New Page'); if (pagename) { - targetform.importdetail.value=pagename+"="+folderseq; + targetform.importdetail.value=escape(pagename)+"="+folderseq; targetform.submit(); } } @@ -2734,7 +2994,7 @@ function makeexamupload() { var title=prompt('Listed Title for the Uploaded Score'); if (title) { this.document.forms.newexamupload.importdetail.value= - title+'=/res/lib/templates/examupload.problem'; + escape(title)+'=/res/lib/templates/examupload.problem'; this.document.forms.newexamupload.submit(); } } @@ -2743,7 +3003,7 @@ function makesmppage() { var title=prompt('Listed Title for the Page'); if (title) { this.document.forms.newsmppg.importdetail.value= - title+'=/adm/$udom/$uname/$now/smppg'; + escape(title)+'=/adm/$udom/$uname/$now/smppg'; this.document.forms.newsmppg.submit(); } } @@ -2752,7 +3012,7 @@ function makesmpproblem() { var title=prompt('Listed Title for the Problem'); if (title) { this.document.forms.newsmpproblem.importdetail.value= - title+'=/res/lib/templates/simpleproblem.problem'; + escape(title)+'=/res/lib/templates/simpleproblem.problem'; this.document.forms.newsmpproblem.submit(); } } @@ -2761,7 +3021,7 @@ function makedropbox() { var title=prompt('Listed Title for the Drop Box'); if (title) { this.document.forms.newdropbox.importdetail.value= - title+'=/res/lib/templates/DropBox.problem'; + escape(title)+'=/res/lib/templates/DropBox.problem'; this.document.forms.newdropbox.submit(); } } @@ -2770,26 +3030,26 @@ function makebulboard() { var title=prompt('Listed Title for the Bulletin Board'); if (title) { this.document.forms.newbul.importdetail.value= - title+'=/adm/$udom/$uname/$now/bulletinboard'; + escape(title)+'=/adm/$udom/$uname/$now/bulletinboard'; this.document.forms.newbul.submit(); } } function makeabout() { - var user=prompt("Enter user\@domain for User's 'About Me' Page"); + var user=prompt("Enter user:domain for User's 'About Me' Page"); if (user) { var comp=new Array(); - comp=user.split('\@'); + comp=user.split(':'); if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) { if ((comp[0]) && (comp[1])) { this.document.forms.newaboutsomeone.importdetail.value= - 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme'; + 'About '+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme'; this.document.forms.newaboutsomeone.submit(); } else { - alert("Not a valid user\@domain"); + alert("Not a valid user:domain"); } } else { - alert("Please enter both user and domain in the format user\@domain"); + alert("Please enter both user and domain in the format user:domain"); } } }