[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

www lon-capa-cvs@mail.lon-capa.org
Sun, 12 Nov 2006 02:13:06 -0000


This is a MIME encoded message

--www1163297586
Content-Type: text/plain

www		Sat Nov 11 21:13:06 2006 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  Saving my work: DOCS change log
  
  
--www1163297586
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20061111211306.txt"

Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.246 loncom/interface/londocs.pm:1.247
--- loncom/interface/londocs.pm:1.246	Sat Nov 11 13:36:43 2006
+++ loncom/interface/londocs.pm	Sat Nov 11 21:13:05 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.246 2006/11/11 18:36:43 raeburn Exp $
+# $Id: londocs.pm,v 1.247 2006/11/12 02:13:05 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -991,6 +991,135 @@
 					       'LC_docs_path'),$randompick,$ishidden,$isencrypted);
 }
 
+sub log_docs {
+    return &Apache::lonnet::instructor_log('docslog',@_);
+}
+
+{
+    my @oldresources=();
+    my @oldorder=();
+    my $parmidx;
+    my %parmaction=();
+    my %parmvalue=();
+
+    sub snapshotbefore {
+        @oldresources=@Apache::lonratedt::resources;
+        @oldorder=@Apache::lonratedt::order;
+        $parmidx=undef;
+        %parmaction=();
+        %parmvalue=();
+    }
+
+    sub remember_parms {
+        my ($idx,$parameter,$action,$value)=@_;
+        $parmidx=$idx;
+        $parmaction{$parameter}=$action;
+        $parmvalue{$parameter}=$value;
+    }
+
+    sub log_differences {
+        my $r=shift;
+        my %storehash=('folder' => $env{'form.folder'});
+        if ($parmidx) {
+           $storehash{'parameter_idx'}=$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 ($#Apache::lonratedt::resources>$#oldresources) {
+           $maxidx=$#Apache::lonratedt::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];
+           }
+           if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
+              $storehash{'before_order_'.$idx}=$oldorder[$idx];
+              $storehash{'after_order_'.$idx}=$LONCAPA::map::order[$idx];
+              $storehash{'before_order_res_'.$idx}=$oldresources[$idx];
+              $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$idx];
+           }
+        }
+        &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('<form action="/adm/coursedocs" method="post" name="docslog">'.
+              '<input type="hidden" name="docslog" value="1" />');
+                                                                                                                            
+    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('<nobr>'.&mt('[_1] Records',$countselect).'</nobr>'.
+              '<input type="submit" value="'.&mt('Display').'" /></form>');
+    $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
+              '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
+              &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.
+              &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 ='<br />'.
+                &Apache::loncommon::messagewrapper(&mt('Send message'),
+                                                   $docslog{$id}{'exe_uname'},
+                                                   $docslog{$id}{'exe_udom'});
+        }
+        $r->print(&Apache::loncommon::start_data_table_row());
+        $r->print('<td>'.$time.'</td>
+                       <td>'.$about_me_link.
+                  '<br /><tt>'.$docslog{$id}{'exe_uname'}.
+                                  ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
+                  $send_msg_link.'</td>');
+
+        $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 {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
     my $errtext='';
@@ -1023,68 +1152,73 @@
 # ---------------- 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');
+ 		}
+	    }
 
-		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('<p><font color="red">'.$errtext.'</font></p>');
 		    return;
 		}
-		
 	    }
+		
 	    if ($env{'form.pastemarked'}) {
 # paste resource to end of list
                 my $url=$env{'form.markedcopy_url'};
@@ -1222,6 +1356,7 @@
                    $r->print('<p><font color="red">'.&mt('No map selected.').'</font></p>');
                }
            }
+           &log_differences($r);
        }
 # ---------------------------------------------------------------- End commands
 # ---------------------------------------------------------------- Print screen
@@ -1504,6 +1639,7 @@
 <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
 <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
 <input type="hidden" name="setparms" value="$orderidx" />
+<input type="hidden" name="changeparms" value="0" />
 <td><table border='0' cellspacing='2' cellpadding='0'>
 <tr><td bgcolor="#DDDDDD">
 <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
@@ -1535,6 +1671,7 @@
 <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
 <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
 <input type="hidden" name="setparms" value="$orderidx" />
+<input type="hidden" name="changeparms" value="0" />
 <td><table border='0' cellspacing='2' cellpadding='0'>
 <tr><td bgcolor="#DDDDDD">
 <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
@@ -1632,7 +1769,7 @@
                                               'parameter_encrypturl'))[0]=~/^yes$/i);
 	$url.='folderpath='.&escape($folderpath).$cpinfo;
 	$parameterset='<label>'.&mt('Randomly Pick: ').
-	    '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
+	    '<input type="text" size="4" onChange="this.form.changeparms.value=1;this.form.submit()" name="randpick_'.$orderidx.'" value="'.
 	    (&LONCAPA::map::getparameter($orderidx,
                                               'parameter_randompick'))[0].
                                               '" />'.
@@ -1671,9 +1808,9 @@
 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
 	$line.=(<<ENDPARMS);
 <td bgcolor="#BBBBFF"><font size='-2'>
-<nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
+<nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.changeparms.value=1;this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size='-2'>
-<nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
+<nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.changeparms.value=1;this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
 ENDPARMS
     }
@@ -2169,6 +2306,8 @@
       &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'}) {
@@ -2367,6 +2506,7 @@
 					 'vc' => 'Verify Content',
 					 'cv' => 'Check/Set Resource Versions',
 					 'ls' => 'List Symbs',
+                                         'sl' => 'Show Log'
 					  );
 
        my $folderpath=$env{'form.folderpath'};
@@ -2403,6 +2543,8 @@
 $exportbut
 </td><td bgcolor="#DDDDCC">
     <input type="submit" name="listsymbs" value="$lt{'ls'}" />
+</td><td bgcolor="#DDDDCC">
+    <input type="submit" name="docslog" value="$lt{'sl'}" />
 </td></tr></table>
 </form>
 ENDCOURSEVERIFY

--www1163297586--