--- loncom/interface/domainprefs.pm 2008/05/15 01:56:44 1.51
+++ loncom/interface/domainprefs.pm 2008/05/29 02:58:41 1.52
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.51 2008/05/15 01:56:44 raeburn Exp $
+# $Id: domainprefs.pm,v 1.52 2008/05/29 02:58:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1962,7 +1962,8 @@ sub print_coursecategories {
my $itemcount = 1;
if (ref($settings) eq 'HASH') {
my (@cats,@trails,%allitems,%idx,@jsarray);
- &extract_categories($settings,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
+ &Apache::loncommon::extract_categories($settings,\@cats,\@trails,
+ \%allitems,\%idx,\@jsarray);
my $maxdepth = scalar(@cats);
my $colattrib = '';
if ($maxdepth > 2) {
@@ -2067,7 +2068,7 @@ sub coursecategories_javascript {
my ($output,$jstext);
if (ref($settings) eq 'HASH') {
my (@cats,@jsarray,%idx);
- &gather_categories($settings,\@cats,\%idx,\@jsarray);
+ &Apache::loncommon::gather_categories($settings,\@cats,\%idx,\@jsarray);
if (@jsarray > 0) {
$jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
for (my $i=0; $i<@jsarray; $i++) {
@@ -4239,7 +4240,7 @@ sub modify_coursecategories {
if (ref($domconfig{'coursecategories'}) eq 'HASH') {
if (@deletecategory > 0) {
#FIXME Need to remove category from all courses using a deleted category
- &extract_categories($domconfig{'coursecategories'},\@predelcats,\@predeltrails,\%predelallitems);
+ &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@predelcats,\@predeltrails,\%predelallitems);
foreach my $item (@deletecategory) {
if ($domconfig{'coursecategories'}{$item} ne '') {
delete($domconfig{'coursecategories'}{$item});
@@ -4299,7 +4300,7 @@ sub modify_coursecategories {
}
}
my (@chkcats,@chktrails,%chkallitems);
- &extract_categories($domconfig{'coursecategories'},\@chkcats,\@chktrails,\%chkallitems);
+ &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@chkcats,\@chktrails,\%chkallitems);
if (ref($chkcats[0]) eq 'ARRAY') {
my $depth = 0;
my $chg = 0;
@@ -4321,7 +4322,7 @@ sub modify_coursecategories {
}
my $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
my (@cats,@trails,%allitems);
- &extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems);
+ &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems);
if ($putresult eq 'ok') {
$resulttext = &mt('Changes made:').'
';
if (keys(%deletions) > 0) {
@@ -4406,91 +4407,6 @@ sub recurse_cat_deletes {
}
}
return;
-}
-
-sub gather_categories {
- my ($categories,$cats,$idx,$jsarray) = @_;
- my %counters;
- my $num = 0;
- foreach my $item (keys(%{$categories})) {
- my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
- if ($container eq '' && $depth == 0) {
- $cats->[$depth][$categories->{$item}] = $cat;
- } else {
- $cats->[$depth]{$container}[$categories->{$item}] = $cat;
- }
- my ($escitem,$tail) = split(/:/,$item,2);
- if ($counters{$tail} eq '') {
- $counters{$tail} = $num;
- $num ++;
- }
- if (ref($idx) eq 'HASH') {
- $idx->{$item} = $counters{$tail};
- }
- if (ref($jsarray) eq 'ARRAY') {
- push(@{$jsarray->[$counters{$tail}]},$item);
- }
- }
- return;
-}
-
-sub extract_categories {
- my ($categories,$cats,$trails,$allitems,$idx,$jsarray) = @_;
- if (ref($categories) eq 'HASH') {
- &gather_categories($categories,$cats,$idx,$jsarray);
- if (ref($cats->[0]) eq 'ARRAY') {
- for (my $i=0; $i<@{$cats->[0]}; $i++) {
- my $name = $cats->[0][$i];
- my $item = &escape($name).'::0';
- my $trailstr;
- if ($name eq 'instcode') {
- $trailstr = &mt('Official courses (with institutional codes)');
- } else {
- $trailstr = $name;
- }
- if ($allitems->{$item} eq '') {
- push(@{$trails},$trailstr);
- $allitems->{$item} = scalar(@{$trails})-1;
- }
- my @parents = ($name);
- if (ref($cats->[1]{$name}) eq 'ARRAY') {
- for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
- my $category = $cats->[1]{$name}[$j];
- &recurse_categories($cats,2,$category,$trails,$allitems,\@parents);
- }
- }
- }
- }
- }
- return;
-}
-
-sub recurse_categories {
- my ($cats,$depth,$category,$trails,$allitems,$parents) = @_;
- my $shallower = $depth - 1;
- if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
- for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
- my $name = $cats->[$depth]{$category}[$k];
- my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
- my $trailstr = join(' -> ',(@{$parents},$category));
- if ($allitems->{$item} eq '') {
- push(@{$trails},$trailstr);
- $allitems->{$item} = scalar(@{$trails})-1;
- }
- my $deeper = $depth+1;
- push(@{$parents},$category);
- &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents);
- pop(@{$parents});
- }
- } else {
- my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
- my $trailstr = join(' -> ',(@{$parents},$category));
- if ($allitems->{$item} eq '') {
- push(@{$trails},$trailstr);
- $allitems->{$item} = scalar(@{$trails})-1;
- }
- }
- return;
}
1;