version 1.8, 2005/02/17 08:29:43
|
version 1.29, 2011/01/23 01:04:26
|
Line 34 use Apache::loncommon;
|
Line 34 use Apache::loncommon;
|
use Apache::loncoursedata; |
use Apache::loncoursedata; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use Apache::longroup; |
|
use LONCAPA; |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
Line 42 sub handler {
|
Line 44 sub handler {
|
return OK if $r->header_only; |
return OK if $r->header_only; |
|
|
# ------------------------------------------------------------ Print the screen |
# ------------------------------------------------------------ Print the screen |
my $html=&Apache::lonxml::xmlbegin(); |
$r->print(&Apache::loncommon::start_page("Selecting a User",undef, |
$r->print(<<ENDDOCUMENT); |
{'no_nav_bar' => 1})); |
$html |
|
<head> |
|
<title>The LearningOnline Network with CAPA</title> |
|
</head> |
|
ENDDOCUMENT |
|
|
|
|
|
|
|
|
|
&Apache::loncommon::get_unprocessed_cgi |
&Apache::loncommon::get_unprocessed_cgi |
($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement', |
($ENV{'QUERY_STRING'},['filter','form','unameelement','udomelement', |
'roles']); |
'roles','courseadvonly','clicker']); |
# Allowed? |
# Allowed? |
|
my $allowed; |
|
my $scope = $env{'request.course.id'}; |
|
if (!($allowed = &Apache::lonnet::allowed('srm',$scope))) { |
|
$scope .= '/'.$env{'request.course.sec'}; |
|
$allowed = &Apache::lonnet::allowed('srm',$scope); |
|
if ($allowed) { $allowed = 'section'; } |
|
} |
|
|
unless (($ENV{'form.roles'}) || |
unless (($env{'form.roles'}) || |
(($ENV{'request.course.id'}) && |
(($env{'request.course.id'}) && ($allowed))) { |
(&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})))) { |
$r->print(&mt('No context.'). |
$r->print('<body>No context.</body>'); |
&Apache::loncommon::end_page()); |
return OK; |
return OK; |
} |
} |
|
|
# See if filter present |
# See if filter present |
|
my $filter=$env{'form.filter'}; |
|
my $filtermsg; |
|
my $encoded_filter = &HTML::Entities::encode($filter,'<>&"'); |
|
$filter = quotemeta($filter); |
|
my $change = &mt('Change'); |
|
my $filterbutton =<<FILTER; |
|
<input type="text" name="filter" value="$encoded_filter" /> |
|
<input type="submit" name="Change" value="$change" /> |
|
FILTER |
|
foreach my $name ('form','unameelement','udomelement','roles') { |
|
my $value = &HTML::Entities::encode($env{"form.$name"},'<>&"'); |
|
$filterbutton .= <<HIDDEN; |
|
<input type="hidden" name="$name" value="$value" /> |
|
HIDDEN |
|
} |
|
unless ($env{'form.courseadvonly'}) { |
|
$filtermsg = '<br />'. |
|
&mt('Showing users with a name starting with [_1]', |
|
$filterbutton).'<br />'; |
|
} |
|
if ($filter eq '') { |
|
$filter = '.' |
|
} |
|
|
my $filter=$ENV{'form.filter'}; |
|
$filter=~s/\W//g; |
|
unless ($filter) { $filter='.'; } |
|
|
|
my $classlist=&Apache::loncoursedata::get_classlist(); |
|
|
|
# --------------------------------------- There is such a user, get environment |
# --------------------------------------- There is such a user, get environment |
|
|
$r->print(&Apache::loncommon::bodytag("Selecting a User")); |
|
$r->print(<<ENDSCRIPT); |
$r->print(<<ENDSCRIPT); |
<script> |
<script type="text/javascript"> |
function gochoose(uname,udom) { |
function gochoose(uname,udom) { |
opener.document.$ENV{'form.form'}.$ENV{'form.unameelement'}.value=uname; |
opener.document.$env{'form.form'}.elements['$env{'form.unameelement'}'].value=uname; |
var slct=opener.document.$ENV{'form.form'}.$ENV{'form.udomelement'}; |
var slct=opener.document.$env{'form.form'}.elements['$env{'form.udomelement'}']; |
var i; |
var i; |
for (i=0;i<slct.length;i++) { |
for (i=0;i<slct.length;i++) { |
if (slct.options[i].value==udom) { slct.selectedIndex=i; } |
if (slct.options[i].value==udom) { slct.selectedIndex=i; } |
Line 89 function gochoose(uname,udom) {
|
Line 107 function gochoose(uname,udom) {
|
} |
} |
</script> |
</script> |
ENDSCRIPT |
ENDSCRIPT |
|
|
$r->print('<form>'); |
$r->print('<form>'); |
if ((&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) && |
if ($allowed && (!$env{'form.roles'})) { |
(!$ENV{'form.roles'})) { |
|
# -------------------------------------------------------- Get course personnel |
# -------------------------------------------------------- Get course personnel |
$r->print('<h3>'.$ENV{'course.'.$ENV{'request.course.id'}.'.description'}. |
$r->print('<h3>'.$env{'course.'.$env{'request.course.id'}.'.description'}. |
'</h3>'); |
'</h3>'); |
my %coursepersonnel= |
my %coursepersonnel= |
&Apache::lonnet::get_course_adv_roles(); |
&Apache::lonnet::get_course_adv_roles(); |
$r->print('<table border="2">'); |
$r->print(&Apache::loncommon::start_data_table()); |
foreach my $role (sort keys %coursepersonnel) { |
foreach my $role (sort(keys(%coursepersonnel))) { |
foreach (split(/\,/,$coursepersonnel{$role})) { |
foreach my $user (split(/\,/,$coursepersonnel{$role})) { |
my ($puname,$pudom)=split(/\:/,$_); |
my ($puname,$pudom)=split(/\:/,$user); |
$r->print('<tr><td>'. |
$r->print(&Apache::loncommon::start_data_table_row(). |
'<input type="button" value="Select" onClick="gochoose('. |
'<td>'. |
"'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'. |
'<input type="button" value="'.&mt('Select').'" onClick="gochoose('. |
&Apache::loncommon::aboutmewrapper( |
"'".$puname."','".$pudom."')".'" /></td><td>'.$role.'</td><td>'. |
&Apache::loncommon::plainname($puname, |
&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($puname,$pudom),$puname,$pudom).'</td>'. |
$pudom),$puname,$pudom).'</td></tr>'); |
&Apache::loncommon::end_data_table_row()); |
|
} |
} |
} |
} |
$r->print(&Apache::loncommon::end_data_table().'<p> '); |
$r->print('</table><p> '); |
|
if ($filter ne '.') { |
$r->print($filtermsg); |
$r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />'); |
|
} |
$r->print('</p>'); |
$r->print('</p><p><table>'); |
|
# ------------------------------------------------------------------ Students |
unless ($env{'form.courseadvonly'}) { |
foreach (sort keys %$classlist) { |
|
# the following undefs are for 'domain', and 'username' respectively. |
|
my (undef,undef,$end,$start,$id,$section,$fullname,$status)= |
|
@{$classlist->{$_}}; |
|
if ($_=~/^(\w+)\:(\w+)$/) { |
|
my ($uname,$udom)=($1,$2); |
|
if (($uname=~/^$filter/) || |
|
($fullname=~/^$filter/i)) { |
|
$r->print('<tr><td>'. |
|
'<input type="button" value="'.&mt('Select').'" onClick="gochoose('. |
|
"'".$uname."','".$udom."')".'" /></td>'. |
|
'<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom. |
|
'</tt></td><td>'. |
|
&Apache::loncommon::aboutmewrapper( |
|
$fullname, |
|
$uname,$udom).'</td><td>'.$id.'</td><td>'.$section. |
|
'</td></tr>'); |
|
} |
|
} |
|
} |
|
|
|
$r->print('</table></p>'); |
# ------------------------------------------------------------------ Students |
} else { |
|
$r->print('<h3>'.&mt('Users with Roles Assigned by').' '. |
# Do we have a clicker? |
&Apache::loncommon::plainname($ENV{'user.name'}, |
|
$ENV{'user.domain'}).'</h3>'); |
my $clicker=$env{'form.clicker'}; |
if ($filter ne '.') { |
my @fragments=(); |
$r->print('<br/ >'.&mt('Name starting with').' "'.$filter.'"<br />'); |
if ($clicker) { |
} |
$r->print('<h1>'.&mt('Clicker: [_1]',$clicker).'</h1>'); |
$r->print('<p><table>'); |
my $clicklength=length($clicker); |
my %users=&Apache::lonnet::get_my_roles(); |
my $maxlength=$clicklength-1; |
foreach (sort keys %users) { |
if ($maxlength>2) { |
if ($_=~/^(\w+)\:(\w+)\:(\w+)$/) { |
my $minlength=$maxlength-2; |
|
if ($minlength<2) { $minlength=2; } |
|
for (my $length=$maxlength;$length>=$minlength;$length--) { |
|
for (my $startidx=0; $startidx<=$clicklength-$length; $startidx++) { |
|
push(@fragments,substr($clicker,$startidx,$length)); |
|
} |
|
} |
|
} |
|
} |
|
|
|
my $result; |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $classlist=&Apache::loncoursedata::get_classlist(); |
|
my %grouplist=&Apache::lonnet::get_group_membership($cdom,$cnum); |
|
my $now = time; |
|
my %allgroups = &Apache::longroup::coursegroups($cdom,$cnum); |
|
|
|
foreach my $user (sort(keys(%$classlist))) { |
|
# the following undefs are for 'domain', and 'username' respectively. |
|
my (undef,undef,$end,$start,$id,$section,$fullname,$status)= |
|
@{$classlist->{$user}}; |
|
if ($allowed eq 'section' && $section ne $env{'request.course.sec'}) { |
|
next; |
|
} |
|
if ($user=~/^($LONCAPA::username_re)\:($LONCAPA::domain_re)$/) { |
|
my ($uname,$udom)=($1,$2); |
|
if (($uname=~/^$filter/) || ($fullname=~/^$filter/i)) { |
|
my $grouplist = ''; |
|
foreach my $group (sort(keys(%allgroups))) { |
|
if (exists($grouplist{$group.':'.$uname.':'.$udom})) { |
|
my ($end,$start) = split(/:/,$grouplist{$group.':'.$uname.':'.$udom}); |
|
if (($end!=0) && ($end<$now)) { next; } |
|
if (($start!=0) && ($start>$now)) {next; } |
|
$grouplist .= " $group,"; |
|
} |
|
} |
|
$grouplist =~ s/,$//; |
|
my $markedupclicker; |
|
if ($clicker) { |
|
$markedupclicker=(&Apache::lonnet::userenvironment($udom,$uname,'clickers'))[1]; |
|
if ($markedupclicker!~/\w/) { |
|
$markedupclicker='-'; |
|
} else { |
|
foreach my $frag (@fragments) { |
|
if ($markedupclicker=~/\Q$frag\E/is) { |
|
$markedupclicker=~s/(\Q$frag\E)/<font color=\"green\" size=\"\+1\"><b>$1<\/b><\/font>/gis; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
$result .=&Apache::loncommon::start_data_table_row(). |
|
'<td>'. |
|
'<input type="button" value="'.&mt('Select').'" onClick="gochoose('. |
|
"'".$uname."','".$udom."')".'" /></td>'. |
|
'<td><tt>'.$uname.'</tt></td><td> <tt>'.$udom. |
|
'</tt></td><td>'. |
|
&Apache::loncommon::aboutmewrapper($fullname, |
|
$uname,$udom). |
|
'</td><td>'.$id.'</td><td>'.$section. |
|
'</td><td>'.$grouplist.'</td>'. |
|
($clicker?'<td>'.$markedupclicker.'</td>':''). |
|
&Apache::loncommon::end_data_table_row(); |
|
} |
|
} |
|
} |
|
if (!$result) { |
|
$r->print('<p>'.&mt('No students found.').'</p>'); |
|
} else { |
|
$r->print(&Apache::loncommon::start_data_table(). |
|
&Apache::loncommon::start_data_table_header_row(). |
|
&Apache::loncommon::end_data_table_header_row(). |
|
'<th> </th>'. |
|
'<th>'.&mt('username').'</th>'. |
|
'<th>'.&mt('domain').'</th>'. |
|
'<th>'.&mt('Name').'</th>'. |
|
'<th>'.&mt('ID').'</th>'. |
|
'<th>'.&mt('section').'</th>'. |
|
'<th>'.&mt('active group(s)').'</th>'. |
|
($clicker?'<th>'.&mt('clicker').'</th>':''). |
|
&Apache::loncommon::end_data_table_header_row(). |
|
$result. |
|
&Apache::loncommon::end_data_table()); |
|
} |
|
} |
|
} else { |
|
$r->print('<h3>'.&mt('Users with Roles Assigned by').' '. |
|
&Apache::loncommon::plainname($env{'user.name'}, |
|
$env{'user.domain'}).'</h3>'); |
|
$r->print($filtermsg); |
|
|
|
$r->print('<p>'.&Apache::loncommon::start_data_table()); |
|
my %user_role=&Apache::lonnet::get_my_roles(); |
|
my %users; |
|
foreach my $user_role (keys(%user_role)) { |
|
next if ($user_role !~ |
|
/^($LONCAPA::username_re):($LONCAPA::domain_re):(\w+)$/); |
my ($uname,$udom,$urole)=($1,$2,$3); |
my ($uname,$udom,$urole)=($1,$2,$3); |
my $fullname=&Apache::loncommon::plainname($uname,$udom); |
my $fullname=&Apache::loncommon::plainname($uname,$udom); |
if (($uname=~/^$filter/) || |
next if (($uname!~/^$filter/i) && ($fullname !~/^$filter/i)); |
($fullname=~/^$filter/i)) { |
|
$r->print('<tr><td>'. |
if (!exists($users{"$uname:$udom"})) { |
'<input type="button" value="Select" onClick="gochoose('. |
$users{"$uname:$udom"} = {'fullname' => $fullname }; |
"'".$uname."','".$udom."')".'" /></td>'. |
} |
'<td><tt>'.$uname.'</tt></td><td><tt>'.$udom. |
push(@{$users{"$uname:$udom"}{'roles'}},$urole); |
'</tt></td><td>'. |
} |
&Apache::loncommon::aboutmewrapper( |
foreach my $user (sort {lc($a) cmp lc($b)} (keys(%users))) { |
$fullname, |
my ($uname,$udom) = split(':',$user); |
$uname,$udom).'</td><td><td>'. |
$r->print(&Apache::loncommon::start_data_table_row(). |
&Apache::lonnet::plaintext($urole). |
'<td>'. |
'</td></tr>'); |
'<input type="button" value="'.&mt('Select').'" onClick="gochoose('. |
} |
"'".$uname."','".$udom."')".'" /></td>'. |
} |
'<td><tt>'.$uname.'</tt></td>'. |
|
'<td><tt>'.$udom.'</tt></td><td>'. |
|
&Apache::loncommon::aboutmewrapper($users{$user}{'fullname'}, |
|
$uname,$udom).'</td>'. |
|
'<td>'. |
|
join(', ',sort(map {&Apache::lonnet::plaintext($_)} |
|
(@{$users{$user}{'roles'}}))). |
|
'</td>'. |
|
&Apache::loncommon::end_data_table_row()); |
|
} |
|
$r->print(&Apache::loncommon::end_data_table().'</p>'); |
} |
} |
$r->print('</table></p>'); |
$r->print('</form>'.&Apache::loncommon::end_page()); |
} |
return OK; |
$r->print('</form></body></html>'); |
|
return OK; |
|
} |
} |
|
|
1; |
1; |