--- loncom/interface/lonpickcourse.pm 2008/05/31 00:50:00 1.72 +++ loncom/interface/lonpickcourse.pm 2009/05/01 01:38:20 1.78 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.72 2008/05/31 00:50:00 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.78 2009/05/01 01:38:20 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::loncoursedata; use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; +use Apache::courseclassifier; use LONCAPA; sub handler { @@ -49,7 +50,7 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', - 'multiple','type','setroles']); + 'multiple','type','setroles','fixeddom']); my ($type,$title,$jscript,$multelement,$multiple,$roleelement, $lastaction,$autosubmit,$submitopener); @@ -83,9 +84,13 @@ sub handler { } my %loaditem; + if ($env{'form.numtitles'}) { + $loaditem{'onload'} = 'setElements(); '; + } + if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && ($env{'form.pickedcourse'})) { - $loaditem{'onload'} ="setSections()"; + $loaditem{'onload'} .= 'setSections()'; } $r->print(&Apache::loncommon::start_page($title,undef, {'add_entries' => \%loaditem, @@ -117,6 +122,7 @@ sub handler { # ------------------------------------------ Display of filters to limit search my $filter = {}; my $action = '/adm/pickcourse'; + my $numtitles; if (!$onlyown) { my $filterlist = ['domainfilter','descriptfilter', 'instcodefilter','ownerfilter', @@ -127,12 +133,12 @@ sub handler { push(@{$filterlist},'coursefilter'); } $r->print(&build_filters($filterlist,$type,$roleelement,$multelement, - $filter,$action)); + $filter,$action,\$numtitles)); } # ---------------------------------------------------------------- Get the data if ($env{'form.gosearch'} || $onlyown) { - my %courses = &search_courses($r,$type,$onlyown,$filter); + my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles); &display_matched_courses($r,$type,$multiple,$action,%courses); } $r->print(&Apache::loncommon::end_page()); @@ -228,14 +234,19 @@ sub display_matched_courses { $menuchk = ' checked="checked" '; } $r->print( - ''.(' 'x3).'
'. - '

'); + '
' + .''.&mt('Action').'' + .'
' + .'
' + .'
' + .'
' + ); } } my %by_descrip; @@ -264,7 +275,7 @@ sub display_matched_courses { $r->print(&Apache::loncommon::start_data_table()); $r->print(&Apache::loncommon::start_data_table_header_row()); $r->print(''.&mt('Select').'' - .''.&mt('Course Description').'' + .''.&mt('Course Title').'' .''.&mt('Domain').'' .''.&mt('Course Code').'' .''.&mt('Owner/Co-owner(s)').'' @@ -343,18 +354,25 @@ sub display_matched_courses { $r->print(''); $r->print(''); } elsif ($env{'form.form'} eq 'modifycourse') { - $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form'])); + $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state'])); } else { $r->print(''."\n". ''."\n"); } + if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) { + $r->print(''); + } + if ($env{'form.numtitles'}) { + $r->print(''); + } $r->print("\n"); return; } - sub multiples_tag { my $jscript = &Apache::loncommon::check_uncheck_jscript(); my $multelement = ''; @@ -363,16 +381,15 @@ sub multiples_tag { sub build_filters { my ($filterlist,$type,$roleelement,$multelement,$filter,$action, - $caller) = @_; + $numtitlesref) = @_; my $list; my $formname; + my ($fixeddom,$codedom,$jscript); if (defined($env{'form.form'})) { $formname = $env{'form.form'}; - } else { - $formname = $caller; } my ($domainselectform,$sincefilterform,$ownerdomselectform, - $instcodeform,$typeselectform); + $instcodeform,$typeselectform,$instcodetitle); foreach my $item (@{$filterlist}) { $filter->{$item} = $env{'form.'.$item}; if ($item ne 'descriptfilter' && $item ne 'instcodefilter') { @@ -398,10 +415,19 @@ sub build_filters { $filter->{$item} ||= $env{'request.role.domain'}; $allow_blank=0; } - $domainselectform = - &Apache::loncommon::select_dom_form($filter->{$item}, - 'domainfilter', - $allow_blank); + if ($env{'form.fixeddom'}) { + $domainselectform = ''. + &Apache::lonnet::domain($env{'request.role.domain'}, + 'description'); + $codedom = $env{'request.role.domain'}; + } else { + $domainselectform = + &Apache::loncommon::select_dom_form($filter->{$item}, + 'domainfilter', + $allow_blank); + $codedom = $filter->{'domainfilter'}; + } } elsif ($item eq 'ownerdomfilter') { $ownerdomselectform = &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1); @@ -427,24 +453,41 @@ sub build_filters { '15552000','31104000'])); my %lt = ( - 'cac' => &mt('[_1] Activity',$type), - 'cde' => &mt('[_1] Description',$type), - 'cdo' => &mt('[_1] Domain',$type), - 'cin' => &mt('Course Institutional Code'), - 'cow' => &mt("[_1] Owner's Username",$type), - 'cod' => &mt("[_1] Owner's Domain", $type), + 'cac' => &mt("$type Activity"), + 'cde' => &mt("$type Title"), + 'cdo' => &mt("$type Domain"), + 'ins' => &mt('Institutional Code'), + 'inc' => &mt('Institutional Categorization'), + 'cow' => &mt("$type Owner's Username"), + 'cod' => &mt("$type Owner's Domain"), 'cog' => &mt('Course Type') ); $typeselectform = ''; + $instcodetitle = $lt{'ins'}; + } else { + $instcodetitle = $lt{'inc'}; + } + if ($env{'form.fixeddom'}) { + $instcodetitle .= '
('.$codedom.')'; + } + if ($jscript ne '') { + $jscript = ''."\n"; + } } foreach my $posstype ('Course','Non-standard Course') { $typeselectform.='\n"; + ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."\n"; } $typeselectform.=""; my $output = qq| @@ -469,44 +512,78 @@ $roleelement $multelement |; if ($formname eq 'portform') { - $output .= ''; + $output .= ''."\n"; } } + if ($env{'form.fixeddom'}) { + $output .= ''."\n"; + } + $output .= "
\n".&Apache::lonhtmlcommon::start_pick_box(); if ($sincefilterform) { - $output .= $lt{'cac'}.': '.$sincefilterform.'
'."\n"; + $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'}) + .$sincefilterform + .&Apache::lonhtmlcommon::row_closure(); } if ($domainselectform) { - $output .= $lt{'cdo'}.': '.$domainselectform.'
'."\n"; - } + $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'}) + .$domainselectform + .&Apache::lonhtmlcommon::row_closure(); + } if ($typeselectform) { - $output .= $lt{'cog'}.': '.$typeselectform.'
'."\n"; + $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'}) + .$typeselectform + .&Apache::lonhtmlcommon::row_closure(); } if ($instcodeform) { - $output .= $lt{'cin'}.': '.$instcodeform.'
'."\n"; + $output .= &Apache::lonhtmlcommon::row_title($instcodetitle) + .$instcodeform + .&Apache::lonhtmlcommon::row_closure(); } if (exists($filter->{'ownerfilter'})) { - $output .= $lt{'cow'}.': '. - '
'."\n". - $lt{'cod'}.': '.$ownerdomselectform.'
'."\n"; + $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($lt{'cod'}) + .$ownerdomselectform + .&Apache::lonhtmlcommon::row_closure(); } if (exists($filter->{'coursefilter'})) { - $output .= &mt('LON-CAPA course ID').': '. - '
'; + $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID')) + .'' + .&Apache::lonhtmlcommon::row_closure(); } if (exists($filter->{'descriptfilter'})) { - $output .=$lt{'cde'}.': '. - ''."\n"; + $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'}) + .'' + .&Apache::lonhtmlcommon::row_closure(1); } + $output .= &Apache::lonhtmlcommon::end_pick_box(); $output .= '

'."\n".''."\n".'
'."\n"; - return $output; + return $jscript.$output; +} + +sub instcode_selectors { + my ($codedom,$formname) = @_; + my ($output,@codetitles,%cat_titles,%cat_order,%cat_items); + my ($jscript,$totcodes,$numtitles,$lasttitle) = + &Apache::courseclassifier::instcode_selectors_data($codedom,$formname, + \%cat_items,\@codetitles,\%cat_titles,\%cat_order); + if ($numtitles > 0) { + $output = &Apache::courseclassifier::build_instcode_selectors($numtitles, + $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n". + ''."\n". + ''."\n"; + + } + return ($output,$jscript,$numtitles); } sub search_courses { - my ($r,$type,$onlyown,$filter) = @_; + my ($r,$type,$onlyown,$filter,$numtitles) = @_; my %courses; if (!$onlyown) { $r->print(&mt('Searching ...').'
 
'); @@ -525,14 +602,23 @@ sub search_courses { if ($type eq '') { $type = '.'; } my $timefilter = ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'}); + my ($instcodefilter,$regexpok); + if ($numtitles) { + $instcodefilter = + &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'}, + $numtitles); + $regexpok = 1; + } else { + $instcodefilter = $filter->{'instcodefilter'}; + } %courses = &Apache::lonnet::courseiddump($filter->{'domainfilter'}, $filter->{'descriptfilter'}, $timefilter, - $filter->{'instcodefilter'}, + $instcodefilter, $filter->{'combownerfilter'}, $filter->{'coursefilter'}, - undef,undef,$type); + undef,undef,$type,$regexpok); } else { $r->print('
'); my %coursehash = &Apache::loncommon::findallcourses(); @@ -692,7 +778,7 @@ Course Owner's Username - the username o Course Owner's Domain - the domain of the owner of the course =item * -Course Description - text which appears in the Course Description (or title), as set in the Course Parameters. +Course Title - text which appears in the Course Title, as set in the Course Parameters. =item * Course ID - the internal course number (course ID part after initial 'domain_') used by LON-CAPA (this criterion is only displayed to Domain Coordinators selecting a course in the same domain as their DC role). @@ -765,10 +851,10 @@ Side Effects: None =item * X -B: +B: -Input: 6 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action. +Input: 7 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number). Output: 1 - $output - HTML for display of search criteria, and hidden form elements. @@ -776,10 +862,10 @@ Side Effects: None =item * X -B: +B: -Input: 5 - request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values. +Input: 5 - request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories). Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.