--- loncom/interface/lonrequestcourse.pm 2009/09/07 06:30:49 1.30 +++ loncom/interface/lonrequestcourse.pm 2009/09/11 12:53:10 1.35 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.30 2009/09/07 06:30:49 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.35 2009/09/11 12:53:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -527,9 +527,9 @@ sub form_elements { ); if ($env{'form.sectotal'} > 0) { for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - $extras{'sec_'.$i} = 'checkbox', - $extras{'secnum_'.$i} = 'text', - $extras{'loncapasec_'.$i} = 'text', + $extras{'sec_'.$i} = 'radio'; + $extras{'secnum_'.$i} = 'text'; + $extras{'loncapasec_'.$i} = 'text'; } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -631,7 +631,7 @@ sub course_types { official => 'Official course', unofficial => 'Unofficial course', community => 'Community', - ); + ); return (\@types,\%typename); } @@ -724,7 +724,9 @@ END END - $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.'
'. + $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb. + '

'.&mt('Request creation of a new course, or review your pending course requests.').'

'. + '
'. &Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_title(&mt('Course Domain')). '
'. @@ -755,7 +757,7 @@ END if ($type eq 'official') { $selected = ' selected="selected"'; } - $r->print(''."\n"); } } @@ -800,8 +802,15 @@ END } if ($action eq 'new') { my $jsextra; - unless (($state eq 'review') || ($state eq 'process')) { + if ($state eq 'courseinfo') { $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom); + } elsif ($state eq 'enrollment') { + if (($env{'form.crstype'} eq 'official') && + (&Apache::lonnet::auto_run('',$dom))) { + $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js(); + } + } elsif ($state eq 'personnel') { + $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js(); } $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb); &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode, @@ -849,8 +858,8 @@ END other => 'Modify Request', next => 'Cancel Request', ); - &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'}, - $state,$other,$navtxt{'other'}); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state,$other,$navtxt{'other'}); $r->print('
'); } elsif ($state eq 'cancel') { my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'}); @@ -863,10 +872,11 @@ END next => 'Confirm Cancellation', ); if ($result eq 'ok') { - &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next, + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, $navtxt{'next'},$state); } else { - &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},undef,'',$state); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef, + '',$state); } $r->print(''); } elsif ($state eq 'removal') { @@ -929,6 +939,166 @@ END return; } +sub enrollment_lcsec_js { + my %alerts = §ion_check_alerts(); + my $secname = $alerts{'badsec'}; + my $secnone = $alerts{'reserved'}; + my $output = ' +function validateEnrollSections(formname,nextstate) { + var badsectotal = 0; + var reservedtotal = 0; + var secTest = ""; +'; + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + $output .= " + var selSec = 0; + for (var j=0; j "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.", + badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.', + separate => 'Separate multiple sections with a comma.' + ); + return %lt; +} + +sub section_check_javascript { + return <<"END"; +function validsection(field,mult) { + var str = field.value; + var badsec=0; + var reserved=0; + if (window.RegExp) { + var badsecnum=0; + var reservednum=0; + var pattern=/[^a-zA-Z0-9]/; + str = str.replace(/(^\\s*)|(\\s*\$)/gi,""); + str = str.replace(/[ ]{2,}/gi," "); + if (mult == '1') { + var sections = new Array(); + sections = str.split(/\\s*[\\s,;:]\\s*/); + var i; + for (i=0; i 0) { + return 'badsec'; + } + if (reservednum > 0) { + return 'reserved'; + } + } + return; +} +END +} + sub close_popup_form { my $close= &mt('Close Window'); return << "END"; @@ -966,7 +1136,7 @@ sub print_request_form { next => 'Next', ); $crstype = $env{'form.crstype'}; - $r->print('
'); + $r->print('
'); my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk, @disallowed); if ($crstype eq 'official') { @@ -1003,7 +1173,9 @@ sub print_request_form { $codepicker = &coursecode_form($dom,'instcode',\@codetitles, \%cat_titles,\%cat_order); if ($codepicker) { - $r->print('
'.&Apache::lonhtmlcommon::start_pick_box().$codepicker. + $r->print(&mt('Specify the course to be created.'). + '
'.&Apache::lonhtmlcommon::start_pick_box(). + $codepicker. &Apache::lonhtmlcommon::end_pick_box().'
'); } else { $next = $states->{$action}[$page+2]; @@ -1168,7 +1340,8 @@ sub print_request_form { push(@excluded,'crosslisttotal'); } $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state); return; } @@ -1242,7 +1415,7 @@ sub get_excluded_elements { sub print_enrollment_menu { my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order, $invalidcrosslist) =@_; - my ($sections,$autoenroll,$access_dates,$output); + my ($sections,$autoenroll,$access_dates,$output,$hasauto); my $starttime = time; my $endtime = time+(6*30*24*60*60); # 6 months from now, approx @@ -1261,7 +1434,8 @@ sub print_enrollment_menu { $section_form = &inst_section_selector($dom,$instcode); if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). - '

'.&mt('Sections for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). + ' '.&mt('Sections for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $section_form; } @@ -1288,26 +1462,29 @@ sub print_enrollment_menu { &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } + $hasauto = 1; $autoenroll = - &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')). + &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')). ''.(' 'x3).''. &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')). + &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')). ''.(' 'x3).''. &Apache::lonhtmlcommon::row_closure(1). - &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles); + &date_setting_table($starttime,$endtime,$formname,'enroll', + $hasauto,%enrolltitles); } } my $access_dates = - &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles); + &date_setting_table($starttime,$endtime,$formname,'access',$hasauto, + %accesstitles); $output .= &Apache::lonhtmlcommon::start_pick_box(); if ($sections) { $output .= $sections; @@ -1361,18 +1538,23 @@ sub inst_section_selector { ''.&mt('Include?').''. ''.&mt('Institutional Section').''. - ''.&mt('LON-CAPA section').''. + ''.&Apache::loncommon::help_open_topic('Course_Request_LCSection'). + ' '.&mt('LON-CAPA section').''. &Apache::loncommon::end_data_table_row(); for (my $i=0; $i<@sections; $i++) { my $colflag = $i%2; - my $checked = ' checked="checked"'; + my $secon = ' checked="checked"'; + my $secoff = ''; if ($env{'form.origcnum'}) { - $checked=''; + $secoff = $secon; + $secon=''; } $output .= &Apache::loncommon::start_data_table_row(). - ''. - ''.$sections[$i]. + ''. + (' 'x2).''. + ''.$sections[$i]. ''. ''.&mt('First Name').'
'.$form_elems{'firstname'}.''."\n". ''.&mt('Last Name').'
'.$form_elems{'lastname'}.''."\n". ''.&mt('E-mail').'
'.$form_elems{'emailaddr'}.''."\n". - ''.&mt('Role').'
'.$roleselector.''."\n". - ''.&mt('Section(s)').'
'.$sectionselector.''."\n". + ''.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'
'.$roleselector.''."\n". + ''. + &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'
'.$sectionselector.''."\n". ''.&Apache::lonhtmlcommon::row_closure(); } $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')). @@ -1518,7 +1722,8 @@ sub print_personnel_menu { ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box().'
'; + &Apache::lonhtmlcommon::end_pick_box().'
'. + '

'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'

'; return $output; } @@ -1526,10 +1731,12 @@ sub current_lc_sections { my @currsecs; if ($env{'form.sectotal'}) { for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - if (defined($env{'form.loncapasec_'.$i})) { - my $lcsec = $env{'form.loncapasec_'.$i}; - unless (grep(/^\Q$lcsec\E$/,@currsecs)) { - push(@currsecs,$lcsec); + if ($env{'form.sec_'.$i}) { + if (defined($env{'form.loncapasec_'.$i})) { + my $lcsec = $env{'form.loncapasec_'.$i}; + unless (grep(/^\Q$lcsec\E$/,@currsecs)) { + push(@currsecs,$lcsec); + } } } } @@ -1541,14 +1748,8 @@ sub print_request_status { my ($dom) = @_; my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, $env{'user.name'},'^status:'.$dom); - my ($output,$formname,%queue_by_date,%typenames); - if ($env{'form.crstype'} eq 'any') { - %typenames = &Apache::lonlocal::texthash ( - official => 'Official course', - unofficial => 'Unofficial course', - community => 'Community', - ); - } + my ($output,$formname,%queue_by_date); + my ($types,$typenames) = &course_types(); foreach my $key (keys(%statusinfo)) { if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { (undef,my($cdom,$cnum)) = split(':',$key); @@ -1619,7 +1820,10 @@ sub print_request_status { ''.&unescape($desc).''. ''.$cdom.''; if ($env{'form.crstype'} eq 'any') { - my $typename = $typenames{$type}; + my $typename; + if (ref($typenames) eq 'HASH') { + $typename = &mt($typenames->{$type}); + } if ($typename eq '') { $typename = &mt('Unknown type'); } @@ -1772,7 +1976,7 @@ sub print_review { $crstypename = $env{'form.crstype'}; if (ref($typename) eq 'HASH') { unless ($typename->{$env{'form.crstype'}} eq '') { - $crstypename = $typename->{$env{'form.crstype'}}; + $crstypename = &mt($typename->{$env{'form.crstype'}}); } } my $category = 'Course'; @@ -1933,14 +2137,22 @@ sub print_review { if (ref($disallowed) eq 'ARRAY') { next if (grep(/^$i$/,@{$disallowed})); } - my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec'); + my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec'); + my @allsecs; + foreach my $sec (@officialsecs) { + next unless ($sec =~ /\w/); + next if ($sec =~ /\W/); + next if ($sec eq 'none'); + push(@allsecs,$sec); + } my $newsec = $env{'form.person_'.$i.'_newsec'}; $newsec =~ s/^\s+//; $newsec =~s/\s+$//; - my @newsecs = split(/[\s,;]+/,$newsec); + my @newsecs = split(/\s*[\s,;:]\s*/,$newsec); foreach my $sec (@newsecs) { + next unless ($sec =~ /\w/); next if ($sec =~ /\W/); - next if ($newsec eq 'none'); + next if ($sec eq 'none'); if ($sec ne '') { unless (grep(/^\Q$sec\E$/,@allsecs)) { push(@allsecs,$sec); @@ -2027,14 +2239,18 @@ sub dates_from_form { sub courseinfo_form { my ($dom,$formname,$crstype,$next) = @_; - my $nodescr = &mt('You must provide a (brief) course description.'); + my %lt = &Apache::lonlocal::texthash( + official => 'You must provide a (brief) course description.', + community => 'You must provide a (brief) community description.' + ); + $lt{'unofficial'} = $lt{'official'}; my $js_validate = <<"ENDJS";