--- loncom/interface/lonuserutils.pm 2008/01/05 18:36:26 1.44 +++ loncom/interface/lonuserutils.pm 2008/05/09 17:55:25 1.53 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.44 2008/01/05 18:36:26 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.53 2008/05/09 17:55:25 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); @@ -1251,34 +1252,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')). @@ -1307,8 +1285,10 @@ sub print_userlist { } $r->rflush(); if ($context eq 'course') { - my $classlist = &Apache::loncoursedata::get_classlist(); - %userlist = %{$classlist}; + 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') { @@ -1448,6 +1428,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; @@ -1465,9 +1480,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'; } @@ -1511,6 +1526,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') { @@ -1520,7 +1539,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}); @@ -1789,6 +1807,7 @@ sub make_keylist_array { $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; } @@ -1991,14 +2010,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'; + } } } @@ -2033,6 +2068,7 @@ END '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') { @@ -2091,23 +2127,25 @@ 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

@@ -2241,7 +2279,6 @@ END } # Done with header lines in all formats - my %index; my $i; foreach my $idx (@$keylist) { @@ -2343,6 +2380,8 @@ END 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'); } @@ -2459,8 +2498,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 { @@ -2479,7 +2517,7 @@ END } if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') { - $r->print(' '); + $r->print(' '); } else { $r->print('   '); } @@ -2544,14 +2582,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'}'".')" />'. @@ -2662,20 +2696,14 @@ 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 = ' -