--- loncom/interface/lonuserutils.pm 2007/12/26 14:38:13 1.36 +++ loncom/interface/lonuserutils.pm 2008/04/30 23:16:19 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.36 2007/12/26 14:38:13 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.52 2008/04/30 23:16: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,14 +69,14 @@ 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.':'; } } } } if ($result eq '') { - $result = 'Unable to find section for this student'; + $result = &mt('Unable to find section for this student'); } else { $result =~ s/(ok:)+/ok/g; } @@ -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); @@ -333,17 +334,12 @@ sub print_upload_manager_header { sub javascript_validations { my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain, $context,$groupslist)=@_; - my %param = ( kerb_def_dom => $krbdefdom, curr_authtype => $curr_authtype, ); - if ($mode eq 'createuser') { - $param{'formname'} = 'cu'; - } elsif ($mode eq 'upload') { + if ($mode eq 'upload') { $param{'formname'} = 'studentform'; - } elsif ($mode eq 'singlestudent') { - $param{'formname'} = 'cu'; } elsif ($mode eq 'createcourse') { $param{'formname'} = 'ccrs'; } elsif ($mode eq 'modifycourse') { @@ -367,7 +363,7 @@ sub javascript_validations { } } elsif ($context eq 'domain') { $setsection_call = 'setCourse()'; - $setsections_js = &dc_setcourse_js($param{'formname'},$mode); + $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context); } $finish = " var checkSec = $setsection_call\n". " if (checkSec == 'ok') {\n". @@ -389,8 +385,7 @@ sub javascript_validations { role => 'The optional role field was not specified.', continue => 'Continue adding users?', ); - - my $function_name =(<rflush(); if ($context eq 'course') { - my $classlist = &Apache::loncoursedata::get_classlist(); - my $secidx = &Apache::loncoursedata::CL_SECTION(); - my $viewablesec = &viewable_section($permission); - foreach my $student (keys(%{$classlist})) { - my $section = $classlist->{$student}[$secidx]; - if ($viewablesec ne '') { - if ($section ne $viewablesec) { - next; - } else { - $userlist{$student} = $classlist->{$student}; - } + if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) { + my $classlist = &Apache::loncoursedata::get_classlist(); + %userlist = %{$classlist}; + } + if ($env{'form.showrole'} ne 'st') { + my $showroles; + if ($env{'form.showrole'} ne 'Any') { + $showroles = [$env{'form.showrole'}]; } else { - $userlist{$student} = $classlist->{$student}; + $showroles = undef; } + my $withsec = 1; + my $hidepriv = 1; + my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef, + \@statuses,$showroles,undef,$withsec,$hidepriv); + &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo, + \%advrolehash,$permission); } - my $showroles; - if ($env{'form.showrole'} ne 'Any') { - $showroles = [$env{'form.showrole'}]; - } else { - $showroles = undef; - } - my $withsec = 1; - my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef, - \@statuses,$showroles,undef,$withsec); - &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo, - \%advrolehash,$permission); } else { my (%cstr_roles,%dom_roles); if ($context eq 'author') { @@ -1393,7 +1374,8 @@ sub print_userlist { } elsif ($env{'form.roletype'} eq 'course') { if ($env{'form.coursepick'}) { my %courses = &process_coursepick(); - my %allusers; + my %allusers; + my $hidepriv = 1; foreach my $cid (keys(%courses)) { my ($cnum,$cdom,$cdesc) = &get_course_identity($cid); next if ($cnum eq '' || $cdom eq ''); @@ -1411,7 +1393,7 @@ sub print_userlist { foreach my $type (@statuses) { $access{$type} = $type; } - &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash); + &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv); foreach my $user (keys(%userdata)) { next if (ref($userinfo{$user}) eq 'HASH'); foreach my $item ('fullname','id') { @@ -1486,9 +1468,9 @@ sub section_group_filter { all => 'all', none => 'none', ); - my ($output,@options); + my $output; foreach my $item (@filters) { - my $markup; + my ($markup,@options); if ($env{'form.'.$name{$item}} eq '') { $env{'form.'.$name{$item}} = 'all'; } @@ -1532,6 +1514,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') { @@ -1541,7 +1527,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}); @@ -1809,6 +1794,8 @@ sub make_keylist_array { $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL(); $index->{'role'} = &Apache::loncoursedata::CL_ROLE(); $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT(); + $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO(); + $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL(); foreach my $key (keys(%{$index})) { $keylist->[$index->{$key}] = $key; } @@ -1917,7 +1904,19 @@ END my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox"); my $singconfirm = &mt(' for a single user?'); my $multconfirm = &mt(' for multiple users?'); - my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode); + my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode); + my %lt = &Apache::lonlocal::texthash( + acwi => 'Access will be set to start immediately', + asyo => 'as you did not select an end date in the pop-up window', + accw => 'Access will be set to continue indefinitely', + asyd => 'as you did not select an end date in the pop-up window', + sewi => "Sections will be switched to 'No section'", + ayes => "as you either selected the 'No section' option", + oryo => 'or you did not select a section in the pop-up window', + arol => 'A role with no section will be added', + swbs => 'Sections will be switched to:', + rwba => 'Roles will be added for section(s):', + ); $r->print(< @@ -1943,12 +1942,47 @@ function verify_action (field) { } else { var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text; + var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value; if (numchecked == 1) { message += singconf; } else { message += multconf; } + 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 == '')) { + datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n"; + } + if ((document.studentform.enddate_month.value == '') && + (document.studentform.enddate_day.value == '') && + (document.studentform.enddate_year.value == '')) { + datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n"; + } + if (datemsg != '') { + message += "\\n"+datemsg; + } + } + 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; + if (secshow == '') { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } else { + message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } + } else { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'swbs'} "+secshow+".\\n"; + } else { + message += "\\n\\n$lt{'rwba'} "+secshow+".\\n"; + } + } + } if (confirm(message)) { document.studentform.phase.value = 'bulkchange'; document.studentform.submit(); @@ -1964,14 +1998,30 @@ function username_display_launch(usernam } } if (target == 'modify') { - document.studentform.srchterm.value=username; - document.studentform.srchdomain.value=domain; - document.studentform.phase.value='get_user_info'; - document.studentform.action.value = 'singleuser'; - document.studentform.submit(); + if (document.studentform.userwin.checked == true) { + var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1'; + var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'; + modifywin = window.open(url,'',options,1); + modifywin.focus(); + return; + } else { + document.studentform.srchterm.value=username; + document.studentform.srchdomain.value=domain; + document.studentform.phase.value='get_user_info'; + document.studentform.action.value = 'singleuser'; + document.studentform.submit(); + } } - else { - document.location.href = '/adm/'+domain+'/'+username+'/aboutme'; + if (target == 'aboutme') { + if (document.studentform.userwin.checked == true) { + var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1'; + var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'; + aboutmewin = window.open(url,'',options,1); + aboutmewin.focus(); + return; + } else { + document.location.href = '/adm/'+domain+'/'+username+'/aboutme'; + } } } @@ -1999,12 +2049,14 @@ END 'clicker' => "clicker id", 'photo' => "photo", 'extent' => "extent", + 'go' => "go", 'pr' => "Proceed", 'ca' => "check all", 'ua' => "uncheck all", 'ac' => "Action to take for selected users", 'link' => "Behavior of username links", 'aboutme' => "Display a user's personal page", + 'owin' => "Open in a new window", 'modify' => "Modify a user's information", ); if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { @@ -2063,28 +2115,30 @@ END $output = '

'; my @linkdests = ('aboutme'); if ($permission->{'cusr'}) { - push (@linkdests,'modify'); - $output .= ''.$lt{'link'}.': '; - my $usernamelink = $env{'form.usernamelink'}; - if ($usernamelink eq '') { - $usernamelink = 'aboutme'; - } - foreach my $item (@linkdests) { - my $checkedstr = ''; - if ($item eq $usernamelink) { - $checkedstr = ' checked="checked" '; - } - $output .= '  '; + unshift (@linkdests,'modify'); + } + $output .= ''.$lt{'link'}.': '; + my $usernamelink = $env{'form.usernamelink'}; + if ($usernamelink eq '') { + $usernamelink = 'aboutme'; + } + foreach my $item (@linkdests) { + my $checkedstr = ''; + if ($item eq $usernamelink) { + $checkedstr = ' checked="checked" '; } - $output .= '
'; - } else { - $output .= &mt("Click on a username to view the user's personal page.").'
'; + $output .= '  '; } + my $checkwin; + if ($env{'form.userwin'}) { + $checkwin = 'checked = "checked"'; + } + $output .= '    '.$lt{'owin'}.'

'; if ($actionselect) { - $output .= <<"END"; -$lt{'ac'}: $actionselect

+ $output .= <<"END"; +$lt{'ac'}: $actionselect

  - +

END my @allroles; if ($env{'form.showrole'} eq 'Any') { @@ -2213,7 +2267,6 @@ END } # Done with header lines in all formats - my %index; my $i; foreach my $idx (@$keylist) { @@ -2234,6 +2287,10 @@ END # Get groups, role, permanent e-mail so we can sort on them if # necessary. foreach my $user (keys(%{$userlist})) { + if ($user eq '' ) { + delete($userlist->{$user}); + next; + } if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) { delete($userlist->{$user}); next; @@ -2279,6 +2336,13 @@ END } if ($mode ne 'autoenroll') { my $section = $userlist->{$user}->[$index{'section'}]; + if (($env{'request.course.sec'} ne '') && + ($section ne $env{'request.course.sec'})) { + if ($role eq 'st') { + delete($userlist->{$user}); + next; + } + } if ($secfilter eq 'none') { if ($section ne '') { delete($userlist->{$user}); @@ -2301,6 +2365,15 @@ END next; } } + if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { + if (($displayphotos eq 'on') && ($role eq 'st')) { + $userlist->{$user}->[$index{'photo'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg'); + $userlist->{$user}->[$index{'thumbnail'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname, + 'gif','thumbnail'); + } + } } } my %emails = &Apache::loncommon::getemails($uname,$udom); @@ -2413,8 +2486,7 @@ END } foreach my $item (@cols) { if ($item eq 'username') { - $r->print(''.&print_username_link($mode,$permission, - \%in).''); + $r->print(''.&print_username_link($mode,\%in).''); } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) { $r->print(''.$in{$item}.''."\n"); } else { @@ -2432,11 +2504,8 @@ END $r->print('   '); } if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { - if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') { - my $imgurl = - &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'}, - 'gif','thumbnail'); - $r->print(' '); + if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') { + $r->print(' '); } else { $r->print('   '); } @@ -2501,14 +2570,10 @@ END } sub print_username_link { - my ($mode,$permission,$in) = @_; + my ($mode,$in) = @_; my $output; if ($mode eq 'autoenroll') { $output = $in->{'username'}; - } elsif (!$permission->{'cusr'}) { - $output = &Apache::loncommon::aboutmewrapper($in->{'username'}, - $in->{'username'}, - $in->{'domain'}); } else { $output = '{'username'}','$in->{'domain'}'".')" />'. @@ -2588,7 +2653,7 @@ sub select_actions { } } if ($options) { - $output = ''."\n". ''."\n".$options."\n".''; if ($choices{'dates'}) { @@ -2619,19 +2684,29 @@ sub select_actions { sub date_section_javascript { my ($context,$setting) = @_; - my $title; - if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) { - $title = &mt('Date and Section selector'); - } else { - $title = &mt('Date selector'); - } + my $title = 'Date_And_Section_Selector'; + my %nopopup = &Apache::lonlocal::texthash ( + revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'", + delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'", + none => "Choose an action to take for selected users", + ); my $output = ' -