--- loncom/interface/londocs.pm 2006/11/02 21:06:06 1.245 +++ loncom/interface/londocs.pm 2006/11/13 22:32:56 1.252 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.245 2006/11/02 21:06:06 albertel Exp $ +# $Id: londocs.pm,v 1.252 2006/11/13 22:32:56 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,7 +35,6 @@ use Apache::lonnet; use Apache::loncommon; use LONCAPA::map(); use Apache::lonratedt(); -use Apache::lonratsrv; use Apache::lonxml; use Apache::lonclonecourse; use Apache::lonnavmaps; @@ -955,6 +954,7 @@ sub breadcrumbs { } my $folderpath; my $cpinfo=''; + my $plain=''; if ($env{'form.markedcopy_url'}) { $cpinfo='&markedcopy_url='. &escape($env{'form.markedcopy_url'}). @@ -987,9 +987,186 @@ sub breadcrumbs { 'text'=>''. $name.'' }); + $plain.=$name.' > '; } + $plain=~s/\>\;\s*$//; return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', - 'LC_docs_path'),$randompick,$ishidden,$isencrypted); + '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 $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; } + } + $r->print(&Apache::loncommon::end_data_table()); + $r->print(&Apache::loncommon::end_page()); } sub editor { @@ -1014,7 +1191,7 @@ sub editor { $env{'form.markedcopy_title'}=$title; $env{'form.markedcopy_url'}=$url; } - my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted)=&breadcrumbs($folder); + my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain)=&breadcrumbs($folder); $r->print($breadcrumbtrail); if ($fatal) { $r->print('

'.$errtext.'

'); @@ -1024,68 +1201,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}) { &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos'); + &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx}); } else { &LONCAPA::map::delparameter($idx,'parameter_randompick'); + &remember_parms($idx,'randompick','del'); } if ($env{'form.hidprs_'.$idx}) { &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno'); - } else { + &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}) { &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno'); - } else { + &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]=$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 { + 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]=$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]; - } + 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]; } - @LONCAPA::map::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'}; @@ -1196,7 +1384,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.'

'); @@ -1223,6 +1411,7 @@ sub editor { $r->print('

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

'); } } + &log_differences($plain); } # ---------------------------------------------------------------- End commands # ---------------------------------------------------------------- Print screen @@ -1241,8 +1430,8 @@ sub editor { $r->print(''); foreach (@LONCAPA::map::order) { my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]); - $name=&Apache::lonratsrv::qtescape($name); - $url=&Apache::lonratsrv::qtescape($url); + $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)); @@ -1505,6 +1694,7 @@ ENDCOPY +
@@ -1536,6 +1726,7 @@ ENDCOPY + + + ENDPARMS } @@ -2170,6 +2361,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'}) { @@ -2368,6 +2561,7 @@ sub handler { 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', 'ls' => 'List Symbs', + 'sl' => 'Show Log' ); my $folderpath=$env{'form.folderpath'}; @@ -2404,6 +2598,8 @@ $dumpbut $exportbut
@@ -1633,7 +1824,7 @@ END 'parameter_encrypturl'))[0]=~/^yes$/i); $url.='folderpath='.&escape($folderpath).$cpinfo; $parameterset=' - $parameterset + +
ENDCOURSEVERIFY