--- loncom/interface/lonparmset.pm 2008/06/20 17:38:51 1.401 +++ loncom/interface/lonparmset.pm 2008/12/12 20:22:33 1.413.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.401 2008/06/20 17:38:51 bisitz Exp $ +# $Id: lonparmset.pm,v 1.413.2.1 2008/12/12 20:22:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -325,14 +325,31 @@ sub date_sanity_info { my $crsprefix='course.'.$env{'request.course.id'}.'.'; if ($env{$crsprefix.'default_enrollment_end_date'}) { if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) { - $result.='
'.&mt('After course enrollment end!'); + $result.='
' + .&mt('After course enrollment end!') + .'
'; } } if ($env{$crsprefix.'default_enrollment_start_date'}) { if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) { - $result.='
'.&mt('Before course enrollment start!'); + $result.='
' + .&mt('Before course enrollment start!') + .'
'; } } +# Preparation for additional warnings about dates in the past/future. +# An improved, more context sensitive version is recommended, +# e.g. warn for due and answer dates which are defined before the corresponding open date, etc. +# if ($checkdate'; +# } +# if ($checkdate>time) { +# $result.='
' +# .'('.&mt('in the future').')' +# .'
'; +# } return $result; } ################################################## @@ -551,27 +568,38 @@ sub valout { } else { if ($type eq 'date_interval') { my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value); + my @timer; $year=$year-70; $mday--; if ($year) { - $result.=$year.' yrs '; +# $result.=&mt('[quant,_1,yr]',$year).' '; + push(@timer,&mt('[quant,_1,yr]',$year)); } if ($mon) { - $result.=$mon.' mths '; +# $result.=&mt('[quant,_1,mth]',$mon).' '; + push(@timer,&mt('[quant,_1,mth]',$mon)); } if ($mday) { - $result.=$mday.' days '; +# $result.=&mt('[quant,_1,day]',$mday).' '; + push(@timer,&mt('[quant,_1,day]',$mday)); } if ($hour) { - $result.=$hour.' hrs '; +# $result.=&mt('[quant,_1,hr]',$hour).' '; + push(@timer,&mt('[quant,_1,hr]',$hour)); } if ($min) { - $result.=$min.' mins '; +# $result.=&mt('[quant,_1,min]',$min).' '; + push(@timer,&mt('[quant,_1,min]',$min)); } if ($sec) { - $result.=$sec.' secs '; +# $result.=&mt('[quant,_1,sec]',$sec).' '; + push(@timer,&mt('[quant,_1,sec]',$sec)); } - $result=~s/\s+$//; +# $result=~s/\s+$//; + if (!@timer) { # Special case: all entries 0 -> display "0 secs" intead of empty field to keep this field editable + push(@timer,&mt('[quant,_1,sec]',0)); + } + $result.=join(", ",@timer); } elsif (&isdateparm($type)) { $result = &Apache::lonlocal::locallocaltime($value). &date_sanity_info($value); @@ -973,7 +1001,7 @@ sub extractResourceInformation { if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) { my $display= &Apache::lonnet::metadata($srcf,$key.'.display'); my $parmdis = $display; - $parmdis =~ s/\[Part.*$//g; + $parmdis =~ s/\s*\[Part.*$//g; $$allparms{$name}=$parmdis; if (ref($defkeytype)) { $$defkeytype{$name}= @@ -985,7 +1013,7 @@ sub extractResourceInformation { # allparts is a hash of all parts # my $part= &Apache::lonnet::metadata($srcf,$key.'.part'); - $$allparts{$part} = "Part: $part"; + $$allparts{$part} = &mt('Part: [_1]',$part); # # Remember all keys going with this resource # @@ -1107,8 +1135,8 @@ ENDSCRIPT if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) { $r->print(' checked'); } - $r->print('>'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey} - : $tempkey) + $r->print('>'.($$allparms{$tempkey}=~/\S/ ? &mt($$allparms{$tempkey}) + : &mt($tempkey)) .''); $cnt++; if ($cnt==3) { @@ -1116,21 +1144,46 @@ ENDSCRIPT $cnt=0; } } - $r->print(' - -Select All
-Select Common Only - -Add Problem Dates -Add Content Dates
-Add Discussion Settings -Add Visibilities
-Add Part Parameters - -Unselect All - -'); - $r->print(''); + $r->print('' + .'' + .'' + .'
'.&mt('Parameter Selection').'' + .'' + .'• '.&mt('Select All').'' + .'' + .'
' + .'' + .'• '.&mt('Select Common Only').'' + .'' + .'
' + .'' + .'• '.&mt('Unselect All').'' + .'' + .'
' + .'' + .'' + .'
'.&mt('Add Selection for...').'' + .'' + .'• '.&mt('Problem Dates').'' + .'' + .'' + .' • '.&mt('Content Dates').'' + .'' +# .'
' + .'' + .' • '.&mt('Discussion Settings').'' + .'' + .'' + .' • '.&mt('Visibilities').'' + .'' +# .'
' + .'' + .' • '.&mt('Part Parameters').'' + .'' + .'
' + .'' + .'' + ); } sub partmenu { @@ -1160,21 +1213,18 @@ sub usermenu { my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '. &Apache::loncommon::selectstudent_link('parmform','uname','udom'); my $selscript=&Apache::loncommon::studentbrowser_javascript(); - my %lt=&Apache::lonlocal::texthash( - 'se' => "Section", - 'gr' => "Group", - 'fu' => "For User", - 'oi' => "or ID", - 'ad' => "at Domain" - ); + my $sections=''; my %sectionhash = &Apache::loncommon::get_sections(); my $groups; my %grouphash = &Apache::longroup::coursegroups(); + my $g_s_header=''; + my $g_s_footer=''; + if (%sectionhash) { - $sections=$lt{'se'}.': print(< -$sections -$groups -
-$lt{'fu'} - -$lt{'oi'} - -$lt{'ad'} -$chooseopt - -ENDMENU + + if (%sectionhash || %grouphash) { + $g_s_header='
'.&mt('Group/Section').'
'; + $g_s_footer='
'; + } + + $r->print('' + .$g_s_header + .$sections + .$groups + .$g_s_footer + .'
'.&mt('User').'
' + .&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]' + ,'' + ,' ' + ,$chooseopt) + .'
' + .'
' + ); } sub displaymenu { @@ -1256,7 +1313,7 @@ sub displaymenu { $r->print('
'.&mt('Select Parameters to View').''. &mt('Select Parts to View').'
'); &parmmenu($r,$allparms,$pscat,$keyorder); - $r->print(''); + $r->print(''); &partmenu($r,$allparts,$psprt); $r->print('
'); } @@ -1899,7 +1956,7 @@ ENDTABLEHEADFOUR } $r->print('

' .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]' - ,$foldermap.'
$showtitle
' + ,$foldermap.'
'.$showtitle.'
' ,$tmp ,''.$coursename.'' ) @@ -2126,6 +2183,8 @@ sub crsenv { $setoutput.=&mt('Set').' '.$name.' '.&mt('to').' '; if ($name =~ /^default_enrollment_(start|end)_date$/) { $setoutput .= &Apache::lonlocal::locallocaltime($value); + } elsif ($name eq 'categories') { + $setoutput .= $env{'form.categories_display'}; } else { $setoutput .= $value; } @@ -2134,11 +2193,12 @@ sub crsenv { &change_clone($value,\@oldcloner); } # Update environment and nohist_courseids.db - if ($name eq 'description' || $name eq 'cloners') { + if (($name eq 'description') || ($name eq 'cloners') || + ($name eq 'hidefromcat') || ($name eq 'categories')) { if ($chome eq '') { %crsinfo = &Apache::lonnet::courseiddump($dom,'.',1,'.','.', - $crs,undef,undef,'Course'); + $crs,undef,undef,'.'); $chome = &Apache::lonnet::homeserver($crs,$dom); } } @@ -2151,9 +2211,10 @@ sub crsenv { $chome,'notime'); } } - if ($name eq 'cloners') { + if (($name eq 'cloners') || ($name eq 'hidefromcat') || ($name eq 'categories')) { if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') { - $crsinfo{$env{'request.course.id'}}{'cloners'} = $value; + &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$name => $value}); + $crsinfo{$env{'request.course.id'}}{$name} = $value; my $putresult = &Apache::lonnet::courseidput($dom,\%crsinfo, $chome,'notime'); @@ -2209,6 +2270,7 @@ sub crsenv { my $SelectStyleFile=&mt('Select Style File'); my $SelectSpreadsheetFile=&mt('Select Spreadsheet File'); my $output=''; + my $can_categorize; if (! exists($values{'con_lost'})) { my %descriptions= ('url' => ''.&mt('Top Level Map').'
'. @@ -2345,12 +2407,29 @@ sub crsenv { 'suppress_embed_prompt' => ''.&mt('Suppress prompt to upload items referenced in a web page being uploaded to portfolio, when current role is student.').'
'. - ' ('.&mt('[_1] to suppress, anything else to not suppress','"yes"').')', - ); - my @Display_Order = ('url','description','courseid','cloners','grading', + ' ('.&mt('[_1] to suppress, anything else to not suppress','"yes"').')', + 'hidefromcat' + => ''.&mt('Exclude from course catalog').'
'. + ' ('.&mt('[_1] to exclude, anything else to include - included if assigned an institutional code, or manually catagorized','"yes"').')', + 'categories' + => ''.&mt('Categorize course').' '. + &mt('Display Categories').'', + 'datelocale' + => ''.&mt('Locale used for course calendar').'', + ); + my @Display_Order = ('url','description','courseid','cloners'); + (my $can_toggle_cat,$can_categorize) = &can_modify_catsettings($dom); + if ($can_toggle_cat) { + push(@Display_Order,'hidefromcat'); + } + if ($can_categorize) { + push(@Display_Order,'categories'); + } + push (@Display_Order,('grading', 'externalsyllabus', 'default_xml_style','pageseparators', - 'question.email','question.email.text','comment.email','comment.email.text','policy.email','policy.email.text', + 'question.email','question.email.text','comment.email', + 'comment.email.text','policy.email','policy.email.text', 'student_classlist_view', 'student_classlist_opt_in', 'student_classlist_portfiles', @@ -2360,6 +2439,7 @@ sub crsenv { 'allow_discussion_post_editing', 'languages', 'timezone', + 'datelocale', 'nothideprivileged', 'rndseed', 'receiptalg', @@ -2379,10 +2459,11 @@ sub crsenv { 'texengine', 'disablesigfigs', 'disableexampointprint', - 'task_messages','task_grading', - ); + 'task_messages','task_grading')); foreach my $parameter (sort(keys(%values))) { - unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./)) { + unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) || + ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/) + || ($parameter eq 'type')) { if (! $descriptions{$parameter}) { $descriptions{$parameter}=$parameter; push(@Display_Order,$parameter); @@ -2412,6 +2493,32 @@ sub crsenv { &Apache::loncommon::select_timezone($parameter.'_value', $timezone, $onchange,$includeempty).''; + } elsif ($parameter eq 'datelocale') { + my $includeempty = 1; + my $locale_obj = &Apache::lonlocal::getdatelocale(); + my $currdatelocale; + if (ref($locale_obj)) { + $currdatelocale = $locale_obj->id(); + } + $output .= ''. + &Apache::loncommon::select_datelocale($parameter.'_value', + $currdatelocale, + $onchange,$includeempty).''; + } elsif ($parameter eq 'categories') { + my $catdisplay; + if ($values{'categories'} ne '') { + my @curritems = split(/\&/,$values{'categories'}); + foreach my $item (@curritems) { + my ($name,$parent,$pos) = split(/:/,$item); + $catdisplay .= &unescape($name).'&'; + } + $catdisplay =~ s/\&$//; + } + $output .= ''. + ''. + ''; } else { $output .= ''. &Apache::lonhtmlcommon::textbox($parameter.'_value', @@ -2445,14 +2552,26 @@ sub crsenv { my $Parameter=&mt('Parameter'); my $Value=&mt('Value'); my $Set=&mt('Set'); - my $browse_js= - ''; - + my ($jscript,$categorize_js); + my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset'); + if ($can_categorize) { + $categorize_js = <'; my $start_page = &Apache::loncommon::start_page('Set Course Environment', - $browse_js); + $jscript); my $end_page = &Apache::loncommon::end_page(); my $end_table=&Apache::loncommon::end_data_table(); @@ -2473,6 +2592,98 @@ $end_table $end_page ENDENV } + +sub can_modify_catsettings { + my ($dom) = @_; + my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom); + my ($can_toggle_cat,$can_categorize); + if (ref($domconf{'coursecategories'}) eq 'HASH') { + if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') { + $can_toggle_cat = 1; + } + if ($domconf{'coursecategories'}{'categorize'} eq 'crs') { + $can_categorize = 1; + } + } + return ($can_toggle_cat,$can_categorize); +} + +sub assign_course_categories { + my ($r) = @_; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $hascats = 0; + my $cathash; + my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); + if (ref($domconf{'coursecategories'}) eq 'HASH') { + $cathash = $domconf{'coursecategories'}{'cats'}; + if (ref($cathash) eq 'HASH') { + $hascats = 1; + } + } + my $catwin_js; + if ($hascats) { + my $alert = &mt('Use \"Save\" in the main window to save course categories'); + $catwin_js = < + +function updateCategories() { + var newcategories = ''; + var unescapedcats = ''; + if (document.chgcats.usecategory.length) { + for (var i=0; i 0) { + newcategories = newcategories.slice(0,-1); + } + if (unescapedcats.length > 0) { + unescapedcats = unescapedcats.slice(0,-3); + } + } else { + if (document.chgcats.usecategory.checked == true) { + newcategories = document.chgcats.usecategory.value; + unescapedcats = document.chgcats.catname.value; + } + } + opener.document.envform.categories_value.value = newcategories; + opener.document.envform.categories_display.value = unescapedcats; + opener.document.envform.categories_setparmval.checked = true; + alert("$alert"); + self.close(); + return; +} + + +ENDSCRIPT + } else { + my $onload; + } + my $start_page = + &Apache::loncommon::start_page('Course Categories',$catwin_js, + {'only_body' => 1,}); + my $end_page = &Apache::loncommon::end_page(); + my $categoriesform = '

