--- loncom/interface/lonparmset.pm 2006/11/15 20:13:43 1.345 +++ loncom/interface/lonparmset.pm 2007/01/04 19:34:13 1.356 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.345 2006/11/15 20:13:43 banghart Exp $ +# $Id: lonparmset.pm,v 1.356 2007/01/04 19:34:13 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -65,7 +65,7 @@ use Apache::lonlocal; use Apache::lonnavmaps; use Apache::longroup; use Apache::lonrss; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); # --- Caches local to lonparmset @@ -122,7 +122,10 @@ sub parmval_by_symb { # load caches &cacheparmhash(); - my $useropt=&Apache::lonnet::get_userresdata($uname,$udom); + my $useropt; + if ($uname ne '' && $udom ne '') { + $useropt = &Apache::lonnet::get_userresdata($uname,$udom); + } my $result=''; my @outpar=(); @@ -173,7 +176,7 @@ sub parmval_by_symb { } # ------------------------------------------------------ fourth, back to course - if (defined($csec)) { + if ($csec ne '') { if (defined($$courseopt{$seclevel})) { $outpar[9]=$$courseopt{$seclevel}; $result=9; @@ -189,7 +192,7 @@ sub parmval_by_symb { } } # ------------------------------------------------------ fifth, check course group - if (defined($cgroup)) { + if ($cgroup ne '') { if (defined($$courseopt{$grplevel})) { $outpar[6]=$$courseopt{$grplevel}; $result=6; @@ -206,7 +209,7 @@ sub parmval_by_symb { # ---------------------------------------------------------- fifth, check user - if (defined($uname)) { + if ($uname ne '') { if (defined($$useropt{$courselevel})) { $outpar[3]=$$useropt{$courselevel}; $result=3; @@ -269,10 +272,8 @@ sub resetrulescache { sub rulescache { my $id=shift; - if ($rulesid ne $env{'request.course.id'}) { - %rules=(); - } - unless (defined($rules{$id})) { + if ($rulesid ne $env{'request.course.id'} + && !defined($rules{$id})) { my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs); @@ -2363,8 +2364,7 @@ sub readdata { my $classlist=&Apache::loncoursedata::get_classlist(); foreach (keys %$classlist) { - # the following undefs are for 'domain', and 'username' respectively. - if ($_=~/^(\w+)\:(\w+)$/) { + if ($_=~/^($match_username)\:($match_domain)$/) { my ($tuname,$tudom)=($1,$2); my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom); foreach my $userkey (keys %{$useropt}) { @@ -2486,7 +2486,7 @@ sub storedata { sub extractuser { my $key=shift; - return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./); + return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./); } sub listdata { @@ -2544,7 +2544,7 @@ sub listdata { my $section=&mt('All Students'); if ($middle=~/^\[(.*)\]/) { my $issection=$1; - if ($issection=~/^useropt\:(\w+)\:(\w+)/) { + if ($issection=~/^useropt\:($match_username)\:($match_domain)/) { $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2); } else { $section=&mt('Group/Section').': '.$issection; @@ -2918,7 +2918,7 @@ sub parse_key { $data{'scope_type'} = 'all'; if ($middle=~/^\[(.*)\]/) { $data{'scope'} = $1; - if ($data{'scope'}=~/^useropt\:(\w+)\:(\w+)/) { + if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) { $data{'scope_type'} = 'user'; $data{'scope'} = [$1,$2]; } else { @@ -3190,7 +3190,6 @@ ENDMAINFORMHEAD sub output_row { my ($r, $field_name, $field_text, $added_flag) = @_; my $output; - $output = ""; my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'}; my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'}; if (!defined($options)) { @@ -3198,23 +3197,47 @@ sub output_row { $values = ''; } if (!($options =~ /deleted/)) { - $output = ""; - $output .= ''.$field_text.':'; - $output .= ''; - $output .= "\n"; my @options= ( ['active', 'Show to student'], - ['onlyone','Student may select only one choice'], - ['stuadd', 'Student may type choices']); + ['stuadd', 'Provide text area for students to type catalog information'], + ['choices','Provide choices for students to select from']); +# ['onlyone','Student may select only one choice']); if ($added_flag) { push @options,['deleted', 'Delete Metadata Field']; } + $output = &Apache::loncommon::start_data_table_row(); + $output .= ''.$field_text.':'; + $output .= &Apache::loncommon::end_data_table_row(); foreach my $opt (@options) { my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ; - $output .= ''.(' ' x 5).' '."\n"; - } - + $output .= &Apache::loncommon::continue_data_table_row(); + $output .= ''.(' ' x 5).' '; + $output .= &Apache::loncommon::end_data_table_row(); + } + $output .= &Apache::loncommon::continue_data_table_row(); + $output .= ''.(' ' x 10).''; + $output .= &Apache::loncommon::end_data_table_row(); + my $multiple_checked; + my $single_checked; + if ($options =~ m/onlyone/) { + $multiple_checked = ""; + $single_checked = " CHECKED "; + } else { + $multiple_checked = " CHECKED "; + $single_checked = ""; + } + $output .= &Apache::loncommon::continue_data_table_row(); + $output .= ''.(' ' x 10).' + + Student may select multiple choices from list'; + $output .= &Apache::loncommon::end_data_table_row(); + $output .= &Apache::loncommon::continue_data_table_row(); + $output .= ''.(' ' x 10).' + + Student may select only one choice from list'; + $output .= &Apache::loncommon::end_data_table_row(); } return ($output); } @@ -3370,7 +3393,10 @@ sub setrestrictmeta { if ($env{'form.'.$meta_field.'_stuadd'}) { $options.='stuadd,'; } - if ($env{'form.'.$meta_field.'_onlyone'}) { + if ($env{'form.'.$meta_field.'_choices'}) { + $options.='choices,'; + } + if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') { $options.='onlyone,'; } if ($env{'form.'.$meta_field.'_active'}) { @@ -3379,7 +3405,6 @@ sub setrestrictmeta { if ($env{'form.'.$meta_field.'_deleted'}) { $options.='deleted,'; } - my $name = $save_field; $put_result = &Apache::lonnet::put('environment', {'metadata.'.$meta_field.'.options'=>$options, @@ -3395,29 +3420,34 @@ sub setrestrictmeta { my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio'); # Now get possible added metadata fields my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields); - $output .= ""; + my $row_alt = 1; + $output .= &Apache::loncommon::start_data_table(); foreach my $field (sort(keys(%metadata_fields))) { if ($field ne 'courserestricted') { + $row_alt = $row_alt ? 0 : 1; $output.= &output_row($r, $field, $metadata_fields{$field}); } } + my $buttons = (< +
+
+ + +
+
+ +ENDButtons my $added_flag = 1; foreach my $field (sort(keys(%$added_metadata_fields))) { - $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag); + $row_alt = $row_alt ? 0 : 1; + $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt); } - $output .= "
"; + $output .= &Apache::loncommon::end_data_table(); $r->print(< -

