version 1.374, 2006/05/17 23:25:56
|
version 1.375, 2006/05/18 01:08:50
|
Line 3709 specific user. Roles can be active, prev
|
Line 3709 specific user. Roles can be active, prev
|
|
|
Inputs: |
Inputs: |
user's domain, user's username, course's domain, |
user's domain, user's username, course's domain, |
course's number, optional section/group. |
course's number, optional section ID. |
|
|
Outputs: |
Outputs: |
role status: active, previous or future. |
role status: active, previous or future. |
Line 3815 sub get_sections {
|
Line 3815 sub get_sections {
|
} |
} |
|
|
############################################### |
############################################### |
|
|
=pod |
|
|
|
=item coursegroups |
|
|
|
Retrieve information about groups in a course, |
|
|
|
Input: |
|
1. Optional course domain |
|
2. Optional course number |
|
3. Optional group name |
|
|
|
Course domain and number will be taken from user's |
|
environment if not supplied. Optional group name will' |
|
be passed to lonnet::get_coursegroups() as a regexp to |
|
use in the call to the dump function. |
|
|
|
Output |
|
Returns hash of groups in the course (subject to the |
|
optional group name filter). In the hash, the keys are |
|
group names, and their corresponding values |
|
are scalars containing group information in XML. This |
|
can be sent to &get_group_settings() to be parsed. |
|
|
|
Side effects: |
|
None. |
|
=cut |
|
|
|
############################################### |
|
|
|
sub coursegroups { |
|
my ($cdom,$cnum,$group) = @_; |
|
if (!defined($cdom) || !defined($cnum)) { |
|
my $cid = $env{'request.course.id'}; |
|
|
|
return if (!defined($cid)); |
|
|
|
$cdom = $env{'course.'.$cid.'.domain'}; |
|
$cnum = $env{'course.'.$cid.'.num'}; |
|
} |
|
my %curr_groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group); |
|
my ($tmp) = keys(%curr_groups); |
|
if ($tmp=~/^(con_lost|no_such_host|error: [^2] )/) { |
|
undef(%curr_groups); |
|
&logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom); |
|
} elsif ($tmp=~/^error: 2 /) { |
|
undef(%curr_groups); |
|
} |
|
return %curr_groups; |
|
} |
|
|
|
############################################### |
|
|
|
=pod |
|
|
|
=item get_group_settings |
|
|
|
Uses TokeParser to extract group information from the |
|
XML used to describe course groups. |
|
|
|
Input: |
|
Scalar containing XML - as retrieved from &coursegroups(). |
|
|
|
Output: |
|
Hash containing group information as key=values for (a), and |
|
hash of hashes for (b) |
|
|
|
Keys (in two categories): |
|
(a) groupname, creator, creation, modified, startdate,enddate. |
|
Corresponding values are name of the group, creator of the group |
|
(username:domain), UNIX time for date group was created, and |
|
settings were last modified, and default start and end access |
|
times for group members. |
|
|
|
(b) functions returned in hash of hashes. |
|
Outer hash key is functions. |
|
Inner hash keys are chat,discussion,email,files,homepage,roster. |
|
Corresponding values are either on or off, depending on |
|
whether this type of functionality is available for the group. |
|
|
|
=cut |
|
|
|
############################################### |
|
|
|
sub get_group_settings { |
|
my ($groupinfo)=@_; |
|
my $parser=HTML::TokeParser->new(\$groupinfo); |
|
my $token; |
|
my $tool = ''; |
|
my $role = ''; |
|
my %content=(); |
|
while ($token=$parser->get_token) { |
|
if ($token->[0] eq 'S') { |
|
my $entry=$token->[1]; |
|
if ($entry eq 'functions' || $entry eq 'autosec') { |
|
%{$content{$entry}} = (); |
|
$tool = $entry; |
|
} elsif ($entry eq 'role') { |
|
if ($tool eq 'autosec') { |
|
$role = $token->[2]{id}; |
|
@{$content{$tool}{$role}} = (); |
|
} |
|
} else { |
|
my $value=$parser->get_text('/'.$entry); |
|
if ($entry eq 'name') { |
|
if ($tool eq 'functions') { |
|
my $function = $token->[2]{id}; |
|
$content{$tool}{$function} = $value; |
|
} |
|
} elsif ($entry eq 'groupname') { |
|
$content{$entry}=&unescape($value); |
|
} elsif (($entry eq 'roles') || ($entry eq 'types') || |
|
($entry eq 'sectionpick') || ($entry eq 'defpriv')) { |
|
push(@{$content{$entry}},$value); |
|
} elsif ($entry eq 'section') { |
|
if ($tool eq 'autosec' && $role ne '') { |
|
push(@{$content{$tool}{$role}},$value); |
|
} |
|
} else { |
|
$content{$entry}=$value; |
|
} |
|
} |
|
} elsif ($token->[0] eq 'E') { |
|
if ($token->[1] eq 'functions' || $token->[1] eq 'autosec') { |
|
$tool = ''; |
|
} elsif ($token->[1] eq 'role') { |
|
$role = ''; |
|
} |
|
|
|
} |
|
} |
|
return %content; |
|
} |
|
|
|
sub check_group_access { |
|
my ($group) = @_; |
|
my $access = 1; |
|
my $now = time; |
|
my ($start,$end) = split(/\./,$env{'user.role.gr/'.$env{'request.course,id'}.'/'.$group}); |
|
if (($end!=0) && ($end<$now)) { $access = 0; } |
|
if (($start!=0) && ($start>$now)) { $access=0; } |
|
return $access; |
|
} |
|
|
|
############################################### |
|
|
|
=pod |
=pod |
|
|