'.&mt('Categorize Course').'

'; + if ($hascats) { + my %currsettings = + &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum); + $categoriesform .= &mt('Assign one or more categories to this course.').'

'. + '
'."\n" + .&Apache::loncommon::assign_categories_table($cathash, + $currsettings{'categories'})."\n" + .'

'; + } else { + $categoriesform .= &mt('No categories defined for this domain'); + } + $r->print($start_page.$categoriesform.$end_page); + return; +} + ################################################## # Overview mode ################################################## @@ -2767,8 +2978,8 @@ sub listdata { $$resourcedata{$thiskey}, '',1,'',''). ''. -(($$resourcedata{$thiskey}!=0)?''. -&mt('Shift all dates based on this date').'':''). +(($$resourcedata{$thiskey}!=0)?''. +&mt('Shift all dates based on this date').'':''). &date_sanity_info($$resourcedata{$thiskey}) ); } elsif ($thistype eq 'date_interval') { @@ -3118,7 +3329,7 @@ ENDOVER $r->print('

'. &mt('These parameters refer to resources that do not exist.'). '

'. - ''.'
'. + ''.'
'. '
'); $r->print(&Apache::loncommon::start_data_table(). ''. @@ -3171,7 +3382,7 @@ ENDOVER } } $r->print(&Apache::loncommon::end_data_table().'

'. - ''. + ''. '

'. &Apache::loncommon::end_page()); } @@ -4334,7 +4545,9 @@ sub handler { &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'}, text=>"Shifting Dates"}); &date_shift_two($r); - } + } elsif ($env{'form.action'} eq 'categorizecourse' && $parm_permission) { + &assign_course_categories($r); + } } else { # ----------------------------- Not in a course, or not allowed to modify parms if ($exists) {