version 1.5, 2008/03/21 18:00:18
|
version 1.14, 2011/03/03 00:06:38
|
Line 30 package Apache::courseclassifier;
|
Line 30 package Apache::courseclassifier;
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::loncommon; |
|
use Apache::lonlocal; |
use LONCAPA; |
use LONCAPA; |
|
|
sub retrieve_instcodes { |
sub retrieve_instcodes { |
Line 38 sub retrieve_instcodes {
|
Line 40 sub retrieve_instcodes {
|
my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.', undef,undef,'Course'); |
my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.', undef,undef,'Course'); |
foreach my $course (keys(%courses)) { |
foreach my $course (keys(%courses)) { |
if (ref($courses{$course}) eq 'HASH') { |
if (ref($courses{$course}) eq 'HASH') { |
$$coursecodes{$course} = $courses{$course}{'inst_code'}; |
if ($courses{$course}{'inst_code'} ne '') { |
$totcodes ++; |
$$coursecodes{$course} = $courses{$course}{'inst_code'}; |
|
$totcodes ++; |
|
} |
} |
} |
} |
} |
return $totcodes; |
return $totcodes; |
Line 51 sub sort_cats {
|
Line 55 sub sort_cats {
|
if (defined($$cat_order{$$codetitles[$num]})) { |
if (defined($$cat_order{$$codetitles[$num]})) { |
foreach my $item (@{$$cat_order{$$codetitles[$num]}}) { |
foreach my $item (@{$$cat_order{$$codetitles[$num]}}) { |
if (grep/^\Q$item\E$/,@unsorted) { |
if (grep/^\Q$item\E$/,@unsorted) { |
push @{$sorted}, $item; |
push(@{$sorted},$item); |
} |
} |
} |
} |
} else { |
} else { |
Line 257 sub build_code_selections {
|
Line 261 sub build_code_selections {
|
sub javascript_code_selections { |
sub javascript_code_selections { |
my ($formname,@codetitles) = @_; |
my ($formname,@codetitles) = @_; |
my $numtitles = @codetitles; |
my $numtitles = @codetitles; |
|
my %lt = &Apache::lonlocal::texthash( |
|
Select => 'Select', |
|
Pick => 'Pick', |
|
); |
my $output = (<<END_OF_BLOCK); |
my $output = (<<END_OF_BLOCK); |
var display = new Array($numtitles) |
var display = new Array($numtitles) |
if (caller == "" || caller == "$codetitles[0]") { |
if (caller == "" || caller == "$codetitles[0]") { |
if (caller == "") { |
if (caller == "") { |
document.$formname.Year.length = 0 |
document.$formname.Year.length = 0 |
document.$formname.Year.options[0] = new Option("Select","-1",true,true) |
document.$formname.Year.options[0] = new Option("$lt{'Select'}","-1",true,true) |
display[0] = new Array(idyears.length) |
display[0] = new Array(idyears.length) |
for (var i=0; i<idyears.length; i++) { |
for (var i=0; i<idyears.length; i++) { |
display[0][i] = idyears[i] |
display[0][i] = idyears[i] |
Line 283 sub javascript_code_selections {
|
Line 291 sub javascript_code_selections {
|
document.$formname.Semester.length = 0 |
document.$formname.Semester.length = 0 |
document.$formname.Department.length = 0; |
document.$formname.Department.length = 0; |
document.$formname.Number.length = 0 |
document.$formname.Number.length = 0 |
document.$formname.Department.options[0] = new Option("<-Pick $codetitles[1]","-1",true,true) |
document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true) |
document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true) |
document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true) |
if (idyr == 0 || caller == "") { |
if (idyr == 0 || caller == "") { |
document.$formname.Semester.options[0] = new Option("<-Pick $codetitles[0]","-1",true,true) |
document.$formname.Semester.options[0] = new Option("<-$lt{'Pick'} $codetitles[0]","-1",true,true) |
} |
} |
else { |
else { |
document.$formname.Semester.options[0] = new Option("Select","-1",true,true) |
document.$formname.Semester.options[0] = new Option("$lt{'Select'}","-1",true,true) |
display[1] = new Array(idsems[idyr-1].length) |
display[1] = new Array(idsems[idyr-1].length) |
for (var i=0; i<idsems[idyr-1].length; i++) { |
for (var i=0; i<idsems[idyr-1].length; i++) { |
display[1][i] = idsems[idyr-1][i] |
display[1][i] = idsems[idyr-1][i] |
Line 308 sub javascript_code_selections {
|
Line 316 sub javascript_code_selections {
|
document.$formname.Number.length = 0 |
document.$formname.Number.length = 0 |
document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true) |
document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true) |
if (idsem == 0) { |
if (idsem == 0) { |
document.$formname.Department.options[0] = new Option("<-Pick $codetitles[1]","-1",true,true) |
document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true) |
} |
} |
else { |
else { |
document.$formname.Department.options[0] = new Option("Select","-1",true,true) |
document.$formname.Department.options[0] = new Option("$lt{'Select'}","-1",true,true) |
display[2] = new Array(idcodes[idyr-1][idsem-1].length) |
display[2] = new Array(idcodes[idyr-1][idsem-1].length) |
for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) { |
for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) { |
display[2][i] = idcodes[idyr-1][idsem-1][i] |
display[2][i] = idcodes[idyr-1][idsem-1][i] |
Line 328 sub javascript_code_selections {
|
Line 336 sub javascript_code_selections {
|
if (caller == "$codetitles[2]") { |
if (caller == "$codetitles[2]") { |
document.$formname.Number.length = 0 |
document.$formname.Number.length = 0 |
if (iddept == 0) { |
if (iddept == 0) { |
document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true) |
document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true) |
} |
} |
else { |
else { |
document.$formname.Number.options[0] = new Option("Select","-1",true,true) |
document.$formname.Number.options[0] = new Option("Select","-1",true,true) |
Line 431 sub javascript_definitions {
|
Line 439 sub javascript_definitions {
|
sub courseset_js_start { |
sub courseset_js_start { |
my ($formname,$longtitles_str,$allidlist) = @_; |
my ($formname,$longtitles_str,$allidlist) = @_; |
my $output = <<END; |
my $output = <<END; |
|
|
function courseSet(caller) { |
function courseSet(caller) { |
var longtitles = new Array ("$longtitles_str"); |
var longtitles = new Array ("$longtitles_str"); |
var idyr = document.$formname.Year.selectedIndex |
var idyr = document.$formname.Year.selectedIndex |
Line 442 END
|
Line 451 END
|
return $output; |
return $output; |
} |
} |
|
|
|
sub instcode_selectors_data { |
|
my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order,$officialjs) = @_; |
|
my ($jscript,%coursecodes,%codes,%idlist,%idnums,%idlist_titles, |
|
%by_year,%by_sem,%by_dept); |
|
my ($numtitles,$lasttitle); |
|
my $caller = 'global'; |
|
my $totcodes = &retrieve_instcodes(\%coursecodes,$codedom); |
|
if ($totcodes > 0) { |
|
if (&Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes, |
|
\%codes,$codetitles,$cat_titles,$cat_order) eq 'ok') { |
|
&build_code_selections(\%codes,$codetitles,$cat_titles,$cat_order, |
|
\%idlist,\%idnums,\%idlist_titles); |
|
my ($scripttext,$longtitles) = |
|
&javascript_definitions($codetitles,\%idlist,\%idlist_titles, |
|
\%idnums,$cat_titles); |
|
my $longtitles_str = join('","',@{$longtitles}); |
|
my $allidlist = $idlist{$codetitles->[0]}; |
|
$numtitles = @{$codetitles}; |
|
$lasttitle = $numtitles; |
|
if ($numtitles > 4) { |
|
$lasttitle = 4; |
|
} |
|
if ($numtitles == 0) { |
|
if (!defined($env{'form.state'})) { |
|
$env{'form.state'} = 'listing'; |
|
} |
|
} else { |
|
my @data = ('top'); |
|
for (my $k=0; $k<$lasttitle; $k++) { |
|
my $cat = $codetitles->[$k]; |
|
my $level = 1; |
|
$level = &recurse_options($codetitles->[$k],$idlist{$codetitles->[$k]},$level,$cat,$cat_items,\@data,\%by_year,\%by_sem,\%by_dept); |
|
} |
|
$scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,$cat_order,$codetitles); |
|
if ($officialjs) { |
|
$jscript .= ' |
|
|
|
function toggleOfficial() {'; |
|
for (my $i=0; $i<@{$codetitles}-1; $i++) { |
|
$jscript .= ' |
|
document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;'; |
|
} |
|
$jscript .= ' |
|
} |
|
|
|
function setOfficial(caller) { |
|
if (typeof(caller) != "undefined") { |
|
if (caller.options[caller.selectedIndex].value != 0) { |
|
if (document.'.$formname.'.official.length > 0) { |
|
for (var j=0; j<document.'.$formname.'.official.length; j++) { |
|
if (document.'.$formname.'.official[j].value == "on") { |
|
document.'.$formname.'.official[j].checked = true; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
'; |
|
|
|
$officialjs = 'setOfficial(caller);'; |
|
} |
|
$jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs); |
|
if ($env{'form.state'} eq 'listing') { |
|
my @standardnames = &Apache::loncommon::get_standard_codeitems(); |
|
my %local_to_standard; |
|
if (ref($codetitles) eq 'ARRAY') { |
|
for (my $i=0; $i<@{$codetitles}; $i++) { |
|
$local_to_standard{$codetitles->[$i]} = $standardnames[$i]; |
|
} |
|
} |
|
$jscript .= ' |
|
function setElements() { |
|
'; |
|
for (my $i=0; $i<@{$codetitles}-1; $i++) { |
|
my $item = $local_to_standard{$codetitles->[$i]}; |
|
if ($env{'form.'.$item} != -1) { |
|
$jscript .= ' |
|
for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) { |
|
if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") { |
|
document.'.$formname.'.'.$item.'.selectedIndex = j; |
|
} |
|
} |
|
'; |
|
} |
|
} |
|
$jscript .= ' courseSet()'."\n"; |
|
my $lastcodetitle = $local_to_standard{$codetitles->[-1]}; |
|
if ($env{'form.'.$lastcodetitle} != -1) { |
|
$jscript .= ' |
|
for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) { |
|
if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") { |
|
document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j; |
|
} |
|
} |
|
'; |
|
} |
|
$jscript .= '}'; |
|
} |
|
} |
|
} |
|
} |
|
return ($jscript,$totcodes,$numtitles,$lasttitle); |
|
} |
|
|
|
sub build_instcode_selectors { |
|
my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_; |
|
my $output; |
|
my @standardnames = &Apache::loncommon::get_standard_codeitems(); |
|
if ($numtitles > 0) { |
|
$output .= '<table><tr>'; |
|
for (my $k=0; $k<$lasttitle-1; $k++) { |
|
my (@items,@unsorted); |
|
if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') { |
|
@unsorted = @{$cat_items->{$codetitles->[$k]}}; |
|
} |
|
&sort_cats($k,$cat_order,$codetitles,\@unsorted,\@items); |
|
my @longitems; |
|
if (defined($cat_titles->{$codetitles->[$k]})) { |
|
foreach my $item (@items) { |
|
push(@longitems,$cat_titles->{$codetitles->[$k]}{$item}); |
|
} |
|
} else { |
|
@longitems = @items; |
|
} |
|
$output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n". |
|
'<select name="'.$standardnames[$k].'" onChange="courseSet(this)"'. |
|
'>'."\n".'<option value="0">'.&mt('All').'</option>'."\n"; |
|
for (my $i=0; $i<@items; $i++) { |
|
if ($longitems[$i] eq '') { |
|
$longitems[$i] = $items[$i]; |
|
} |
|
$output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'; |
|
} |
|
$output .= '</select></td>'; |
|
} |
|
$output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n". |
|
'<select name="'.$standardnames[$lasttitle-1].'">'."\n". |
|
'<option value="0">'.&mt('All')."\n". |
|
'</option>'."\n".'</select>'."\n". |
|
'</td></tr></table>'."\n"; |
|
if ($numtitles > 4) { |
|
$output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n". |
|
'<input type="text" name="'.$standardnames[$numtitles-1]. |
|
'" /><br />'."\n"; |
|
} |
|
$output .= '<br />'; |
|
} |
|
return $output; |
|
} |
|
|
|
sub recurse_options { |
|
my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_; |
|
if (ref($currlist) eq 'HASH') { |
|
$level ++; |
|
foreach my $key (sort(keys(%{$currlist}))) { |
|
$$data[$level-1]= $key; |
|
&recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept); |
|
} |
|
} else { |
|
$level --; |
|
my @contents = split(/","/,$currlist); |
|
foreach my $item (@contents) { |
|
if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) { |
|
push(@{$cat_options->{$cat}},$item); |
|
} |
|
if ($level == 3) { |
|
if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) { |
|
push(@{$by_year->{$data->[1]}->{$currkey}},$item); |
|
} |
|
if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) { |
|
push(@{$by_sem->{$data->[2]}->{$currkey}},$item); |
|
} |
|
if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) { |
|
push(@{$by_dept->{$currkey}},$item); |
|
} |
|
|
|
} |
|
} |
|
} |
|
return $level; |
|
} |
|
|
|
sub build_javascript { |
|
my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_; |
|
my @unsorted = keys(%{$by_year}); |
|
my @sorted_yrs; |
|
&sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs); my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n". |
|
'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n". |
|
'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n"; |
|
for (my $i=0; $i<@sorted_yrs; $i++) { |
|
my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}}); |
|
$output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n"; |
|
if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') { |
|
@unsorted = keys(%{$by_year->{$sorted_yrs[$i]}}); |
|
my @sorted_depts; |
|
&Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts); |
|
$output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n"; |
|
for (my $j=0; $j<@sorted_depts; $j++) { |
|
$output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|; |
|
$output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n"; |
|
} |
|
} |
|
} |
|
@unsorted = keys(%{$by_sem}); |
|
my @sorted_sems; |
|
&sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems); |
|
$output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n". |
|
'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n". |
|
'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n"; |
|
for (my $i=0; $i<@sorted_sems; $i++) { |
|
my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}}); |
|
$output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n"; |
|
if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') { |
|
@unsorted = keys(%{$by_sem->{$sorted_sems[$i]}}); |
|
my @sorted_depts; |
|
&sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts); |
|
$output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n"; |
|
for (my $j=0; $j<@sorted_depts; $j++) { |
|
$output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n"; |
|
} |
|
} |
|
} |
|
@unsorted = keys(%{$by_dept}); |
|
my @sorted_deps; |
|
&sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps); |
|
$output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n"; |
|
for (my $k=0; $k<@sorted_deps; $k++) { |
|
$output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n"; |
|
} |
|
return $output; |
|
} |
|
|
|
sub javascript_select_filler { |
|
my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_; |
|
my $all = &mt('All'); |
|
my $nocrs = &mt('No courses'); |
|
my $output = <<END; |
|
|
|
function courseSet(caller) { |
|
var longtitles = new Array ("$longtitles_str"); |
|
var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value |
|
var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value |
|
var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value |
|
var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value |
|
var idyears = new Array("$allidlist"); |
|
var idyr = -1; |
|
var idsem = -1; |
|
var iddept = -1; |
|
document.$formname.Number.length = 0; |
|
|
|
$scripttext |
|
|
|
selYear = document.$formname.Year.selectedIndex-1; |
|
selSemester = document.$formname.Semester.selectedIndex-1; |
|
selDepartment = document.$formname.Department.selectedIndex-1; |
|
if (selYear == -1) { |
|
if (selSemester == -1) { |
|
if (selDepartment > -1) { |
|
document.$formname.Number.options[0] = new Option('$all','0',false,false); |
|
for (var k=0; k<idcse_by_dep[selDepartment].length; k++) { |
|
document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false); |
|
|
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$all','0',true,true); |
|
} |
|
} |
|
else { |
|
if (selDepartment > -1) { |
|
for (var i=0; i<idcse_by_sem_sems.length; i++) { |
|
if (idcse_by_sem_sems[i] == valsem) { |
|
idsem = i; |
|
} |
|
} |
|
if (idsem != -1) { |
|
for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) { |
|
if (idcse_by_sem_dept[idsem][i] == valdept) { |
|
iddept = i; |
|
} |
|
} |
|
} |
|
if (iddept != -1) { |
|
document.$formname.Number.options[0] = new Option('$all','0',false,false); |
|
for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) { |
|
document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false); |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$nocrs','0',true,true); |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$all','0',true,true); |
|
} |
|
} |
|
} |
|
else { |
|
if (selSemester == -1) { |
|
if (selDepartment > -1) { |
|
for (var i=0; i<idcse_by_yr_year.length; i++) { |
|
if (idcse_by_yr_year[i] == valyr) { |
|
idyr = i; |
|
} |
|
} |
|
if (idyr != -1) { |
|
for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) { |
|
if (idcse_by_yr_dept[idyr][i] == valdept) { |
|
iddept = i; |
|
} |
|
} |
|
} |
|
if (iddept != -1) { |
|
document.$formname.Number.options[0] = new Option('$all','0',false,false); |
|
for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) { |
|
document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false); |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$nocrs','0',true,true); |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$all','0',true,true); |
|
} |
|
} |
|
else { |
|
if (selDepartment > -1) { |
|
for (var k=0; k<idyears.length; k++) { |
|
if (idyears[k] == valyr) { |
|
idyr = k; |
|
} |
|
} |
|
if (idyr != -1) { |
|
for (var k=0; k<idsems[idyr].length; k++) { |
|
if (idsems[idyr][k] == valsem) { |
|
idsem = k; |
|
} |
|
} |
|
} |
|
if (idsem != -1) { |
|
for (var k=0; k<idcodes[idyr][idsem].length; k++) { |
|
if (idcodes[idyr][idsem][k] == valdept) { |
|
iddept = k; |
|
} |
|
} |
|
} |
|
if (iddept != -1) { |
|
document.$formname.Number.options[0] = new Option('$all','0',false,false); |
|
for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) { |
|
var display = idcourses[idyr][idsem][iddept][i]; |
|
if (longtitles[3] == 1) { |
|
if (idcourseslongs[idyr][idsem][iddept][i] != "") { |
|
display = idcourseslongs[idyr][idsem][iddept][i] |
|
} |
|
} |
|
document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false) |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$nocrs','0',true,true); |
|
} |
|
} |
|
else { |
|
document.$formname.Number.options[0] = new Option('$all','0',true,true); |
|
} |
|
} |
|
document.$formname.Number.selectedIndex = 0 |
|
} |
|
$officialjs |
|
} |
|
END |
|
return $output; |
|
} |
|
|
|
sub instcode_search_str { |
|
my ($domain,$numtitles,$codetitles) = @_; |
|
my $instcode; |
|
if (defined($numtitles) && $numtitles == 0) { |
|
$instcode = '.+'; |
|
} else { |
|
my (%codedefaults,@code_order); |
|
my $defaults_result = |
|
&Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults, |
|
\@code_order); |
|
my @standardnames = &Apache::loncommon::get_standard_codeitems(); |
|
my %local_to_standard; |
|
if (ref($codetitles) eq 'ARRAY') { |
|
for (my $i=0; $i<@{$codetitles}; $i++) { |
|
$local_to_standard{$codetitles->[$i]} = $standardnames[$i]; |
|
} |
|
} |
|
if ($defaults_result eq 'ok') { |
|
$instcode ='^'; |
|
foreach my $loctitle (@code_order) { |
|
my $item = $local_to_standard{$loctitle}; |
|
if ($item ne '') { |
|
if ($env{'form.'.$item} eq '0' ) { |
|
$instcode .= $codedefaults{$loctitle}; |
|
} else { |
|
$instcode .= $env{'form.'.$item}; |
|
} |
|
} else { |
|
$instcode .= '.+'; |
|
} |
|
} |
|
$instcode .= '$'; |
|
} else { |
|
$instcode = '.+'; |
|
} |
|
} |
|
return $instcode; |
|
} |
|
|
|
sub instcode_from_selectors { |
|
my ($cdom,$noregexps) = @_; |
|
my $instcode; |
|
my $caller = 'global'; |
|
my (%coursecodes,%codes,@codetitles,%cat_titles,%cat_order, |
|
%codedefaults,@code_order); |
|
my $format_reply = |
|
&Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes, |
|
\%codes,\@codetitles,\%cat_titles,\%cat_order); |
|
my $defaults_result = |
|
&Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults, |
|
\@code_order); |
|
if (($defaults_result eq 'ok') && ($format_reply eq 'ok')) { |
|
my @standardnames = &Apache::loncommon::get_standard_codeitems(); |
|
my %local_to_standard; |
|
for (my $i=0; $i<@codetitles; $i++) { |
|
$local_to_standard{$codetitles[$i]} = $standardnames[$i]; |
|
} |
|
foreach my $loctitle (@code_order) { |
|
my $category = $local_to_standard{$loctitle}; |
|
if ($category ne '') { |
|
if ($env{'form.'.$category} eq '-1' ) { |
|
if ($noregexps) { |
|
$instcode .= ' '; |
|
} else { |
|
$instcode .= $codedefaults{$category}; |
|
} |
|
} else { |
|
$instcode .= $env{'form.'.$category}; |
|
} |
|
} else { |
|
$instcode .= '.+'; |
|
} |
|
} |
|
} |
|
return $instcode; |
|
} |
|
|
1; |
1; |
|
|