--- loncom/interface/lonparmset.pm 2006/04/13 21:32:23 1.285 +++ loncom/interface/lonparmset.pm 2006/04/18 20:35:47 1.294 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.285 2006/04/13 21:32:23 albertel Exp $ +# $Id: lonparmset.pm,v 1.294 2006/04/18 20:35:47 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -394,38 +394,13 @@ sub storeparm_by_symb { return ''; } -{ - my $logid; - sub log_parmset { - my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_; - $logid++; - my $id=time().'00000'.$$.'00000'.$logid; - &Apache::lonnet::put('parameterlog', - { - $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 - }, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'} - ); - } +sub log_parmset { + return &Apache::lonnet::instructor_log('parameterlog',@_); } 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 +454,11 @@ sub storeparm_by_symb_inner { 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 +479,11 @@ sub storeparm_by_symb_inner { 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 +2400,7 @@ sub storedata { 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('
'.&mt('Stored modified parameter for').' '. &Apache::loncommon::plainname($tuname,$tudom)); } else { @@ -2436,6 +2416,7 @@ sub storedata { } elsif ($cmd eq 'del') { if ($tuname) { if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') { + &log_parmset({$tkey=>''},1,$tuname,$tudom); $r->print('
'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom)); } else { $r->print('

'. @@ -2453,6 +2434,7 @@ sub storedata { 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('
'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom)); } else { $r->print('

'. @@ -2473,6 +2455,8 @@ sub storedata { 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('

'.&mt('Deleted [_1] parameter(s)

',$delentries)); } else { $r->print('

'. @@ -2482,6 +2466,7 @@ sub storedata { } if ($putentries) { if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') { + &log_parmset(\%newdata,0); $r->print('

'.&mt('Stored [_1] parameter(s)',$putentries/2).'

'); } else { $r->print('

'. @@ -2607,8 +2592,8 @@ sub listdata { # # Ready to print # - $r->print(&tablestart().''.$name. - ':'); $foundkeys++; if (&isdateparm($thistype)) { @@ -3046,7 +3031,7 @@ ENDMAINFORMHEAD action => 'setdefaults', permission => $parm_permission, }, - { text => 'Parameter Change Log and Course Blog Posting', + { text => 'Parameter Change Log and Course Blog Posting/User Notification', action => 'parameterchangelog', permission => $parm_permission, }, @@ -3316,9 +3301,140 @@ ENDYESNO return; } +sub components { + my ($key,$uname,$udom,$exeuser,$exedomain)=@_; + my $typeflag=0; + if ($key=~/\.type$/) { + $key=~s/\.type$//; + $typeflag=1; + } + my $issection; + my ($middle,$part,$name)=($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); + my $section=&mt('All Students'); + if ($middle=~/^\[(.*)\]/) { + $issection=$1; + $section=&mt('Group/Section').': '.$issection; + $middle=~s/^\[(.*)\]//; + } + $middle=~s/\.+$//; + $middle=~s/^\.+//; + if ($uname) { + $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom); + $issection=''; + } + my $realm=''.&mt('All Resources').''; + if ($middle=~/^(.+)\_\_\_\(all\)$/) { + $realm=''.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).'
('.$1.')
'; + } elsif ($middle) { + my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle); + $realm=''.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).'
('.$url.' in '.$map.' id: '.$id.')
'; + } + my $what=$part.'.'.$name; + return ($realm,$section,$name,$part,$typeflag, + $what,$middle,$uname,$udom,$issection); +} + +sub standard_parameter_names { + my ($name)=@_; + my %standard_parms=&Apache::lonlocal::texthash('duedate' => 'Due Date', + 'answerdate' => 'Answer Date', + 'opendate' => 'Open Date', + 'maxtries' => 'Max. Number of Tries', + 'weight' => 'Weight', + 'date_start' => 'Starting Date', + 'date_end' => 'Ending Date', + 'int_pos' => 'Positive Integer', + 'int_zero_pos' => 'Positive Integer or Zero', + 'hinttries' => 'Number of Tries till Hints appear'); + if ($standard_parms{$name}) { + return $standard_parms{$name}; + } else { + return $name; + } +} + sub parm_change_log { my ($r)=@_; &startpage($r); + my %parmlog=&Apache::lonnet::dump('nohist_parameterlog', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + my $courseopt=&Apache::lonnet::get_courseresdata($env{'course.'.$env{'request.course.id'}.'.num'}, + $env{'course.'.$env{'request.course.id'}.'.domain'}); + $r->print(''); + my $bgcolor='#EEEEEE'; + foreach my $id (sort { $parmlog{$b}{'exe_time'}<=>$parmlog{$a}{'exe_time'} } (keys(%parmlog))) { + if ($bgcolor eq '#EEEEEE') { $bgcolor='#FFFFCC'; } else { $bgcolor='#EEEEEE'; } + my @changes=keys(%{$parmlog{$id}{'logentry'}}); + my $count=$#changes+1; + my $time = + &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'}); + my $plainname = + &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'}, + $parmlog{$id}{'exe_udom'}); + my $about_me_link = + &Apache::loncommon::aboutmewrapper($plainname, + $parmlog{$id}{'exe_uname'}, + $parmlog{$id}{'exe_udom'}); + my $send_msg_link=''; + if ((($parmlog{$id}{'exe_uname'} ne $env{'user.name'}) + || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) { + $send_msg_link ='
'. + &Apache::loncommon::messagewrapper(&mt('Send message'), + $parmlog{$id}{'exe_uname'}, + $parmlog{$id}{'exe_udom'}); + } + $r->print(' + '); + my $makenewrow=0; + my %istype=(); + foreach my $changed (reverse(sort(@changes))) { + my $value=$parmlog{$id}{'logentry'}->{$changed}; + my ($realm,$section,$parmname,$part,$typeflag,$what,$middle,$uname,$udom,$issection)= + &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'}); + if ($typeflag) { $istype{$parmname}=$value; } + if ($makenewrow) { $r->print(''); } else { $makenewrow=1; } + $r->print(''); + if ($stillactive) { + if (($uname) && ($udom)) { + $r->print(''); + } else { + $r->print(''); + } + } else { + $r->print(''); + } + $r->print(''); + } + } + $r->print('
'.$time.''.$about_me_link. + '
'.$parmlog{$id}{'exe_uname'}. + ':'.$parmlog{$id}{'exe_udom'}.''. + $send_msg_link.'
'.$realm.''.$section.''. + &standard_parameter_names($parmname).''. + ($part?&mt('Part: [_1]',$part):&mt('All Parts')).''); + my $stillactive=0; + if ($parmlog{$id}{'deleteflag'}) { + $r->print(&mt('Deleted')); + } else { + if ($typeflag) { + $r->print(&mt('Type: [_1]',&standard_parameter_names($value))); + } else { + my ($level,@all)=&parmval_by_symb($what,$middle,&Apache::lonnet::metadata($middle,$what), + $uname,$udom,$issection,$issection,$courseopt); + if (&isdateparm($istype{$parmname})) { + $r->print(&Apache::lonlocal::locallocaltime($value)); + } else { + $r->print($value); + } + if ($value ne $all[$level]) { + $r->print('
'.&mt('Not active anymore').''); + } else { + $stillactive=1; + } + } + } + $r->print('
Notify LinkBlog Link 
'); $r->print(&Apache::loncommon::end_page()); } @@ -3416,7 +3532,7 @@ sub handler { &assessparms($r); } elsif ($env{'form.action'} eq 'parameterchangelog' && $parm_permission) { &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable', - text=>"Parameter Change Log and Course Blog Posting"}); + text=>"Parameter Change Log"}); &parm_change_log($r); } } else {