--- loncom/interface/lonparmset.pm 2006/11/29 22:02:47 1.349 +++ loncom/interface/lonparmset.pm 2007/03/20 00:08:09 1.364 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.349 2006/11/29 22:02:47 www Exp $ +# $Id: lonparmset.pm,v 1.364 2007/03/20 00:08:09 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); @@ -553,7 +554,8 @@ sub valout { } $result=~s/\s+$//; } elsif (&isdateparm($type)) { - $result = localtime($value).&date_sanity_info($value); + $result = &Apache::lonlocal::locallocaltime($value). + &date_sanity_info($value); } else { $result = $value; } @@ -933,57 +935,66 @@ sub extractResourceInformation { $$typep{$id}=$1; $$keyp{$id}=''; $$uris{$id}=$srcf; - foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) { - if ($_=~/^parameter\_(.*)/) { - my $key=$_; + foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) { + next if ($key!~/^parameter_/); + # Hidden parameters - if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') { - next; - } - my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); - my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); - my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); + next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm'); # # allparms is a hash of parameter names # + my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); + if (!exists($$allparms{$name})) { + my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); my $parmdis = $display; $parmdis =~ s/\[Part.*$//g; - $$allparms{$name}=$parmdis; - $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type'); + $$allparms{$name}=$parmdis; + if (ref($defkeytype)) { + $$defkeytype{$name}= + &Apache::lonnet::metadata($srcf,$key.'.type'); + } + } + # # allparts is a hash of all parts # - $$allparts{$part} = "Part: $part"; + my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); + $$allparts{$part} = "Part: $part"; # # Remember all keys going with this resource # - if ($$keyp{$id}) { - $$keyp{$id}.=','.$key; - } else { - $$keyp{$id}=$key; - } + if ($$keyp{$id}) { + $$keyp{$id}.=','.$key; + } else { + $$keyp{$id}=$key; + } # # Put in order # - unless ($$keyorder{$key}) { - $$keyorder{$key}=$keyordercnt; - $keyordercnt++; - } - + unless ($$keyorder{$key}) { + $$keyorder{$key}=$keyordercnt; + $keyordercnt++; } } - $$mapp{$id}= - &Apache::lonnet::declutter($resource->enclosing_map_src()); - $$mapp{$mapid}=$$mapp{$id}; - $$allmaps{$mapid}=$$mapp{$id}; - if ($mapid eq '1') { - $$maptitles{$mapid}='Main Course Documents'; + + + if (!exists($$mapp{$mapid})) { + $$mapp{$id}= + &Apache::lonnet::declutter($resource->enclosing_map_src()); + $$mapp{$mapid}=$$mapp{$id}; + $$allmaps{$mapid}=$$mapp{$id}; + if ($mapid eq '1') { + $$maptitles{$mapid}='Main Course Documents'; + } else { + $$maptitles{$mapid}= + &Apache::lonnet::gettitle($$mapp{$id}); + } + $$maptitles{$$mapp{$id}}=$$maptitles{$mapid}; + $$symbp{$mapid}=$$mapp{$id}.'___(all)'; } else { - $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id})); + $$mapp{$id} = $$mapp{$mapid}; } - $$maptitles{$$mapp{$id}}=$$maptitles{$mapid}; $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf); - $$symbp{$mapid}=$$mapp{$id}.'___(all)'; } } @@ -2033,6 +2044,22 @@ sub crsenv { if ($name =~ /^default_enrollment_(start|end)_date$/) { $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value'); } + # + # Deal with the emails + if ($name =~ /\.email$/) { + my ($user,$domain) = split(/:/,$value); + if (!defined($user) || !defined($domain)) { + $setoutput.= '
'. + &mt("Invalid email address specified, address must be of the form username:domain"). + ''; + undef($value); + } elsif (&Apache::lonnet::homeserver($user,$domain) eq 'no_host') { + $setoutput.= '
'. + &mt("Invalid email address specified, user [_1] is unknown.",$value). + ''; + undef($value); + } + } # Get existing cloners my @oldcloner = (); if ($name eq 'cloners') { @@ -2120,10 +2147,16 @@ sub crsenv { 'question.email' => ''.&mt('Feedback Addresses for Resource Content Question'). '
(user:domain,'. 'user:domain(section;section;...;*;...),...)', + 'question.email.text' => ''.&mt('Custom Text for Resource Content Question Option in Feedback'). + '', 'comment.email' => ''.&mt('Feedback Addresses for Course Content Comments').'
'. '(user:domain,user:domain(section;section;...;*;...),...)', + 'comment.email.text' => ''.&mt('Custom Text for Course Content Option in Feedback'). + '', 'policy.email' => ''.&mt('Feedback Addresses for Course Policy').''. '
(user:domain,user:domain(section;section;...;*;...),...)', + 'policy.email.text' => ''.&mt('Custom Text for Course Policy Option in Feedback'). + '', 'hideemptyrows' => ''.&mt('Hide Empty Rows in Spreadsheets').'
'. '('.&mt('"[_1]" for default hiding','yes').')', 'pageseparators' => ''.&mt('Visibly Separate Items on Pages').'
'. @@ -2206,7 +2239,7 @@ sub crsenv { => ''.&mt('Disable display of problem receipts').'
'. ' ('.&mt('"[_1]" to disable, anything else if not','yes').')', 'task_messages' - => ''.&mt('Send message to student when clicking Done on Tasks. [_1] to send a message only to student, [_2] to send message to student and add record to user information page for instructors. Leave blank to disable.','only_student','student_and_user_notes_screen').'', + => ''.&mt('Send message to student when clicking Done on Tasks').'
('.&mt('[_1] to send a message only to student, [_2] to send message to student and add record to user information page for instructors. Leave blank to disable.','only_student','student_and_user_notes_screen').')', 'disablesigfigs' => ''.&mt('Disable checking of Significant Figures').'
'. ' ('.&mt('"[_1]" to disable, anything else if not','yes').')', @@ -2221,7 +2254,7 @@ sub crsenv { my @Display_Order = ('url','description','courseid','cloners','grading', 'externalsyllabus', 'default_xml_style','pageseparators', - 'question.email','comment.email','policy.email', + 'question.email','question.email.text','comment.email','comment.email.text','policy.email','policy.email.text', 'student_classlist_view', 'plc.roles.denied','plc.users.denied', 'pch.roles.denied','pch.users.denied', @@ -2363,8 +2396,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 +2518,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 +2576,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; @@ -2875,6 +2907,11 @@ ENDOVER '' ); $r->print(''); + my $display_value = $resourcedata->{$thiskey}; + if (&isdateparm($resourcedata->{$thiskey.'.type'})) { + $display_value = + &Apache::lonlocal::locallocaltime($display_value); + } $r->print(&mt('Parameter: "[_1]" with value: "[_2]"', &standard_parameter_names($data{'parameter_name'}), $resourcedata->{$thiskey})); @@ -2899,7 +2936,7 @@ ENDOVER $r->print(&mt('Resource: [_1]
   with ID: [_2]
   in folder [_3]', $url,$resid,$map)); } - $r->print(&mt('Part: [_1]',$data{'parameter_part'})); + $r->print('
   '.&mt('Part: [_1]',$data{'parameter_part'})); $r->print(''); } @@ -2918,7 +2955,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 { @@ -3189,7 +3226,6 @@ ENDMAINFORMHEAD ### Set portfolio metadata sub output_row { my ($r, $field_name, $field_text, $added_flag) = @_; - my $row_class; my $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'}; @@ -3198,26 +3234,47 @@ sub output_row { $values = ''; } if (!($options =~ /deleted/)) { - $output = &Apache::loncommon::start_data_table_row(); - $output .= ''.$field_text.':'; - # $output .= ''.$field_text.':'; - $output .= ''; - $output .= &Apache::loncommon::end_data_table_row(); 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 .= &Apache::loncommon::continue_data_table_row(); - $output .= ''.(' ' x 5).' '; + $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); } @@ -3268,7 +3325,7 @@ sub order_meta_fields { {'metadata.addedorder'=>$ordered_fields},$dom,$crs); &Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields); } - my $fields = &get_added_meta_fieldnames(); + my $fields = &get_added_meta_fieldnames($env{'request.course.id'}); my $ordered_fields; my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}; if (!@fields_in_order) { @@ -3303,6 +3360,13 @@ sub order_meta_fields { $r->print(''); return 'ok'; } +sub continue { + my $output; + $output .= '
'; + $output .= ''; + $output .= ''; + return ($output); +} sub addmetafield { my ($r)=@_; $r->print(&Apache::loncommon::start_page('Add Metadata Field')); @@ -3310,7 +3374,7 @@ sub addmetafield { my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; if (exists($env{'form.undelete'})) { - my @meta_fields = &Apache::loncommon::get_env_multiple('form.undelete'); + my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield'); foreach my $meta_field(@meta_fields) { my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'}; $options =~ s/deleted//; @@ -3320,9 +3384,7 @@ sub addmetafield { $r->print('Undeleted Metadata Field '.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}." with result ".$put_result.'
'); } - $r->print(''); - $r->print(''); - $r->print(''); + $r->print(&continue()); } elsif (exists($env{'form.fieldname'})) { my $meta_field = $env{'form.fieldname'}; my $display_field = $env{'form.fieldname'}; @@ -3332,14 +3394,15 @@ sub addmetafield { {'metadata.'.$meta_field.'.values'=>"", 'metadata.'.$meta_field.'.added'=>"$display_field", 'metadata.'.$meta_field.'.options'=>""},$dom,$crs); - $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result); + $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result.'
'); + $r->print(&continue()); } else { - my $fields = &get_deleted_meta_fieldnames(); + my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'}); if ($fields) { $r->print('You may undelete previously deleted fields.
Check those you wish to undelete and click Undelete.
'); $r->print(''); foreach my $key(keys(%$fields)) { - $r->print(''.$$fields{$key}.'
print(''.$$fields{$key}.'
print(''); $r->print('
'); @@ -3347,8 +3410,8 @@ sub addmetafield { $r->print('
Or you may enter a new metadata field name.
print('
'); $r->print(''); - $r->print('
'); } + $r->print(''); } sub setrestrictmeta { my ($r)=@_; @@ -3373,7 +3436,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'}) { @@ -3382,7 +3448,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, @@ -3397,7 +3462,7 @@ sub setrestrictmeta { # Get the default metadata fields my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio'); # Now get possible added metadata fields - my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields); + my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'}); my $row_alt = 1; $output .= &Apache::loncommon::start_data_table(); foreach my $field (sort(keys(%metadata_fields))) { @@ -3406,6 +3471,16 @@ sub setrestrictmeta { $output.= &output_row($r, $field, $metadata_fields{$field}); } } + my $buttons = (< +
+
+ +
+
+
+ +ENDButtons my $added_flag = 1; foreach my $field (sort(keys(%$added_metadata_fields))) { $row_alt = $row_alt ? 0 : 1; @@ -3415,14 +3490,7 @@ sub setrestrictmeta { $r->print(< $output - -
-
- -
-
-
- + $buttons
ENDenv $r->print(&Apache::loncommon::end_page()); @@ -3430,9 +3498,10 @@ ENDenv } ################################################## sub get_added_meta_fieldnames { + my ($cid) = @_; my %fields; foreach my $key(%env) { - if ($key =~ m/\.metadata\.(.+)\.added$/) { + if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) { my $field_name = $1; my ($display_field_name) = $env{$key}; $fields{$field_name} = $display_field_name; @@ -3441,10 +3510,10 @@ sub get_added_meta_fieldnames { return \%fields; } sub get_deleted_meta_fieldnames { + my ($cid) = @_; my %fields; - my ($default_fields) = @_; foreach my $key(%env) { - if ($key =~ m/\.metadata\.(.+)\.added$/) { + if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) { my $field_name = $1; if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) { my ($display_field_name) = $env{$key}; @@ -3728,7 +3797,15 @@ sub parm_change_log { } if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); } } - foreach my $id (sort { $parmlog{$b}{'exe_time'}<=>$parmlog{$a}{'exe_time'} } (keys(%parmlog))) { + 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 = @@ -3836,6 +3913,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; +} + ################################################## ################################################## @@ -3879,7 +3962,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'); @@ -3949,8 +4034,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;