--- loncom/interface/lonpickcourse.pm 2004/11/30 00:21:24 1.21 +++ loncom/interface/lonpickcourse.pm 2010/07/08 23:19:19 1.99 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.21 2004/11/30 00:21:24 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.99 2010/07/08 23:19:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,6 +34,9 @@ use Apache::loncommon; use Apache::loncoursedata; use Apache::lonnet; use Apache::lonlocal; +use Apache::longroup; +use Apache::courseclassifier; +use LONCAPA qw(:DEFAULT :match); sub handler { my $r = shift; @@ -42,201 +45,1252 @@ sub handler { return OK if $r->header_only; # ------------------------------------------------------------ Print the screen - $r->print(< - -The LearningOnline Network with CAPA - -ENDDOCUMENT -# 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']); -# domain filter and selection - my $domainfilter=$ENV{'form.domainfilter'}; - $domainfilter=~s/\W//g; - unless ($domainfilter) { $domainfilter=''; } - my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter, - 'domainfilter',1); -# description filter - my $descriptfilter=$ENV{'form.descriptfilter'}; - unless ($descriptfilter) { $descriptfilter=''; } - my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"'); -# institutional code filter - my $instcodefilter=$ENV{'form.instcodefilter'}; - unless ($instcodefilter) { $instcodefilter=''; } - my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"'); -# course owner filter - my $ownerfilter=$ENV{'form.ownerfilter'}; - unless ($ownerfilter) { $ownerfilter=''; } - my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"'); -# last course activity filter and selection - my $sincefilter=$ENV{'form.sincefilter'}; - $sincefilter=~s/[^\d-]//g; - unless ($sincefilter) { $sincefilter=-1; } - my $sincefilterform=&Apache::loncommon::select_form($sincefilter, - 'sincefilter',('-1'=>'', - '86400' => 'today', - '604800' => 'last week', - '2592000' => 'last month', - '7776000' => 'last three months', - '15552000' => 'last six months', - '31104000' => 'last year', - 'select_form_order' => - ['-1','86400','604800','2592000','7776000', - '15552000','31104000'])); -# if called from loncreateuser, report sections, then close - my ($loaditem,$seclist); - my $num_sections = 0; - if ($ENV{'form.form'} eq 'cu' && $ENV{'form.pickedcourse'}) { - $loaditem = 'onLoad="setSections()"'; - my ($cdom,$cnum) = split/_/,$ENV{'form.pickedcourse'}; - my %sections_count = (); - $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count); - my @sections = (); - if ($num_sections > 0) { - @sections = (sort {$a <=> $b} keys %sections_count); - $seclist = join('","',@sections); - } - } - $r->print(&Apache::loncommon::bodytag("Selecting a Course",undef,$loaditem)); - my %lt=&Apache::lonlocal::texthash( - 'cac' => 'Course Activity', - 'cde' => 'Course Description', - 'cdo' => 'Course Domain', - 'cin' => 'Course Institutional Code', - 'cow' => "Course Owner's usename"); - my ($name_code,$name_input); - if (defined($ENV{'form.cnameelement'}) && $ENV{'form.cnameelement'} ne '') { - $name_code = "opener.document.$ENV{'form.form'}.$ENV{'form.cnameelement'}.value=cdesc;"; - $name_input =''; - } - my $submitopener = ''; - my $autosubmit = ''; - my $roleelement = ''; - my $lastaction = 'self.close()'; - if ($ENV{'form.form'} eq 'cu') { - $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". - 'document.courselist.submit();'; + 'multiple','type','setroles','fixeddom','cloner']); + my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement, + $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom); + + # Get course type - Course or Community. + $type = $env{'form.type'}; + if (!defined($env{'form.type'})) { + $type = 'Course'; } - my $roledom = $ENV{'form.roleelement'}; + $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 = 'Selecting '.$type.'(s)'; + } + + # if called when a DC is selecting a course + my $roledom = $env{'form.roleelement'}; if ($roledom) { $roleelement = ''; - $submitopener = &Apache::lonroles::processpick($roledom); + $submitopener = &processpick(); $autosubmit = 'process_pick("'.$roledom.'")'; } - $r->print(< -function gochoose(cname,cdom,cdesc) { - $name_code - var openerForm = "$ENV{'form.form'}"; - opener.document.$ENV{'form.form'}.$ENV{'form.cnumelement'}.value=cname; - if (openerForm == 'cu' || openerForm == 'rolechoice') { - opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'}.value=cdom; + if ($env{'form.typeelement'} ne '') { + $typeelement = ''; } - else { - var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'}; - var i; - for (i=0;iprint(&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' || ($env{'form.form'} eq 'studentform' && + !$multiple)) { + $lastaction = + 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n". + 'document.courselist.submit();'; + } else { + $lastaction = 'self.close()'; + } + + # if called to assign a role in a course to a user via CUSR + 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'}) && ($env{'form.updater'} eq '')) || + $onlyown) { + $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction)); + } + $r->print(''); + $r->print($submitopener); + +# ------------------------------------------ Display of filters to limit search + my $filter = {}; + my $action = '/adm/pickcourse'; + my ($numtitles,$showroles,$nohost,@codetitles); + if (!$onlyown) { + my $filterlist = ['domainfilter']; + # created filter for DCs only + if ($env{'user.adv'} && $env{'form.domainfilter'} && + exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'}) + && $env{'form.form'} ne 'portform') { + my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'}); + if ($loncaparev ne 'unknown_cmd') { + push(@{$filterlist},'createdfilter'); + } + } + push(@{$filterlist},('descriptfilter','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,\$numtitles,undef,$cloneruname, + $clonerudom,$typeelement,\@codetitles)); + } + +# ---------------------------------------------------------------- Get the data + if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || + $onlyown) { + my $domcloner; + if ($env{'form.form'} eq 'ccrs') { + if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) && + (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) { + $domcloner = 1; + } + } + my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles, + $cloneruname,$clonerudom,$domcloner,\@codetitles); + 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; } -function setSections() { - var numSections = $num_sections - var sectionsArray = new Array("$seclist") - opener.document.$ENV{"form.form"}.currsec.length = 0 - if (numSections == 0) { - opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('No existing sections','',false,false) +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 %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) = + &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,$action,$showroles,$cloneruname,$clonerudom,%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 $ccrole = 'cc'; + if ($type eq 'Community') { + $ccrole = 'co'; + } + my $cctitle = &Apache::lonnet::plaintext($ccrole,$type); + my $dctitle = &Apache::lonnet::plaintext('dc'); + my $ccrolechk = ' '; + my $menuchk = ' checked="checked" '; + $r->print( + '
' + .''.&mt('Action').'' + .'
' + .'
' + .'
' + .'
' + ); } - opener.document.$ENV{"form.form"}.currsec.multiple=true - if (numSections < 3) { - opener.document.$ENV{"form.form"}.currsec.size=numSections; + } + my %by_descrip; + foreach my $course (keys(%courses)) { + my $descr; + if (ref($courses{$course}) eq 'HASH') { + $descr = $courses{$course}{'description'}; + } elsif ($courses{$course} =~ m/^([^:]*):/i) { + $descr = &unescape($1); + } else { + $descr = &unescape($courses{$course}); } - else { - opener.document.$ENV{"form.form"}.currsec.size=3; + my $description = $descr; + push (@{$by_descrip{$description}}, $course); + } + + if ($numcourses > 1 && $multiple) { + $r->print(' +    +

'); + } + + if (%courses) { + $r->print(&Apache::loncommon::start_data_table()); + $r->print(&Apache::loncommon::start_data_table_header_row()); + my $titlehdr = &mt('Course Title'); + if ($type eq 'Community') { + $titlehdr = &mt('Community Title'); + } + $r->print(''.&mt('Select').'' + .''.$titlehdr.'' + .''.&mt('Domain').''); + unless ($type eq 'Community') { + $r->print(''.&mt('Course Code').''); + } + $r->print(''.&mt('Owner/Co-owner(s)').''); + if ($showroles) { + $r->print(''.&mt("Role(s) for [_1]", + &Apache::loncommon::plainname($env{'form.personfilter'}, + $env{'form.persondomfilter'},'firstname')).''); + } + $r->print(&Apache::loncommon::end_data_table_header_row()); + } + my %cc_cloneable; + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + my ($coord_cloneable,$warning) = + &get_coordinator_cloneable($cloneruname,$clonerudom,$type); + if ($coord_cloneable) { + map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable); + } + } + foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) { + foreach my $course (@{$by_descrip{$description}}) { + $r->print(&Apache::loncommon::start_data_table_row()); + my $cleandesc=&HTML::Entities::encode($description,'<>&"'); + $cleandesc=~s/'/\\'/g; + my ($cdom,$cnum)=split(/\_/,$course); + my ($descr,$instcode,$ttype,$canclone,@owners); + if (ref($courses{$course}) eq 'HASH') { + $descr = $courses{$course}{'description'}; + $instcode = $courses{$course}{'inst_code'}; + $ttype = $courses{$course}{'type'}; + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + if ($env{'form.form'} eq 'ccrs') { + if (($env{'request.role.domain'} eq $cdom) && + (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) { + $canclone = 1; + } + } + unless ($canclone) { + if ($cc_cloneable{$cnum.':'.$cdom}) { + $canclone = 1; + } + } + unless ($canclone) { + my $cloners = $courses{$course}{'cloners'}; + if ($cloners ne '') { + my @cloneable = split(',',$cloners); + if (grep(/^\*$/,@cloneable)) { + $canclone = 1; + } + if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) { + $canclone = 1; + } + if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) { + $canclone = 1; + } + } + } + } + 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 $ownerstr = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } @owners); + $r->print(''.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).''); + $r->print(''.$description.''); + $r->print(''); + $r->print(&Apache::lonnet::domain($cdom,'description')? + $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom); + $r->print(''); + unless ($type eq 'Community') { + $r->print(''); + if ($instcode ne '') { + $r->print(&unescape($instcode)); + } else { + $r->print(' '); + } + $r->print(''); + } + $r->print(''.$ownerstr.''); + if ($showroles) { + $r->print(''); + my $rolestr; + if (ref($courses{$course}{'roles'}) eq 'ARRAY') { + my @roles = sort(@{$courses{$course}{'roles'}}); + foreach my $role (@roles) { + if ($role =~ /^cr/) { + my (undef,$crdom,$crname,$crtitle) = split('/',$role); + $rolestr .= $crtitle.', '; + } else { + $rolestr .= &Apache::lonnet::plaintext($role,$type).', '; + } + } + $rolestr =~ s/\, $//; + } + $r->print($rolestr.''); + } + if ($multiple) { $r->print("\n"); } + $r->print(&Apache::loncommon::end_data_table_row()); + # $r->print("
\n"); + } + } + if (%courses) { + $r->print(&Apache::loncommon::end_data_table()); + } + + if (!%courses) { + $r->print(&mt('None found')); + } elsif ($multiple) { + $r->print(''); + } + $r->print(''. + "\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','numtitles','state'])); + } else { + $r->print(''."\n". + ''."\n"); + if ($env{'form.typeelement'} ne '') { + $r->print(''."\n"); + } - opener.document.$ENV{"form.form"}.currsec.options[0].selected = false } - self.close() + if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) { + $r->print(''); + } + if ($env{'form.numtitles'}) { + $r->print(''); + } + $r->print("
\n"); + return; } - -$submitopener -
- - + +sub multiples_tag { + my $jscript = &Apache::loncommon::check_uncheck_jscript(); + my $multelement = ''; + return ($jscript,$multelement); +} + +sub build_filters { + my ($filterlist,$type,$roleelement,$multelement,$filter,$action, + $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_; + my ($list,$formname,$fixeddom,$codedom,$jscript); + $codedom = $env{'request.role.domain'}; + if (defined($env{'form.form'})) { + $formname = $env{'form.form'}; + } else { + $formname = $caller; + } + my $onchange = 'javascript:updateFilters(this)'; + my ($domainselectform,$sincefilterform,$createdfilterform, + $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') { + $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; + } + 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; + } + 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},'<>&"'); + } + } + + # last course activity filter and selection + $sincefilterform = &timebased_select_form('sincefilter',$filter); + + # course created filter and selection + if (exists($filter->{'createdfilter'})) { + $createdfilterform = &timebased_select_form('createdfilter',$filter); + } + + my %lt = &Apache::lonlocal::texthash( + 'cac' => "$type Activity", + 'ccr' => "$type Created", + 'cde' => "$type Title", + 'cdo' => "$type Domain", + 'ins' => 'Institutional Code', + 'inc' => 'Institutional Categorization', + 'cow' => "$type Owner/Co-owner", + 'cop' => "$type Personnel Includes", + 'cog' => 'Type', + ); + + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + my $typeval = 'Course'; + if ($type eq 'Community') { + $typeval = 'Community'; + } + $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') { + if (exists($filter->{'instcodefilter'})) { + if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs') + || ($formname eq 'modifycourse')) { + $officialjs = 1; + ($instcodeform,$jscript,$$numtitlesref) = + &instcode_selectors($codedom,'filterpicker',$officialjs,$codetitlesref); + if ($jscript) { + $jscript = ''."\n"; + } + } + if ($instcodeform eq '') { + $instcodeform = + ''; + $instcodetitle = $lt{'ins'}; + } else { + $instcodetitle = $lt{'inc'}; + } + if ($env{'form.fixeddom'}) { + $instcodetitle .= '
('.$codedom.')'; + } + } + } + + 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 -$lt{'cac'}: $sincefilterform -
-$lt{'cdo'}: $domainselectform -
-$lt{'cin'}: - -
-$lt{'cow'}: - -
-$lt{'cde'}: - -

-
-
-ENDSCRIPT -# ---------------------------------------------------------------- Get the data - if ($ENV{'form.gosearch'}) { - $r->print(&mt('Searching').' ...
 
'); +$multelement +$typeelement +|; + if ($formname eq 'portform') { + $output .= ''."\n"; + } + } + if ($env{'form.fixeddom'}) { + $output .= ''."\n"; + } + $output .= "
\n".&Apache::lonhtmlcommon::start_pick_box(); + if ($sincefilterform) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'}) + .$sincefilterform + .&Apache::lonhtmlcommon::row_closure(); + } + if ($createdfilterform) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'}) + .$createdfilterform + .&Apache::lonhtmlcommon::row_closure(); + } + if ($domainselectform) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'}) + .$domainselectform + .&Apache::lonhtmlcommon::row_closure(); + } + if ($typeselectform) { + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + $output .= $typeselectform; + } else { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'}) + .$typeselectform + .&Apache::lonhtmlcommon::row_closure(); + } + } + if ($instcodeform) { + $output .= &Apache::lonhtmlcommon::row_title($instcodetitle) + .$instcodeform + .&Apache::lonhtmlcommon::row_closure(); + } + if (exists($filter->{'ownerfilter'})) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}). + '
'.&mt('Username').'
'. + '
'.&mt('Domain').'
'. + $ownerdomselectform.'
'. + &Apache::lonhtmlcommon::row_closure(); + } + if (exists($filter->{'personfilter'})) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}). + '
'.&mt('Username').'
'. + '
'.&mt('Domain').'
'. + $persondomselectform.'
'. + &Apache::lonhtmlcommon::row_closure(); + } + if (exists($filter->{'coursefilter'})) { + $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID')) + .'' + .&Apache::lonhtmlcommon::row_closure(); + } + if ($cloneableonlyform) { + $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle). + $cloneableonlyform.&Apache::lonhtmlcommon::row_closure(); + } + if (exists($filter->{'descriptfilter'})) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'}) + .'' + .&Apache::lonhtmlcommon::row_closure(1); + } + $output .= &Apache::lonhtmlcommon::end_pick_box().'

'; + my ($coord_cloneable,$warning); + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + ($coord_cloneable,$warning) = + &get_coordinator_cloneable($cloneruname,$clonerudom,$type); + if ($env{'form.form'} eq 'ccrs') { + $output .= ''."\n"; + } + if ($coord_cloneable) { + $output .= ''; + } + } + $output .= ''."\n". + '

'."\n".''."\n".'
'."\n"; + return $jscript.$warning.$output; +} + +sub timebased_select_form { + my ($item,$filter) = @_; + if (ref($filter) eq 'HASH') { + $filter->{$item} = $env{'form.'.$item}; + $filter->{$item} =~ s/[^\d-]//g; + if (!$filter->{$item}) { $filter->{$item}=-1; } + return &Apache::loncommon::select_form( + $filter->{$item}, + $item, + { '-1' => '', + '86400' => &mt('today'), + '604800' => &mt('last week'), + '2592000' => &mt('last month'), + '7776000' => &mt('last three months'), + '15552000' => &mt('last six months'), + '31104000' => &mt('last year'), + 'select_form_order' => + ['-1','86400','604800','2592000','7776000', + '15552000','31104000']}); + } +} + +sub get_coordinator_cloneable { + my ($cloneruname,$clonerudom,$type) = @_; + if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') { + my $warning = '
'.&mt('Intended course owner does not exist'). + '
'; + return ('',$warning); + } else { + my ($cc_clone,$ccrole); + if ($type eq 'Community') { + $ccrole = 'co'; + } elsif ($type eq 'Course') { + $ccrole = 'cc'; + } + my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom, + 'userroles',['active'], [$ccrole]); + foreach my $key (sort(keys(%ccroles))) { + my ($cnum,$cdom,$role) = split(':',$key); + $cc_clone .= $cdom.':'.$cnum.'&'; + } + $cc_clone =~ s/\&$//; + return ($cc_clone); + } +} + +sub instcode_selectors { + my ($codedom,$formname,$officialjs,$codetitles) = @_; + my ($output,%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,$officialjs); + if ($numtitles > 0) { + my $official = ' checked="checked" '; + my $unofficial = ''; + if ($env{'form.official'} eq 'off') { + $unofficial = $official; + $official = ''; + } + $output .= ''.&mt('Official course:').' '.(' 'x3).'
'. + &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,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_; + my (%courses,%showcourses,$cloner,$ccrole); + if ($type eq 'Community') { + $ccrole = 'co'; + } else { + $ccrole = 'cc'; + } + if (!$onlyown) { + $r->print(&mt('Searching ...').'
 
'); $r->rflush(); - unless ($descriptfilter) { $descriptfilter='.'; } - unless ($instcodefilter) { $instcodefilter='.'; } - unless ($ownerfilter) { $ownerfilter='.'; } - my $timefilter=($sincefilter==-1?1:time-$sincefilter); - my %courses= - &Apache::lonnet::courseiddump - ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter); - $r->print('
'); - my %by_descrip; - foreach my $course (keys %courses) { - my $descr; - if ($courses{$course} =~ m/^([^:]*):/) { - $descr = &Apache::lonnet::unescape($1); - } else { - $descr = &Apache::lonnet::unescape($courses{$course}); - } - $by_descrip{lc($descr)}=$course; - } - foreach my $description (sort(keys(%by_descrip))) { - my $course=$by_descrip{$description}; - my $cleandesc=&HTML::Entities::encode($description,'<>&"'); - $cleandesc=~s/'/\\'/g; - my ($cdom,$cnum)=split(/\_/,$course); - $r->print(' '.$description.' ('. - ($Apache::lonnet::domaindescription{$cdom}? - $Apache::lonnet::domaindescription{$cdom}:$cdom). - ")
\n"); - } - if (!%courses) { $r->print(&mt('None found')); } - $r->print(''."\n". - ''."\n". - ''."\n". - ''."\n". - '
'); + if (($filter->{'ownerfilter'} ne '') || + ($filter->{'ownerdomfilter'} ne '')) { + $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'. + $filter->{'ownerdomfilter'}; + } + foreach my $item ('descriptfilter','coursefilter','combownerfilter') { + if (!$filter->{$item}) { + $filter->{$item}='.'; + } + } + my $now = time; + my $timefilter = + ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'}); + my ($createdbefore,$createdafter); + if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) { + $createdbefore = $now; + $createdafter = $now-$filter->{'createdfilter'}; + } + my ($instcodefilter,$regexpok); + if ($numtitles) { + if ($env{'form.official'} eq 'on') { + $instcodefilter = + &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles); + $regexpok = 1; + } elsif ($env{'form.official'} eq 'off') { + $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles); + unless ($instcodefilter eq '') { + $regexpok = -1; + } + } + } else { + $instcodefilter = $filter->{'instcodefilter'}; + } + if ($instcodefilter eq '') { $instcodefilter = '.'; } + if ($type eq '') { $type = '.'; } + + if (($clonerudom ne '') && ($cloneruname ne '')) { + $cloner = $cloneruname.':'.$clonerudom; + } + %courses = + &Apache::lonnet::courseiddump($filter->{'domainfilter'}, + $filter->{'descriptfilter'}, + $timefilter, + $instcodefilter, + $filter->{'combownerfilter'}, + $filter->{'coursefilter'}, + undef,undef,$type,$regexpok,undef,undef, + undef,undef,$cloner,$env{'form.cc_clone'}, + $filter->{'cloneableonly'}, + $createdbefore,$createdafter,undef, + $domcloner); + if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) { + my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'}, + $filter->{'persondomfilter'}, + 'userroles',undef, + [$ccrole,'in','ad','ep','ta','cr'], + $filter->{'domainfilter'}); + foreach my $role (keys(%rolehash)) { + my ($cnum,$cdom,$courserole) = split(':',$role); + my $cid = $cdom.'_'.$cnum; + if (exists($courses{$cid})) { + if (ref($courses{$cid}) eq 'HASH') { + if (ref($courses{$cid}{roles}) eq 'ARRAY') { + if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) { + push (@{$courses{$cid}{roles}},$courserole); + } + } else { + $courses{$cid}{roles} = [$courserole]; + } + $showcourses{$cid} = $courses{$cid}; + } + } + } + %courses = %showcourses; + } + } else { + $r->print('
'); + my %coursehash = &Apache::loncommon::findallcourses(); + foreach my $cid (sort(keys(%coursehash))) { + $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'}; + } } - $r->print(''); - return OK; + return %courses; +} + +sub course_chooser { + my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_; + my $output; + if ($multiple) { + $output = '