--- loncom/interface/lonpickcourse.pm 2007/06/01 18:07:47 1.63.2.1 +++ loncom/interface/lonpickcourse.pm 2009/11/04 14:12:19 1.90 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.63.2.1 2007/06/01 18:07:47 albertel Exp $ +# $Id: lonpickcourse.pm,v 1.90 2009/11/04 14:12:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,7 +35,8 @@ use Apache::loncoursedata; use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; -use LONCAPA; +use Apache::courseclassifier; +use LONCAPA qw(:DEFAULT :match); sub handler { my $r = shift; @@ -49,32 +50,45 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', - 'multiple','type','setroles']); + 'multiple','type','setroles','fixeddom','cloner']); + my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, + $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom); - my ($type,$title,$jscript,$multelement,$multiple,$roleelement, - $lastaction,$autosubmit,$submitopener); - - # Get course type - Course or Non-standard Course. + # Get course type - Course or Community. $type = $env{'form.type'}; if (!defined($env{'form.type'})) { $type = 'Course'; } - $title = &mt('Selecting a [_1]',$type); + $title = 'Selecting a '.$type; # Setup for multiple course selections, if flag for multiples set. $multiple = $env{'form.multiple'}; if ($multiple) { ($jscript,$multelement) = &multiples_tag(); - $title = &mt('Selecting [_1](s)',lc($type)); + $title = 'Selecting '.$type.'(s)'; } # 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.'")'; } + if ($env{'form.typeelement'} ne '') { + $typeelement = ''; + } + + # if called when a DC is creating a course + if ($env{'form.form'} eq 'ccrs') { + ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/); + } + + # if called when requesting a course + if ($env{'form.form'} eq 'requestcrs') { + $cloneruname = $env{'user.name'}; + $clonerudom = $env{'user.domain'}; + } my $onlyown = 0; # if called to assign course-based portfolio access control @@ -83,16 +97,25 @@ sub handler { } my %loaditem; - if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) { - $loaditem{'onload'} ="setSections()"; + if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) { + if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) { + $loaditem{'onload'} = 'setElements(document.filterpicker); '; + } + } + + if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && + ($env{'form.pickedcourse'})) { + $loaditem{'onload'} .= 'setRoles();setSections();'; } - $r->print(&Apache::loncommon::start_page($title,undef, + my $js = &js_changer(); + $r->print(&Apache::loncommon::start_page($title,$js, {'add_entries' => \%loaditem, 'no_nav_bar' => 1, })); if ($env{'form.form'} eq 'portform') { $lastaction = 'document.courselist.submit()'; - } elsif ($env{'form.form'} eq 'cu') { + } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' && + !$multiple)) { $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". 'document.courselist.submit();'; @@ -101,48 +124,148 @@ sub handler { } # if called to assign a role in a course to a user via CUSR - if ($env{'form.form'} eq 'cu') { - $r->print(&create_user_javascript($type)); + if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') { + $r->print(&create_user_javascript($type)); } # print javascript functions for choosing a course - if ($env{'form.gosearch'} || $onlyown) { + if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || + $onlyown) { $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction)); } - $r->print(''); + $r->print(''); $r->print($submitopener); # ------------------------------------------ Display of filters to limit search my $filter = {}; my $action = '/adm/pickcourse'; + my ($numtitles,$showroles,$nohost); if (!$onlyown) { my $filterlist = ['domainfilter','descriptfilter', - 'instcodefilter','ownerfilter', - 'ownerdomfilter']; + 'instcodefilter']; + if ($env{'form.form'} eq 'rules') { + push(@{$filterlist},'personfilter'); + if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) { + if (&Apache::lonnet::homeserver($env{'form.personfilter'}, + $env{'form.persondomfilter'}) eq 'no_host') { + $nohost = 1; + } else { + $showroles = 1; + } + } + } else { + push(@{$filterlist},'ownerfilter'); + } # course ID filter for DCs only if ($env{'user.adv'} && $env{'form.domainfilter'} && exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) { push(@{$filterlist},'coursefilter'); } + if ($cloneruname ne '' && $clonerudom ne '') { + push(@{$filterlist},'cloneableonly'); + } + $r->print(&build_filters($filterlist,$type,$roleelement,$multelement, - $filter,$action)); + $filter,$action,\$numtitles,undef,$cloneruname, + $clonerudom,$typeelement)); } # ---------------------------------------------------------------- Get the data - if ($env{'form.gosearch'} || $onlyown) { - my %courses = &search_courses($r,$type,$onlyown,$filter); - &display_matched_courses($r,$type,$multiple,$action,%courses); + if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || + $onlyown) { + my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles, + $cloneruname,$clonerudom); + if ($nohost) { + $r->print (''. + &mt('User does not exist - username: [_1], domain: [_2].', + ''.$filter->{'personfilter'}.'', + ''.$filter->{'persondomfilter'}.'').''); + } else { + &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname, + $clonerudom,%courses); + } } $r->print(&Apache::loncommon::end_page()); return OK; } +sub js_changer { + return <<"ENDJS"; + + +ENDJS + +} + +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 %coursedescription = + &Apache::lonnet::coursedescription($env{'form.pickedcourse'}, + {'one_time' => '1'}); + my $cdom = $coursedescription{'domain'}; + my $cnum = $coursedescription{'num'}; + my $crstype = $coursedescription{'type'}; my $sec_element = 'currsec'; my $grplist_element = 'groups'; my ($sections,$groups) = @@ -156,7 +279,10 @@ sub create_user_javascript { function setSections() { opener.document.$env{"form.form"}.$grplist_element.value='$groupslist'; window.opener.setSect('$seclist'); - self.close() + self.close(); +} +function setRoles() { + window.opener.setRole('$crstype'); } |; @@ -166,16 +292,57 @@ function setSections() { } sub display_matched_courses { - my ($r,$type,$multiple,$action,%courses) = @_; + my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_; if ($env{'form.form'} eq 'portform') { $action = '/adm/portfolio'; } + my $numcourses = keys(%courses); $r->print('
\n"); return; } - sub multiples_tag { my $jscript = &Apache::loncommon::check_uncheck_jscript(); my $multelement = ''; @@ -252,25 +510,47 @@ sub multiples_tag { sub build_filters { my ($filterlist,$type,$roleelement,$multelement,$filter,$action, - $caller) = @_; - my $list; - my $formname; + $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement) = @_; + my ($list,$formname,$fixeddom,$codedom,$jscript); + $codedom = $env{'request.role.domain'}; if (defined($env{'form.form'})) { - $formname = $env{'form.form'}; + $formname = $env{'form.form'}; } else { - $formname = $caller; + $formname = $caller; } - my ($domainselectform,$sincefilterform,$ownerdomselectform, - $instcodeform,$typeselectform); + my $onchange; + unless ($env{'form.interface'} eq 'textual') { + $onchange = 'javascript:updateFilters(this)'; + } + my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform, + $instcodeform,$typeselectform,$instcodetitle); foreach my $item (@{$filterlist}) { $filter->{$item} = $env{'form.'.$item}; if ($item ne 'descriptfilter' && $item ne 'instcodefilter') { - if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') { + if ($item eq 'domainfilter') { $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}); + $filter->{'ownerdomfilter'} = + &LONCAPA::clean_domain($env{'form.ownerdomfilter'}); + $ownerdomselectform = + &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'}, + 'ownerdomfilter',1); + } elsif ($item eq 'personfilter') { + $filter->{$item} = &LONCAPA::clean_username($filter->{$item}); + if ($env{'form.persondomfilter'} eq '') { + unless ($env{'form.gosearch'}) { + $filter->{'persondomfilter'} = $env{'request.role.domain'}; + } + } else { + $filter->{'persondomfilter'} = + &LONCAPA::clean_domain($env{'form.persondomfilter'}); + } + $persondomselectform = + &Apache::loncommon::select_dom_form($filter->{'persondomfilter'}, + 'persondomfilter',1); } else { $filter->{$item} =~ s/\W//g; } @@ -283,14 +563,23 @@ sub build_filters { if ($formname eq 'portform') { $filter->{$item} ||= $env{'user.domain'}; $allow_blank=0; - } - $domainselectform = - &Apache::loncommon::select_dom_form($filter->{$item}, - 'domainfilter', - $allow_blank); - } elsif ($item eq 'ownerdomfilter') { - $ownerdomselectform = - &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1); + } elsif ($formname eq 'studentform') { + $filter->{$item} ||= $env{'request.role.domain'}; + $allow_blank=0; + } + 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,'',$onchange); + $codedom = $filter->{'domainfilter'}; + } } else { $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"'); } @@ -313,34 +602,86 @@ 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), - 'cog' => &mt('Course 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/Co-owner"), + 'cop' => &mt("$type Personnel Includes"), + 'cog' => &mt('Type') ); - $typeselectform = ''; + } else { + $typeselectform = '"; + } + + my ($cloneableonlyform,$cloneabletitle); + if (exists($filter->{'cloneableonly'})) { + my $cloneableon = ''; + my $cloneableoff = ' checked="checked"'; + if ($filter->{'cloneableonly'}) { + $cloneableon = $cloneableoff; + $cloneableoff = ''; + } + $cloneableonlyform = ''.(' 'x3).''; + if ($env{'form.form'} eq 'ccrs') { + $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom; + } else { + $cloneabletitle = &mt('Cloneable by you'); + } + } + my $officialjs; if ($type eq 'Course') { - $instcodeform = - ''; - } - foreach my $posstype ('Course','Non-standard Course') { - $typeselectform.='\n"; + if (exists($filter->{'instcodefilter'})) { + if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs') + || ($formname eq 'modifycourse')) { + $officialjs = 1; + ($instcodeform,$jscript,$$numtitlesref) = + &instcode_selectors($codedom,'filterpicker',$officialjs); + if ($jscript) { + $jscript = ''."\n"; + } + } + if ($instcodeform eq '') { + $instcodeform = + ''; + $instcodetitle = $lt{'ins'}; + } else { + $instcodetitle = $lt{'inc'}; + } + if ($env{'form.fixeddom'}) { + $instcodetitle .= '