--- loncom/interface/lonparmset.pm 2007/07/20 00:15:06 1.372 +++ loncom/interface/lonparmset.pm 2008/05/29 01:40:12 1.397 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.372 2007/07/20 00:15:06 raeburn Exp $ +# $Id: lonparmset.pm,v 1.397 2008/05/29 01:40:12 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,16 +67,6 @@ use Apache::longroup; use Apache::lonrss; use LONCAPA qw(:DEFAULT :match); -# --- Caches local to lonparmset - -my $parmhashid; -my %parmhash; -my $symbsid; -my %symbs; -my $rulesid; -my %rules; - -# --- end local caches ################################################## ################################################## @@ -119,8 +109,6 @@ sub parmval { sub parmval_by_symb { my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_; -# load caches - &cacheparmhash(); my $useropt; if ($uname ne '' && $udom ne '') { @@ -167,7 +155,7 @@ sub parmval_by_symb { # ------------------------------------------------------ third, check map parms - my $thisparm=$parmhash{$symbparm}; + my $thisparm=&parmhash($symbparm); if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; } if (defined($$courseopt{$courselevelr})) { @@ -228,58 +216,90 @@ sub parmval_by_symb { return ($result,@outpar); } -sub resetparmhash { - $parmhashid=''; -} -sub cacheparmhash { - if ($parmhashid eq $env{'request.course.fn'}) { return; } - my %parmhashfile; - if (tie(%parmhashfile,'GDBM_File', - $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) { - %parmhash=%parmhashfile; - untie %parmhashfile; - $parmhashid=$env{'request.course.fn'}; - } -} -sub resetsymbcache { - $symbsid=''; +# --- Caches local to lonparmset + + +sub reset_caches { + &resetparmhash(); + &resetsymbcache(); + &resetrulescache(); } -sub symbcache { - my $id=shift; - if ($symbsid ne $env{'request.course.id'}) { - %symbs=(); +{ + my $parmhashid; + my %parmhash; + sub resetparmhash { + undef($parmhashid); + undef(%parmhash); } - unless ($symbs{$id}) { - my $navmap = Apache::lonnavmaps::navmap->new(); - if ($id=~/\./) { - my $resource=$navmap->getById($id); - $symbs{$id}=$resource->symb(); - } else { - my $resource=$navmap->getByMapPc($id); - $symbs{$id}=&Apache::lonnet::declutter($resource->src()); + + sub cacheparmhash { + if ($parmhashid eq $env{'request.course.fn'}) { return; } + my %parmhashfile; + if (tie(%parmhashfile,'GDBM_File', + $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) { + %parmhash=%parmhashfile; + untie(%parmhashfile); + $parmhashid=$env{'request.course.fn'}; } - $symbsid=$env{'request.course.id'}; } - return $symbs{$id}; -} - -sub resetrulescache { - $rulesid=''; -} + + sub parmhash { + my ($id) = @_; + &cacheparmhash(); + return $parmhash{$id}; + } + } + +{ + my $symbsid; + my %symbs; + sub resetsymbcache { + undef($symbsid); + undef(%symbs); + } + + sub symbcache { + my $id=shift; + if ($symbsid ne $env{'request.course.id'}) { + undef(%symbs); + } + if (!$symbs{$id}) { + my $navmap = Apache::lonnavmaps::navmap->new(); + if ($id=~/\./) { + my $resource=$navmap->getById($id); + $symbs{$id}=$resource->symb(); + } else { + my $resource=$navmap->getByMapPc($id); + $symbs{$id}=&Apache::lonnet::declutter($resource->src()); + } + $symbsid=$env{'request.course.id'}; + } + return $symbs{$id}; + } + } -sub rulescache { - my $id=shift; - 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); - $rulesid=$env{'request.course.id'}; +{ + my $rulesid; + my %rules; + sub resetrulescache { + undef($rulesid); + undef(%rules); + } + + sub rulescache { + my $id=shift; + 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); + $rulesid=$env{'request.course.id'}; + } + return $rules{$id}; } - return $rules{$id}; } sub preset_defaults { @@ -345,7 +365,6 @@ sub storeparm { # - new type # - username # - userdomain - my %recstack; sub storeparm_by_symb { my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_; @@ -558,6 +577,7 @@ sub valout { &date_sanity_info($value); } else { $result = $value; + $result = &HTML::Entities::encode($result,'"<>&'); } } return $result; @@ -594,10 +614,16 @@ sub plink { my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/); my ($hour,$min,$sec,$val)=&preset_defaults($parmname); unless (defined($winvalue)) { $winvalue=$val; } + my $valout = &valout($value,$type,1); + foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call, + \$hour, \$min, \$sec) { + $$item = &HTML::Entities::encode($$item,'"<>&'); + $$item =~ s/\'/\\\'/g; + } return '
'. ''. - &valout($value,$type,1).'
'; + $valout.''; } sub page_js { @@ -944,7 +970,7 @@ sub extractResourceInformation { # allparms is a hash of parameter names # my $name=&Apache::lonnet::metadata($srcf,$key.'.name'); - if (!exists($$allparms{$name})) { + if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) { my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); my $parmdis = $display; $parmdis =~ s/\[Part.*$//g; @@ -1081,7 +1107,9 @@ ENDSCRIPT if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) { $r->print(' checked'); } - $r->print('>'.$$allparms{$tempkey}.''); + $r->print('>'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey} + : $tempkey) + .''); $cnt++; if ($cnt==3) { $r->print("\n"); @@ -1573,7 +1601,8 @@ sub assessparms { foreach ('tolerance','date_default','date_start','date_end', 'date_interval','int','float','string') { $r->print(''); + &HTML::Entities::encode($env{'form.recent_'.$_},'"&<>'). + '" name="recent_'.$_.'" />'); } if (!$pssymb) { @@ -1997,6 +2026,8 @@ sub crsenv { my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; + my (%crsinfo,$chome); + # # Go through list of changes foreach (keys %env) { @@ -2080,40 +2111,85 @@ sub crsenv { # # Let the user know we made the changes if ($name && defined($value)) { - my $failed_cloners; + my %failed_cloners; if ($name eq 'cloners') { $value =~ s/\s//g; $value =~ s/^,//; $value =~ s/,$//; # check requested clones are valid users. - $failed_cloners = &check_cloners(\$value,\@oldcloner); + %failed_cloners = &check_cloners(\$value,\@oldcloner); } my $put_result = &Apache::lonnet::put('environment', {$name=>$value},$dom,$crs); if ($put_result eq 'ok') { - $setoutput.=&mt('Set').' '.$name.' '.&mt('to').' '.$value.'.
'; + $setoutput.=&mt('Set').' '.$name.' '.&mt('to').' '; + if ($name =~ /^default_enrollment_(start|end)_date$/) { + $setoutput .= &Apache::lonlocal::locallocaltime($value); + } else { + $setoutput .= $value; + } + $setoutput .= '.
'; if ($name eq 'cloners') { &change_clone($value,\@oldcloner); } - # Flush the course logs so course description is immediately updated + # Update environment and nohist_courseids.db + if ($name eq 'description' || $name eq 'cloners') { + if ($chome eq '') { + %crsinfo = + &Apache::lonnet::courseiddump($dom,'.',1,'.','.', + $crs,undef,undef,'Course'); + $chome = &Apache::lonnet::homeserver($crs,$dom); + } + } if ($name eq 'description' && defined($value)) { - &Apache::lonnet::flushcourselogs(); + &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $value}); + if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') { + $crsinfo{$env{'request.course.id'}}{'description'} = $value; + my $putresult = + &Apache::lonnet::courseidput($dom,\%crsinfo, + $chome,'notime'); + } + } + if ($name eq 'cloners') { + if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') { + $crsinfo{$env{'request.course.id'}}{'cloners'} = $value; + my $putresult = + &Apache::lonnet::courseidput($dom,\%crsinfo, + $chome,'notime'); + } } } else { $setoutput.=&mt('Unable to set').' '.$name.' '.&mt('to'). ' '.$value.' '.&mt('due to').' '.$put_result.'.
'; } - if (($name eq 'cloners') && ($failed_cloners)) { - $setoutput.= &mt('Unable to include').' - '.$failed_cloners.', '. - &mt('reason').' - '.&mt('LON-CAPA user(s) do(es) not exist'). - '.
'.&mt('Please '). - ' '. - &mt('add the user(s)').', '. - &mt('and then return to the '). - ''. - &mt('Course Parameters page').' '. - &mt('to add the new user(s) to the list of possible cloners'). - '.
'; + if (($name eq 'cloners') && (keys(%failed_cloners) > 0)) { + $setoutput.= &mt('Unable to include').': '; + my @fails; + my $num = 0; + if (defined($failed_cloners{'format'})) { + $fails[$num] .= ''.$failed_cloners{'format'}. + ', '.&mt('reason').' - '. + &mt('Invalid format'); + $num ++; + } + if (defined($failed_cloners{'domain'})) { + $fails[$num] .= ''.$failed_cloners{'domain'}. + ', '.&mt('reason').' - '. + &mt('Domain does not exist'); + $num ++; + } + if (defined($failed_cloners{'newuser'})) { + $fails[$num] .= ''.$failed_cloners{'newuser'}. ', '.&mt('reason').' - '. + &mt('LON-CAPA user(s) do(es) not exist.'). + '.
'.&mt('Please '). + ' '. + &mt('add the user(s)').', '. + &mt('and then return to the '). + ''. + &mt('Course Parameters page').' '. + &mt('to add the new user(s) to the list of possible cloners'); + } + $setoutput .= join(';  ',@fails).'.
'; } } } @@ -2134,70 +2210,72 @@ sub crsenv { my $output=''; if (! exists($values{'con_lost'})) { my %descriptions= - ('url' => ''.&mt('Top Level Map').' '. + ('url' => ''.&mt('Top Level Map').'
'. '". &mt('Select Map').'
'. - &mt('Modification may make assessment data inaccessible'). + &mt('Modification may make assessment data inaccessible!'). '', 'description' => ''.&mt('Course Description').'', 'courseid' => ''.&mt('Course ID or number'). '
'. - '('.&mt('internal').', '.&mt('optional').')', - 'cloners' => ''.&mt('Users allowed to clone course').'
(user:domain,user:domain)
'.&mt('Users with active Course Coordinator role in the course automatically have the right to clone it, and can be omitted from list.'), + '('.&mt('internal, optional').')', + 'cloners' => ''.&mt('Users allowed to clone course').'
' + .'("'.&mt('user:domain,user:domain,*:domain').'")
' + .&mt('Users with active Course Coordinator role in this course are permitted to clone and need not be included.').'
' + .&mt('Use [_1] to allow course to be cloned by anyone in the specified domain.','"*:domain"').'
' + .&mt('Use [_1] to allow unrestricted cloning in all domains.','"*"'), 'grading' => ''.&mt('Grading').'
'. - '"standard", "external", or "spreadsheet" '.&Apache::loncommon::help_open_topic('GradingOptions'), - 'default_xml_style' => ''.&mt('Default XML Style File').' '. + &mt('[_1], [_2], or [_3]','"standard"','"external"','"spreadsheet"').&Apache::loncommon::help_open_topic('GradingOptions'), + 'task_grading' => ''.&mt('Bridge Task Grading').'
' + .&mt('Instructors and TAs in sections, when grading bridge tasks, should be allowed to grade other sections.').'
' + .'('.&mt('[_1]: they are allowed (this is the default). [_2]: no, they can only grade their own section.','"any"','"section"').')', + 'default_xml_style' => ''.&mt('Default XML Style File').'
'. '$SelectStyleFile
", - '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').'
'. - '('.&mt('"[_1]" for visible separation','yes').', '. - &mt('changes will not show until next login').')', - 'student_classlist_view' => ''.&mt('Allow students to view classlist.').''.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'), - 'student_classlist_portfiles' => ''.&mt('Include link to accessible portfolio files').'
'.&mt('"[_1]" for link to each a listing of each student\'s files.','yes'), - 'student_classlist_opt_in' => ''.&mt("Student's agreement needed for listing in student-viewable roster").'
'.&mt('"[_1]" to require students to opt-in to listing in the roster (on the roster page).','yes'), - 'plc.roles.denied'=> ''.&mt('Disallow live chatroom use for Roles'). - '
"st": '. - &mt('student').', "ta": '. - 'TA, "in": '. - &mt('instructor').';
'.&mt('role,role,...').') '. - Apache::loncommon::help_open_topic("Course_Disable_Discussion"), + 'question.email' => ''.&mt('Feedback Addresses for Resource Content Question').'
' + .'("'.&mt('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').'
' + .'("'.&mt('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').'
' + .'("'.&mt('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').'
' + .'('.&mt('[_1] for visible separation.','"yes"').' ' + .&mt('Changes will not show until next login.').')', + 'student_classlist_view' => ''.&mt('Allow students to view classlist.').'
' + .'('.&mt('[_1]: students can view all sections. [_2]: students can only view their own section. blank or [_3] prevents student view.','"all"','"section"','"disabled"').')', + 'student_classlist_portfiles' => ''.&mt('Include link to accessible portfolio files').'
' + .'('.&mt('[_1] for link to each a listing of each student\'s files.','"yes"').')', + 'student_classlist_opt_in' => ''.&mt("Student's agreement needed for listing in student-viewable roster").'
' + .'('.&mt('[_1] to require students to opt-in to listing in the roster (on the roster page).','"yes"').')', + 'plc.roles.denied'=> ''.&mt('Disallow live chatroom use for Roles').'
' + .'('.&mt('[_1]: student, [_2]: TA, [_3]: instructor','"st"','"ta"','"in"').')
' + .'("'.&mt('role,role,...').'") ' + .Apache::loncommon::help_open_topic("Course_Disable_Discussion"), 'plc.users.denied' => ''.&mt('Disallow live chatroom use for Users').'
'. - '(user:domain,user:domain,...)', + '("'.&mt('user:domain,user:domain,...').'")', - 'pch.roles.denied'=> ''.&mt('Disallow Resource Discussion for Roles'). - '
"st": '. - 'student, "ta": '. - 'TA, "in": '. - 'instructor;
role,role,...) '. - Apache::loncommon::help_open_topic("Course_Disable_Discussion"), + 'pch.roles.denied'=> ''.&mt('Disallow Resource Discussion for Roles').'
' + .'('.&mt('[_1]: student, [_2]: TA, [_3]: instructor','"st"','"ta"','"in"') + .'("'.&mt('role,role,...').'") ' + .Apache::loncommon::help_open_topic("Course_Disable_Discussion"), 'pch.users.denied' => ''.&mt('Disallow Resource Discussion for Users').'
'. - '(user:domain,user:domain,...)', + '("'.&mt('user:domain,user:domain,...').'")', 'spreadsheet_default_classcalc' => ''.&mt('Default Course Spreadsheet').' '. '$SelectSpreadsheetFile
", 'spreadsheet_default_studentcalc' - => ''.&mt('Default Student Spreadsheet').' '. + => ''.&mt('Default Student Spreadsheet').'
'. '$SelectSpreadsheetFile
", @@ -2208,43 +2286,45 @@ sub crsenv { ",'spreadsheet')\">$SelectSpreadsheetFile
", 'allow_limited_html_in_feedback' => ''.&mt('Allow limited HTML in discussion posts').'
'. - '('.&mt('Set value to "[_1]" to allow',"yes").')', + '('.&mt('Set value to [_1] to allow.','"yes"').')', 'allow_discussion_post_editing' - => ''.&mt('Allow users with specified roles to edit/delete their own discussion posts').'
"st": '. - &mt('student').', "ta": '. - 'TA, "in": '. - &mt('instructor').'; ('.&mt('role:section,role:section,..., e.g., st:001,st:002,in,cc would permit students in sections 001 and 002 and instructors in any section, and course coordinators to edit their own posts.').')
'. - '('.&mt('or set value to "[_1]" to allow all roles',"yes").')', + => ''.&mt('Allow users with specified roles to edit/delete their own discussion posts').'
' + .'('.&mt('[_1]: student, [_2]: TA, [_3]: instructor','"st"','"ta"','"in"').')
' + .'('.&mt('Set value to [_1] to allow all roles.','"yes"').')' + .'("'.&mt('role:section,role:section,...').'")
' + .'('.&mt('Example: "st:001,st:002,in,cc" would permit students in sections 001 and 002 and instructors in any section, and course coordinators to edit their own posts.').')', 'rndseed' - => ''.&mt('Randomization algorithm used').'
'. - ''.&mt('Modifying this will make problems').' '. - &mt('have different numbers and answers').'', + => ''.&mt('Randomization algorithm used').'
' + .'' + .&mt('Modifying this will make problems have different numbers and answers!') + .'', 'receiptalg' => ''.&mt('Receipt algorithm used').'
'. &mt('This controls how receipt numbers are generated.'), 'suppress_tries' => ''.&mt('Suppress number of tries in printing').'
'. - ' ('.&mt('"[_1]" to suppress, anything else to not suppress','yes').')', + ' ('.&mt('[_1] to suppress, anything else to not suppress','"yes"').')', 'problem_stream_switch' => ''.&mt('Allow problems to be split over pages').'
'. - ' ('.&mt('"[_1]" if allowed, anything else if not','yes').')', + ' ('.&mt('[_1] if allowed, anything else if not','"yes"').')', 'default_paper_size' => ''.&mt('Default paper type').'
'. ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'. ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'. ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])', 'print_header_format' - => &mtn(' Print header format; substitutions : %n student name %c course id %a assignment note, numbers after the % limit the field size.').'', + => ' '.&mt('Print header format').'
' + .&mt('Substitutions:
[_1]: student name, [_2]: course id, [_3]: assignment note. Numbers after the % limit the field size.','"%n"','"%c"','"%a"'), 'default_enrollment_start_date' => ''.&mt('Default beginning date for student access.').'', 'default_enrollment_end_date' => ''.&mt('Default ending date for student access.').'', - 'nothideprivileged' => ''.&mt('Privileged users that should not be hidden on staff listings').''. - '
(user:domain,user:domain,...)', + 'nothideprivileged' => ''.&mt('Privileged users that should not be hidden on staff listings').'
' + .'("'.&mt('user:domain,user:domain,*:domain').'")', 'languages' => ''.&mt('Languages used').'', 'disable_receipt_display' => ''.&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').'
('.&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').')', + => ''.&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').')', @@ -2257,7 +2337,11 @@ sub crsenv { => ''.&mt('Default set of options to pass to tth/m when converting tex').'', 'texengine' - => ''.&mt('Force all students in the course to use a specific math rendering engine.').'
'.&mt('(Valid options are [_1].)','"tth", "jsMath", "mimetex"').'', + => ''.&mt('Force all students in the course to use a specific math rendering engine.').'
' + .'('.&mt('[_1], [_2] (Convert to Images), [_3] (TeX to HTML), or blank for student\'s preference','"jsMath"','"mimetex"','"tth"').')', + 'timezone' + => ''.&mt('Timezone in which the course takes place').'' + ); my @Display_Order = ('url','description','courseid','cloners','grading', 'externalsyllabus', @@ -2271,6 +2355,7 @@ sub crsenv { 'allow_limited_html_in_feedback', 'allow_discussion_post_editing', 'languages', + 'timezone', 'nothideprivileged', 'rndseed', 'receiptalg', @@ -2289,7 +2374,7 @@ sub crsenv { 'texengine', 'disablesigfigs', 'disableexampointprint', - 'task_messages' + 'task_messages','task_grading', ); foreach my $parameter (sort(keys(%values))) { unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./)) { @@ -2341,8 +2426,8 @@ sub crsenv { my %lt=&Apache::lonlocal::texthash( 'par' => 'Parameter', 'val' => 'Value', - 'set' => 'Set', - 'sce' => 'Set Course Environment' + 'set' => 'Set?', + 'sav' => 'Save' ); my $Parameter=&mt('Parameter'); @@ -2364,13 +2449,14 @@ $start_page $breadcrumbs
$setoutput +
$start_table $start_header_row -$lt{'par'}$lt{'val'}$lt{'set'}? +$lt{'par'}$lt{'val'}$lt{'set'} $end_header_row $output $end_table - +
$end_page ENDENV @@ -2443,16 +2529,28 @@ sub storedata { if ($tuname) { $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./; } - if ($cmd eq 'set') { - my $data=$env{$_}; - my $typeof=$env{'form.typeof_'.$thiskey}; - if ($$olddata{$thiskey} ne $data) { + if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') { + my ($data, $typeof, $text); + if ($cmd eq 'set') { + $data=$env{$_}; + $typeof=$env{'form.typeof_'.$thiskey}; + $text = &mt('Saved modified parameter for'); + } elsif ($cmd eq 'datepointer') { + $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_}); + $typeof=$env{'form.typeof_'.$thiskey}; + $text = &mt('Saved modified date for'); + } elsif ($cmd eq 'dateinterval') { + $data=&get_date_interval_from_form($thiskey); + $typeof=$env{'form.typeof_'.$thiskey}; + $text = &mt('Saved modified date for'); + } + if (defined($data) and $$olddata{$thiskey} ne $data) { if ($tuname) { 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('Saved modified parameter for').' '. + $r->print('
'.$text.' '. &Apache::loncommon::plainname($tuname,$tudom)); } else { $r->print('
'. @@ -2477,26 +2575,6 @@ sub storedata { } else { push (@deldata,$thiskey,$thiskey.'.type'); } - } elsif ($cmd eq 'datepointer') { - my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_}); - my $typeof=$env{'form.typeof_'.$thiskey}; - if (defined($data) and $$olddata{$thiskey} ne $data) { - if ($tuname) { - 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('Saved modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom)); - } else { - $r->print('
'. - &mt('Error saving parameters').'
'); - } - &Apache::lonnet::devalidateuserresdata($tuname,$tudom); - } else { - $newdata{$thiskey}=$data; - $newdata{$thiskey.'.type'}=$typeof; - } - } } } } @@ -2532,6 +2610,26 @@ sub extractuser { return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./); } +sub parse_listdata_key { + my ($key,$listdata) = @_; + # split into student/section affected, and + # the realm (folder/resource part and parameter + my ($student,$realm) = + ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/); + # if course wide student would be undefined + if (!defined($student)) { + ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/); + } + # strip off the .type if it's not the Question type parameter + if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) { + $realm=~s/\.type//; + } + # split into resource+part and parameter name + my ($res, $parm) = ($realm=~/^(.*)\.(.*)$/); + ($res, my $part) = ($res =~/^(.*)\.(.*)$/); + return ($student,$res,$part,$parm); +} + sub listdata { my ($r,$resourcedata,$listdata,$sortorder)=@_; # Start list output @@ -2543,40 +2641,48 @@ sub listdata { $tableopen=0; my $foundkeys=0; my %keyorder=&standardkeyorder(); + foreach my $thiskey (sort { + my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata); + my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata); + + # get the numerical order for the param + $aparm=$keyorder{'parameter_0_'.$aparm}; + $bparm=$keyorder{'parameter_0_'.$bparm}; + + my $result=0; + if ($sortorder eq 'realmstudent') { - my ($astudent,$arealm)=($a=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/); - my ($bstudent,$brealm)=($b=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/); - if (!defined($astudent)) { - ($arealm)=($a=~/^\Q$env{'request.course.id'}\E\.(.+)$/); - } - if (!defined($bstudent)) { - ($brealm)=($b=~/^\Q$env{'request.course.id'}\E\.(.+)$/); - } - $arealm=~s/\.type//; - my ($ares, $aparm) = ($arealm=~/^(.*)\.(.*)$/); - $aparm=$keyorder{'parameter_0_'.$aparm}; - $brealm=~s/\.type//; - my ($bres, $bparm) = ($brealm=~/^(.*)\.(.*)$/); - $bparm=$keyorder{'parameter_0_'.$bparm}; - if ($ares eq $bres) { - if (defined($aparm) && defined($bparm)) { - ($aparm <=> $bparm); - } elsif (defined($aparm)) { - -1; - } elsif (defined($bparm)) { - 1; - } else { - ($arealm cmp $brealm) || ($astudent cmp $bstudent); - } - } else { - ($arealm cmp $brealm) || ($astudent cmp $bstudent); + if ($ares ne $bres ) { + $result = ($ares cmp $bres); + } elsif ($astudent ne $bstudent) { + $result = ($astudent cmp $bstudent); + } elsif ($apart ne $bpart ) { + $result = ($apart cmp $bpart); } } else { - $a cmp $b; + if ($astudent ne $bstudent) { + $result = ($astudent cmp $bstudent); + } elsif ($ares ne $bres ) { + $result = ($ares cmp $bres); + } elsif ($apart ne $bpart ) { + $result = ($apart cmp $bpart); + } } + + if (!$result) { + if (defined($aparm) && defined($bparm)) { + $result = ($aparm <=> $bparm); + } elsif (defined($aparm)) { + $result = -1; + } elsif (defined($bparm)) { + $result = 1; + } + } + + $result; } keys %{$listdata}) { - + if ($$listdata{$thiskey.'.type'}) { my $thistype=$$listdata{$thiskey.'.type'}; if ($$resourcedata{$thiskey.'.type'}) { @@ -2649,32 +2755,18 @@ sub listdata { $$resourcedata{$thiskey}, '',1,'',''). ''. +(($$resourcedata{$thiskey}!=0)?''. +&mt('Shift all dates based on this date').'':''). &date_sanity_info($$resourcedata{$thiskey}) ); - } elsif ($thistype eq 'string_yesno') { - my $showval; - if (defined($$resourcedata{$thiskey})) { - $showval=$$resourcedata{$thiskey}; - } - $r->print(' '); - $r->print(''); + } elsif ($thistype eq 'date_interval') { + $r->print(&date_interval_selector($thiskey, + $$resourcedata{$thiskey})); + } elsif ($thistype =~ m/^string/) { + $r->print(&string_selector($thistype,$thiskey, + $$resourcedata{$thiskey})); } else { - my $showval; - if (defined($$resourcedata{$thiskey})) { - $showval=$$resourcedata{$thiskey}; - } - $r->print(''); + $r->print(&default_selector($thiskey,$$resourcedata{$thiskey})); } $r->print(''); @@ -2684,6 +2776,117 @@ sub listdata { return $foundkeys; } + +sub date_interval_selector { + my ($thiskey, $showval) = @_; + my $result; + foreach my $which (['days', 86400, 31], + ['hours', 3600, 23], + ['minutes', 60, 59], + ['seconds', 1, 59]) { + my ($name, $factor, $max) = @{ $which }; + my $amount = int($showval/$factor); + $showval %= $factor; + my %select = ((map {$_ => $_} (0..$max)), + 'select_form_order' => [0..$max]); + $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey, + %select); + $result .= ' '.&mt($name); + } + $result .= ''; + return $result; + +} + +sub get_date_interval_from_form { + my ($key) = @_; + my $seconds = 0; + foreach my $which (['days', 86400], + ['hours', 3600], + ['minutes', 60], + ['seconds', 1]) { + my ($name, $factor) = @{ $which }; + if (defined($env{'form.'.$name.'_'.$key})) { + $seconds += $env{'form.'.$name.'_'.$key} * $factor; + } + } + return $seconds; +} + + +sub default_selector { + my ($thiskey, $showval) = @_; + return ''; +} + +my %strings = + ( + 'string_yesno' + => [[ 'yes', 'Yes' ], + [ 'no', 'No' ]], + 'string_problemstatus' + => [[ 'yes', 'Yes' ], + [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ], + [ 'no', 'No, don\'t show correct/incorrect feedback.' ], + [ 'no_feedback_ever', 'No, show no feedback at all.' ]], + ); + + +sub string_selector { + my ($thistype, $thiskey, $showval) = @_; + + if (!exists($strings{$thistype})) { + return &default_selector($thiskey,$showval); + } + + my $result; + foreach my $possibilities (@{ $strings{$thistype} }) { + my ($name, $description) = @{ $possibilities }; + $result .= '