$output - -
-

- -
-
-
- + $buttons
ENDenv $r->print(&Apache::loncommon::end_page()); @@ -3701,13 +3731,7 @@ sub parm_change_log { \%saveable_parameters); &Apache::loncommon::restore_course_settings('parameter_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::display_filter(). ''. ''); @@ -3719,7 +3743,25 @@ sub parm_change_log { &mt('Parameter').''.&mt('Part').''.&mt('New Value').''.&mt('Announce').''. &Apache::loncommon::end_data_table_header_row()); my $shown=0; - foreach my $id (sort { $parmlog{$b}{'exe_time'}<=>$parmlog{$a}{'exe_time'} } (keys(%parmlog))) { + my $folder=''; + if ($env{'form.displayfilter'} eq 'currentfolder') { + my $last=''; + if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', + &GDBM_READER(),0640)) { + $last=$hash{'last_known'}; + untie(%hash); + } + if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); } + } + foreach my $id (sort + { + if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) { + return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'} + } + my $aid = (split('00000',$a))[-1]; + my $bid = (split('00000',$b))[-1]; + return $bid<=>$aid; + } (keys(%parmlog))) { my @changes=keys(%{$parmlog{$id}{'logentry'}}); my $count = 0; my $time = @@ -3740,7 +3782,6 @@ sub parm_change_log { $parmlog{$id}{'exe_udom'}); } my $row_start=&Apache::loncommon::start_data_table_row(); - $r->print($row_start); my $makenewrow=0; my %istype=(); my $output; @@ -3750,6 +3791,11 @@ sub parm_change_log { !exists($parmlog{$id}{'logentry'}{$changed.'.type'})); my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)= &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag); + if ($env{'form.displayfilter'} eq 'currentfolder') { + if ($folder) { + if ($middle!~/^\Q$folder\E/) { next; } + } + } if ($typeflag) { $istype{$parmname}=$value; if (!$env{'form.includetypes'}) { next; } @@ -3802,13 +3848,20 @@ sub parm_change_log { } $output .= ''.&Apache::loncommon::end_data_table_row(); } - $r->print(''.$time.' + if ($env{'form.displayfilter'} eq 'containing') { + my $wholeentry=$about_me_link.':'. + $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'. + $output; + if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } + } + if ($count) { + $r->print($row_start.''.$time.' '.$about_me_link. '
'.$parmlog{$id}{'exe_uname'}. ':'.$parmlog{$id}{'exe_udom'}.''. $send_msg_link.''.$output); - - $shown++; + $shown++; + } if (!($env{'form.show'} eq &mt('all') || $shown<=$env{'form.show'})) { last; } } @@ -3816,6 +3869,12 @@ sub parm_change_log { $r->print(&Apache::loncommon::end_page()); } +sub check_for_course_info { + my $navmap = Apache::lonnavmaps::navmap->new(); + return 1 if ($navmap); + return 0; +} + ################################################## ################################################## @@ -3859,7 +3918,9 @@ sub handler { (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) || &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'. $env{'request.course.sec'})); - if ($env{'request.course.id'} && $parm_permission) { + my $exists = &check_for_course_info(); + + if ($env{'request.course.id'} && $parm_permission && $exists) { # Start Page &Apache::loncommon::content_type($r,'text/html'); @@ -3929,8 +3990,13 @@ sub handler { } } else { # ----------------------------- Not in a course, or not allowed to modify parms - $env{'user.error.msg'}= - "/adm/parmset:opa:0:0:Cannot modify assessment parameters"; + if ($exists) { + $env{'user.error.msg'}= + "/adm/parmset:opa:0:0:Cannot modify assessment parameters"; + } else { + $env{'user.error.msg'}= + "/adm/parmset::0:1:Course environment gone, reinitialize the course"; + } return HTTP_NOT_ACCEPTABLE; } return OK;