[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 22 Jun 2006 15:33:36 -0000
This is a MIME encoded message
--albertel1150990416
Content-Type: text/plain
albertel Thu Jun 22 11:33:36 2006 EDT
Modified files:
/loncom/interface portfolio.pm
Log:
- eliminate xml for access settings
--albertel1150990416
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060622113336.txt"
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.108 loncom/interface/portfolio.pm:1.109
--- loncom/interface/portfolio.pm:1.108 Thu Jun 22 09:27:13 2006
+++ loncom/interface/portfolio.pm Thu Jun 22 11:33:35 2006
@@ -539,8 +539,9 @@
}
my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
$uname);
- my %access_controls = &Apache::lonnet::get_access_controls(
- $current_permissions,$group,$file_name);
+ my %access_controls =
+ &Apache::lonnet::get_access_controls($current_permissions,
+ $group,$file_name);
if ($totalprocessed) {
if ($outcome eq 'ok') {
my $updated_controls = $access_controls{$file_name};
@@ -573,8 +574,7 @@
if ($chg eq 'activate') {
$newkey =~ s/^(\d+)/$$translation{$1}/;
}
- my %content = &Apache::lonnet::parse_access_controls(
- $$updated_controls{$newkey});
+ my $content = $$updated_controls{$newkey};
if ($chg eq 'delete') {
$showstart = &mt('Deleted');
$showend = $showstart;
@@ -589,7 +589,7 @@
$r->print('<td>'.&mt($scope));
if (($scope eq 'course') || ($scope eq 'group')) {
if ($chg ne 'delete') {
- my $cid = $content{'domain'}.'_'.$content{'number'};
+ my $cid = $content->{'domain'}.'_'.$content->{'number'};
my %course_description = &Apache::lonnet::coursedescription($cid);
$r->print('<br />('.$course_description{'description'}.')');
}
@@ -598,7 +598,7 @@
'<br />'.&mt('End: ').$showend.'</td><td>');
if ($chg ne 'delete') {
if ($scope eq 'guest') {
- $r->print(&mt('Password').': '.$content{'password'});
+ $r->print(&mt('Password').': '.$content->{'password'});
} elsif ($scope eq 'course' || $scope eq 'group') {
$r->print('<table border="0"><tr bgcol = "'.
$tablecolor.'">');
@@ -611,7 +611,7 @@
$r->print('<th>'.&mt('Teams').'</th>');
}
$r->print('</tr>');
- foreach my $id (sort(keys(%{$content{'roles'}}))) {
+ foreach my $id (sort(keys(%{$content->{'roles'}}))) {
$r->print('<tr>');
foreach my $item ('role','access','section','group') {
$r->print('<td>');
@@ -619,7 +619,7 @@
my $ucscope = $scope;
$ucscope =~ s/^(\w)/uc($1)/;
my $role_output;
- foreach my $role (@{$content{'roles'}{$id}{$item}}) {
+ foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
if ($role eq 'all') {
$role_output .= $role.',';
} elsif ($role =~ /^cr/) {
@@ -631,7 +631,7 @@
$role_output =~ s/,$//;
$r->print($role_output);
} else {
- $r->print(join(',',@{$content{'roles'}{$id}{$item}}));
+ $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
}
$r->print('</td>');
}
@@ -639,9 +639,9 @@
$r->print(&Apache::loncommon::end_data_table_row());
$r->print(&Apache::loncommon::end_data_table());
} elsif ($scope eq 'domains') {
- $r->print(&mt('Domains: ').join(',',@{$content{'dom'}}));
+ $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
} elsif ($scope eq 'users') {
- my $curr_user_list = &sort_users($content{'users'});
+ my $curr_user_list = &sort_users($content->{'users'});
$r->print(&mt('Users: ').$curr_user_list);
} else {
$r->print(' ');
@@ -701,95 +701,73 @@
sub build_access_record {
my ($num,$scope,$start,$end,$chg) = @_;
- my $record = '<scope type="'.$scope.'"><start>'.$start.'</start><end>'.
- $end.'</end>';
- if ($scope eq 'guest') {
- $record .= '<password>'.$env{'form.password'}.'</password>';
+ my $record = {
+ type => $scope,
+ time => {
+ start => $start,
+ end => $end
+ },
+ };
+
+ if ($scope eq 'guest') {
+ $record->{'password'} = $env{'form.password'};
} elsif (($scope eq 'course') || ($scope eq 'group')) {
- $record .= '<domain>'.$env{'form.crsdom_'.$num}.'</domain><number>'.
- $env{'form.crsnum_'.$num}.'</number>';
+ $record->{'domain'} = $env{'form.crsdom_'.$num};
+ $record->{'number'} = $env{'form.crsnum_'.$num};
my @role_ids;
- my @delete_role_ids;
- if (exists($env{'form.delete_role_'.$num})) {
- @delete_role_ids = &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
- }
- if (exists($env{'form.preserve_role_'.$num})) {
- my @preserves = &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
- if (@delete_role_ids > 0) {
- foreach my $id (@preserves) {
- if (grep/^\Q$id\E$/,@delete_role_ids) {
- next;
- }
- push(@role_ids,$id);
- }
- } else {
- push(@role_ids,@preserves);
- }
- }
- my $next_id = '';
- if (exists($env{'form.add_role_'.$num})) {
- $next_id = $env{'form.add_role_'.$num};
- if ($next_id) {
- push(@role_ids,$next_id);
- }
- }
+ my @delete_role_ids =
+ &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
+ my @preserves =
+ &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
+ if (@delete_role_ids) {
+ foreach my $id (@preserves) {
+ if (grep {$_ = $id} (@delete_role_ids)) {
+ next;
+ }
+ push(@role_ids,$id);
+ }
+ } else {
+ push(@role_ids,@preserves);
+ }
+
+ my $next_id = $env{'form.add_role_'.$num};
+ if ($next_id) {
+ push(@role_ids,$next_id);
+ }
+
foreach my $id (@role_ids) {
my (@roles,@accesses,@sections,@groups);
if (($id == $next_id) && ($chg eq 'update')) {
- @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
+ @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
@accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
@sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
- @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
+ @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
} else {
@roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
@accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
@sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
@groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
}
- $record .= '<roles id="'.$id.'">';
- foreach my $role (@roles) {
- $record .= '<role>'.$role.'</role>';
- }
- foreach my $access (@accesses) {
- $record .= '<access>'.$access.'</access>';
- }
- foreach my $section (@sections) {
- $record .= '<section>'.$section.'</section>';
- }
- foreach my $group (@groups) {
- $record .= '<group>'.$group.'</group>';
- }
- $record .= '</roles>';
+ $record->{'roles'}{$id}{'role'} = \@roles;
+ $record->{'roles'}{$id}{'access'} = \@accesses;
+ $record->{'roles'}{$id}{'section'} = \@sections;
+ $record->{'roles'}{$id}{'group'} = \@groups;
}
} elsif ($scope eq 'domains') {
my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
- foreach my $dom (@doms) {
- if ($dom ne '') {
- $record .= '<dom>'.$dom.'</dom>';
- }
- }
+ $record->{'dom'} = \@doms;
} elsif ($scope eq 'users') {
my $userlist = $env{'form.users_'.$num};
- $userlist =~ s/[\r\n\f]+//g;
- $userlist =~ s/\s+//g;
- my @users = split/,/,$userlist;
- my %userhash;
- my @unique_users;
- foreach my $user (@users) {
- if (!exists($userhash{$user})) {
- $userhash{$user} = 1;
- push(@unique_users,$user);
- }
- }
- $record .= '<users>';
- foreach my $user (@unique_users) {
+ $userlist =~ s/\s+//sg;
+ my %userhash = map { ($_,1) } (split(/,/,$userlist));
+ foreach my $user (keys(%userhash)) {
my ($uname,$udom) = split(/:/,$user);
- $record .= '<user><uname>'.$uname.'</uname><udom>'.$udom.
- '</udom></user>';
- }
- $record .= '</users>';
+ push(@{$record->{'users'}}, {
+ 'uname' => $uname,
+ 'udom' => $udom
+ });
+ }
}
- $record .= '</scope>';
return $record;
}
@@ -806,12 +784,11 @@
}
sub sort_users {
- my ($users_hash) = @_;
- my @curr_users;
- foreach my $user (keys(%{$users_hash})) {
- $curr_users[$$users_hash{$user}] = $user;
- }
- my $curr_user_list = join(",\n",@curr_users);
+ my ($users) = @_;
+ my @curr_users = map {
+ $_->{'uname'}.':'.$_->{'udom'}
+ } (@{$users});
+ my $curr_user_list = join(",\n",sort(@curr_users));
return $curr_user_list;
}
@@ -876,9 +853,7 @@
$r->print(&Apache::loncommon::start_data_table_row());
my $passwd;
if ($guest) {
- my %content = &Apache::lonnet::parse_access_controls(
- $$access_controls{$guest});
- $passwd = $content{'password'};
+ $passwd = $$access_controls{$guest}{'password'};
$r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
&dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
} else {
@@ -994,9 +969,7 @@
my %content;
my $defdom = $env{'user.domain'};
if ($status eq 'old') {
- %content = &Apache::lonnet::parse_access_controls(
- $$access_controls{$item});
- $defdom = $content{'domain'};
+ $defdom = $$access_controls{$item}{'domain'};
}
$r->print(&Apache::loncommon::coursebrowser_javascript($defdom));
$r->print(qq|
@@ -1091,11 +1064,10 @@
' <option value="">'.&mt('Please select').'</option>';
$r->print(&Apache::loncommon::start_data_table_row());
if ($status eq 'old') {
- my %content = &Apache::lonnet::parse_access_controls(
- $$access_controls{$item});
- my @curr_doms = @{$content{'dom'}};
- foreach my $dom (@{$all_doms}) {
- if ((@{$content{'dom'}} > 0) && (grep(/^\Q$dom\E$/,@{$content{'dom'}}))) {
+ my $content = $$access_controls{$item};
+ foreach my $dom (@{$all_doms}) {
+ if ((@{$content->{'dom'}} > 0)
+ && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
$dom_select .= '<option value="'.$dom.'" selected>'.
$dom.'</option>';
} else {
@@ -1120,9 +1092,8 @@
'users');
my $curr_user_list;
if ($status eq 'old') {
- my %content = &Apache::lonnet::parse_access_controls(
- $$access_controls{$item});
- $curr_user_list = &sort_users($content{'users'});
+ my $content = $$access_controls{$item};
+ $curr_user_list = &sort_users($content->{'users'});
}
$r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30" rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
$r->print(&Apache::loncommon::end_data_table_row());
--albertel1150990416--