version 1.51, 2008/05/15 01:56:44
|
version 1.52, 2008/05/29 02:58:41
|
Line 1962 sub print_coursecategories {
|
Line 1962 sub print_coursecategories {
|
my $itemcount = 1; |
my $itemcount = 1; |
if (ref($settings) eq 'HASH') { |
if (ref($settings) eq 'HASH') { |
my (@cats,@trails,%allitems,%idx,@jsarray); |
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 $maxdepth = scalar(@cats); |
my $colattrib = ''; |
my $colattrib = ''; |
if ($maxdepth > 2) { |
if ($maxdepth > 2) { |
Line 2067 sub coursecategories_javascript {
|
Line 2068 sub coursecategories_javascript {
|
my ($output,$jstext); |
my ($output,$jstext); |
if (ref($settings) eq 'HASH') { |
if (ref($settings) eq 'HASH') { |
my (@cats,@jsarray,%idx); |
my (@cats,@jsarray,%idx); |
&gather_categories($settings,\@cats,\%idx,\@jsarray); |
&Apache::loncommon::gather_categories($settings,\@cats,\%idx,\@jsarray); |
if (@jsarray > 0) { |
if (@jsarray > 0) { |
$jstext = ' var categories = Array('.scalar(@jsarray).');'."\n"; |
$jstext = ' var categories = Array('.scalar(@jsarray).');'."\n"; |
for (my $i=0; $i<@jsarray; $i++) { |
for (my $i=0; $i<@jsarray; $i++) { |
Line 4239 sub modify_coursecategories {
|
Line 4240 sub modify_coursecategories {
|
if (ref($domconfig{'coursecategories'}) eq 'HASH') { |
if (ref($domconfig{'coursecategories'}) eq 'HASH') { |
if (@deletecategory > 0) { |
if (@deletecategory > 0) { |
#FIXME Need to remove category from all courses using a deleted category |
#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) { |
foreach my $item (@deletecategory) { |
if ($domconfig{'coursecategories'}{$item} ne '') { |
if ($domconfig{'coursecategories'}{$item} ne '') { |
delete($domconfig{'coursecategories'}{$item}); |
delete($domconfig{'coursecategories'}{$item}); |
Line 4299 sub modify_coursecategories {
|
Line 4300 sub modify_coursecategories {
|
} |
} |
} |
} |
my (@chkcats,@chktrails,%chkallitems); |
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') { |
if (ref($chkcats[0]) eq 'ARRAY') { |
my $depth = 0; |
my $depth = 0; |
my $chg = 0; |
my $chg = 0; |
Line 4321 sub modify_coursecategories {
|
Line 4322 sub modify_coursecategories {
|
} |
} |
my $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom); |
my $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom); |
my (@cats,@trails,%allitems); |
my (@cats,@trails,%allitems); |
&extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems); |
&Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems); |
if ($putresult eq 'ok') { |
if ($putresult eq 'ok') { |
$resulttext = &mt('Changes made:').'<ul>'; |
$resulttext = &mt('Changes made:').'<ul>'; |
if (keys(%deletions) > 0) { |
if (keys(%deletions) > 0) { |
Line 4406 sub recurse_cat_deletes {
|
Line 4407 sub recurse_cat_deletes {
|
} |
} |
} |
} |
return; |
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; |
1; |