--- loncom/interface/lonpickcourse.pm 2009/05/04 13:24:12 1.79 +++ loncom/interface/lonpickcourse.pm 2010/06/08 16:37:20 1.96 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.79 2009/05/04 13:24:12 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.96 2010/06/08 16:37:20 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,7 +36,7 @@ use Apache::lonnet; use Apache::lonlocal; use Apache::longroup; use Apache::courseclassifier; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); sub handler { my $r = shift; @@ -50,23 +50,22 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', - 'multiple','type','setroles','fixeddom']); + '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 @@ -76,6 +75,20 @@ sub handler { $submitopener = &processpick(); $autosubmit = 'process_pick("'.$roledom.'")'; } + if ($env{'form.typeelement'} ne '') { + $typeelement = ''; + } + + # if called when a DC is creating a course for another user. + 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 @@ -84,15 +97,18 @@ sub handler { } my %loaditem; - if ($env{'form.numtitles'}) { - $loaditem{'onload'} = 'setElements(); '; + 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'} .= 'setSections()'; + $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, })); @@ -113,7 +129,8 @@ sub handler { } # 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(' + +ENDJS + +} + sub processpick { my $openerform = 'rolechoice'; if ($env{'form.form'} eq 'studentform') { @@ -181,7 +232,12 @@ ENDONE $process_pick .= <<"ENDTWO"; if (pickedDomain == dom) { if (pickedCourse != '') { - var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse + var ccrole = "cc"; + var pickedType = "$env{'form.type'}"; + if (pickedType == "Community") { + ccrole = "co"; + } + var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse opener.document.title='Role selected. Please stand by.'; opener.status='Role selected. Please stand by.'; opener.document.rolechoice.newrole.value=courseTarget @@ -213,7 +269,12 @@ sub create_user_javascript { 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) = @@ -227,7 +288,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'); } |; @@ -237,7 +301,7 @@ function setSections() { } sub display_matched_courses { - my ($r,$type,$multiple,$action,$showroles,%courses) = @_; + my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_; if ($env{'form.form'} eq 'portform') { $action = '/adm/portfolio'; } @@ -245,25 +309,34 @@ sub display_matched_courses { $r->print('