--- loncom/interface/lonpickcourse.pm 2009/07/25 23:16:04 1.83 +++ loncom/interface/lonpickcourse.pm 2014/03/11 21:42:18 1.110 @@ -1,7 +1,7 @@ # The LearningOnline Network # Pick a course # -# $Id: lonpickcourse.pm,v 1.83 2009/07/25 23:16:04 raeburn Exp $ +# $Id: lonpickcourse.pm,v 1.110 2014/03/11 21:42:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,12 +31,13 @@ package Apache::lonpickcourse; use strict; use Apache::Constants qw(:common); use Apache::loncommon; +use Apache::lonhtmlcommon; use Apache::loncoursedata; 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,9 +51,9 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement', 'cdomelement','cnameelement','roleelement', - 'multiple','type','setroles','fixeddom']); - my ($type,$title,$jscript,$multelement,$multiple,$roleelement, - $lastaction,$autosubmit,$submitopener); + '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'}; @@ -75,6 +76,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 @@ -83,15 +98,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'} .= 'setDefaultCredits();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, })); @@ -112,20 +130,29 @@ 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(''); + $r->print(&Apache::lonhtmlcommon::scripttag($jscript)); $r->print($submitopener); # ------------------------------------------ Display of filters to limit search my $filter = {}; my $action = '/adm/pickcourse'; - my ($numtitles,$showroles,$nohost); + my ($numtitles,$showroles,$nohost,@codetitles); if (!$onlyown) { - my $filterlist = ['domainfilter','descriptfilter', - 'instcodefilter']; + 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 '')) { @@ -144,26 +171,57 @@ sub handler { 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)); + $filter,$action,\$numtitles,undef,$cloneruname, + $clonerudom,$typeelement,\@codetitles)); } # ---------------------------------------------------------------- Get the data - if ($env{'form.gosearch'} || $onlyown) { - my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles); + 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,%courses); + &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname, + $clonerudom,%courses); } } $r->print(&Apache::loncommon::end_page()); return OK; } +sub js_changer { + return < +// + + +ENDJS +} + sub processpick { my $openerform = 'rolechoice'; if ($env{'form.form'} eq 'studentform') { @@ -180,7 +238,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 @@ -212,7 +275,19 @@ 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 %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + my ($showcredits,$credits); + if (($crstype ne 'Community') && + (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}))) { + $showcredits = 1; + $credits = $coursedescription{'internal.defaultcredits'}; + } my $sec_element = 'currsec'; my $grplist_element = 'groups'; my ($sections,$groups) = @@ -223,20 +298,33 @@ sub create_user_javascript { my $groupslist = join(',',@{$groups}); $output = qq| |; -; } return $output; } 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'; } @@ -244,27 +332,37 @@ sub display_matched_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" '; + 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').'' - .'' + '' + .'' + .''.&mt('Pick action').'' + .'' .'' - .' '.&mt('Enter the course with the role of [_1].',$cctitle) - .'' - .'' - .' ' - .&mt('View or modify course settings which only a [_1] may modify.',$dctitle) - .'' - .'' - .'' + .' '); + if ($type eq 'Community') { + $r->print(&mt('Enter the community with the role of [_1].',$cctitle)); + } else { + $r->print(&mt('Enter the course with the role of [_1].',$cctitle)); + } + $r->print('' + .'' + .' '); + if ($type eq 'Community') { + $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle)); + } else { + $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle)); + } + $r->print('' + .'' + .'' ); } } @@ -283,9 +381,9 @@ sub display_matched_courses { } if ($numcourses > 1 && $multiple) { - $r->print('print(' - '); } @@ -293,13 +391,17 @@ sub display_matched_courses { 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').'' - .''.&mt('Course Title').'' - .''.&mt('Domain').'' - .''.&mt('Course Code').'' - .''.&mt('Owner/Co-owner(s)').'' - .''.&mt('Type').'' - ); + .''.$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'}, @@ -307,21 +409,57 @@ sub display_matched_courses { } $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,@owners); + 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'}; - 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)); + $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,$courses{$course}{'owner'}); + if ($courses{$course}{'co-owners'} ne '') { + foreach my $item (split(/,/,$courses{$course}{'co-owners'})) { + push(@owners,$item); } } } else { @@ -329,28 +467,23 @@ sub display_matched_courses { ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course}); push(@owners,&unescape($singleowner)); } - my $ownerstr = join(', ',@owners); - $r->print(''.&course_chooser($multiple,$cdom,$cnum,$cleandesc).''); + 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(''); - $r->print(''); - if ($instcode ne '') { - $r->print(&unescape($instcode)); - } else { - $r->print(' '); + unless ($type eq 'Community') { + $r->print(''); + if ($instcode ne '') { + $r->print(&unescape($instcode)); + } else { + $r->print(' '); + } + $r->print(''); } - $r->print(''); $r->print(''.$ownerstr.''); - $r->print(''); - if ($ttype ne '') { - $r->print(&mt(&unescape($ttype))); - } else { - $r->print(' '); - } - $r->print(''); if ($showroles) { $r->print(''); my $rolestr; @@ -361,7 +494,7 @@ sub display_matched_courses { my (undef,$crdom,$crname,$crtitle) = split('/',$role); $rolestr .= $crtitle.', '; } else { - $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', '; + $rolestr .= &Apache::lonnet::plaintext($role,$type).', '; } } $rolestr =~ s/\, $//; @@ -378,9 +511,9 @@ sub display_matched_courses { } if (!%courses) { - $r->print(&mt('None found')); + $r->print(''.&mt('None found').''); } elsif ($multiple) { - $r->print(''); + $r->print(''); } $r->print(''. "\n".''."\n". @@ -401,6 +534,11 @@ sub display_matched_courses { $env{'form.cnumelement'}.'" />'."\n". ''."\n"); + if ($env{'form.typeelement'} ne '') { + $r->print(''."\n"); + + } } if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) { $r->print(' &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('Course Type') + $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', ); - $typeselectform = ''."\n"; - my $officialjs; - if ($type eq 'Course') { - if ($env{'form.fixeddom'}) { - $officialjs = 1; - ($instcodeform,$jscript,$$numtitlesref) = - &instcode_selectors($codedom,'filterpicker',$officialjs); - } - if ($instcodeform eq '') { - $instcodeform = - ''; - $instcodetitle = $lt{'ins'}; - } else { - $instcodetitle = $lt{'inc'}; - } - if ($env{'form.fixeddom'}) { - $instcodetitle .= '('.$codedom.')'; + if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) { + my $typeval = 'Course'; + if ($type eq 'Community') { + $typeval = 'Community'; } - if ($jscript ne '') { - $jscript = ''."\n"; + $typeselectform = ''; + } else { + $typeselectform = '".&mt($posstype)."\n"; + } + $typeselectform.=""; + } + + my ($cloneableonlyform,$cloneabletitle); + if (exists($filter->{'cloneableonly'})) { + my $cloneableon = ''; + my $cloneableoff = ' checked="checked"'; + if ($filter->{'cloneableonly'}) { + $cloneableon = $cloneableoff; + $cloneableoff = ''; + } + $cloneableonlyform = ' '.&mt('Required').''.(' 'x3).' '.&mt('No restriction').''; + if ($env{'form.form'} eq 'ccrs') { + $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom; + } else { + $cloneabletitle = &mt('Cloneable by you'); } } - foreach my $posstype ('Course','Community') { - $typeselectform.='".&mt($posstype)."\n"; + 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) = + &Apache::courseclassifier::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.')'; + } + } } - $typeselectform.=""; + my $output = qq| @@ -570,6 +735,7 @@ sub build_filters { $name_input $roleelement $multelement +$typeelement |; if ($formname eq 'portform') { $output .= ''."\n"; @@ -584,15 +750,24 @@ $multelement .$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) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'}) - .$typeselectform - .&Apache::lonhtmlcommon::row_closure(); + 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) @@ -621,50 +796,94 @@ $multelement .$list->{'coursefilter'}.'" />' .&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(); - $output .= ''."\n"; + } + if ($coord_cloneable) { + $output .= ''; + } + } + $output .= ''."\n". + ''."\n".''."\n".''."\n"; - return $jscript.$output; + return $jscript.$warning.$output; } -sub instcode_selectors { - my ($codedom,$formname,$officialjs) = @_; - 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,$officialjs); - if ($numtitles > 0) { - my $unofficial = ' checked="checked" '; - my $official = ''; - if ($env{'form.official'}) { - $official = $unofficial; - $unofficial = ''; - } - $output .= ''.&mt('Official course:').' '. - ''. - &mt('Yes').''.(' 'x3).''. - ''.&mt('No').''. - &Apache::courseclassifier::build_instcode_selectors($numtitles, - $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n". - ''."\n". - ''."\n"; - +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 (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) { + my $warning = ''.&mt('Intended course owner not specified'). + ''; + return ('',$warning); + } elsif (&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); } - return ($output,$jscript,$numtitles); } sub search_courses { - my ($r,$type,$onlyown,$filter,$numtitles) = @_; - my (%courses,%showcourses); + 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->print(''.&mt('Searching ...').''); $r->rflush(); if (($filter->{'ownerfilter'} ne '') || ($filter->{'ownerdomfilter'} ne '')) { @@ -676,21 +895,35 @@ sub search_courses { $filter->{$item}='.'; } } + my $now = time; my $timefilter = - ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'}); + ($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'}) { + if ($env{'form.official'} eq 'on') { $instcodefilter = - &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'}, - $numtitles); + &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'}, @@ -698,12 +931,16 @@ sub search_courses { $instcodefilter, $filter->{'combownerfilter'}, $filter->{'coursefilter'}, - undef,undef,$type,$regexpok); + 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, - ['cc','in','ad','ep','ta','cr'], + [$ccrole,'in','ad','ep','ta','cr'], $filter->{'domainfilter'}); foreach my $role (keys(%rolehash)) { my ($cnum,$cdom,$courserole) = split(':',$role); @@ -734,12 +971,18 @@ sub search_courses { } sub course_chooser { - my ($multiple,$cdom,$cnum,$cleandesc) = @_; + my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_; my $output; if ($multiple) { $output = ''."\n"; + } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) { + if ($env{'form.form'} eq 'ccrs') { + $output = &mt('No cloning for ').$env{'form.cloner'}."\n"; + } else { + $output = &mt('No rights to clone')."\n"; + } } else { - $output = ''."\n"; } return $output; @@ -754,13 +997,12 @@ sub gochoose_javascript { list => 'courselist', }, 'Community' => { - name => 'grouppick', - total => 'grouptotal', - list => 'grouplist', + name => 'coursepick', + total => 'coursetotal', + list => 'courselist', }, ); - my $output .= qq| - |; - return $output; + return &Apache::lonhtmlcommon::scripttag($output); } 1; @@ -870,7 +1122,7 @@ Course Activity - how recently was cours Course Domain - the domain of the course =item * -Course Type - Course or Community +Type - Course or Community =item * Course Institutional Code - the institutional identifier assigned to the course @@ -934,9 +1186,9 @@ javascript code for reporting selected s =item * X -B: +B: -Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), hash of courses. +Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), username of new course owner, domain of new course owner, hash of courses. Output: 0 @@ -955,10 +1207,10 @@ Side Effects: None =item * X -B: +B: -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); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm). +Input: 12 - 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); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm); username and domain of new course owner who wants to clone, $typeelem; reference to array of titles of components in institutional codes (official courses). Output: 1 - $output - HTML for display of search criteria, and hidden form elements. @@ -966,10 +1218,12 @@ 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; for institutional codes - number of categories). +Input: 9 - 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; optional username of new course owner, optional domain of new course owner). Seventh and eighth needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in +domain being filtered by (used when DC is using course creation form). Ninth is reference to array of titles of components in institutional codes (official courses). Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type. @@ -978,11 +1232,11 @@ Side Effects: None =item * X -B: +B: -Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description. +Input: 5 - single (0) or multiple (1) courses; course domain, course number; course description; can clone course (1 if new course owner has cloning rights). -Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection. +Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection. Side Effects: None @@ -1029,7 +1283,11 @@ javascript functions used when user sele =item -(g) Scantron Operator uploading a scantron file to a course - course number is written to visible form element in opener window. Child window closes. +(g) Bubblesheet Scanning Operator uploading a bubblesheet file to a course - course number is written to visible form element in opener window. Child window closes. + +=item + +(h) User requesting creation of a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes. =back
'.&mt('None found').'
'."\n"; + } + if ($coord_cloneable) { + $output .= ''; + } + } + $output .= ''."\n". + '