--- loncom/interface/lonuserutils.pm 2008/01/20 00:19:11 1.49 +++ loncom/interface/lonuserutils.pm 2008/05/19 17:10:19 1.55 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.49 2008/01/20 00:19:11 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.55 2008/05/19 17:10:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,7 @@ use LONCAPA qw(:DEFAULT :match); ############################################################### # Drop student from all sections of a course, except optional $csec sub modifystudent { - my ($udom,$unam,$courseid,$csec,$desiredhost)=@_; + my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_; # if $csec is undefined, drop the student from all the courses matching # this one. If $csec is defined, drop them from all other sections of # this course and add them to section $csec @@ -69,7 +69,7 @@ sub modifystudent { # dom name id mode pass f m l g ($udom,$unam,'', '', '',undef,undef,undef,undef, $section,time,undef,undef,$desiredhost,'','manual', - '',$courseid); + '',$courseid,'',$context); $result .= $reply.':'; } } @@ -129,7 +129,8 @@ sub modifyuserrole { if ($role ne '') { $role =~ s/_/\//g; $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope, - $role,$end,$start); + $role,$end,$start,'', + '',$context); } } return ($userresult,$authresult,$roleresult,$idresult); @@ -924,8 +925,15 @@ sub setup_date_selectors { sub get_dates_from_form { - my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate'); - my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate'); + my ($startname,$endname) = @_; + if ($startname eq '') { + $startname = 'startdate'; + } + if ($endname eq '') { + $endname = 'enddate'; + } + my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname); + my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname); if ($env{'form.no_end_date'}) { $enddate = 0; } @@ -1251,34 +1259,11 @@ sub print_userlist { if ($env{'form.showrole'} eq 'Any') { $roleselected = ' selected="selected" '; } - my ($role_select,$cnum,$cdom); - if ($context eq 'domain') { - $role_select = &domain_roles_select(); - $r->print(''); - } else { - $role_select = ''; - $r->print(''); - if ($context eq 'course') { - ($cnum,$cdom) = &get_course_identity(); - $r->print(§ion_group_filter($cnum,$cdom)); - } + my ($cnum,$cdom); + $r->print(&role_filter($context)); + if ($context eq 'course') { + ($cnum,$cdom) = &get_course_identity(); + $r->print(§ion_group_filter($cnum,$cdom)); } if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) { $r->print(' '.&list_submit_button(&mt('Update Display')). @@ -1450,6 +1435,41 @@ sub print_userlist { $env{'form.phase'}.'" />'); } +sub role_filter { + my ($context) = @_; + my $output; + my $roleselected = ''; + if ($env{'form.showrole'} eq 'Any') { + $roleselected = ' selected="selected" '; + } + my ($role_select); + if ($context eq 'domain') { + $role_select = &domain_roles_select(); + $output = ''; + } else { + $role_select = ''; + $output = ''; + } + return $output; +} + sub section_group_filter { my ($cnum,$cdom) = @_; my @filters; @@ -1513,6 +1533,10 @@ sub list_submit_button { sub gather_userinfo { my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_; + my $viewablesec; + if ($context eq 'course') { + $viewablesec = &viewable_section($permission); + } foreach my $item (keys(%{$rolehash})) { my %userdata; if ($context eq 'author') { @@ -1522,7 +1546,6 @@ sub gather_userinfo { &build_user_record($context,\%userdata,$userinfo,$indexhash, $item,$userlist); } elsif ($context eq 'course') { - my $viewablesec = &viewable_section($permission); ($userdata{'username'},$userdata{'domain'},$userdata{'role'}, $userdata{'section'}) = split(/:/,$item,-1); ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item}); @@ -1840,7 +1863,10 @@ sub process_date_info { } sub show_users_list { - my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_; + my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_; + if ($formname eq '') { + $formname = 'studentform'; + } # # Variables for excel output my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format); @@ -1855,6 +1881,9 @@ sub show_users_list { } else { push(@sortable,'extent'); } + if ($mode eq 'pickauthor') { + @sortable = ('username','fullname','email','status'); + } if (!grep(/^\Q$sortby\E$/,@sortable)) { $sortby = 'username'; } @@ -1895,7 +1924,7 @@ function photowindow(photolink) { END } } - if ($mode ne 'autoenroll') { + if ($mode ne 'autoenroll' && $mode ne 'pickauthor') { my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript(); my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox"); my $singconfirm = &mt(' for a single user?'); @@ -1937,8 +1966,8 @@ function verify_action (field) { alert("$alert"); } else { - var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text; - var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value; + var message = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].text; + var choice = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].value; if (numchecked == 1) { message += singconf; } @@ -1947,14 +1976,14 @@ function verify_action (field) { } if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') { var datemsg = ''; - if ((document.studentform.startdate_month.value == '') && - (document.studentform.startdate_day.value == '') && - (document.studentform.startdate_year.value == '')) { + if ((document.$formname.startdate_month.value == '') && + (document.$formname.startdate_day.value == '') && + (document.$formname.startdate_year.value == '')) { datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n"; } - if ((document.studentform.enddate_month.value == '') && - (document.studentform.enddate_day.value == '') && - (document.studentform.enddate_year.value == '')) { + if ((document.$formname.enddate_month.value == '') && + (document.$formname.enddate_day.value == '') && + (document.$formname.enddate_year.value == '')) { datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n"; } if (datemsg != '') { @@ -1962,9 +1991,9 @@ function verify_action (field) { } } if (choice == 'chgsec') { - var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value; - var retained = document.studentform.retainsec.value; - var secshow = document.studentform.newsecs.value; + var rolefilter = document.$formname.showrole.options[document.$formname.showrole.selectedIndex].value; + var retained = document.$formname.retainsec.value; + var secshow = document.$formname.newsecs.value; if (secshow == '') { if (rolefilter == 'st' || retained == 0 || retained == "") { message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; @@ -1980,33 +2009,44 @@ function verify_action (field) { } } if (confirm(message)) { - document.studentform.phase.value = 'bulkchange'; - document.studentform.submit(); + document.$formname.phase.value = 'bulkchange'; + document.$formname.submit(); } } } function username_display_launch(username,domain) { var target; - for (var i=0; i @@ -2041,7 +2081,7 @@ END 'ac' => "Action to take for selected users", 'link' => "Behavior of username links", 'aboutme' => "Display a user's personal page", - 'aboutmewin' => "Display a user's personal page in a new window", + 'owin' => "Open in a new window", 'modify' => "Modify a user's information", ); if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { @@ -2049,28 +2089,33 @@ END } elsif ($context eq 'author') { $lt{'extent'} = &mt('Author'); } - my @cols = ('username','domain','id','fullname'); - if ($context eq 'course') { - push(@cols,'section'); - } - if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { - push(@cols,('start','end')); - } - if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') { - push(@cols,'role'); - } - if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' || - $env{'form.roletype'} eq 'course')) { - push (@cols,'extent'); - } - if (($statusmode eq 'Any') && - (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) { - push(@cols,'status'); - } - if ($context eq 'course') { - push(@cols,'groups'); + my @cols; + if ($mode eq 'pickauthor') { + @cols = ('username','fullname','status','email'); + } else { + @cols = ('username','domain','id','fullname'); + if ($context eq 'course') { + push(@cols,'section'); + } + if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { + push(@cols,('start','end')); + } + if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') { + push(@cols,'role'); + } + if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' || + $env{'form.roletype'} eq 'course')) { + push (@cols,'extent'); + } + if (($statusmode eq 'Any') && + (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) { + push(@cols,'status'); + } + if ($context eq 'course') { + push(@cols,'groups'); + } + push(@cols,'email'); } - push(@cols,'email'); my $rolefilter = $env{'form.showrole'}; if ($env{'form.showrole'} eq 'cr') { @@ -2085,10 +2130,10 @@ END $r->print(''.$results_description.'
'); } my ($output,$actionselect,%canchange,%canchangesec); - if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') { - if ($mode ne 'autoenroll') { + if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') { + if ($mode ne 'autoenroll' && $mode ne 'pickauthor') { if ($permission->{'cusr'}) { - $actionselect = &select_actions($context,$setting,$statusmode); + $actionselect = &select_actions($context,$setting,$statusmode,$formname); } $r->print(< @@ -2098,7 +2143,7 @@ END END $output = '

'; - my @linkdests = ('aboutme','aboutmewin'); + my @linkdests = ('aboutme'); if ($permission->{'cusr'}) { unshift (@linkdests,'modify'); } @@ -2114,12 +2159,16 @@ END } $output .= '  '; } - $output .= '
'; + my $checkwin; + if ($env{'form.userwin'}) { + $checkwin = 'checked = "checked"'; + } + $output .= '    '.$lt{'owin'}.'
'; if ($actionselect) { $output .= <<"END"; -$lt{'ac'}: $actionselect

-

  -

+$lt{'ac'}: $actionselect

+

  +

END my @allroles; if ($env{'form.showrole'} eq 'Any') { @@ -2167,16 +2216,20 @@ END &Apache::loncommon::start_data_table_header_row(); if ($mode eq 'autoenroll') { $output .= " - $lt{'type'} + $lt{'type'} "; } else { - $output .= "\n".''.&mt('Count').''."\n"; + if ($mode eq 'pickauthor') { + $output .= "\n".' '."\n"; + } else { + $output .= "\n".''.&mt('Count').''."\n"; + } if ($actionselect) { $output .= ''.&mt('Select').''."\n"; } } foreach my $item (@cols) { - $output .= "$lt{$item}\n"; + $output .= "$lt{$item}\n"; } my %role_types = &role_type_names(); if ($context eq 'course' && $mode ne 'autoenroll') { @@ -2191,8 +2244,8 @@ END $clickerchg = 'off'; } $output .= ' '."\n".' '. - ''. + ''. $clicker_options{$clickerchg}.' '.$lt{'clicker'}."\n". ' '."\n"; @@ -2207,8 +2260,8 @@ END $photochg = 'off'; } $output .= ' '."\n".' '. - ''. + ''. $photo_options{$photochg}.' '.$lt{'photo'}."\n". ' '."\n"; } @@ -2407,7 +2460,7 @@ END } else { $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); } - if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { + if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') { $r->print(&Apache::loncommon::start_data_table_row()); my $checkval; if ($mode eq 'autoenroll') { @@ -2429,7 +2482,9 @@ END } $r->print("$cellentry\n"); } else { - $r->print("$rowcount\n"); + if ($mode ne 'pickauthor') { + $r->print("$rowcount\n"); + } if ($actionselect) { my $showcheckbox; if ($role =~ /^cr\//) { @@ -2463,6 +2518,8 @@ END } else { $r->print(' '); } + } elsif ($mode eq 'pickauthor') { + $r->print(''); } } foreach my $item (@cols) { @@ -2530,7 +2587,7 @@ END $row++; } } - if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { + if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') { $r->print(&Apache::loncommon::end_data_table().'
'); } elsif ($mode eq 'excel') { $excel_workbook->close(); @@ -2573,7 +2630,7 @@ sub role_type_names { } sub select_actions { - my ($context,$setting,$statusmode) = @_; + my ($context,$setting,$statusmode,$formname) = @_; my %lt = &Apache::lonlocal::texthash( revoke => "Revoke user roles", delete => "Delete user roles", @@ -2634,7 +2691,7 @@ sub select_actions { } } if ($options) { - $output = ''."\n". ''."\n".$options."\n".''; if ($choices{'dates'}) { @@ -3642,13 +3699,14 @@ sub upfile_drop_add { $sec = $secs[0]; } &modifystudent($domain,$username,$cid,$sec, - $desiredhost); + $desiredhost,$context); $roleresult = &Apache::lonnet::modifystudent ($domain,$username,$id,$amode,$password, $fname,$mname,$lname,$gen,$sec,$enddate, $startdate,$env{'form.forceid'}, - $desiredhost,$email,'manual','',$cid); + $desiredhost,$email,'manual','',$cid, + '',$context); $userresult = $roleresult; } else { if ($role ne '') { @@ -3954,24 +4012,25 @@ sub update_user_list { $end = $now; $type = 'manual'; $result = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context); } elsif ($choice eq 'revoke') { # revoke or delete user role $end = $now; if ($role eq 'st') { $result = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context); } else { $result = - &Apache::lonnet::revokerole($udom,$uname,$scope,$role); + &Apache::lonnet::revokerole($udom,$uname,$scope,$role, + '','',$context); } } elsif ($choice eq 'delete') { if ($role eq 'st') { - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid); + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context); } $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now, - $start,1); + $start,1,'',$context); } else { #reenable, activate, change access dates or change section if ($choice ne 'chgsec') { @@ -3980,25 +4039,25 @@ sub update_user_list { } if ($choice eq 'reenable') { if ($role eq 'st') { - $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); + $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context); } else { $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end, - $now); + $now,'','',$context); } } elsif ($choice eq 'activate') { if ($role eq 'st') { - $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); + $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context); } else { $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end, - $now); + $now,'','',$context); } } elsif ($choice eq 'chgdates') { if ($role eq 'st') { - $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); + $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context); } else { $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end, - $start); + $start,'','',$context); } } elsif ($choice eq 'chgsec') { my (@newsecs,$revresult,$nochg,@retained); @@ -4014,7 +4073,8 @@ sub update_user_list { } else { $revresult = &Apache::lonnet::revokerole($udom,$uname, - $scope,$role); + $scope,$role, + '','',$context); } } else { if (@newsecs > 0) { @@ -4023,12 +4083,14 @@ sub update_user_list { } else { $revresult = &Apache::lonnet::revokerole($udom,$uname, - $scope,$role); + $scope,$role, + '','',$context); } } else { $revresult = &Apache::lonnet::revokerole($udom,$uname, - $scope,$role); + $scope,$role, + '','',$context); } } } else { @@ -4043,17 +4105,17 @@ sub update_user_list { if (!$nochg) { if ($role eq 'st') { $result = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid); + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context); } else { my $newscope = $scopestem; - $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start); + $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context); } } } else { foreach my $newsec (@newsecs) { if (!grep(/^\Q$newsec\E$/,@retained)) { if ($role eq 'st') { - $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid); + $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context); } else { my $newscope = $scopestem; if ($newsec ne '') { @@ -4192,17 +4254,29 @@ sub set_login { } sub course_sections { - my ($sections_count,$role) = @_; + my ($sections_count,$role,$current_sec) = @_; my $output = ''; my @sections = (sort {$a <=> $b} keys %{$sections_count}); my $numsec = scalar(@sections); + my $is_selected = ' selected="selected" '; if ($numsec <= 1) { $output = ''.&mt('Select').''."\n". + ' '."\n"; + if ($current_sec eq 'none') { + $output .= + ' \n"; + } else { + $output .= ' \n"; + } } else { $output .= 'multiple="multiple" size="'.$multiple.'">'."\n"; } foreach my $sec (@sections) { - $output .= '\n"; + if ($current_sec eq $sec) { + $output .= '\n"; + } else { + $output .= '\n"; + } } } $output .= '';