version 1.48, 2008/05/07 23:01:50
|
version 1.49, 2008/05/08 22:13:32
|
Line 370 sub process_changes {
|
Line 370 sub process_changes {
|
sub print_config_box { |
sub print_config_box { |
my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_; |
my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_; |
my $rowtotal = 0; |
my $rowtotal = 0; |
my $output = |
my $output; |
|
if ($action eq 'coursecategories') { |
|
$output = &coursecategories_javascript($settings); |
|
} |
|
$output .= |
'<table class="LC_nested_outer"> |
'<table class="LC_nested_outer"> |
<tr> |
<tr> |
<th align="left"><span class="LC_nobreak">'.&mt($item->{text}). |
<th align="left"><span class="LC_nobreak">'.&mt($item->{text}). |
Line 1935 sub legacy_scantronformat {
|
Line 1939 sub legacy_scantronformat {
|
return ($url,$error); |
return ($url,$error); |
} |
} |
|
|
sub print_coursecategories { |
sub print_coursecategories { |
my ($dom,$item,$settings,$rowtotal) = @_; |
my ($dom,$hdritem,$settings,$rowtotal) = @_; |
my ($datatable,$css_class); |
my ($datatable,$css_class); |
my $itemcount = 1; |
my $itemcount = 1; |
# FIXME Need to add javascrpt to update other select boxes when one is changed. |
|
if (ref($settings) eq 'HASH') { |
if (ref($settings) eq 'HASH') { |
my (@cats,@trails,%allitems); |
my (@cats,@trails,%allitems,%idx,@jsarray); |
&extract_categories($settings,\@cats,\@trails,\%allitems); |
&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) { |
$colattrib = ' colspan="2" '; |
$colattrib = ' colspan="2" '; |
Line 1956 sub print_coursecategories {
|
Line 1959 sub print_coursecategories {
|
if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { |
if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { |
$maxnum ++; |
$maxnum ++; |
} |
} |
|
my $lastidx; |
for (my $i=0; $i<$numtop; $i++) { |
for (my $i=0; $i<$numtop; $i++) { |
my $parent = $cats[0][$i]; |
my $parent = $cats[0][$i]; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
my $item = &escape($parent).'::0'; |
my $item = &escape($parent).'::0'; |
|
my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"'; |
|
$lastidx = $idx{$item}; |
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">' |
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">' |
.'<select name="'.$item.'">'; |
.'<select name="'.$item.'"'.$chgstr.'>'; |
for (my $k=0; $k<=$maxnum; $k++) { |
for (my $k=0; $k<=$maxnum; $k++) { |
my $vpos = $k+1; |
my $vpos = $k+1; |
my $selstr; |
my $selstr; |
Line 1986 sub print_coursecategories {
|
Line 1992 sub print_coursecategories {
|
} |
} |
my $depth = 1; |
my $depth = 1; |
push(@path,$parent); |
push(@path,$parent); |
$datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path); |
$datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx); |
pop(@path); |
pop(@path); |
$datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>'; |
$datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>'; |
$itemcount ++; |
$itemcount ++; |
} |
} |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos">'; |
my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"'; |
|
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>'; |
for (my $k=0; $k<=$maxnum; $k++) { |
for (my $k=0; $k<=$maxnum; $k++) { |
my $vpos = $k+1; |
my $vpos = $k+1; |
my $selstr; |
my $selstr; |
Line 2007 sub print_coursecategories {
|
Line 2014 sub print_coursecategories {
|
$itemcount ++; |
$itemcount ++; |
if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { |
if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
|
my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"'; |
$datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'. |
$datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'. |
'<span class="LC_nobreak"><select name="instcode_pos">'; |
'<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>'; |
for (my $k=0; $k<=$maxnum; $k++) { |
for (my $k=0; $k<=$maxnum; $k++) { |
my $vpos = $k+1; |
my $vpos = $k+1; |
my $selstr; |
my $selstr; |
Line 2030 sub print_coursecategories {
|
Line 2038 sub print_coursecategories {
|
$datatable .= &initialize_categories($itemcount); |
$datatable .= &initialize_categories($itemcount); |
} |
} |
} else { |
} else { |
$datatable .= '<td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>' |
$datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>' |
.&initialize_categories($itemcount); |
.&initialize_categories($itemcount); |
} |
} |
$$rowtotal += $itemcount; |
$$rowtotal += $itemcount; |
return $datatable; |
return $datatable; |
} |
} |
|
|
|
sub coursecategories_javascript { |
|
my ($settings) = @_; |
|
my ($output,$jstext); |
|
if (ref($settings) eq 'HASH') { |
|
my (@cats,@jsarray,%idx); |
|
&gather_categories($settings,\@cats,\%idx,\@jsarray); |
|
if (@jsarray > 0) { |
|
$jstext = ' var categories = Array('.scalar(@jsarray).');'."\n"; |
|
for (my $i=0; $i<@jsarray; $i++) { |
|
if (ref($jsarray[$i]) eq 'ARRAY') { |
|
my $catstr = join('","',@{$jsarray[$i]}); |
|
$jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n"; |
|
} |
|
} |
|
} |
|
} else { |
|
$jstext = ' var categories = Array(1);'."\n". |
|
' categories[0] = Array("instcode_pos");'."\n"; |
|
} |
|
$output = <<"ENDSCRIPT"; |
|
<script type="text/javascript"> |
|
function reorderCats(form,parent,item,idx) { |
|
var changedVal; |
|
$jstext |
|
var newpos = 'addcategory_pos'; |
|
var current = new Array; |
|
if (parent == '') { |
|
var has_instcode = 0; |
|
var maxtop = categories[idx].length; |
|
for (var j=0; j<maxtop; j++) { |
|
if (categories[idx][j] == 'instcode::0') { |
|
has_instcode == 1; |
|
} |
|
} |
|
if (has_instcode == 0) { |
|
categories[idx][maxtop] = 'instcode_pos'; |
|
} |
|
} else { |
|
newpos += '_'+parent; |
|
} |
|
var maxh = 1 + categories[idx].length; |
|
var current = new Array; |
|
var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value; |
|
if (item == newpos) { |
|
changedVal = newitemVal; |
|
} else { |
|
changedVal = form.elements[item].options[form.elements[item].selectedIndex].value; |
|
current[newitemVal] = newpos; |
|
} |
|
for (var i=0; i<categories[idx].length; i++) { |
|
var elementName = categories[idx][i]; |
|
if (elementName != item) { |
|
if (form.elements[elementName]) { |
|
var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value; |
|
current[currVal] = elementName; |
|
} |
|
} |
|
} |
|
var oldVal; |
|
for (var j=0; j<maxh; j++) { |
|
if (current[j] == undefined) { |
|
oldVal = j; |
|
} |
|
} |
|
if (oldVal < changedVal) { |
|
for (var k=oldVal+1; k<=changedVal ; k++) { |
|
var elementName = current[k]; |
|
form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1; |
|
} |
|
} else { |
|
for (var k=changedVal; k<oldVal; k++) { |
|
var elementName = current[k]; |
|
form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1; |
|
} |
|
} |
|
return; |
|
} |
|
</script> |
|
|
|
ENDSCRIPT |
|
return $output; |
|
} |
|
|
sub initialize_categories { |
sub initialize_categories { |
my ($itemcount) = @_; |
my ($itemcount) = @_; |
my $datatable; |
my $datatable; |
my $css_class = $itemcount%2?' class="LC_odd_row"':''; |
my $css_class = $itemcount%2?' class="LC_odd_row"':''; |
|
my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"'; |
|
|
$datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">' |
$datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">' |
.'<select name="instcode_pos"><option value="0" selected="selected">1</option>' |
.'<select name="instcode_pos"><option value="0" selected="selected">1</option>' |
.'<option value="1">2</option></select> ' |
.'<option value="1">2</option></select> ' |
Line 2052 sub initialize_categories {
|
Line 2145 sub initialize_categories {
|
.'</label></span></td></tr>'; |
.'</label></span></td></tr>'; |
$itemcount ++; |
$itemcount ++; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
$css_class = $itemcount%2?' class="LC_odd_row"':''; |
|
$chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"'; |
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">' |
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">' |
.'<select name="addcategory_pos"><option value="0">1</option>' |
.'<select name="addcategory_pos"'.$chgstr/'><option value="0">1</option>' |
.'<option value="1" selected="selected">2</option></select> ' |
.'<option value="1" selected="selected">2</option></select> ' |
.&mt('Add category').'</td><td>'.&mt('Name:') |
.&mt('Add category').'</td><td>'.&mt('Name:') |
.' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>'; |
.' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>'; |
Line 2061 sub initialize_categories {
|
Line 2155 sub initialize_categories {
|
} |
} |
|
|
sub build_category_rows { |
sub build_category_rows { |
my ($itemcount,$cats,$depth,$parent,$path) = @_; |
my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_; |
my ($text,$name,$item); |
my ($text,$name,$item,$chgstr); |
if (ref($cats) eq 'ARRAY') { |
if (ref($cats) eq 'ARRAY') { |
my $maxdepth = scalar(@{$cats}); |
my $maxdepth = scalar(@{$cats}); |
if (ref($cats->[$depth]) eq 'HASH') { |
if (ref($cats->[$depth]) eq 'HASH') { |
Line 2070 sub build_category_rows {
|
Line 2164 sub build_category_rows {
|
my $numchildren = @{$cats->[$depth]{$parent}}; |
my $numchildren = @{$cats->[$depth]{$parent}}; |
my $css_class = $itemcount%2?' class="LC_odd_row"':''; |
my $css_class = $itemcount%2?' class="LC_odd_row"':''; |
$text .= '<td><table class="LC_datatable">'; |
$text .= '<td><table class="LC_datatable">'; |
|
my ($idxnum,$parent_name,$parent_item); |
|
my $higher = $depth - 1; |
|
if ($higher == 0) { |
|
$parent_name = &escape($parent).'::'.$higher; |
|
} else { |
|
if (ref($path) eq 'ARRAY') { |
|
$parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher; |
|
} |
|
} |
|
$parent_item = 'addcategory_pos_'.$parent_name; |
for (my $j=0; $j<=$numchildren; $j++) { |
for (my $j=0; $j<=$numchildren; $j++) { |
if ($j == $numchildren) { |
if ($j < $numchildren) { |
my $higher = $depth-1; |
|
if ($higher == 0) { |
|
$name = &escape($parent).'::'.$higher; |
|
} else { |
|
if (ref($path) eq 'ARRAY') { |
|
$name = &escape($parent).':'.&escape($path->[-2]).':'.$higher; |
|
} |
|
} |
|
$item = 'addcategory_pos_'.$name; |
|
} else { |
|
$name = $cats->[$depth]{$parent}[$j]; |
$name = $cats->[$depth]{$parent}[$j]; |
$item = &escape($name).':'.&escape($parent).':'.$depth; |
$item = &escape($name).':'.&escape($parent).':'.$depth; |
|
$idxnum = $idx->{$item}; |
|
} else { |
|
$name = $parent_name; |
|
$item = $parent_item; |
} |
} |
$text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'">'; |
$chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"'; |
|
$text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>'; |
for (my $i=0; $i<=$numchildren; $i++) { |
for (my $i=0; $i<=$numchildren; $i++) { |
my $vpos = $i+1; |
my $vpos = $i+1; |
my $selstr; |
my $selstr; |
Line 2102 sub build_category_rows {
|
Line 2201 sub build_category_rows {
|
.$item.'" />'.&mt('Delete').'</label></span></td><td>'; |
.$item.'" />'.&mt('Delete').'</label></span></td><td>'; |
if(ref($path) eq 'ARRAY') { |
if(ref($path) eq 'ARRAY') { |
push(@{$path},$name); |
push(@{$path},$name); |
$text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path); |
$text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx); |
pop(@{$path}); |
pop(@{$path}); |
} |
} |
} else { |
} else { |
Line 4226 sub recurse_cat_deletes {
|
Line 4325 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 { |
sub extract_categories { |
my ($categories,$cats,$trails,$allitems) = @_; |
my ($categories,$cats,$trails,$allitems,$idx,$jsarray) = @_; |
if (ref($categories) eq 'HASH') { |
if (ref($categories) eq 'HASH') { |
foreach my $item (keys(%{$categories})) { |
&gather_categories($categories,$cats,$idx,$jsarray); |
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; |
|
} |
|
} |
|
if (ref($cats->[0]) eq 'ARRAY') { |
if (ref($cats->[0]) eq 'ARRAY') { |
for (my $i=0; $i<@{$cats->[0]}; $i++) { |
for (my $i=0; $i<@{$cats->[0]}; $i++) { |
my $name = $cats->[0][$i]; |
my $name = $cats->[0][$i]; |
my $item = &escape($name).'::0'; |
my $item = &escape($name).'::0'; |
my $trailstr; |
my $trailstr; |
if ($name eq 'instcode') { |
if ($name eq 'instcode') { |
$trailstr = &mt('Official courses (with institutional codes)'); |
$trailstr = &mt('Official courses (with institutional codes)'); |
} else { |
} else { |
Line 4266 sub extract_categories {
|
Line 4384 sub extract_categories {
|
|
|
sub recurse_categories { |
sub recurse_categories { |
my ($cats,$depth,$category,$trails,$allitems,$parents) = @_; |
my ($cats,$depth,$category,$trails,$allitems,$parents) = @_; |
|
my $shallower = $depth - 1; |
if (ref($cats->[$depth]{$category}) eq 'ARRAY') { |
if (ref($cats->[$depth]{$category}) eq 'ARRAY') { |
for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) { |
for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) { |
my $shallower = $depth - 1; |
|
my $name = $cats->[$depth]{$category}[$k]; |
my $name = $cats->[$depth]{$category}[$k]; |
my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower; |
my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower; |
my $trailstr = join(' -> ',(@{$parents},$category)); |
my $trailstr = join(' -> ',(@{$parents},$category)); |
Line 4282 sub recurse_categories {
|
Line 4400 sub recurse_categories {
|
pop(@{$parents}); |
pop(@{$parents}); |
} |
} |
} else { |
} else { |
$depth --; |
my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower; |
my $item = &escape($category).':'.&escape($parents->[-1]).':'.$depth; |
|
my $trailstr = join(' -> ',(@{$parents},$category)); |
my $trailstr = join(' -> ',(@{$parents},$category)); |
if ($allitems->{$item} eq '') { |
if ($allitems->{$item} eq '') { |
push(@{$trails},$trailstr); |
push(@{$trails},$trailstr); |