[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 05 Dec 2007 19:11:37 -0000
raeburn Wed Dec 5 14:11:37 2007 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
Bug 3414. Radio button to switch functionality of each username
link in a list of users between "About Me" page and "Modify User".
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.9 loncom/interface/lonuserutils.pm:1.10
--- loncom/interface/lonuserutils.pm:1.9 Wed Dec 5 12:53:13 2007
+++ loncom/interface/lonuserutils.pm Wed Dec 5 14:11:37 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.9 2007/12/05 17:53:13 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.10 2007/12/05 19:11:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1358,6 +1358,8 @@
&gather_userinfo($context,$format,\%userlist,$indexhash,
\%userinfo,\%allusers);
} else {
+ $r->print('<input type="hidden" name="phase" value="'.
+ $env{'form.phase'}.'" /></form>');
return;
}
}
@@ -1381,17 +1383,18 @@
# Print out the available choices
my $usercount;
if ($env{'form.action'} eq 'modifystudent') {
- ($usercount) = &show_users_list($r,$context,'view','modify',
+ ($usercount) = &show_users_list($r,$context,'view',$permission,
$env{'form.Status'},\%userlist,$keylist);
} else {
($usercount) = &show_users_list($r,$context,$env{'form.output'},
- 'aboutme',$env{'form.Status'},\%userlist,$keylist);
+ $permission,$env{'form.Status'},\%userlist,$keylist);
}
if (!$usercount) {
$r->print('<br />'.&mt('There are no users matching the search criteria.'));
}
}
- $r->print('</form>');
+ $r->print('<input type="hidden" name="phase" value="'.
+ $env{'form.phase'}.'" /></form>');
}
sub list_submit_button {
@@ -1696,7 +1699,7 @@
}
sub show_users_list {
- my ($r,$context,$mode,$linkto,$statusmode,$userlist,$keylist)=@_;
+ my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1749,6 +1752,29 @@
}
unless ($mode eq 'autoenroll') {
$r->print(<<END);
+
+<script type="text/javascript" language="Javascript">
+
+function username_display_launch(username,domain) {
+ var target;
+ for (var i=0; i<document.studentform.usernamelink.length; i++) {
+ if (document.studentform.usernamelink[i].checked) {
+ target = document.studentform.usernamelink[i].value;
+ }
+ }
+ 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();
+ }
+ else {
+ document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
+ }
+}
+</script>
+
<input type="hidden" name="state" value="$env{'form.state'}" />
END
}
@@ -1772,6 +1798,9 @@
'clicker' => "clicker id",
'photo' => "photo",
'extent' => "extent",
+ 'link' => "Behavior of username links",
+ 'aboutme' => "Display a user's personal page",
+ 'modify' => "Modify a user's information",
);
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
$lt{'extent'} = &mt('Course(s): description, section(s), status');
@@ -1813,13 +1842,33 @@
my $output;
if ($mode eq 'html' || $mode eq 'view') {
$r->print(<<END);
-<input type="hidden" name="sname" value="" />
-<input type="hidden" name="sdom" value="" />
+<input type="hidden" name="srchby" value="uname" />
+<input type="hidden" name="srchin" value="dom" />
+<input type="hidden" name="srchtype" value="exact" />
+<input type="hidden" name="srchterm" value="" />
+<input type="hidden" name="srchdomain" value="" />
END
- if ($linkto eq 'aboutme') {
- $output = &mt("Select a user name to view the user's personal page.");
- } elsif ($linkto eq 'modify') {
- $output = &mt("Select a user name to modify the user's information");
+ if ($mode ne 'autoenroll') {
+ $output = '<p>';
+ my @linkdests = ('aboutme');
+ if ($permission->{'cusr'}) {
+ push (@linkdests,'modify');
+ $output .= '<span class="LC_nobreak">'.$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 .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label> ';
+ }
+ $output .= '</span><br />';
+ } else {
+ $output .= &mt("Click on a username to view the user's personal page.").'<br />';
+ }
}
$output .= "\n<p>\n".
&Apache::loncommon::start_data_table().
@@ -2000,22 +2049,12 @@
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
$r->print(&Apache::loncommon::start_data_table_row());
$r->print("<td>$rowcount</td>\n");
- if ($linkto eq 'aboutme') {
- $in{'username'} =
- &Apache::loncommon::aboutmewrapper($in{'username'},
- $in{'username'},
- $in{'domain'});
- } elsif ($linkto eq 'modify') {
- $in{'username'} = '<a href="'.
- "javascript:document.studentform.sname.value='".
- $in{'username'}.
- "';document.studentform.sdom.value='".$in{'domain'}.
- "';document.studentform.state.value='selected".
- "';document.studentform.submit();".'">'.
- $in{'username'}."</a>\n";
- }
foreach my $item (@cols) {
- $r->print('<td>'.$in{$item}.'</td>'."\n");
+ if ($item eq 'username') {
+ $r->print('<td>'.&print_username_link($permission,\%in).'</td>');
+ } else {
+ $r->print('<td>'.$in{$item}.'</td>'."\n");
+ }
}
if ($context eq 'course') {
if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
@@ -2096,6 +2135,21 @@
}
}
+sub print_username_link {
+ my ($permission,$in) = @_;
+ my $output;
+ if (!$permission->{'cusr'}) {
+ $output = &Apache::loncommon::aboutmewrapper($in->{'username'},
+ $in->{'username'},
+ $in->{'domain'});
+ } else {
+ $output = '<a href="javascript:username_display_launch('.
+ "'$in->{'username'}','$in->{'domain'}'".')" />'.
+ $in->{'username'}.'</a>';
+ }
+ return $output;
+}
+
sub role_type_names {
my %lt = &Apache::lonlocal::texthash (
'domain' => 'Domain Roles',