--- loncom/interface/lonuserutils.pm 2007/12/01 04:18:04 1.7 +++ loncom/interface/lonuserutils.pm 2007/12/05 16:49:55 1.8 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.7 2007/12/01 04:18:04 albertel Exp $ +# $Id: lonuserutils.pm,v 1.8 2007/12/05 16:49:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,7 +35,8 @@ use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon; use Apache::lonlocal; -use LONCAPA(); +use Apache::longroup; +use LONCAPA qw(:DEFAULT :match); ############################################################### ############################################################### @@ -2873,12 +2874,34 @@ sub expire_user_list { $r->print('

'.&mt('Re-enrollment will re-activate data.')) if ($count); } -sub section_check_js { - my $groupslist; - my %curr_groups = &Apache::longroup::coursegroups(); - if (%curr_groups) { - $groupslist = join('","',sort(keys(%curr_groups))); +sub classlist_drop { + my ($scope,$uname,$udom,$now,$action) = @_; + my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); + my $cid=$cdom.'_'.$cnum; + my $user = $uname.':'.$udom; + if ($action eq 'drop') { + if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { + my $result = + &Apache::lonnet::cput('classlist', + { $user => $now }, + $env{'course.'.$cid.'.domain'}, + $env{'course.'.$cid.'.num'}); + return &mt('Drop from classlist: [_1]', + ''.$result.'').'
'; + } } +} + +sub active_student_roles { + my ($cnum,$cdom,$uname,$udom) = @_; + my %roles = + &Apache::lonnet::get_my_roles($uname,$udom,'userroles', + ['future','active'],['st']); + return exists($roles{"$cnum:$cdom:st"}); +} + +sub section_check_js { + my $groupslist= &get_groupslist(); return <<"END"; function validate(caller) { var groups = new Array("$groupslist"); @@ -2928,5 +2951,144 @@ sub set_login { return $response; } +sub course_sections { + my ($sections_count,$role) = @_; + my $output = ''; + my @sections = (sort {$a <=> $b} keys %{$sections_count}); + if (scalar(@sections) == 1) { + $output = ''."\n"; + foreach my $sec (@sections) { + $output .= '\n"; + } + } + $output .= ''; + return $output; +} + +sub get_groupslist { + my $groupslist; + my %curr_groups = &Apache::longroup::coursegroups(); + if (%curr_groups) { + $groupslist = join('","',sort(keys(%curr_groups))); + $groupslist = '"'.$groupslist.'"'; + } + return $groupslist; +} + +sub setsections_javascript { + my ($form,$groupslist) = @_; + my ($checkincluded,$finish,$roleplace,$setsection_js); + if ($form eq 'cu') { + $checkincluded = 'formname.elements[i-1].checked == true'; + $finish = 'formname.submit()'; + $roleplace = 3; + } else { + $checkincluded = 'formname.name == "'.$form.'"'; + $finish = "seccheck = 'ok';"; + $roleplace = 1; + $setsection_js = "var seccheck = 'alert';"; + } + my %alerts = &Apache::lonlocal::texthash( + secd => 'Section designations do not apply to Course Coordinator roles.', + accr => 'A course coordinator role will be added with access to all sections.', + inea => 'In each course, each user may only have one student role at a time.', + youh => 'You had selected ', + secs => 'sections.', + plmo => 'Please modify your selections so they include no more than one section.', + mayn => 'may not be used as the name for a section, as it is a reserved word.', + plch => 'Please choose a different section name.', + mnot => 'may not be used as a section name, as it is the name of a course group.', + secn => 'Section names and group names must be distinct. Please choose a different section name.', + ); + $setsection_js .= <<"ENDSECCODE"; + +function setSections(formname) { + var re1 = /^currsec_/; + var groups = new Array($groupslist); + for (var i=0;i 0) { + if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) { + sections = sections + "," + formname.elements[i+1].value; + } + } + else { + sections = formname.elements[i+1].value; + } + var newsecs = formname.elements[i+1].value; + var numsplit; + if (newsecs != null && newsecs != "") { + numsplit = newsecs.split(/,/g); + numsec = numsec + numsplit.length; + } + + if ((role == 'st') && (numsec > 1)) { + alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}") + return; + } + else { + if (numsplit != null) { + for (var j=0; j