--- loncom/interface/lonpickcourse.pm 2006/11/05 20:59:17 1.54 +++ loncom/interface/lonpickcourse.pm 2008/05/19 21:40:26 1.71 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.54 2006/11/05 20:59:17 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.71 2008/05/19 21:40:26 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,7 +35,6 @@ use Apache::loncoursedata; use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; -use lib '/home/httpd/lib/perl/'; use LONCAPA; sub handler { @@ -46,17 +45,16 @@ sub handler { # ------------------------------------------------------------ Print the screen -# Get parameters from query string + # Get parameters from query string &Apache::loncommon::get_unprocessed_cgi - ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter', - 'sincefilter','form','cnumelement', + ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', - 'pickedcourse','instcodefilter', - 'ownerfilter','coursefilter','multiple', - 'type','ownerdomfilter']); + 'multiple','type','setroles']); - my ($type,$title,$jscript,$multelement,$multiple,$name_code,$name_input, - $roleelement); + my ($type,$title,$jscript,$multelement,$multiple,$roleelement, + $lastaction,$autosubmit,$submitopener); + + # Get course type - Course or Non-standard Course. $type = $env{'form.type'}; if (!defined($env{'form.type'})) { $type = 'Course'; @@ -64,177 +62,188 @@ sub handler { $title = &mt('Selecting a [_1]',$type); # Setup for multiple course selections, if flag for multiples set. - ($title,$jscript,$multelement,$multiple) = &multiples_tag($type,$title); - - if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') { - $name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.". - "value=cdesc;"; - $name_input =''; + $multiple = $env{'form.multiple'}; + if ($multiple) { + ($jscript,$multelement) = &multiples_tag(); + $title = &mt('Selecting [_1](s)',lc($type)); } - my $submitopener = ''; - my $autosubmit = ''; - my $lastaction = 'self.close()'; - if ($env{'form.form'} eq 'cu') { - $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". - 'document.courselist.submit();'; - } - if ($env{'form.form'} eq 'portform') { - $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". - 'document.courselist.submit();'; - } + # if called when a DC is selecting a course my $roledom = $env{'form.roleelement'}; if ($roledom) { $roleelement = ''; - $submitopener = &Apache::lonroles::processpick(); + $submitopener = &processpick(); $autosubmit = 'process_pick("'.$roledom.'")'; } - my (%filter,%list); - my $filterdisplay; my $onlyown = 0; - if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) { + # if called to assign course-based portfolio access control + if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) { $onlyown = 1; - } else { - $filterdisplay = &build_filters($type,$name_input,$roleelement, - $multelement, \%filter,\%list); - } -# if called from loncreateuser, report sections, then close - my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist, - $accesslist,$accessnameslist); - my $sec_element = 'currsec'; - my $grplist_element = 'groups'; - my $num_sections = 0; - my $num_groups = 0; - my $num_roles = 0; - my $num_access = 0; - my ($cdom,$cnum); - if ($env{'form.pickedcourse'}) { - ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'}; } - if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) { + + my %loaditem; + if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && + ($env{'form.pickedcourse'})) { $loaditem{'onload'} ="setSections()"; - ($seclist,$num_sections,$groupslist,$num_groups) = - &build_selection_lists($cdom,$cnum,$type,undef,undef, - $env{'form.form'}); - } -# if called from portfolio, report roles, sections, groups and close - my ($roles_element,$groups_element,$status_element,$setitems_function); - if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) { - $loaditem{'onload'} ="setItems()"; - ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles, - $rolesnameslist,$accesslist,$num_access,$accessnameslist) = - &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'}); - ($sec_element,$grplist_element,$setitems_function) = - &setitems_javascript($seclist,$num_sections,$groupslist,$num_groups, - $roleslist,$num_roles,$rolesnameslist, - $accesslist,$num_access,$accessnameslist); } $r->print(&Apache::loncommon::start_page($title,undef, {'add_entries' => \%loaditem, 'no_nav_bar' => 1, })); - my %elements = ( - 'Course' => { - name => 'coursepick', - total => 'coursetotal', - list => 'courselist', - }, - 'Non-standard course' => { - name => 'grouppick', - total => 'grouptotal', - list => 'grouplist', - }, - ); - my $setsec_func = &setsec_javascript($seclist,$sec_element,$grplist_element, - $groupslist,$num_sections); - $r->print(< -function gochoose(cname,cdom,cdesc,multiple,caller) { - var openerForm = "$env{'form.form'}"; - courseCount = 0; - var courses = ''; - if (multiple) { - if (typeof(document.courselist.course_id.length) == 'undefined') { - // only 1 course checkbox was created - if (document.courselist.course_id.checked) { - courses = courses + document.courselist.course_id.value + "&&"; - courseCount ++; - } - } else { - for (var j=0; j 0) { - courses = courses.substr(0,courses.length-2); - opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses; - } + + if ($env{'form.form'} eq 'portform') { + $lastaction = 'document.courselist.submit()'; + } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' && + !$multiple)) { + $lastaction = + 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". + 'document.courselist.submit();'; } else { - $name_code - opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname; - var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'}; - if (slct.options == undefined) { - opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom; - } - else { - var i; - for (i=0;iprint(&create_user_javascript($type)); + } -$setitems_function + # print javascript functions for choosing a course + if ($env{'form.gosearch'} || $onlyown) { + $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction)); + } + $r->print(''); + $r->print($submitopener); -$jscript - -$submitopener -ENDSCRIPT - $r->print($filterdisplay); +# ------------------------------------------ Display of filters to limit search + my $filter = {}; + my $action = '/adm/pickcourse'; + if (!$onlyown) { + my $filterlist = ['domainfilter','descriptfilter', + 'instcodefilter','ownerfilter', + 'ownerdomfilter']; + # course ID filter for DCs only + if ($env{'user.adv'} && $env{'form.domainfilter'} && + exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) { + push(@{$filterlist},'coursefilter'); + } + $r->print(&build_filters($filterlist,$type,$roleelement,$multelement, + $filter,$action)); + } # ---------------------------------------------------------------- Get the data if ($env{'form.gosearch'} || $onlyown) { - my %courses = &search_courses($r,$type,$onlyown,\%filter); - &display_matched_courses($r,$type,$multiple,%courses); + my %courses = &search_courses($r,$type,$onlyown,$filter); + &display_matched_courses($r,$type,$multiple,$action,%courses); } $r->print(&Apache::loncommon::end_page()); return OK; } +sub processpick { + my $openerform = 'rolechoice'; + if ($env{'form.form'} eq 'studentform') { + $openerform = $env{'form.form'}; + } + my $process_pick = <<"ENDONE"; + +"; + return $process_pick; +} + +sub create_user_javascript { + my ($type) = @_; + my $output; + #javascript for reporting sections and groups then closing + if ($env{'form.pickedcourse'}) { + my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'}; + my $sec_element = 'currsec'; + my $grplist_element = 'groups'; + my ($sections,$groups) = + &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type); + my $num_sections = scalar(@{$sections}); + my $seclist = join(',',@{$sections}); + my $num_groups = scalar(@{$groups}); + my $groupslist = join(',',@{$groups}); + $output = qq| + +|; +; + } + return $output; +} + sub display_matched_courses { - my ($r,$type,$multiple,%courses) = @_; - $r->print('
'); - my %by_descrip; + my ($r,$type,$multiple,$action,%courses) = @_; + if ($env{'form.form'} eq 'portform') { + $action = '/adm/portfolio'; + } my $numcourses = keys(%courses); + $r->print(''); + if ($env{'form.form'} eq 'modifycourse') { + if ($numcourses > 0) { + my $cctitle = &Apache::lonnet::plaintext('cc',$type); + my $dctitle = &Apache::lonnet::plaintext('dc'); + my $ccrolechk = ' checked="checked" '; + my $menuchk = ' '; + if ($env{'form.prevphase'} ne '') { + $ccrolechk = ' '; + $menuchk = ' checked="checked" '; + } + $r->print( + ''.(' 'x3).'
'. + '

'); + } + } + my %by_descrip; foreach my $course (keys(%courses)) { my $descr; - if ($courses{$course} =~ m/^([^:]*):/i) { + if (ref($courses{$course}) eq 'HASH') { + $descr = $courses{$course}{'description'}; + } elsif ($courses{$course} =~ m/^([^:]*):/i) { $descr = &unescape($1); } else { $descr = &unescape($courses{$course}); @@ -242,6 +251,7 @@ sub display_matched_courses { my $description = $descr; push (@{$by_descrip{$description}}, $course); } + if ($numcourses > 1 && $multiple) { $r->print(' @@ -249,83 +259,155 @@ sub display_matched_courses { onclick="javascript:uncheckAll(document.courselist.course_id)" />

'); } + + if (%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('Domain').'' + .''.&mt('Course Code').'' + .''.&mt('Owner:Domain').'' + .''.&mt('Type').'' + ); + $r->print(&Apache::loncommon::end_data_table_header_row()); + } foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) { + $r->print(&Apache::loncommon::start_data_table_row()); foreach my $course (@{$by_descrip{$description}}) { my $cleandesc=&HTML::Entities::encode($description,'<>&"'); $cleandesc=~s/'/\\'/g; my ($cdom,$cnum)=split(/\_/,$course); - my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course}; - $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc)); - $r->print($description.'('. - ($Apache::lonnet::domaindescription{$cdom}? - $Apache::lonnet::domaindescription{$cdom}:$cdom).")"); - unless ($instcode eq '') { - $r->print(" - ".&unescape($instcode)); - } - unless ($owner eq '') { - $r->print(", owner - ".&unescape($owner)); + my ($descr,$instcode,$ttype,@owners); + if (ref($courses{$course}) eq 'HASH') { + $descr = $courses{$course}{'description'}; + $instcode = $courses{$course}{'inst_code'}; + $ttype = $courses{$course}{'type'}; + push(@owners,&unescape($courses{$course}{'owner'})); + if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') { + foreach my $item (@{$courses{$course}{'co-owners'}}) { + push(@owners,&unescape($item)); + } + } + } else { + my $singleowner; + ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course}); + push(@owners,&unescape($singleowner)); + } + my $owner = join(', ',@owners); + $r->print(''.&course_chooser($multiple,$cdom,$cnum,$cleandesc).''); + $r->print(''.$description.''); + $r->print(''); + $r->print(&Apache::lonnet::domain($cdom,'description')? + $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom); + $r->print(''); + $r->print(''); + if ($instcode ne '') { + $r->print(&unescape($instcode)); + } else { + $r->print(' '); } - unless ($ttype eq '') { - $r->print('('.&Apache::lonnet::unescape($ttype).')'); + $r->print(''); + $r->print(''); + if (@owners > 1) { +# $r->print(', '.&mt('owners').' - ',join(', ',@owners)); + $r->print(join(', ',@owners)); + } elsif (@owners == 1) { +# $r->print(', '.&mt('owner').' - '.$owner); + $r->print($owner); + } + $r->print(''); + $r->print(''); + if ($ttype ne '') { + $r->print(&mt(&unescape($ttype))); + } else { + $r->print(' '); } + $r->print(''); if ($multiple) { $r->print("\n"); } - $r->print("
\n"); + # $r->print("
\n"); } + $r->print(&Apache::loncommon::end_data_table_row()); } + $r->print(&Apache::loncommon::end_data_table()); + if (!%courses) { $r->print(&mt('None found')); } elsif ($multiple) { - $r->print(''); + $r->print(''); } $r->print(''. "\n".''."\n". - ''."\n". - ''."\n". ''."\n"); if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) { $r->print(''."\n"); } + if ($env{'form.form'} eq 'portform') { + $r->print(''); + $r->print(''); + $r->print(''); + $r->print(''); + } elsif ($env{'form.form'} eq 'modifycourse') { + $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form'])); + } else { + $r->print(''."\n". + ''."\n"); + } $r->print("
\n"); return; } sub multiples_tag { - my ($type,$title) = @_; - my ($jscript,$multelement,$multiple); - $multiple = $env{'form.multiple'}; - if ($multiple) { - $title = &mt('Selecting [_1](s)',lc($type)); - $jscript = &Apache::loncommon::check_uncheck_jscript(); - $multelement = ''; - } - return ($title,$jscript,$multelement,$multiple); + my $jscript = &Apache::loncommon::check_uncheck_jscript(); + my $multelement = ''; + return ($jscript,$multelement); } sub build_filters { - my ($type,$name_input,$roleelement,$multelement,$filter,$list) = @_; - my @filters = ('domainfilter','descriptfilter','instcodefilter','ownerfilter','ownerdomfilter'); - # course ID filter for DCs only - my ($courseidtag,$domainselectform,$sincefilterform,$ownerdomselectform, - $instcodeform,$typeselectform); - if ($env{'user.adv'} && $env{'form.domainfilter'} && - exists($env{'user.role.dc./'.$env{'form.domainfilter'}})) { - push(@filters,'coursefilter'); - $courseidtag=&mt('LON-CAPA course ID'). - '
'; + my ($filterlist,$type,$roleelement,$multelement,$filter,$action, + $caller) = @_; + my $list; + my $formname; + if (defined($env{'form.form'})) { + $formname = $env{'form.form'}; + } else { + $formname = $caller; } - foreach my $item (@filters) { + my ($domainselectform,$sincefilterform,$ownerdomselectform, + $instcodeform,$typeselectform); + foreach my $item (@{$filterlist}) { $filter->{$item} = $env{'form.'.$item}; if ($item ne 'descriptfilter' && $item ne 'instcodefilter') { - $filter->{$item} =~ s/\W//g; + if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') { + $filter->{$item} = &LONCAPA::clean_domain($filter->{$item}); + } elsif ($item eq 'coursefilter') { + $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item}); + } elsif ($item eq 'ownerfilter') { + $filter->{$item} = &LONCAPA::clean_username($filter->{$item}); + } else { + $filter->{$item} =~ s/\W//g; + } if (!$filter->{$item}) { $filter->{$item} = ''; } } if ($item eq 'domainfilter') { + my $allow_blank = 1; + if ($formname eq 'portform') { + $filter->{$item} ||= $env{'user.domain'}; + $allow_blank=0; + } elsif ($formname eq 'studentform') { + $filter->{$item} ||= $env{'request.role.domain'}; + $allow_blank=0; + } $domainselectform = - &Apache::loncommon::select_dom_form($filter->{$item},'domainfilter',1); + &Apache::loncommon::select_dom_form($filter->{$item}, + 'domainfilter', + $allow_blank); } elsif ($item eq 'ownerdomfilter') { $ownerdomselectform = &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1); @@ -360,44 +442,72 @@ sub build_filters { 'cog' => &mt('Course Type') ); - $typeselectform = ''; } - foreach my $posstype ('Course','Non-standard course') { + foreach my $posstype ('Course','Non-standard Course') { $typeselectform.='\n"; } $typeselectform.=""; - my $output = <<"END"; -
+ my $output = qq| + + +|; + if ($formname eq 'modifycourse') { + $output .= ''."\n". + ''."\n"; + } else { + my $name_input; + if ($env{'form.cnameelement'} ne '') { + $name_input = ''; + } + $output .= qq| $name_input - $roleelement $multelement -$lt{'cac'}: $sincefilterform -
-$lt{'cdo'}: $domainselectform -
-$lt{'cog'}: $typeselectform -
-$instcodeform -$lt{'cow'}: - -
-$lt{'cod'}: $ownerdomselectform -
-$courseidtag -$lt{'cde'}: - -

-
-
-END +|; + if ($formname eq 'portform') { + $output .= ''; + } + } + if ($sincefilterform) { + $output .= $lt{'cac'}.': '.$sincefilterform.'
'."\n"; + } + if ($domainselectform) { + $output .= $lt{'cdo'}.': '.$domainselectform.'
'."\n"; + } + if ($typeselectform) { + $output .= $lt{'cog'}.': '.$typeselectform.'
'."\n"; + } + if ($instcodeform) { + $output .= $lt{'cin'}.': '.$instcodeform.'
'."\n"; + } + if (exists($filter->{'ownerfilter'})) { + $output .= $lt{'cow'}.': '. + '
'."\n". + $lt{'cod'}.': '.$ownerdomselectform.'
'."\n"; + } + if (exists($filter->{'coursefilter'})) { + $output .= &mt('LON-CAPA course ID').': '. + '
'; + } + if (exists($filter->{'descriptfilter'})) { + $output .=$lt{'cde'}.': '. + ''."\n"; + } + $output .= '

'."\n".''."\n".'
'."\n"; return $output; } @@ -405,7 +515,7 @@ sub search_courses { my ($r,$type,$onlyown,$filter) = @_; my %courses; if (!$onlyown) { - $r->print(&mt('Searching').' ...
 
'); + $r->print(&mt('Searching ...').'
 
'); $r->rflush(); if (($filter->{'ownerfilter'} ne '') || ($filter->{'ownerdomfilter'} ne '')) { @@ -431,8 +541,9 @@ sub search_courses { undef,undef,$type); } else { $r->print('
'); - foreach my $cid (sort(&Apache::loncommon::findallcourses())) { - $courses{$cid} = $env{'course.'.$cid.'.description'}; + my %coursehash = &Apache::loncommon::findallcourses(); + foreach my $cid (sort(keys(%coursehash))) { + $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'}; } } return %courses; @@ -444,187 +555,298 @@ sub course_chooser { if ($multiple) { $output = '