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

www lon-capa-cvs@mail.lon-capa.org
Sat, 15 Apr 2006 21:12:58 -0000


This is a MIME encoded message

--www1145135578
Content-Type: text/plain

www		Sat Apr 15 17:12:58 2006 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Working on parameter log
  
  
--www1145135578
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20060415171258.txt"

Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.289 loncom/interface/lonparmset.pm:1.290
--- loncom/interface/lonparmset.pm:1.289	Fri Apr 14 22:22:33 2006
+++ loncom/interface/lonparmset.pm	Sat Apr 15 17:12:56 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.289 2006/04/15 02:22:33 www Exp $
+# $Id: lonparmset.pm,v 1.290 2006/04/15 21:12:56 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -397,7 +397,10 @@
 {
     my $logid;
     sub log_parmset {
-	my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
+	my ($storehash,$delflag,$uname,$udom)=@_;
+        my $logentry=join(',',map {
+	    &Apache::lonnet::escape($_).'=>'.&Apache::lonnet::escape($$storehash{$_});
+	} keys %$storehash);
 	$logid++;
 	my $id=time().'00000'.$$.'00000'.$logid;
 	&Apache::lonnet::put('nohist_parameterlog',
@@ -406,15 +409,10 @@
 				 $id.'_exe_udom'  => $env{'user.domain'},
 				 $id.'_exe_time'  => time(),
 				 $id.'_exe_ip'    => $ENV{'REMOTE_ADDR'},
-				 $id.'_symb'      => $symb,
-				 $id.'_spnam'     => $spnam,
-				 $id.'_snum'      => $snum,
-				 $id.'_nval'      => $nval,
-				 $id.'_ntype'     => $ntype,
+				 $id.'_delflag'   => $delflag,
+                                 $id.'_logentry'  => $logentry,
 				 $id.'_uname'     => $uname,
 				 $id.'_udom'      => $udom,
-				 $id.'_csec'      => $csec,
-				 $id.'_cgroup'    => $cgroup
 			     },
 			     $env{'course.'.$env{'request.course.id'}.'.domain'},
 			     $env{'course.'.$env{'request.course.id'}.'.num'}
@@ -425,7 +423,6 @@
 sub storeparm_by_symb_inner {
 # ---------------------------------------------------------- Get symb, map, etc
     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
-    &log_parmset(@_);
 # ---------------------------------------------------------- Construct prefixes
     $spnam=~s/\_([^\_]+)$/\.$1/;
     my $map=(&Apache::lonnet::decode_symb($symb))[0];    
@@ -479,9 +476,11 @@
 	if ($delete) {
 	    $reply=&Apache::lonnet::del
 		('resourcedata',[keys(%storecontent)],$cdom,$cnum);
+            &log_parmset(\%storecontent,1);
 	} else {
 	    $reply=&Apache::lonnet::cput
 		('resourcedata',\%storecontent,$cdom,$cnum);
+	    &log_parmset(\%storecontent);
 	}
 	&Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
     } else {
@@ -502,9 +501,11 @@
 	if ($delete) {
 	    $reply=&Apache::lonnet::del
 		('resourcedata',[keys(%storecontent)],$udom,$uname);
+	    &log_parmset(\%storecontent,1,$uname,$udom);
 	} else {
 	    $reply=&Apache::lonnet::cput
 		('resourcedata',\%storecontent,$udom,$uname);
+	    &log_parmset(\%storecontent,0,$uname,$udom);
 	}
 	&Apache::lonnet::devalidateuserresdata($uname,$udom);
     }
@@ -2421,6 +2422,7 @@
 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
 								 $tkey.'.type' => $typeof},
 						 $tudom,$tuname) eq 'ok') {
+			    &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
 			    $r->print('<br />'.&mt('Stored modified parameter for').' '.
 				      &Apache::loncommon::plainname($tuname,$tudom));
 			} else {
@@ -2436,6 +2438,7 @@
 	    } elsif ($cmd eq 'del') {
 		if ($tuname) {
 		    if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
+			    &log_parmset({$tkey=>''},1,$tuname,$tudom);
 			$r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 		    } else {
 			$r->print('<h2><font color="red">'.
@@ -2453,6 +2456,7 @@
 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
 								 $tkey.'.type' => $typeof},
 						 $tudom,$tuname) eq 'ok') {
+			    &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
 			    $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 			} else {
 			    $r->print('<h2><font color="red">'.
@@ -2473,6 +2477,8 @@
     my $putentries=$#newdatakeys+1;
     if ($delentries) {
 	if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
+	    my %loghash=map { $_ => '' } @deldata;
+	    &log_parmset(\%loghash,1);
 	    $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
 	} else {
 	    $r->print('<h2><font color="red">'.
@@ -2482,6 +2488,7 @@
     }
     if ($putentries) {
 	if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
+			    &log_parmset(\%newdata,0);
 	    $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
 	} else {
 	    $r->print('<h2><font color="red">'.
@@ -3316,76 +3323,39 @@
     return;
 }
 
+sub components {
+    my ($key,$uname,$udom)=@_;
+    my $typeflag=0;
+    if ($key=~/\.type$/) {
+	$key=~s/\.type$//;
+        $typeflag=1;
+    }
+    my ($middle,$part,$name)=($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
+    my $section=&mt('All Students');
+    if ($middle=~/^\[(.*)\]/) {
+	my $issection=$1;
+	if ($uname) {
+	    $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
+	} else {
+	    $section=&mt('Group/Section').': '.$issection;
+	}
+	$middle=~s/^\[(.*)\]//;
+    }
+    $middle=~s/\.+$//;
+    $middle=~s/^\.+//;
+    my $realm='<font color="red">'.&mt('All Resources').'</font>';
+    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
+	$realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
+    } elsif ($middle) {
+	my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
+	$realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
+    }
+    return ($realm,$section,$name,$part,$typeflag);
+}
+
 sub parm_change_log {
     my ($r)=@_;
     &startpage($r);
-
-    my @ids=();
-    my %symbp=();
-    my %mapp=();
-    my %typep=();
-    my %keyp=();
-    my %uris=();
-    my %maptitles=();
-
-# -------------------------------------------------------- Variable declaration
-
-    my %allmaps=();
-    my %alllevs=();
-
-    my $uname;
-    my $udom;
-    my $uhome;
-    my $csec;
-    my $cgroup;
-    my $grouplist;
-    my @usersgroups = ();
- 
-    my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
-
-    $alllevs{'Resource Level'}='full';
-    $alllevs{'Map/Folder Level'}='map';
-    $alllevs{'Course Level'}='general';
-
-    my %allparms;
-    my %allparts;
-    my %keyorder;
-# --------------------------------------------------------- Get all assessments
-    &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
-				\%mapp, \%symbp,\%maptitles,\%uris,
-				\%keyorder);
-
-    $mapp{'0.0'} = '';
-    $symbp{'0.0'} = '';
-
-    my %level=&Apache::lonlocal::texthash('parmlevel_14' => 'General Course',
-					  'parmlevel_13' => 'Map or Folder level in course',
-					  'parmlevel_12' => 'Resource default',
-					  'parmlevel_11' => 'Map default',
-					  'parmlevel_10' => 'Resource level in course',
-					  'parmlevel_9' => 'General for section',
-					  'parmlevel_8' => 'Map or Folder level for section',
-					  'parmlevel_7' => 'Resource level in section',
-					  'parmlevel_6' => 'General for group',
-					  'parmlevel_5' => 'Map or Folder level for group',
-					  'parmlevel_4' => 'Resource level in group',
-					  'parmlevel_3' => 'General for specific student',
-					  'parmlevel_2' => 'Map or Folder level for specific student',
-					  'parmlevel_1' => 'Resource level for specific student');
-
-#    $id.'_exe_uname' => $env{'user.name'},
-#    $id.'_exe_udom'  => $env{'user.domain'},
-#    $id.'_exe_time'  => time(),
-#    $id.'_exe_ip'    => $ENV{'REMOTE_ADDR'},
-#    $id.'_symb'      => $symb,
-#    $id.'_spnam'     => $spnam,
-#    $id.'_snum'      => $snum,
-#    $id.'_nval'      => $nval,
-#    $id.'_ntype'     => $ntype,
-#    $id.'_uname'     => $uname,
-#    $id.'_udom'      => $udom,
-#    $id.'_csec'      => $csec,
-#    $id.'_cgroup'    => $cgroup
     my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',
 				      $env{'course.'.$env{'request.course.id'}.'.domain'},
 				      $env{'course.'.$env{'request.course.id'}.'.num'});
@@ -3397,8 +3367,8 @@
     }
     $r->print('<table border="2">');
     foreach my $id (sort { $exetime{$a}<=>$exetime{$b} } (keys(%exetime))) {
-        my ($part,$name)=($parmlog{$id.'_spnam'}=~/^(.*)[\_\.]([^\_\.]+)$/);
-        my $spnam=$part.'_'.$name;
+        my @changes=split(/\,/,$parmlog{$id.'_logentry'});
+	my $count=$#changes+1;
 	my $time =
 	    &Apache::lonlocal::locallocaltime($parmlog{$id.'_exe_time'});
 	my $plainname = 
@@ -3417,28 +3387,34 @@
 						   $parmlog{$id.'_exe_uname'},
 						   $parmlog{$id.'_exe_udom'});
 	}
-	my $value;
-	if ($parmlog{$id.'_nval'}) {
-	    if (&isdateparm($spnam)) {
-		$value = 
-		    &Apache::lonlocal::locallocaltime($parmlog{$id.'_nval'});
+	$r->print('<tr><td rowspan="'.$count.'">'.$time.'</td>
+                       <td rowspan="'.$count.'">'.$about_me_link.
+		  '<br /><tt>'.$parmlog{$id.'_exe_uname'}.
+			          ':'.$parmlog{$id.'_exe_udom'}.'</tt>'.
+		  $send_msg_link.'</td>');
+	my $makenewrow=0;
+	my %istype=();
+	foreach my $changed (sort @changes) {
+            my ($key,$value)=split(/\=\>/,&Apache::lonnet::unescape($changed));
+            my ($realm,$section,$parmname,$part,$typeflag)=
+		&components($key,$parmlog{$id.'_uname'},$parmlog{$id.'_udom'});
+	    if ($typeflag) { $istype{$parmname}=$value; }
+	    if ($makenewrow) { $r->print('<tr>'); } else { $makenewrow=1; }
+	    $r->print('<td>'.$realm.'</td><td>'.$section.'</td><td>'.
+		      &mt('Part: [_1]',$part).'</td><td>');
+	    if ($parmlog{$id.'_deleteflag'}) {
+		$r->print(&mt('Deleted'));
 	    } else {
-		$value = $parmlog{$id.'_nval'};
+		if ($typeflag) {
+		    $r->print(&mt('Type: [_1]',$value));
+		} elsif (&isdateparm($istype{$parmname})) {
+		    $r->print(&Apache::lonlocal::locallocaltime($value));
+		} else {
+		    $r->print($value);
+		}
 	    }
-	} else {
-	    $value = &mt('Deleted Parameter');
+	    $r->print('</td></tr>');
 	}
-	$r->print('<tr><td>'.$time.'</td>
-                       <td>'.$about_me_link.'<br />
-                            <tt>'.$parmlog{$id.'_exe_udom'}.'</tt><br />
-                            <tt>'.$parmlog{$id.'_exe_uname'}.
-			          ':'.$parmlog{$id.'_exe_udom'}.'</tt>'.
-			    $send_msg_link.'</td>
-                       <td>'.$level{'parmlevel_'.$parmlog{$id.'_snum'}}.'</td>
-                       <td>'.&mt($allparms{$name}).'<br /><tt>'.$name.'</tt></td>
-                       <td>'.($part?&mt('Part: [_1]',$part):&mt('All parts')).'</td>
-                       <td>'.$parmlog{$id.'_symb'}.'</td>
-                       <td>'.$value.'</td></tr>');
     }
     $r->print('</table>');
     $r->print(&Apache::loncommon::end_page());

--www1145135578--